//Macromedia Functions
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showHideObj(id,visStr) { //showHide for style sheets
   if(visStr == 'show') this.document.getElementById(id).style.display='inline';
   else if(visStr == 'hide') this.document.getElementById(id).style.display='none';
}

function mmFocus(focus_state) {
        document.form1.agent_parentcompany.selectedIndex = focus_state;
}

function showhideDisplay(id) {
			if (this.document.getElementById(id).style.display=='none') {
				this.document.getElementById(id).style.display='inline'
				if (this.document.getElementById(id+"link") != undefined) {
					this.document.getElementById(id+"link").style.display='none';
				}
						
			} else {
				this.document.getElementById(id).style.display='none'
				if (this.document.getElementById(id+"link") != undefined) {
					this.document.getElementById(id+"link").style.display='inline';
				}
			}
		}

function showhideSelect(id,field,fieldid) { //id=hideshow,field=fieldlabel,fieldid=selectedindex
	if (this.document.getElementById(field).selectedIndex == fieldid) {
		showhideDisplay(id);
	} else {
		this.document.getElementById(id).style.display='none';
	}
}

function agentlocator() {
	var whichForm = 'agent_locator';
	theForm = document.forms[whichForm];
	if (!validZip(theForm.zip_code.value)) {
	        alert("Please enter a zip code.");
	        theForm.zip_code.focus();
		return (false);
	}
	if (theForm.type.options[theForm.type.selectedIndex].value==0) {
	        alert("Please select a type of insurance.");
		return (false);
	}
	document.getElementById("espera").innerHTML='<b><i><span style="font-size:15.0pt;color:red">Please wait...</span></i></b>';
	theForm.submit();
}

function validEmail(email) {
     invalidChars = " /:,;"
     if (email == "") {
                return (false);
     }
     for (i=0; i<invalidChars.length; i++) {
          badChar = invalidChars.charAt(i)
          if (email.indexOf(badChar,0) != -1) {
                return (false);
                }
    }
    atPos = email.indexOf("@",1)
    if (atPos == -1) {
                return (false);
    }
    if (email.indexOf("@",atPos+1) != -1) {
                return (false);
    }
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {
                return (false);
    }
    if (periodPos+3 > email.length) {
                return (false);
    }
    return (true);
}

function isNum(passedVal) {
	if (passedVal == "") {
		return (false); //check if passedVal empty then error
	}
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) < "0") {
			return (false);
		}
		if (passedVal.charAt(i) > "9") {
			return (false);
		}
	}
	return (true);
}
		
function validZip(inZip) {
 	if (inZip == "") { //check if Zip empty then error
 	   return (false);  
	}
	lenzip = inZip.length;
	if(lenzip!=5) { //check if Zip is 5-digit
	   return (false);
	}
	if (isNum(inZip)) { //check if Zip is numeric
		return (true);
	}
	return (false);
}

//###### STAGE 1  ####### ####### #######

//start autotab phone numbers, check phone fields
var isNav;
var isIE;

if (navigator.appName == "Netscape") {
	isNav = 0;
	document.captureEvents(Event.KEYPRESS);
} else if (navigator.appName == "Microsoft Internet Explorer") {
	isIE = 1;
} else {
	isIE = 1;
}

function checkKey(e) {
	var keyChar;

	if (isNav == 0) {
		if(e.which < 48 || e.which > 57) e.RETURNVALUE = false;
	} else {
		if(e.keyCode < 48 || e.keyCode > 57) e.returnValue = false;
	}
	
}

function isBlank(txt1, txt2, txt3, ptype) { //phone filter 1
	if ((txt1.value.length == 0) && (txt2.value.length == 0) && (txt3.value.length == 0)) {
		alert("Please enter your complete "+ptype+" number.\nStarting with the area code then "+ptype+" number.");
		txt1.focus();
		return (false);
	} 
	return (true);
}

function is10digitNew(txt1, txt2, txt3, ptype) { //phone filter 2
	if (txt1.value.length != 3) { 
		alert("Your "+ptype+" number must contain 10 digits.");
		txt1.focus();
		return (false);
	 } else if (txt2.value.length != 3) {
	  	alert("Your "+ptype+" number must contain 10 digits.");
		txt2.focus();
		return (false);
	 } else if (txt3.value.length != 4) {
	 	alert("Your "+ptype+" number must contain 10 digits.");
		txt3.focus();
		return (false);
	 }
	 return (true);
}
//end autotab numbers, check phone fields

