function chkVal(strQ, strVal) {
		//alert('document.loan_search.' + strQ + '.value = "' + strVal + '"');
		eval('document.loan_search.' + strQ + '.value = "' + strVal + '"');
}

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour + minute + second +  ap;
   return timeString;
}


function hide(strDiv,blnHide){
    if (blnHide == 1) {
		document.getElementById(strDiv).style.display = 'none';
	} else {
		document.getElementById(strDiv).style.display = '';
	}
}

function validate(){
 var goforit = "";
 var retvalAmount = true;
 var retvalValue = true;

 if (document.all){
   data = document.loan_search;
 } else if (document.layers){
   data = document.loan_search;
 } else {
   data = document.loan_search;
 }


 if (data.state && data.state.type != "hidden") {
   if(data.state[data.state.selectedIndex].value == ""){
       alert("Please Select a state");
       //document.state.focus();
       return false;
    }   
 } 

if (data.loan_amount && data.loan_amount.type != "hidden") {   
	retvalAmount =  number_validation(data.loan_amount.value);
	if ((retvalAmount == "") || (data.loan_amount.value == 0)) {
	    alert("Please enter a valid loan amount.");
            data.loan_amount.value = "";
            data.loan_amount.focus();
            return false;
	} 
        data.loan_amount.value = retvalAmount;
}

if (data.property_value && data.property_value.type != "hidden") {
	retvalValue = number_validation(data.property_value.value);
	if ((retvalValue == "") || (data.property_value.value == 0)) {
            alert("Please enter a valid property value.");
	    data.property_value.value = "";
	    data.property_value.focus();
	    return false;
	}
        data.property_value.value = retvalValue;
}
  
//if (data.documentation_type[0] && data.documentation_type[1]) {
//	if (!data.documentation_type[0].checked && !data.documentation_type[1].checked) {
//         alert("Please enter a value for \'Can you document your income?\'.");
//	    return false;
//	}
//}

if (data.impounds) {
	if (data.impounds.length == 2) {
		if (!(data.impounds[0].checked) && !(data.impounds[1].checked) ) {
		    alert("Please enter a value for \'Will you be paying your taxes and insurance along with your mortgage payment?\'.");
			return false;
		}
	}
	if (data.impounds.length == 3) {
		var impCtr;
		var i;
		impCtr = 0;
		for (i=0; i < 3;i++) {
			if (data.impounds[i]) {
				if ( (data.impounds[i].type == "radio") && (data.impounds[i].checked) ) {
					impCtr = 1;
				}
			}
		}
		if (impCtr == 0) {
		     alert("Please enter a value for \'Will you be paying your taxes and insurance along with your mortgage payment?\'.");
			return false;		
		}
	}
	
}

   data.action = 'JProcess_Search.cfm?ts=' + getClockTime() + '&RequestTimeout=50000#anchResults';
   hide('pleaseWaitDiv',0);
   
   if (document.getElementById('ResultsDiv')) {
    //alert('ResultsDiv:' + document.getElementById('ResultsDiv').style.display);
   	hide('ResultsDiv',1);
   }
   if (document.getElementById('CostsDiv')) {
    //alert('costsdiv:' + document.getElementById('CostsDiv').style.display);
   	hide('CostsDiv',1);
   }
   if (document.getElementById('AssumptionsDiv')) {
    //alert('AssumptionsDiv:' + document.getElementById('AssumptionsDiv').style.display);
  	hide('AssumptionsDiv',1);
   }
   if (document.getElementById('MoreRatesDiv')) {
    //alert('MoreRatesDiv:' + document.getElementById('MoreRatesDiv').style.display);
  	hide('MoreRatesDiv',1);
   }
   
   data.submit();
   return true;
}

function number_validation(val){
   edited_value = '';
   var len=val.length;
   var dot_cntr = 0;

	for(var i=0;i<len;i++){
		if((val.charAt(i) >= 0 && val.charAt(i) <= 9) || val.charAt(i) == "."){
			if(val.charAt(i) == "." ){
				++dot_cntr;
				if(dot_cntr >= 2){
					alert("There are two decimals in the amount field, the amount field will be zeroed out.");
					edited_value = 0;
					break;
				}
			}
			val.value = '';
			edited_value = edited_value + val.charAt(i);
		}
  }
 return edited_value;
 }