
function locationReplace()
{
	//parent.location.replace("default.asp");
	if (parent.frames.length > 0 && !parent.loader)
	{
		//parent.location.href = self.document.location
		parent.location.replace(self.document.location);
	}
}

//megan 12 Aug 2003, format to a currecny value
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
		//return (((sign)?'':'-') + '$' + num + '.' + cents);
		return (((sign)?'':'-') + num );
}




//
// 4 Image rollover functions:
//

	function swapImgRestore() { //v3.0
	  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.p) d.p=new Array();
	    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
	}

	function 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=findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function swapImage() { //v3.0
	  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}


//
// Function to create popup Windows:
//

	function openWindow(url,name,scroll,width,height,top,left) 
	{
	  var objWin = window.open(url,name, 'scrollbars='+scroll+',width='+width+',height='+height+',top='+top+',left='+left)
	  objWin.focus();
	  return objWin;
	}
	
	function openWindowWithStatus(url,name,scroll,width,height,top,left) 
	{
	  var objWin = window.open(url,name, 'status=1, scrollbars='+scroll+',width='+width+',height='+height+',top='+top+',left='+left)
	  objWin.focus();
	  return objWin;
	}

//_------------------------_------------------------_------------------------
	function openNewWindow(theURL,winName,features) 
	{ //v2.0
	  var objWin = window.open(theURL,winName,features);
	  objWin.focus();
	  return objWin;
	  
	}
//_------------------------_------------------------_------------------------
//
// Breadcrumb Trail functions:
//

	function setCookie(name, value, expires, path, domain, secure)
		// name - name of the cookie
		// value - value of the cookie
		// [expires] - expiration date of the cookie
		// (defaults to end of current session)
		// [path] - path for which the cookie is valid
		// (defaults to path of calling document)
		// [domain] - domain for which the cookie is valid
		// (defaults to domain of calling document)
		// [secure] - Boolean value indicating if
		// the cookie transmission requires a secure transmission
		// * an argument defaults when it is assigned null as a placeholder
		// * a null placeholder is not required for trailing omitted arguments
		{
		var caution = false
		
		if (value != null)
			{
			var curCookie = name + "=" + escape(value) +
			  ((expires) ? "; expires=" + expires.toGMTString() : "") +
			  ((path) ? "; path=" + path : "") +
			  ((domain) ? "; domain=" + domain : "") +
			  ((secure) ? "; secure" : "")
			if (!caution || (name + "=" + escape(value)).length <= 4000)
			  document.cookie = curCookie
			else
			  if (confirm("Cookie exceeds 4KB and will be cut!"))
			    document.cookie = curCookie
			}
		}

	function getCookie(name)
		// name - name of the cookie
		// * return string containing value
		// of specified cookie or null if cookie
		// does not exist
		{
	  var prefix = name + "="
	  var cookieStartIndex = document.cookie.indexOf(prefix)
	  if (cookieStartIndex == -1)
			return null
	  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	  if (cookieEndIndex == -1)
			cookieEndIndex = document.cookie.length
	  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
		}

	function fixDate(date)
		// date - any instance of the Date object
		// * you should hand all instances of the
		// Date object to this function for "repairs"
		// * this function is taken from
		// Chapter 14, "Time and Date in JavaScript", in
		// "Learn Advanced JavaScript Programming"
		{
		var base = new Date(0)
		var skew = base.getTime()
		if (skew > 0)
		  date.setTime(date.getTime() - skew)
		}


	function window_onload() {	
		if(top.loader) return true;
		var dtNow = new Date()
		fixDate(dtNow)
		dtNow.setTime(dtNow.getTime() + 3600000)
		
		var sURL = window.top.location.href
		var cookieEndIndex = sURL.indexOf("&c=")
		if (cookieEndIndex != -1)
			{
			sURL = sURL.substring(0, cookieEndIndex)
			
			}
		
		var sNewCookie = sURL + ';' + sPageTitle // Replaces document.title
		var sCookie = getCookie("p0")
					
		//Only add to trail if current page different to previous page:
		if (sNewCookie != sCookie)
			{
			setCookie("p4", getCookie("p3"), dtNow, "/")			
			setCookie("p3", getCookie("p2"), dtNow, "/")
			setCookie("p2", getCookie("p1"), dtNow, "/")
			setCookie("p1", sCookie, dtNow, "/")
			setCookie("p0", sNewCookie, dtNow, "/")
			}	
	}

	function showLink(sPage)
		{
		var sCookie, i, sURL, sTitle
		sCookie = getCookie(sPage)
		if (sCookie != null)
			{
			i = sCookie.lastIndexOf(';')
			sURL = sCookie.substring(0, i)
			sTitle = sCookie.substring(i + 1, sCookie.length)
			document.write ('<a href="' + sURL + '" target="_top" class="breadcrumbs">' + sTitle + '</a><span class="breadcrumbs">:&#160; </span>')
			}
		}


