function saveLocation() {
			var xht = getHttpRequest();
			xht.open("POST", 'core/saveDefaultLocation.php', true);
			xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xht.onreadystatechange = callback_Location;
			var date = new Date();
			date.setTime(date.getTime()+(1*60*60*1000));
		    expires = "; expires="+date.toGMTString();			
		    
		    document.cookie = "homey_default_loc"+"="+document.fDefault.default_location.options[document.fDefault.default_location.selectedIndex].value+expires+"; path=/";
		
			var objStr =  "dLocation="+document.fDefault.default_location.options[document.fDefault.default_location.selectedIndex].value;
			
			xht.send(objStr);		
}	
	
function callback_Location() {
	        if(xmlHttp.readyState==4)
	        {
	            if(xmlHttp.status==200)
	            {
	                var xmlDoc = xmlHttp.responseXML;
	                
	                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
	                
	                if (val == 1) {
							alert("Default Location Saved");		                
	                }	else {
		             	alert("Error Saving Default Location\nPlease Login to Your Account");   
	                }
                }
            }
	
}


function getCounties() {
			var xht = getHttpRequest();
			xht.open("POST", 'core/getCounties.php', true);
			xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xht.onreadystatechange = callback_countyListing;
		
			var objStr =  "";
			
			xht.send(objStr);		
}



function callback_countyListing() {
	        if(xmlHttp.readyState==4)
	        {
	            if(xmlHttp.status==200)
	            {
	                var xmlDoc = xmlHttp.responseXML;
	                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
	        		var bToggle = 0;        
	        		var nFeedID = 0;
	        		var sCounty = "";
	        		var sSelect = "<select name='county' onChange='selValue(\"Cnty\");'>\n";
	        		sSelect += "<option value=''>Select County</option>\n";
	                if (val == 1) {
						var root = xmlDoc.getElementsByTagName('counties')[0];
						for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
							var node = root.childNodes.item(iNode);	
			
			   				for (i = 0; i < node.childNodes.length; i++) {
			      					var sibling = node.childNodes.item(i);							
			      					
			      					if (bToggle == 0) {
			      						nFeedID = sibling.data;
			      						bToggle = 1;
			      						
		      						} else {
			      						bToggle = 0;
			      						sCounty = sibling.data;
			      						sSelect += "<option value='"+sCounty+"^"+nFeedID+"'>"+sCounty+"</option>\n";		
		      						}
			      					
		      				}
						}
		                
	                }	
	                
	                sSelect += "</select>\n";
	                
	                document.getElementById("col_city_cnty_zip").innerHTML = sSelect;
	                document.getElementById("city_cnty_zip").innerHTML = "<b>County:</b>";
	                document.fNarrow.cnty_city_zip[0].checked = true;
                }
            }
	
}

function getZipCodes() {
			var xht = getHttpRequest();
			xht.open("POST", 'core/getZipCodes.php', true);
			xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xht.onreadystatechange = callback_zipcodeListing;
		
			var objStr =  "";
			
			xht.send(objStr);		
}

function callback_zipcodeListing() {
	        if(xmlHttp.readyState==4)
	        {
	            if(xmlHttp.status==200)
	            {
	                var xmlDoc = xmlHttp.responseXML;
	                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
	        		var bToggle = 0;        
	        		var nFeedID = 0;
	        		var sZipCode = "";
	        		var sSelect = "<select name='zipcode' onChange='selValue(\"Zip\");'>\n";
	        		sSelect += "<option value=''>Select Zip Code</option>\n";
	                if (val == 1) {
						var root = xmlDoc.getElementsByTagName('zipcodes')[0];
						for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
							var node = root.childNodes.item(iNode);	
			
			   				for (i = 0; i < node.childNodes.length; i++) {
			      					var sibling = node.childNodes.item(i);							
			      					if (bToggle == 0) {
			      						nFeedID = sibling.data;
			      						bToggle = 1;
			      						
		      						} else {
			      						bToggle = 0;
			      						sZipCode = sibling.data;
			      						sSelect += "<option value='"+sZipCode+"^"+nFeedID+"'>"+sZipCode+"</option>\n";		
		      						}
			      					
		      				}
						}
		                
	                }	
	                sSelect += "</select>\n";
	                
	                document.getElementById("col_city_cnty_zip").innerHTML = sSelect;
	                document.getElementById("city_cnty_zip").innerHTML = "<b>Zip Code:</b>";
                }
            }
	
}

