function SetContentPanel(contentpanelid, footerpanelid) 
{
	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);
    
	if (contentpanel.clientHeight > 400)
		footerpanel.style.top = (contentpanel.clientHeight + 350) + "px";
}

/**
 * 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 setBackgroundColor(control, valid)
{
    if (valid)
    {
		control.style.backgroundColor = '';
		control.style.color = '';
    }
    else
    {
		control.style.backgroundColor = '#b4e0fb';
		control.style.color = 'Black';
    }
}

/**
 * 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 = '#a13d3d';
	}
	else
	{	
		obj.style.color = 'black';
	}
}

/**
 * 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))
}

function checkEmail(formulier)
{
	if(!isValidEmailAddress(formulier.txtEmail.value))
	{
	  formulier.txtEmail.style.color = 'red';
	  return false;
	}
	else
	{
	  formulier.txtEmail.style.color = '#999999';
	}
}

/**
 * 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)) || (formulier.txtName.value == "Naam"))
	{
	  setBackgroundColor(formulier.txtName, false);
	  return false;
	}
	else
	{
	  setBackgroundColor(formulier.txtName, true);
	}
	
	if(!isValidEmailAddress(formulier.txtEmail.value))
	{
	  setBackgroundColor(formulier.txtEmail, false);
	  return false;
	}
	else
	{
	  setBackgroundColor(formulier.txtEmail, true);
	}
}

/**
 * Preload a given image.
 */
function PreloadImage(imageurl)
{
    if(document.images)
    {
        var image = new Image(100, 200);
        image.src = "../images/" + imageurl;
    }
}

/**
 * When a textbox has lost focus and is empty, set
 * a clarifiing text given in the text parameter.
 */
function TextBoxOnBlur(textbox, text)
{
    if(textbox.value == "")
    {
        textbox.style.color = "#666666";
        textbox.value = text;
    }    
}

/**
 * Clear the textbox if the text is equal to the text variable.
 */
function TextBoxOnFocus(textbox, text)
{
    if(textbox.value == text)
    {
        textbox.style.color = "";
        textbox.value = "";
    }    
}
