function MM_reloadPage(init)
{ //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function MM_displayStatusMsg(msgStr)
{ 
  status=msgStr;
  document.MM_returnValue = true;
}


function pop_Window(theURL,winName,features)
{ 
  window.open(theURL,winName,features);
}


function MM_preloadImages()
{
  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 opennew(img,x,y)
{
  if (screen.width > 800)
  {
  openpage(img,x,y);
  }
  if (screen.width <= 800)
  {
  openplain(img,x,y);
  }
}

function openplain(img,x,y)
{
  var winLeft = ((screen.width/2)-(x/2))
  var msgWindow = window.open('','','Width=' + x + ',Height=' + y + ',top=0,screenX=0,left=' + winLeft + ',screenY=' + winLeft + '');
  var page='<IMG SRC=\"' + img + '\">';
  msgWindow.document.open();
  msgWindow.document.write('<HTML><HEAD><TITLE>Team GTM Image Gallery</TITLE></HEAD>')
  msgWindow.document.write('<BODY LEFTMARGIN=\"0\" TOPMARGIN=\"0\" MARGINWIDTH=\"0\" MARGINHEIGHT=\"0\">')
  msgWindow.document.write(page);
  msgWindow.document.write('</BODY></HTML>')
  msgWindow.document.close();
}

function openpage(img,x,y)
{
  x = x + 100
  if (x < 600)
  {
  x = 600
  }
  y = y + 120;
  var winLeft = ((screen.width/2)-(x/2));
  var msgWindow = window.open('','','Width=' + x + ',Height=' + y + ',top=0,screenX=0,left=' + winLeft + ',screenY=' + winLeft + '');
  var page='<IMG SRC=\"' + img + '\">';
  msgWindow.document.open();
  msgWindow.document.write('<HTML><HEAD><TITLE>Team GTM Image Gallery</TITLE></HEAD>')
  msgWindow.document.write('<BODY BGCOLOR=\"#000033\" LEFTMARGIN=\"0\" TOPMARGIN=\"0\" MARGINWIDTH=\"0\" MARGINHEIGHT=\"0\">')
  msgWindow.document.write('<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"25\" align=\"center\">')
  msgWindow.document.write('<tr><td></td></tr></table>')
  msgWindow.document.write('<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr>')
  msgWindow.document.write('<td height=\"15\"><img src=\"/images/picturegalleryheader.gif\" width=\"500\" height=\"15\" border=\"0\"></td></tr>')
  msgWindow.document.write('<tr><td height=\"25\"></td></tr>')
  msgWindow.document.write('<tr><td align=\"center\" valign=\"top\">')
  msgWindow.document.write(page);
  msgWindow.document.write('</td></tr><tr><td height=\"25\"></td></tr>')
  msgWindow.document.write('<tr><td height=\"13\" align=\"center\"><a href=\"javascript:window.close()\">Close Window</a></td></tr>')
  msgWindow.document.write('</table></BODY></HTML>')
  msgWindow.document.close();
}

function validate_request()
{
  var accepted = ('true');

  if (document.request.password.value == '')
  {
    accepted = 'false';
  }   
  if (document.request.confpassword.value == '')
  {
    accepted = 'false';
  }   
  if (document.request.postcode.value == '')
  {
    accepted = 'false';
  }   
  if (document.request.email.value == '')
  {
    accepted = 'false';
  }
  if (document.request.vehicle.value == '0')
  {
    accepted = 'false';
  }   
  if (document.request.engine.value == '0')
  {
    accepted = 'false';
  }

  if (accepted == 'false')
  {alert('One or more required fields (red) are blank'); return false;} else	

  if (document.request.password.value != document.request.confpassword.value)
  {alert('Your password does not match your confirmation password'); return false;} else

  if (document.request.password.value.length < 6)
  {alert('Your password must be at least 6 characters long'); return false;} else

  // allow ONLY alphanumeric keys, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var checkStr = document.request.username.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
  ch = checkStr.charAt(i);
  for (j = 0;  j < checkOK.length;  j++)
  if (ch == checkOK.charAt(j))
  break;
  if (j == checkOK.length)
  {
  allValid = false;
  break;
  }
  }
  if (!allValid)
  {
  alert("Please enter only letter and numeric characters in the \"Username\" field."); return (false);} else

  // allow ONLY alphanumeric keys, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
  var checkStr = document.request.password.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
  ch = checkStr.charAt(i);
  for (j = 0;  j < checkOK.length;  j++)
  if (ch == checkOK.charAt(j))
  break;
  if (j == checkOK.length)
  {
  allValid = false;
  break;
  }
  }
  if (!allValid)
  {
  alert("Please enter only letter and numeric characters in the \"Password\" field."); return (false);} else

  // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = document.request.email.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
  ch = checkStr.charAt(i);
  for (j = 0;  j < checkEmail.length;  j++)
  {
  if (ch == checkEmail.charAt(j) && ch == "@")
  EmailAt = true;
  if (ch == checkEmail.charAt(j) && ch == ".")
  EmailPeriod = true;
   	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
  if (EmailAt && EmailPeriod)
  {
		EmailValid = true
		break;
	}
  }
  if (!EmailValid)
  {
  alert("The \"email\" field must contain an \"@\" and a \".\"."); return (false);} else

  if (accepted == 'true') 
  {return true}

}