function getCities() {
			var xht = getHttpRequest();
			xht.open("POST", 'core/getCities.php', true);
			xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xht.onreadystatechange = callback_cityListing;
		
			var objStr =  "";
			
			xht.send(objStr);		
}

function callback_cityListing() {
	        if(xmlHttp.readyState==4)
	        {
	            if(xmlHttp.status==200)
	            {
	                var xmlDoc = xmlHttp.responseXML;
	                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
	        		var bToggle = 0;        
	        		var nFeedID = 0;
	        		var sCity = "";
	        		var sSelect = "<select name='city' onChange='selValue(\"City\");'>\n";
	        		sSelect += "<option value=''>Select City</option>\n";
	                if (val == 1) {
						var root = xmlDoc.getElementsByTagName('cities')[0];
						for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
							var node = root.childNodes.item(iNode);	
			
			   				for (i = 0; i < node.childNodes.length; i++) {
			      					var sibling = node.childNodes.item(i);							
			      					if (bToggle == 0) {
			      						nFeedID = sibling.data;
			      						bToggle = 1;
			      						
		      						} else {
			      						bToggle = 0;
			      						sCity = sibling.data;
			      						sSelect += "<option value='"+sCity+"^"+nFeedID+"'>"+sCity+"</option>\n";		
		      						}
			      					
		      				}
						}
		                
	                }	
	                sSelect += "</select>\n";
	                
	                document.getElementById("col_city_cnty_zip").innerHTML = sSelect;
	                document.getElementById("city_cnty_zip").innerHTML = "<b>City:</b>";
                }
            }
	
}
function FocusFirstField() {    
	var topIndex = null;    
	var fields = $("input:visible:enabled:first, select:visible:enabled:first, textarea:visible:enabled:first");     
	if (fields.size() > 0)        
	     topIndex = 0;     
	for (var i = 1; i < fields.size(); i++)       
	    if (fields[i].offsetTop < fields[topIndex].offsetTop)           
	topIndex = i;    
	if (topIndex != null)        
	fields.get(topIndex).focus();
}


		function getHttpRequest() {
		
			try
			  {
			  // Firefox, Opera 8.0+, Safari
			  xmlHttp=new XMLHttpRequest();
			  }
			catch (e)
			  {
			  // Internet Explorer
			  try
			    {
			    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			    }
			  catch (e)
			    {
			    try
			      {
			      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			      }
			    catch (e)
			      {
			      alert("Your browser does not support AJAX!");
			      return false;
			      }
			    }
			  }
		  return xmlHttp;
		}
		
	function saveListing(item,id) {

		if (cookieUserID > 0) {
			var xht = getHttpRequest();
			xht.open("POST", 'core/saveListing.php', true);
			xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xht.onreadystatechange = callback_saveListing;
		
			var objStr =  "mls="+item+"&table="+id+"&loc="+sCookieLocation;
			
			xht.send(objStr);		
		} else {
			loginHomey(item,id);	
		}

	}		
	
	function callback_saveListing() {
	        if(xmlHttp.readyState==4)
	        {
	            if(xmlHttp.status==200)
	            {
	                var xmlDoc = xmlHttp.responseXML;
	                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
	                if (val == 1) {
	                 	var mls = xmlDoc.getElementsByTagName("mls")[0].childNodes[0].nodeValue;
	                 	var table =  xmlDoc.getElementsByTagName("table")[0].childNodes[0].nodeValue;
	                    var html_id = mls+"_"+table;
	                    
						var cntListing =  xmlDoc.getElementsByTagName("cntlisting")[0].childNodes[0].nodeValue;
	                    var myget = $("[id*=html_id]").text(); 	
						$("#cntListing").html(cntListing);
	                    $('#'+html_id).unbind("click");
	                    document.getElementById(html_id).onclick=null;
						
	                    document.getElementById(html_id).innerHTML = "<font color=red>Saved To myHomey&nbsp;|&nbsp;View myHomey Listings</font>";
	                    //window.location.hash=mls+"_anchor"; 		
	                    //$('#'+html_id).attr("href", "myHomeyListings.php");
	                    document.getElementById(html_id).href = "myHomeyListings.php";
	                    
	                    
	                    
                    }
	                
	                
	            }
	        }
	
		
	}	

	

