
// Init
window.onload = init;
function init() {
		writeDate();
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"h1 span", sFlashSrc:"swf/vandenkeere.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#e9e6d5", sHoverColor:"#CCCCCC"}));
			sIFR.replaceElement(named({sSelector:"h1 span.highlight", sFlashSrc:"swf/vandenkeere.swf", sColor:"#266863", sLinkColor:"#000000", sBgColor:"#e9e6d5", sHoverColor:"#CCCCCC"}));
		};
}
	
// Date
function writeDate() {
	var date = new Date();
		var day = date.getDate();
		var month = date.getMonth()+1;
		var year = date.getFullYear();
	
	// Month Name
	if (month==1) monthName=("January");
	else if (month==2) monthName=("February");
	else if (month==3) monthName=("March");
	else if (month==4) monthName=("April");
	else if (month==5) monthName=("May");
	else if (month==6) monthName=("June");
	else if (month==7) monthName=("July");
	else if (month==8) monthName=("August");
	else if (month==9) monthName=("September");
	else if (month==10) monthName=("October");
	else if (month==11) monthName=("November");
	else monthName=("December");
		
	var e = document.getElementById("date");
	var textDay = document.createTextNode(day+" ");
	var textMonth = document.createTextNode(monthName+" ");
	var textYear = document.createTextNode(year);
	
	e.appendChild(textDay);
	e.appendChild(textMonth);
	e.appendChild(textYear);
}

function sendMail(frmName){		
	var objVar = new getObjVars();
	objVar.fieldN[0] = "firstname";
	objVar.fieldV[0] = "Please enter your first name";
	objVar.fieldT[0] = "text";
	objVar.fieldI[0] = "first_nameID";
	objVar.fieldN[1] = "surname";
	objVar.fieldV[1] = "Please enter your surname";
	objVar.fieldT[1] = "text";
	objVar.fieldI[1] = "surnameID";	
	objVar.fieldN[2] = "email";
	objVar.fieldV[2] = "Please enter your email";
	objVar.fieldT[2] = "text";
	objVar.fieldI[2] = "emailID";	
	objVar.fieldN[3] = "phone";
	objVar.fieldV[3] = "Please enter your phone";
	objVar.fieldT[3] = "text";
	objVar.fieldI[3] = "phoneID";
	if(validateForm(frmName,objVar)){		
		var ajaxVar = new ajaxVars();
		ajaxVar.incModule = 'property';
		ajaxVar.vars['action'] = "runFunction";
		ajaxVar.vars['func'] = "sendMailINC";
		ajaxVar.vars['nosplit'] = 1;
		ajaxVar.vars['email'] = eval("document."+frmName+".email.value");
		ajaxVar.vars['firstname'] = eval("document."+frmName+".firstname.value");
		ajaxVar.vars['surname'] = eval("document."+frmName+".surname.value");
		ajaxVar.vars['phone'] = eval("document."+frmName+".phone.value");
		ajaxVar.vars['property_code'] = eval("document."+frmName+".property_code.value");
		ajaxVar.fnVars['frmID'] = frmName;
		ajaxVar.fnVars['objVar'] = objVar;
		ajaxVar.gotoFunction = 'confirmEmailSend';	  		 	
		ajaxVar.AjaxPostSQL();
	}	
}

