// JavaScript Document
//tried to combine this with dropdown funtions--menu won't work unless code is in separate file

//this adjusts window to pictures width/height--need change all pages to use this
function openWin3(pic,w,h) {
  var features = "width="+ w + ",height=" + h + ",left=" + ((screen.width - w)/2) + ",top=" + ((screen.height - h)/2) + ",screenX=" + ((screen.width - w)/2) + ",screenY=" +((screen.height - h)/2);
 myWin = window.open(pic,"",features);
}

//foreign mailing address changes
function changeLabelForeignAddr(countryList,cityLabel,stateField,zipField){
  var selnewcountry = document.getElementsByName(countryList)[0].value;  //alternative finds value in IE
  var selnewcountry = document.getElementById(countryList);
  newcountry = document.getElementById(countryList).options[document.getElementById(countryList).selectedIndex].value;
  //alert(selnewcountry);
   if (newcountry == "United States") {
		document.getElementById(cityLabel).style.display = "none";   
		document.getElementById(stateField).style.display = "";
		document.getElementById(zipField).style.display = "";
               
   } else{
	   document.getElementById(cityLabel).style.display = "";  //display: City / Province / District / Locality
	   document.getElementById(stateField).style.display = "none";
	   document.getElementById(zipField).style.display = "none";
            document.forms[0].principalAddressState.selectedIndex = "";
	  // alert(document.forms[0].principalAddressState.selectedIndex);
    }
}


//Form check and general purpose functions
function checkPhone(phone){
	//phone numbers are accepted in the forms: (xxx)xxx-xxxx | xxx-xxx-xxxx | xxx xxx xxxx
	re = /^(\(\d{3})\)\d{3}-\d{4}$|^\d{3}-\d{3}-\d{4}$|^\d{3}\s\d{3}\s\d{4}$/;
	return re.test(phone);
}
function checkForeignPhone(phone) {
	//regex = /^[1-9]+[0-9]*$/;   num >0 only
	regex = /^([0-9\(\)\/\+ \-\.]*)$/;  
	return regex.test(phone);
}

function foreignPhoneNumber(phone){
	if(document.forms[0].cbxForeignPhoneNumber.checked == true){
		document.getElementById('USphone').style.display = "none";//hide US input box
		document.getElementById('foreignPhone').style.display = "";//display foreign input box
	} else{
		document.getElementById('USphone').style.display = "";//display US input box
		document.getElementById('foreignPhone').style.display = "none";//hide foreign input box
	}
}


    function checkEmail(email){
	    //email = document.getElementById("email");
		email = email.toLowerCase();
		re = /^.+@[^\.].*\.[a-z]{2,}$/;
		return re.test(email);
	}
    function verifyEmail(){
	   var email = document.getElementById("email").value;
	   var emCheck = document.getElementById("emCheck").value;
	   //alert("emCheck" + document.getElementById("emCheck").value);
	   if (email != emCheck){
		 return false;
	   }else{
		 return true;
	   }
    }


    function checkZip(zip) {
	     re = /^\d{5}(-\d{4})?$|^ &/;
	     return re.test(zip);
	}
	

    //for contact form only
  	function checkForm(){
		var name = document.getElementById("name");
		var email = document.getElementById("email");
		//emCheck = document.getElementById("emCheck");
		contact = document.getElementById("contact");

		if (name.value.length == 0){
			alert("You must enter a name");
			return false;
		}
		//check principal address
		if (document.forms[0].principalAddressCountry.value =="United States"){
			if ((document.forms[0].principalAddress.value == "") || (document.forms[0].principalAddressCity.value == "") || (document.forms[0].principalAddressState.selectedIndex == "") || (document.forms[0].principalAddressZip.value == "") )	{
				alert("business address");
				return false;
		   }
		}
		if (document.forms[0].principalAddressCountry.value !="United States"){
			if ((document.forms[0].principalAddress.value == "") || (document.forms[0].principalAddressCity.value == "") ){
				alert("business address");
				return false;
			}
		}
		if(document.forms[0].cbxForeignPhoneNumber.checked == true){
		   phone = document.getElementById("phoneNumberforeign").value;
		   if (checkForeignPhone(phone) != true){                                                        //validate foreign number
				alert("Enter a valid phone number.");
			   return false;
		    }  
	    }else{
           phone = document.getElementById("phoneNumber").value;                                 //validate US number
		   if (checkPhone(phone) != true){
		     alert("Enter a valid phone number.");
			return false;
		   }
	    }
		
		if (checkEmail(email.value) != true){
			alert("You must enter a valid email.");
			return false;
		}
		
		if (verifyEmail() != true){
			alert("Enter the same email ");
			return false;
		}
		if (document.forms[0].service[0].checked != true && document.forms[0].service[1].checked != true && document.forms[0].service[2].checked != true && document.forms[0].service[3].checked != true && document.forms[0].service[4].checked != true && document.forms[0].service[5].checked != true){
			alert("select a service");
			return false;
		}
	}
	
	//end contact form code
     function checkBrowser(){
		 document.write("Browser CodeName: " + navigator.appCodeName);
		document.write("<br /><br />");
		document.write("Browser Name: " + navigator.appName);
		document.write("<br /><br />");
		document.write("Browser Version: " + navigator.appVersion);
		document.write("<br /><br />");
		document.write("Cookies Enabled: " + navigator.cookieEnabled);
		document.write("<br /><br />");
		document.write("Platform: " + navigator.platform);
		document.write("<br /><br />");
		document.write("User-agent header: " + navigator.userAgent);
	 }
	
