// 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 confirmEmailSend(dataArr,fnVars){	
	var retVal = validateForm(fnVars['frmID'],fnVars['objVar']);
	//inlineErrMsg(1,'prop_code','Email send',3,fnVars['frmID']);
	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;
	
}