function closePopup(fromCloseLink)
{
	var popupDIV = document.getElementById("info_popup");
	popupDIV.style.display = "none";
	/*When clicking register in offers lozenge do not strink iframe when closing popup*/
	if(fromCloseLink != "offer_995")
	{
		growIframe(parent.document.getElementById("mainFrame"), "260px");
	}
}

function prepareLinks()
{
	if(!document.getElementsByTagName) return false;
	var homesaboutLinksArr = document.getElementsByTagName("a");
	
	for(var i=0; i<homesaboutLinksArr.length;i++)
	{
		if(homesaboutLinksArr[i].className == "popup")
		{
			homesaboutLinksArr[i].onclick = function(event)
			{
				var coords = getMouseXY(event); 
				homesaboutPopup(coords, this.id, event);
				return false;
			}
			/*homesaboutLinksArr[i].onmouseover = function(event)
			{
				var coords = getMouseXY(event); 
				homesaboutPopup(coords, this.id, event);
			}
			homesaboutLinksArr[i].onmouseout = function(event)
			{
				var coords = getMouseXY(event); 
				homesaboutPopup(coords, this.id, event);
			}*/
		}
		if(homesaboutLinksArr[i].className == "propsforsalelink"){
			homesaboutLinksArr[i].onclick = function()
			{
				var letbtn = document.getElementById("propstoletbtn");
				var letlink = document.getElementById("propstoletlink");
				var salesbtn = document.getElementById("propsforsalebtn");
				var saleslink = document.getElementById("propsforsalelink");
				
				letbtn.style.background = "none";
				letlink.style.color = "#FFFFFF";
				
				salesbtn.style.background = "url(images/search_engine_btn_sales.gif) no-repeat top";
				saleslink.style.color = "#942824";
				
				saleslink.blur();
				saleslink.hideFocus = false;
				//saleslink.style.outline = null;
				
				letlink.blur();
				letlink.hideFocus = false;
				//letlink.style.outline = null;
				
				document.form_search_form_r.pricetype.value = 1;
				
				updateprices(0);
				
				return false;
			}
		}
		if(homesaboutLinksArr[i].className == "propstoletlink"){
			homesaboutLinksArr[i].onclick = function()
			{
				var letbtn = document.getElementById("propstoletbtn");
				var letlink = document.getElementById("propstoletlink");
				var salesbtn = document.getElementById("propsforsalebtn");
				var saleslink = document.getElementById("propsforsalelink");
			
				salesbtn.style.background = "none";
				saleslink.style.color = "#FFFFFF";

				letbtn.style.background = "url(images/search_engine_btn_tolet.gif) no-repeat top right";
				letlink.style.color = "#942824";
				
				saleslink.blur();
				saleslink.hideFocus = false;
				//saleslink.style.outline = null;
				
				letlink.blur();
				letlink.hideFocus = false;
				//letlink.style.outline = null;	
				
				document.form_search_form_r.pricetype.value = 2;
				
				updateprices(1);
				
				return false;
			}
		}
	}
	
}

function getMouseXY(e) 
{
	var IE = document.all?true:false;
	var tempX = 0;
	var tempY = 0;
	var coords = "";
	
	if (IE) 
	{ 
		tempX = event.clientX - 200; //+ document.body.scrollLeft - 225;
		tempY = event.clientY + 20; //+ document.body.scrollTop + 2055;
	} 
	else 
	{	
		tempX = e.pageX  - 200; //- 237;
		tempY = e.pageY  + 20; //- 100;
	}  
	
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	
	coords = "X" + tempX + "Y" + tempY;
	
	return coords;
}