////////////////////////  old link code -  don't use anymore. Doesn't validate.  Use the code below. ////////////////////	
	//no link display Does not include www
	function showLink(part1,part2,part3){
		var Link = part1+part2+part3;
		document.write("<a href='http://" + Link+  "' rel='nofollow' target='_blank'>"  );
		
	}
	//no link display and https Secure Does not include www. 
		function showLinkSecure(part1,part2,part3){
		var Link = part1+part2+part3;
		document.write("<a href='https://" + Link+  "' rel='nofollow' target='_blank'>"  );
		
	}

        //no link display. includes www
        function showL(part1,part2,part3){
		var Link = part1+part2+part3;
		document.write("<a href='http://www." + Link+  "' rel='nofollow' target='_blank'>"  );
		
	}
		//no link display and https Secure. includes www
	function showLSecure(part1,part2,part3){
		var Link = part1+part2+part3;
		document.write("<a href='https://www." + Link+  "' rel='nofollow' target='_blank'>"  );

}
/////////////////////////////////////////////////////////////////////////////////////////////

////////////////new link code.  Use this.  includes closing <a> tags. 
//includes www
function showST(part1, part2, part3) {
    var Link = part1 + part2 + part3;
    document.write("<a href='http://www." + Link + "' rel='nofollow' target='_blank'>http://www." + Link + "</a>");

}
// Does not include www
function showLinkST(part1,part2,part3){
				var Link = part1+part2+part3;
				document.write("<a href='http://" + Link+  "' rel='nofollow' target='_blank'>http://" + Link +"</a>" );
}

//https Secure Does not include www. 
	function showLSecureSTnoW(part1,part2,part3){
	var Link = part1+part2+part3;
	document.write("<a href='https://" + Link+  "' rel='nofollow' target='_blank'>https://" + Link +"</a>" );
}

//https Secure. includes www
function showLSecureST(part1,part2,part3){
	var Link = part1+part2+part3;
	document.write("<a href='https://www." + Link+  "' rel='nofollow' target='_blank'>https://www." + Link +"</a>" );
		}
//////////////////////////////////////////////////////
 
 //link to NW database. no link display and https Secure. includes www
	function showNWLSecure(){
		parent.location='https://www.llcagent.com/affiliate/login.asp'
		
	}


	//no email display, different name to not conflict with showRA() hardcoded on pages
	function showRAemail(){
		var Name="fo@northw";
		var Server="estregiste";
		var Link = Name+Server;
		document.write("<a href='mailto:in" + Link+  "redagent.com'>"  );
		document.write("in" + Link + "redagent.com");
		document.write("</a>");
	}

	//no email display
	function showEm(Name,Server){
		var Link = Name+Server;
		document.write("<a href='mailto:" + Link +  "'>"  );
		document.write(Link);
		document.write("</a>");
	}

function display(it,expand){
	   if(document.getElementById(expand).innerHTML == "+"){
		document.getElementById(it).style.display="";
		document.getElementById(expand).innerHTML = "-";
		//document.getElementById(expand).innerHTML = "&ndash;"; 
		
	   }
	   else{
		document.getElementById(it).style.display="none";
		document.getElementById(expand).innerHTML = "+";
		
	   }
	}

// help information pop up
var t=0;
function ShowTip(item) {
  if (!document.getElementById) return;
  thelink=document.getElementById(item);
  thetip=document.getElementById("tip-" + item);
  //thetip.style.left=thelink.offsetLeft + thelink.offsetWidth + 400;
  //thetip.style.top=thelink.offsetTop + 300;
  
  t=window.setTimeout("ShowIt(\""+item+"\");",500);
  thetip.style.backgroundColor="#FFD9B3";
}
function ShowIt(item) {
  t=0;
  thetip=document.getElementById("tip-" + item);
  thetip.style.visibility="visible";
}
function HideTip(item) {
  if (!document.getElementById) return;
  if (t) window.clearTimeout(t);
  thetip=document.getElementById("tip-" + item);
  thetip.style.visibility="hidden";
}

