// JavaScript Functions
// CopyRight 2004 Dimension Ventures Inc.

//SITE URLS FOR TITLE INSURANCE DROP DOWN MENU
var BASE_URL_JS = "http://www.invtitle.com/";
var NC_URL_JS = "http://nc.invtitle.com/";
var SC_URL_JS = "http://sc.invtitle.com/";

/* This method resizes the popup window according to the screen resoltion */ 
function popupWithRes(url, name, width, height){
	var w = screen.width;
	if (w<850) {
		popup(url, name, 650, 500);
		//window.open('cat.html','cat','width=650,height=500,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	}
	else if (w>=850 && w<1200){
		popup(url, name, 650, 625)
		//window.open('hat.html','hat','width=650,height=500,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	}
	else {
		popup(url, name, 700, 850)
		//window.open('mat.html','mat','width=650,height=500,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	}
}

/* This method opens a new popup window */
function popup(url, name, width, height) {
settings="toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width="+width+",height="+height;

MyNewWindow=window.open(url,name,settings);
MyNewWindow.focus()
}

function mmLoadMenus() {
	if (window.mm_menu_0616180207_0) return;
    window.mm_menu_0616180207_0_1 = new Menu("Choose a state",120,15,"Verdana, Arial, Helvetica, sans-serif",11,"#666666","#ffffff","#ffffff","#006666","left","middle",2,0,100,-5,7,true,true,true,0,false,true);
    mm_menu_0616180207_0_1.addMenuItem("Alabama","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Georgia","window.open(BASE_URL_JS+'contact/', '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Illinois","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Kentucky","window.open(BASE_URL_JS+'contact/', '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Louisiana","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Maryland","window.open(BASE_URL_JS+'contact/', '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Michigan","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Minnesota","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Mississippi","window.open(BASE_URL_JS+'contact/', '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Nebraska","window.open(BASE_URL_JS+'contact/', '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("New York","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("<b>North Carolina</b>","window.open(NC_URL_JS, '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Pennsylvania","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("<b>South Carolina</b>","window.open(SC_URL_JS, '_blank');");
    mm_menu_0616180207_0_1.addMenuItem("Tennessee","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("Virginia","window.open(BASE_URL_JS+'contact/', '_blank');");
	mm_menu_0616180207_0_1.addMenuItem("West Virginia","window.open(BASE_URL_JS+'contact/', '_blank');");

	mm_menu_0616180207_0_1.hideOnMouseOut=true;
    mm_menu_0616180207_0_1.bgColor='#006666';
    mm_menu_0616180207_0_1.menuBorder=1;
    mm_menu_0616180207_0_1.menuLiteBgColor='#ffffff';
    mm_menu_0616180207_0_1.menuBorderBgColor='#999999';
  	window.mm_menu_0616180207_0 = new Menu("root",110,15,"Verdana, Arial, Helvetica, sans-serif",11,"#666666","#ffffff","#ffffff","#006666","left","middle",2,0,100,-5,7,true,true,true,0,false,true);
  	mm_menu_0616180207_0.addMenuItem(mm_menu_0616180207_0_1,"location=''");
   	mm_menu_0616180207_0.hideOnMouseOut=true;
   	mm_menu_0616180207_0.childMenuIcon="http://www.invtitle.com/common/icons/arrows.gif";
   	mm_menu_0616180207_0.bgColor='#006666';
   	mm_menu_0616180207_0.menuBorder=1;
   	mm_menu_0616180207_0.menuLiteBgColor='#ffffff';
   	mm_menu_0616180207_0.menuBorderBgColor='#999999';
	
	mm_menu_0616180207_0.writeMenus();
} // mmLoadMenus()


//email format validation
function checkEmail(myField) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myField.value)){
		return (true)
	}
		alert("Invalid E-mail address! Please re-enter.")
		return (false)
}
// Check that s is integer.
function isInteger(s) {  
	var i;
	for (i = 0; i < s.length; i++) {   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
//this function use to validate form field
function form_field_validator(theForm) {
	var phonemsg = 'Please enter a 10 digit number including area code (eg. 9199289829)';
	if(theForm.fname.value == '') {
		alert("Please enter your First Name");
		theForm.fname.focus();
		return false;
	}
	if(theForm.lname.value == '') {
		alert("Please enter your Last Name");
		theForm.lname.focus();
		return false;
	}
//check for the phone number is integer
	if(theForm.phone.value != '') {
		var phone_no = theForm.phone.value;
		if(phone_no.length != 10) {
			alert(phonemsg);
			theForm.phone.focus();
			return false;
		}
		if(!isInteger(theForm.phone.value)){
			alert(phonemsg);
			theForm.phone.focus();
			return false;
		}
	}
//check for the fax number is integer
	if(theForm.fax.value != '') {
		if(!isInteger(theForm.fax.value)){
			alert(phonemsg);
			theForm.fax.focus();
			return false;
		}
		var fax_no = theForm.fax.value;
		if(fax_no.length != 10) {
			alert(phonemsg);
			theForm.fax.focus();
			return false;
		}
	}

	if(theForm.email.value == '') {
		alert("Please enter your email address");
		theForm.email.focus();
		return false;
	}
//check the Email Correct Format	
	if(!checkEmail(theForm.email)) {
			theForm.email.focus();
			return false;
	}

return true;
}

//validation for email and telephone number in exchange-form.php
function exchangeFormValidation(theForm){
	
	var phonemsg = 'Please enter a 10 digit number including area code (eg. 9199289829)';

	//check for the phone number is integer
	if(theForm.phone.value != '') {	
		var phone_no = theForm.phone.value;
		
		//Check weather telephone number count is 10 or not
		if(phone_no.length != 10) {
			alert(phonemsg);
			theForm.phone.focus();
			return false;
		}
		//check for the phone number is integer
		if(!isInteger(theForm.phone.value)){
			//alert("Phone number can only have numbers.");
			alert(phonemsg);
			theForm.phone.focus();
			return false;
		}
	}
	
	if(theForm.email.value != '') {	
	//check the Email Correct Format	
		if(!checkEmail(theForm.email)) {
			theForm.email.focus();
			return false;
		}
	}	
return true;
}	 //End function for exchange-form.php