/*********************************
* Returns the element with the specified id
**********************************/
function el(id)
{
	return document.getElementById(id);
}

/*********************************
* Returns value of querystring variable
**********************************/
function getQueryVariable(variable) 
{ 
  var query = window.location.search.substring(1); 
  var vars = query.split("&");
   
  for (var i=0;i<vars.length;i++) 
  { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) 
	{ 
      return pair[1]; 
    }
	else
	{
		return null;
	}
  } 
} 

/*********************************
* Returns height of window in pixels
**********************************/
function getWindowHeight()
{
	// calculate windowheight 
	var height = 0;
	
	if( typeof(window.innerHeight ) == 'number' )
	{
		//Non-IE
		height = window.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight )
	{
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight )
	{
		//IE 4 compatible
		height = document.body.clientHeight;
	}
	return height;
}

/*********************************
* Returns width of window in pixels
**********************************/
function getWindowWidth()
{
	// calculate windowheight 
	var width = 0;
	
	if( typeof(window.innerWidth ) == 'number' )
	{
		//Non-IE
		width = window.innerWidth;
	}
	else if( document.documentElement && document.documentElement.clientWidth )
	{
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth )
	{
		//IE 4 compatible
		width = document.body.clientWidth;
	}
	return width;
}

/*********************************
* Returns height of body in pixels
**********************************/
function getBodyHeight()
{
	return document.getElementsByTagName('body')[0].clientHeight;
}

/*********************************
* Returns width of body in pixels
**********************************/
function getBodyWidth()
{
	return document.getElementsByTagName('body')[0].clientWidth;
}
var _ah = 0; //actual height

var _isHomepage = false;
var _hasNoCustomSection = true;

function onLoad(isHomePage, hasNoCustomSection )
{
	_isHomepage = isHomePage;
	_hasNoCustomSection = hasNoCustomSection;
	
	if(hasNoCustomSection == false && isHomePage == false)
	{
		setScrollContainer();
	}
	else 
	{	
		doResize();
	}
	
	/*
	if( !window.onresize )
	{
		window.onresize = doResize;
		geeft een BUG in IE waardoor IE vast loopt
	}
	*/
}
function setScrollContainer()
{
	var heightHeader = el('header').clientHeight;
	var footerHeight = el('customwrapper').clientHeight + el('footer').clientHeight;
	var bodyHeight = getInnerHeight();
	var customHeight = bodyHeight - (heightHeader + footerHeight);
	var contentHeight = el('insidecontainer').clientHeight;
	
	el('customsection').style.height = customHeight+'px';
	el('customsection').style.overflow = 'auto';
	el('container').style.height = customHeight+'px';
	
	if(contentHeight < customHeight)
	{
		el('insidecontainer').style.height = customHeight+'px';
	}
	
	
}
function doResize()
{
	var isHomePage = _isHomepage;
	var hasNoCustomSection = _hasNoCustomSection;
	var hh = el('header').clientHeight;
	var fh = el('footer').clientHeight;
	var bh = getInnerHeight();
	if( isHomePage )
	{
		var nh = (bh - hh ) - fh;
		if( _ah == 0 ){ 
			_ah = el('customsection').style.height; 
			}
		//alert( _ah + " / " + nh );
		if( 630 < nh )
		{
			el('customsection').style.height = nh+'px';
		}
		//alert( bh + " " + hh + " " + fh  + " " + isHomePage + " " + _ah );		
	}
	else
	{
		var nh = (bh - hh ) - fh ;//-33
		var minHeight = (el('maininside').clientHeight)?el('maininside').clientHeight*1:630;

		/* 
		* Hack for IE 7...element main word gecontroleerd op extra content.
		*/
		//var minHeight2 = (el('main').clientHeight)?el('main').clientHeight*1:630;
		/* End Hack */
		//if(minHeight < minHeight2){
		//	minHeight = minHeight2;
		//}
		if( !hasNoCustomSection )
		{
			var csh = el('customwrapper').clientHeight;
			nh = nh - csh;
			//minHeight = minHeight - csh;
		}
		if( minHeight < nh ){
			el('main').style.height = nh+'px';
		}else{
			el('main').style.height = 'auto';
		}
		//alert(el('main').clientHeight);
		//alert( bh + " " + hh + " " + fh  + " " + minHeight + "/ " + nh + " - " +el('maininside') + " = " + el('maininside').clientHeight);		
	}
}

