window.onload=initialise;

function initialise(){
	createInputs();
	externalLinks();
	captureURLRedEye();
	ipHomeimage();
/*	buildSurvey()
	investSurvey() */
	tooltip();
	initSurveys();

}


/* commented out as requested for lingubot project- didn't want survey to appear. this fucntion is called from the flash file.  AK */
function survey(){
/*if(document.getElementById("survey")){setTimeout(randomise,3000);}*/
}


var fillDrop = function (arr){
	var sel, opts, opt, txt;
	if (arr){
		sel = document.getElementById("quote");
		opts = arr.length;
		
		for (var i = 0; i < opts; i++){
			opt = document.createElement("option");
			opt.value = arr[i][0];
			txt = document.createTextNode(arr[i][1]);
			opt.appendChild(txt);
			sel.appendChild(opt);
		}
	}
};

var clearDrop = function (){
	var sel, opts;
	if (document.getElementById("quote")){
		sel = document.getElementById("quote");
		opts = sel.childNodes.length;
		for (var i = sel.childNodes.length; i > 0 ; i--){
			sel.removeChild(sel.childNodes[0]);
		}
	}
};

var setDrop = function (obj){
	clearDrop();
	
	switch (obj){
		case "radio_quote_new" :
		fillDrop(this["arr_0"]);
		break;
		case "radio_quote_retrieve" :
		fillDrop(this["arr_1"]);
		break;
		default:
		return;
	};
};

var switchRadio = function (){
	setDrop(this.id);
	this.checked = true;
	this.opp.checked = false;
};

var createInputs = function (){
	var divEl, inpEl_0, inpEl_1, labEl_0, labEl_1, txt_0, txt_1, attr;
	
	if (document.getElementById("quote-radios")){
		divEl = document.getElementById("quote-radios"); 
		
		inpEl_0 = document.createElement("input");
		inpEl_0.setAttribute("type", "radio");
		inpEl_0.name = "radio_quote";
		inpEl_0.id = "radio_quote_new";
		inpEl_0.setAttribute("value", "");
		
		labEl_0 = document.createElement("label");
		labEl_0.setAttribute("for", "radio_quote_new");
		txt_0 = document.createTextNode("New quote");
		labEl_0.appendChild(txt_0);
		
		inpEl_1 = document.createElement("input");
		inpEl_1.setAttribute("type", "radio");
		inpEl_1.name = "radio_quote";
		inpEl_1.id = "radio_quote_retrieve";
		inpEl_1.setAttribute("value", "");
		
		labEl_1 = document.createElement("label");
		labEl_1.setAttribute("for", "radio_quote_retrieve");
		txt_1 =  document.createTextNode("Retrieve a quote");
		labEl_1.appendChild(txt_1);
		
		divEl.appendChild(inpEl_0);
		divEl.appendChild(labEl_0);
		
		divEl.appendChild(inpEl_1);
		divEl.appendChild(labEl_1);
		
		inpEl_0.opp = document.getElementById("radio_quote_retrieve");
		inpEl_1.opp = document.getElementById("radio_quote_new");
		
		inpEl_1.onfocus = inpEl_0.onfocus = switchRadio;
	}
};

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.getAttribute("rel") == "pdf"){
			anchor.target = "_blank";
			anchor.title = "opens in a new window";
		}
	}
}

function sitestat(ns_l){
	ns_l += '&amp;ns__t=' + (new Date()).getTime();
	ns_pixelUrl = ns_l;
	ns_0 = document.referrer;
	ns_0 = (ns_0.lastIndexOf('/') == ns_0.length-1) ? ns_0.substring(ns_0.lastIndexOf('/'),0) : ns_0;
	if(ns_0.length>0){
		ns_l += '&ns_referrer=' + escape(ns_0);
	}
	if(document.images){
		ns_1=new Image();
		ns_1.src=ns_l;
	}else{
		document.write('<img src="../../resources/js/' + ns_l + '" width="1" height="1" alt="">');
	}
}

/* ****************** START REDEYE MARKERS ****************************** */

