var t


function tabtextarea() {
if (t) {clearTimeout(t)}
 t = setTimeout("document.frmHandle.txtAgreement.scrollTop = 0;",100);
 
}

function redirect2Cancel()
{
	document.frmHandle.action = "membership.aspx?pagename=A3&pagemode=input&formmode=cancel"
	document.frmHandle.submit();
}

function redirect2Submit()
{
	document.frmHandle.action = "membership.aspx?pagename=A3pre&pagemode=input&formmode=submit"
	document.frmHandle.submit();
}

function submitThisForm()
{

	if (ValidateHandleInfo(6)){
//		alert("Hello");
//		redirect2Submit();
	 //inserted for pop up.  If this value isn't present, pop up occurs.
		//I commented this out since this function isn't defined anywhere and sounds useless anyway :P 
		//Maybe it was used at one time to make sure the user doesn't click sign up twice or something. ~J. Skibitsky 9/12/08
		//CheckForClick();
		return true;
	}
	else{
//		alert("Here Else!!");
		return false;
	}


}	
	
function ValidateHandleInfo(iLength)
{	
	var form = document.frmHandle;
	if (form.pd.value != 1) 
	{
		var male = form.rdoGender[0].checked
		var female = form.rdoGender[1].checked
	}
	// If we need to focus a field that has bad data, assign it to this...
	var oFieldToFocus	
	var errmsg = '';
	var sErrorMessage = '';
	var sEmailErrorMsg = '';
	var sHandleErrorMsg = '';
	var sPasswordErrorMsg = '';
	var sConfirmPasswordErrorMsg = '';
	document.frmHandle.handle.value = Trim(document.frmHandle.handle.value)
	var sHandle = document.frmHandle.handle.value;
	var sPassword = document.frmHandle.password.value;
	var sConfirmPassword = document.frmHandle.txtconfirmPassword.value;
	var sZipPostal = document.frmHandle.txtZip.value
	var re_space = /\s/gi;
	
	if (form.pd.value != 1 || form.notify.value == 1 )
	{ 
		if ((form.rdoGender.value == "choose" || form.rdoGender.value == ''))
		{
			//if (errmsg == '')
			errmsg += "Are you a Man or a Woman?\n";	
		}
		if ((form.rdoMatchGender.value == "choose" || form.rdoMatchGender.value == ''))
		{
			//if (errmsg == '')
				//oFieldToFocus = form.rdoMatchGender(0);
			errmsg += "Who are you looking for? A Man or a Woman?\n";	
		}
	}	
	
	if (sZipPostal == '' || sZipPostal < 5)
	{
		//if (errmsg == '')
			//oFieldToFocus = document.frmHandle.txtZip;
		errmsg += "The Zip or Postal Code you used appears to be invalid.\n";
	}
	
	//**************
	//* Birth Month
	//**************
	
	if (form.selMonth.value == "Month" || form.selMonth.value == '')
	{		
		//if (errmsg == '')
			//oFieldToFocus = form.selMonth;
		errmsg += "Please select your month of birth.\n";
	}
	//**************
	//* Birth Day
	//**************
	
	if (form.selDay.value == "Day" || form.selDay.value == '')
	{
		//if (errmsg == '')
			//oFieldToFocus = form.selDay;
		errmsg += "Please select your day of birth.\n";
	}
	//**************
	//* Birth Year
	//**************
	if (form.selYear.value == "Year" || form.selYear.value == '')
	{
		//if (errmsg == '')
			//oFieldToFocus = form.selYear;
		errmsg += "Please select your year of birth.\n";
	}	
	
	/*****************/
	/* is Handle OK? */
	/*****************/
	sHandleErrorMsg += ValidateHandle(document.frmHandle.handle.value);
	/*if (document.frmHandle.handle.value.length < 2)
		sHandleErrorMsg += "Your Online Name must be at least 2 characters.\n"
		
	if (sHandle.indexOf('"') > -1)
		sHandleErrorMsg += "Please don't use quotes in your Online Name.\n";

	if (sHandle.indexOf('@') > -1 || sHandle.indexOf('.') > -1 || sHandle.indexOf('&') > -1 || sHandle.indexOf('<') > -1 || sHandle.indexOf('>') > -1)
		sHandleErrorMsg += "Please don't use symbols in your Online Name.\n";
*/
	/*******************/
	/* is Password OK? */
	/*******************/
	if (sPassword.length < iLength)
		sPasswordErrorMsg += "Please make your password at least " + iLength + " characters.\n";

	if (sPassword.indexOf('"') > -1)
		sPasswordErrorMsg += "Please don't use quotes in your password.\n";

	if (sPassword.indexOf('&') > -1 )
		sPasswordErrorMsg += "Please don't use the symbol (&) in your password.\n";

	if (re_space.test(sPassword))
		sPasswordErrorMsg += "Please don't use spaces in your Password.\n";

	/***************************/
	/* is Confirm Password OK? */
	/***************************/
/* NOT NEEDED - just check the orig password.

if (sConfirmPassword.length < iLength)
		sConfirmPasswordErrorMsg += "Your Confirmation Password must be at least " + iLength + " characters\n";

	if (sConfirmPassword.indexOf('"') > -1)
		sConfirmPasswordErrorMsg += "No Quotes in your Confirmation Password\n";

	if (re_space.test(sConfirmPassword))
		sConfirmPasswordErrorMsg += "No Spaces in your Confirmation Password\n"; 
*/

	if (sConfirmPassword != sPassword)
		sConfirmPasswordErrorMsg += "The passwords you typed didn't match. Please try again.\n";

		
	form.txtEmail.value = Trim(form.txtEmail.value)
	var re_cat = /^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\._-]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/gi;
	var re_cat2 = /^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\._-]+\.([a-zA-Z]{2})(\]?)$/gi;
	var re_cat2b = /^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\._-]+\.(us|ca)(\]?)$/gi;
	var re_cat3 = /(^\.)|(^@)|(@.*@)|(\.\.)|(@\.)|(\.@)|[[:space:]]/gi;
	
	if (form.txtEmail.value.match(re_cat)){
		if (form.txtEmail.value.match(re_cat3)){		
			sEmailErrorMsg += "Your email address appears to be invalid.\n";
			}
		if (form.txtEmail.value.match(re_cat2)&& form.txtEmail.value.match(re_cat2b)== null){
			sEmailErrorMsg += "Your email address appears to be invalid because it is outside of North America.\n";		
			}
	}
	else {
		sEmailErrorMsg += "Your email address appears to be invalid.\n";
		}


	if (Trim(form.txtEmail.value) != Trim(form.txtconfirmEmail.value))
	{
		sEmailErrorMsg += "The email address you typed don't match. Check for typos, correct and then click \"Sign me up\"\n";
	}
	
		
 	
	
	/***************************/
	/* Concatenate messages */
	/***************************/	
	sErrorMessage = errmsg + sHandleErrorMsg + sPasswordErrorMsg + sConfirmPasswordErrorMsg;
	
	if (!document.frmHandle.chkAcceptAgreement.checked)
	{
		sErrorMessage += "Please accept our Terms of Use.\n";
			//location = "membership.aspx?pagename=A3";
		
	}

	if (sErrorMessage != '')
	{ 
		alert ("Oops! Looks like you missed something:\n\n" + sErrorMessage);
		/*****************************************************/
		/* Based on where we have error message, assign focus*/
		/*****************************************************/
//		alert(sHandleErrorMsg);
		if (sHandleErrorMsg > '')
			document.frmHandle.handle.focus();
		else if	(sPasswordErrorMsg > '')
			document.frmHandle.password.focus();
		else if	(sConfirmPasswordErrorMsg > '')
			document.frmHandle.txtconfirmPassword.focus();
		return false;
	}
	else{
		return true; 
	}
}
function ValidateHandle(sHandle)
{
	var errmsg = '';
	var valid = true;
	var i = 0;
	var badChars = new Array()
	badChars[0] = "/";
	badChars[1] = "\\";
	badChars[2] = "@";
	badChars[3] = "$";
	badChars[4] = "'";
	badChars[5] = "\"";
	badChars[6] = "#";
	badChars[7] = "<";
	badChars[8] = ">";
	badChars[9] = "&";
	badChars[10] = ")";
	badChars[11] = "(";
	badChars[12] = "{";
	badChars[13] = "}";
	badChars[14] = "]";
	badChars[15] = "[";
	badChars[16] = ";";
	badChars[17] = ":";
	badChars[18] = ",";
	badChars[19] = "=";
	badChars[20] = " ";
	
if (sHandle.length < 3)
{
errmsg += "Your handle must be at least 3 characters long.\n";
valid = false;
}



if (valid == true)
{
	while(i < badChars.length)
	 {
		
		if(sHandle.indexOf(badChars[i]) == -1)
		{
			++i;

		}
		else if(sHandle.indexOf(badChars[i]) != -1) 
		{
			valid = false;
			
			if((badChars[i] == "\"") || (badChars[i])== "\'")
			{
			errmsg += "Invalid handle entered.  Please enter a handle that does not contain quotes." + "\n";
			}
			else
			{
			errmsg += "Invalid handle entered.  Please enter a handle not containing the character \" " + badChars[i] + " \"." + "\n";
			}
			break;
		}

	}


}

return errmsg;

 
}

