function ResizeImageBackground(pnlid, pnlimageid, imageid, imageurl)
{
	var page = getPageDimensions();
	var pnl = document.getElementById(pnlid);	
	var pnlimage = document.getElementById(pnlimageid);
	var imglarge = document.getElementById(imageid);

	/// Set the background panel
	pnl.style.visibility = 'visible';
	pnl.style.height = page.scrollHeight + 'px';
	pnl.style.width = page.scrollWidth + 'px';
	
	/// Set the image panel
	pnlimage.style.top = (page.innerHeight/2)-300 + 'px';
	pnlimage.style.left = (page.innerWidth/2)-375 + 'px';
	
	/// Set the image
	imglarge.src = 'images/portfolio/' + imageurl;
}

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 = '';
    }
    else
    {
		control.style.backgroundColor = '#d37272';
    }
}

/**
 * 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))
}

/**
 * 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);
	  //ShowHide('errorDiv', 'De opgegeven naam is incorrect of is niet ingevoerd.', true);
	  return false;
	}
	else
	{
   	  changeLabel("testLabel", true);
	  setBorder(formulier.txtName, true);
   	  //ShowHide('errorDiv', '', false);
	}
	
	if(!isValidEmailAddress(formulier.txtEmail.value))
	{
   	  changeLabel("emailLabel", false);
	  setBorder(formulier.txtEmail, false);
	  //ShowHide('errorDiv', 'Het opgegeven e-mail adres is incorrect of niet ingevoerd.', true);
	  return false;
	}
	else
	{
	  changeLabel("emailLabel", true);
	  setBorder(formulier.txtEmail, true);
   	  //ShowHide('errorDiv', '', false);
	}
	
	if(!hasLengthWithin(formulier.txtSubject.value, 2, 70))
	{
   	  changeLabel("subjectLabel", false);
	  setBorder(formulier.txtSubject, false);
	  //ShowHide('errorDiv', 'Het opgegeven onderwerp is incorrect of niet ingevoerd.', true);
	  return false;
	}
	else
	{
	  changeLabel("subjectLabel", true);
	  setBorder(formulier.txtSubject, true);
   	  //ShowHide('errorDiv', '', false);
	}
}

/**
 * Preload a given image.
 */
function PreloadImage(imageurl)
{
    if(document.images)
    {
        var image = new Image(100, 200);
        image.src = "../images/" + imageurl;
    }
}
