function SetContentPanel(contentpanelid, footerpanelid, backgroundpanelid) 
{
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		myHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}

	var contentpanel = document.getElementById(contentpanelid);
	var footerpanel = document.getElementById(footerpanelid);
	var backgroundpanel = document.getElementById(backgroundpanelid);
	if (contentpanel.clientHeight < 400)
	{
		contentpanel.style.height = '675px';
		footerpanel.style.top = (contentpanel.clientHeight + 25) + "px";
		if ((myHeight - (contentpanel.clientHeight + 25)) > 150) 
		{
			footerpanel.style.height = myHeight - (contentpanel.clientHeight + 25) + "px";
		}
	}
	else 
	{
		//alert('WUT?');
		footerpanel.style.top = (contentpanel.clientHeight + 475) + "px";
		//footerpanel.style.top = (contentpanel.clientHeight + 100) + "px";
		backgroundpanel.style.height = (contentpanel.clientHeight) + "px";
	}
}

function getPageDimensions()
{
	var dE = document.documentElement || document.body;

	return {
		scrollWidth: Math.max(dE.scrollWidth, dE.clientWidth),
		scrollHeight: Math.max(dE.scrollHeight, dE.clientHeight),
		innerWidth: window.innerWidth || (dE.offsetWidth - 2 * (dE.clientLeft || 0)),
		innerHeight: window.innerHeight || (dE.offsetHeight - 2 * (dE.clientTop || 0)),
		availWidth: dE.clientWidth,
		availHeight: dE.clientHeight,
		offsetX: window.pageXOffset || dE.scrollLeft,
		offsetY: window.pageYOffset || dE.scrollTop
	};
}

/**
 * This function sets the border of a form field to red if invalid. The form
 * item gets back it's original state when the field is correctly entered.
 */
function setBorder(control, valid)
{
    if (valid)
    {
		control.style.backgroundColor = '';
		control.style.color = '';
    }
    else
    {
		control.style.backgroundColor = '#b3d479';
		control.style.color = 'White';
    }
}

/**
 * This function shows or hides a given DIV layer with the corresponding message
 * when a field is not valid. If the form is validated again and the form item is
 * correctly checked it will remove the message.
 */
function ShowHide(id, message, visible) 
{
    obj = document.getElementsByTagName("div");
    if(visible)
    {
		obj[id].style.visibility = 'visible';
		obj[id].innerHTML = '';
		obj[id].innerHTML = message;    
    }
    else
    {
    	obj[id].style.visibility = 'hidden';
    }
}

/**
 * This function changes the label of any given form object. Be sure there is 
 * an ID given to the corresponding lable.
 */
function changeLabel(controlname, valid)
{
    obj = document.getElementById(controlname);
	if(!valid)
	{
		obj.style.color = '#78a22f';
	}
	else
	{	
		obj.style.color = '#828181';
	}
}

/**
 * Checks if the e-mail address given is a correct e-mail address. If not, it will notify.
 */
function isValidEmailAddress(address)
{
    var regex = new RegExp(/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i);
    
    return regex.test(address);
}

/**
 * Checks if the length of a given string is correct.
 */
function hasLengthWithin(text, minlength, maxlength)
{
    return ((text != null) && (text.length >= minlength) && (text.length <= maxlength))
}

/**
 * This function checks if the mailform is filled in correctly. If not it will display the output to the user.
 */
function checkMailForm(formulier)
{
	if(!hasLengthWithin(formulier.txtName.value, 2, 70))
	{
   	  changeLabel("testLabel", false);
	  setBorder(formulier.txtName, false);
	  return false;
	}
	else
	{
   	  changeLabel("testLabel", true);
	  setBorder(formulier.txtName, true);
	}
	
	if(!isValidEmailAddress(formulier.txtEmail.value))
	{
   	  changeLabel("emailLabel", false);
	  setBorder(formulier.txtEmail, false);
	  return false;
	}
	else
	{
	  changeLabel("emailLabel", true);
	  setBorder(formulier.txtEmail, true);
    }
	
	if(!hasLengthWithin(formulier.txtSubject.value, 2, 70))
	{
   	  changeLabel("subjectLabel", false);
	  setBorder(formulier.txtSubject, false);
	  return false;
	}
	else
	{
	  changeLabel("subjectLabel", true);
	  setBorder(formulier.txtSubject, true);
	}
}

/**
 * Preload a given image.
 */
function PreloadImage(imageurl)
{
    if(document.images)
    {
        var image = new Image(100, 200);
        image.src = "../images/" + imageurl;
    }
}