/*function AgreementOK()
{
	var error = true;
	if (!document.frmHandle.chkAcceptAgreement.checked)
	{
		if(alert("Did you forget to accept our Terms of Use? You need to check the checkbox to continue signing up. Thanks."))
			location = "membership.aspx?pagename=A3";
		error = false;
	}
	return error;
}*/

function LINK(ID) {
	if (ID == 1) {window.location.href = "corporate.asp?pagename=H3#G";}      
}

// take out leading spaces
function Trim(sString)
{
	var iCounter=0;
	var OrigLen=sString.length;	
	while ( (sString.charAt(iCounter)==" ") && (iCounter < sString.length) )
		iCounter++;
	if (iCounter != 0)
		 sString = sString.substring(iCounter,OrigLen);
	while (sString.charAt(sString.length-1)==" ")
		sString=sString.substring(0,sString.length-1)
	return sString;
}

//function tabnext()	{
  //document.frmHandle.password.focus();	
	//}

function checkEmailPref()
{
	//if (document.frmHandle.notify.value == 1 && document.frmHandle.events.checked == false)
	//{	
		//if(confirm('Oops... You selected to GET NOTIFIED of upcoming, Cupid.com/PreDating events in your local area but you unchecked the option on the previous page to \"Email me: about Cupid.com, local singles parties, membership discounts, etc.\"  You may continue with your registration, but you will not receive these notifications unless you check that option.')) 
		//{
			//document.frmHandle.alreadyAsked.value = "yes";
			if(document.frmHandle.alreadyAsked.value != "yes" && document.frmHandle.pd.value == 1 && document.frmHandle.notify.value != 1 && document.frmHandle.MailMessage.checked == false)
			{
				if(confirm('Oops... You should select \"Email me: when I have new MESSAGES\" if you are registering for a Cupid.com/PreDating event so that we can alert you when you have MESSAGES waiting from your speed dating matches. \n\nClick Cancel to stop and select that option now, or click OK to continue with your current selections.')) 
				{
					document.frmHandle.alreadyAsked.value = "yes";
					return true;
				}
				else return false;
			} 
		//}
		//else return false;
	//}

}

