<!--
flag=1;
var noexitad;
var shasha;
var strCountryMsg = "State is invalid.";
	
if ('' != "")   /* noexitad will almost always be set to 0 */
	noexitad = 1;
else
	noexitad = 0;

/*********** this is onUnload and opens the new window ************************/
function go() 
{
// there isn't anything here...
}

function RunScripts()
{
	return CheckRegularExpression(document.frmOrder.boxFN,/^[a-zA-Z .]{2,}$/,"First Name is invalid.") &&
	CheckRegularExpression(document.frmOrder.boxLN,/^[a-zA-Z .]{2,}$/,"Last Name is invalid.") &&
	CheckRegularExpression(document.frmOrder.boxAddress,/^[a-zA-Z0-9_\W]{5,}$/,"Address is invalid.") &&
	CheckRegularExpression(document.frmOrder.boxCity,/^[a-zA-Z .-]{3,}$/,"City is invalid.") &&
	CheckRegularExpression(document.frmOrder.boxState,/^[a-zA-Z]{1,}$/,strCountryMsg) &&
	CheckZipCode(document.frmOrder.boxZip,document.frmOrder.boxCountry) &&
	CheckRegularExpression(document.frmOrder.boxEmail,/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/,"Email is invalid.") &&
	CheckSameness(document.frmOrder.boxEmail, document.frmOrder.boxConfirmEmail,"Email addresses don't match each other.") &&
	ValidDatePhone(document.frmOrder.boxAreaCode,document.frmOrder.boxExchange,document.frmOrder.boxPNumber,'',"1") &&
	ValidDatePhone(document.frmOrder.boxAreaCode2,document.frmOrder.boxExchange2,document.frmOrder.boxPNumber2,'',"2") &&
	CheckRegularExpression(document.frmOrder.ddtime,/\S{1,}$/,"Best time to call is required.") &&
	CheckRegularExpression(document.frmOrder.ddtimezone,/\S{1,}$/,"Best timezone to call is required.") &&

	//CheckRegularExpression(document.frmOrder.ddMonth,/\S{1,}$/,"Date(Month) of Birth.") &&
	//CheckRegularExpression(document.frmOrder.ddDay,/\S{1,}$/,"Date(Day) of Birth is required.") &&
	//CheckRegularExpression(document.frmOrder.ddYear,/\S{1,}$/,"Date(Year) of Birth is required.") &&
	//CheckGender() &&
	//CheckRegularExpression(document.frmOrder.selQuestion1,/\S{1,}$/,"Question 1 is required.") &&
	//CheckRegularExpression(document.frmOrder.selQuestion2,/\S{1,}$/,"Question 2 is required.") &&
	//CheckRegularExpression(document.frmOrder.selQuestion3,/\S{1,}$/,"Question 3 is required.") &&
	//CheckRegularExpression(document.frmOrder.selQuestion4,/\S{1,}$/,"Question 4 is required.") &&
	//CheckDidInPast() &&

	Verify(document.frmOrder.cbVerify);

}

function Verify(strField)
{
	if (!strField.checked)
		{
		alert("Please read the disclaimer and check the box to continue!");
		strField.focus();
		return false;
		}
	return true;
}
	
function Join() 
{
	//document.frmOrder.boxNoRunaround.value = 2;
	/* window.location.href = "Affiliate/SignUp.asp?ac=<%=tempAffiliateID%>" */
	window.open("Affiliate/SignUp.asp?ac=1239","SignUP");
}

