// $Id$

//
//
function openCalc() {
	//var calcUrl = "http://www.gemhl.co.uk/fnol/BrandedDTIR/FnD2UAffordCalc.aspx"
	win = window.open(this.href, 'calcWin','height=550,width=440,left=10,top=10,resizable=yes,status=0,scrollbars=1');
	return false;
}

// $Id$

// ?
function lhspopup() {

	var alterit = 0;

	if ((navigator.userAgent.indexOf('Safari') != -1) || (navigator.userAgent.indexOf('Opera') != -1)){
		alterit = -10;
	}

	if (document.getElementById('lhs-popup').style.display != "block") {
		document.getElementById('lhs-popup').style.top = (parseInt(document.getElementById('lhs-toolbox').offsetTop) + 104-110+alterit)+"px";
		document.getElementById('lhs-popup').style.left = (parseInt(document.getElementById('lhs-toolbox').offsetLeft) + -91)+"px";

		if (!document.getElementById('popupholder')) {

			var popupcontents = document.getElementById('lhs-popup').innerHTML;

			var newcontents = "<table id=\"popupholder\" border=\"0\"><tr><td colspan='3'><img src='img/spacer.gif' alt='' width='320' height='110' onmouseover='lhspopout()'/></td></tr><tr><td><img src='img/spacer.gif' alt='' width='50' height='345' onmouseover='lhspopout()'/></td><td class=\"popupstuff\">"+popupcontents+"</td><td><img src='img/spacer.gif' alt='' width='250' height='345' onmouseover='lhspopout()'/></td></tr><tr><td colspan='3'><img src='img/spacer.gif' alt='' width='310' height='110' onmouseover='lhspopout()'/></td></tr></table>";

			document.getElementById('lhs-popup').innerHTML = newcontents;
		}

		document.getElementById('lhs-popup').style.display = "block";
	}
}


// ?
function lhspopout() {
	//alert('out!');
	if (document.getElementById('lhs-popup').style.display == "block") {
		setTimeout("document.getElementById('lhs-popup').style.display = 'none';",1);
	}
}


function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//
// opens up a smaller popup window
function spawn(url, nameW, w, h){
	x4 = screen.width/2 - (w/2);
	y4 = screen.height/2 - (h/2);
	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=1,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
}


// preloads the image rollovers?
function init() {
	document.getElementById('quickdoc').innerHTML = "QUICK DOC (PDF)<br/>DOWNLOAD";
	MM_preloadImages('img/butt_buytolet-mortgage-over.gif','img/butt_buytolet-over.gif','img/butt_decision-in-principle-over.gif','img/butt_download-direct-debit2-over.gif','img/butt_download-direct-debit--over.gif','img/butt_download-know-your-cus-over.gif','img/butt_download-new-property-over.gif','img/butt_download-product-guide-over.gif','img/butt_mortgage-application-over.gif');
}



//
// swap images, used for link rollovers
function swapimage(name,state) {
	if (state==0) {
		document.getElementById(name).src = "img/"+name+".gif";
	} else {
		document.getElementById(name).src = "img/"+name+"-over.gif";
	}
}





// function to open a link up in new windows
// also adds in an image to indicate it's going to open a new window
// only if the link has a rel="external" attribute
function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	}

	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {

			anchor.target = "_blank";
			anchor.title += ' (opens in new window)';

			// change img alt if exists
			var link_img = anchor.getElementsByTagName('img')[0];
			if (link_img) {
				link_img.alt += ' (opens in new window)';
				anchor.title = link_img.alt;
			}

		// AFFORDABILITY CALCULATOR
		} else  if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "affordability-calculator") {
			anchor.onclick = openCalc;
			anchor.title += ' (opens in new window)';
		}

	}

	// imagemap on home page
	var flashmap_links = document.getElementById('flashmap');

	if (flashmap_links) {
		var links = flashmap_links.getElementsByTagName('area');

		num_links = links.length;
		for (i=0; i<num_links; i++) {
			links[i].target = "_blank";
			links[i].alt += ' (opens in new window)';
		}

	}
}

// THIS CODE RUNS TO DO THE POPUP LINKS!!!!
window.onload = externalLinks;