function Validator1(form1) {

  if (form1.agent_firstname.value == "") {
    alert("Please enter a value for the first name.");
    form1.agent_firstname.focus();
    return (false);
  }

  if (form1.agent_lastname.value == "") {
    alert("Please enter a value for the last name.");
    form1.agent_lastname.focus();
    return (false);
  }

  if (form1.agent_agencyname.value == "") {
    alert("Please enter a value for the agency's company name.");
    form1.agent_agencyname.focus();
    return (false);
  }

  if (form1.agent_address.value == "") {
    alert("Please enter a value for the address.");
    form1.agent_address.focus();
    return (false);
  }

  // zip code must be numbers-only, 5-digit US format
  if (!validZip(form1.agent_zipcode.value)) {
    alert("Please enter your 5-digit zip code.\nUse numbers only. No dashes or letters.");
    form1.agent_zipcode.focus();
    form1.agent_zipcode.select();
    return (false);
  }

  if (!isBlank(form1.PhoneAreaCode, form1.PhonePrefix, form1.PhoneNumber, 'phone')) {
    return (false);
  }
  if (!is10digitNew(form1.PhoneAreaCode, form1.PhonePrefix, form1.PhoneNumber, 'phone')) {
	return (false);
  }
  if (!isBlank(form1.FaxAreaCode, form1.FaxPrefix, form1.FaxNumber, 'fax')) {
    return (false);
  }
  if (!is10digitNew(form1.FaxAreaCode, form1.FaxPrefix, form1.FaxNumber, 'fax')) {
	return (false);
  }
  
  if (!validEmail(form1.agent_email.value)) {
      alert("Please enter a valid email address.");
      form1.agent_email.focus();
      form1.agent_email.select();
      return (false);
  }
  
  if (form1.agent_email.value!=form1.agent_email2.value) {
      alert("Both email addresses must match.\nPlease verify your email address.");
      form1.agent_email2.focus();
      form1.agent_email2.select();
      return (false);	  
  }
  
  if ((!form1.type_auto.checked) && (!form1.type_home.checked) && (!form1.type_life.checked) && (!form1.type_health.checked) && (!form1.type_business.checked)) {
      alert("You must choose at least one type of insurance represented by your company.");
      return (false);	  
  } 
  
  captiveOption = -1;
  for (i=0; i<form1.agent_captive.length; i++) {
		if (form1.agent_captive[i].checked) {
			captiveOption = i;
		  }
  }
  if (captiveOption == -1) {
		alert("Please choose YES or NO for the captive agent question.");
		return (false);	
  }
  //if cativevalue = YES then require drop down menu selection
  if ((form1.agent_captive[0].checked) && (form1.agent_parentcompany.selectedIndex == 0)) {
      alert("Please choose your parent insurance company.");
	  //document.form1.agent_parentcompany.focus();
      return (false);	
  }
  if ((form1.agent_captive[0].checked) && (form1.agent_parentcompany.selectedIndex != 0)) {
      form1.mmParentCompanyIndex.value = form1.agent_parentcompany.selectedIndex;
  }
  return (true);
}
	
	
//###### STAGE 2  ####### ####### #######
function Validator2(form2) { 

  var mlic = form2.agent_license.value.length;
  if (mlic < 5) {
    alert("Please enter your complete license number.");
    form2.agent_license.focus();
    return (false);
  }
  
  var mpass = form2.agent_passwd.value.length;
  if ((mpass < 6) || (mpass > 16)) {
    	alert("Your password must be 6-16 characters.");
    	form2.agent_passwd.focus();
    	return (false);
  }
  //Also see http://hotwired.lycos.com/webmonkey/templates/print_template.htmlt?meta=/webmonkey/01/40/index3a_meta.html
  //O'Reilley sample below
  var illegalChars = /[\W_]/; // allow only letters and numbers
  if (illegalChars.test(form2.agent_passwd.value))  {
     alert("Only letters and numbers are allowed for passwords.");
	 form2.agent_passwd.focus();
	 return (false);
  }
  
  if (form2.agent_passwd.value!=form2.agent_passwd2.value) {
      alert("Both passwords must match.\nPlease verify both passwords.");
      form2.agent_passwd.focus();
      form2.agent_passwd.select();
      return (false);	  
  }
  
  if (form2.agent_sec_q.selectedIndex == 0) {
      alert("Please select a security question.");
      form2.agent_sec_q.focus();
      return (false);
  }
  //if securityselection = OTHER then require text box entry
  if ((form2.agent_sec_q.selectedIndex == 1) && (form2.agent_sec_q2.value == "Write your question here")) {
      alert("Please create in your custom security question.");
      form2.agent_sec_q2.focus();
      return (false);
  }
  //if security question is not OTHER, set agent_sec_q2 to NULL
  if (form2.agent_sec_q.selectedIndex != 1) {
     document.form2.agent_sec_q2.value = "";
  }
  
  if (form2.agent_sec_a.value == "") {
    alert("Please enter a value for the security answer.");
    form2.agent_sec_a.focus();
    return (false);
  }
   //if hear about us = OTHER then require text box entry
    if ((form2.agent_how_hear.selectedIndex == 1) && (form2.agent_how_hear2.value == "")) {
      alert("Please describe how you heard about us.");
      form2.agent_how_hear2.focus();
      return (false);
  }
  
    return (true);
} 