function captureURLRedEye(){
	var counterName = document.location.pathname;

	var qs = document.location.search;
	var linkName;
	if (qs && qs.indexOf("link=")>=0) {
		//alert("link: " + qs.substring(qs.indexOf("link=")+5) );
		linkName = qs.substring(qs.indexOf("link=")+5);

		if (linkName.indexOf("&")>0) {
			var linkName = linkName.substring(0, linkName.indexOf("&"));
			//alert("t1: " + linkName);
		}

	}

	if(counterName.lastIndexOf(".")!=-1){
	var end = counterName.lastIndexOf(".");
	}
	else{
	var end = counterName.length;
	}
	counterName = counterName.substring(1,end);
	//counterName = counterName.replace(/[\/]/g, ".");

	if(counterName.substring(counterName.length-1)=="."){
	counterName = counterName.slice(0,counterName.length-1)
	}

	if (counterName=="") {
		counterName="homepage";
	}

	counterName = "http://report.legalandgeneral.com/cgi-bin/rr.cgi/images/blank.gif?nourl=direct/"+counterName+"&norefer="+escape(window.document.referrer);
	if (linkName) {
		counterName += "\n&landg_link=" + linkName;
	}

	sitestatRedEye(counterName);
}



function sitestatRedEye(ns_l){
//ns_l+='&ns__t='+(new Date()).getTime();ns_pixelUrl=ns_l;
//ns_0=document.referrer;
//ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;
//if(ns_0.length>0)ns_l+='&ns_referrer='+escape(ns_0);
if(document.images){ns_1=new Image();ns_1.src=ns_l;}else

document.write('<img src="file:///C|/Documents and Settings/Richard/My Documents/wareabouts/htdocs/v2/resources/js/'+ns_l+'" width="1" height="1" alt="" border="0">');
//document.write("REDEYE LINK: " + ns_l);
//alert(ns_l);

}

function RedEyeTag(strTag){
	imgRedEye = new Image();
	imgRedEye.src = 'http://report.legalandgeneral.com/cgi-bin/rr.cgi/images/blank.gif?nourl=' + strTag;
}


/* ****************** END REDEYE MARKERS ****************************** */


/* NAVIGATION */
if(document.images){
InvestRoll = new Image();
InvestRoll.src = "/web_resources/images/nav/nav1-roll.gif";
InvestOff = new Image();
InvestOff.src = "/web_resources/images/nav/nav1.gif";

PensionsRoll = new Image();
PensionsRoll.src = "/web_resources/images/nav/nav2-roll.gif";
PensionsOff = new Image();
PensionsOff.src = "/web_resources/images/nav/nav2.gif";

LifeRoll = new Image();
LifeRoll.src = "/web_resources/images/nav/nav3-roll.gif";
LifeOff = new Image();
LifeOff.src = "/web_resources/images/nav/nav3.gif";

HomeRoll = new Image();
HomeRoll.src = "/web_resources/images/nav/nav4-roll.gif";
HomeOff = new Image();
HomeOff.src = "/web_resources/images/nav/nav4.gif";

EmployeesRoll = new Image();
EmployeesRoll.src = "/web_resources/images/nav/nav11-roll.gif";
EmployeesOff = new Image();
EmployeesOff.src = "/web_resources/images/nav/nav11.gif";

EmployersRoll = new Image();
EmployersRoll.src = "/web_resources/images/nav/nav12-roll.gif";
EmployersOff = new Image();
EmployersOff.src = "/web_resources/images/nav/nav12.gif";

AdvisersRoll = new Image();
AdvisersRoll.src = "/web_resources/images/nav/nav13-roll.gif";
AdvisersOff = new Image();
AdvisersOff.src = "/web_resources/images/nav/nav13.gif";
}

function imgRoll(n){
	if(document.getElementById(n+"Link")){document.getElementById(n+"Link").src = eval(n+"Roll").src}
}

function imgOff(n){
	if(document.getElementById(n+"Link")){document.getElementById(n+"Link").src = eval(n+"Off").src}
}



function quickLinks(){
var newURL = document.getElementById("quicklinks").quick.options[document.getElementById("quicklinks").quick.selectedIndex].value
if(newURL!=""){
document.location.href = newURL
}
}
function quotesURL(){
var newURL = document.getElementById("quotes").quote.options[document.getElementById("quotes").quote.selectedIndex].value
if(newURL!=""){
document.location.href = newURL
}
}

