var touchapplication="false";
var keyboard="false";

function setuptouchapplication(ty){
	if (ty=='keyboard'){
		
		touchapplication="true";
		keyboard="true";
	}else if (ty=='nokeyboard'){
	
		touchapplication="true";
	}
}
function load_touchlink_other(str){
	sendAirEvent(str);
}
function touchapp_detail_link(property,ID,propertytype){
	
	//THIS SECTION OF CODE IS  RESERVED FOR TOUCH APPLICATION. 
	//THIS HANDLES THE DETAILS HYPERLINK ONLY.
		
	// at this point check to see if the property that is to be previewed is a featured listing or rental. If it isnt send it to the proper page. If it is, send it to the featured page.
	var url = "../../check_featured_preview.aspx?ID="+ID+"&propertytype="+propertytype;
	var xml = new JKL.ParseXML( url );
	var data = xml.parse();
	var theresult = data["interfacedata"]["resultStatus"];
	
	switch (theresult){
		case "true":
			//NATHANS LINK
				//var preview = window.open('featured.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true','_blank','');
				sendAirEvent('featured.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true')
			break;
		case "false": //not featured
				if (property=='rent' || propertytype=='REN'){
					//NATHANS LINK
					//var preview = window.open('rentals.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true','_blank','');
					sendAirEvent('rentals.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true')
				}else{
					//NATHANS LINK
					//var preview = window.open('listings.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true','_blank','');
					sendAirEvent('listings.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype+'&touch=true')
				}
			break;
		default:
			break;
	}
	
}
function sendAirEvent(varToPass){
	//Generate an artificial click event 
	//alert("sending air event")
	var clickevent=document.createEvent("MouseEvents")
	clickevent.initEvent("click", true, true)
	clickevent.pageVar = varToPass
	document.getElementById("dummyAirElement").dispatchEvent(clickevent)
	//alert(document.getElementById("dummyAirElement"))
}
function touchapp_load_neighborhood_detail(id){
	//THIS SECTION OF CODE IS  RESERVED FOR TOUCH APPLICATION. 
	//window.open("neighborhood.aspx?id="+id+"&c="+logged_in_id)
	sendAirEvent("neighborhood.aspx?id="+id+"&c="+logged_in_id+"&touch=true")
}
function check_garage_status(str){
	if (str=="rent"){
		document.getElementById('garagelabel').style.display="none"
		document.getElementById('featuredlabel').style.display="none"
		document.getElementById('HomeType').style.display="none"
		document.forms['thesearchform'].featuredlistings.checked=false;
	}else{
		document.getElementById('HomeType').style.display="block"
		document.getElementById('garagelabel').style.display="block"
		document.getElementById('featuredlabel').style.display="block"
	}
}
function handleSliderUpdate(jsTarget, min, max){
	//alert(jsTarget)
	if (jsTarget=='price'){
		document.getElementById('minprice').value = min;
		document.getElementById('maxprice').value = max;
	}else{ //footage
		document.getElementById('minft').value = min;
		document.getElementById('maxft').value = max;
	}
}
function dropdown_handler(query,addto){
	if (query.selectedIndex!=0){
		var index = query.selectedIndex;
		document.getElementById(addto).value = query.options[index].value;
	}
}
function click_blur(objname,copy,func){
if (func=='click'){
	if (document.getElementById(objname).value==copy){
		document.getElementById(objname).value="";
	}
	}else{
		if (document.getElementById(objname).value==""){
			document.getElementById(objname).value=copy;
		}
	}
}
function submit_indexfrm(){
	if (document.getElementById('first_name').value =="First Name" || document.getElementById('first_name').value =="" || document.getElementById('last_name').value =="Last Name" || document.getElementById('last_name').value =="" || document.getElementById('email').value =="" || document.getElementById('email').value =="Email" || document.getElementById('phone').value =="Phone" || document.getElementById('phone').value ==""){
		call_alert_com("All Fields are required. Please complete the entire form.");
		return;
	}else{
		if (echeck(document.getElementById('email').value)!=false){
			document.forms.thefrm.submit()
			//clear fields
			document.getElementById('first_name').value = "First Name";
			document.getElementById('last_name').value = "Last Name";
			document.getElementById('email').value = "Email";
			document.getElementById('phone').value = "Phone";
			document.getElementById('description').value = "";
			
		}
			
	}

}
function submitted_short_contact_form(){
	//alert("hit");
	call_alert_com("Thank you for your inquiry. A member from the team with contact you.");
}
function runbodyfunction(str){
	
	if (str!=''){
		logged_in_status="true";
		logged_in_id=str;
	}
}
function save_favorite(ID,propertytype,address,price,bed,bath,interestType,zip){
	
	if (logged_in_status=='true'){
	
		
		var url = "../../add_favorites_interface.aspx?ID="+ID+"&userid="+logged_in_id+"&propertytype="+propertytype+"&address="+address+"&price="+price+"&bed="+bed+"&bath="+bath+"&interesttype="+interestType+"&zip="+zip; //items from login_register_forms.js
		
		//these were messing things up . replaced on the .net end
		url = url.split("\'").join("[apos]")
		url = url.split("#").join("[pnd]")
		
		var xml = new JKL.ParseXML( url );
		var data = xml.parse();
		var theresult = data["interfacedata"]["resultStatus"];
		
		switch (theresult){
			case "Exists":
				call_alert_com("This property already exists in your favorites list.");
				//alert("This property already exists in your favorites list.");
				break;
			case "Saved":
				call_alert_com("Your favorite property has been saved.");
				
				break;
			default:
				break;
		}
	}else{
		call_alert_com("You must sign in before you can add a favorite.");
		//alert("You must sign in before you can add a favorite.");
		document.getElementById('column1').style.display="none"; //ensure that the results form is NOT shown
		document.getElementById('column2').style.display="block"; //ensure that the login form is displayed
	}
}
function remove_favorite(ID,propertytype,address,price,bed,bath,interestType,zip){
	
		var url = "../../add_favorites_interface.aspx?remove=true&ID="+ID+"&userid="+logged_in_id;
		var xml = new JKL.ParseXML( url );
		var data = xml.parse();
		
		call_alert_com("Favorite has been removed.");
		load_favorite_listings()
	
}
function remove_neighborhood_favorite(name,ID){
	
		var url = "../../add_favorites_interface.aspx?remove=true&propertytype=neighborhood&ID="+ID+"&userid="+logged_in_id;
		var xml = new JKL.ParseXML( url );
		var data = xml.parse();
		
		call_alert_com("Favorite has been removed.");
		load_favorite_listings()
	
}
function save_fav_from_neigborhooddetail(uid,name,ID){
	if (uid!=''){
		logged_in_status='true';
		logged_in_id=uid;
		save_neighborhood_favorite(name,ID)
		//add_favorites_interface.aspx?ID="+ID+"&userid="+logged_in_id+"&propertytype="+propertytype+"&address="+address+"&price="+price+"&bed="+bed+"&bath="+bath+"&interesttype="+interesttype; 
	}else{
		call_alert_com("You must be logged in to save favorites. Please return to the main page and <a href=\"index.aspx?account=true\" >sign in</a>.");
	}
	
}
function save_neighborhood_favorite(name,ID){

	if (logged_in_status=='true'){
		var url = "../../add_favorites_interface.aspx?ID="+ID+"&userid="+logged_in_id+"&propertytype=neighborhood"; //items from login_register_forms.js
		
		var xml = new JKL.ParseXML( url );
		var data = xml.parse();
		var theresult = data["interfacedata"]["resultStatus"];
		
		switch (theresult){
			case "Exists":
				call_alert_com("This property already exists in your favorites list.");
				break;
			case "Saved":
				call_alert_com("Your favorite neighborhood has been saved.");
				break;
			default:
				break;
		}
	}else{
		call_alert_com("You must sign in before you can add a favorite.");
		document.getElementById('column1').style.display="none"; //ensure that the results form is NOT shown
		document.getElementById('column2').style.display="block"; //ensure that the login form is displayed
	}
}
function homepagesearch(){	
	if (document.getElementById("txtsearch").value=="Find Orlando Homes for Sale, by MLS # or address"){
		document.location = 'index.aspx?find=search&criteria=';
	}else{ document.location = 'index.aspx?find=search&criteria='+document.getElementById("txtsearch").value;
	}
	
}
function load_preview(property,ID,propertytype){

	// at this point check to see if the property that is to be previewed is a featured listing or rental. If it isnt send it to the proper page. If it is, send it to the featured page.
	var url = "../../check_featured_preview.aspx?ID="+ID+"&propertytype="+propertytype;
	var xml = new JKL.ParseXML( url );
	var data = xml.parse();
	var theresult = data["interfacedata"]["resultStatus"];
	
	switch (theresult){
		case "true":
				var preview = window.open('featured.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype,'_blank','');
				preview.focus();
			break;
		case "false": //not featured
				if (property=='rent' || propertytype=='REN'){
					var preview = window.open('rentals.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype,'_blank','');
					preview.focus();
				}else{
				//	alert('listings.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype);
					var preview = window.open('listings.aspx?ID='+ID+'&u='+logged_in_id+'&propertytype='+propertytype,'_blank','');
					preview.focus();
				}
			break;
		default:
			break;
	}
	

	
}
function noenter() {
  return !(window.event && window.event.keyCode == 13); }

function check_add_to_favorites(u,id,propertytype){
	if (u!=''){
		save_favorite(id,propertytype);
		//add_favorites_interface.aspx?ID="+ID+"&userid="+logged_in_id+"&propertytype="+propertytype+"&address="+address+"&price="+price+"&bed="+bed+"&bath="+bath+"&interesttype="+interesttype; 
	}else{
		call_alert_com("You must be logged in to save favorites. Please return to the main page and <a href=\"index.aspx?account=true\" >sign in</a>.");
	}
	
}
function remove_all_favorites(){
	if (confirm("Are you sure you would like to remove all favorite properties?")){
		xml = new JKL.ParseXML("../../add_favorites_interface.aspx?removeall=true&memberid="+logged_in_id);
		data = xml.parse();
		call_alert_com("All favorite properties have been removed.");
		load_favorite_listings() //reload
	}
}
function call_alert_com(str){
	document.getElementById("domWrapper").style.display="block";
	document.getElementById("dom").innerHTML="<p>"+str+"</p>"
	document.getElementById("domLink").innerHTML="<a href='javascript:closedom();\' ></a>"
	
}
function closedom(){
	document.getElementById("domWrapper").style.display="none";
}