//-->
function isEmpty(variable)
{
	//** Test whether variable is Empty (which includes containing nothing but blanks)

  if (variable == null || variable == "" || variable == " ")
    return true;
  // Test for all characters being blanks
  for (i = 0; i < variable.length; i++)
  {
    if (variable.charAt(i) != " ")
      return false;
  }
  return true;  // No non-blank characters found
}


	function isEmailAddress(strEmailAddress)
	{
		// PURPOSE: Test whether or not strEmailAddress is a valid eMail address
		
		// Check for value not entered
		if (strEmailAddress.length == 0)
	    return false;

		if (strEmailAddress.indexOf(" ") != -1)
		  return false;

		// Check that address is in format anyname@domain.level
		var oRegExp2 = /\w+\@(\w[\w-]*\w)+\.\w+/;
		if (!oRegExp2.test(strEmailAddress))
	    return false;
		
		// Check that there is one and only one @ sign
		var oRegExp = new RegExp("@","g");
		var oMatches = strEmailAddress.match(oRegExp);
		if (oMatches.length != 1)
	    return false;
		
		// No errors found
		return true;
	}
	
	function replaceChars(entry, out, add)
	{
		//out = "a"; // replace this
		//add = "z"; // with this
		temp = "" + entry; // temporary holder

		while (temp.indexOf(out)>-1)
		{
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add + 
			temp.substring((pos + out.length), temp.length));
		}
		return temp;
	}
	
	function ValidateLogin()
	{
		if(document.forms[0].txtUS_EmailAddress_Login.value == '')
		{
			alert('Please enter your email address');
			document.forms[0].txtUS_EmailAddress_Login.focus();
			return;
		}
		
		if(!isEmailAddress(document.forms[0].txtUS_EmailAddress_Login.value))
		{
			alert('Please enter a valid email address');
			document.forms[0].txtUS_EmailAddress_Login.focus();
			document.forms[0].txtUS_EmailAddress_Login.select();
			return;
		}
		if(document.forms[0].txtUS_Password.value == '')
		{
			alert('Please enter your password');
			document.forms[0].txtUS_Password.focus();
			return;
		}
		document.forms[0].txtAction.value = "LOGIN";
		document.forms[0].submit();
	}
	
	function ValidateForgottenPassword()
	{
		if(document.forms[0].txtUS_EmailAddress_ForgottenPassword.value == '')
		{
			alert('Please enter your email address');
			document.forms[0].txtUS_EmailAddress_ForgottenPassword.focus();
			return;
		}
		if(!isEmailAddress(document.forms[0].txtUS_EmailAddress_ForgottenPassword.value))
		{
			alert('Please enter a valid email address');
			document.forms[0].txtUS_EmailAddress_ForgottenPassword.focus();
			document.forms[0].txtUS_EmailAddress_ForgottenPassword.select();
			return;
		}		
		document.forms[0].txtAction.value = "FORGOTTEN_PASSWORD";
		document.forms[0].submit();	
	}