function sendMail2(frmName){	
		
	var objVar = new getObjVars();
	objVar.fieldN[0] = "firstname";
	objVar.fieldV[0] = "Please enter your first name";
	objVar.fieldT[0] = "text";
	objVar.fieldI[0] = "first_nameID";
	objVar.fieldN[1] = "surname";
	objVar.fieldV[1] = "Please enter your surname";
	objVar.fieldT[1] = "text";
	objVar.fieldI[1] = "surnameID";	
	objVar.fieldN[2] = "emailaddr";
	objVar.fieldV[2] = "Please enter your email";
	objVar.fieldT[2] = "text";
	objVar.fieldI[2] = "emailaddrID";	
	objVar.fieldN[3] = "phone";
	objVar.fieldV[3] = "Please enter your phone";
	objVar.fieldT[3] = "text";
	objVar.fieldI[3] = "phoneID";
	if(validateForm(frmName,objVar)){		
		var ajaxVar = new ajaxVars();
		ajaxVar.incModule = 'property';
		ajaxVar.vars['action'] = "runFunction";
		ajaxVar.vars['func'] = "sendMailINCMULTI";
		ajaxVar.vars['nosplit'] = 1;
		ajaxVar.vars['emailaddr'] = eval("document."+frmName+".emailaddr.value");
		ajaxVar.vars['firstname'] = eval("document."+frmName+".firstname.value");
		ajaxVar.vars['surname'] = eval("document."+frmName+".surname.value");
		ajaxVar.vars['phone'] = eval("document."+frmName+".phone.value");
		
		if(eval("document."+frmName+".area.value")){
			ajaxVar.vars['area'] = eval("document."+frmName+".area.value");
		}
		ajaxVar.vars['phone'] = eval("document."+frmName+".phone.value");
		ajaxVar.vars['property_code'] = eval("document."+frmName+".property_code.value");
		ajaxVar.fnVars['frmID'] = frmName;
		ajaxVar.fnVars['objVar'] = objVar;
		ajaxVar.gotoFunction = 'confirmEmail2Send';	  		 	
		ajaxVar.AjaxPostSQL();
	}	
}

function confirmEmailSend(dataArr,fnVars){	
	var retVal = validateForm(fnVars['frmID'],fnVars['objVar']);
	//inlineErrMsg(1,'prop_code','Email send',3,fnVars['frmID']);
	if(dataArr==1){
		window.location = "hampstead-thankyou-enquiry.html";
	}else if(dataArr==2){
		window.location = "hampstead-garden-suburb-thankyou-enquiry.html";
	}else if(dataArr==3){
		window.location = "highgate-thankyou-enquiry.html";
	}else if(dataArr==4){
		window.location = "kenwood-thankyou-enquiry.html";
	}else{
		window.location = "thankyou-enquiry.html";	
	}	
}

function confirmEmail2Send(dataArr,fnVars){	
	var retVal = validateForm(fnVars['frmID'],fnVars['objVar']);
	//inlineErrMsg(1,'prop_code','Email send',3,fnVars['frmID']);
	if(dataArr==1){
		window.location = "hampstead-thankyou-enquiry.html";
	}else if(dataArr==2){
		window.location = "hampstead-garden-suburb-thankyou-enquiry.html";
	}else if(dataArr==3){
		window.location = "highgate-thankyou-enquiry.html";
	}else if(dataArr==4){
		window.location = "kenwood-thankyou-enquiry.html";
	}else{
		window.location = "thankyou-enquiry.html";	
	}	
}

function AlertSaleProperty(frmName){
	var objVar = new getObjVars();
	objVar.fieldN[0] = "name";
	objVar.fieldV[0] = "Please enter your name";
	objVar.fieldT[0] = "text";
	objVar.fieldI[0] = "nameID";	
	objVar.fieldN[2] = "email";
	objVar.fieldV[2] = "Please enter your email";
	objVar.fieldT[2] = "text";
	objVar.fieldI[2] = "emailID";	
	objVar.fieldN[3] = "password";
	objVar.fieldV[3] = "Please enter your password";
	objVar.fieldT[3] = "text";
	objVar.fieldI[3] = "passwordID";
	if(validateForm(frmName,objVar)){		
		var ajaxVar = new ajaxVars();
		ajaxVar.incModule = 'property';
		ajaxVar.vars['action'] = "phpArray";
		ajaxVar.vars['func'] = "setAlertSalePropertyINC";
		ajaxVar.vars['nosplit'] = 1;		
		ajaxVar.vars['name'] = eval("document."+frmName+".name.value");
		ajaxVar.vars['email'] = eval("document."+frmName+".email.value");
		ajaxVar.vars['password'] = eval("document."+frmName+".password.value");		
		ajaxVar.vars['frequency'] = eval("document."+frmName+".frequency.value");
		ajaxVar.vars['type'] = eval("document."+frmName+".type.value");
		ajaxVar.vars['f_price'] = eval("document."+frmName+".f_price.value");
		ajaxVar.vars['t_price'] = eval("document."+frmName+".t_price.value");
		ajaxVar.fnVars['pass'] = eval("document."+frmName+".password.value");	
		ajaxVar.fnVars['email'] = eval("document."+frmName+".email.value");	
		ajaxVar.gotoFunction = 'showAlertInfo';	  		 	
		ajaxVar.AjaxPostSQL();
	}

	return false;
}

