
var xx = 0;

// ## Misc Functions ################################################

function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement){
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



// ## State Display Functionality ################################################

function fnPrepareStates(){
	if(!document.getElementById) return false;
	if(!$("content_statesSelect")) return false;
	
	var targetList = $("content_statesSelect");
	
	if(targetList.hasChildNodes){
		var tl_child = targetList.childNodes;
		
		for(var i=0; i<tl_child.length; i++){
			if(tl_child[i].nodeName == "UL"){
				var targetTag = tl_child[i];
				
				targetTag.style.height = "110px";
				targetTag.style.overflow = "hidden";
			}
			
			if(tl_child[i].nodeName == "H3"){
				var targetTag = tl_child[i];
				
				targetTag.style.cursor = "pointer";
				targetTag.onclick = function(){
					fnShowStates(this, "show");
				}
			}
			
		}
	}
}	

function fnShowStates(targetWhat, doWhat){
	if(!document.getElementById) return false;
	
	var targetParent = targetWhat.parentNode;	
	
	if(targetParent.hasChildNodes){
		var tl_child = targetParent.childNodes;
		
		for(var i=0; i<tl_child.length; i++){
			if(tl_child[i].nodeName == "UL"){
				var targetTag = tl_child[i];
				
				if(doWhat == "show"){
					targetTag.style.height = "auto";
					targetTag.style.overflow = "auto";
				} else {
					targetTag.style.height = "110px";
					targetTag.style.overflow = "hidden";
				}
			}
			
			if(tl_child[i].nodeName == "H3"){
				var targetTag = tl_child[i];
				
				if(doWhat == "show"){
					targetTag.style.background = "url(images/hdr_searchAndOtherLinks_alt.gif) 0 0 no-repeat";
					targetTag.onclick = function(){
						fnShowStates(this, "hide");
					}
				} else {
					targetTag.style.background = "url(images/hdr_searchAndOtherLinks.gif) 0 0 no-repeat";
					targetTag.onclick = function(){
						fnShowStates(this, "show");
					}
				}
			}
		}
	}
}



// ## Print Functionality ################################################

function fnPrint() {
	window.print();
}

function fnAttachPrint(attachToWhat) {
	if(!document.getElementById) return false;
	
	var targetClass = document.getElementsByClassName(attachToWhat);
	
	for(var i = 0; i < targetClass.length; i++) {
		targetClass[i].onclick = function() {
			fnPrint();
			return false;
		}
	}
}



// ## Form Validation ################################################

function fnFormAttach (attachToWhat) {
	if(!document.getElementById) return false;
	//TODO: check for attacheToWhat on the page
	if(!$(attachToWhat)) return false;
	$(attachToWhat).onsubmit = function(){
		return fnValidateForm(this, this.parentNode);		
	}
}

function fnValidateForm(validateWhat, parentEle) {
	var errors='';
	var emailFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var poboxFilter = /^([Pp]\.{0,1}[Oo]\.{0,1} *[Bb][Oo][Xx] *\d{1,5})/;
	
	var targetForm = $(validateWhat);
	
	if(targetForm.id == "form_franchiseSearch") {
		if ($F("dd_selectIndustry") == "-1") {//check to see if industry is selected
			if($F("dd_selectInvestment") == "-1") {//if not check to see if investment level is selected
				if($F("dd_selectLocation") == "-1") {//if not check to see if location is selected
					if($F("input_keyword") == "Enter Keyword" || $F("input_keyword") == "") {//if not check to see if location is selected
						//if none are selected then generate an error message
						errors = 'Please Select an Industry, Investment Level, or a Location';
						
						//create an element that will hold our error
						if(parentEle.nodeName != "DIV"){//since our from appears in a few places, we only want to create the element if it is in a convient location
							alert(errors);//if the parent node is anything other than a div, then we just display an alert
						} else {//if it is a div then we create an element and place our error message in it
							var errorElement = document.createElement("p");
							errorElement.setAttribute("id", "errorElement");
							errorElement.className = "error";
							var errorElementContent = document.createTextNode(errors);
							errorElement.appendChild(errorElementContent);
							
							parentEle.insertBefore(errorElement,targetForm);
						}
						
						return false;//return false to make sure that the form doesn't process
					}
				}
			}	
			
		} else {
			return true;//if all is ok, then we process the form
		}
	} else if (targetForm.id == "form_leadCapture") {//we can use this validation for other forms too
		//|| $F("input_phone1") == ""  || $F("input_phone2") == ""  || $F("input_phone3") == ""  
		if ($F("input_lastName") == "" || $F("input_firstName") == "" || $F("input_emailAddr1") == "" )  {
			alert("Please complete all the (*) fields");
			return false;	
		} else {
			
			var str = $F("input_lastName");
			if(!chkSandC(str)) { 
				alert("Please enter the correct last name");
				return false;
			}
			
			var fname = $F("input_firstName");
			if(!chkSandC(fname)){ 
				alert("Please enter the correct first name");
				return false;
			} 
			
			if($F("input_phone1") != "" || $F("input_phone2") != "" || $F("input_phone3") != ""){
				var phone_num1 = $F("input_phone1");
				if(!IsNumeric(phone_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var phone_num2 = $F("input_phone2");
				if(!IsNumeric(phone_num2)){ 
					alert("Please correct the area code");
					return false;
				}
				
				var phone_num3 = $F("input_phone3");
				if(!IsNumeric(phone_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_ext = $F("input_phoneEx");
				if($F("input_phoneEx") != "") {
					if(!IsNumeric(phone_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
			
			var email = $F("input_emailAddr1");
			//alert(email)
			if( emailCheck(email) == true ){ 
				return true;
			} else {		
				return false;
			}
			
		}
		//return false;  
	} else if (targetForm.id == "form_leadCapture_detail") {//we can use this validation for other forms too
		
		if ($F("input_lastName") == "" || $F("input_firstName") == "" || $F("input_phone1") == ""  || $F("input_phone2") == ""  || $F("input_phone3") == ""  || $F("input_emailAddr1") == "" || $F("input_addr1") == "" || $F("input_city") == "" || $F("input_zip") == "")  { 
			alert("Please complete all the (*) fields");
			return false;	
		} else {
			
			var str = $F("input_lastName");
			if(!chkSandC(str)) { 
				alert("Please enter the correct last name");
				return false;
			}
			
			var fname = $F("input_firstName");
			if(!chkSandC(fname)){ 
				alert("Please enter the correct first name");
				return false;
			} 
			
			if($F("input_phone1") != "" || $F("input_phone2") != "" || $F("input_phone3") != ""){
				var phone_num1 = $F("input_phone1");
				if(!IsNumeric(phone_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var phone_num2 = $F("input_phone2");
				if(!IsNumeric(phone_num2)){ 
					alert("Please correct the area code");
					return false;
				}
				
				var phone_num3 = $F("input_phone3");
				if(!IsNumeric(phone_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_ext = $F("input_phoneEx");
				if($F("input_phoneEx") != "") {
					if(!IsNumeric(phone_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
			
			if($F("alternate_phone1") != "" || $F("alternate_phone2") != "" || $F("alternate_phone3") != "") {			
				var alt_num1 = $F("alternate_phone1");
				if(!IsNumeric(alt_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var alt_num2 = $F("alternate_phone2");
				if(!IsNumeric(alt_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alt_num3 = $F("alternate_phone3");
				if(!IsNumeric(alt_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alt_ext = $F("alternate_phoneEx");
				if($F("alternate_phoneEx") != "") {				
					if(!IsNumeric(alt_ext)){ 
						alert("Please ckect the extension");
						return false;
					}
				}
			}
			
			var email = $F("input_emailAddr1");
			if( emailCheck(email) == false ){ 
				return false;
			} 
			
			var addr1 = $F("input_addr1");
			if(!chkSNC(addr1)) { 
				alert("Please enter the address fields");
				return false;
			}
			
			var str = $F("input_city");
			if(!chkSandC(str)) { 
				alert("Please enter the correct city name");
				return false;
			}
			
			str = $F("input_zip");
			if(!chkSNC(str)) { 
				alert("Please enter the correct zip code");
				return false;
			}
			
			if($F("input_state") == "-1") { 
				alert("Please select the state");
				return false;
			}
			
			if($F("input_contactTime") == "-1") { 
				alert("Please select contact time");
				return false;
			}
			
			if($F("input_investTimeFrame") == "-1") { 
				alert("Please select contact time");
				return false;
			}
			
			if($F("input_capital") == "-1") { 
				alert("Please select capital available");
				return false;
			}
			
			return true;
			
		}
		return false;
	} else if (targetForm.id == "form_stayInformed") {// form_stayInformed we can use this validation for other forms too
		//alert($F("input_emailAddr"))
		var email = $F("input_emailAddr");
			if( emailCheck(email) == false ){ 
				return false;
		}
		return true; 
	} else if (targetForm.id == "newsletterSignup_form") {// newsletterSignup_form we can use this validation for other forms too
		var email = $F("input_emailAddr");
			if( emailCheck(email) == false ){ 
				return false;
		}
		return true;
	} else if (targetForm.id == "franchisors_leadCapture") { // franchisors_leadCapture we can use this validation for other forms too
		if ($F("input_lastName") == "" || $F("input_firstName") == "" || $F("input_emailAddr1") == "" || $F("company_name") == "" )  { 
			alert("Please complete all the (*) fields");
			return false;	
		} else {
			var str = $F("input_firstName");
			if(!chkSandC(str)) { 
				alert("Please enter the correct first name");
				return false;
			}
			
			var fname = $F("input_lastName");
			if(!chkSandC(fname)){ 
				alert("Please enter the correct last name");
				return false;
			} 
			
			var cname = $F("company_name");
			if( !chkSandC(cname) ){ 
				alert("Please check the company name");
				return false;
			}
			
			var email = $F("input_emailAddr1");
			if( emailCheck(email) == false ){ 
				return false;
			} 
			
			if($F("input_phone1") != "" || $F("input_phone2") != "" || $F("input_phone3") != ""){
				var phone_num1 = $F("input_phone1");
				if(!IsNumeric(phone_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var phone_num2 = $F("input_phone2");
				if(!IsNumeric(phone_num2)){ 
					alert("Please correct the area code");
					return false;
				}
				
				var phone_num3 = $F("input_phone3");
				if(!IsNumeric(phone_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_ext = $F("input_phoneEx");
				if($F("input_phoneEx") != "") {
					if(!IsNumeric(phone_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
			
			
			if($F("alternate_phone1") != "" || $F("alternate_phone2") != "" || $F("alternate_phone3") != "") {			
				var alt_num1 = $F("alternate_phone1");
				if(!IsNumeric(alt_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var alt_num2 = $F("alternate_phone2");
				if(!IsNumeric(alt_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alt_num3 = $F("alternate_phone3");
				if(!IsNumeric(alt_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alt_ext = $F("alternate_phoneEx");
				if($F("alternate_phoneEx") != "") {				
					if(!IsNumeric(alt_ext)){ 
						alert("Please ckect the extension");
						return false;
					}
				}
			}
		/*	
			if ($F("input_addr1") != "" || $F("input_city") != "" || $F("input_zip") != "" || $F("input_state") != "-1" ) { 
				var addr1 = $F("input_addr1");
				if(!chkSNC(addr1)) { 
					alert("Please complete the address fields");
					return false;
				}
								
				var str = $F("input_city");
				if(!chkSNC(str)) { 
					alert("Please enter the correct city name");
					return false;
				}
				
				var zip = $F("input_zip");
				if(!chkSNC(zip)) { 
					alert("Please enter the correct zip");
					return false;
				}
				
				if($F("input_state") == "-1") { 
					alert("Please select the state");
					return false;
				}
			} // END IF IN ELSE PART
			*/
		}
		return true;
			
			
	} else if (targetForm.id == "form_leadCapture_aboutUs") {// form_leadCapture_aboutUs we can use this validation for other forms too
		if ($F("input_lastName") == "" || $F("input_firstName") == "" || $F("input_emailAddr1") == "" || $F("input_iam") == "-1" )  {
			alert("Please complete all the (*) fields");
			return false;	
		} else {
			
			var str = $F("input_lastName");
			if(!chkSandC(str)) { 
				alert("Please enter the correct last name");
				return false;
			}
			
			var fname = $F("input_firstName");
			if(!chkSandC(fname)){ 
				alert("Please enter the correct first name");
				return false;
			} 
			
			var email = $F("input_emailAddr1");
			//alert(email)
			if( emailCheck(email) == false ){ 
				return false;
			} 
			
			if($F("input_phone1") != "" || $F("input_phone2") != "" || $F("input_phone3") != ""){
				var phone_num1 = $F("input_phone1");
				//alert("HERE")
				if(!IsNumeric(phone_num1)){ 
					
					alert("Please check the area code");
					return false;
				}
				
				var phone_num2 = $F("input_phone2");
				if(!IsNumeric(phone_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_num3 = $F("input_phone3");
				if(!IsNumeric(phone_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_ext = $F("input_phoneEx");
				if($F("input_phoneEx") != "") {
					if(!IsNumeric(phone_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
			
			if($F("alternate_phone1") != "" || $F("alternate_phone2") != "" || $F("alternate_phone3") != ""){
				var alternate_num1 = $F("alternate_phone1");
				if(!IsNumeric(alternate_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var alternate_num2 = $F("alternate_phone2");
				if(!IsNumeric(alternate_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alternate_num3 = $F("alternate_phone3");
				if(!IsNumeric(alternate_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alternate_ext = $F("alternate_phoneEx");
				if($F("alternate_phoneEx") != "") {
					if(!IsNumeric(alternate_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
		}
		return true;
	}  else if (targetForm.id == "franchisors_leadCapture_zorInfo") {// franchisors_leadCapture_zorInfo we can use this validation for other forms too
		if ($F("input_lastName") == "" || $F("input_firstName") == "" || $F("input_emailAddr1") == "" || $F("company_name") == "" )  {
			alert("Please complete all the (*) fields");
			return false;	
		} else {
			
			var str = $F("input_lastName");
			if(!chkSandC(str)) { 
				alert("Please enter the correct last name");
				return false;
			}
			
			var fname = $F("input_firstName");
			if(!chkSandC(fname)){ 
				alert("Please enter the correct first name");
				return false;
			} 
			
			var cname = $F("company_name");
			if(!chkSandC(cname)){ 
				alert("Please check the company name");
				return false;
			}  
			
			var email = $F("input_emailAddr1");
			//alert(email)
			if( emailCheck(email) == false ){ 
				return false;
			} 
			
			if($F("input_phone1") != "" || $F("input_phone2") != "" || $F("input_phone3") != ""){
				var phone_num1 = $F("input_phone1");
				if(!IsNumeric(phone_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var phone_num2 = $F("input_phone2");
				if(!IsNumeric(phone_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_num3 = $F("input_phone3");
				if(!IsNumeric(phone_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var phone_ext = $F("input_phoneEx");
				if($F("input_phoneEx") != "") {
					if(!IsNumeric(phone_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
			
			if($F("alternate_phone1") != "" || $F("alternate_phone2") != "" || $F("alternate_phone3") != ""){
				var alternate_num1 = $F("alternate_phone1");
				if(!IsNumeric(alternate_num1)){ 
					alert("Please check the area code");
					return false;
				}
				
				var alternate_num2 = $F("alternate_phone2");
				if(!IsNumeric(alternate_num2)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alternate_num3 = $F("alternate_phone3");
				if(!IsNumeric(alternate_num3)){ 
					alert("Please correct the phone number");
					return false;
				}
				
				var alternate_ext = $F("alternate_phoneEx");
				if($F("alternate_phoneEx") != "") {
					if(!IsNumeric(alternate_ext)){ 
						alert("Please check the extension");
						return false;
					}
				}
			}
		}
		return true;
	} else if (targetForm.id == "some_form") {// franchisors_leadCapture_zorInfo we can use this validation for other forms too
		//some other form validation....
	}
	
}

function chkSandC (str) {
    var allSpaces = true;
	var good = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	for(i=0; i<str.length; i++) {
		if(good.indexOf(str.charAt(i)) != -1){
			if(allSpaces) { 
				if(str.charAt(i) != ' ') {
					allSpaces = false;
				}
			}
		}
	}
   
   if(allSpaces) return false;
   return true;
}

function chkSNC (str) {
    var allSpaces = true;
	var good = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	for(i=0; i<str.length; i++) {
		if(good.indexOf(str.charAt(i)) != -1){
			if(allSpaces) { 
				if(str.charAt(i) != ' ') {
					allSpaces = false;
				}
			}
		}
	}
   
   if(allSpaces) return false;
   return true;
}

function chkNMSNC (str) {
    var allSpaces = true;
	var good = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	for(i=0; i<str.length; i++) {
		if(good.indexOf(str.charAt(i)) != -1){
			if(allSpaces) { 
				if(str.charAt(i) != ' ') {
					allSpaces = false;
				}
			}
		}
	}
   
   if(allSpaces) return true;
   return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function emailCheck (emailStr) {
	//alert(emailStr);
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	
	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */
	
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
}

var user=matchArray[1];
var domain=matchArray[2];
	
// Start by checking that only basic ASCII characters are in the strings (0-127).
	
for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		alert("Ths username contains invalid characters.");
		return false;
   }
}
	
for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
		alert("Ths domain name contains invalid characters.");
		return false;
   }
}
	
// See if "user" is valid 
	
if (user.match(userPat)==null) {	
	// user is not valid
	
	alert("The username doesn't seem to be valid.");
	return false;
}
	
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
	
var IPArray=domain.match(ipDomainPat);

if (IPArray!=null) {
	// this is an IP address
	
	for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
			alert("Destination IP address is invalid!");
			return false;
	   }
	}
	
	return true;
}
	
// Domain is symbolic name.  Check if it's valid.
	 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		return false;
   }
}
	
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */
	
if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
}
	
// Make sure there's a host name preceding the domain.
	
if (len<2) {
	alert("This address is missing a hostname!");
	return false;
}
	
	// If we've gotten this far, everything's valid!
	return true;
}

// ## Form Narrow Industry Display Functionality ################################################

function fnAttachNarrowResults (attachToWhat) {	
	if(!document.getElementById) return false;
	
	var targetEl = $(attachToWhat);
	
	targetEl.onchange = function () {
		xx = 0;
		var ind_value = targetEl.value;
		var narrowSelect = '<select id="dd_narrowSelect" class="secondarySelect" name="dd_narrowSelect"><option value="-1">Select Sub Industry:</option><option value="0">All:</option>';
		var narrowSelectEnd = '</select>';
		var txt="";
		for( i=0; i< sub_industries.length; i++) {
			var array = sub_industries[i];
			if(ind_value == array[2]){
				xx = 1;
				txt  = txt.concat('<option value='+sub_industries[i][0]+'>'+sub_industries[i][1]+'</option>');
			}
			
		}
		if( xx == 1) $("narrowIndustryContainer").innerHTML = narrowSelect+txt+narrowSelectEnd;
		else $("narrowIndustryContainer").innerHTML ="";

	}

}

// ## Some fancy form stuff ################################################# 

function fnContactZor() {//sets focus when item is clicked
	if(!document.getElementById) return false;
	
	var targetEl = $("btn_requestInfo");
	
	if(!targetEl) return false;
	
	targetEl.onclick = function(){
		$("input_firstName").focus();
		return false;
	}
	
}

function fnPhNumbersJog(){
	if(!document.getElementById) return false;
	
	var phoneCycle = document.getElementsByClassName("phone_field");
	
	for(var i=0; i<phoneCycle.length; i++){
		var inputElements = phoneCycle[i].getElementsByTagName("input");
		
		for(var j=0; j<inputElements.length; j++){
			if(inputElements[j].className != "ex_input"){
				if(inputElements[j].id != "input_phone3"){
					if(inputElements[j].id != "alternate_phone3"){
						inputElements[j].onkeyup = function(){
							//fnAutoTab(this);
							if(this.value.length == this.maxLength){
								var curName = this.id;
								var baseName = curName.substring(0,curName.length-1);
								var baseNum = curName.substring(curName.length-1);
								var setNum = Number(baseNum) + 1;
								
								var nextNodeSet = baseName + setNum;
								$(nextNodeSet).focus();
							}
						}
					}
						
				}
				
			}
			
		}
	}
	
	//alert(inputElements.length);
	//alert(phoneCycle.length);
}


// ## Page Load Events ################################################

//TODO: comment out addLoadEvent(fnPrepareStates);
//addLoadEvent(fnPrepareStates);
addLoadEvent(function() {
	fnAttachPrint("btn_print");
	fnAttachNarrowResults("dd_selectIndustry");
	fnFormAttach("form_franchiseSearch");
	fnFormAttach("form_leadCapture");
	fnFormAttach("form_leadCapture_detail");
	fnFormAttach("franchisors_leadCapture");
	fnFormAttach("form_stayInformed");
	fnFormAttach("newsletterSignup_form");
	fnFormAttach("form_leadCapture_aboutUs");
	fnFormAttach("franchisors_leadCapture_zorInfo");
	fnContactZor();
	fnPhNumbersJog();
});
