function set_form(areas) {

	var area_array = areas.split(", ");
	
	for (keyVar in area_array){
		if(document.getElementById){
			var ctrl = document.getElementById(area_array[keyVar]);
			if(ctrl != null)
				ctrl.style.display = "none";		
		}
	}
}

function show_form(areas) {

	var area_array = areas.split(", ");
	
	for(keyVar in area_array)
	{
		if(document.getElementById)
		{
			var ctrl = document.getElementById(area_array[keyVar]);
			if(ctrl != null)
				ctrl.style.display = "block";		
		}
	}
}

function show_form2(areas, displayVal) {

	var area_array = areas.split(", ");
	
	for (keyVar in area_array){
		if(document.getElementById){
			document.getElementById(area_array[keyVar]).style.display = displayVal;		
		}
	}
}

function hide_form(areas) {

	var area_array = areas.split(", ");
	
	for (keyVar in area_array){
		if(document.getElementById){
			document.getElementById(area_array[keyVar]).style.display = "none";		
		}
	}
}

function show_form_value(element, area, amount) {

		if(document.getElementById){
			for (var x = 1; x <= amount; x++){		
				document.getElementById(area+x).style.display = "none";
			}

			for (var x = document.getElementById(element).selectedIndex; x >= 1; x--){	
				document.getElementById(area+x).style.display = "block";
			}

		}
}

function openPage() {
	var linkLocation = "";
	
	// Get select box object
	var sel = document.getElementById('type_of_cover');
	// Get select box selected index
	var selectedIndex = sel.selectedIndex;
	// Get selected index value
	var page = sel.options[selectedIndex].firstChild.nodeValue;

	switch (page) {
		case 'Level term life & critical illness insurance':
			linkLocation="/help/life1.aspx";
			break;
		
		case 'Level Term life Insurance':
			linkLocation="/help/life1.aspx#level";
			break;

		case 'Decreasing Term Life & Critical Illness':
			linkLocation="/help/life1.aspx#decreasing_critical";
			break;

		case 'Decreasing Term Life Insurance':
			linkLocation="/help/life1.aspx#decreasing";
			break;

		case 'Critical Illness Insurance':
			linkLocation="/help/life1.aspx#critical";
			break;
			
		case 'Tax efficient life insurance':
			linkLocation="/help/life1.aspx#tax_efficient";
			break;

		case 'Pension Term Insurance':
			linkLocation="/help/life1.aspx#pension";
			break;
			
		case 'Level Tax Efficient Life Insurance':
			linkLocation="/help/life1.aspx#level_tax_efficient";
			break;
			
		case 'Decreasing Tax Efficient Life Insurance':
			linkLocation="/help/life1.aspx#decreasing_tax_efficient";
			break;
			
		case 'Level Citical Illness Insurance':
			linkLocation="/help/life1.aspx#level_critical_illness";
			break;
			
		case 'Decreasing Critical Illness Insurance':
			linkLocation="/help/life1.aspx#decreasing_critial_illness";
			break;	
			
		default:
			linkLocation="/help/life1.aspx";
			break;
	}
	window.open(linkLocation,'Help','width=520,height=450,scrollbars=yes')
}
				
				
function openInsurancePage() {
	var linkLocation = "";
	
	// Get select box object
	var sel = document.getElementById('insurance_type');
	// Get select box selected index
	var selectedIndex = sel.selectedIndex;
	// Get selected index value
	var page = sel.options[selectedIndex].firstChild.nodeValue;

	switch (page) {
		case 'Life Insurance':
			linkLocation="/about.htm";
			break;
		
		case 'House Insurance':
			linkLocation="/houseinsurance.htm";
			break;

		case 'Car Insurance':
			linkLocation="/forms/car/default.aspx";
			break;

		case 'Travel Insurance':
			linkLocation="/forms/travel/holiday/";
			break;

		case 'Health Insurance':
			linkLocation="/forms/health/";
			break;							
			
		case 'Life Insurance':
			linkLocation="/about.htm";
			break;
			
		case 'Whole Life Assurance':
			linkLocation="/forms/life/?type=whole";
			break;
			
		case 'Level Tax Efficient Life Insurance':
			linkLocation="/forms/life/?type=level_tax_efficient";
			break;
			
		case 'Decreasing Tax Efficient Life Insurance':
			linkLocation="/forms/life/decreasing.aspx";
			break;
			
		case 'Level Citical Illness Insurance':
			linkLocation="/forms/life/?type=level_critical_illness";
			break;
			
		case 'Decreasing Critical Illness Insurance':
			linkLocation="/mortgageinsurance.htm";
			break;	
			
		case 'Income Protection':
			linkLocation="/forms/income/";
			break;
			
		case 'Critical Illness Insurance':
			linkLocation="/basicinfoci.asp";
			break;
			
		case 'Tax Efficient Life Insurance':
			linkLocation="/forms/life/?type=tax";
			break;
			
		case 'Buildings & Contents Insurance':
			linkLocation="/houseinsurance.htm";
			break;

		case 'Buildings Insurance':
			linkLocation="/forms/house/buildings.aspx";
			break;

		case 'Contents Insurance':
			linkLocation="/forms/house/contents.aspx";
			break;

		case 'Buy to Let Insurance':
			linkLocation="/forms/house/buytolet.aspx";
			break;
			
		case 'Private Medical Insurance':
			linkLocation="/forms/health/pmi.aspx";
			break;
			
		case 'Mortgage':
			linkLocation="/mpp.htm";
			break;

		case 'Mortgage Payment Protection':
			linkLocation="/forms/mortgage/Mpp.aspx";
			break;
			
		case 'Holiday Travel Insurance':
			linkLocation="/forms/travel/holiday/";
			break;
			
		case 'Ski Travel Insurance':
			linkLocation="/forms/travel/ski/";
			break;

		case 'Multi-trip Travel Insurance':
			linkLocation="/forms/travel/multi/";
			break;
			
		default:
			linkLocation="/basicinfo.asp";
			break;
	}
	return linkLocation;
}

