//

$d = document;
$e = function(el) {
	$el = $d.getElementById(el);
	return $el;
}

//
$d.refreshTime = 30000;

//
function GAJAX() {

	this.createAjaxObj = function() {
		var httprequest=false;
		if (window.XMLHttpRequest){ 
			httprequest=new XMLHttpRequest();
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml');
		}
		else if (window.ActiveXObject){ 
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
			}
		}
		return httprequest;
	}

	this.ajaxpack=new Object();
	this.ajaxpack.basedomain="http://"+window.location.hostname;
	this.ajaxpack.ajaxobj=this.createAjaxObj();
	this.ajaxpack.filetype="txt";
	this.ajaxpack.addrandomnumber=0;

	this.getAjaxRequest = function(url, parameters, callbackfunc, filetype){
		this.ajaxpack.ajaxobj=this.createAjaxObj(); 
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
		if (this.ajaxpack.ajaxobj){
			this.ajaxpack.filetype=filetype;
			this.ajaxpack.ajaxobj.onreadystatechange=callbackfunc;
			this.ajaxpack.ajaxobj.open('GET', url+"?"+parameters, true);
			this.ajaxpack.ajaxobj.send(null);
		}
	}

	this.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
		this.ajaxpack.ajaxobj=this.createAjaxObj();
		if (this.ajaxpack.ajaxobj){
			this.ajaxpack.filetype=filetype;
			this.ajaxpack.ajaxobj.onreadystatechange = callbackfunc;
			this.ajaxpack.ajaxobj.open('POST', url, true);
			this.ajaxpack.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.ajaxpack.ajaxobj.setRequestHeader("Content-length", parameters.length);
			this.ajaxpack.ajaxobj.setRequestHeader("Connection", "close");
			this.ajaxpack.ajaxobj.send(parameters);
		}
	}	
}

//
function SamplePost() {
	var url = ""
	var method = "post";
	var ObjAjax =  new GAJAX();
	var gcmd1 = document.getElementById("gcmd1");
	var parameters="";
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				alert("Page successfully save!" + myajax.responseText);
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}

//
function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(email)) {
		return true;
	}
	return false;
}

//
function stripTags(html) {
	return html.replace(/(<([^>]+)>)/ig,"").replace(/^\s+|\s+$/g,"");
}

//
function gpopwin(url,width,height) {
	var defWidth = 200;
	var defHeight = 200;
	if(width.length>0) {
		defWidth = width;
	} else {
		width = 100;
	}
	if(height.length>0) {
		defHeight = height;
	} else {
		height = 100;
	}
	var winTop = window.screen.availHeight;
	var winLeft = window.screen.availWidth;
	winTop = (winTop/2) - (height/2);
	winLeft = (winLeft/2) - (width/2);
	if(defWidth>window.screen.availWidth) {
		defWidth = window.screen.availWidth;
	}
	if(defHeight>window.screen.availHeight) {
		defHeight = window.screen.availHeight;
	}
	if(parseInt(defHeight)<height) {
		defHeight = height;
	}
	var gwin = window.open(url,"_blank","status=no,scrollbars=no,toolbar=no,resizable=no,location=no,menubar=no," +
		"top="+winTop+",left="+winLeft+",height="+defHeight+",width="+defWidth);
	return gwin;
}

//
function OpenSignupForm() {
	var w = "371"; var h = "560";
	var url = "create-account.htm";
	if($d.frm_signup) {
		if($d.frm_signup.closed) {
			$d.frm_signup = gpopwin(url,w,h);
		} else {
			$d.frm_signup.focus();
		}
	} else {
		$d.frm_signup = gpopwin(url,w,h);
	}
}

//
function OpenSigninForm() {
	var w = "311"; var h = "230";
	var url = "sign-in.htm";
	if($d.frm_signin) {
		if($d.frm_signin.closed) {
			$d.frm_signin = gpopwin(url,w,h);
		} else {
			$d.frm_signin.focus();
		}
	} else {
		$d.frm_signin = gpopwin(url,w,h);
	}
}

