﻿/*****************

  (c) 2006 Q42 B.V.

  The contents of this file, partially or in whole, may not be reproduced
  without prior written permission by Q42 B.V.

*****************/

function XmlHttp(){}
XmlHttp.prototype =
{
  req: new Array(),
  request: function(url, send, asynchronous, processReqChangeFunction, post)
  {
    if (window.XMLHttpRequest)
			this.req[processReqChangeFunction] = new XMLHttpRequest();
    else if (window.ActiveXObject)
			this.req[processReqChangeFunction] = new ActiveXObject("Microsoft.XMLHTTP");
    if (this.req[processReqChangeFunction] == null)
			return;
    if (asynchronous)
			this.req[processReqChangeFunction].onreadystatechange = eval(processReqChangeFunction);
		
		if (post) {
		  this.req[processReqChangeFunction].open("POST", url, asynchronous);
		  this.req[processReqChangeFunction].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		else
		{
		  this.req[processReqChangeFunction].open("GET", url, asynchronous);
		}
    
    this.req[processReqChangeFunction].send(send);
    return this.req[processReqChangeFunction];
  }
}
var xmlhttp = new XmlHttp();

function getElementsByTagNameAttributeValue(ancestorEl, tagName, attrName, attrValue)
{
  if (typeof(attrValue) == "undefined")
    attrValue = null;

  var els = [];
  var a = ancestorEl.getElementsByTagName(tagName);
  for (var i=0; i<a.length; i++)
  {
    var el = a[i];
    switch (attrName)
    {
      case "className":
      case "class":
        if (el.className.indexOf(attrValue) != -1)
          els.push(el);
        break;
      default:
        if(attrName=="for")
        {
			var val = el.htmlFor;
        }
        else var val = el.getAttribute(attrName) || el[attrName];
        if ((val != null) && ((attrValue == null) || (val == attrValue)))
          els.push(el);
    }
  }
  return els;
};

Function.prototype.trim = function() {
    return this.replace(/^\s*|\s*$/g,"");
}

function resize_iframe()
{
    //Catch cross domain problems
    try
    {
        var parentFrame = parent.document.getElementById('iframeVacanceSelect');
        if (parentFrame)
        {
            parentFrame.style.height = document.body.scrollHeight + 15;
        }
    }
    catch (err)
    {
    }
}

function resizeFrame(f) 
{
	try
	{
		if (f != null)
		{
			//Firefox
			if (f.contentWindow.document.compatMode &&
					f.contentWindow.document.compatMode != 'BackCompat') 
			{
				f.style.height = f.contentWindow.document.documentElement.scrollHeight + 15 + 'px';
				f.style.width = f.contentWindow.document.documentElement.scrollWidth + 15 + 'px';
			}
			
			//IE
			else 
			{
				f.style.height = f.contentWindow.document.body.scrollHeight + 15 + 'px';
				f.style.width = f.contentWindow.document.body.scrollWidth + 15 + 'px';
			}
		}
	}
	catch (e)
	{
		//alert(e.message);
	}
}

function pageWidth() {
  try {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : 0;
  }
  catch (e) {
  }

  return 0;
}

function pageHeight() {
  try {
  return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : 0;
  }
  catch (e) {
  }

  return 0;
}

function posLeft() {
  try {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
  }
  catch (e) {
  }

  return 0;
}

function posTop() {
  try {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
  }
  catch (e) {
  }

  return 0;
}

function posRight() {
  return posLeft() + pageWidth();
}

function posBottom() {
  return posTop() + pageHeight();
}

function isScollingUtil(evt)
{ 
	var container = document.getElementById("googleMiniMapContainer");
	if (container)
	{
		alert(container.pageYOffset);
	}
}

function VSTooltip(){}
VSTooltip.prototype =
{
  dInterval: 500,
  zInterval: 0,
  zHideInterval: 0,
  xPos: 0,
  yPos: 0,
  defaultText: '',
  scText: '',
  c2rText: '',
  showOnTop: false,
  showOnLeft: false,

  setDelay: function(delay) {
    vstooltip.dInterval = delay;
  },

  setDefaultText: function(txt) {
    vstooltip.defaultText = txt;
  },

  setDefaultScText: function(txt) {
    vstooltip.scText = txt;
  },

  setDefaultC2rText: function(txt) {
    vstooltip.c2rText = txt;
  },

  setShowOnTop: function(bool) {
    vstooltip.showOnTop = bool;
  },

  setShowOnLeft: function(bool) {
    vstooltip.showOnLeft = bool;
  },
  
  setMouseCoords: function(e) {
    var top = posTop();
    var bottom = posBottom();
    if (document.all) {
      vstooltip.xPos = window.event.clientX;
      vstooltip.yPos = window.event.clientY + top;
    } else {
      vstooltip.xPos = e.pageX;
      vstooltip.yPos = e.pageY;
    }
    if ((bottom - vstooltip.yPos) < 50) vstooltip.yPos -= 100;
    else if ((bottom - vstooltip.yPos) < 75) vstooltip.yPos -= 75;
  },

  showToolTip: function(e) {
    vstooltip.setMouseCoords(e);
    clearInterval(vstooltip.zInterval);
    vstooltip.zInterval = setTimeout(function() { vstooltip.doShowToolTip(e); }, vstooltip.dInterval);
  },

  doShowToolTip: function(e) {
    clearInterval(vstooltip.zInterval);
    var toolTip = document.getElementById("toolTip");
    var zText = e.subject.getAttribute("tooltip");
    if (zText == null) {
      zText = vstooltip.defaultText;
    }
    else if (zText == 'sc') {
      zText = vstooltip.scText;
    }
    else if (zText == 'c2r') {
      zText = vstooltip.c2rText;
    }
    toolTip.style.top = (vstooltip.yPos + 20) + "px";
    toolTip.style.left = vstooltip.xPos + "px";
    toolTip.innerHTML = zText;
    toolTip.style.display = "block";
    if (vstooltip.showOnTop) {
      toolTip.style.top = (vstooltip.yPos - toolTip.offsetHeight - 10) + "px";
    }
    if (vstooltip.showOnLeft) {
      toolTip.style.left = (vstooltip.xPos - toolTip.offsetWidth - 10) + "px";
    }
    if (vstooltip.zHideInterval > 0) {
      vstooltip.zInterval = setTimeout(function() { vstooltip.hideToolTip(); }, vstooltip.zHideInterval);
    }
  },

  hideToolTip: function() {
    document.getElementById("toolTip").style.display = "none";
    clearInterval(vstooltip.zInterval);
  },

  attachTooltip: function(tooltip) {
    var info_tooltip = document.getElementById(tooltip);
    if (info_tooltip) {
      Spif.DOMEvents.attach(info_tooltip, 'mouseover', vstooltip.showToolTip);
      Spif.DOMEvents.attach(info_tooltip, 'mouseout', vstooltip.hideToolTip);
    }
  }
}
var vstooltip = new VSTooltip();

if(!Array.indexOf){
	      Array.prototype.indexOf = function(obj){
	          for(var i=0; i<this.length; i++){
	              if(this[i]==obj){
	                  return i;
	              }
	          }
	          return -1;
	      }
	  }
