function tooltipOn(event,text) {
	
	/* config */
	var tooltipSpacingX = 10;
	var tooltipSpacingY = 10;
	
	elm=document.getElementById('tooltip');
	/* display element for size measurement */
	elm.style.display='block';
	
	/* set text */
	elm.innerHTML = text;
	
	/* get tooltip size */
	//var tooltipSizeX = 100;
	var tooltipSizeX = elm.offsetWidth;
	var tooltipSizeY = elm.offsetHeight;
	
	/* get mousepointer position */
	var pointerPosX = event.clientX;
	var pointerPosY = event.clientY;
	
	/* window size */
	var windowSizeX = document.body.clientWidth;
	var windowSizeY = document.body.clientHeight;
	
	/* window size */ 
	var tooltipPosX = pointerPosX + tooltipSpacingX;
	var tooltipPosY = pointerPosY + tooltipSpacingY;
	
	/* tooltip doesn't fit screen X*/
	//elm.innerHTML = tooltipSizeX +'-'+ pointerPosX +'-'+ tooltipSpacingX +'>'+ windowSizeX;
	
	if ((tooltipSizeX + pointerPosX + tooltipSpacingX) > windowSizeX ) {
		tooltipPosX = pointerPosX - tooltipSpacingX - tooltipSizeX;
	}
	
	/* tooltip doesn't fit screen Y */
	if ((tooltipSizeY + pointerPosY + tooltipSpacingY) > windowSizeY ) {
		tooltipPosY = pointerPosY - tooltipSpacingY - tooltipSizeY;
	}
	
	// determine how much has been scrolled
	var scrolledX, scrolledY; 

	if( self.pageYOffset ) { 

		scrolledX = self.pageXOffset; 
		scrolledY = self.pageYOffset; 

	} else if( document.documentElement && document.documentElement.scrollTop ) { 

		scrolledX = document.documentElement.scrollLeft; 
		scrolledY = document.documentElement.scrollTop; 
			
	} else if( document.body ) { 

		scrolledX = document.body.scrollLeft; 
		scrolledY = document.body.scrollTop; 
		
	} 
	
	elm.style.left = tooltipPosX + scrolledX + 'px';
	elm.style.top = tooltipPosY + scrolledY + 'px';
	
}

function tooltipOff() {
	elm=document.getElementById('tooltip');
	elm.style.display='none';
	elm.style.left=0 + 'px';
	elm.style.top=0 + 'px';
}

function zoekprof(new_value){
	var cookie = "profielkeuze="+new_value+"; path=/";
	document.cookie = cookie;
	
	woningaanbod_checkboxes();
}

function woningaanbod_checkboxes(){
	
	pac = document.getElementById("passend_aanbod").checked;
	pzc = document.getElementById("passend_zoekprofiel").checked;
	
	path = '/wonen/woningaanbod/actueel_woningaanbod/';
	
	headervar = '';
	
	if(pac == true){
		headervar = headervar+'&pac=true';
	}
	if(pzc == true){
		headervar = headervar+'&pzc=true';
	}
	
	 window.top.location=path+'?rel=1'+headervar;
}

function woningaanbod_checkboxes1(){
	path = '/wonen/woningaanbod/actueel_woningaanbod/';
	 window.top.location=path+'?rel=1';
}

function csearch(naam) { //cookie/value opzoeken
  var str = document.cookie;
  var zstr = naam + "=";
  var start = str.indexOf(zstr, 0);
  if(start == -1) {
    return false;
  } else {
    start += zstr.length;
    var eind = str.indexOf(";", start);
    if(eind == -1) eind = str.length;
    return unescape(str.substring(start, eind));
  }
}

function SetVisible(tabblad){
	
	if(tabblad==1){// Woningaanbod weergeven
		document.getElementById("legenda_1").style.display='block';
		document.getElementById("legenda_2").style.display='none';

		document.getElementById("tab_woningaanbod").style.display='block';
		document.getElementById("tab_aanbod_in_de_kaart").style.display='none';
		
		document.getElementById("butt_woningaanbod").className='active';
		document.getElementById("butt_aanbod_in_de_kaart").className='';
		
		// Cookie(s) setten voor correcte weergave verladen pagina (juiste tabblad open)
		document.cookie = "wa=open";
		document.cookie = "aindk=closed";
	}
	if(tabblad==2){// Aanbod in de kaart weergeven
		document.getElementById("legenda_1").style.display='none';
		document.getElementById("legenda_2").style.display='block';
	
		document.getElementById("tab_woningaanbod").style.display='none';
		document.getElementById("tab_aanbod_in_de_kaart").style.display='block';
		
		document.getElementById("butt_woningaanbod").className='';
		document.getElementById("butt_aanbod_in_de_kaart").className='active';
		
		// Cookie(s) setten voor correcte weergave verladen pagina (juiste tabblad open)
		document.cookie = "wa=closed";
		document.cookie = "aindk=open";
	}
}

function readCookie(cookieName) {
  cookie_array = document.cookie.split ("; ");
  for (x=0; x < cookie_array.length; x++) {
      cookieParts_array = cookie_array[x].split("=");
      if (cookieParts_array[0] == cookieName)
        return cookieParts_array[1];
    }
  return null;
}

function startStyle() 
{
  
  identity=document.getElementById("content_frame");
  identity2=document.getElementById("header");
  cook=readCookie("activestyle");
  if(cook=="groot")
  {
    identity.className="groot";
    identity2.className="groot";
  }
  else if(cook=="klein") {
    identity.className="klein";
    identity2.className="klein";
  }
}