//
function OnAddListingSubmit(stepid) {
	var with_err = false;
	var err_msg = "Please complete the following fields: \n";
	var frm = $d.frmAdder;
	if(stepid==1) {
		/*
		if(frm.fld_street_number.value=="") {
			with_err = true;
			err_msg += "     - Street Number \n";
		}
		*/
		if(frm.fld_street_name.value=="") {
			with_err = true;
			err_msg += "     - Street Name \n";
		}
		if(frm.fld_city.value=="") {
			with_err = true;
			err_msg += "     - City \n";
		}		
		if(frm.fld_zip_code.value=="") {
			with_err = true;
			err_msg += "     - Zip Code \n";
		}		
	} else if(stepid==2) {
		if(frm.fld_listing_price.value=="") {
			with_err = true;
			err_msg += "     - Listing Price \n";
		} else {
			if(isNaN(frm.fld_listing_price.value)) {
				with_err = true;
				err_msg += "     - Listing Price is not numeric\n";
			}
		}
		if(frm.fld_square_feet.value=="") {
			with_err = true;
			err_msg += "     - Square Feet \n";
		}			
		if(frm.fld_square_feet.value=="") {
			with_err = true;
			err_msg += "     - Square Feet \n";
		}					
		if(frm.fld_description.value=="") {
			with_err = true;
			err_msg += "     - Descriptions \n";
		}							
		if(frm.fld_listing_title.value=="") {
			with_err = true;
			err_msg += "     - Listing Title \n";
		}					
		if(frm.fld_listing_url.value=="") {
			with_err = true;
			err_msg += "     - Listing URL \n";
		}							
	} else if(stepid==3) {
		if(frm.fld_photo_uploaded.value=="" && frm.fld_photo_url.value=="") {
			with_err = true;
			err_msg += "     - Photo Upload/URL required \n";
		}											
	} else if(stepid==4) {
		if(!frm.fld_agree.checked) {
			with_err = true;
			err_msg = "You must agree with the terms and condition.";
		}													
	} else if(stepid==5) {
	}
	if(with_err) {
		alert(err_msg);
	} else {
		frm.submit();
	}
}

//
function AddListingStepLoader(stepid) {
	var url = "include/add-listing-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=load&stepid="+stepid;
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var postInfo = myajax.responseText;
				$e("add-stepper").innerHTML = postInfo;
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		
}

//
function EditListingStepLoader(stepid) {
	var url = "include/edit-listing-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=load&stepid="+stepid;
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var postInfo = myajax.responseText;
				$e("add-stepper").innerHTML = postInfo;
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		
}

//
function ActivateSearchTab(tab_id) {
	if(!$d.ctab_id) {
		$d.ctab_id = 1;
	}
	$e("search-tab"+$d.ctab_id).style.display="none";	
	$e("search-tab"+tab_id).style.display="";
	$d.ctab_id = tab_id;
}

//
function onSubmitSignUp(frm) {
	var with_err = false;
	var err_msg = "Please complete the following fields: \n";
	if(frm.fld_firstname.value=="") {
		with_err = true;
		err_msg += "     - Firstname \n";
	}
	if(frm.fld_lastname.value=="") {
		with_err = true;
		err_msg += "     - Lastname \n";
	}
	if(frm.fld_address.value=="") {
		with_err = true;
		err_msg += "     - Location \n";
	}
	if(frm.fld_password.value=="") {
		with_err = true;
		err_msg += "     - Password \n";
	} else {
		if(frm.fld_password.value.length>=4) {
			if(frm.fld_password.value!=frm.fld_cpassword.value) {
					with_err = true;
					err_msg += "     - Re-Type password not match\n";
			}		
		} else {
			with_err = true;
			err_msg += "     - Password must have 4 characters minimum in length\n";		
		}
	}
	if(frm.fld_email.value=="") {
		with_err = true;
		err_msg += "     - Email \n";		
	} else {
		if(!checkEmail(frm.fld_email.value)) {
			with_err = true;
			err_msg += "     - Invalid Email Address \n";				
		}		
	}
	if(with_err) {
		err_msg += "\n Thank you!";
		alert(err_msg);
	} else {
		validateSignUp(frm);
	}
	return false;
}