//###### STAGE 3 TERMS AND CONDIDTIONS ####### ####### #######
function Validator3(form3) {

  if ((!document.form3.agree.checked) && (!document.form3.disagree.checked)) {
	  alert("You must check if you agree or disagree with these policies and conditions.");
      return (false);	  
  }  
  
  return (true);
} 

function checkAgree(isState){
	if ((document.form3.agree.checked) && (document.form3.disagree.checked)) {
		alert("You may only check one box."); // remove both checks
		document.form3.agree.checked=false;
		document.form3.disagree.checked=false;
		return (false);	  
    } else {
	    if (isState=='agree'){
		document.form3.btnSubmit.disabled=false;
		document.form3.btnCancel.disabled=true;
	    } else {
		document.form3.btnSubmit.disabled=true;
		document.form3.btnCancel.disabled=false;
	    }
	}
	return (true);
}

//###### STAGE 5 PROFILE ####### ####### #######
function Validator5(form5) {

  emailOption = -1;
  for (i=0; i<form5.showemail.length; i++) {
		if (form5.showemail[i].checked) {
			emailOption = i;
		  }
  }
  if (emailOption == -1) {
		alert("Please choose YES or NO if you wish to display your email address with your profile.");
		return (false);	
  }

  websiteOption = -1;
  for (i=0; i<form5.websiteyes.length; i++) {
		if (form5.websiteyes[i].checked) {
			websiteOption = i;
		}
  }
  if (websiteOption == -1) {
		alert("Please choose YES or NO if you have a web site for your agency.");
		return (false);	
  }
 //if value = YES then require website entry
  if ((form5.websiteyes[0].checked) && (form5.websiteurl.value == "")) {
      alert("Please enter your web site address.");
      document.form5.websiteurl.focus();
      return (false);	
  }
  
  if (!document.form5.approvedhrs.checked)  {
      alert("Please check the box approving your hours of operation.");
      return (false);	  
  }  
  
  if ((!document.form5.lang_en.checked) && (!document.form5.lang_es.checked) && (!document.form5.lang_fr.checked) && (!document.form5.lang_it.checked) && (!document.form5.lang_pt.checked) && (!document.form5.lang_de.checked))  {
      alert("You must check at least one language spoken for your company profile.");
      return (false);	  
  }
  
  //if office is closed on certain day, set open/close values to null
  //0 mon
  for (i=0; i<form5.open0.length; i++) {
		if (form5.open0[i].checked) {
		    hrsOption0 = i;
		}
  }
  if (form5.open0[hrsOption0].value=="0") {
	document.form5.dayopen0.value = "00:00";
	document.form5.dayclose0.value = "00:00";	
  }
  //1 tues
  for (i=0; i<form5.open1.length; i++) {
		if (form5.open1[i].checked) {
		    hrsOption1 = i;
		}
  }
  if (form5.open1[hrsOption1].value=="0") {
	document.form5.dayopen1.value = "00:00";
	document.form5.dayclose1.value = "00:00";	
  }
  //2 wed
  for (i=0; i<form5.open2.length; i++) {
		if (form5.open2[i].checked) {
		    hrsOption2 = i;
		}
  }
  if (form5.open2[hrsOption2].value=="0") {
	document.form5.dayopen2.value = "00:00";
	document.form5.dayclose2.value = "00:00";	
  }
  //3 thurs
  for (i=0; i<form5.open3.length; i++) {
		if (form5.open3[i].checked) {
		    hrsOption3 = i;
		}
  }
  if (form5.open3[hrsOption3].value=="0") {
	document.form5.dayopen3.value = "00:00";
	document.form5.dayclose3.value = "00:00";	
  }
  //4 fri
  for (i=0; i<form5.open4.length; i++) {
		if (form5.open4[i].checked) {
		    hrsOption4 = i;
		}
  }
  if (form5.open5[hrsOption4].value=="0") {
	document.form5.dayopen4.value = "00:00";
	document.form5.dayclose4.value = "00:00";	
  }  
  //5 sat
  for (i=0; i<form5.open5.length; i++) {
		if (form5.open5[i].checked) {
		    hrsOption5 = i;
		}
  }
  if (form5.open5[hrsOption5].value=="0") {
	document.form5.dayopen5.value = "00:00";
	document.form5.dayclose5.value = "00:00";	
  }
  //6 sun
  for (i=0; i<form5.open6.length; i++) {
		if (form5.open6[i].checked) {
		    hrsOption6 = i;
		}
  }
  if (form5.open6[hrsOption6].value=="0") {
	document.form5.dayopen6.value = "00:00";
	document.form5.dayclose6.value = "00:00";	
  }
  
  return (true);
} 