//===================================
	function SubmitPlaceUsedCarAd(intLoggedOn)
	{
		//intLoggedOn: Indicates whether an existing profile is being updated OR a new one is being created
		
		if(!isEmailAddress(document.forms[0].txtUS_EmailAddress.value))
		{
			alert('Please enter a valid email address');
			document.forms[0].txtUS_EmailAddress.focus();
			document.forms[0].txtUS_EmailAddress.select();
			return;
		}
		
		if(intLoggedOn == 0)
		{
			if(document.forms[0].txtUS_Password.value == '')
			{
				alert('Please enter your Password');
				document.forms[0].txtUS_Password.focus();
				return;
			}
			if(document.forms[0].txtUS_Password_Confirm.value == '')
			{
				alert('Please confirm your Password');
				document.frmRegister.txtUS_Password_Confirm.focus();
				return;
			}
		}
		
		if(document.forms[0].cboTI_ID.options[document.forms[0].cboTI_ID.selectedIndex].value == 0)
		{
			alert('Please select a Title');
			document.frmRegister.cboTI_ID.focus();
			return;
		}
		if(document.forms[0].txtUS_FirstName.value == '')
		{
			alert('Please enter your First name');
			document.forms[0].txtUS_FirstName.focus();
			return;
		}
		if(document.forms[0].txtUS_LastName.value == '')
		{
			alert('Please enter your Surname');
			document.forms[0].txtUS_LastName.focus();
			return;
		}
		
		if(document.forms[0].txtUS_TelephoneDay.value == '')
		{
			alert('Please enter your day telephone number');
			document.forms[0].txtUS_TelephoneDay.focus();
			return;
		}
		
		if(document.forms[0].txtUS_AddressLine1.value == '')
		{
			alert('Please enter your Address Line 1');
			document.forms[0].txtUS_AddressLine1.focus();
			return;
		}
		
		/* Not required
		if(document.forms[0].txtUS_AddressLine2.value == '')
		{
			alert('Please enter your Address Line 2');
			document.forms[0].txtUS_AddressLine2.focus();
			return;
		}
		if(document.forms[0].txtUS_AddressLine3.value == '')
		{
			alert('Please enter your Address Line 3');
			document.forms[0].txtUS_AddressLine3.focus();
			return;
		}
		if(document.forms[0].txtUS_Town.value == '')
		{
			alert('Please enter your Town');
			document.forms[0].txtUS_Town.focus();
			return;
		}
		*/
		
		if(document.forms[0].txtUS_PostCode.value == '')
		{
			alert('Please enter your Postcode');
			document.forms[0].txtUS_PostCode.focus();
			return;
		}
		
		/*
		if(document.forms[0].txtUS_County.value == '')
		{
			alert('Please enter your County');
			document.forms[0].txtUS_County.focus();
			return;
		}
		*/
		
		if(document.forms[0].cboCT_ID.options[document.forms[0].cboCT_ID.selectedIndex].value == 0)
		{
			alert('Please select your Country');
			document.forms[0].cboCT_ID.focus();
			return;
		}	
			
		/*
		if(document.forms[0].cboAR_ID.options[document.forms[0].cboAR_ID.selectedIndex].value == 0)
		{
			alert('Please select your Age range');
			document.forms[0].cboAR_ID.focus();
			return;
		}
		*/
		document.forms[0].txtAlreadyLoggedOn.value = intLoggedOn;
		
		
		if(intLoggedOn == 0)
		{
			document.forms[0].txtAction.value = 'REGISTER';
		}
		else
		{
			
			document.forms[0].txtAction.value = 'PLACE_AD_AND_REGISTER';
			
		}
		document.forms[0].submit();
	}
	//=========================================

	function SubmitBookATestDrive(intLoggedOn)
	{
		//intLoggedOn: Indicates whether an existing profile is being updated OR a new one is being created
		
		if(!isEmailAddress(document.frmRegister.txtUS_EmailAddress.value))
		{
			alert('Please enter a valid email address');
			document.frmRegister.txtUS_EmailAddress.focus();
			document.frmRegister.txtUS_EmailAddress.select();
			return;
		}
		
		if(intLoggedOn == 0)
		{
			if(document.frmRegister.txtUS_Password.value == '')
			{
				alert('Please enter your Password');
				document.frmRegister.txtUS_Password.focus();
				return;
			}
			if(document.frmRegister.txtUS_Password_Confirm.value == '')
			{
				alert('Please confirm your Password');
				document.frmRegister.txtUS_Password_Confirm.focus();
				return;
			}
		}
		/*
		if(intLoggedOn != 0)
		{
			if(document.frmRegister.txtUS_Password.value != '')
			{
				if(document.frmRegister.txtUS_Password_Confirm.value == '')
				{
					alert('Please confirm your Password');
					document.frmRegister.txtUS_Password_Confirm.focus();
					return;
				}
				if(document.frmRegister.txtUS_Password_Current.value == '')
				{
					alert('Please enter your existing password');
					document.frmRegister.txtUS_Password_Current.focus();
					document.frmRegister.txtUS_Password_Current.select();
					return;
				}
			}
		}
			
		if(document.frmRegister.txtUS_Password_Confirm.value != document.frmRegister.txtUS_Password.value)
		{
			alert("Passwords don't match.  Please re-enter.");
			document.frmRegister.txtUS_Password.focus();
			return;
		}
*/
		if(document.frmRegister.cboTI_ID.options[document.frmRegister.cboTI_ID.selectedIndex].value == 0)
		{
			alert('Please select a Title');
			document.frmRegister.cboTI_ID.focus();
			return;
		}
		if(document.frmRegister.txtUS_FirstName.value == '')
		{
			alert('Please enter your First name');
			document.frmRegister.txtUS_FirstName.focus();
			return;
		}
		if(document.frmRegister.txtUS_LastName.value == '')
		{
			alert('Please enter your Surname');
			document.frmRegister.txtUS_LastName.focus();
			return;
		}
		if(document.frmRegister.txtUS_AddressLine1.value == '')
		{
			alert('Please enter your Address');
			document.frmRegister.txtUS_AddressLine1.focus();
			return;
		}
		if(document.frmRegister.txtUS_AddressLine2.value == '')
		{
			alert('Please enter your Address');
			document.frmRegister.txtUS_AddressLine2.focus();
			return;
		}
		if(document.frmRegister.txtUS_AddressLine3.value == '')
		{
			alert('Please enter your Address');
			document.frmRegister.txtUS_AddressLine3.focus();
			return;
		}
		if(document.frmRegister.txtUS_Town.value == '')
		{
			alert('Please enter your Town');
			document.frmRegister.txtUS_Town.focus();
			return;
		}
		if(document.frmRegister.txtUS_PostCode.value == '')
		{
			alert('Please enter your Postcode');
			document.frmRegister.txtUS_PostCode.focus();
			return;
		}
		if(document.frmRegister.txtUS_County.value == '')
		{
			alert('Please enter your County');
			document.frmRegister.txtUS_County.focus();
			return;
		}
		if(document.frmRegister.cboCT_ID.options[document.frmRegister.cboCT_ID.selectedIndex].value == 0)
		{
			alert('Please select your Country');
			document.frmRegister.cboCT_ID.focus();
			return;
		}		
		
		if(document.frmRegister.cboAR_ID.options[document.frmRegister.cboAR_ID.selectedIndex].value == 0)
		{
			alert('Please select your Age range');
			document.frmRegister.cboAR_ID.focus();
			return;
		}

		document.frmRegister.txtAlreadyLoggedOn.value = intLoggedOn;
		if(intLoggedOn == 0)
		{
			document.frmRegister.txtAction.value = 'REGISTER';
		}
		{
			document.frmRegister.txtAction.value = 'CONFIRM_BOOKING';
		}
		document.frmRegister.submit();
	}
	
	function SubmitRegisterForm(intLoggedOn)
	{
		//intLoggedOn: Indicates whether an existing profile is being updated OR a new one is being created
		
		if(!isEmailAddress(document.frmRegister.txtUS_EmailAddress.value))
		{
			alert('Please enter a valid email address');
			document.frmRegister.txtUS_EmailAddress.focus();
			document.frmRegister.txtUS_EmailAddress.select();
			return false;
		}
		
		if(intLoggedOn == 0)
		{
			if(document.frmRegister.txtUS_Password.value == '')
			{
				alert('Please enter your Password');
				document.frmRegister.txtUS_Password.focus();
				return false;
			}
			if(document.frmRegister.txtUS_Password_Confirm.value == '')
			{
				alert('Please confirm your Password');
				document.frmRegister.txtUS_Password_Confirm.focus();
				return false;
			}
		}

		if(intLoggedOn != 0)
		{
			if(document.frmRegister.txtUS_Password.value != '')
			{
				if(document.frmRegister.txtUS_Password_Confirm.value == '')
				{
					alert('Please confirm your Password');
					document.frmRegister.txtUS_Password_Confirm.focus();
					return false;
				}
				if(document.frmRegister.txtUS_Password_Current.value == '')
				{
					alert('Please enter your existing password');
					document.frmRegister.txtUS_Password_Current.focus();
					document.frmRegister.txtUS_Password_Current.select();
					return false;
				}
			}
		}		
		if(document.frmRegister.txtUS_Password_Confirm.value != document.frmRegister.txtUS_Password.value)
		{
			alert("Passwords don't match.  Please re-enter.");
			document.frmRegister.txtUS_Password.focus();
			return false;
		}

		if(document.frmRegister.cboTI_ID.options[document.frmRegister.cboTI_ID.selectedIndex].value == 0)
		{
			alert('Please select a Title');
			document.frmRegister.cboTI_ID.focus();
			return false;
		}
		if(document.frmRegister.txtUS_FirstName.value == '')
		{
			alert('Please enter your First name');
			document.frmRegister.txtUS_FirstName.focus();
			return false;
		}
		if(document.frmRegister.txtUS_LastName.value == '')
		{
			alert('Please enter your Surname');
			document.frmRegister.txtUS_LastName.focus();
			return false;
		}
		if(document.frmRegister.txtUS_AddressLine1.value == '')
		{
			alert('Please enter your Address Line 1');
			document.frmRegister.txtUS_AddressLine1.focus();
			return false;
		}
		/*
		if(document.frmRegister.txtUS_AddressLine2.value == '')
		{
			alert('Please enter your Address Line 2');
			document.frmRegister.txtUS_AddressLine2.focus();
			return false;
		}
		if(document.frmRegister.txtUS_AddressLine3.value == '')
		{
			alert('Please enter your Address Line 3');
			document.frmRegister.txtUS_AddressLine3.focus();
			return false;
		}
		if(document.frmRegister.txtUS_Town.value == '')
		{
			alert('Please enter your Town');
			document.frmRegister.txtUS_Town.focus();
			return false;
		}
		*/
		if(document.frmRegister.txtUS_PostCode.value == '')
		{
			alert('Please enter your Postcode');
			document.frmRegister.txtUS_PostCode.focus();
			return false;
		}
		/*
		if(document.frmRegister.txtUS_County.value == '')
		{
			alert('Please enter your County');
			document.frmRegister.txtUS_County.focus();
			return false;
		}
		*/
		if(document.frmRegister.cboCT_ID.options[document.frmRegister.cboCT_ID.selectedIndex].value == 0)
		{
			alert('Please select your Country');
			document.frmRegister.cboCT_ID.focus();
			return false;
		}
		/*
		if(document.frmRegister.cboAR_ID.options[document.frmRegister.cboAR_ID.selectedIndex].value == 0)
		{
			alert('Please select your Age range');
			document.frmRegister.cboAR_ID.focus();
			return false;
		}
		*/

		if(document.frmRegister.txtUS_1stCar_ChangeDate.value != '')
		{
			if(!dateCheck(document.frmRegister.txtUS_1stCar_ChangeDate.value, '%dd/%mm/%yyyy'))
			{
				document.frmRegister.txtUS_1stCar_ChangeDate.focus();
				document.frmRegister.txtUS_1stCar_ChangeDate.select();
				return false;
			}
		}		
		if(document.frmRegister.txtUS_2ndCar_ChangeDate.value != '')
		{
			if(!dateCheck(document.frmRegister.txtUS_2ndCar_ChangeDate.value, '%dd/%mm/%yyyy'))
			{
				document.frmRegister.txtUS_2ndCar_ChangeDate.focus();
				document.frmRegister.txtUS_2ndCar_ChangeDate.select();
				return false;
			}
		}
				
		document.frmRegister.txtAction.value = 'SAVE';
		document.frmRegister.submit();
	}
	
	
	
	//Ad free Subscription - close window and refresh opener window
	function closewindow()
	{
		if (window.confirm("Close this window and surf to the ad free WhatCar? online."))
		{
			window.opener.location = "../default.asp"
			window.self.close();
			//document.frmRegister.submit();

		}
		return;
		
	}

