var isEligible = true;
var needPartnerDOB = false;
var titleTxt;

function salesPathwayInit()
{
	if(typeof sIFR == "function"){
		/* Landing Page */
		sIFR.replaceElement(named({sSelector:"#SP_pageTitle h2 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#ffffff" }));
		sIFR.replaceElement(named({sSelector:"#SP_Quote_step1 h3 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_Recommendation_step2 h3 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_Options_step3 h3 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_col_1 h3 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_col_2 h3 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_col_2 h4 .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#666666" }));

		sIFR.replaceElement(named({sSelector:"fieldset legend .interstate", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/interstate.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:"#SP_pageTitle h2 .mayfield", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/mayfield.swf", sColor:"#ffffff" }));
		sIFR.replaceElement(named({sSelector:".step1intro h3 .mayfield", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/mayfield.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:".step2intro h3 .mayfield", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/mayfield.swf", sColor:"#0078c1" }));
		sIFR.replaceElement(named({sSelector:".step2introSBS h3 .mayfield", sWmode:"transparent", sFlashSrc:getHostName() + "/MBFSystem/Flashfiles/mayfield.swf", sColor:"#0078c1" }));
	}
	
	$("div").filter(".dob_partner").hide();
	$("div").filter(".pop").width((bodyWidth/5)*4);
	$("div").filter(".pop").css("left",((bodyWidth/5)/2));
	$("div").filter(".pop").css("opacity", 0);
	
	$("#quickQuoteCriteria").css("opacity", 0);
	$("#quickQuoteCriteria").hide();
	
	$("#emailquote").css("opacity", 0);
	$("#emailquote").hide();
	
	$("#quickQuote_Exist").click(loadCriteriaOptions);
	
	if ((!document.getElementById("quickQuote_Exist") && document.getElementById("quickQuoteCriteria")) ||
		document.getElementById("criteria_errors")) 
		loadCriteriaOptions();
	
	$("a").filter(".banner_promo_link").click(function(event){
		loadBannerPromo($(this).parent().next("div"),event.pageY, $(this).attr("class").split(" ")[0]);
	});

	var currenturl = location.href;
	if (currenturl.indexOf("?tcpopup")!=-1) {
		loadBannerPromo($("a").filter(".banner_promo_link").parent().next("div"),500, $("a").filter(".banner_promo_link").attr("class").split(" ")[0]);
	} 
	else {
	}	
	
	$("div").filter(".banner_promo").css("opacity", 0);
	$("div").filter(".banner_promo").hide();
	
	$("a").filter(".clicktocall_button").click(function(event){
		appendClickToCalliFrame();
		loadClickToClall($(this).parent().next("div"),event.pageY, $(this).attr("class").split(" ")[0]);
	});
	$("div").filter(".clicktocall").css("opacity", 0);
	$("div").filter(".clicktocall").hide();
	
	if(document.getElementById("excess")) {
		var a = document.getElementById("excess").value;
		if (a != null) {
			if(a == '1000') {
				$("#levy_excess").slideDown();
			}
		}
	}
	$("#quickQuoteCriteria p:eq(1)").hide();
	
	//Click to Call for PHI application fix - to be removed once the PHI application enhancements are released.
	var elmlength = $("div#clicktocall").children("fieldset#container").children("#clicktocallframe").length;
	if(elmlength==0){
		$("div#clicktocall").children("fieldset#container").html("<iframe name='ClickToCall' id='clicktocallframe' height='300' scrolling='no' src='' width='435' frameborder='0'></iframe>");
	}
	
	//Sales Pathway Marketing Banner segment selection
	var stateSelected = $("#criteria_state").val();	
	if(stateSelected == 'W') {
		$("#banner2").slideDown("slow");
		$('#campID').val("2010WO012");	
	}
	else {
		$("#banner1").slideDown("slow");		
	}
	
	$(".step1intro h3").html("What you've told us");
	$(".step2intro h3").html("Your health cover options");	
	$(".step3intro h3").html("Your next steps");
}

function appendClickToCalliFrame()
{
	//$("div#clicktocall").children("fieldset#container").html("<iframe name='ClickToCall' height='330' scrolling='no' src='https://click.messagestick.com.au/call/2708' width='430' frameborder='0'></iframe>");
	
	document.getElementById('clicktocallframe').setAttribute("src","https://click.messagestick.com.au/call/2708");
}

function updateField(fieldValue, obj)
{	
	cursor_wait();
	$(obj).parent().parent().children("dd").children("a").removeClass("active");
	$(obj).addClass("active");
	$(obj).parent().parent().children("dd").children("input").attr("value",fieldValue);
	
	if (fieldValue == 'REBATE_NOT_ELIGIBLE' && $(obj).parent().parent().attr("id") == 'Control_Rebate' && isEligible)
	{
		isEligible = false;
		$("#not_eligible").slideDown();
		$("#apply_now_btn").slideUp('normal', function(){ $("#apply_now_btn").hide();});
		cursor_clear();
	}
	else if (fieldValue != 'REBATE_NOT_ELIGIBLE' && $(obj).parent().parent().attr("id") == 'Control_Rebate' && !isEligible)
	{
		isEligible = true;
		$("#not_eligible").slideUp();
		$("#apply_now_btn").slideDown('normal',submitSettingSelection);
	}
	else if (fieldValue == 'REBATE_NOT_ELIGIBLE' && $(obj).parent().parent().attr("id") == 'Control_Rebate')
	{
		return false;
	}
	else
	{
		submitSettingSelection();
	}
}

function loadSendFriendOptions()
{
	$("#emailquote").prepend("<div class='pop-close'><a href='javascript://' onClick='hideSendFriendOptions()'>close window x</a></div>");
	showOverlay();
	$("#emailquote").css("left",(bodyWidth/2)-($("#emailquote").width()/2));
	$("#emailquote select").show();
	$("#emailquote").fadeTo("slow", 1);
}

function hideSendFriendOptions()
{
	hideOverlay();
	$("#emailquote").fadeTo("slow", 0, function(){$("#emailquote").hide();});
}

function cancelQuoteCriteria()
{
	if (document.getElementById("quickQuote_Exist")) 
	{
		hideCriteriaSelection();
		
	} else {
		
		history.go(-1);
	}
}

function loadCriteriaOptions()
{
	if (document.getElementById("quickQuote_Exist")) 
	{
		$("#quickQuoteCriteria").prepend("<div class='pop-close'><a href='javascript://' onClick='hideCriteriaSelection()'>close window x</a></div>");
	} else {
		//$("#quickQuoteCriteria").prepend("<div class='pop-close'><a href='javascript://' onClick='cancelQuoteCriteria()'>close window x</a></div>");
	}
	
	showOverlay();
	
	$("#quickQuoteCriteria").css("left",(bodyWidth/2)-($("#quickQuoteCriteria").width()/2));
	$("#quickQuoteCriteria select").show();
	$("#quickQuoteCriteria").fadeTo("slow", 1);
	
	$("input").filter(".chkddmm").blur(function(){
		currVal = $(this).val();
		if ( $(this).val().length < 2)
		{
				$(this).val("0"+currVal);
		}
	});
	
	$("input").filter(".chkyyyy").blur(function(){
		currVal = $(this).val();
		currLength = $(this).val().length;
		switch(currLength)
		{
		case 1:
			$(this).val("190"+currVal);
			break
		case 2:
			$(this).val("19"+currVal);
			break
		case 3:
			$(this).val("1"+currVal);
			break
		default:
			return false;
		}
				
	});
	
	togglePartnerDetails();
	getStaticProducts();
	$("#criteria_status").change(togglePartnerDetails);
	$("#criteria_status").change(toggleDEmsg);
}


function getStaticProducts()
{
	if($("#staticHospitalProduct").val() != null)
	{
		$("#hospitalProduct").val($("#staticHospitalProduct").val());
		$("#extrasProduct").val($("#staticExtrasProduct").val());
	}
}

function togglePartnerDetails()
{
	if (($("#criteria_status").val() == "F" || $("#criteria_status").val() == "FAMILY DE" || $("#criteria_status").val() == "C") && !needPartnerDOB)
	{
		$("div").filter(".dob_partner").slideDown();
		needPartnerDOB = true;
	}
	else if (($("#criteria_status").val() != "F" && $("#criteria_status").val() != "FAMILY DE" && $("#criteria_status").val() != "C") && needPartnerDOB)
	{
		$("div").filter(".dob_partner").children("div").filter(".dob").children("input:text").clearFields();
		$("div").filter(".dob_partner").slideUp();
		needPartnerDOB = false;
	}
	else
	{
		return false
	}
}

function toggleDEmsg()
{
	if (($("#criteria_status").val() == "FAMILY DE" || $("#criteria_status").val() == "SOLE PRNT DE"))
	{
		$("#quickQuoteCriteria p:eq(1)").slideDown();
	} else {
		var isVisible = $('#quickQuoteCriteria p:eq(1)').is(':visible');
		if (isVisible == 1)
		{
			$("#quickQuoteCriteria p:eq(1)").slideUp();
		} else {
			$("#quickQuoteCriteria p:eq(1)").hide();
		}
	}	
}

function loadClickToClall(obj, pageY, popWidth)
{
	$(obj).width(popWidth);
	$(obj).prepend("<div class='pop-close'><a href='javascript://'>close window x</a></div>");
	showOverlay();
	$(obj).css("top",(pageY-($(obj).height()/2)));
	$(obj).css("left",(bodyWidth/2)-($(obj).width()/2));
	$(obj).show();
	$(obj).fadeTo("slow", 1);
	
	$(obj).children("div").filter(".pop-close").children("a").click(function(){
		hideClickToClall(obj);
	});
}

function hideClickToClall(obj)
{
	hideOverlay();
	$(obj).fadeTo("slow", 0, function(){$(obj).hide();});
}

function loadBannerPromo(obj, pageY, popWidth)
{
	$(obj).width(popWidth);
	$(obj).prepend("<div class='pop-close'><a href='javascript://'>close window x</a></div>");
	showOverlay();
	$(obj).css("top",(pageY-($(obj).height()/2)));
	$(obj).css("left",(bodyWidth/2)-($(obj).width()/2));
	$(obj).show();
	$(obj).fadeTo("slow", 1);
	
	$(obj).children("div").filter(".pop-close").children("a").click(function(){
		hideBannerPromo(obj);
	});
}

function hideBannerPromo(obj)
{
	hideOverlay();
	$(obj).fadeTo("slow", 0, function(){$(obj).hide();});
}

function numbersonly(input, obj)
{
	var unicode=input.charCode? input.charCode : input.keyCode
	
	if (unicode != 8 && unicode != 13 && unicode != 9)
	{
		if (unicode<48||unicode>57)
		{
			return false
		}
	}
}

function hideCriteriaSelection()
{
	hideOverlay();
	$("#quickQuoteCriteria").fadeTo("slow", 0, function(){$("#quickQuoteCriteria").hide();});
}

/************************************************
**** 31/11/2007 Updated to allow close links ****
************************************************/

function recommendationInit()
{
	
	$("#apply_now_btn a img").attr("src","/MBFSystem/Images/spathway/b_applynow.gif");
	
	$("#Additional_Hospital").hide();
	$("#Additional_Extras").hide();
	
	$("h6").filter(".hospital").children("a").toggle(function(){
		$(this).toggleClass("active");
		$("#Additional_Hospital").slideToggle("slow");
	},function(){
		$(this).toggleClass("active");
		$("#Additional_Hospital").slideToggle("slow");
	});
	
	$("p").filter(".hospital_close").children("a").click(function(){
		$("h6").filter(".hospital").children("a").toggleClass("active");
		$("#Additional_Hospital").slideToggle("slow");
	});
	
	$("h6").filter(".extras").children("a").toggle(function(){
		$(this).toggleClass("active");
		$("#Additional_Extras").slideToggle("slow");
	},function(){
		$(this).toggleClass("active");
		$("#Additional_Extras").slideToggle("slow");
	});
	
	$("p").filter(".extras_close").children("a").click(function(){
		$("h6").filter(".extras").children("a").toggleClass("active");
		$("#Additional_Extras").slideToggle("slow");
	});
}

/****************************************
**** 15/11/2007 Choices Product page ****
****************************************/

function productPageInit()
{
	$("#layer1").hide();
	$("#layer2").hide();
	$("#layer3").hide();
	$("#layer4").hide();
	
		$("a").filter(".hospital_cover").click(function(){
			$("#layer1").slideToggle("slow");
			$("a").filter(".hospital_cover").each(function(){  
				$(this).toggleClass("active");
			});
		});
		
		$("a").filter(".extras_cover").click(function(){
			$("#layer2").slideToggle("slow");
			$("a").filter(".extras_cover").each(function(){  
				$(this).toggleClass("active");
			});
		});
		
		$("a").filter(".unexpected_benefits").click(function(){
			$("#layer3").slideToggle("slow");
			$("a").filter(".unexpected_benefits").each(function(){  
				$(this).toggleClass("active");
			});
		});
		
		$("a").filter(".hospital_programs").click(function(){
			$("#layer4").slideToggle("slow");
			$("a").filter(".hospital_programs").each(function(){  
				$(this).toggleClass("active");
			});
		});
}

/****************************************
******* End Choices Product page ********
****************************************/

function sideBySideInit()
{
	var maxlength = $("#SP_SideBySide table tr .col_0 table tr").children();
	
	for (i = 0; i < maxlength.length; i++)
	{
		a = $("#SP_SideBySide table tr .col_0 table tr").children()[i];
		b = $("#SP_SideBySide table tr .col_1 table tr").children()[i];
		c = $("#SP_SideBySide table tr .col_2 table tr").children()[i];
		d = $("#SP_SideBySide table tr .col_3 table tr").children()[i];
		
		maxHeight = Math.max($(a).height(),$(b).height(),$(c).height(),$(d).height());
		
		$(a).height(maxHeight+34);
		$(c).height(maxHeight+34);
		$(b).height(maxHeight+34);
		$(d).height(maxHeight+34);		
	}
}

function productSelectorInit()
{	

	$("#btn_finalQuote").attr("src","/MBFSystem/Images/spathway/b_getaquote.gif").show();
	
	$.each( $("#Table_Hospital thead tr td img"), function(i, l){
		if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_1_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_1.gif") {
			$(this).hide().before("<span>Basic cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_2_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_2.gif") {
			$(this).hide().before("<span>Medium cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_3_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_3.gif") {
			$(this).hide().before("<span>Medium cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_4_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_4.gif") {
			$(this).hide().before("<span>Top cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_5_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_5.gif") {
			$(this).hide().before("<span>Top cover</span>");
		}
	 });
	
	$.each( $("#Table_Extras thead tr td img"), function(i, l){
		if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_1_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_1_lime.gif") {
			$(this).hide().before("<span>Basic cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_2_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_2_lime.gif") {
			$(this).hide().before("<span>Medium cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_3_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_3_lime.gif") {
			$(this).hide().before("<span>Medium cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_4_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_4_lime.gif") {
			$(this).hide().before("<span>Top cover</span>");
		} else if($(l).attr("src") == "/mbf-portlets/static/images/sp/bar_5_green.gif" || $(l).attr("src") == "/mbf-portlets/static/images/sp/bar_5_lime.gif") {
			$(this).hide().before("<span>Top cover</span>");
		}
	 });
	
	$("#Table_Hospital thead td").each(function(i){
		$(this).click(function(){
			selectProduct(i, $(this).parent().parent().parent().attr("id"));
		});
	});
	
	$("#Table_Extras thead td").each(function(i){
		$(this).click(function(){
			selectProduct(i, $(this).parent().parent().parent().attr("id"));
		});
	});	
	
	$("#Select_Hospital .col").each(function(i){
		$(this).children().children().children().filter(".hasmoreinfo").each(function(j){
			$(this).hover(function(){
				$("#Select_Hospital .col").each(function(k){
					$($(this).children().children().children().filter(".hasmoreinfo")[j]).addClass("over");
				});
			},function(){
				$("#Select_Hospital .col").each(function(k){
					$($(this).children().children().children().filter(".hasmoreinfo")[j]).removeClass("over");
				});
			});
			
			$(this).click(function(event){
				loadMoreInfoHospital(j, event.pageY);
			});
		});
	});
	
	$("#Select_Extras .col").each(function(i){
		$(this).children().children().children().filter(".hasmoreinfo").each(function(j){
			$(this).hover(function(){
				$("#Select_Extras .col").each(function(k){
					$($(this).children().children().children().filter(".hasmoreinfo")[j]).addClass("over");
				});
			},function(){
				$("#Select_Extras .col").each(function(k){
					$($(this).children().children().children().filter(".hasmoreinfo")[j]).removeClass("over");
				});
			});
			
			$(this).click(function(event){
				loadMoreInfoExtras(j, event.pageY);
			});
		});
	});
	
	$("#ProductSelect_Nav dd a").click(changeTab);
	$("td").filter(".inactive").css("opacity",0.3);
	$("td").filter(".inactive").css("background-color","#cccccc");
	
	var JSrows = $($("#Select_Hospital .col")[0]).children().children().children();
	var JScols = $("#Select_Hospital .colcount").children();
	var JScolArr = $("#Select_Hospital tr .col");
	
	for (r=0; r<JSrows.length; r++)
	{
		maxheight = 0;
		
		for (c=0; c<JScols.length; c++)
		{
			rowArr = $($(JScolArr[c]).children().children().children().get(r)).height();
			
			if (maxheight < rowArr) maxheight = rowArr;
		}
		
		for (c=0; c<JScols.length; c++)
		{
			$($(JScolArr[c]).children().children().children().get(r)).height(maxheight);
		}
	}
	
	var Erows = $($("#Select_Extras .col")[0]).children().children().children();
	var Ecols = $("#Select_Extras .colcount").children();
	var EcolArr = $("#Select_Extras tr .col");
	
	for (r=0; r<Erows.length; r++)
	{
		maxheight = 0;
		
		for (c=0; c<Ecols.length; c++)
		{
			rowArr = $($(EcolArr[c]).children().children().children().get(r)).height();
			if (maxheight < rowArr) maxheight = rowArr;
		}
		
		for (c=0; c<Ecols.length; c++)
		{
			$($(EcolArr[c]).children().children().children().get(r)).height(maxheight);
		}
	}
	
	if ( $("dd").filter(".extra_tab").children("a").attr("class") == 'active' )
	{
		$("#Select_Hospital").hide();
		$("#Select_Extras").show();
	}
	
	if ( $("dd").filter(".hospital_tab").children("a").attr("class") == 'active' )
	{
		$("#Select_Hospital").show();
		$("#Select_Extras").hide();	
	}
	
	$("table").filter(".hospital-moreinfo").parent().hide();
	$("table").filter(".extras-moreinfo").parent().hide();
	$("div").filter(".pop").hide();
}


function selectProduct(index, type)
{
	type = type.split("_")[1];
	
	obj = $("#Table_"+type+" thead td")[index];
	product = $(obj).parent().parent().children("tr").children("th")[index+1];
}

function changeTab()
{
	$(this).parent().siblings().children("a").removeClass("active");
	$(this).addClass("active");
	if ($(this).parent().attr("class") != "hospital_tab")
	{

		$(this).parent().parent().attr("class","extras");
		$("#Select_Hospital").hide();
		$("#Select_Extras").show();
		$("label:contains('conditions apply*')").html("<small>terms apply*</small>");
		
	}
	else if ($(this).parent().attr("class") != "extras_tab")
	{
		$(this).parent().parent().attr("class","hospital");
		$("#Select_Hospital").show();
		$("#Select_Extras").hide();
		$("label:contains('terms apply*')").html("<small>terms apply*</small>");
		
	}
}

function hideMoreInfo()
{
	$("div").filter(".pop").fadeTo("slow", 0, function(){$("div").filter(".pop").hide();});
	hideOverlay();
}


function loadMoreInfoHospital(index, mousePos)
{
	showOverlay();
	$("div").filter(".pop").html($("#HS_row"+index).html());
	//$("div").filter(".pop").prepend("<div class='pop-close'><a href='javascript://' onClick='hideMoreInfo()'>close window x</a></div>");
	//$("div").filter(".pop").css("top", mousePos);
	$("div").filter(".pop").css("top", 300);
	//$("div").filter(".pop").fadeTo("slow", 0.3, function(){
	$("div").filter(".pop").fadeTo("slow", 0, function(){
		extraRows = $($("div.pop table tr .mcol")[0]).children().children().children();
		extraColCount = $("div.pop table .mcolcount").children();
		extraColArr = $("div.pop table tbody tr .mcol");
				
		$("div.pop table tr .mcol table thead tr th").each(function(i){
			var currTitle = $.trim($(this).html());
			var currArr = $("#Table_Hospital thead th");
			
			if (!(currTitle == "Service category" || currTitle == "Waiting periods"))
			{
				for (j = 0; j < currArr.length; j++)
				{
					if ($.trim($(currArr[j]).html()) == currTitle || $(this).parent().parent().parent().parent().attr("title") == "active")
					{
						$(this).parent().parent().parent().parent().attr("title","active");
						$(this).parent().parent().parent().parent().show();
					}
					else
					{
						$(this).parent().parent().parent().parent().hide();
					}
				}
			}
		});
		
		for (r=0; r<extraRows.length; r++)
		{
			maxheight = 0;
			
			for (c=0; c<extraColCount.length; c++)
			{
				rowArr = $($(extraColArr[c]).children().children().children().get(r)).height();
				if (maxheight < rowArr) maxheight = rowArr;
			}
			
			for (c=0; c<extraColCount.length; c++)
			{
				$($(extraColArr[c]).children().children().children().get(r)).height(maxheight);
			}
		}
		
		$("div").filter("#loading").fadeTo("slow", 0);
		$("div").filter(".pop").fadeTo("slow", 1);
	});
}

function loadMoreInfoExtras(index, mousePos)
{
	showOverlay();
	$("div").filter(".pop").html($("#ES_row"+index).html());
	//$("div").filter(".pop").prepend("<div class='pop-close'><a href='javascript://' onClick='hideMoreInfo()'>close window x</a></div>");
	//$("div").filter(".pop").css("top", mousePos);
	//$("div").filter(".pop").fadeTo("slow", 0.3, function(){
	$("div").filter(".pop").css("top", 300);
	$("div").filter(".pop").fadeTo("slow", 0, function(){
		extraRows = $($("div.pop table tr .mcol")[0]).children().children().children();
		extraColCount = $("div.pop table .mcolcount").children();
		extraColArr = $("div.pop table tbody tr .mcol");
				
		$("div.pop table tr .mcol table thead tr th").each(function(i){
			var currTitle = $.trim($(this).html());
			var currArr = $("#Table_Extras thead th");
			
			if (!(currTitle == "Service category" || currTitle == "Waiting periods"))
			{
				for (j = 0; j < currArr.length; j++)
				{
					if ($.trim($(currArr[j]).html()) == currTitle || $(this).parent().parent().parent().parent().attr("title") == "active")
					{
						$(this).parent().parent().parent().parent().attr("title","active");
						$(this).parent().parent().parent().parent().show();
					}
					else
					{
						$(this).parent().parent().parent().parent().hide();
					}
				}
			}
		});
		
		for (r=0; r<extraRows.length; r++)
		{
			maxheight = 0;
			
			for (c=0; c<extraColCount.length; c++)
			{
				rowArr = $($(extraColArr[c]).children().children().children().get(r)).height();
				if (maxheight < rowArr) maxheight = rowArr;
			}
			
			for (c=0; c<extraColCount.length; c++)
			{
				$($(extraColArr[c]).children().children().children().get(r)).height(maxheight);
			}
		}
		
		$("div").filter("#loading").fadeTo("slow", 0);
		$("div").filter(".pop").fadeTo("slow", 1);
	});
}

// Changes the cursor to an hourglass
function cursor_wait() {
	document.body.style.cursor = 'wait';
}

// Returns the cursor to the default pointer
function cursor_clear() {
	document.body.style.cursor = 'default';
}

// Does some arduous calculation
function calc() {
	var dummy = 0;
	
	for (var i=0; i<1000000;i++) {
		for (var z=0; i<1000000;i++) {
			dummy = dummy + z + i;
		}
	}

	cursor_clear();
}

//  PHI Application premium update highlight
function updatePremium() {
	$("fieldset").filter("#gradient").highlightFade({speed:2000,start:'red',attr:'borderColor',iterator:'linear'});
	$("label").filter(".price").highlightFade({speed:2000,start:'red',attr:'color',iterator:'linear'});
	$("span").filter("#updated").highlightFade({speed:2000,start:'red',attr:'color',iterator:'linear'});
}

$(document).ready(salesPathwayInit);
$(document).ready(sideBySideInit);
$(document).ready(recommendationInit);
$(document).ready(productSelectorInit);
$(document).ready(productPageInit);