function movewin(win, width, height) {
	var fullWidth = screen.availWidth;
	var fullHeight = screen.availHeight;
	var x = (fullWidth / 2) - (width / 2);
	var y = (fullHeight / 2) - (height / 2);
	win.moveTo(x, y);
}

function viewWin(filenames, width, height) {
	filenames = filenames;

	var newwin = window.open(filenames, 'mydoc', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,maximize=0,width=' + width + ',height=' + height);

	movewin(newwin, width, height);
	if (navigator.appName == "Netscape")
		newwin.location = url;

	newwin.opener = window;
	newwin.focus();
	return false;
}



function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;

}

//Email check 
var testresults
function checkemail(email){
var str=email;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
 alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}

function chk_contact()
{
	var frm=document.contact;
	if(trimAll(frm.name.value)=="")
	{
		alert("Please enter your name");
		frm.name.focus();
		return false;
	}
	
	
if(trimAll(frm.email.value)=="")
	{
		alert("Please fill your Email.");
		frm.email.focus();
		return false;
	}
	else
		{
			var result;
			
			result=checkemail(frm.email.value);
			if(result)
			{
				//true
			}
			else
				{
			     frm.email.value="";
			     return result;
		     }
		}
	
	if(trimAll(frm.phone.value)=="")
	{
		alert("Please fill your phone number.");
		frm.phone.focus();
		return false;
	}
	
}

function chk_apply()
{
	var frm=document.apply;

	//agent name
	
	if(trimAll(frm.agent.value)=="")
	{
		alert("Please select agent.");
		frm.agent.focus();
		return false;
	}

	if(trimAll(frm.applicant_title.value)=="")
	{
		alert("Please select title.");
		frm.applicant_title.focus();
		return false;
	}
	//applicant_first_name
		if(trimAll(frm.applicant_first_name.value)=="")
	{
		alert("Please enter your first name.");
		frm.applicant_first_name.focus();
		return false;
	}
	//applicant_last_name
	
	if(trimAll(frm.applicant_last_name.value)=="")
	{
		alert("Please enter your last name.");
		frm.applicant_last_name.focus();
		return false;
	}
	//applicant_home_number
		if(trimAll(frm.applicant_home_number.value)=="")
	{
		alert("Please enter your home phone number.");
		frm.applicant_home_number.focus();
		return false;
	}
	
	//applicant_email
			if(trimAll(frm.applicant_email.value)=="")
	{
		alert("Please enter your email.");
		frm.applicant_email.focus();
		return false;
	}
	else
		{
			var result;
			
			result=checkemail(frm.applicant_email.value);
			if(result)
			{
				//true
			}
			else
				{
			     frm.applicant_email.value="";
			     return result;
		     }
		}
		
		//contact_method
		if(trimAll(frm.contact_method.value)=="")
			{
				alert("Please select contact method.");
				frm.contact_method.focus();
				return false;
			}
			//applicant_address
			
		if(trimAll(frm.applicant_address.value)=="")
			{
				alert("Please enter applicatn address.");
				frm.applicant_address.focus();
				return false;
			}
	 //applicant_city_town
	 	if(trimAll(frm.applicant_city_town.value)=="")
			{
				alert("Please enter  your city.");
				frm.applicant_city_town.focus();
				return false;
			}
	  //applicant_province
	  	if(trimAll(frm.applicant_province.value)=="")
			{
				alert("Please enter  your province.");
				frm.applicant_province.focus();
				return false;
			}
			//applicant_postal_code
			if(trimAll(frm.applicant_postal_code.value)=="")
			{
				alert("Please enter  your postal code.");
				frm.applicant_postal_code.focus();
				return false;
			}
			//contact_between1
				if(trimAll(frm.contact_between1.value)=="")
				{
					alert("Please enter  preferred contact time.");
					frm.contact_between1.focus();
					return false;
				}
				//contact_time1
				if(trimAll(frm.contact_time1.value)=="")
				{
					alert("Please select  preferred contact time.");
					frm.contact_time1.focus();
					return false;
				}
				//contact_between2
				
					if(trimAll(frm.contact_between2.value)=="")
				{
					alert("Please enter  preferred contact time.");
					frm.contact_between2.focus();
					return false;
				}
			//contact_time2
				if(trimAll(frm.contact_time2.value)=="")
				{
					alert("Please select  preferred contact time.");
					frm.contact_time2.focus();
					return false;
				}
				
				//preferred_day1
				if(trimAll(frm.preferred_day1.value)=="")
				{
					alert("Please select  preferred day to contact.");
					frm.preferred_day1.focus();
					return false;
				}
				
				//calling_location1
					if(trimAll(frm.calling_location1.value)=="")
				{
					alert("Please select  preferred location to contact.");
					frm.calling_location1.focus();
					return false;
				}

}
function chk_login()
{
     	var frm=document.login;
        	if(trimAll(frm.user_name.value)=="")
    		{
    			alert("Please enter your user name.");
    			frm.user_name.focus();
    			return false;
    		}

            	if(trimAll(frm.password1.value)=="")
    		{
    			alert("Please enter your password.");
    			frm.password1.focus();
    			return false;
    		}
}





