var SITE_URL = "http://www.sharkconsoc.com";

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();

		
		//alert("called");
	       //Does the container Exists?!!1
		if(document.getElementById("contentarea"))
		{
			//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("contentarea").style.height = "";

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


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showin() { //v2.0
  window.open(''+SITE_URL+'/site_structure/richardpeirce/staticpages/booking-form.htm','BookingForm','width=600,height=600,scrollbars=yes,resizable=yes');
}

function showform() { //v2.0
  window.open('SharkCornwallBooking.htm','BookingForm','width=600,height=600,scrollbars=yes,resizable=yes');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function show(loc,copy){
picwin=window.open('','','toolbar=no,width=280,height=280')
var table='<br>'
var shown='<head></head><body bgcolor="#AAD2D5"><center><Title>Shark Cornwall Action</Title><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2"><img src="'+SITE_URL+'/images/sharkcornwall/largethumbnails/'+loc+'.jpg" border="2"></td></tr><tr><td align="left"><small><font face="Arial"><br></a></font></small></td><td align="right"><small><font face="Arial"><br><table border="0" cellpadding="1" cellspacing="0"><small>Photo Copyright 2006 '+copy+' </font></small><br><a href="javascript:self.close()"><img src="'+SITE_URL+'/images/buttons/close2.gif" alt="Close Window" align="right" border="0"></a></table></td></tr></table></center></body>'
picwin.document.write(shown);
}

function showcover(loc,copy,title){
picwin=window.open('','','toolbar=no,width=480,height=690, scrollbars=yes')
var table='<br>'
var shown='<head></head><body bgcolor="#AAD2D5"><center><Title>'+title+'</Title><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2"><img src="images/book/Large/'+loc+'.jpg" border="2"></td></tr><tr><td align="left"><small><font face="Arial"><br></a></font></small></td><td align="right"><small><font face="Arial"><br><table border="0" cellpadding="1" cellspacing="0"><small>Photo Copyright 2008 '+copy+' </font></small><br><a href="javascript:self.close()"><img src="'+SITE_URL+'/images/buttons/close2.gif" alt="Close Window" align="right" border="0"></a></table></td></tr></table></center></body>'
picwin.document.write(shown);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function checkShopItem(that)
{
	if (that.quantity.value>"")
	{
		if(!IsNumeric(that.quantity.value))
		{
			alert("Please correct the following errors and try again:\n\n- The quantity is not valid.");
			return false;
		}
	}
	else
	{
		alert("Please correct the following errors and try again:\n\n- The quantity is not valid.");
		return false;
	}
	
	return true;
}

function makeDonation(that)
{
	errcount = 0;
	message = "Please correct the following errors and try again:\n\n";
	if(that.payname.value == "")
	{
		errcount++;
		message += "- You must enter your name.\n";
	}
	if (that.quantity.value>"")
	{
		if(!IsNumeric(that.quantity.value))
		{
			errcount++;
			message += "- The payment amount is not valid.\n";
		}
	}
	else
	{
		errcount++;
		message += "- The payment amount is not valid.";
	}

	if(errcount > 0)
	{
		alert(message);
		return false;
	}
	else
	{
		return true;
	}
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