/*********************************
* Returns innerheight of body in pixels
**********************************/
function getInnerHeight() 
{
	var winHeight = 0;
			  
	if( typeof(window.innerWidth ) == 'number' ) {
		//Non-IE
		winHeight = window.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight )
	{
		//IE 6+ in 'standards compliant mode'
		winHeight = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight )
	{
		//IE 4 compatible
		winHeight = document.body.clientHeight;
	}
	return winHeight;
}

	/** ============================================================
	 * General mouseover hover function 
	 *
	 * Example:		onmouseover="idi_mOver(this)" onmouseout="idi_mOut(this)"
	 */
	function idi_mOver( element )
	{
		element.className += " hover";
	}
	function idi_mOut( element )
	{
		element.className = element.className.replace(' hover','');
		//required if the element has default no className 
		element.className = element.className.replace('hover','');
	}


/*********************************
* zoek adviseur box
**********************************/
function zoekenAdviseur( formname ){
   var error = "false";
   if(document.forms[formname].postCode.value==""){
      errorMsg="Vul a.u.b. goede waarde voor postcode in";
      error= "true";
   }
   if(document.forms[formname].postCode.value.length < 4){
         errorMsg="Vul a.u.b. goede waarde voor postcode in";
         error= "true";
   }
   if(!checkNumber(document.forms[formname].postCode.value)){
      errorMsg="Vul a.u.b. goede waarde voor postcode in";
      error= "true";
   }
   if(error == "false"){
     //var sUrl = 'http://www.goudse.nl/nl/includes/webservice.jsp?serviceType=zoeken&postCode='+document.forms[formname].postCode.value;
     var sUrl = 'http://www.goudse.nl/nl/includes/webservice.jsp?serviceType=zoeken&postCode='+document.forms[formname].postCode.value;
     ExLightbox.show( sUrl, "Hieronder vindt u de assurantie-adviseur bij u in de buurt", "width=800, height=500" );
   }else{
      alert(errorMsg);
   }
   return false;
}

function testLightbox()
{
  alert(sUrl);  
  var oOptions= {initialWidth:600, initialHeight:500, overlayOpacity:0.2, closeKeys: [27, 70] };
  Lightbox.open(sUrl, "Hieronder vindt u de assurantie-adviseurs bij u in de buurt", oOptions );
}

function openKoersInfo()
{
	var sUrl = 'http://www.goudse.nl/nl/degoudse/index.jsp';
	ExLightbox.show( sUrl, "In dit overzicht vindt u de actuele koersen van de verschillende beleggingsfondsen van De Goudse.", "width=800, height=500" );
	return false;
}

function checkAdviseur( formname ){
   var error = "false";
   if(document.forms[formname].postCode.value==""){
      errorMsg="Vul a.u.b. goede waarde voor postcode in";
      error= "true";
   }
   if(document.forms[formname].postCode.value.length < 4){
            errorMsg="Vul a.u.b. goede waarde voor postcode in";
            error= "true";
   }
   if(!checkNumber(document.forms[formname].postCode.value)){
         errorMsg="Vul a.u.b. goede waarde voor postcode in";
         error= "true";
   }
   if(error == "false"){
      return true;
   }else{
      alert(errorMsg);
      return false;
   }
   return true;
}

function checkNumber(num){
  var x=num
  var anum=/(^\d+$)/
  if (anum.test(x))
    testresult=true
  else{
    testresult=false
  }
  return (testresult)
}