//for tickets	

function SubmitBuyTicket(intLoggedOn)
	{
		//intLoggedOn: Indicates whether an existing profile is being updated OR a new one is being created
		
		if(!isEmailAddress(document.forms[0].txtUS_EmailAddress.value))
		{
			alert('Please enter a valid email address');
			document.forms[0].txtUS_EmailAddress.focus();
			document.forms[0].txtUS_EmailAddress.select();
			return;
		}
		
		if(intLoggedOn == 0)
		{
			if(document.forms[0].txtUS_Password.value == '')
			{
				alert('Please enter your Password');
				document.forms[0].txtUS_Password.focus();
				return;
			}
			if(document.forms[0].txtUS_Password_Confirm.value == '')
			{
				alert('Please confirm your Password');
				document.frmRegister.txtUS_Password_Confirm.focus();
				return;
			}
		}
		
		if(document.forms[0].cboTI_ID.options[document.forms[0].cboTI_ID.selectedIndex].value == 0)
		{
			alert('Please select a Title');
			document.frmRegister.cboTI_ID.focus();
			return;
		}
		if(document.forms[0].txtUS_FirstName.value == '')
		{
			alert('Please enter your First name');
			document.forms[0].txtUS_FirstName.focus();
			return;
		}
		if(document.forms[0].txtUS_LastName.value == '')
		{
			alert('Please enter your Surname');
			document.forms[0].txtUS_LastName.focus();
			return;
		}
		
		if(document.forms[0].txtUS_TelephoneDay.value == '')
		{
			alert('Please enter your day telephone number');
			document.forms[0].txtUS_TelephoneDay.focus();
			return;
		}
		
		if(document.forms[0].txtUS_AddressLine1.value == '')
		{
			alert('Please enter your Address Line 1');
			document.forms[0].txtUS_AddressLine1.focus();
			return;
		}
		
		/* Not required
		if(document.forms[0].txtUS_AddressLine2.value == '')
		{
			alert('Please enter your Address Line 2');
			document.forms[0].txtUS_AddressLine2.focus();
			return;
		}
		if(document.forms[0].txtUS_AddressLine3.value == '')
		{
			alert('Please enter your Address Line 3');
			document.forms[0].txtUS_AddressLine3.focus();
			return;
		}
		if(document.forms[0].txtUS_Town.value == '')
		{
			alert('Please enter your Town');
			document.forms[0].txtUS_Town.focus();
			return;
		}
		*/
		
		if(document.forms[0].txtUS_PostCode.value == '')
		{
			alert('Please enter your Postcode');
			document.forms[0].txtUS_PostCode.focus();
			return;
		}
		
		/*
		if(document.forms[0].txtUS_County.value == '')
		{
			alert('Please enter your County');
			document.forms[0].txtUS_County.focus();
			return;
		}
		*/
		
		if(document.forms[0].cboCT_ID.options[document.forms[0].cboCT_ID.selectedIndex].value == 0)
		{
			alert('Please select your Country');
			document.forms[0].cboCT_ID.focus();
			return;
		}	
		
		if(document.forms[0].txtDOB.value == '')
		{
			alert('Please enter your D.O.B');
			document.forms[0].txtDOB.focus();
			return;
		}	
		if(document.forms[0].txtDOB.value != '')
		{
			if(!dateCheck(document.forms[0].txtDOB.value, '%dd/%mm/%yyyy'))
			{
				document.forms[0].txtDOB.focus();
				document.forms[0].txtDOB.select();
				return;
			}
		}
		
		document.forms[0].txtAlreadyLoggedOn.value = intLoggedOn;
		
		
		if(intLoggedOn == 0)
		{
			document.forms[0].txtAction.value = 'REGISTER';
		}
		else
		{
			
			document.forms[0].txtAction.value = 'PLACE_AD_AND_REGISTER';
			
		}
		document.forms[0].submit();
	}
	//=========================================

	

