//Pop up enlarge image

PositionX = (screen.width/2) - 250;
PositionY = (screen.height/2) - 150;

defaultWidth  = 600;
defaultHeight = 600;

var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
	writeln('<sc'+'ript>');
	writeln('var isIE7;');
	writeln('isIE7 = 1;');
	writeln('</sc'+'ript>');
	writeln('<!--'+'[if lt'+' IE 7]>');
	writeln('<sc'+'ript>');
	writeln('isIE7 = 0;');
	writeln('</sc'+'ript>');
	writeln('<![end'+'if]-->');
	writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
	writeln('width=100-(document.body.clientWidth-document.images[0].width);');
	writeln('height=100-(document.body.clientHeight-document.images[0].height);');
	writeln('if (isIE7){');
	writeln('width=width+150;');
	writeln('height=height+80;');
	writeln('}');
	writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
	writeln('function doTitle(){document.title="View Image";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
	close();
	}
}

//Loan calculator
function Morgcal() { 
			form = document.myform 
if (trim(form.LoanAmount.value).length < 1) {
	alert("Please enter your loan amount");
} else if (trim(form.InterestRate.value).length < 1) {
	alert("Please enter your interest rate");
} else if (trim(form.NumberOfYears.value).length < 1) {
	alert("Please enter term of your loan");
} else {


LoanAmount= form.LoanAmount.value 
DownPayment= "0" 
AnnualInterestRate = form.InterestRate.value/100 
Years= form.NumberOfYears.value 
MonthRate=AnnualInterestRate/12 
NumPayments=Years*12 
Prin=LoanAmount-DownPayment 
MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100 
form.NumberOfPayments.value=NumPayments 
form.MonthlyPayment.value=MonthPayment 
}
} 

//Pop up a new window
function popup(aUrl,width,height) 
 { var w;
   var u;
   var s = 'scrollbars=no,menubar=no,status=no,toolbar=no,left=10,top=10,width=' + width + ',height=' + height;
   u = aUrl;w = window.open(u,'',s);
 }

function antispam(name,domain) {
    	document.location = "mailto:" + name + "@" + domain;
	}
	
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function radioVal(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return "";
}

function filterFileType(fieldvalue, ext) {
fieldvalue = fieldvalue.toLowerCase();
if (fieldvalue.indexOf('.' + ext) == -1) {
return false;
}
return true;
} 

//validate
function validatenewsletter(form)
{
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}

return true
}

function validatelogin(form)
{
checkUsername = trim(form.txtUsername.value)
checkPassword = trim(form.txtPassword.value)

if (checkUsername.length < 1){
alert("Please enter your user name")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}

return true
}

function validatemembers(form)
{
checkCAPTCHA = trim(form.txtCAPTCHA.value)
checkUsername = trim(form.txtUsername.value)
checkName = trim(form.txtName.value)
checkPassword = trim(form.txtPassword.value)
checkEmail = trim(form.txtEmail.value)
checkPhone = trim(form.txtPhone.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkUsername.length < 1){
alert("Please enter your user name")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Type the characters in the image above")
return false
}

return true
}

function validatepost(form)
{
	checkCAPTCHA = trim(form.txtCAPTCHA.value)
checkPic1 = trim(form.pic1.value)
checkProjects = form.cbbProjects.selectedIndex
checkPropertyType = form.cbbPropertyType.selectedIndex

if (checkProjects == 0){
alert("Please select project")
return false
}
else if (checkPropertyType == 0){
alert("Please select type of property")
return false
}
else if (!filterFileType(checkPic1, "jpg") && !filterFileType(checkPic1, "gif") && !filterFileType(checkPic1, "tif") && checkPic1.length > 0) {
alert("Only .jpg, .gif and .tif support")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Type the characters in the image above")
return false
}

return true
}



function validateregister(form)
{
checkCAPTCHA = trim(form.txtCAPTCHA.value)
checkName = trim(form.txtName.value)
checkAddress = trim(form.txtAddress.value)
checkHouse = trim(form.txtHouse.value)
checkMobile = trim(form.txtMobile.value)
checkOccupation = trim(form.txtOccupation.value)
checkEmail = trim(form.txtEmail.value)
checkGender = trim(radioVal(form.radGender))
checkMarital = trim(radioVal(form.radMarital))
checkIncome = trim(radioVal(form.radIncome))
checkHousing = trim(radioVal(form.radHousing))
checkPrice = trim(radioVal(form.radPrice))
checkLevel = trim(radioVal(form.radLevel))
checkFound = form.cbbFound.selectedIndex
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkAddress.length < 1){
alert("Please enter your address")
return false
}
else if (checkHouse.length < 1){
alert("Please enter your house contact no")
return false
}
else if (checkMobile.length < 1){
alert("Please enter your mobile no")
return false
}
else if ((aliaspos == -1 || dotpos == -1) && checkEmail.length != 0)
{ alert ("Not a valid email")
return false
}
else if (checkOccupation.length < 1){
alert("Please enter your occupation")
return false
}
else if (checkGender.length < 1){
alert("Please choose your gender")
return false
}
else if (checkMarital.length < 1){
alert("Please choose your marital status")
return false
}
else if (checkIncome.length < 1){
alert("Please choose your monthly income range")
return false
}
else if (checkHousing.length < 1){
alert("Please choose your current housing")
return false
}
else if (checkPrice.length < 1){
alert("Please choose pricing range that you are interested")
return false
}
else if (checkLevel.length < 1){
alert("Please choose no level(s) of property that you are interested")
return false
}
else if (checkFound == 0){
alert("How you found about Jesin?")
return false
}
else if ((form.chbNewsletter.checked) && (checkEmail.length < 1)){
alert("Please enter your email to include you in the mailing list for future project"); 
return false
}
else if (checkCAPTCHA.length < 1){
alert("Type the characters in the image above")
return false
}

return true
}

 function antispam(name,domain) {
    	document.location = "mailto:" + name + "@" + domain;
	}
	
	function validateforgot(form)
{
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}

return true
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}



