// JavaScript Document

/* Form javascript start  */

function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];

	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}


function isBlank(C) {
	for (i=0;i<C.length;i++) {if (C.charAt(i) != " ") return false}
	return true;
}

function validate_app(dm) {
	var strError="";		
	if(isBlank(dm.printname.value))
	strError += "Print Name\n";		
	if(isBlank(dm.youremail.value)||checkEmail(dm.email.value)==0)
    strError += " Enter Your Email Address\n";	
	if(strError!=""){		
		alert("Check these Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}	
	return true;

  }

function validate_mail(dm) {
	var strError="";				
	if(isBlank(dm.email.value))
	  {
		alert("Email Address is Empty\n");
		return false;
		  }
		  else if(checkEmail(dm.email.value)==0){	
		  alert("Invalid Email Address\n");
		  return false;
			  }
			  else{
				  return true;
				  }

     }
	 
function validate_onlineapp(dm) {
	var strError="";		
	if(isBlank(dm.m_loantype.value))
	strError += "Select Purpose of Loan\n";	
	if(isBlank(dm.property_value.value))
	strError += "Estimated Property Value\n";	
	if(isBlank(dm.loan_program.value))
	strError += "Select Loan Program\n";	
	if(isBlank(dm.loan_amount.value)){	
		if(isBlank(dm.percent_down.value)){
		strError += "Loan amount you are applying for\n";	
	    }else{
			strError += "% Down payment\n";
			}
	}
	if(isBlank(dm.subject_property_street.value))
	strError += "Street Address\n";	
	if(isBlank(dm.property_type.value))
	strError += "Select Property type\n";	
	if(isBlank(dm.subject_property_city.value))
	strError += "City\n";	
	if(isBlank(dm.subject_property_state.value))
	strError += "Select State\n";	
	if(isBlank(dm.subject_property_zip.value))
	strError += "Zip\n";	
	if(isBlank(dm.property_will_be.value))
	strError += "Select Property will be\n";	
	if(isBlank(dm.b_first_name.value))
	strError += "First Name\n";	
	if(isBlank(dm.b_last_name.value))
	strError += "Last Name\n";	
	if(isBlank(dm.b_social_security.value))
	strError += "Social Security Number\n";	
	if(isBlank(dm.b_DOB.value))
	strError += "Date of Birth\n";	
	if(isBlank(dm.m_b_email.value)||checkEmail(dm.m_b_email.value)==0)
    strError += "Enter Email Address\n";		
	if(strError!=""){		
		alert("Check these Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}	
	return true;

  }	 

		
function showhide(){
	var divn1 = document.getElementById("result");
    if (divn1.style.display == "none") {
	     divn1.style.display = "block";
	}
	else {
	  divn1.style.display = "none";
	}
}

function validate_morgcalc(dm) {
	var strError="";		
	if(isBlank(dm.mortgage.value))
	strError += "Enter Mortgage Amount\n";
	if(isBlank(dm.aa.value))
	strError += "Enter Loan Amount\n";
	if(isBlank(dm.bb.value))
	strError += "Enter Interest Rate\n";	
	if(isBlank(dm.cc.value))
	strError += "Enter Mortgage Term in Years\n";	
	if(strError!=""){		
		alert("Check these Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}
	return true;
}
function checnum(valDel)
{
		
	if(isNaN(eval(valDel).value)==true){
		alert("Enter Only Numeric Value!!!");
		eval(valDel).value="";
		valDel.focus();
	  }
}
function OnlyNumeric(valDel)
{
   if(isNaN(eval(valDel).value)==true)
   {
 	alert("Enter Only Numeric Value!!!");
	eval(valDel).value="";
 	valDel.focus();
  }
}
function loan(dm)
{
   	var a = dm.aa.value;
	var b = dm.bb.value;
	var c = dm.cc.value;
	var n = c * 12;
	var r = b/(12*100);
	var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
	var prin = Math.round(p*100)/100;
	dm.r1.value = prin;
	var mon = Math.round(((n * prin) - a)*100)/100;
	dm.r2.value = mon;
	var tot = Math.round((mon/n)*100)/100;
	dm.r3.value = tot;
	for(var i=0;i<n;i++)
	{
		var z = a * r * 1;
		var q = Math.round(z*100)/100;
		var t = p - z;
		var w = Math.round(t*100)/100;
		var e = a-t;
		var l = Math.round(e*100)/100;
		a=e;
	}
}

function validate_extapayment(dm) {
	var strError="";		
	if(isBlank(dm.aa.value))
	strError += "Enter Loan Amount\n";
	if(isBlank(dm.bb.value))
	strError += "Enter Loan Rate\n";	
	if(isBlank(dm.cc.value))
	strError += "Enter Loan Length in Years\n";
	if(isBlank(dm.extra.value))
	strError += "Enter Extra Payment Amount\n";		
	if(strError!=""){		
		alert("Check these Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}	
	return true;
}

function extapayment()
{
   validate_extapayment(document.extapayment);
	var p = document.extapayment.p.value;
	var int = document.extapayment.i.value;
	var month = document.extapayment.n.value;
	var e = document.extapayment.e.value;
	var n = month * 12;
	var i = int/1200;
	var monint = Math.round(P*Math.pow(a,n)*i/(Math.pow(a,n)-1));
	document.extapayment.monthlypay.value = monint;
}

function validate_refinance(dm) {
	var strError="";		
	if(isBlank(dm.aa.value))
	strError += "Enter Loan Amount\n";
	if(isBlank(dm.bb.value))
	strError += "Enter Loan Rate\n";	
	if(isBlank(dm.cc.value))
	strError += "Enter Loan Length in Years\n";	
	if(isBlank(dm.new_bb.value))
	strError += "Enter New Loan Rate\n";	
	if(isBlank(dm.new_cc.value))
	strError += "Enter New Loan Length in Years\n";
	if(strError!=""){		
		alert("Check these Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}	
	return true;
}

/* Form javascript End */





