var agent = navigator.userAgent.toLowerCase();
var is_chrome = (agent.indexOf('chrome') != -1);
var is_ie = (agent.indexOf('msie') != -1);
function NewWindow(url,ht,wd,sc,rs,name){
	l = (screen.width) ? (screen.width-parseInt(wd))/2 : 0;
	t = (screen.height) ? (screen.height-parseInt(ht))/2 : 0;	
	param = "height=" + parseInt(ht) + ",width=" + parseInt(wd) + ",top=" + t + ",left=" + l + ",location=no,toolbar=no,status=no,menubar=no,scrollbars=" + sc + ",resizable=" + rs + ",copyhistory=no";			
	oc_infowin = window.open(url,name,param);
	if(oc_infowin != null){
		oc_infowin.opener = self;
	}
	oc_infowin.focus();
}
function Trim(strVal){
    var strMatch = strVal.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    result = (strMatch == null) ? "" : strMatch[1];
    return result;
}
function isEmail(objObject) {
	var regEmail, strValue;	
	regEmail =/^([A-Za-z0-9]{1})([A-Za-z0-9_.\-]*)([A-Za-z0-9]{1})(@)([A-Za-z0-9]{1})([A-Za-z0-9_.\-]*)([A-Za-z0-9]{1})(\.)([A-Za-z]{1})([A-Za-z]*)$/
	strValue = objObject.value;
	if (objObject.value == "") return true;
	if(! regEmail.test(strValue)) {
		objObject.focus();
		return false;
	}
	return true;
}
function doFORMFIELDS(objFIELDNAME){
	document.getElementById("mort_fields").style.display = "none";	
	document.getElementById("form-bottom-space").style.height = "73px";
	if(objFIELDNAME.name == "cmbHOME_STATUS"){
		if(objFIELDNAME.value == "Mortgaged Home"){
			document.getElementById("mort_fields").style.display = "block";
			if(is_chrome){
				document.getElementById("form-bottom-space").style.height = "23px";
			}else if(is_ie){
				document.getElementById("form-bottom-space").style.height = "23px";
			}else{
				document.getElementById("form-bottom-space").style.height = "25px";
			}
		}
	}
}
function doFORMVALIDATION(){
	var theForm = document.frmLOAN_APPLICATION;
	if(theForm.cmbLOAN_PURPOSE.selectedIndex <= 0){
		alert("Please select your purpose of loan.");
		document.getElementById("cmbLOAN_PURPOSE").style.backgroundColor = "#FEC2C2";
		theForm.cmbLOAN_PURPOSE.focus();		
		return false;
	}else{
		document.getElementById("cmbLOAN_PURPOSE").style.backgroundColor = "#FFFFFF";
	}
	if(theForm.cmbLOAN_AMOUNT.selectedIndex <= 0){
		alert("Please select your loan amount.");		
		document.getElementById("cmbLOAN_AMOUNT").style.backgroundColor = "#FEC2C2";
		theForm.cmbLOAN_AMOUNT.focus();
		return false;
	}else{
		document.getElementById("cmbLOAN_AMOUNT").style.backgroundColor = "#FFFFFF";
	}
	if((theForm.cmbHOME_STATUS.selectedIndex <= 0) || (Trim(theForm.cmbHOME_STATUS.value).length <= 0)){
		alert("Please select your residential status.");		
		document.getElementById("cmbHOME_STATUS").style.backgroundColor = "#FEC2C2";
		theForm.cmbHOME_STATUS.focus();
		return false;
	}else{
		document.getElementById("cmbHOME_STATUS").style.backgroundColor = "#FFFFFF";
	}
	if(theForm.cmbHOME_STATUS.selectedIndex > 0){
		if(theForm.cmbHOME_STATUS.value == "Mortgaged Home"){
			if(theForm.cmbPROPERTY_VALUE.selectedIndex <= 0){
				alert("Please select your property value.");				
				document.getElementById("cmbPROPERTY_VALUE").style.backgroundColor = "#FEC2C2";
				theForm.cmbPROPERTY_VALUE.focus();
				return false;
			}else{
				document.getElementById("cmbPROPERTY_VALUE").style.backgroundColor = "#FFFFFF";
			}
			if(theForm.cmbMORTGAGE_REMAINING.selectedIndex <= 0){
				alert("Please select your mortgage remaining.");				
				document.getElementById("cmbMORTGAGE_REMAINING").style.backgroundColor = "#FEC2C2";
				theForm.cmbMORTGAGE_REMAINING.focus();
				return false;
			}else{
				document.getElementById("cmbMORTGAGE_REMAINING").style.backgroundColor = "#FFFFFF";
			}
		}
	}
	if(Trim(theForm.txtFIRST_NAME.value).length == 0){
		alert("Please enter your first name.");		
		document.getElementById("txtFIRST_NAME").style.backgroundColor = "#FEC2C2";
		theForm.txtFIRST_NAME.focus();
		return false;
	}else{
		document.getElementById("txtFIRST_NAME").style.backgroundColor = "#FFFFFF";
	}
	if(Trim(theForm.txtSURNAME.value).length == 0){
		alert("Please enter your surname.");		
		document.getElementById("txtSURNAME").style.backgroundColor = "#FEC2C2";
		theForm.txtSURNAME.focus();
		return false;
	}else{
		document.getElementById("txtFIRST_NAME").style.backgroundColor = "#FFFFFF";
	}
	if(Trim(theForm.txtHOME_PHONE.value).length == 0){
		alert("Please enter your home phone number.");		
		document.getElementById("txtHOME_PHONE").style.backgroundColor = "#FEC2C2";
		theForm.txtHOME_PHONE.focus();
		return false;
	}else{
		document.getElementById("txtHOME_PHONE").style.backgroundColor = "#FFFFFF";
	}
	if(Trim(theForm.txtEMAIL_ADDRESS.value).length > 0){
		if(isEmail(theForm.txtEMAIL_ADDRESS) == false) {
			alert("Please enter your valid email address.\nFor Example: xyz@xyz.com");		
			document.getElementById("txtEMAIL_ADDRESS").style.backgroundColor = "#FEC2C2";
			theForm.txtEMAIL_ADDRESS.focus();
			return false;
		}else{
			document.getElementById("txtEMAIL_ADDRESS").style.backgroundColor = "#FFFFFF";
		}
	}
	theForm.hidACTION.value = "SubmitApplication";
	theForm.action = "formaction.php";
	return true;
}
