function ValidateRegForm(source, arguments) 
{ 
        //User ID - text field
        if(document.Form1.ContactInfoControl1_tbUserID != null)
        {
				if (Trim(document.Form1.ContactInfoControl1_tbUserID.value).length == 0) 
				{ 
						alert("Please enter a User ID."); 
						document.Form1.ContactInfoControl1_tbUserID.focus(); 
						arguments.IsValid=false;
						return;
				}
        } 

		if (document.Form1.ContactInfoControl1_tbUserID != null)
		{
				if (!verifyLegal(document.Form1.ContactInfoControl1_tbUserID)) 
				{ 
						arguments.IsValid=false;
						return;
				}         
		}

        //Password - text field 
        if (document.Form1.ContactInfoControl1_tbPassword.value.length < 6) 
        { 
                alert("Please select a 6-15 character password."); 
                document.Form1.ContactInfoControl1_tbPassword.focus(); 
                arguments.IsValid=false;
                return;
        } 

        // Confirm Password - text field 
        if (document.Form1.ContactInfoControl1_tbPassword.value != document.Form1.ContactInfoControl1_tbConfirmPassword.value) 
        { 
                alert("Passwords do not match"); 
                document.Form1.ContactInfoControl1_tbConfirmPassword.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //Password Question - text field
        if (Trim(document.Form1.ContactInfoControl1_tbQuestion.value).length == 0) 
        { 
                alert("Please enter a password question."); 
                document.Form1.ContactInfoControl1_tbQuestion.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //Password Answer - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbAnswer.value).length == 0) 
        { 
                alert("Please enter a password answer."); 
                document.Form1.ContactInfoControl1_tbAnswer.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //Company - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbCompany.value).length == 0) 
        { 
                alert("Please enter your company name."); 
                document.Form1.ContactInfoControl1_tbCompany.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //First Name - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbFirstName.value).length == 0) 
                { 
                alert("Please enter your first name."); 
                document.Form1.ContactInfoControl1_tbFirstName.focus(); 
                arguments.IsValid=false;
                return;
                } 

        //Last Name - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbLastName.value).length == 0) 
                { 
                alert("Please enter your last name."); 
                document.Form1.ContactInfoControl1_tbLastName.focus(); 
                arguments.IsValid=false;
                return;
                } 
                
        //Title - drop down selection box 
        if(SelectValue(document.Form1.ContactInfoControl1_ddlTitle) == "") 
        { 
                alert("Please select your title from the drop down list."); 
                document.Form1.ContactInfoControl1_ddlTitle.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //Address Line 1 - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbAddress1.value).length == 0) 
        { 
                alert("Please enter your company address."); 
                document.Form1.ContactInfoControl1_tbAddress1.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //City - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbCity.value).length == 0) 
        { 
                alert("Please enter your city."); 
                document.Form1.ContactInfoControl1_tbCity.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //State - drop down selection box 
        if(SelectValue(document.Form1.ContactInfoControl1_ddlState) == "") 
        { 
                alert("Please select your state from the drop down list."); 
                document.Form1.ContactInfoControl1_ddlState.focus(); 
                arguments.IsValid=false;
                return;
        }
        
        //Zip Code - required field 
        if (Trim(document.Form1.ContactInfoControl1_tbPostalCode.value).length == 0) 
        { 
                alert("Please enter your zip code."); 
                document.Form1.ContactInfoControl1_tbPostalCode.focus(); 
                arguments.IsValid=false;
                return;
        } 

        //Zip Code - only validate if domestic - USA only 
        if(SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "US") 
        { 
                if (!verifyZip1(document.Form1.ContactInfoControl1_tbPostalCode)) 
                { 
					arguments.IsValid=false;
					return;
                } 
        } 
        

        //Country - drop down selection box 
        if(SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "" ) 
        { 
                alert("Please select your country from the drop down list."); 
                document.Form1.ContactInfoControl1_ddlCountry.focus(); 
                arguments.IsValid=false;
                return;
        } 

        var varState = SelectValue(document.Form1.ContactInfoControl1_ddlState);         
        if(varState == "OTHER") 
        { 
                if( (SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "US") || (SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "CA") ) 
                { 
                    alert("Please select another country for the selected State option."); 
                    document.Form1.ContactInfoControl1_ddlCountry.focus(); 
					arguments.IsValid=false;
					return;
                } 
        } 
        else if  //check for Canadian provinces 
                ( (varState == "AB") || 
                 (varState == "BC") || 
                 (varState == "MB") || 
                 (varState == "NB") || 
                 (varState == "NF") || 
                 (varState == "NS") || 
                 (varState == "NT") || 
                 (varState == "ON") || 
                 (varState == "PE") || 
                 (varState == "QC") || 
                 (varState == "SK") || 
                 (varState == "YT") 
          )         
                { 
                        if (SelectValue(document.Form1.ContactInfoControl1_ddlCountry) != "CA" ) 
                        {
							alert("The province you have selected is a Canadian province. Please check the country."); 
							document.Form1.ContactInfoControl1_ddlCountry.focus(); 
							arguments.IsValid=false;
							return; 
                        } 
                } 
        else  //check for USA states 
                { 
                        if (SelectValue(document.Form1.ContactInfoControl1_ddlCountry) != "US") 
                        { 
							alert("Please select United states for the selected State option."); 
							document.Form1.ContactInfoControl1_ddlCountry.focus(); 
							arguments.IsValid=false;
							return; 
                        } 
                } 

        //Set the country description values 
        //document.Form1.ContactInfoControl1_countryCode.value = document.Form1.ContactInfoControl1_country.options[document.Form1.ContactInfoControl1_country.selectedIndex].value; 
        //document.Form1.ContactInfoControl1_countryName.value = document.Form1.ContactInfoControl1_country.options[document.Form1.ContactInfoControl1_country.selectedIndex].text; 

        //Phone Number - numeric field 
        if (Trim(document.Form1.ContactInfoControl1_tbPhone.value).length == 0) 
        { 
                alert("Please enter your telephone number."); 
                document.Form1.ContactInfoControl1_tbPhone.focus(); 
				arguments.IsValid=false;
				return; 
        } 

        //Phone Number - numeric field -validate only US and Canadian numbers 
        if(SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "US" || SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "CA" ) 
        { 
                if (!verifyPhone(document.Form1.ContactInfoControl1_tbPhone)) 
                { 
					arguments.IsValid=false;
					return; 
                } 
        } 

        //Fax Number - numeric field 
        if (Trim(document.Form1.ContactInfoControl1_tbFax.value).length != 0) 
        { 
                if (SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "US" || SelectValue(document.Form1.ContactInfoControl1_ddlCountry) == "CA" ) 
                { 
                        if (!verifyFaxnbr(document.Form1.ContactInfoControl1_tbFax)) 
                        { 
							arguments.IsValid=false;
							return; 
                        } 
                } 
        }         

        //Email Address - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbEmail.value).length != 0) 
        { 
                if (!fneMailCheck(document.Form1.ContactInfoControl1_tbEmail)) 
                { 
					arguments.IsValid=false;
					return; 
                } 
        } 

        //************************************************************* 
        //Contact Permissions - radio buttons
        if(!document.Form1.ContactInfoControl1_rdoEmailYes.checked && !document.Form1.ContactInfoControl1_rdoEmailNo.checked) 
        { 
                alert("Please indicate your e-mail consent."); 
                document.Form1.ContactInfoControl1_rdoEmailYes.focus(); 
				arguments.IsValid=false;
				return; 
        } 
        if(!document.Form1.ContactInfoControl1_rdoFaxYes.checked && !document.Form1.ContactInfoControl1_rdoFaxNo.checked) 
        { 
                alert("Please indicate your fax consent."); 
                document.Form1.ContactInfoControl1_rdoFaxYes.focus();
				arguments.IsValid=false;
				return; 
        } 
        if(!document.Form1.ContactInfoControl1_rdoPhoneYes.checked && !document.Form1.ContactInfoControl1_rdoPhoneNo.checked) 
        { 
                alert("Please indicate your phone consent."); 
                document.Form1.ContactInfoControl1_rdoPhoneYes.focus();
				arguments.IsValid=false;
				return; 
        } 
        if(!document.Form1.ContactInfoControl1_rdoMailYes.checked && !document.Form1.ContactInfoControl1_rdoMailNo.checked) 
        { 
                alert("Please indicate your mail consent."); 
                document.Form1.ContactInfoControl1_rdoMailYes.focus();
				arguments.IsValid=false;
				return; 
        } 
        if(!document.Form1.ContactInfoControl1_rdoSharingYes.checked && !document.Form1.ContactInfoControl1_rdoSharingNo.checked)
        { 
                alert("Please indicate your information sharing consent."); 
                document.Form1.ContactInfoControl1_rdoSharingYes.focus();
				arguments.IsValid=false;
				return; 
        } 
        
        //Contact permissions and related fields 
        if (document.Form1.ContactInfoControl1_rdoEmailYes.checked == true && Trim(document.Form1.ContactInfoControl1_tbEmail.value).length == 0) 
        { 
                alert("You indicated e-mail consent. \nPlease enter the email address."); 
                document.Form1.ContactInfoControl1_tbEmail.focus(); 
				arguments.IsValid=false;
				return; 
        } 
        if (document.Form1.ContactInfoControl1_rdoFaxYes.checked == true && Trim(document.Form1.ContactInfoControl1_tbFax.value).length == 0) 
        { 
                alert("You indicated fax consent. \nPlease enter the fax number."); 
                document.Form1.ContactInfoControl1_tbFax.focus(); 
				arguments.IsValid=false;
				return; 
        } 
        if (document.Form1.ContactInfoControl1_rdoEmailYes.checked == false && Trim(document.Form1.ContactInfoControl1_tbEmail.value).length > 0) 
        { 
                alert("E-mail is present. \nPlease consent to the e-mail permission."); 
                document.Form1.ContactInfoControl1_rdoEmailYes.focus(); 
				arguments.IsValid=false;
				return; 
        } 
        if (document.Form1.ContactInfoControl1_rdoFaxYes.checked == false && Trim(document.Form1.ContactInfoControl1_tbFax.value).length > 0) 
        { 
                alert("Fax number is present. \nPlease consent to the fax permission or clear the fax number."); 
                document.Form1.ContactInfoControl1_rdoFaxYes.focus(); 
				arguments.IsValid=false;
				return; 
        } 

        //************************************************************* 
        
        // Signature - text field 
        if (Trim(document.Form1.ContactInfoControl1_tbSignature.value).length == 0) 
        { 
                alert("Please type your name intended as a signature.");
                document.Form1.ContactInfoControl1_tbSignature.focus();
				arguments.IsValid=false;
				return; 
        } 
        
        //Business Type - check boxes 
        if(PrimaryBizSelected() == false) 
        { 
                alert("Please indicate your primary business type."); 
                document.Form1.ContactInfoControl1_rdoPrimaryBiz_0.focus(); 
				arguments.IsValid=false;
				return; 
        } 

        if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_9.checked) 
        { 
                if (document.Form1.ContactInfoControl1_tbPrimaryBizOther.value.length == 0 ) 
                { 
					alert("You indicated Other as your primary business type. Please describe."); 
					document.Form1.ContactInfoControl1_tbPrimaryBizOther.focus(); 
					arguments.IsValid=false;
					return; 
                } 
        } 

        if (Trim(document.Form1.ContactInfoControl1_tbPrimaryBizOther.value).length > 0 ) 
        { 
				if(!document.Form1.ContactInfoControl1_rdoPrimaryBiz_9.checked) 
				{ 
					alert("You have text in the description box for Primary types of business. Please choose the corresponding button."); 
					document.Form1.ContactInfoControl1_rdoPrimaryBiz_9.focus(); 
					arguments.IsValid=false;
					return; 
                } 
        } 

        //Other Business Field - text field 
        if(document.Form1.ContactInfoControl1_cbAltBiz_9.checked) 
        { 
                if (document.Form1.ContactInfoControl1_tbAltBizOther.value.length==0 ) 
                { 
                        alert("You indicated Other in other business types. Please describe."); 
                        document.Form1.ContactInfoControl1_tbAltBizOther.focus(); 
						arguments.IsValid=false;
						return; 
                } 
        } 

        //check for value in other-desciption field, but OTH checkbox not checked 
        if (Trim(document.Form1.ContactInfoControl1_tbAltBizOther.value).length > 0) 
        { 
				if(!document.Form1.ContactInfoControl1_cbAltBiz_9.checked) 
				{ 
						alert("You have text in the description box for Other types of business. Please check the corresponding box.");
						document.Form1.ContactInfoControl1_cbAltBiz_9.focus();
						arguments.IsValid=false;
						return; 
				}
        } 

       /* if (Trim(document.Form1.ContactInfoControl1_tbWebSite.value).length == 0 && document.Form1.ContactInfoControl1_rdoIncludeCompanyYes.checked) 
        { 
				alert("Please enter your web address.");
				document.Form1.ContactInfoControl1_tbWebSite.focus();
				arguments.IsValid=false;
				return; 
        }*/ 

		// You made it!  CONGRATULATIONS!  You may submit the form.
		arguments.IsValid = true;
        return;
}

function ValidateBizForm(source, arguments) 
{
		if(!isNum(document.Form1.tbBusStartMo.value))
		{
			alert("Please enter a number for your business start month.");
			document.Form1.tbBusStartMo.focus();
			arguments.IsValid=false;
			return;
		}
		if(document.Form1.tbBusStartMo.value < 1 || document.Form1.tbBusStartMo.value > 12)
		{
			alert("Please enter a valid month (1-12).");
			document.Form1.tbBusStartMo.focus();
			arguments.IsValid=false;
			return;
		}
		if(!isNum(document.Form1.tbBusStartYr.value))
		{
			alert("Please enter a number for your business start year.");
			document.Form1.tbBusStartYr.focus();
			arguments.IsValid=false;
			return;
		}
		if(!isNum(document.Form1.tbSalesPercentHanes.value))
		{
			alert("Please enter a number for your Hanes percentage.");
			document.Form1.tbSalesPercentHanes.focus();
			arguments.IsValid=false;
			return;
		}
		if(!isNum(document.Form1.tbSalesPercentObs.value))
		{
			alert("Please enter a number for your Outer Banks percentage.");
			document.Form1.tbSalesPercentObs.focus();
			arguments.IsValid=false;
			return;
		}
		// make sure the textbox exists (invisible for OBS)
		if(document.Form1.tbRecommendedBeefy != null)
		{
			if(!isNum(document.Form1.tbRecommendedBeefy.value))
			{
				alert("Please enter a number for Beefy-T recommendations.");
				document.Form1.tbRecommendedBeefy.focus();
				arguments.IsValid=false;
				return;
			}
		}
		if(!isNum(document.Form1.tbYouthPercent.value))
		{
			alert("Please enter a number for the youth percent.");
			document.Form1.tbYouthPercent.focus();
			arguments.IsValid=false;
			return;
		}
		if(!isNum(document.Form1.tbWomensPercent.value))
		{
			alert("Please enter a number for the women's percent.");
			document.Form1.tbWomensPercent.focus();
			arguments.IsValid=false;
			return;
		}

		arguments.IsValid = true;
        return;
}

function SelectValue(dropdown)
{
	return dropdown.options[dropdown.selectedIndex].value;
}

function PrimaryBizSelected()
{
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_0.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_1.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_2.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_3.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_4.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_5.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_6.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_7.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_8.checked)
		return true;
	if(document.Form1.ContactInfoControl1_rdoPrimaryBiz_9.checked)
		return true;

	return false;
}

function verifyLegal (inputField) 
{
	rc_num = inputField.value;
	rc_legal_chars = "'()_-.\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	rc_newnum = "";
	for ( rc_i = 0; rc_i < rc_num.length; rc_i++ ) {
		rc_char = rc_num.charAt( rc_i );
		if ( rc_legal_chars.indexOf( rc_char ) == -1 ) {
			alert ( "Invalid characters found. Please reenter." );
			inputField.focus();
			return false;
		}
	}
	return true;
}

function verifyZip1 (inputZip) 
{
	rc_num = inputZip.value;
	rc_number_chars = '0123456789-';
	rc_newnum = '';
//	rc_submit_OK = true;
	for ( rc_i = 0; rc_i < rc_num.length; rc_i++ ) {
		rc_char = rc_num.charAt( rc_i );
		if ( rc_number_chars.indexOf( rc_char ) != -1 ) {
			rc_newnum += rc_char;
		} 
	}
	if ( rc_newnum.length < 5 ) {
		alert ( "Please enter a valid zip code.\nThis must include only numeric characters and not less than 5 digits." );
		inputZip.focus();
		return false;
	}
	inputZip.value = rc_newnum;
		
	return true;
}

function verifyPhone (inputPhone) {
	rc_num = inputPhone.value;
	//rc_legal_chars = '()-. ';
	rc_number_chars = '0123456789';
	rc_newnum = '';
	rc_submit_OK = true;
	for ( rc_i = 0; rc_i < rc_num.length; rc_i++ ) {
		rc_char = rc_num.charAt( rc_i );
		if ( rc_number_chars.indexOf( rc_char ) != -1 ) {
			rc_newnum += rc_char;
		} else  {
			alert ( "Invalid telephone number: \nPlease enter numeric characters only (0-9)." );
			inputPhone.focus();
			return false;
		}
	}
	if ( rc_newnum.length < 10 ) {
		alert ( "Please enter a valid telephone number.\nThis should include your area code." );
		inputPhone.focus();
		return false;
	}
	inputPhone.value = rc_newnum;
	return true;
}

function verifyFaxnbr (inputFax) {
	rc_num = inputFax.value;
	//rc_legal_chars = '()-. ';
	rc_number_chars = '0123456789';
	rc_newnum = '';
	rc_submit_OK = true;
	for ( rc_i = 0; rc_i < rc_num.length; rc_i++ ) {
		rc_char = rc_num.charAt( rc_i );
		if ( rc_number_chars.indexOf( rc_char ) != -1 ) {
			rc_newnum += rc_char;
		} else  {
			alert ( "Invalid fax number: \nPlease enter numeric characters only (0-9)." );
			inputFax.focus();
			return false;
		}
	}
	if ( rc_newnum.length < 10 ) {
		alert ( "Please enter a valid fax number.\nThis should include your area code." );
		inputFax.focus();
		return false;
	}
	inputFax.value = rc_newnum;
	return true;
}

function fneMailCheck(s)
{
//	var s = document.frmMyInfo.email.value;

// 091602 hrn removed email as required field per Deborah's request
//	if(s.length == 0)
//	{
//		alert("Please enter an e-mail address");
//		document.frmMyInfo.email.focus();
//		return false;
//	}

//there must be >= 1 character before @, so we start looking at character position 1

var i=1;
var sLength=s.value.length;

//look for @

	while((i<sLength) && (s.value.charAt(i) != "@"))
	{
		i++;
	}

	if((i>=sLength) || (s.value.charAt(i) != "@")) 
	{
		alert("Please check e-mail address format");
		s.focus();
		return false;
	}
	else
	{
		 i+= 2;
	}

// look for .
	while((i<sLength) && (s.value.charAt(i) != "."))
	{
		i++;
	}

//there must be at least one character after the .
	if((i>=sLength - 1) || (s.value.charAt(i) != ".")) 
	{
		alert("Please check e-mail address format");
		s.focus();
		return false;
	}
	else
	{
		return s.value;
	}

}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isNum(passedVal)
{
	if(passedVal == "")
	{
		return false;
	}
	for(i=0;i<passedVal.length;i++)
	{
		if(passedVal.charAt(i) < "0")
		{
			return false;
		}
		if(passedVal.charAt(i) > "9")
		{
			return false;
		}
	}
	return true;
}