// prepare the form when the DOM is ready 
$(document).ready(function() { 
    var options_register = { 
        target:        '#registerBox',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequestRegister,  // pre-submit callback 
        success:       showResponseRegister,  // post-submit callback 
        dataType: 'xml',
        type: 'get'
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    var options_login = { 
        target:        '',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequestLogin,  // pre-submit callback 
        success:       showResponseLogin,  // post-submit callback 
        type: 'get',
        dataType: 'xml'
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };     
    
    var options_forget = { 
        target:        '',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequestForget,  // pre-submit callback 
        success:       showResponseForget,  // post-submit callback 
        type: 'get',
        dataType: 'xml'
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };         
    
    var options_account = { 
        target:        '',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequestAccount,  // pre-submit callback 
        success:       showResponseAccount,  // post-submit callback 
        type: 'get',
        dataType: 'xml'
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };     
        
    // bind to the form's submit event 
    $('#fAccount').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options_account); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
        
    // bind to the form's submit event 
    $('#fRegister').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options_register); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
    
    // bind to the form's submit event 
    $('#fLogin').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options_login); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });  
    
    // bind to the form's submit event 
    $('#fForget').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options_forget); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });      
       

    
    
        
});


// pre-submit callback 
function showRequestAccount(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
     var form = jqForm[0]; 
 	 var sMsg = "";
    if (form.sFirstName.value == "")
        sMsg = "<br>Please enter a first name";
    if (form.sLastName.value == "")
        sMsg += "<br>Please enter a last name";    
     if (form.sEmail.value == "")
        sMsg += "<br>Please enter a email address";    
        
    
 	if (sMsg > "") {
	 	$("#accountError").html(sMsg);
	 	return false;	
 	}        
 	
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponseAccount(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 

  	
	$(responseText).find("rc").each(function()
	{
		
		//valid registration
		if ($(this).text() == 1) {
			//set cookie
			sUserID = $(responseText).find("user_id").text();
			sName = $(responseText).find("user_name").text();
			sFacebook =$(responseText).find("facebook").text();
			
			$.cookies.set('homey',sUserID+','+sName);	
			cookieUserID = sUserID;

            $("#registerError").html("Account Updated");
                
         
		}	else {
			//account failed
		  	$("#registerError").html("Account Update Failed");
		}

	});            

} 				




// pre-submit callback 
function showRequestForget(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
     var form = jqForm[0]; 
 	 var sMsg = "";
    if (form.email.value == "")
        sMsg = "Please enter a email address";
        
        
 	if (sMsg > "") {
	 	$("#forgetError").html(sMsg);
	 	return false;	
 	}
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponseForget(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
  	
	$(responseText).find("rc").each(function()
	{

		//valid login
		if ($(this).text() == 1) {
			//set cookie
		   $("#forgetError").text("Your account credentials have been emailed too you");	
			$('#forgetBox').slideUp(0000);			
		} else {
		//invalid email address
		  
		  $("#forgetError").text("Account associated with email address has not been found");
		}

	});      	
        

} 






// pre-submit callback 
function showRequestLogin(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
     var form = jqForm[0]; 
 	 var sMsg = "";
    if (form.email.value == "")
        sMsg = "Please enter a email address";
    if (form.password.value == "")
        sMsg += "<br>Please enter a password";
        
        
 	if (sMsg > "") {
	 	$("#loginError").html(sMsg);
	 	return false;	
 	}

    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponseLogin(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
  	
	$(responseText).find("rc").each(function()
	{

		
		//valid login
		if ($(this).text() == 1) {
			//set cookie
			sUserID = $(responseText).find("user_id").text();
			sName = $(responseText).find("user_name").text();
			sMLS = $(responseText).find("mls").text();
			sTable = $(responseText).find("table").text();
			cntListings = $(responseText).find("cntlisting").text();
			
			$.cookies.set('homey',sUserID+','+sName);	
			cookieUserID = sUserID;
			$('#loginBox').slideUp(0000);			
			if (sMLS > "" && sTable > "") {
                var html_id = sMLS+"_"+sTable;

                var myget = $("[id*=html_id]").text(); 	

                

                document.getElementById(html_id).innerHTML = "<font color=red>Saved To myHomey&nbsp;|&nbsp;View myHomey Listings</font>";
                
				  $('#'+html_id).click(function(e) {
				     window.open("myHomeyListings.php","_self");
				     e.stopPropagation();
				     return false;

				   });	        
				               

			}
			var sMenuHTML = "Hello "+sName+" | <a href=\"myHomeyListings.php\">myHomey (<span id=\"cntListing\">"+cntListings+"</span> listings)</a> | <a href=\"myHomeyAccount.php\">My Account</a> | <a href=\"javascript:signOut();\">Sign Out</a>";
			
    		$("#myHomeyMenu").html(sMenuHTML);	
    		if (document.getElementById("location_section")) {
	    		document.getElementById("location_section").style.display = "block";
    		}
			
			
		} else if ($(this).text() == 0) {
		//invalid login
	
		  $("#loginError").text("Invalid Password, Please Try Again");
		} else {
		  $("#loginError").text("Invalid User Name, Please Try Again");	
		}

	});      	
        

} 




// pre-submit callback 
function showRequestRegister(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
     var form = jqForm[0]; 
 
 	 var sMsg = "";
    if (form.fName.value == "")
        sMsg = "<br>Please enter a first name";
    if (form.lName.value == "")
        sMsg += "<br>Please enter a last name";    
     if (form.password.value == "")
        sMsg += "<br>Please enter a password";    
     if (form.confirm_password.value == "")
        sMsg += "<br>Please enter a confirm password";    
     if (form.confirm_password.value != form.password.value)
        sMsg += "<br>Password and confirm password do not match";
     if (form.email.value == "")
        sMsg += "<br>Please enter a email address";    
        
    
 	if (sMsg > "") {
	 	$("#registerError").html(sMsg);
	 	return false;	
 	}        
 	
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponseRegister(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 

  	
	$(responseText).find("rc").each(function()
	{
		
		//valid registration
		if ($(this).text() == 1) {
			//set cookie
			sUserID = $(responseText).find("user_id").text();
			sName = $(responseText).find("user_name").text();
			sMLS = $(responseText).find("mls").text();
			sTable = $(responseText).find("table").text();

			$.cookies.set('homey',sUserID+','+sName);	
			cookieUserID = sUserID;
			$('#registerBox').slideUp(0000);		
			if (sMLS > "" && sTable > "") {
                var html_id = sMLS+"_"+sTable;
                var myget = $("[id*=html_id]").text(); 	
                document.getElementById(html_id).innerHTML = "<font color=red>Saved To myHomey&nbsp;|&nbsp;View myHomey Listings</font>";
                
				  $('#'+html_id).click(function(e) {
				     window.open("myHomeyListings.php","_self");
				     e.stopPropagation();
				     return false;

				   });	                    

			}	
			var sMenuHTML = "Hello "+sName+" | <a href=\"myHomeyListings.php\">myHomey (<span id=\"cntListing\">0</span> listings)</a> | <a href=\"myHomeyAccount.php\">My Account</a> | <a href=\"javascript:signOut();\">Sign Out</a>";
			
    		$("#myHomeyMenu").html(sMenuHTML);	
    	    window.open("myHomeyListings.php?register=1","_self");
			
		} else if ($(this).text() == 2) {
			$("#registerError").html("Email address is already registered");	
		} else if ($(this).text() == 3) {
			$("#registerError").html("Email address is already registered");	
		}	else {
			//registration failed
		  	$("#registerError").html("Registration failed");
		}

	});            

} 








/* this function will be called from listing to login to home */
function loginHomey(sMLS,sTable) {
	 $('#registerBox').slideUp(0000);
	 $('#loginBox').slideDown(0000);
	 $('#loginError').html("");
	 document.getElementById("login_mlsid").value = sMLS;
	 document.getElementById("login_table").value = sTable;
	 document.getElementById("register_mlsid").value = sMLS;
	 document.getElementById("register_table").value = sTable;
	 
	 document.getElementById("login_loc").value = sCookieLocation;
	 document.fLogin.email.focus();

	 
 	
}

function registerHomey() {
	 $('#loginBox').slideUp(0000);
	 $('#registerBox').slideDown(0000);
	 $('#registerError').html("");
	document.fRegister.fName.focus();
}

/* the following are for the buttons on the forms */
$(function() {
 $('#loginTag').click(function() {
	 
	 $('#loginBox').slideDown(0000);
	 $('#loginError').html("");
	 document.fLogin.email.focus();
 	}
 	
 	);
 	
 $('#bLoginCancel').click(function() {
	 
	 $('#loginBox').slideUp(0000);
 	}
 	
 	); 	
 	
 $('#bLoginRegister').click(function() {
	 
	 $('#loginBox').slideUp(0000);
	 $('#registerBox').slideDown(0000);
	 $('#registerError').html("");
	 document.fRegister.fName.focus();
 	}
 	
 	); 	 
 	
 $('#bLoginForget').click(function() {
	 
	 $('#loginBox').slideUp(0000);
	 $('#forgetBox').slideDown(0000);
	 $('#forgetError').html("");
	 document.fForget.email.focus();
 	}
 	
 	); 	  	
 	
 $('#bRegisterLogin').click(function() {
	 $('#registerBox').slideUp(0000);
	 $('#loginBox').slideDown(0000);
	 $('#loginError').html("");
	 document.fLogin.email.focus();
 	}
 	); 	  	
 		
 $('#bRegisterForget').click(function() {
	 $('#registerBox').slideUp(0000);
	 $('#forgetBox').slideDown(0000);
	 $('#forgetError').html("");
	 document.fForget.email.focus();
 	}
 	); 	  		 	
 	
 $('#bRegisterCancel').click(function() {
	 $('#loginError').html("");
	 $('#registerError').html("");
	 $('#registerBox').slideUp(0000);
 	}
 	
 	); 	 	
 	
 $('#bForgetCancel').click(function() {
	 $('#forgetError').html("");
	 $('#forgetBox').slideUp(0000);
 	}
 	
 	); 	 	
 	
 $('#bForgetRegister').click(function() {
	 $('#registerError').html("");
	 $('#forgetBox').slideUp(0000);
	 $('#registerBox').slideDown(0000);
	 document.fRegister.fName.focus();
 	}
 	
 	); 	 	 	

 $('#bForgetLogin').click(function() {
	 $('#loginError').html("");
	 $('#forgetBox').slideUp(0000);
	 $('#loginBox').slideDown(0000);
	 document.fLogin.email.focus();
 	}
 	
 	); 	 	 	
 	
 	 	
});


function removeListing(item,id) {

	if (cookieUserID > 0) {
		var xht = getHttpRequest();
		xht.open("POST", 'core/removeListing.php', true);
		xht.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xht.onreadystatechange = callback_removeListing;
	
		var objStr =  "mls="+item+"&table="+id;
		
		xht.send(objStr);		
	} else {
		loginHomey(item,id);	
	}

}		

function callback_removeListing() {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                var xmlDoc = xmlHttp.responseXML;
                var val = xmlDoc.getElementsByTagName("rc")[0].childNodes[0].nodeValue;
                
                
                if (val == 1) {
                 	var mls = xmlDoc.getElementsByTagName("mls")[0].childNodes[0].nodeValue;
                 	var table =  xmlDoc.getElementsByTagName("table")[0].childNodes[0].nodeValue;
                    var html_id = "row1_"+mls+"_"+table;
				    var cntListing =  xmlDoc.getElementsByTagName("cntlisting")[0].childNodes[0].nodeValue;
                    
                    $("#cntListing").html(cntListing);
                    
					$("#" + html_id).remove();   
					html_id = "row2_"+mls+"_"+table;
					$("#" + html_id).remove();   
                    

                }
                
                
            }
        }

}



function signOut() {
	
	$.cookies.del('homey');
	var sMenuHTML = "<font color=red>New</font>&nbsp;<a href=\"javascript:registerHomey();\">Sign Up</a>&nbsp;OR <a href=\"javascript:loginHomey('','');\">Login</a> to save your search listings with myHomey";
    $("#myHomeyMenu").html(sMenuHTML);	
    window.open("index.php","_self");
	
	
}
