window.onload = function() {
	
	//removeLastBorder();	
	//buildTable();
	//getURL();
	//createId();	
	
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++) {
		if (links[i].getAttribute('rel')=='external')
		links[i].setAttribute('target', '_blank');
	}
	
}



function removeLastBorder() {

	var uls = document.getElementsByTagName("ul");
	for (var i=0; i<uls.length; i++) {
		var as = uls[i].getElementsByTagName("a");
		
		
		if (as[0] && as[0].className == "") {
			as[0].style.borderLeft = "0";			
		}		
		
		//if ((as[as.length-1].parentNode.parentNode.className = "hor-link-list") && (as[as.length-1].className = "on")){
		//as[as.length-1].style.borderRight = "0";			
		//}
		
	}
}

										
function createId(){

	getURL();

	var link = document.getElementsByTagName("a");

	for (var i=0; i<link.length; i++) {

		var href = link[i].getAttribute("href"); 

		var att = href.substring(href.lastIndexOf("/")+1, href.lastIndexOf("."))
		
		link[i].setAttribute("id", att);		
		//if (att == "document_downloads"){
		//	att = "document_downloads";				
		//}
		if (parentPage == att){
			link[i].className ="on";
			link[i].style.borderRight = "solid 1px #fff";
			
			
		}
		
	}
	
	
	

}
										


function buildTable(){

// creates footer where appropriate
var tbls = document.getElementsByTagName("table");

	for (var i=0; i<tbls.length; i++) {
	document.getElementsByTagName("table")[i].style.border = "0";
	
		if (tbls[i].className=="ImmTS_Rates"){ 
		
			var tfoot = tbls[i].appendChild(document.createElement("tfoot"));
		    var row = tfoot.appendChild(document.createElement("tr"));
		    for (var j=0; j<8; j++) {
		    	cell = row.appendChild(document.createElement("td"));
		
				if (j == 0){
				
					var att = document.createAttribute("class");
					att.value="lft";
					cell.setAttributeNode(att);
			 		cell.innerHTML="&#160;";			
				
				} 								
			
				if (j == 7){
				
					var att = document.createAttribute("class");
					att.value="rgt";
					cell.setAttributeNode(att);
			 		cell.innerHTML="&#160;";	
				
				} 
			}	
    	}
	
	}

}