// whitespace characters
var whitespace = " \t\n\r";

/****************************************************************/
function trim_string(strValue) {
	var ichar, icount;
	//var strValue = this;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	return strValue;
}

function openTrackDayEventDetail(intTD_ID)
{
	var objWin = openWindow("popups/trackdaydiary_event.asp?id=" + intTD_ID, 'trackday','yes',530,550,10,10);
	objWin.focus();
	return;
}

function openTrackDayApplyOnline(intTD_ID, strFrom)
{
	// strFrom: popup = called from a page inside the popup folder
	//			root  = called frmo a page on the root of the site
	if(strFrom == 'root')
	{
		var objWin = openWindow("popups/trackdaydiary_applyonline.asp?id=" + intTD_ID, 'trackday_applyonline','yes',550,620,10,10);
		objWin.focus();
		return;
	}
	else if(strFrom == 'popup')
	{
		var objWin = openWindow("trackdaydiary_applyonline.asp?id=" + intTD_ID, 'trackday_applyonline','yes',550,620,40,40);
		objWin.focus();
		return;
	}
}

function openTrackDayTellUs()
{
	var objWin = openWindow("popups/trackdaydiary_tellus.asp", 'trackday_tellus','yes',550,620,10,10);
	objWin.focus();
	return;
}

/* ========== Date Validation function starts ============= */