function changeStyle() 
{
  identity=document.getElementById("content_frame");
  identity2=document.getElementById("header");
  if (identity.className=="groot") 
  {
    identity.className="klein";
    identity2.className="klein";
    document.cookie = "activestyle=klein;path=/";
  }
  else 
  {
    identity.className="groot";
    identity2.className="groot";
    document.cookie = "activestyle=groot;path=/";
  }
}


function clearDefault(elm) {
  if(elm.value==elm.defaultValue)elm.value='';
}
function setDefault(elm) {
  if(elm.value=='')elm.value=elm.defaultValue;
}

/* GIDS fold/ unfold */
function showItemDetails(productID) {
	elm = document.getElementById(productID);
	if (elm.style.display == 'block') {
		elm.style.display = 'none';
		}
		else {
			elm.style.display = 'block';
			}
		}
		
/* ajax search */

var url;
var tm;
var http;

/* AJAX DETAIL SOAP CALLS */
function soapDetail(input,url,target) {
  if (input.length > 1) {
    http = getHTTPObject();
    http.open("GET", url + escape(input), true); 
    http.onreadystatechange = function () { handleRequest(target); }; 
    http.send(null);
  } else {
    clearSearchDiv();
  }
}

function handleRequest(target) {
  if (http.readyState == 4) {
    document.getElementById(target).innerHTML = http.responseText;
    document.getElementById(target).className='visible';
  }
}

function clearRequest(elmId) {
  document.getElementById(elmId).innerHTML = '';
  document.getElementById(elmId).className='hidden';
}


/* AJAX SUGGEST */
function search(input,url) {
  if (input.length > 1) {
    http = getHTTPObject();
    http.open("GET", url + escape(input), true); 
    http.onreadystatechange = handleSearch; 
    http.send(null);
  } else {
    clearSearchDiv();
  }
}

function handleSearch() {
  if (http.readyState == 4) {
    document.getElementById('search-frame').innerHTML = http.responseText;
    document.getElementById('search-frame').style.visibility='visible';
  }
}
function clearSearch() {
  tm = setTimeout('clearSearchDiv()', 500);
}
function clearSearchTimeout() {
  window.clearTimeout(tm);
}
function clearSearchDiv(input) {
  document.getElementById('search-frame').innerHTML = '';
  document.getElementById('search-frame').style.visibility='hidden';
}

function getHTTPObject() { 
  var xmlhttp; 
  /*@cc_on 
  @if (@_jscript_version >= 5) 
    try { 
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (e) { 
      try { 
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
      } catch (E) { 
        xmlhttp = false; 
      } 
    } 
  @else 
  xmlhttp = false; 
  @end @*/  
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 
    try { 
      xmlhttp = new XMLHttpRequest(); 
    } catch (e) { 
      xmlhttp = false; 
    } 
  } 
  return xmlhttp; 
} 

// Klantonderzoek: op elke externe link wordt Exit popup geopend
function popupWin(elm) {
	// if external link, then open popup
	var sUrl = elm.attributes['href'].value;
	
	// if cookie exists
	if (readCookie('popupCookie') != null) {
		var popupCookieStrings = readCookie('popupCookie').split(',');

		if (popupCookieStrings[1] == 'false'){
			if (sUrl.indexOf('http') > -1) {
				if (sUrl.indexOf('hetpunt.nl') == -1) {
					var oWin = window.open('/popup/exit/','lastWin','status=no,resizable=yes,scrollbars=yes,location=auto,left=0,top=0,width=600,height=500');
					document.cookie = 'popupCookie'+"=" + popupCookieStrings[0]+',true'  +"; path=/";
				}
			}
			else {
				var cookieTime = new Date(popupCookieStrings[0]);
				cookieTime = cookieTime.setSeconds(cookieTime.getSeconds() + 90);
				var now = new Date();
				if (cookieTime<now){
					var oWin = window.open('/popup/exit/','lastWin','status=no,resizable=yes,scrollbars=yes,location=auto,left=0,top=0,width=600,height=500');
					document.cookie = 'popupCookie'+"=" + popupCookieStrings[0]+',true'  +"; path=/";
				}
			}
		}
	}
	else {
		setPopupCookie();
	}
}

/*function popupWin2() {
	var oWin2 = document.getElementById('popup');
	oWin2.style.display='block';
}*/

function init() { // initialise scripts
	// for all links in the website, if there is not already a onclick handler, call the popupWin function 'onclick'
	var aA = document.getElementsByTagName('a');
	for (var i=0; i<aA.length; i++) {
		if (typeof(aA[i].onclick)!='function')
			aA[i].onclick = function() { popupWin(this); };
	}
	// check if cookie, otherwise set it
	if (readCookie('popupCookie') == null) {
		setPopupCookie();
	}
}

function setPopupCookie(){
	var now = new Date();
	// session cookie, geen expiration time
	//var expireDate = new Date();
	//expireDate.setTime(expireDate.getTime()+(7*60*60*1000)); // expiration date is now+7 hours
	//var expires = "; expires="+expireDate.toGMTString();

	document.cookie = 'popupCookie' +"=" + now +",false"  +"; path=/";	
}

// [BV] - poll disabled op verzoek van Sandra Uytdewilligen 31-8-2011
//window.onload = function(){ init();}
