// JavaScript Document

var siteurl="http://www.mortgageforless.com/";
//var siteurl="http://192.168.1.150/matrix/mortgageforeless/development/";

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

//MM_preloadImages(siteurl+'images/submit.jpg',siteurl+'images/refresh.jpg');

//MM_preloadImages('images/submit.jpg');

//MM_preloadImages('images/refresh.jpg');



function validateapplyonline(thisform) { 
	with (thisform)
	{
	 	if (emptyvalidation(fname,"Please fill in your Name.")==false) 
		{
			fname.select();
			fname.focus();
			return false;
		}
		if (emptyvalidation(email,"Please fill in your Email Address.")==false) 
		{
			email.select();
			email.focus();
			return false;
		}
		if(emailvalidation(email)==false)
		{
			alert("Sorry, you have entered an invalid Email Address.");
			email.select();
			email.focus();
			return false;			
		}

		if (emptyvalidation(loanamount,"Please fill in your Mortgage Amount.")==false) 
		{
			loanamount.select();
			loanamount.focus();
			return false;
		}
		if (emptyvalidation(purpose,"Please select Purpose.")==false) 
		{
			purpose.focus();
			return false;
		}
		if (emptyvalidation(rating,"Please select Credit Rating.")==false) 
		{
			rating.focus();
			return false;
		}
		if (userdigit.value==userdigit.defaultValue || userdigit.value=="Invalid Verification Code") 
		{
			userdigit.value="";	
		}
		if(emptyvalidation(userdigit,"Please fill  Verification code.")==false)
		{
			userdigit.focus();
			return false;
		}
		runAjax1('check_captcha', siteurl+'process_mail.php',thisform.userdigit.value);
		return false; 
		
		//document.getElementById("loadimagenew").innerHTML='<img  src="images/loader2.gif" alt=""  />';

	

		

	} 
	return false;	
}


function emailvalidation(thisform) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = thisform.value;
   var email = address.split(',');
   for (var i = 0; i < email.length; i++) {
		if(reg.test(email[i]) == false) {
			return false;
		}
		else {
		}
   }
}

/********************Captch refresh ****************/

function captcha_refresh()  { 
	document.getElementById("button_div").src= siteurl+'button.php?'+Math.random();
	return false;
}

/********************** Ajax for checking the captcha code ends here *************/

var xmlHttp;

function runAjax1(field,argurl,argVal) {
	document.getElementById("load_send").innerHTML = "Loading...";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=argurl;
	url=url+"?userdigit="+argVal;
	url=url+"&sid="+Math.random();
	if(field=='check_captcha')
		xmlHttp.onreadystatechange=check_captcha;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null)
}

/************************check captcha ************************************/

function check_captcha()  { 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText=="yes") {
			document.getElementById("load_send").innerHTML = "Loading...";
			document.onlinecontact.submit();
			return flase;
		}
		else {

			document.getElementById("load_send").innerHTML=' <a href="#" class="button2_style" onClick="return validateapplyonline(document.onlinecontact)" title="SUBMIT"> Submit</a>';
			captcha_refresh();
			//document.onlinecontact.userdigit.focus();
			document.onlinecontact.userdigit.value= 'Invalid Verification Code';
			return false;
		}

	} 

} 

/******************** XMLHTTPObject ***************************/

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest)  {
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}


