var SITE_URL = "http://www.guitar-retreats.co.uk";

function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}



	if (navigator.appName == "Microsoft Internet Explorer")
		{yposition = document.body.scrollTop;}
	else {yposition = window.pageYOffset;}

	if (navigator.appName == "Microsoft Internet Explorer")
		{xposition = document.body.scrollLeft;}
	else {xposition = window.pageXOffset;}	

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, xposition, yposition);
	//alert(pageWidth +","+ pageHeight+","+windowWidth+","+windowHeight+","+xposition+","+yposition);
	return arrayPageSize;
}

function init() 
{
	if (arguments.callee.done) return;
	arguments.callee.done = true;

	      //DOM has now loaded!
	      //alert("hi");
	FullScreenContainer();

};

	/* for Mozilla */
if (document.addEventListener) 
{
	document.addEventListener("DOMContentLoaded", init, false);
}

	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
                document.write("<script defer src="+SITE_URL+"/ie_onload.js><"+"/script>");
        /*@end @*/

	/* for other browsers */
	window.onload = init;
	window.onresize = function()
	{
		FullScreenContainer();
	}

	function FullScreenContainer()
	{
		var arrSizes = getPageSize();

		
		
	       //Does the container Exists?!!1
		if(document.getElementById("pagecontainer"))
		{
			//Doe the height of the container equal less than the screen height.!!
//			document.title = "Screen "+arrSizes[3]+" Div Height "+document.getElementById("container").offsetHeight+"";
			//alert("Screen "+arrSizes[3]+" Div Height "+document.getElementById("pagecontainer").offsetHeight);

			//Clear height!
			document.getElementById("pagecontainer").style.height = "";

			if (document.getElementById("pagecontainer").offsetHeight<arrSizes[3])
			{
				//alert("Expand");
				document.getElementById("pagecontainer").style.height = ""+arrSizes[3]+"px";
				document.getElementById("page").style.height = ""+arrSizes[3]+"px";
				document.getElementById("contentarea").style.height = ""+arrSizes[3]+"px";
			}
		}
	}


//CONTACT PAGE RELATED JAVASCRIPT
/////////////////////////////////////

function validate_contact_form()
{
	errstr = "";
	errcount = 0;

	//Check name
	if(document.getElementById("contact_name").value.length < 1)
	{
		errstr += "You must enter a name before submitting the contact form\n";
		errcount++;
	}

	//Check that there is an email address or a telephone number
	email = document.getElementById("contact_email").value;
	phone = document.getElementById("contact_telephone").value;
	
	if((email.length < 1)&&(phone.length < 1))
	{
		errstr += "You must enter a contact email address or telephone number before submitting the contact form\n";
		errcount++;
	}
	else
	{
		if(email.length > 1)
		{
			if(!validEmail(email))
			{
				errstr += "You must enter a valid email address before submitting the contact form\n";
				errcount++;
			}
		}
	}

	//Check query text
	if(document.getElementById("contact_query").value.length < 1)
	{
		errstr += "You must enter some text in the query area before submitting the contact form\n";
		errcount++;
	}

	if(errcount == 0)
	{
		document.getElementById("contact_form").submit();
	}
	else
	{
		alert(errstr);
	}
}

function validEmail(email)
{
	var rPattern = "^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$";
	var re = new RegExp(rPattern);

	if (email.match(re)) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
}