//
function validateSignUp(frm) {
	var url = "include/signup-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=check&fld_email=" + frm.fld_email.value;

	$e("statSignup").innerHTML = "Validating wait...";	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>exist</pre>') {
					$e("statSignup").innerHTML = "";
					alert("Email address already exist!");
				} else {				
					frm.submit();
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;			
}

//
function OnSignupSaveCompleted(msg) {
	$e("divSignup").innerHTML = msg;
}

//
function OnSubmitSignin(frm) {
	var with_err = false;
	var err_msg = "Please complete the following fields: \n";
	if(frm.fld_email.value=="") {
		with_err = true;
		err_msg += "     - Email \n";
	}
	if(frm.fld_password.value=="") {
		with_err = true;
		err_msg += "     - Password \n";
	}
	if(with_err) {
		alert(err_msg);
	} else {
		validateSignIn(frm);
	}
	return false;	
}

//
function validateSignIn(frm) {
	var url = "include/signin-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=signin&fld_email=" + frm.fld_email.value + "&fld_password=" + frm.fld_password.value;

	$e("statSignin").innerHTML = "Validating wait...";	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>denied</pre>') {
					$e("statSignin").innerHTML = "";
					alert("Invalid user email/password!");
				} else {			
					window.opener.$e("header").innerHTML = logInfo;
					window.close();
					if(window.opener.location.href.indexOf("index.htm")>0) {
						window.opener.loadRighBox();
					}
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}

//
function loadRighBox() {
	var url = "include/index-right-box-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="";

	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				$e("contRight").innerHTML = logInfo;
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
	
}