function getURL() {
	uri.dir = location.href.substring(0,location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	

	return uri;
}


var uri = new Object();
getURL(uri);

var parentPage;
var string = uri.path;
var stringArray = string.split('/');
var length = stringArray.length;



if(stringArray !=""){

//alert(stringArray[1])

if(length == 1) parentPage = stringArray[0];
if(length > 1) parentPage = stringArray[1];
if(length == 1 && stringArray[1] == null) parentPage = "document_downloads";; 
}

/********* IW - 23-09-2006 ************/
// tag from Red Eye for file/rss/external etc... links

function RedEyeTag(strTag){

    imgRedEye = new Image();
    imgRedEye.src = 'https://reporting.cheltglos.co.uk/cgi-bin/rr.cgi/images/blank.gif?nourl=www.cheltglos.co.uk/ifa' + strTag;

}

function RedEyeTagCon(strTag){
    imgRedEye = new Image();
    imgRedEye.src = 'http://reporting.cheltglos.co.uk/cgi-bin/rr.cgi/images/blank.gif?nourl=www.cheltglos.co.uk/intlnk/affordabilitycalc/' + strTag ;
}

function RedEyeTagLTSB(strTag){
    imgRedEye = new Image();
    imgRedEye.src = 'http://reporting.cheltglos.co.uk/cgi-bin/rr.cgi/images/blank.gif?nourl=www.cheltglos.co.uk/ltsb/mortgages/affordabilitycalc/' + strTag ;
}


    
                  
var vaWindow = null; 
	function openVA() {			
				
		//optional arguments
		var parameters = (arguments[0]) ? arguments[0] : {};		
		
		//Parameter Defaults (the url, height, and width need to be specified)	
		//url
		//specified the default base url of the Virtual Assistant (without any get parameters attached). 
		if (! parameters.url) parameters.url = "http://ask.cheltglos-intermediaries.co.uk/cgistaging/bot.htm"; 		
		//height
		//specifies the default height of the Virtual Assistant. Typically 480
		if (! parameters.height) parameters.height = "580";
		//width
		//specifies the default width of the Virtual Assistant. Typically 270 or 540
		if (! parameters.width) parameters.width = "330";	
		//name
		//specifies the name of popup window. Typically 'va'.  Used to access the window via javascript
		if (! parameters.name) parameters.name = "va";					
		//center
		//set this true if you'd like the window centered by default	
		if (! parameters.center) parameters.center = false; 
			
		//if neither top or left was specified and center is set to true, calculate location based on screen size
		if ((! parameters.top) && (! parameters.left) && (screen.availWidth) && (parameters.center)){
			
			parameters.top = (screen.availHeight-parameters.height-80) / 2;
			parameters.left = (screen.availWidth-parameters.width-20) / 2;
		
		} else {
		
			//top
			//distance in pixels of the popup window from the top of the screen
			if (! parameters.top) parameters.top = "10";
			//left
			//distance in pixels of the popup window from the left of the screen
			if (! parameters.left) parameters.left = "10";		
		}	
	
		//check resolution, and reset location if necessary
		if (screen.availWidth) {			
			if ((parameters.width > screen.availWidth) || (parameters.height > screen.availHeight)){
				alert("You may have trouble using this Virtual Assistant with your current screen resolution.  Increase your resolution for better usability.");
				parameters.top = 0;
				parameters.left = 0;
			}
		}		
				
		//entry
		//Used to submit an initial question to be asked when the Virtual Assistant is first started.
		//ie: Can I protect my ncd?
		if (! parameters.entry) parameters.entry = ""; 		
		//startContext
		//Indicates which set of Context-driven FAQs should be displayed when the Virtual Assistant is first started.
		//ie: FAQ.Home Insurance
		if (! parameters.startContext) parameters.startContext = ""; 	
		//siteContext
		//Used in multi-site implementations to indicate from which site the user has come.
		//Can be used in single-site installations to indicate from which area of the web site the user has come. Enables reporting by web site area.		
		if (! parameters.siteContext) parameters.siteContext = ""; 
		//noFree
		//Used to suppress display of free text entry box in the Virtual Assistant window when calling from (for example) help buttons on forms. 
		//Allows the user to navigate existing FAQs but not to ask free-text questions/engage in smalltalk.
		//Any non-null value indicates that the free text entry box should be suppressed (this feature is not available by default)	
		if (! parameters.noFree) parameters.noFree = ""; 

		//uid	
		//Required unique identifier
		parameters.uid = new Date().getTime() + Math.floor(Math.random()*100);  	
		
		var openParameters = 'resizable=no, toolbar=no, location=no, status=no, scrollbars=no, menubar=no, titlebar=no, width=' + parameters.width + ',height=' + parameters.height + ', top=' + parameters.top + ', left=' + parameters.left;
		
		var getParameters = "";
		
		getParameters += "uid=" + parameters.uid;
		
		if (parameters.entry.length > 0) getParameters += "&entry=" + encodeURIComponent(parameters.entry);
		if (parameters.startContext.length > 0) getParameters += "&StartContext=" + encodeURIComponent(parameters.startContext);
		if (parameters.siteContext.length > 0) getParameters += "&SiteContext=" + encodeURIComponent(parameters.siteContext);
		if (parameters.noFree.length > 0) getParameters += "&NoFree=" + encodeURIComponent(parameters.noFree);
		
		var fullUrl = parameters.url + "?" + getParameters;
				
		var windowExists = false;
		
		try{
			if(vaWindow && vaWindow.open && !vaWindow.closed)	windowExists = true;
  		} catch(err) {
			try{
				vaWindow.close();
  			} catch(subErr) {}	
  		}		
				
		if(windowExists){//if popup window already exists, update location and focus
					
			var windowLocation = vaWindow.location.href;
			var setLocation = fullUrl;
			
			//update location if necessary
			if (windowLocation.lastIndexOf('/') !== -1)	
				windowLocation = windowLocation.substr(windowLocation.lastIndexOf('/') + 1, windowLocation.length - windowLocation.lastIndexOf('/') - 1);
			windowLocation = windowLocation.replace(/uid=[^\&]*/, "");
			
			if (setLocation.lastIndexOf('/') !== -1)	
				setLocation = setLocation.substr(setLocation.lastIndexOf('/') + 1, setLocation.length - setLocation.lastIndexOf('/') - 1);
			setLocation = setLocation.replace(/uid=[^\&]*/, "");									
				
			if (windowLocation != setLocation)	vaWindow.location.href = fullUrl;
			vaWindow.focus();
			
		} else {//create the VA pop-up
		
			vaWindow = window.open(fullUrl, parameters.name, openParameters);
		}
		
		return false;

	}//end openVA

	