//###### STAGE 1 LOST PASSWORD ####### ####### #######
function ValidReset1(reset1) {

  if (!validEmail(reset1.login.value)) {
      alert("Please enter a valid email address.");
      reset1.login.focus();
      reset1.login.select();
      return (false);
  }
  // zip code must be numbers-only, 5-digit US format
  if (!validZip(reset1.zipcode.value)) {
    alert("Please enter your 5-digit zip code.\nUse numbers only. No dashes or letters.");
    reset1.zipcode.focus();
	reset1.zipcode.select();
    return (false);
  }
  
 return (true);
} 
//###### STAGE 2 LOST PASSWORD ####### ####### #######
function ValidReset2(reset2) {

  if (reset2.agent_sec_a.value == "") {
    alert("Please enter a value for the security answer.");
    reset2.agent_sec_a.focus();
    return (false);
  }
  if (reset2.areacode.value == "") {
    alert("Please enter a value for the 3-digit phone area code.");
    reset2.areacode.focus();
    return (false);
  }

 return (true);
} 
//###### STAGE 4 LOST PASSWORD ####### ####### #######
function ValidReset4(reset4) {
  var mpass = reset4.agent_passwd.value.length;
  if ((mpass < 6) || (mpass > 16)) {
    	alert("Your password must be 6-16 characters.");
    	reset4.agent_passwd.focus();
    	return (false);
  }
  var illegalChars = /[\W_]/; // allow only letters and numbers
  if (illegalChars.test(reset4.agent_passwd.value))  {
     alert("Only letters and numbers are allowed for passwords.");
	 reset4.agent_passwd.focus();
	 return (false);
  }
  
  if (reset4.agent_passwd.value!=reset4.agent_passwd2.value) {
      alert("Both passwords must match.\nPlease verify both passwords.");
      reset4.agent_passwd.focus();
      reset4.agent_passwd.select();
      return (false);	  
  }

 return (true);
}