//
function SignOut() {
	var url = "include/signin-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=logout";

	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				$e("header").innerHTML = logInfo;
				if(window.location.href.indexOf("index.htm")>0) {
					loadRighBox();
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
	
}

//
function OnChangeMemberType(target) {
	if(target.value=="Real Estate Pro") {
		$e("fld_pro_type").disabled = "";
	} else {
		$e("fld_pro_type").value = "";
		$e("fld_pro_type").disabled = "disabled";
	}
}

//-------------------------------------------------------------------------------------------------------------------------------------

//
function OnSearchTabSubmit(id) {
	var with_err = false;
	var err_msg = "Please complete the following fields: \n";
	frm = $d["frmTab"+id];
	if(id==1 || id==3 || id==6) {
		if(frm.fld_city.value=="") {
			with_err = true;
			err_msg += "     - City \n";
		}
	} 
	if(id==2) {
		if(frm.fld_zip_code.value=="") {
			with_err = true;
			err_msg += "     - Zip Code \n";
		}				
	}
	if(id==3) {
		if(frm.fld_street_number.value=="") {
			with_err = true;
			err_msg += "     - Street Number \n";
		}				
		if(frm.fld_street_name.value=="") {
			with_err = true;
			err_msg += "     - Street Name \n";
		}						
	}	
	if(id==4) {
		if(frm.fld_country.value=="") {
			with_err = true;
			err_msg += "     - County/Country \n";
		}								
	}
	if(id==5) {
		if(frm.fld_school.value=="") {
			with_err = true;
			err_msg += "     - School \n";
		}								
	}	
	if(id==6) {
		if(frm.fld_mls_id.value=="") {
			with_err = true;
			err_msg += "     - MLS ID \n";
		}								
	}	
	if(id==7) {
		if(frm.fld_zip_city.value=="") {
			with_err = true;
			err_msg += "     - City/Zip \n";
		}								
	}			
	if(with_err) {
		alert(err_msg);
		return false;
	}
	frm.submit();
}

//
function onToggleUpdate(target,utype,key) {
	var ischecked = target.checked;
	var action = "";
	if(ischecked) {
		action = "add";
	} else {
		action = "remove";
	}
	var url = "include/update-data-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="utype="+utype+"&listing_id="+key+"&action="+action;
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				//alert(myajax.responseText);
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
	
}

//
function DeleteListing(key) {
	var nret = confirm("Delete this listing permanently?");
	if(!nret) {
		return;
	}
	var url = "include/update-data-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="utype=d1&listing_id="+key+"&action=remove";
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				$e("item"+key).style.display = "none";
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		
}

//
function PostComment(key,author) {	
	if(author=='') {
		alert("This feature available only for members.");
		return;
	}
	if($e("fld_comment").value=="") {
		alert("Comment required!");
		return;
	}
	var url = "include/comment-data-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=add&listing_id="+key+"&comment="+$e("fld_comment").value;
	
	$e("btnComment").disabled = "disabled";
	$e("fld_comment").disabled = "disabled";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				if($e("contComments").innerHTML.indexOf("NoComment")>0) {
					$e("contComments").innerHTML = myajax.responseText;
				} else {
					$e("contComments").innerHTML += myajax.responseText;
				}
				$e("fld_comment").value = "";
				$e("btnComment").disabled = "";
				$e("fld_comment").disabled = "";				
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		
}

//
function PostQuestion(key,author) {	
	if(author=='') {
		alert("This feature available only for members.");
		return;
	}
	if($e("fld_question").value=="") {
		alert("Question required!");
		return;
	}
	var url = "include/question-data-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=add&listing_id="+key+"&question="+$e("fld_question").value;
	
	$e("btnQuestion").disabled = "disabled";
	$e("fld_question").disabled = "disabled";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				if($e("contQuestions").innerHTML.indexOf("NoQuestion")>0) {
					$e("contQuestions").innerHTML = myajax.responseText;
				} else {
					$e("contQuestions").innerHTML += myajax.responseText;
				}
				$e("fld_question").value = "";
				$e("btnQuestion").disabled = "";
				$e("fld_question").disabled = "";				
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		
}

//
function ShowProfileEditForm() {
	$e("contProfile").style.display = "none";
	$e("formProfile").style.display = "";
	if($e("formProfile").innerHTML!="") {
		return;
	}
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=load-profile";

	$e("formProfile").innerHTML = "Loading wait...";
	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				$e("formProfile").innerHTML = myajax.responseText;
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;		

}

//
function CancelEditProfile() {
	$e("contProfile").style.display = "";
	$e("formProfile").style.display = "none";
}

//
function OnSubmitEditProfile(frm) {
	var with_err = false;
	var err_msg = "Please complete the following fields: \n";
	if(frm.fld_firstname.value=="") {
		with_err = true;
		err_msg += "     - Firstname \n";
	}
	if(frm.fld_lastname.value=="") {
		with_err = true;
		err_msg += "     - Lastname \n";
	}
	if(frm.fld_address.value=="") {
		with_err = true;
		err_msg += "     - Location \n";
	}
	if(frm.fld_email.value=="") {
		with_err = true;
		err_msg += "     - Email \n";		
	} else {
		if(!checkEmail(frm.fld_email.value)) {
			with_err = true;
			err_msg += "     - Invalid Email Address \n";				
		}		
	}
	if(with_err) {
		err_msg += "\n Thank you!";
		alert(err_msg);
	} else {
		if(frm.fld_email.value!=frm.old_email.value) {
			validateEditProfile(frm);
		} else {
			frm.submit();
		}
	}
	return false;
}

//
function validateEditProfile(frm) {
	var url = "include/signup-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=check&fld_email=" + frm.fld_email.value;

	$e("statSignup").innerHTML = "Validating wait...";	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>exist</pre>') {
					$e("statSignup").innerHTML = "";
					alert("Email address already exist!");
				} else {				
					frm.submit();
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;			
}

//
function OnPostEditProfile() {
	$e("contProfile").style.display = "";
	$e("formProfile").style.display = "none";	
	$e("contFullname").innerHTML = $e("fld_firstname").value + " " + $e("fld_lastname").value;
	$e("contHeadline").innerHTML = $e("fld_headline").value;
	$e("contProType").innerHTML = $e("fld_member_type").value;
	if($e("fld_member_type").value=="Real Estate Pro") {
		$e("contProType").innerHTML += " as " + $e("fld_pro_type").value;
	}
	$e("contProName").innerHTML = $e("fld_profile_name").value;
	$e("contEmail").innerHTML = $e("fld_email").value;
	$e("contPhone").innerHTML = $e("fld_phone").value;
	alert("Profile updated!");
}

//
function ShowAboutEditForm() {
	$e("contAbout").style.display = "none";
	$e("formAbout").style.display = "";
	$e("fld_about").value = $e("textAbout").innerHTML;
}

//
function PostAboutEditForm(target) {
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=save-aboutme&about_me=" + encodeURIComponent($e("fld_about").value);
	
	target.disabled = "disabled";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>posted</pre>') {
					target.disabled = "";
					$e("textAbout").innerHTML = $e("fld_about").value;
					$e("contAbout").style.display = "";
					$e("formAbout").style.display = "none";					
					alert("Profile updated!");
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;			
}

//
function CancelEditAbout() {
	$e("contAbout").style.display = "";
	$e("formAbout").style.display = "none";
}

//
function ShowInterestEditForm() {
	$e("contInterest").style.display = "none";
	$e("formInterest").style.display = "";
	$e("fld_interest").value = $e("textInterest").innerHTML;
}

//
function PostInterestEditForm(target) {
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=save-interest&interest=" + encodeURIComponent($e("fld_interest").value);
	
	target.disabled = "disabled";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>posted</pre>') {
					target.disabled = "";
					$e("textInterest").innerHTML = $e("fld_interest").value;
					$e("contInterest").style.display = "";
					$e("formInterest").style.display = "none";					
					alert("Profile updated!");
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;			
}

//
function CancelEditInterest() {
	$e("contInterest").style.display = "";
	$e("formInterest").style.display = "none";
}


//
function ShowQuestionEditForm(key) {
	$e("contQuestion"+key).style.display = "none";
	$e("formQuestion"+key).style.display = "";
	if($e("textQuestion" + key).innerHTML.indexOf("NoAnswer")>0) {
		$e("fld_question"+key).value = "";
	} else {	
		$e("fld_question"+key).value = $e("textQuestion" + key).innerHTML;
	}
}

//
function PostQuestionEditForm(target,key) {
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=save-answer&key="+key+"&answer=" + encodeURIComponent($e("fld_question"+key).value);
	
	target.disabled = "disabled";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>posted</pre>') {
					target.disabled = "";
					$e("textQuestion"+key).innerHTML = $e("fld_question"+key).value;
					$e("contQuestion"+key).style.display = "";
					$e("formQuestion"+key).style.display = "none";					
					alert("Answer posted!");
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;			
}

//
function CancelEditQuestion(key) {
	$e("contQuestion"+key).style.display = "";
	$e("formQuestion"+key).style.display = "none";
}

//
function AddtoMyHomes(mid,pid) {
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=add2homes&mid="+mid+"&pid="+pid;
	
	$e("contStatus").innerHTML = "Adding to your homes...wait...";
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>posted</pre>') {
					alert("Property successfully added to your save homes!");
				}
				$e("contStatus").innerHTML = "";
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}

//
function RemoveFromMyHomes(mid,pid) {
	var dret = confirm("Delete this item?");
	if(!dret) {
		return;
	}
	var url = "include/edit-profile-handler.php"
	var method = "post";
	var ObjAjax =  new GAJAX();
	var parameters="action=removehome&mid="+mid+"&pid="+pid;

	$e("itemHome"+pid).style.display="none";	
	this.processGetPost = function(){
		var myajax=ObjAjax.ajaxpack.ajaxobj;
		var myfiletype=ObjAjax.ajaxpack.filetype;
		if (myajax.readyState == 4){ 
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
				var logInfo = myajax.responseText;
				if(logInfo=='<pre>posted</pre>') {
					alert("Item successfully removed!");
				}
			}
		}
	}
	
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}

//
function ChangeLang(el) {
	//alert($e("target_url").value.replace("_lid_",el.value));
	$d.gform_lang.action = $e("target_url").value.replace("_lid_",el.value);
	$d.gform_lang.submit();
}

