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.php.htm";
			break;
		
		case 'Level Term life Insurance':
			linkLocation="/help/life1.php#level";
			break;

		case 'Decreasing Term Life & Critical Illness':
			linkLocation="/help/life1.php#decreasing_critical";
			break;

		case 'Decreasing Term Life Insurance':
			linkLocation="/help/life1.php#decreasing";
			break;

		case 'Critical Illness Insurance':
			linkLocation="/help/life1.php#critical";
			break;
			
		case 'Tax efficient life insurance':
			linkLocation="/help/life1.php#tax_efficient";
			break;

		case 'Pension Term Insurance':
			linkLocation="/help/life1.php#pension";
			break;
			
		case 'Level Tax Efficient Life Insurance':
			linkLocation="/help/life1.php#level_tax_efficient";
			break;
			
		case 'Decreasing Tax Efficient Life Insurance':
			linkLocation="/help/life1.php#decreasing_tax_efficient";
			break;
			
		case 'Level Citical Illness Insurance':
			linkLocation="/help/life1.php#level_critical_illness";
			break;
			
		case 'Decreasing Critical Illness Insurance':
			linkLocation="/help/life1.php#decreasing_critial_illness";
			break;	
			
		default:
			linkLocation="../help/life1.php.htm";
			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/index.php.htm";
			break;

		case 'Travel Insurance':
			linkLocation="../forms/travel/holiday/default.htm";
			break;

		case 'Health Insurance':
			linkLocation="../forms/health/default.htm";
			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.php.htm";
			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/default.htm";
			break;
			
		case 'Critical Illness Insurance':
			linkLocation="../basicinfoci.asp.htm";
			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.php.htm";
			break;

		case 'Contents Insurance':
			linkLocation="../forms/house/contents.php.htm";
			break;

		case 'Buy to Let Insurance':
			linkLocation="../forms/house/buytolet.php.htm";
			break;
			
		case 'Private Medical Insurance':
			linkLocation="../forms/health/pmi.php.htm";
			break;
			
		case 'Mortgage':
			linkLocation="../mpp.htm";
			break;

		case 'Mortgage Payment Protection':
			linkLocation="../forms/mortgage/Mpp.php.htm";
			break;
			
		case 'Holiday Travel Insurance':
			linkLocation="../forms/travel/holiday/default.htm";
			break;
			
		case 'Ski Travel Insurance':
			linkLocation="../forms/travel/ski/default.htm";
			break;

		case 'Multi-trip Travel Insurance':
			linkLocation="../forms/travel/multi/default.htm";
			break;
			
		default:
			linkLocation="../basicinfo.asp.htm";
			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.php.htm";
			break;
		
		case 'House Insurance':
			linkLocation="../houseinsurance.htm";
			break;

		case 'Car Insurance':
			linkLocation="../forms/car/index.php.htm";
			break;

		case 'Travel Insurance':
			linkLocation="../forms/travel/holiday/default.htm";
			break;

		case 'Health Insurance':
			linkLocation="../forms/health/default.htm";
			break;							
			
		case 'Life Insurance':
		    linkLocation="../about.htm";
			//linkLocation="../cre/life.php.htm";
			break;
			
		case 'Whole Life Assurance':
		    linkLocation="../about.htm";
			//linkLocation="../cre/Wc7468ff515be3.htm";
			break;
			
		case 'Level Tax Efficient Life Insurance':
		    linkLocation="../Wc8443d397aad8.htm";
			//linkLocation="../cre/Wc49276fa27834.htm";
			break;
			
		case 'Decreasing Tax Efficient Life Insurance':
		    linkLocation="../Wcc358876053ca.htm";
			//linkLocation="../cre/Wcece5a446671f.htm";
			break;
			
		case 'Level Citical Illness Insurance':
		    linkLocation="../Wc28fc65ac801.htm";
			//linkLocation="../cre/Wc39fbdf77da5b.htm";
			break;
			
		case 'Decreasing Critical Illness Insurance':
		    linkLocation="../Wccafdcb5a5db.htm";
			//linkLocation="../cre/Wc2312ff93910e.htm";
			break;	
			
		case 'Income Protection':
			linkLocation="../forms/income/default.htm";
			break;
			
		case 'Critical Illness Insurance':
		    linkLocation="../Wcca2932a36c15.htm";
			//linkLocation="../cre/Wcc4b3810ba6bd.htm";
			break;
			
		case 'Tax Efficient Life Insurance':
		    linkLocation="../Wc5de69769a04.htm";
			//linkLocation="../cre/Wcb44dade50ac.htm";
			break;
			
		case 'Buildings & Contents Insurance':
			linkLocation="../houseinsurance.htm";
			break;

		case 'Buildings Insurance':
			linkLocation="../forms/house/buildings.php.htm";
			break;

		case 'Contents Insurance':
			linkLocation="../forms/house/contents.php.htm";
			break;

		case 'Buy to Let Insurance':
			linkLocation="../forms/house/buytolet.php.htm";
			break;
			
		case 'Private Medical Insurance':
			linkLocation="../forms/health/pmi.php.htm";
			break;
			
		case 'Mortgage':
			linkLocation="../mpp.htm";
			break;

		case 'Mortgage Payment Protection':
			linkLocation="../forms/mortgage/Mpp.php.htm";
			break;
			
		case 'Holiday Travel Insurance':
			linkLocation="../forms/travel/holiday/default.htm";
			break;
			
		case 'Ski Travel Insurance':
			linkLocation="../forms/travel/ski/default.htm";
			break;

		case 'Multi-trip Travel Insurance':
			linkLocation="../forms/travel/multi/default.htm";
			break;
			
		default:
		    linkLocation="../about.htm";
			//linkLocation="../cre/life.php.htm";
			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.htm";
				break;

			case 'Buildings Insurance':
				jumpTo = "../forms/house/b/2.php.htm";
				break;
				
			case 'Contents Insurance':
				jumpTo = "../forms/house/c/2.php.htm";
				break;

			case 'Buy to Let Insurance':
				jumpTo = "../forms/house/bc/2.php.htm";
				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.htm';
		hide_form('joint_policy');
	} else {
		document.getElementById("form").action = '../forms/life/squotes.php.htm';
		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;
	}
}

//Get Position of Elements of a Page
function GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}

function GetElementLeft(eElement)
{
    if (!eElement && this)                       // if argument is invalid
    {                                            // (not specified, is null or is 0)
        eElement = this;                         // and function is a method
    }                                            // identify the element as the method owner
    
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function hideCornerImage(eElement,minHeight, maxHeight)
{

    var corner_image = document.getElementById(eElement);
    var eHeight = GetElementTop(corner_image);
    //alert(eHeight);
    if ((minHeight != 0 && eHeight <= minHeight) || (maxHeight != 0 && eHeight > maxHeight))
    { corner_image.style.visibility = "hidden"; }
    else
    { corner_image.style.visibility = "visible"; }

}