/* Here's the list of tokens we support:
   m (or M) : month number, one or two digits.
   mm (or MM) : month number, strictly two digits (i.e. April is 04).
   d (or D) : day number, one or two digits.
   dd (or DD) : day number, strictly two digits.
   y (or Y) : year, two or four digits.
   yy (or YY) : year, strictly two digits.
   yyyy (or YYYY) : year, strictly four digits.
   mon : abbreviated month name (April is apr, Apr, APR, etc.)
   Mon : abbreviated month name, mixed-case (i.e. April is Apr only).
   MON : abbreviated month name, all upper-case (i.e. April is APR only).
   mon_strict : abbreviated month name, all lower-case (i.e. April is apr 
         only).
   month : full month name (April is april, April, APRIL, etc.)
   Month : full month name, mixed-case (i.e. April only).
   MONTH: full month name, all upper-case (i.e. APRIL only).
   month_strict : full month name, all lower-case (i.e. april only).
   h (or H) : hour, one or two digits.
   hh (or HH) : hour, strictly two digits.
   min (or MIN): minutes, one or two digits.
   mins (or MINS) : minutes, strictly two digits.
   s (or S) : seconds, one or two digits.
   ss (or SS) : seconds, strictly two digits.
   ampm (or AMPM) : am/pm setting.  Valid values to match this token are
         am, pm, AM, PM, a.m., p.m., A.M., P.M.
*/
// Be careful with this pattern.  Longer tokens should be placed before shorter
// tokens to disambiguate them.  For example, parsing "mon_strict" should 
// result in one token "mon_strict" and not two tokens "mon" and a literal
// "_strict".

var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mins|MINS|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");

// lowerMonArr is used to map months to their numeric values.

var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}

// monPatArr contains regular expressions used for matching abbreviated months
// in a date string.

var monPatArr=new Array();
monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');

// monthPatArr contains regular expressions used for matching full months
// in a date string.

var monthPatArr=new Array();
monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);

// cutoffYear is the cut-off for assigning "19" or "20" as century.  Any
// two-digit year >= cutoffYear will get a century of "19", and everything
// else gets a century of "20".

var cutoffYear=50;

// FormatToken is a datatype we use for storing extracted tokens from the
// format string.

function FormatToken (token, type) {
this.token=token;
this.type=type;
}

function parseFormatString (formatStr) {
var tokArr=new Array;
var tokInd=0;
var strInd=0;
var foundTok=0;
    
while (strInd < formatStr.length) {
if (formatStr.charAt(strInd)=="%" &&
(matchArray=formatStr.substr(strInd+1).match(tokPat)) != null) {
strInd+=matchArray[0].length+1;
tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
} else {

// No token matched current position, so current character should 
// be saved as a required literal.

if (tokInd>0 && tokArr[tokInd-1].type=="literal") {

// Literal tokens can be combined.Just add to the last token.

tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
}
else {
tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
      }
   }
}
return tokArr;
}

/* buildDate does all the real work.It takes a date string and format string,
 tries to match the two up, and returns a Date object (with the supplied date
 string value).If a date string doesn't contain all the fields that a Date
 object contains (for example, a date string with just the month), all
 unprovided fields are defaulted to those characteristics of the current
 date. Time fields that aren't provided default to 0.Thus, a date string
 like "3/30/2000" in "%mm/%dd/%yyyy" format results in a Date object for that
 date at midnight.formatStr is a free-form string that indicates special
 tokens via the % character.Here are some examples that will return a Date
 object:

 buildDate('3/30/2000','%mm/%dd/%y') // March 30, 2000
 buildDate('March 30, 2000','%Mon %d, %y') // Same as above.
 buildDate('Here is the date: 30-3-00','Here is the date: %dd-%m-%yy')

 If the format string does not match the string provided, an error message
 (i.e. String object) is returned.Thus, to see if buildDate succeeded, the
 caller can use the "typeof" command on the return value.For example,
 here's the dateCheck function, which returns true if a given date is
 valid,and false otherwise (and reports an error in the false case):

 function dateCheck(dateStr,formatStr) {
 var myObj=buildDate(dateStr,formatStr);
 if (typeof myObj=="object") {
 // We got a Date object, so good.
 return true;
 } else {
 // We got an error string.
 alert(myObj);
 return false;
 }
 }

*/