function CheckZipCode(strZipCode,strCountry)
{
	if( strCountry.value == "US" )
	{
		if( CheckRegularExpression(document.frmOrder.boxZip,/(^\d{5}$)|(^\d{5}-\d{4}$)/,"Zip code is invalid.") == false )
			return false;
	}
	else if( strCountry.value == "CA"  )
	{
		if( CheckRegularExpression(document.frmOrder.boxZip,/[a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d$/,"Postal Code is invalid. ex: X0X 0X0") == false )
			return false;
	}
	else if( strCountry.value == "UK"  )
	{
		if( CheckRegularExpression(document.frmOrder.boxZip,/[A-Z]{1,2}\d[A-Z\d]? \d[ABD-HJLNP-UW-Z]{2}$/,"Zip code is invalid.") == false )
			return false;
	}
	return true;
}

function ValidDatePhone(intAreaCode,intExchange,intPNumber,intPhone,strPhoneField)
{
	if( (strPhoneField == "1") || (strPhoneField == "2" && intAreaCode.value != "") ) 
	{
		var strAreaCode = new String(intAreaCode.value)
		if( CheckRegularExpression(intAreaCode,/\d{3}$/,"Phone number is invalid.") &&
			CheckRegularExpression(intExchange,/\d{3}$/,"Phone number is invalid.") &&
			CheckRegularExpression(intPNumber,/\d{4}$/,"Phone number is invalid.") &&
			CheckForRepeatingChar(intAreaCode,"Area Code is invalid."))
		{
			if( strAreaCode.charAt(0) != "0" && strAreaCode.charAt(0) != "1" && 
				intExchange.value != "000" && intExchange.value != "111" && 
				intExchange.value != "555" )
			{
				intPhone.value = intAreaCode.value + '-' + intExchange.value + '-' + intPNumber.value;
			}
			else
			{
				alert("Phone number is invalid.");
				intAreaCode.focus();
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	return true;
}

function CheckSameness(strField1,strField2,strMessage)
{
	if(strField1.value != strField2.value)
	{
		alert(strMessage);
		strField1.focus();
		return false;
	}
	return true;
}
	
function CheckForRepeatingChar(strField,strMessage)
{
	var strText = new String(strField.value);
	var strTemp = new String();
	var intTimesEqual = 0;
	var blnValid = true;
	//Check for character repeating more then 2 times
	for(var x=0; x < strText.length && blnValid; ++x)
	{
		if(strText.charAt(x) == strTemp)
		{
			++intTimesEqual;
		}
		else
		{
			strTemp = strText.charAt(x);
			intTimesEqual = 1;
		}
		if(intTimesEqual > 2)
			blnValid = false;
	}
	
	if (!blnValid)
	{
		alert(strMessage);
		strField.focus();
		return false;
	}
	return true;
}

function CheckForPatterns(strField,strMessage)
{
	var strText = new String(strField.value);
	var strTemp = new String();
	var intTimesEqual = 0;
	var blnValid = true;
	
	//Check for character repeating more then 2 times
	for(var x=0; x < strText.length && blnValid; ++x)
	{
		if(strText.charAt(x) == strTemp)
		{
			++intTimesEqual;
		}
		else
		{
			strTemp = strText.charAt(x);
			intTimesEqual = 1;
		}
		if(intTimesEqual > 2)
			blnValid = false;
	}
		
	strTemp = "";
	intTimesEqual = 0;
	//Check for pattern repeating more then 1 time
	for(var z=0; z < strText.length && blnValid; ++z)
	{
		for(var x=z; x < strText.length && blnValid; ++x)
		{
			if(strText.charAt(x) == strTemp.charAt(0) && 1 < strTemp.length)
			{
				for(var i=0; i < strTemp.length && blnValid;++i)
				{
					if(strTemp.charAt(i) == strText.charAt(x + i))
						++intTimesEqual;
					else
					{
						intTimesEqual = 0;
						i = strTemp.length + 1;
						strTemp = "";
					}
				}
				//found a matching pattern if intTimesEqual is greater then 0
				if(intTimesEqual > 1)
					blnValid = false;
			}
			else
			{
				strTemp = strTemp.concat(strText.charAt(x));
				intTimesEqual = 0;
			}
		}
		strTemp = "";
		intTimesEqual = 0;
	}
		
	if (!blnValid)
	{
		alert(strMessage);
		strField.focus();
		return false;
	}
	return true;
}

function CheckRegularExpression(strField,Pattern,strMessage)
{
  //alert("Checking: "+strField.name + " : " + strField.value);
	if(navigator.userAgent.indexOf('Mac') > 0)
	{
		if(strField.value == "")
		{
			alert(strMessage);
			strField.focus();
			return false;
		}
	}
	else
	{
		var re = new RegExp(Pattern);

		if(!re.test(trim(strField.value)))
		{
			alert(strMessage);
			strField.focus();
			return false;
		}
	}
	return true;
}

function checkFilledIn(strField, strMessage)
  {
  alert("Checking Filled In"); 
  compField = trim(strField.value);
  if (compField == "")
    {
    alert(strMessage);
		strField.focus();
		return false;
    }
  return true;
  } // end function

function trim(strText)
{ 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function CheckGender()
{
	if(!document.frmOrder.rGender[0].checked && !document.frmOrder.rGender[1].checked)
	{
		alert("Please select gender.");
		document.frmOrder.rGender[0].focus();
		return false;
	}
	return true;
}

function CheckDidInPast()
{
	if(!document.frmOrder.selQuestion5[0].checked && !document.frmOrder.selQuestion5[1].checked)
	{
		alert("Question 5 is required.");
		document.frmOrder.selQuestion5[0].focus();
		return false;
	}
	return true;
}

function CheckHasDebt()
{
	if(!document.frmOrder.selQuestion6[0].checked && !document.frmOrder.selQuestion6[1].checked)
	{
		alert("Question 6 is required.");
		document.frmOrder.selQuestion6[0].focus();
		return false;
	}
	return true;
}

	
function JumpBox(tempMaxLength,e,tempCurrBox,tempNextBox) 
{
	var tempCurrValueLength = tempCurrBox.value;
	tempCurrValueLength = tempCurrValueLength.length;
	var charCode = e.keyCode
	if ((eval(charCode) != 9) && (eval(charCode) != 16)) 
	{
		if (tempCurrValueLength >= eval(tempMaxLength)) 
		{
			if (isNaN(tempCurrBox.value)) 
			{
				alert("Please enter a valid number.");
				tempCurrBox.value = "";
				document.frmOrder.hidCurrentLength.value = 1;
				tempCurrBox.focus();
			}
			else 
			{
				tempNextBox.focus();
			}
			document.frmOrder.hidCurrentLength.value = 1;
		}
		else 
		{
			document.frmOrder.hidCurrentLength.value = tempCurrValueLength;
		}
	}
	return true;
}
//-->