//###### EDIT CONTACT ####### ####### #######
function ValidEdit1(editContact) {

  if (editContact.agent_agencyname.value == "") {
    alert("Please enter a value for the agency's company name.");
    editContact.agent_agencyname.focus();
    return (false);
  }

  if (editContact.agent_address.value == "") {
    alert("Please enter a value for the address.");
    editContact.agent_address.focus();
    return (false);
  }

  // zip code must be numbers-only, 5-digit US format
  if (!validZip(editContact.agent_zipcode.value)) {
    alert("Please enter your 5-digit zip code.\nUse numbers only. No dashes or letters.");
    editContact.agent_zipcode.focus();
    editContact.agent_zipcode.select();
    return (false);
  }

  if (!isBlank(editContact.PhoneAreaCode, editContact.PhonePrefix, editContact.PhoneNumber, 'phone')) {
    return (false);
  }
  if (!is10digitNew(editContact.PhoneAreaCode, editContact.PhonePrefix, editContact.PhoneNumber, 'phone')) {
	return (false);
  }
  if (!isBlank(editContact.FaxAreaCode, editContact.FaxPrefix, editContact.FaxNumber, 'fax')) {
    return (false);
  }
  if (!is10digitNew(editContact.FaxAreaCode, editContact.FaxPrefix, editContact.FaxNumber, 'fax')) {
	return (false);
  }
  
  if (!validEmail(editContact.agent_email.value)) {
      alert("Please enter a valid email address.");
      editContact.agent_email.focus();
      editContact.agent_email.select();
      return (false);
  }
  
  if (editContact.agent_email.value!=editContact.agent_email2.value) {
      alert("Both email addresses must match.\nPlease verify your email address.");
      editContact.agent_email2.focus();
      editContact.agent_email2.select();
      return (false);	  
  }

}
//###### EDIT ABOUT ####### ####### #######
function ValidEdit2(editAbout) {

  if ((!editAbout.type_auto.checked) && (!editAbout.type_home.checked) && (!editAbout.type_life.checked) && (!editAbout.type_health.checked) && (!editAbout.type_business.checked)) {
	  alert("You must choose at least one type of insurance represented by your company.");
      return (false);	  
  } 
  
}
//###### EDIT PASSWORD ####### ####### #######
function ValidEdit3(editPass) {

  if (editPass.agent_passwd.value == "") {
    alert("Please enter a value for the old password.");
    editPass.agent_passwd.focus();
    return (false);
  }

  var mpass = editPass.agent_passwdN1.value.length;
  if ((mpass < 6) || (mpass > 16)) {
    	alert("Your new password must be 6-16 characters.");
    	editPass.agent_passwdN1.focus();
    	return (false);
  }
  
  var illegalChars = /[\W_]/; // allow only letters and numbers
  if (illegalChars.test(editPass.agent_passwdN1.value))  {
     alert("Only letters and numbers are allowed for passwords.");
	 editPass.agent_passwdN1.focus();
	 return (false);
  }
  
  if (editPass.agent_passwdN1.value!=editPass.agent_passwdN2.value) {
      alert("Both passwords must match.\nPlease verify both passwords.");
      editPass.agent_passwdN1.focus();
      editPass.agent_passwdN1.select();
      return (false);	  
  }
  
  if (editPass.agent_sec_q.selectedIndex == 0) {
      alert("Please select a security question.");
      editPass.agent_sec_q.focus();
      return (false);
  }
  //if securityselection = OTHER then require text box entry
  if ((editPass.agent_sec_q.selectedIndex == 1) && (editPass.agent_sec_q2.value == "Write your question here")) {
      alert("Please create in your custom security question.");
      editPass.agent_sec_q2.focus();
      return (false);
  }
  //if security question is not OTHER, set agent_sec_q2 to NULL
  if (editPass.agent_sec_q.selectedIndex != 1) {
      document.editPass.agent_sec_q2.value = "";
  }
    
  if (editPass.agent_sec_a.value == "") {
     alert("Please enter a value for the security answer.");
     editPass.agent_sec_a.focus();
     return (false);
  }

}
//######

// old obj js 
function show(obj,block) {
obj.style.visibility = 'visible';
if(block)obj.style.display = 'block';
}

function hide(obj,block) {
obj.style.visibility = 'hidden';
if(block)obj.style.display = 'none';
}



function checkAgentMail() {
var whichForm = 'agentmail';
var fields = '';
theform = document.forms[whichForm];
	
  if (!validEmail(theform.contactemail.value)) {
      alert("Please enter a valid email address.");
      theform.contactemail.focus();
      theform.contactemail.select();
      return (false);
  }
  
    return (true);
} 