function fundsURL(){
var newURL = document.getElementById("funds").fund.options[document.getElementById("funds").fund.selectedIndex].value
if(newURL!=""){
document.location.href = newURL
}
}

function quoteURL2(){
var newURL = document.getElementById("quotes2").quote2.options[document.getElementById("quotes2").quote2.selectedIndex].value
if(newURL!=""){
document.location.href = newURL
}
}

function claimURL(){
var newURL = document.getElementById("claims").claim.options[document.getElementById("claims").claim.selectedIndex].value
if(newURL!=""){
document.location.href = newURL
}
}

/* FORMS > clear field */
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

/* LINGUBOT > home page link */
/* nj code 

function openBot(url){
	var uid = new Date().getTime() + Math.floor(Math.random()*100);
	window.open(url+'?uid='+uid,'BOT','width=645,height=620');
} */

function openBot(){

     var url = "http://legalandgeneral.creativevirtual.com/LandGNew/bot.htm"

     var uid = new Date().getTime() + Math.floor(Math.random()*100);

     window.open(url+'?uid='+uid,'BOT','width=645,height=620');

}



/* HOME > IP > random images */
var images = new Array();

images[0] = "banner.jpg"

var ranNum = Math.floor(Math.random()*1);

function ipHomeimage(){
if(document.getElementById("home-ip-img")){
document.getElementById("home-ip-img").src = images[ranNum];}
}





/*OTHER SITES LINK*/
var otherSites = function(type){

		var toolsLinks = document.getElementById("toolsLinks");
		var opts = toolsLinks.getElementsByTagName("option");
		
		var otherSitesDiv = document.createElement("div");
		otherSitesDiv.className="other-sites";
		
		var quickLinks = document.createElement("a");
		quickLinks.id="other-sites";
		quickLinks.href="#";
		
		if(type=="home"){
			quickLinks.appendChild(document.createTextNode("Our sites"));
		}
		else{
		quickLinks.appendChild(document.createTextNode("Quick links"));
		}
	
		var sites = document.createElement("div");
		sites.className="sites off";
		sites.id="sites";
	
		var padding = document.createElement("div");
		padding.className="padding clear";
	
		var col1 = document.createElement("div");
		col1.className="col1";
		
		var col2 = document.createElement("div");
		col2.className="col2";
	
		var ul1 = document.createElement("ul");
		var ul2 = document.createElement("ul");
	
		var half = Math.floor((opts.length)/2);
		half++;
		
		
		for(i=1;i<half;i++){
			var li = document.createElement("li");
			var anc = document.createElement("a");
			anc.href=opts[i].value;
			anc.innerHTML=opts[i].innerHTML;
			li.appendChild(anc);
			ul1.appendChild(li);
		}
		
		for(i=half;i<opts.length;i++){
			var li = document.createElement("li");
			var anc = document.createElement("a");
			anc.href=opts[i].value;
			anc.innerHTML=opts[i].innerHTML;
			li.appendChild(anc);
			ul2.appendChild(li);
		}
	
	
		col1.appendChild(ul1);
		col2.appendChild(ul2);
		padding.appendChild(col1);
		padding.appendChild(col2);
		sites.appendChild(padding);
		toolsLinks.appendChild(quickLinks);
		toolsLinks.appendChild(sites);
		var form = toolsLinks.getElementsByTagName("form");
		form[0].parentNode.removeChild(form[0]);
		
		

	var sites = document.getElementById("sites")
	var sitesLink = document.getElementById("other-sites")

	sites.className+=" off";
	var toggle = 0;

	sitesLink.onclick=function(){
	
		if(toggle==1){
			sites.className="sites off";
			sitesLink.className="";
			toggle=0;
		}
		else{
			sites.className="sites";
			sitesLink.className="close";
			toggle=1;
		}
		
		return false;

	}

}


function validateSearchForm()
{

  if (document.rightsearchform.q.value == "")
  {
    alert("Please enter a search term.");
    document.rightsearchform.q.focus();
    return (false);
  }
  else
  {
  return (true);
  }
}