function buildDate(dateStr,formatStr) {
// parse the format string first.
var tokArr=parseFormatString(formatStr);
var strInd=0;
var tokInd=0;
var intMonth;
var intDay;
var intYear;
var intHour;
var intMin;
var intSec;
var ampm="";
var strOffset;

// Create a date object with the current date so that if the user only
// gives a month or day string, we can still return a valid date.

var curdate=new Date();
intMonth=curdate.getMonth()+1;
intDay=curdate.getDate();
intYear=curdate.getFullYear();

// Default time to midnight, so that if given just date info, we return
// a Date object for that date at midnight.

intHour=0;
intMin=0;
intSec=0;

// Walk across dateStr, matching the parsed formatStr until we find a 
// mismatch or succeed.

while (strInd < dateStr.length && tokInd < tokArr.length) {

// Start with the easy case of matching a literal.

if (tokArr[tokInd].type=="literal") {
if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd) {

// The current position in the string does match the format 
// pattern.

strInd+=tokArr[tokInd++].token.length;
continue;
}
else {

// ACK! There was a mismatch; return error.

return "\"" + dateStr + "\" does not conform to the expected format: " + formatStr;
   }
}

// If we get here, we're matching to a symbolic token.
switch (tokArr[tokInd].token) {
case 'm':
case 'M':
case 'd':
case 'D':
case 'h':
case 'H':
case 'min':
case 'MIN':
case 's':
case 'S':

// Extract one or two characters from the date-time string and if 
// it's a number, save it as the month, day, hour, or minute, as
// appropriate.

curChar=dateStr.charAt(strInd);
nextChar=dateStr.charAt(strInd+1);
matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
if (matchArr==null) {

// First character isn't a number; there's a mismatch between
// the pattern and date string, so return error.

switch (tokArr[tokInd].token.toLowerCase()) {
case 'd': var unit="day"; break;
case 'm': var unit="month"; break;
case 'h': var unit="hour"; break;
case 'min': var unit="minute"; break;
case 's': var unit="second"; break;
}
return "Invalid " + unit + " \"" + curChar + "\" or \"" + curChar +
nextChar + "\".";
}
strOffset=matchArr[0].length;
switch (tokArr[tokInd].token.toLowerCase()) {
case 'd': intDay=parseInt(matchArr[0],10); break;
case 'm': intMonth=parseInt(matchArr[0],10); break;
case 'h': intHour=parseInt(matchArr[0],10); break;
case 'min': intMin=parseInt(matchArr[0],10); break;
case 's': intSec=parseInt(matchArr[0],10); break;
}
break;
case 'mm':
case 'MM':
case 'dd':
case 'DD':
case 'hh':
case 'HH':
case 'mins':
case 'MINS':
case 'ss':
case 'SS':

// Extract two characters from the date string and if it's a 
// number, save it as the month, day, or hour, as appropriate.

strOffset=2;
matchArr=dateStr.substr(strInd).match(/^\d{2}/);
if (matchArr==null) {

// The two characters aren't a number; there's a mismatch 
// between the pattern and date string, so return an error
// message.

switch (tokArr[tokInd].token.toLowerCase()) {
case 'dd': var unit="day"; break;
case 'mm': var unit="month"; break;
case 'hh': var unit="hour"; break;
case 'mins': var unit="minute"; break;
case 'ss': var unit="second"; break;
}
return "Invalid " + unit + " \"" + dateStr.substr(strInd,2) + 
"\".";
}
switch (tokArr[tokInd].token.toLowerCase()) {
case 'dd': intDay=parseInt(matchArr[0],10); break;
case 'mm': intMonth=parseInt(matchArr[0],10); break;
case 'hh': intHour=parseInt(matchArr[0],10); break;
case 'mins': intMin=parseInt(matchArr[0],10); break;
case 'ss': intSec=parseInt(matchArr[0],10); break;
}
break;
case 'y':
case 'Y':

// Extract two or four characters from the date string and if it's
// a number, save it as the year.Convert two-digit years to four
// digit years by assigning a century of '19' if the year is >= 
// cutoffYear, and '20' otherwise.

if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {

// Four digit year.

intYear=parseInt(dateStr.substr(strInd,4),10);
strOffset=4;
}
else {
if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {

// Two digit year.

intYear=parseInt(dateStr.substr(strInd,2),10);
if (intYear>=cutoffYear) {
intYear+=1900;
}
else {
intYear+=2000;
}
strOffset=2;
}
else {

// Bad year; return error.

return "Invalid year \"" + dateStr.substr(strInd,2) + 
"\". Must be two or four digits.";
   }
}
break;
case 'yy':
case 'YY':

// Extract two characters from the date string and if it's a 
// number, save it as the year.Convert two-digit years to four 
// digit years by assigning a century of '19' if the year is >= 
// cutoffYear, and '20' otherwise.

if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {

// Two digit year.

intYear=parseInt(dateStr.substr(strInd,2),10);
if (intYear>=cutoffYear) {
intYear+=1900;
}
else {
intYear+=2000;
}
strOffset=2;
} else {
// Bad year; return error
return "Invalid year \"" + dateStr.substr(strInd,2) + 
"\". Must be two digits.";
}
break;
case 'yyyy':
case 'YYYY':

// Extract four characters from the date string and if it's a 
// number, save it as the year.

if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {

// Four digit year.

intYear=parseInt(dateStr.substr(strInd,4),10);
strOffset=4;
}
else {

// Bad year; return error.

return "Invalid year \"" + dateStr.substr(strInd,4) + 
"\". Must be four digits.";
}
break;
case 'mon':
case 'Mon':
case 'MON':
case 'mon_strict':

// Extract three characters from dateStr and parse them as 
// lower-case, mixed-case, or upper-case abbreviated months,
// as appropriate.

monPat=monPatArr[tokArr[tokInd].token];
if (dateStr.substr(strInd,3).search(monPat) != -1) {
intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
}
else {

// Bad month, return error.

switch (tokArr[tokInd].token) {
case 'mon_strict': caseStat="lower-case"; break;
case 'Mon': caseStat="mixed-case"; break;
case 'MON': caseStat="upper-case"; break;
case 'mon': caseStat="between Jan and Dec"; break;
}
return "Invalid month \"" + dateStr.substr(strInd,3) + 
"\". Must be " + caseStat + ".";
}
strOffset=3;
break;
case 'month':
case 'Month':
case 'MONTH':
case 'month_strict':

// Extract a full month name at strInd from dateStr if possible.

monPat=monthPatArr[tokArr[tokInd].token];
matchArray=dateStr.substr(strInd).match(monPat);
if (matchArray==null) {

// Bad month, return error.

return "Can't find a month beginning at \"" +
dateStr.substr(strInd) + "\".";
}

// It's a good month.

intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
strOffset=matchArray[0].length;
break;
case 'ampm':
case 'AMPM':
matchArr=dateStr.substr(strInd).match(/^(am|pm|AM|PM|a\.m\.|p\.m\.|A\.M\.|P\.M\.)/);
if (matchArr==null) {

// There's no am/pm in the string.Return error msg.

return "Missing am/pm designation.";
}

// Store am/pm value for later (as just am or pm, to make things
// easier later).

if (matchArr[0].substr(0,1).toLowerCase() == "a") {

// This is am.

ampm = "am";
}
else {
ampm = "pm";
}
strOffset = matchArr[0].length;
break;
}
strInd += strOffset;
tokInd++;
}
if (tokInd != tokArr.length || strInd != dateStr.length) {

/* We got through the whole date string or format string, but there's 
 more data in the other, so there's a mismatch. */

return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: DD/MM/YYYY HH:SS";
}