function Right(str, n)
/***
IN: str - the string we are RIGHTing
n - the number of characters we want to return
RETVAL: n characters from the right side of the string
***/
{
if (n <= 0)     // Invalid bound, return blank string
return "";
else if (n > String(str).length)   // Invalid bound, return
return str;                     // entire string
else { // Valid bound, return appropriate substring
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}

function validate_submitphoto()
{
  var accepted = ('true');
  var mycheck1 = Right(document.submitphoto.file1.value, 3);

  if (document.submitphoto.file1.value == '')
  {
    accepted = 'false';
  }
  
  if (accepted == 'true') 
  {
	alert('The transfer will start when you click Ok and may take several minutes');
	return true;
  }
	else
  {
  alert('You must select a photograph to transfer!');
  return false;
  }	
}

function setcookie(name,value,duration)
{
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	document.cookie=cookiestring;
	if(!getcookie(name))
	{
		return false;
	}
	else
	{
	return true;
	}
}


function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}


function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}



function validate_logon()
{
 	document.logon.hiddencheck.value = "False";

	if (document.logon.memchecked.checked == true)
	{
 	document.logon.hiddencheck.value = "True";
	}
	return true;
}

function validate_groupemail()
{
 	var accepted = ('true');
	if (document.groupemail.subject.value == '')
	{
	accepted = 'false';
	}
	
 	if (accepted == 'false') 
    	{
  	alert('Please enter a subject');
   	}

	if (accepted == 'true')
	{
	if (document.groupemail.bodytext.value == '')
		{
  		alert('You must type a message!');
		accepted = 'false';
		}
	}


  	if (accepted == 'true') 
	{return true}
	else
	{return false;}
}



function validate_booktrack()
{
  var accepted = ('true');

  if (document.booktrack.name.value == '')
  {
    accepted = 'false';
  }   
  if (document.booktrack.email.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.telnumber.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.make.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.model.value == '')
  {
    accepted = 'false';
  }   
  if (document.booktrack.engine.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.colour.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.addr1.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.addr2.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.addr3.value == '')
  {
    accepted = 'false';
  }
  if (document.booktrack.postcode.value == '')
  {
    accepted = 'false';
  }

  if (accepted == 'false')
  {
	alert('One or more required fields are blank');
	return false;
  } 
  else	
  {


  // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = document.booktrack.email.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
  ch = checkStr.charAt(i);
  for (j = 0;  j < checkEmail.length;  j++)
  {
  if (ch == checkEmail.charAt(j) && ch == "@")
  EmailAt = true;
  if (ch == checkEmail.charAt(j) && ch == ".")
  EmailPeriod = true;
   	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
  if (EmailAt && EmailPeriod)
  {
		EmailValid = true
		break;
	}
  }
  }

  if (!EmailValid)
  {
  alert("You must enter a valid email address");
  return false;
  }
  else
  {
  setcookie("tdbookTrackdayID", document.booktrack.TrackDayID.value, 365);
  setcookie("tdbookFullName", document.booktrack.name.value, 365);
  setcookie("tdbookEmail", document.booktrack.email.value, 365);
  setcookie("tdbookTelNumber", document.booktrack.telnumber.value, 365);
  setcookie("tdbookCarMake", document.booktrack.make.value, 365);
  setcookie("tdbookCarModel", document.booktrack.model.value, 365);
  setcookie("tdbookCarEngine", document.booktrack.engine.value, 365);
  setcookie("tdbookCarColour", document.booktrack.colour.value, 365);
  setcookie("tdbookAddress1", document.booktrack.addr1.value, 365);
  setcookie("tdbookAddress2", document.booktrack.addr2.value, 365);
  setcookie("tdbookAddress3", document.booktrack.addr3.value, 365);
  setcookie("tdbookPostCode", document.booktrack.postcode.value, 365);

  alert("Remember to click PayPals 'Continue' button after completing your payment !!!");
  return true
  }
}