function showAlertInfo(dataArr,fnVars){	
		switch (dataArr['errorType'].toString()){
			case '1': //existing member			
				// reload profile.php page 
				document.TblAlert.password = fnVars['pass'];
				document.TblAlert.email = fnVars['email'];
				document.TblAlert.setAttribute("action","profile.php");
				document.TblAlert.submit();
				//window.location = "profile.php";				
				return 1;
				inlineErrMsg(1,'alertMsgID','Modify your information and click save.',3,'alertMsgID');
				getMoreHeight();
				slidedown('form2ID');				
				var emnts = document.TblAlert2.elements;
				document.TblAlert2.type.value = dataArr['type'];
				document.TblAlert2.f_price.value = dataArr['f_price'];
				document.TblAlert2.t_price.value = dataArr['t_price'];
				document.TblAlert2.id.value = dataArr['id'];
				document.TblAlert2.email.value = dataArr['email'];
				document.TblAlert2.frequency.value = dataArr['frequency'];				
			break;
			case '2':  //new member
				//inlineErrMsg(1,'alertMsgID','Property alert successfully submitted.',3,'alertMsgID');
				window.location = "thankyou-alert.html";
			break;
			case '3': //password mismatch
				inlineErrMsg(1,'alertMsgID','Password mismatch.',3,'alertMsgID');
			break;
		}	
}



function AlertSaleProperty1(frmName){
	var objVar = new getObjVars();
	objVar.fieldN[0] = "name";
	objVar.fieldV[0] = "Please enter your name";
	objVar.fieldT[0] = "text";
	objVar.fieldI[0] = "nameID";	
	objVar.fieldN[2] = "email";
	objVar.fieldV[2] = "Please enter your email";
	objVar.fieldT[2] = "text";
	objVar.fieldI[2] = "emailID";	
	objVar.fieldN[3] = "password";
	objVar.fieldV[3] = "Please enter your password";
	objVar.fieldT[3] = "text";
	objVar.fieldI[3] = "passwordID";
	if(validateForm(frmName,objVar)){		
		var ajaxVar = new ajaxVars();
		ajaxVar.incModule = 'property';
		ajaxVar.vars['action'] = "phpArray";
		ajaxVar.vars['func'] = "setAlertSalePropertyINC";
		ajaxVar.vars['nosplit'] = 1;		
		ajaxVar.vars['name'] = eval("document."+frmName+".name.value");
		ajaxVar.vars['email'] = eval("document."+frmName+".email.value");
		ajaxVar.vars['password'] = eval("document."+frmName+".password.value");		
		ajaxVar.vars['frequency'] = eval("document."+frmName+".frequency.value");
		ajaxVar.vars['type'] = eval("document."+frmName+".type.value");
		ajaxVar.vars['f_price'] = eval("document."+frmName+".f_price.value");
		ajaxVar.vars['t_price'] = eval("document."+frmName+".t_price.value");
		ajaxVar.fnVars['pass'] = eval("document."+frmName+".password.value");	
		ajaxVar.fnVars['email'] = eval("document."+frmName+".email.value");	
		ajaxVar.gotoFunction = 'showAlertInfo1';	  		 	
		ajaxVar.AjaxPostSQL();
	}

	return false;
}

