function Ajax() {
	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 SendLead() {
	var url = "/app/leads.php"
	var method = "post";
	var ObjAjax =  new Ajax();

	var MLS_ID = document.getElementById("MLS_ID");

	var fname = document.getElementById("fname");
	var lname = document.getElementById("lname");
	var email = document.getElementById("emailadd");
	var phome = document.getElementById("phonehome");
	var pmobile = document.getElementById("phonemobile");
	var pwork = document.getElementById("phonework");
	var city = document.getElementById("cityname");
	var zip = document.getElementById("zip");
	var ctype = document.getElementById("customer_type");
	var ptype = document.getElementById("property_type");
    var plocation = document.getElementById("CityList");
	var bed = document.getElementById("bed");
	var bath = document.getElementById("bath");
	var area = document.getElementById("area");
	var pricefrom = document.getElementById("price_from");
	var priceto = document.getElementById("price_to");
	var movetime = document.getElementById("move_time");

	var msg_cont = document.getElementById("msg_cont");
	var btn = document.getElementById("cmd");
	msg_cont.innerHTML = "Sending Lead Form...Please wait...";
	btn.disabled = true;
	
	
	var parameters="fname="+fname.value+"&lname="+lname.value+"&email="+email.value+"&phome="+phome.value+"&pmobile="+pmobile.value+"&pwork="+pwork.value+"&city="+city.value+"&zip="+zip.value+"&ctype="+ctype.value+"&ptype="+ptype.value+"&plocation="+plocation.value+"&bed="+bed.value+"&bath="+bath.value+"&area="+area.value+"&pricefrom="+pricefrom.value+"&priceto="+priceto.value+"&movetime="+movetime.value;
	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 (myajax.responseText=="<pre>Invalid</pre>") 
				{
				alert("Not a Valid Email Address");
				}
				else
				{
				msg_cont.innerHTML = "Redirecting to property page...Please wait...";
				window.location.href = '/property/'+ MLS_ID.value;
				} 
			
			}
		}
	}
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}


function VisLogin() {
	var url = "/app/vlogin.php"
	var method = "post";
	var ObjAjax =  new Ajax();
	
	var MLS_ID = document.getElementById("MLS_ID");

	var username = document.getElementById("username");
	var password = document.getElementById("password");

	var msg_v = document.getElementById("msg_v");
	msg_v.innerHTML = "Login Account...Please wait...";
	
	var parameters="username="+username.value+"&password="+password.value;
	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 (myajax.responseText == "Invalid") 
				{
				msg_v.innerHTML = "Invalid Login Information";
				}
				else
				{
				msg_cont.innerHTML = "Redirecting to property page...Please wait...";
				window.location.href = '/property/'+ MLS_ID.value;
				} 
			
			}
		}
	}
	ObjAjax.postAjaxRequest(url, parameters, this.processGetPost, 'txt');
	return;	
}