// Make sure all components are in the right ranges.

if (intMonth < 1 || intMonth > 12) {
return "Month must be between 1 and 12.";
}
if (intDay < 1 || intDay > 31) {
return "Day must be between 1 and 31.";
}

// Make sure user doesn't put 31 for a month that only has 30 days

if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31) {
return "Month "+intMonth+" doesn't have 31 days!";
}

// Check for February date validity (including leap years) 

if (intMonth == 2) {

// figure out if "year" is a leap year; don't forget that
// century years are only leap years if divisible by 400

var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
if (intDay > 29 || (intDay == 29 && !isleap)) {
return "February " + intYear + " doesn't have " + intDay + 
" days!";
   }
}

// Check that if am/pm is not provided, hours are between 0 and 23.

if (ampm == "") {
if (intHour < 0 || intHour > 23) {
return "Hour must be between 0 and 23 for military time.";
   }
}
else {

// non-military time, so make sure it's between 1 and 12.

if (intHour < 1|| intHour > 12) {
return "Hour must be between 1 and 12 for standard time.";
   }
}

// If user specified amor pm, convert intHour to military.

if (ampm=="am" && intHour==12) {
intHour=0;
}
if (ampm=="pm" && intHour < 12) {
intHour += 12;
}
if (intMin < 0 || intMin > 59) {
return "Minute must be between 0 and 59.";
}
if (intSec < 0 || intSec > 59) {
return "Second must be between 0 and 59.";
}
return new Date(intYear,intMonth-1,intDay,intHour,intMin,intSec);
}
function dateCheck(dateStr,formatStr) {
var myObj = buildDate(dateStr,formatStr);
if (typeof myObj == "object") {

// We got a Date object, so good.

return true;
}
else {

// We got an error string.

alert(myObj);
return false;
   }
}
//  End -->
/* ========== Date Validation function ends ============= */