function showAlertInfo1(dataArr,fnVars){	
		switch (dataArr['errorType'].toString()){
			case '1': //existing member			
				// reload profile.php page 
				document.TblAlert3.password = fnVars['pass'];
				document.TblAlert3.email = fnVars['email'];
				
				document.TblAlert3.setAttribute("action","profile.php");
				document.TblAlert3.submit();
				//window.location = "profile.php";				
				return 1;
				inlineErrMsg(1,'alertMsgID1','Modify your information and click save.',3,'alertMsgID');
				getMoreHeight();
				slidedown('form2ID');				
				var emnts = document.TblAlert2.elements;
				document.TblAlert2.type.value = dataArr['type'];
				document.TblAlert2.f_price.value = dataArr['f_price'];
				document.TblAlert2.t_price.value = dataArr['t_price'];
				document.TblAlert2.id.value = dataArr['id'];
				document.TblAlert2.email.value = dataArr['email'];
				document.TblAlert2.frequency.value = dataArr['frequency'];				
			break;
			case '2':  //new member
				//inlineErrMsg(1,'alertMsgID1','Property alert successfully submitted.',3,'alertMsgID1');
				window.location = "thankyou-alert.html";
			break;
			case '3': //password mismatch
				inlineErrMsg(1,'alertMsgID1','Password mismatch.',3,'alertMsgID1');
			break;
		}	
}




function saveAlertForm(){
	var objVar = new getObjVars();
	objVar.fieldN[0] = "password";
	objVar.fieldV[0] = "Please enter password";
	objVar.fieldT[0] = "text";
	objVar.fieldI[0] = "password2ID";	
	objVar.fieldN[2] = "repassword";
	objVar.fieldV[2] = "Please re-type password";
	objVar.fieldT[2] = "text";
	objVar.fieldI[2] = "repassword2ID";	
	if(document.getElementById('chkBoxChangePassId').checked)  //change password is ticked
		if(!validateForm('TblAlert2',objVar) || !matchPasswords('password2ID',document.getElementById('password2ID').value,document.getElementById('repassword2ID').value))
			return false;	// either password and repassowrd is empty or they do not match 
	
	// save in db
	var ajaxVar = new ajaxVars();	
	ajaxVar.incModule = 'property';
	ajaxVar.vars['action'] = "runFunction";
	ajaxVar.vars['func'] = "saveAlertInfoINC";
	ajaxVar.vars['nosplit'] = 1;
	var emnts = document.TblAlert2.elements;
	for(i=0;i<emnts.length;i++){
		//alert(emnts[i].name+'|'+emnts[i].value);
		if(emnts[i].type == 'checkbox'){			
			if(emnts[i].checked)
				ajaxVar.vars[emnts[i].name] = 1;
			else
				ajaxVar.vars[emnts[i].name] = 0;
		}else{
			ajaxVar.vars[emnts[i].name] = emnts[i].value;				
		}
	}
	ajaxVar.gotoFunction = 'showReturnMsg';	  		 	
	ajaxVar.AjaxPostSQL();
				
	return false;
}

function matchPasswords(passObjId,passVal, rePassVal){  
	if(passVal != rePassVal){	// password mismatch and shows mismatch message and returns false
		inlineErrMsg(1,passObjId,'Password mismatch.',3,passObjId);
		return false;
	}else{		//returns true as password and retype password match
		return true;
	}
}

function showReturnMsg(dataArr,fnVars){	
	removeChildDiv();
	//inlineErrMsg(1,'alertMsgID','Details saved successfully.',3,'alertMsgID');
	window.location = "thankyou-alert.html";
}

function togglePasswordArea(toggledVal){
	if(toggledVal)
		document.getElementById('chgPassTDID').style.visibility = 'visible';
	else
		document.getElementById('chgPassTDID').style.visibility = 'hidden';
	document.TblAlert2.password.value = '';
}

function getMoreHeight(){
	if(document.getElementById('form2ID').style.display == 'block')
		document.getElementById('alert_div').style.height = '214px';
	else
		document.getElementById('alert_div').style.height = '450px';
}

