var agentInfoButton = false;
var newsInfoButton = false;
var openHouseButton = false;
var saveSearch;
var saveListings;

function toggleAgentInfo()
{
	var button = document.getElementById("agentInfoRow");
	var title = document.getElementById("agentInfoRowTitle");
	if (agentInfoButton) //deselect button
	{
		if (button)	button.style.display = "none";
		if (title) title.style.display = "none";
		agentInfoButton = false;
	}
	else  //select button
	{
		if (button)	button.style.display = "";
		if (title) title.style.display = "";
		agentInfoButton = true;
		if (newsInfoButton)	toggleNewsInfo();
		if (openHouseButton) toggleOpenHouse();
	}
}

function displayAgentInfo(choice)
{
	var div = null;
	var biography = document.getElementById("biography");
	var testimonials = document.getElementById("testimonials");
	var announcements = document.getElementById("announcements");
	if (choice == 2)
		div = testimonials;
	else if (choice == 3)
		div = announcements;
	else
		div = biography;
	biography.style.display="none";
	testimonials.style.display="none";
	announcements.style.display="none";
	div.style.display = "";
}

function toggleNewsInfo()
{
	var button = document.getElementById("newsInfoRow");
	var title = document.getElementById("newInfoRowTitle");
	if (newsInfoButton) //deselect button
	{
		button.style.display = "none";
		title.style.display = "none";
		newsInfoButton = false;
	}
	else  //select button
	{
		button.style.display = "";
		title.style.display = "";
		newsInfoButton = true;
		if (agentInfoButton) toggleAgentInfo();
		if (openHouseButton) toggleOpenHouse();
	}
}

function toggleOpenHouse()
{
	var button = document.getElementById("openHouseRow");
	var title = document.getElementById("openHouseRowTitle");
	if (openHouseButton) //deselect button
	{
		button.style.display = "none";
		title.style.display = "none";
		openHouseButton = false;
	}
	else  //select button
	{
		button.style.display = "";
		title.style.display = "";
		openHouseButton = true;
		if (agentInfoButton) toggleAgentInfo();
		if (newsInfoButton)	toggleNewsInfo();
	}
}

function DeleteAll(url)
{
	var where_to= confirm("Are you sure you want to delete all favorites?");
	if (where_to== true)
		window.location="AgentInfo.php?deleteFavorites=1&" + url;
}
function openHaves() 
{
  	new1window = window.open('http://www.havesandneeds.net/OPEN%20HOUSE.htm', '', '');
}

function initAgent()
{
	var theForm = document.SBPTSearchForm;
	var AgentSelect = theForm.Agent;
	var CompanySelect = theForm.Company;
	
	AgentSelect.options[0] = new Option('Any Agent', '0');
	AgentSelect.selectedIndex = 0;
	for (var i=0; i < totalAgents; i++)
			AgentSelect.options[i+1] = new Option(AgentNames[i], AgentIds[i]);	
}



function getSearchURL(pickListings, agentid)
{
	appendURL = "";
	theForm = document.SBPTSearchForm;
	theForm.method = "GET";
	hidden = document.createElement("input");	hidden.type = "hidden"; hidden.name = "branded";hidden.value = 1;theForm.appendChild(hidden);
	hidden = document.createElement("input");	hidden.type = "hidden"; hidden.name = "agentid";hidden.value = agentid;theForm.appendChild(hidden);
	hidden = document.createElement("input");	hidden.type = "hidden"; hidden.name = "search";hidden.value = 1;theForm.appendChild(hidden);
	theForm.branded=1;
	theForm.action = ""
	theForm.submit();
}

function createLinkWindow()
{
	var fullURL = getOurCookie().replace('&pickListings=1', '')
	var newContent = "<html><head><title>Get link to Selected Listings</title></head>"
	newContent += "<" + "script language=javascript>"
	newContent += "function CopyText() "
	newContent += "{"
	newContent += "		var copyArea = document.getElementById(\"copyAreaID\");"
	newContent += "		var copyText = document.getElementById(\"fullURLid\");"
	newContent += "		var textAreaObj = document.getElementById(\"textAreaID\");"
	newContent += "		copyArea.value=copyText.innerHTML;"
	newContent += "		while (copyArea.value.indexOf('&amp;') > 0) copyArea.value = copyArea.value.replace('&amp;', '&');"
	newContent += "		try { r=copyArea.createTextRange(); } catch(errorInfo) { alert('Automatic Copy to Clipboard not supported. " 
	newContent += "	Press Control-C'); textAreaObj.focus(); textAreaObj.select(); return;}"
	newContent += "		if (!r) alert('not supported');"
	newContent += "		r.select();"
	newContent += "		r.execCommand('copy');"
	newContent += "}"

	newContent += "<" + "/script>"
	newContent += "<body><div align=center><a id=fullURLid href='#' onclick=\"window.open('" + fullURL + "');\">" + fullURL + "</a><br>"
	newContent += "<input type='hidden' id='copyAreaID' name='copyArea' value=''>"
	newContent += "<textarea rows=5 cols=100 id='textAreaID'>" + fullURL + "</textarea><br>"
	newContent += "<input type='button' name='copyToClipboard' value='Copy to clipboard' onClick='CopyText();'>"

	newContent += "</div></body></html>"
	var linkWindow = window.open(fullURL, 'email','height=200, width=900')
	linkWindow.document.write(newContent)
	linkWindow.document.close()
	linkWindow.focus()
}