function openInsurancePageCRE() {
	var linkLocation = "";
	
	// Get select box object
	var sel = document.getElementById('insurance_type');
	// Get select box selected index
	var selectedIndex = sel.selectedIndex;
	// Get selected index value
	var page = sel.options[selectedIndex].firstChild.nodeValue;

	switch (page) {
		case 'Life Insurance':
			linkLocation="/about.htm";
			//linkLocation="/cre/life.aspx";
			break;
		
		case 'House Insurance':
			linkLocation="/houseinsurance.htm";
			break;

		case 'Car Insurance':
			linkLocation="/forms/car/default.aspx";
			break;

		case 'Travel Insurance':
			linkLocation="/forms/travel/holiday/";
			break;

		case 'Health Insurance':
			linkLocation="/forms/health/";
			break;							
			
		case 'Life Insurance':
		    linkLocation="/about.htm";
			//linkLocation="/cre/life.aspx";
			break;
			
		case 'Whole Life Assurance':
		    linkLocation="/about.htm";
			//linkLocation="/cre/life.aspx?type=whole";
			break;
			
		case 'Level Tax Efficient Life Insurance':
		    linkLocation="/about.htm?type=level_tax_efficient";
			//linkLocation="/cre/life.aspx?type=level_tax_efficient";
			break;
			
		case 'Decreasing Tax Efficient Life Insurance':
		    linkLocation="/about.htm?type=decreasing_tax";
			//linkLocation="/cre/life.aspx?type=decreasing_tax";
			break;
			
		case 'Level Citical Illness Insurance':
		    linkLocation="/about.htm?type=level_cic";
			//linkLocation="/cre/life.aspx?type=level_cic";
			break;
			
		case 'Decreasing Critical Illness Insurance':
		    linkLocation="/about.htm?type=decreasing_cic";
			//linkLocation="/cre/life.aspx?type=decreasing_cic";
			break;	
			
		case 'Income Protection':
			linkLocation="/forms/income/";
			break;
			
		case 'Critical Illness Insurance':
		    linkLocation="/about.htm?type=cic";
			//linkLocation="/cre/life.aspx?type=cic";
			break;
			
		case 'Tax Efficient Life Insurance':
		    linkLocation="/about.htm?type=tax";
			//linkLocation="/cre/life.aspx?type=tax";
			break;
			
		case 'Buildings & Contents Insurance':
			linkLocation="/houseinsurance.htm";
			break;

		case 'Buildings Insurance':
			linkLocation="/forms/house/buildings.aspx";
			break;

		case 'Contents Insurance':
			linkLocation="/forms/house/contents.aspx";
			break;

		case 'Buy to Let Insurance':
			linkLocation="/forms/house/buytolet.aspx";
			break;
			
		case 'Private Medical Insurance':
			linkLocation="/forms/health/pmi.aspx";
			break;
			
		case 'Mortgage':
			linkLocation="/mpp.htm";
			break;

		case 'Mortgage Payment Protection':
			linkLocation="/forms/mortgage/Mpp.aspx";
			break;
			
		case 'Holiday Travel Insurance':
			linkLocation="/forms/travel/holiday/";
			break;
			
		case 'Ski Travel Insurance':
			linkLocation="/forms/travel/ski/";
			break;

		case 'Multi-trip Travel Insurance':
			linkLocation="/forms/travel/multi/";
			break;
			
		default:
		    linkLocation="/about.htm";
			//linkLocation="/cre/life.aspx";
			break;
	}
	return linkLocation;
}