function homesaboutPopup(coords, LinkID, e)
{	
/* Build popup DIV at position of mouse and populate with applicable text dependent on link clicked*/

	var topY = coords.substring(coords.indexOf("Y")+1, coords.length);
	var leftX = coords.substring(coords.indexOf("X")+1, coords.indexOf("Y"));
	var IE = document.all?true:false;
	var mainFrameDIV = parent.document.getElementById('mainFrame');
	var popupDIV = document.getElementById('info_popup');
	popupDIV.className = LinkID;
	
	var popupContent = "";
	switch(LinkID)
	{
		case "hips" : popupContent = "<div id='closebtn' class='closebtn'><a href='#' onclick='closePopup(\"hips\"); return false'>CLOSE</a></div><p><strong>Homesabout are delighted to be working with My Home Information Pack, (part of My Home Move) for our Hips solutions.</strong></p><ul><li>Fast and efficient delivery of each pack</li><li>Flexible pricing packages</li><li>24/7 Support via telephone or online</li></ul><h3>What is a Home Information Pack (HIPs)?</h3><p>Home Information Packs (HIPs) are designed to speed up the home buying process by making sure the seller has information about their property ready before starting to market the property for sale. This means that under Part 5 of the Housing Act 2004 a legal responsibility will fall on the person selling the property (the vendor) or their marketing agent to ensure all relevant documents are ready to present to prospective buyers on request.</p><p><strong>For details please contact our team for further information.</strong></p>"; popupDIV.innerHTML = popupContent; break;
		case "offer_995" : popupContent = "<div id='closebtn' class='closebtn'><a href='#' onclick='closePopup(\"offer_995\"); return false'>CLOSE</a></div><h3><strong>Sell your property for just £995!</strong></h3><p>If you register with homesabout Estate Agents on a sole agent contract we will sell your house at a fixed fee of £995 for any size property!</p><p>No sale, no fee and no hidden charges.</P><p>So what are you waiting for, let us get you moving... <a href='http://agentslive.net/hoab/registerb.asp' target='mainFrame'>click here to register</a> and one of our friendly staff will contact you.</p><p class='footnotes'>*&pound;995 + VAT is subject to sole agency agreement for 8 weeks. No sale, no fee.</p>"; popupDIV.innerHTML = popupContent; break;
	}
	
	if(!IE)
	{
		if(e.type == "mouseover")
		{
			popupDIV.style.display = "block";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";
		}
		else if(e.type == "click")
		{
			popupDIV.style.display = "block";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";

			growIframe(mainFrameDIV, "600px");
		}
		else if(e.type == "mouseout")
		{
			popupDIV.style.display = "none";
			popupDIV.innerHTML = "";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";
		}
	}
	else
	{
		if(event.type == "mouseover")
		{
			popupDIV.style.display = "block";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";
		}
		else if(event.type == "click")
		{
			popupDIV.style.display = "block";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";
			growIframe(mainFrameDIV, "600px");
		}
		else if(event.type == "mouseout")
		{
			popupDIV.style.display = "none";		
			popupDIV.innerHTML = "";
			popupDIV.style.top = topY + "px";
			popupDIV.style.left = leftX + "px";
		}
	}
}

function growIframe(iframeObj, size)
{	
	try
	{
		/* Affects non-estateIT pages. Because estateIT pages do not return a href 
		we can automatically assume that the other pages should be resized to 260px.
		Just add URL case statement to control corporate page iframe growth.
		*/
		var iframeURL = window.frames["mainFrame"].location.href;
				
		if( (iframeURL.substring(iframeURL.lastIndexOf("/")+1, iframeURL.lastIndexOf(".")) == "news") ) //|| (iframeURL.substring(iframeURL.lastIndexOf("/")+1, iframeURL.lastIndexOf(".")) == "lettings") )
		{
			iframeObj.style.height = "580px";
		}
		else
		{
			iframeObj.style.height = "260px";
		}
	}
	catch(e)
	{
		//alert(size);
		iframeObj.style.height = size;
	}
	
	var DIVid = document.getElementById('info_popup');
	if((DIVid.className == "offer_995") && (iframeObj.style.height == "430px"))
	{
		DIVid.style.display = "none";
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

/* MAIN NAV FUNCTIONS */

startList = function() {
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("nav_menu");
		for (i=0; i<navRoot.childNodes.length; i++) {
		var	node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					if(this.id)
					{
					submenu = this.id + "SUB";
					submenu_id = document.getElementById(submenu);
					submenu_id.style.display = "block";
					}
				}
				node.onmouseout=function() {
					if(this.id)
					{
					submenu = this.id + "SUB";
					submenu_id = document.getElementById(submenu);
					submenu_id.style.display = "none";
					}
				}
			}
		}
	}
}

function prepareNavigation()
{	
	window.defaultStatus='Welcome to homesabout';
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("nav_menu")) return false;
	var nav = document.getElementById("nav_menu");
	
	var links = nav.getElementsByTagName("a");
	for(i=0;i < links.length; i++)
	{
		var linkURL = links[i].getAttribute("href");
		var page = linkURL.substring(linkURL.lastIndexOf("/")+1, linkURL.lastIndexOf("."));
		switch(page)
		{
			case "home" : links[i].onmouseover=function(){window.status='Home page'; return true}; break;
			case "benefits" : links[i].onmouseover=function(){window.status='Why choose us?'; return true}; break;
			case "registerb" : links[i].onmouseover=function(){window.status='Register with homesabout'; return true}; break;
			case "services" : links[i].onmouseover=function(){window.status='Other services and links'; return true}; break;
			case "team" : links[i].onmouseover=function(){window.status='Meet our dedicated team'; return true}; break;
			case "contactus" : links[i].onmouseover=function(){window.status='Contact details'; return true}; break; 
		}       
		
		
	}
}

window.onload = function(){
	prepareNavigation();
	startList();
	prepareLinks();
}