function clearFormData(formName){
	var emnts = eval("document."+formName+".elements;");
	for(i=0;i<emnts.length;i++)
		if(emnts[i].type== 'hidden' || emnts[i].type== 'text' || emnts[i].type== 'password')
			emnts[i].value = '';		
}

function alertDivToggle(){
	showHideDiv('alert_div');
	removeChildDiv();
	clearFormData('TblAlert');
	clearFormData('TblAlert2');	
	document.getElementById('alert_div').style.height = '214px';
	document.getElementById('form2ID').style.display = 'none';
}



function clearAlertForm(){	
	removeChildDiv();
	clearFormData('TblAlert');
	clearFormData('TblAlert2');	
	document.getElementById('alert_div').style.height = '214px';
	document.getElementById('form2ID').style.display = 'none';
}


function alertDivToggle1(){
	showHideDiv('alert_div1');
	removeChildDiv();
	clearFormData('TblAlert3');
	
	document.getElementById('alert_div1').style.height = '220px';
	
}

function clearAlertForm1(){	
	
	clearFormData('TblAlert3');
	
	document.getElementById('alert_div1').style.height = '220px';
	
}

function check_open(){
	if(document.getElementById('alert_div')){
		
		if(document.getElementById('alert_div').style.visibility=='hidden' || document.getElementById('alert_div').style.visibility==''){
			document.getElementById('alertbtn').src='images/alert_btn.gif';
		}else{
			document.getElementById('alertbtn').src='images/alert_over2.gif';
		}
	}else{
		document.getElementById('alertbtn').src='images/alert_btn.gif';
	}
}

function check_open_hover(){
	
		if(document.getElementById('alert_div').style.visibility=='visible'){
			document.getElementById('alertbtn').src='images/alert_over2.gif';
		}else{
			document.getElementById('alertbtn').src='images/alert_over.gif';
		}
	
}



function check_opend(){
	if(document.getElementById('alert_div1')){
		
		if(document.getElementById('alert_div1').style.visibility=='hidden' || document.getElementById('alert_div1').style.visibility==''){
			document.getElementById('alertbtn1').src='images/alert_btn.gif';
		}else{
			document.getElementById('alertbtn1').src='images/alert_over2.gif';
		}
	}else{
		document.getElementById('alertbtn1').src='images/alert_btn.gif';
	}
}

function check_open_hoverd(){
	
		if(document.getElementById('alert_div1').style.visibility=='visible'){
			document.getElementById('alertbtn1').src='images/alert_over2.gif';
		}else{
			document.getElementById('alertbtn1').src='images/alert_over.gif';
		}
	
}

function show_hide_map(divId,postcd){

// 	if(document.getElementById(divId).style.visibility=='hidden'){
// 		document.getElementById(divId).style.visibility ="visible";
// 		document.getElementById(divId).style.display ="block";
 location.href='#map_area'
   setTimeout("op_map('" + divId + "','" + postcd + "')",2000);
//   	mapLoad();
//       usePointFromPostcode(postcd, setCenterToPoint);
//       location.href='#map_area'
 		//document.getElementById(divId).style.height ="300px";
// 	}else{
// 	document.getElementById(divId).style.visibility ="hidden";
// 	document.getElementById(divId).style.display ="none";
// 	}
}
function op_map(divId,postcd){
	
		mapLoad();
      usePointFromPostcode(postcd, setCenterToPoint);
     
}

function showOrgImage(imgId,divId){
	var ajaxVar = new ajaxVars();
	ajaxVar.incModule = 'common';	
	ajaxVar.vars['action'] = "runFunction";
	ajaxVar.vars['func'] = "show_main";
	ajaxVar.vars['nosplit'] = 1;
    ajaxVar.vars['imgid'] = imgId;
    ajaxVar.fnVars['divId'] = divId;
   
	ajaxVar.gotoFunction = 'show_main_det';
	ajaxVar.AjaxPostSQL();
}

function show_main_det(dataArr, fnVars){
	var divId = fnVars['divId'];
	
	var divObj = document.getElementById(divId);
	divObj.innerHTML = dataArr;
	
}

