var fePopup=null;

function emailFriend(e,prop_id)
{
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	if(fePopup)
		return false;
	
	fePopup=createPopup(e,400,300);
	fePopup.innerHTML="Loading...";

	query_string="prop_id="+prop_id;
	http_request.onreadystatechange = function() { processEmailFriend(http_request); };
	try {
		AJAXSend(http_request,"functions/processEmailFriend.php",query_string);
	}
	catch (e)
	{
		alert("Error requesting data from server.  Contact OpenSpace.com for assistance.\n\r"+e);
		efCancel();
	}
}

function sendFriend(prop_id)
{
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	
	var f=document.getElementById("email_friend_form");
	query_string="prop_id="+prop_id;
	query_string+="&command=send&";
	query_string+=getQueryString(f,"message");
	query_string+=getQueryString(f,"email");
	query_string+=getQueryString(f,"name");
	fePopup.innerHTML="Sending...";
	http_request.onreadystatechange = function() { processEmailFriend(http_request); };
	try {
		AJAXSend(http_request,"functions/processEmailFriend.php",query_string);
	}
	catch (e)
	{
		alert("Error requesting data from server.  Contact OpenSpace.com for assistance.\n\r"+e);
		efCancel();
	}
}

function processEmailFriend(http_request)
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			fePopup.innerHTML=http_request.responseText;
		}
		else
		{
			alert('Server Error, contact OpenSpace.com for assistance.');
			efCancel();
		}
	}
}

function efCancel()
{
	document.body.removeChild(fePopup);
	fePopup=null;
}

function emailSeller(e,prop_id)
{
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	if(fePopup)
		return false;
	
	fePopup=createPopup(e,400,300);
	fePopup.innerHTML="Loading...";

	query_string="prop_id="+prop_id;
	http_request.onreadystatechange = function() { processEmailFriend(http_request); };
	try {
		AJAXSend(http_request,"functions/processEmailSeller.php",query_string);
	}
	catch (e)
	{
		alert("Error requesting data from server.  Contact OpenSpace.com for assistance.\n\r"+e);
		efCancel();
	}
}

function sendSeller(prop_id)
{
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	
	var f=document.getElementById("email_seller_form");
	query_string="prop_id="+prop_id;
	query_string+="&command=send&";
	query_string+=getQueryString(f,"message");
	query_string+=getQueryString(f,"email");
	query_string+=getQueryString(f,"name");
	fePopup.innerHTML="Sending...";
	http_request.onreadystatechange = function() { processEmailFriend(http_request); };
	try {
		AJAXSend(http_request,"functions/processEmailSeller.php",query_string);
	}
	catch (e)
	{
		alert("Error requesting data from server.  Contact OpenSpace.com for assistance.\n\r"+e);
		efCancel();
	}
}

function switchDivs(openD){
  x=1;
  while(document.getElementById('div'+x)){
    document.getElementById('div'+x).style.display='none';
    document.getElementById('btn'+x).style.color="#000000";
    x++;
  }
  document.getElementById('div'+openD).style.display = 'block';
  document.getElementById('btn'+openD).style.color="#CCCCCC";
	if(openD==3)
	{
		load();
	}
}