var m_jsPrevOnLoad = window.onload;
window.onload = function() {
	if(typeof(m_jsPrevOnLoad) == 'function')
		m_jsPrevOnLoad();
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("main_menu");
		if(navRoot == null)
		    return;
		navRoot = navRoot.firstChild;
		for (i=0; i<navRoot.childNodes.length; i++) {

			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" hover";
					this.childNodes[2].className+=" hover";
					this.childNodes[2].style.display = "block";
					this.childNodes[3].style.display = "block";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" hover", "");
					this.childNodes[2].className=this.childNodes[2].className.replace(" hover", "");
					this.childNodes[2].style.display = "none";
					this.childNodes[3].style.display = "none";
				}
			}
			
			for (c=0; c<node.childNodes.length; c++) {
				var ul = node.childNodes[c];
				for (c2=0; c2<ul.childNodes.length; c2++) {
					var li = ul.childNodes[c2];
					if (c2 !=ul.childNodes.length-1) {
						if(	li.nodeName == 'LI') {
							li.onmouseover=function() {
								this.className+=" hover";
							}
							li.onmouseout=function() {
								this.className=this.className.replace(" hover", "");
							}	
						}
					} else {
						if(	li.nodeName == 'LI') {
							li.onmouseover=function() {
								this.className+=" last_hover";
							}
							li.onmouseout=function() {
								this.className=this.className.replace(" last_hover", "");
							}	
						}	
					}
				}			
			}		
		}
	}
}

function changePage(newPage,currentPage) {
	var selectedIndex = newPage.selectedIndex;
	// Get selected index value
	var page = newPage.options[selectedIndex].firstChild.nodeValue;
	// Change to the correct page if we're not already on it
	if(!(currentPage == 'bc' && (page == 'Buildings & Contents' || page == 'Buy to Let Insurance')) && !(currentPage == 'b' && page == 'Buildings Insurance') && !(currentPage == 'c' && page == 'Contents Insurance')) {
		var jumpTo = '';
		switch (page) {
			case 'Buildings & Contents':
				jumpTo = "/forms/house/bc/2.php";
				break;

			case 'Buildings Insurance':
				jumpTo = "/forms/house/b/2.php";
				break;
				
			case 'Contents Insurance':
				jumpTo = "/forms/house/c/2.php";
				break;

			case 'Buy to Let Insurance':
				jumpTo = "/forms/house/bc/2.php";
				break;
		}
		document.location.href=jumpTo;
	}
}


function setAction(sel) {
	var selectedIndex = sel.selectedIndex;
	// Get selected index value
	var action = sel.options[selectedIndex].firstChild.nodeValue;
	if(action=='Tax efficient life insurance') {
		document.getElementById("form").action = '/forms/life/stquotes.php';
		hide_form('joint_policy');
	} else {
		document.getElementById("form").action = '/forms/life/squotes.php';
		show_form('joint_policy')
	}
}

function __bdiShowElementsById()
{
	if(document.getElementById)
	{
		var visible = __bdiShowElementsById.arguments[0];
		if(__bdiShowElementsById.arguments.length > 1)
		{
			for(var i = 1; i < __bdiShowElementsById.arguments.length; i++)
			{
				var ctrl = document.getElementById(__bdiShowElementsById.arguments[i]);
				if(ctrl != null)
					__bdiShowElement(visible, ctrl);
			}
		}
	}
}

function __bdiShowElement(visible,obj)
{
	if(obj == null)
		return;
	if(visible)
	{
		// show hide element and return true
		// because the element is now visible
		obj.style.display = '';
		return true;
	}
	else
	{
		// hide element and return false
		// because the element is now hidden
		obj.style.display = 'none';
		return false;
	}
}

			

//------------------------------------------------------------
//	Event Functions
//------------------------------------------------------------

// Add a function to be run on page loa
function addLoadEvent(func) {

  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}