function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless){ //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function mapButton()
{
	GP_AdvOpenWindow('map.html','mapit','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',690,610,'center','ignoreLink','',0,'');
}

function closeWindow()
{
	window.close()
}

function footballButton()
{
	GP_AdvOpenWindow('football.html','football','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',796,488,'center','ignoreLink','',0,'');
}

// JavaScript Document

function checkContactForm()
{
	//check required fields first
	if(checkDataEntry(document.frmData.strContactName.value)==0)
	{
		alert("Please enter your Contact Name");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if(checkDataEntry(e)==0)
	{
		alert("Please enter your eMail Address");
		return false;
	}
	else
	{
		if (checkEmailValid(e)!="0") 
		{
			alert(checkEmailValid(e,'Your'));
			return false;	
		}
	}
	if(checkDataEntry(document.frmData.strMessage.value)==0)
	{
		alert("Please enter your Message");
		return false;
	}
	var c=document.frmData.strContactName.value;
	var p=document.frmData.strTelephone.value;
	var m=document.frmData.strMessage.value;
	
	//if we got here then all data is valid
	
	var tgt= document.getElementById('contcontainer');
	
	tgt.innerHTML="<p><br /><br />&nbsp;&nbsp;&nbsp;<img src='images/ajax-loader.gif' alt=' processing ajax ' align='absmiddle' />&nbsp;Processing your request...</p>";
	var doc = null; 
 
	// Make a new XMLHttp object
	if (typeof window.ActiveXObject != 'undefined' ) 
   { 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
   } 
   else 
   { 
	   doc = new XMLHttpRequest(); 
	
   } 
  
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	doc.open("GET", "processcontacts.asp?c="+c+"&e="+e+"&p="+p+"&m="+m, true);
	doc.send(null);
	
	function handleStateChange()
	{        
		if (doc.readyState == 4)
		{
			tgt.innerHTML=doc.responseText
			//needs a return false to make it work for safari
		return false;
		}
	}	
}

function checkDataEntry(obj)
{
	var mycode
	var count=0;
	if(obj.length!=0)
	{
		for(i=0; i<obj.length; i++)
		{
			mycode = obj.charCodeAt(i);
			if((mycode>47 && mycode<58) || (mycode>64 && mycode<91) || (mycode>96 && mycode<123) || (mycode>3584 && mycode<3631) || (mycode>3647 && mycode<3653))
			{
				count=count+1;
			}
		}
	}
	return count;
}

function checkEmailValid(emailStr,msg)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var errMsg="";   
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
	   errMsg=errMsg+msg+" eMail Address seems incorrect";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {
		errMsg=errMsg+msg+" eMail Address seems incorrect";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+msg+" eMail Address seems incorrect";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+msg+" eMail Address seems incorrect";
		 return errMsg;
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	   {
		 errMsg=errMsg+msg+" eMail Address seems incorrect";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+msg+" eMail Address seems incorrect";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

