//Email Validation
function emailCheck(emailStr)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
		alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) 
	{
		alert("The username doesn't seem to be valid.")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++)
		{
		if (IPArray[i]>255)
		{
			alert("Destination IP address is invalid!")
			return false
		}
		}
return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
	return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
	domArr[domArr.length-1].length>4) {
   alert("The address must end in a valid domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
return true;
}

//Show Date
function showDate()
{
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10)
		daym="0"+daym
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
	document.write("<span class=text11black><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></span>")
}

var xmlHttp // xmlHttp variable
function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.
var objXMLHttp=null // Sets objXMLHttp to null as default.
if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.
objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.
}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
} // End ElseIf.
return objXMLHttp // Returns the xhttp object.
} // Close Function

//Check Username
function CheckUsername(username)
{ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/checkusername.php?username="+username; // Url that we will use to check the username.
xmlHttp.open("GET",url,true); // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("usernameresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("usernameresult").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State & City
function getState(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("statediv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("statediv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("citydiv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("citydiv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State1 & City1
function getState1(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("statediv1").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("statediv1").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity1(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("citydiv1").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("citydiv1").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State2 & City2
function getState2(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState1.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("statediv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("statediv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity2(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity1.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
	document.getElementById("citydiv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
	document.getElementById("citydiv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State3 & City3
function getState3(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState2.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("statediv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("statediv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity3(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity2.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("citydiv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("citydiv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State4 & City4
function getState4(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState3.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("statediv").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("statediv").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity4(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity3.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("citydiv1").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("citydiv1").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State5 & City5
function getState5(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState5.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("statediv2").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("statediv2").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity5(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity5.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("citydiv2").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("citydiv2").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

//State6 & City6
function getState6(countryID){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findState4.php?country="+countryID; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("statediv4").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("statediv4").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function getCity6(stateId){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="includes/findCity4.php?state="+stateId; // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4)
{ // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("citydiv4").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
else
{
document.getElementById("citydiv4").innerHTML = '<img src="images/loader.gif">';
}
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function apprai()
{
	var country = document.getElementById('country').value;
	var state = document.getElementById('state').value;
	var city = document.getElementById('city').value;
	getAppraiser(country,state,city);
}
function getAppraiser(country,state,city) {
	var strURL="includes/appraiser.php?country="+country+"&state="+state+"&city="+city;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('appraiser').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}			
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}


function brok()
{
	//alert('hello');
	var country = document.getElementById('country').value;
	var state = document.getElementById('state').value;
	var city = document.getElementById('city').value;
	getBroker(country,state,city);
}
function getBroker(country,state,city) {
	var strURL="includes/broker.php?country="+country+"&state="+state+"&city="+city;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('broker').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}			
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}


function lawy()
{
	var country = document.getElementById('country').value;
	var state = document.getElementById('state').value;
	var city = document.getElementById('city').value;
	getLawyer(country,state,city);
}
function getLawyer(country,state,city) {
	var strURL="includes/lawyer.php?country="+country+"&state="+state+"&city="+city;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('lawyer').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}			
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}



function homeins()
{
	var country = document.getElementById('country').value;
	var state = document.getElementById('state').value;
	var city = document.getElementById('city').value;
	getHomeInsp(country,state,city);
}
function getHomeInsp(country,state,city) {
	var strURL="includes/homeins.php?country="+country+"&state="+state+"&city="+city;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('homeins').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}			
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}

function other()
{
	var country = document.getElementById('country').value;
	var state = document.getElementById('state').value;
	var city = document.getElementById('city').value;
	getOther(country,state,city);
}
function getOther(country,state,city) {
	var strURL="includes/other.php?country="+country+"&state="+state+"&city="+city;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('other').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}			
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}






//Savings Calculator
function formatCurrency(num, strip_cents)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	
	if(strip_cents == true)
	return (((sign)?'':'-') + '' + num);
	else
	return (((sign)?'':'-') + '' + num + '.' + cents);
}

function index_calculate_savings() 
{
	price = document.getElementById('house_value').value;
	if (isNaN(price))
	{
		alert('Make sure Selling Price is a number - do not include commas.');
	}
	else
	{
		price = price * 0.05;
		document.getElementById('saving_calc_result').value = formatCurrency(price, true)
	}
}

//Mortgage Calculator
function calcPay()
{
	fff=document.fMortgage;
	nMortgage = fff.mortgage.value*(1-fff.percentage.value/100);
	nAmort = fff.amort.value;
	nIntrate = fff.intrate.value;
	nFreq = fff.freq.value;
	nCompound=2;
	var compound = nCompound/12;
	var monTime = nAmort * 12;
	var rate = (nIntrate*1.0)/100;
	var yrRate = rate/nCompound;
	var rdefine    = Math.pow((1.0 + yrRate),compound)-1.0;
	var payment = (nMortgage*rdefine * (Math.pow((1.0 + rdefine),monTime)))/  ((Math.pow((1.0 + rdefine),monTime)) - 1.0);
	if(payment!=0)
	{
		payment =Math.round(payment*100)/100;
		sPeriod="month";
		if(nFreq==12){ payment=payment; sPeriod="month";}
		if(nFreq==24){ payment=payment/2.0; sPeriod="semi-month"; }
		if(nFreq==26){ payment=payment/2.0; sPeriod="bi-week"; }
		if(nFreq==52){payment=payment/4.0;  sPeriod="week";}
		//fff.paymentM.value="$" + payment + "/"+sPeriod;
		document.getElementById('mortgage_result').value = "$" + payment + "/"+sPeriod;
	}
}

function calcPay1()
{
	fff=document.fMortgage;
	nMortgage = fff.mortgage.value*(1-fff.percentage.value/100);
	nAmort = fff.amort.value;
	nIntrate = fff.intrate.value;
	nFreq = fff.freq.value;
	nCompound=2;
	var compound = nCompound/12;
	var monTime = nAmort * 12;
	var rate = (nIntrate*1.0)/100;
	var yrRate = rate/nCompound;
	var rdefine    = Math.pow((1.0 + yrRate),compound)-1.0;
	var payment = (nMortgage*rdefine * (Math.pow((1.0 + rdefine),monTime)))/  ((Math.pow((1.0 + rdefine),monTime)) - 1.0);
	if(payment!=0)
	{
		payment =Math.round(payment*100)/100;
		sPeriod="month";
		if(nFreq==12){ payment=payment; sPeriod="month";}
		if(nFreq==24){ payment=payment/2.0; sPeriod="semi-month"; }
		if(nFreq==26){ payment=payment/2.0; sPeriod="bi-week"; }
		if(nFreq==52){payment=payment/4.0;  sPeriod="week";}
		//fff.paymentM.value="$" + payment + "/"+sPeriod;
		document.getElementById('mortgage_result').value = "$" + payment + "/"+sPeriod;
	}
}


//Seller Profile Validation
function validate(form)
{
	if((form.fname.value == ""))
	{
		alert('Please Specify First Name');
		form.fname.focus();
		return false;
	}
	
	if((form.lname.value == ""))
	{
		alert('Please Specify Last Name');
		form.lname.focus();
		return false;
	}

	if((form.dayPhone.value == ""))
	{
		alert('Please Specify Phone Number');
		form.dayPhone.focus();
		return false;
	}
	
	if((form.dayPhone.value.match(/[&<>]+/)))
	{
		alert('Phone Number can contain only numeric characters.');
		form.dayPhone.focus();
		return false;
	}
	
	if((form.address.value == ""))
	{
		alert('Please Specify Address');
		form.address.focus();
		return false;
	}
	
	if((form.zip.value == ""))
	{
		alert('Please Specify Postal Code/Zip');
		form.zip.focus();
		return false;
	}
	
	if((form.zip.value.match(/[^a-zA-Z0-9.]/)))
	{
		alert('Postal Code/Zip can contain only alphanumeric characters.');
		form.zip.focus();
		return false;
	}

	if((form.province.selectedIndex == 0))
	{
		alert('Please Select Province');
		form.province.focus();
		return false;
	}

	if((form.comm_city.selectedIndex == 0))
	{
		alert('Please Select City');
		form.comm_city.focus();
		return false;
	}
	
	if((form.country.selectedIndex == 0))
	{
		alert('Please Specify Country');
		form.country.focus();
		return false;
	}
	
	if((form.email.value == ""))
	{
		alert('Please Specify Email Address');
		form.email.focus();
		return false;
	}
	
	if(!emailCheck(form.email.value))
	{
		form.email.focus();
		return false;
	}
	
	if((form.password.value == ""))
	{
		alert('Please Specify Password');
		form.password.focus();
		return false;
	}
	
	if((form.password.value != form.rpassword.value))
	{
		alert('Password do not match');
		form.rpassword.value="";
		form.password.focus();
		form.password.select();
		return false;
	}
}

//Jump menu for View All Listing Page in Member Section
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	if(selObj.options[selObj.selectedIndex].value != ""){
	  if(selObj.selectedIndex == 4){
	  	if(confirm('Are you sure you want to delete this property?'))
		  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  }else
	  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  selObj.selectedIndex=0;
	}
}


//Show Appropriate Form According to Form Type and Package Selection
function showForm(type,pkg)
{
	if((type=='resi' || type=='comm' || type=='intl') && pkg=='1')
	{
		document.getElementById('resi_comm_self').style.display = "block";
		document.getElementById('resi_full').style.display = "none";
		document.getElementById('comm_full').style.display = "none";
		document.getElementById('intl_resi_comm').style.display = "none";
	}
	if((type=='resi') && (pkg=='2' || pkg=='3'))
	{
		document.getElementById('resi_comm_self').style.display = "none";
		document.getElementById('resi_full').style.display = "block";
		document.getElementById('comm_full').style.display = "none";
		document.getElementById('intl_resi_comm').style.display = "none";
	}
	if((type=='comm') && (pkg=='2' || pkg=='3'))
	{
		document.getElementById('resi_comm_self').style.display = "none";
		document.getElementById('resi_full').style.display = "none";
		document.getElementById('comm_full').style.display = "block";
		document.getElementById('intl_resi_comm').style.display = "none";
	}
	
	if((type=='intl') && (pkg=='2' || pkg=='3'))
	{
		document.getElementById('resi_comm_self').style.display = "none";
		document.getElementById('resi_full').style.display = "none";
		document.getElementById('comm_full').style.display = "none";
		document.getElementById('intl_resi_comm').style.display = "block";
	}
}

//Search Form
function search_form(type)
{
	if(type=='resi')
	{
		document.getElementById('form_resi').style.display = "block";
		document.getElementById('form_comm').style.display = "none";
		document.getElementById('form_intl').style.display = "none";
	}
	if(type=='comm')
	{
		document.getElementById('form_resi').style.display = "none";
		document.getElementById('form_comm').style.display = "block";
		document.getElementById('form_intl').style.display = "none";
	}
	if(type=='intl')
	{
		document.getElementById('form_resi').style.display = "none";
		document.getElementById('form_comm').style.display = "none";
		document.getElementById('form_intl').style.display = "block";
	}
}


//Validation of Add New Listing Form in Member Section
function validatelisting(form)
{
	if((!form.form_type[0].checked) && (!form.form_type[1].checked) && (!form.form_type[2].checked))
	{
		alert("Please Select Property Type");
		return false;
	}
	
	if((form.address.value == ""))
	{
		alert("Please Specify Address");
		form.address.focus();
		return false;
	}
	
/*	if((form.street_name.value == ""))
	{
		alert("Please Specify Street Name");
		form.street_name.focus();
		return false;
	}*/
	
	if((form.province.selectedIndex == 0))
	{
		alert("Please Select Province");
		form.province.focus();
		return false;
	}
	
	if((form.city.selectedIndex == 0))
	{
		alert("Please Select City");
		form.city.focus();
		return false;
	}
	
	if((form.postal_code.value == ""))
	{
		alert("Please Specify Postal Code");
		form.postal_code.focus();
		return false;
	}
	
	if((form.seller_fname.value == ""))
	{
		alert("Please Specify First Name");
		form.seller_fname.focus();
		return false;
	}
	
	/*if((form.seller_lname.value == ""))
	{
		alert("Please Specify Last Name");
		form.seller_lname.focus();
		return false;
	}*/
	
	/*if((form.seller_phone.value == ""))
	{
		alert("Please Specify Phone Number");
		form.seller_phone.focus();
		return false;
	}
	
	if((form.seller_phone.value.match(/[^0-9.]/)))
	{
		alert('Phone Number can contain only numeric characters.');
		form.seller_phone.focus();
		return false;
	}*/
	
	/*if((form.seller_email.value == ""))
	{
		alert("Please Specify Email Address");
		form.seller_email.focus();
		return false;
	}
	
	if(!emailCheck(form.seller_email.value))
	{
		form.seller_email.focus();
		return false;
	}*/
	
	if(!form.agree.checked)
	{
		alert("Please Read the terms and policies and check the box below");
		return false;
	}
	
return true;
}

function twdCount(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}

function emailwindow(x)
{
	window.open("email.php?filepath="+x,"","width=500,height=350, left=50, top=50");
}
function showMap1(sss){
	new_window = window.open(sss, "Image",
		"top=30,left=90,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	new_window.focus();
	}

function checklogin(form2)
{
	if((form2.username.value == ""))
	{
		alert("Please specify Username");
		form.username.focus();
		return false;
	}
	
	if((form2.password.value == ""))
	{
		alert("Please specify Password");
		form.password.focus();
		return false;
	}
}

function show_div(type)
{
	if(type=='resi')
	{
		document.getElementById('resi_comm').style.display = "block";
		document.getElementById('intl').style.display = "none";
	}
	if(type=='comm')
	{
		document.getElementById('resi_comm').style.display = "block";
		document.getElementById('intl').style.display = "none";
	}
	if(type=='intl')
	{
		document.getElementById('resi_comm').style.display = "none";
		document.getElementById('intl').style.display = "block";
	}
}

function validrental(form)
{
	if((form.cat.selectedIndex == 0))
	{
		alert("Please select Category");
		form.cat.focus();
		return false;
	}
	if((form.type.selectedIndex == 0))
	{
		alert("Please select Property Type");
		form.type.focus();
		return false;
	}
	if((form.resi_state.selectedIndex == 0))
	{
		alert("Please select Province");
		form.resi_state.focus();
		return false;
	}
	if((form.resi_city.selectedIndex == 0))
	{
		alert("Please select City");
		form.resi_city.focus();
		return false;
	}
	if((form.rent.value == ""))
	{
		alert("Please enter Monthly Rent");
		form.rent.focus();
		return false;
	}
	if((form.address.value == ""))
	{
		alert("Please enter Address");
		form.address.focus();
		return false;
	}
	if((form.postal_code.value == ""))
	{
		alert("Please enter Postal Code");
		form.postal_code.focus();
		return false;
	}
	if((form.seller_name.value == ""))
	{
		alert("Please enter Your Name");
		form.seller_name.focus();
		return false;
	}
	if((form.seller_email.value == ""))
	{
		alert("Please enter Email Address");
		form.seller_email.focus();
		return false;
	}
	
	if(!emailCheck(form.seller_email.value))
	{
		form.seller_email.focus();
		return false;
	}
	
	if((form.seller_phone.value == ""))
	{
		alert("Please enter Your Phone Number");
		form.seller_phone.focus();
		return false;
	}
}