// JavaScript Document

function SetBlur() {
	entries = document.getElementsByTagName('a');
	for (var i=0; i < entries.length; i++) {
		entries[i].onfocus = function() {this.blur()}
	}
}

function SetActiveTab(){
	var currentPageId = document.body.getAttribute('id');
	
	objMenuItemCollection = document.getElementById('mainMenu').getElementsByTagName('li');
	for( var i = 0; i < objMenuItemCollection.length; i++ ){
		if (objMenuItemCollection[i].getAttribute('id').substr(2) == currentPageId){
			if (currentPageId.toLowerCase() == 'home'){
				objMenuItemCollection[i].className = 'home_current';
			} else {
				objMenuItemCollection[i].className = 'current';
			}
		}
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} 
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} 
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

var DEFAULTCONTENTHEIGHT = 0;

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			DEFAULTCONTENTHEIGHT = document.getElementById('header').offsetHeight + document.getElementById('mainMenu').offsetHeight + document.getElementById('panel').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight = footerElement.offsetHeight;
			if (windowHeight - (DEFAULTCONTENTHEIGHT + footerHeight) >= 0) {
				footerElement.style.position = 'absolute';
				footerElement.style.top = (windowHeight - footerHeight + 0) + 'px'; // het getal erbij is de padding van de 'con' container. 
			}
			else {
				//footerElement.style.position = 'static';
				footerElement.style.position = 'absolute';
				footerElement.style.top = (DEFAULTCONTENTHEIGHT + 30) + 'px'; // het getal erbij is de padding van de 'con' container.
			}
		}
	}
}



// Custom validation function for validating date
// Validates date is in correct format and not in the future
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
function ValidateDate(sender, args){
   
    var x = document.forms[0].elements;
    var name = "ddl_geboortedatum";
    //debugger    
    var day = parseInt(x[name+"_dag"].options[x[name+"_dag"].selectedIndex].value);
    var month = parseInt(x[name+"_maand"].options[x[name+"_maand"].selectedIndex].value);
    var year = parseInt(x["txt_geboortedatum_jaar"].value);

    if (!day || !month || !year){
        args.IsValid = false;
        return;
    }

    if (year/4 == parseInt(year/4))
        monthLength[1] = 29;

    if (day > monthLength[month-1]){
        args.IsValid = false;
        return;
    }
    
    monthLength[1] = 28;

    var now = new Date();
    now = now.getTime(); //NN3

    var dateToCheck = new Date();
    dateToCheck.setYear(year);
    dateToCheck.setMonth(month-1);
    dateToCheck.setDate(day);
    var checkDate = dateToCheck.getTime();
    
    // Check if date isn't in the future
    args.IsValid=(checkDate < now);
}

// Validates if on of the gender radio buttons has been selected
function ValidateGender(sender, args){
    for (i=0;i<document.forms[0].rdo_geslacht.length;i++)
    {
        if (document.forms[0].rdo_geslacht[i].checked)
        {
	        args.IsValid = true;
	        return;
        }
    }
    
    // No selection has been made
    args.IsValid = false;
}

preloadImages('left.gif', 'left-on.gif', 'left-home.gif', 'left-home-on.gif', 'right.gif', 'right-on.gif', 'right-end.gif');

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
	var imagePath = 'static/img/';
    var i,j = document.imageArray.length, args = preloadImages.arguments;

    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = imagePath + args[i];
      }
    }
  }
}

/* Replacement calls. Please see documentation for more information. */
function CreateHeadlines(){
	if(typeof sIFR == "function"){
	
	// This is the preferred "named argument" syntax
		sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"static/flash/VAGRounded_LT_Light.swf", sColor:"#a9a18c", sLinkColor:"#a9a18c", sBgColor:"#FFFFFF", sHoverColor:"#a9a18c"}));
		
		sIFR.replaceElement(named({sSelector:"body h2", sFlashSrc:"static/flash/VAGRounded_LT_Light.swf", sColor:"#a9a18c", sLinkColor:"#a9a18c", sBgColor:"#FFFFFF", sHoverColor:"#a9a18c"}));
		
				sIFR.replaceElement(named({sSelector:"body h3", sFlashSrc:"static/flash/VAGRounded_LT_Light.swf", sColor:"#a9a18c", sLinkColor:"#a9a18c", sBgColor:"#FFFFFF", sHoverColor:"#a9a18c"}));
				sIFR.replaceElement(named({sSelector:"body h4", sFlashSrc:"static/flash/VAGRounded_LT_Light.swf", sColor:"#a9a18c", sLinkColor:"#a9a18c", sBgColor:"#FFFFFF", sHoverColor:"#a9a18c"}));
	}
}