/*
	Created			:		S.k.v
	Date				:		Aug 03 07
	Modified		:		May 13 08 ,S.k.v
*/
var http = null;
//Function to Show the Properties for Sales / Rent
function showProperty(username,transaction,usertype,offset, addparam ){
	d.getElementById('current').innerHTML = ip.loading("Loading...");
	http = new getHTTPObject();
	url = ip.host() + "/index.php?option=search&page=similarpropresults&uname="+username+"&trans="+transaction+"&usertype="+usertype+"&notemplate=yes";
	if(offset>0) url = url + "&offset="+offset;
	if(addparam != '' || addparam!='undefined')	url	= url + addparam;
	http.open('get',url,true);	
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			var response = http.responseText;
			if(response=="") response="Request has been cancelled by the user.";
			d.getElementById('current').innerHTML = response;
		}
	};
	http.send(null);
}
//Function to Show the Properties for Buy/Rent Request
function showProperty4Buy(username,transaction,usertype){
	d.getElementById('current').innerHTML = ip.loading("Loading...");
	http = new getHTTPObject();
	http.open('get',ip.host() + '/index.php?option=search&page=similarpropbuyresults&uname='+username+'&trans='+transaction+'&usertype='+usertype+'&notemplate=yes');
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			var response = http.responseText;
			d.getElementById('current').innerHTML = response;
		}
	};
	http.send(null);
}
function sendenquiry(frm){
	if(!ValidCallSeller(frm)) return false;
	http = new getHTTPObject();
	var name 	  = frm.strname.value;
	var email 	  = frm.stremail.value;
	var phone 	  = frm.strphone.value;
	var msg 	  = frm.strmessage.value;
	var strtoname = frm.strtoname.value;
	var url = "strname="+name+"&stremail="+email+"&strphone="+phone+"&strmessage="+msg+"& username="+strtoname;
	var urltoget = ip.host() + "/index.php?option=search&page=similar_mailenquiry&notemplate=yes&"+url;
	d.getElementById("MailEnquiryTable").style.display = "none";
	d.getElementById("mailenquiry").style.display ="";
	d.getElementById("mailenquiry").innerHTML=  ip.loading("Sending mail...Please wait");
	if (http){
		http.open("GET", urltoget, true);
		http.send(null);
		http.onreadystatechange = function(){
			if (http.readyState == 4){
				var res = (http.responseText=="0") ? "Enquiry sending failed..." : http.responseText;
				d.getElementById("mailenquiry").innerHTML=  res + "<br clear=\"all\"/>";
				/*setTimeout(function(){
					d.getElementById("mailenquiry").style.display = "none";
					d.getElementById("MailEnquiryTable").style.display = "";
				},10000);
				frm.strname.value="";
				frm.stremail.value="";
				frm.strphone.value="";
				frm.strmessage.value="";
				*/
			}
		};
	}
	return false;	//always it doesnt return true... becoz ajax
}
function ValidCallSeller(frm) {
	if(!IsMandatory(frm.strname,"text","Please enter a name.")) return false;
	if(IsMin(frm.strname.value,4)) return ip.throwErr(frm.strname,"Name must contain a minimum of 4 characters.");
	if(!IsValidCharacters(frm.strname.value, alphabets + "&.-_ ",alphabets)) return ip.throwErr(frm.strname,"Special characters are not allowed. Please use only alphabets.");
	if(!IsMandatory(frm.stremail,"text","Please enter an e-mail ID.")) return false;
	if(!ip.IsValidEmail(frm.stremail.value)) return ip.throwErr(frm.stremail,"Please enter a valid e-mail ID.");
	if(!IsMandatory(frm.strphone,"text","Please enter a phone number.")) return false;
	if(!IsValidCharacters(frm.strphone.value, numbers + "- ",numbers)) return ip.throwErr(frm.strphone,"Special characters are not allowed.");
	if(IsMin(frm.strphone.value,8)) return ip.throwErr(frm.strphone,"Please check the phone number.");
	if(!IsMandatory(frm.strmessage,"textarea","Please enter your message.")) return false;
	if(IsMin(frm.strmessage.value,50)) return ip.throwErr(frm.strmessage,"Message should not be less than 50 characters.");
	if(IsMax(frm.strmessage.value,140)) return ip.throwErr(frm.strmessage,"Message cannot exceed 140 characters.");
	if(!IsValidCharacters(frm.strmessage.value, alphabets + numbers + " ,.?/;:'!@#$%*()-_+=|\[]{}",alphabets + numbers)) return ip.throwErr(frm.strmessage,"Special characters are not allowed.");
	return true;
}