function submit_selected(){
	var searchType = document.getElementById('searchtype').checked;
	
	if(searchType){
		document.sales_form.submit();
	}else{
		if(document.getElementById('s_from').value=='' || document.getElementById('s_to').value==''){
			alert('Please enter price range properly');
			return false;
		}
		document.getElementById('wmin').value = document.getElementById('s_from').value;
		document.getElementById('wmax').value = document.getElementById('s_to').value;
		if(document.getElementById('s_type').value == 'all'){
			document.getElementById('rhouse').value = 'true';
			document.getElementById('rflat').value = 'true';
		}else if(document.getElementById('s_type').value == 1){
			document.getElementById('rflat').value = 'true';
		}else{
			document.getElementById('rhouse').value = 'true';
		}
		
		if(document.getElementById('s_order').value == 'asc'){
			document.getElementById('sort_in').value ='londonnorth/Glentreelettings.438/__localind';	
		}else{
			document.getElementById('sort_in').value ='londonnorth/Glentreelettings.438/__localind.rev';	
		}
		document.rentals_form.submit();
 
	}

}

function setprice(stVal){
	var ckObj1 = document.getElementById('fprice');
	var ckObj2 = document.getElementById('tprice');
	
	if(stVal=='1'){
		ckObj1.innerHTML = "&nbsp;&nbsp;&pound;<select name=\"s_from\" id=\"s_from\" style=\"margin-left:2px; width:70px;\" class=\"dropbx2\"><option value=0>No Min</option><option value=250000>250k</option><option value=500000>500k</option><option value=1000000>1m</option><option value=2000000>2m</option><option value=5000000>5m</option></select>";
        ckObj2.innerHTML = '&nbsp;&nbsp;&pound;<select name="s_to" id="s_to" style="margin-left:2px; width:68px;" class="dropbx2"><option value=250000>250k</option><option value=500000>500k</option><option value=1000000>1m</option><option value=2000000>2m</option><option selected value=5000000>5m+</option></select>';
                                                     
                                
	}else{
		ckObj1.innerHTML = '&nbsp;&nbsp;&pound;<input type=text name="s_from" id="s_from" value="10" class="dropbx2" style="margin-left:2px; width:65px; height:16px;" >';
		ckObj2.innerHTML = '&nbsp;&nbsp;&pound;<input type=text name="s_to" id="s_to" value="50,000" class="dropbx2" style="margin-left:2px; width:65px; height:16px;" > Per Week';
	}
}

function show_enq_form(pid,Obj){
	var topPos = String(obtenerPosicionY(Obj)+35)+'px';
	var leftPos = String(obtenerPosicionX(Obj)-121)+'px';
	
	document.getElementById('enqfrmDiv').className='vdiv';
	document.getElementById('enqfrmDiv').style.left = leftPos;
	document.getElementById('enqfrmDiv').style.top = topPos;
	
	document.getElementById('hpcode').value = pid;
}

function show_enq_form1(pid,Obj){
	var topPos = String(obtenerPosicionY(Obj)+55)+'px';
	var leftPos = String(obtenerPosicionX(Obj)-186)+'px';
	
	document.getElementById('enqfrmDiv').className='vdiv';
	document.getElementById('enqfrmDiv').style.left = leftPos;
	document.getElementById('enqfrmDiv').style.top = topPos;
	
	document.getElementById('hpcode').value = pid;
}
function close_enq_form(){
	document.getElementById('enqfrmDiv').className='hdiv';
	document.getElementById('msg_0').style.display='none';
	document.getElementById('msg_1').style.display='none';
	document.getElementById('msg_2').style.display='none';
	document.getElementById('msg_3').style.display='none';
	
	
}

function obtenerPosicionX(elemento)
{
var x=0;
while(elemento)
{
x += elemento.offsetLeft;
elemento=elemento.offsetParent;
}
return x;
}

//Get Y position
function obtenerPosicionY(elemento)
{
var y=0;
while(elemento)
{
y += elemento.offsetTop;
elemento=elemento.offsetParent;
}
return y;
}