// for master-register.cfm

function displayAddress(){
	if(document.getElementById('internationalAddress').checked){
		document.getElementById('FullAddressTr1').style.display = 'block';
		document.getElementById('FullAddressTr2').style.display = 'block';
		document.getElementById('USAddress1Tr1').style.display = 'none';
		document.getElementById('USAddress1Tr2').style.display = 'none';
		document.getElementById('USAddress2Tr1').style.display = 'none';
		document.getElementById('USAddress2Tr2').style.display = 'none';
		document.getElementById('USCityStateTr1').style.display = 'none';
		document.getElementById('USCityStateTr2').style.display = 'none';
	}else{
		document.getElementById('FullAddressTr1').style.display = 'none';
		document.getElementById('FullAddressTr2').style.display = 'none';
		document.getElementById('USAddress1Tr1').style.display = 'block';
		document.getElementById('USAddress1Tr2').style.display = 'block';
		document.getElementById('USAddress2Tr1').style.display = 'block';
		document.getElementById('USAddress2Tr2').style.display = 'block';
		document.getElementById('USCityStateTr1').style.display = 'block';
		document.getElementById('USCityStateTr2').style.display = 'block';
	}
}

function validateForm(){
	trueFalse = true;
	
	if(document.getElementById('Name').value == ''){
		alert('Please enter your name.');
		document.getElementById('Name').focus();
		trueFalse = false;
	}else if(document.getElementById('Company').value == ''){
		alert('Please enter your company.');
		document.getElementById('Company').focus();
		trueFalse = false;
	}else if(document.getElementById('Phone').value == ''){
		alert('Please enter your daytime phone.');
		document.getElementById('Phone').focus();
		trueFalse = false;
	/*}else if(IsNumeric(document.getElementById('Phone').value) == false){
		alert('Please enter a valid daytime telephone number.\nTelephone numbers must be numeric.\nExample: 333-333-3333');
		document.getElementById('Phone').focus();
		trueFalse = false;*/
	}else if(document.getElementById('Email').value == ''){
		alert('Please enter your email address.');
		document.getElementById('Email').focus();
		trueFalse = false;
	}else if(IsEmail(document.getElementById('Email').value) == false){
		alert('Please enter a valid email address.');
		document.getElementById('Email').focus();
		trueFalse = false;
	}else if(document.getElementById('Email').value != document.getElementById('ConfirmEmail').value){
		alert('The email and confirmation email you have entered does not match\nThe email address must be the same as your confirmation email address.');
		document.getElementById('Email').focus();
		trueFalse = false;
	}else if(document.getElementById('Password').value == ''){
		alert('Please enter a password.');
		document.getElementById('Password').focus();
		trueFalse = false;
	}else if(document.getElementById('Password').value.length < 6){
		alert('Password must be at least 6 characters long');
		document.getElementById('Password').focus();
		trueFalse = false;
	}else if(document.getElementById('Password').value != document.getElementById('ConfirmPassword').value){
		alert('The password and confirmation password you have entered does not match\nThe password must be the same as your confirmation password.');
		document.getElementById('Password').focus();
		trueFalse = false;
	}else if(validateRadio('frmRegister','AreYou') == false){
		alert('Please check one of the options to indicate who you are.');
		//document.frmRegister.AreYou[0].focus();
		trueFalse = false;
	}else if(validateCheckBoxes() == false){
		alert('Please check one of the options to indicate what you are interested in.');
		//document.frmRegister.AreYou[0].focus();
		trueFalse = false;
	}/*else if(document.getElementById('internationalAddress').checked == false){
		// US Address
		if(IsNumeric(document.getElementById('Zipcode').value) == false){
			alert('Please enter a valid zipcode.');
			document.getElementById('Zipcode').focus();
			trueFalse = false;
		}else if(document.getElementById('Zipcode').value.length > 0 && document.getElementById('Zipcode').value.length < 5){
			alert('Please enter a 5 digit zipcode.');
			document.getElementById('Zipcode').focus();
			trueFalse = false;
		}
	}*/
	
	
	// removed because was causing errors with URL string.
	//resetFormAction();
	
	return trueFalse;
}

function validateCheckBoxes() {
	if (document.getElementById('yourInterest_coupons').checked == false &&
		document.getElementById('yourInterest_rebates').checked == false &&
		document.getElementById('yourInterest_sweepstakes').checked == false &&
		document.getElementById('yourInterest_fulfillment').checked == false &&
		document.getElementById('yourInterest_promoPlan').checked == false &&
		document.getElementById('yourInterest_digiPromos').checked == false &&
		document.getElementById('yourInterest_other').checked == false) {
			//alert ('You didn\'t choose any of the checkboxes!');
			return false;
		} else {
			return true;
		}
	}


function validateRadio(thisForm,thisField) {
	
	
	radioIsChecked = false;
	tempFieldObj = 'document.'+thisForm+'.'+thisField;
	tempFieldObj = eval(tempFieldObj);
	
	for (i=tempFieldObj.length-1; i > -1; i--) {
		if (tempFieldObj[i].checked) {
			radioIsChecked = true;
			break;
		}
	}
	return radioIsChecked;
	
}

// removed because was causing errors with URL string.
function resetFormAction(){
	var newActionString = document.frmRegister.action + '?company=' + document.getElementById('Company').value + '&email=' + document.getElementById('Email').value
	document.frmRegister.action = newActionString;
}

function IsNumeric(strString)
//  check for valid numeric strings	
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   //if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
function IsEmail(entry){ 
	var rex= /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,5})(\]?)$/; 
	return rex.test(entry)
} 

