/***
	Generic JavaScript functions.
	(Comments to luckyluke@luckyluke.eu)
***/
var validated_ok;
$(document).ready(function(){

	$("#overlay_dd").hide();//this hides element that can be found in /js/calc_rates.js
	$("#overlay").hide();
	$(".tabContent").hide();
	if($(".tabs")[0]){
		$.jtabber({
			mainLinkTag: ".tabs a", // much like a css selector, you must have a 'title' attribute that links to the div id name
			activeLinkClass: "on", // class that is applied to the tab once it's clicked
			hiddenContentClass: "tabContent", // the class of the content you are hiding until the tab is clicked
			showDefaultTab: 1, // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
			showErrors: false, // true/false - if you want errors to be alerted to you
			effect: 'fade', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
			effectSpeed: 'medium' // 'slow', 'medium' or 'fast' - the speed of the effect
		})
	}
	
	$(".collapsible H3 SPAN").wrap("<a href=\"#\"></a>")
	$(".collapsible H3").next().hide()
	$(".collapsible H3").click(function(){
		$(this).toggleClass("expanded")
		if($(this).next().css("display")!="block"){
			$(this).next().slideDown(250);
		} else {
			$(this).next().slideUp(250);
		}
		return false;
	})
	

overlayInitialized = false;
if (validated_ok)	{
//$("#checkTheAnswers").click(function(){

	//heading for error message
	var err_mess = '<p><strong>You are eligible for cover however claims from the following are excluded:</strong></p>';
	
	//if yes to doctor checked then display this message
	if (document.getElementById('yes_consulted_doctor'))	{
		if (document.getElementById('yes_consulted_doctor').checked)	{
			err_mess = err_mess + "<ul><li>You will be covered for any new medical condition, however, claims from the following are excluded:</li><ul><li>Any medical condition which occurs in the first 24 months of the policy as a result of any medical condition for which treatment had been given or diagnosis commenced during the 12 months before the start date. Any chronic or continuing condition which you already have.</li></ul></ul>";
			var displ = 'true';
			var dis_sick = 'true';
		}
	}

	//if yes to impending sicknes checked then display this message
	if (document.getElementById('yes_impending_sickness'))	{
		if (document.getElementById('yes_impending_sickness').checked && dis_sick != 'true')	{
			err_mess = err_mess + "<ul><li>You will be covered for any new medical condition, however,claims from the following are excluded:</li><ul><li>Any medical condition which occurs in the first 24 months of the policy as a result of any medical condition for which treatment had been given or diagnosis commenced during the 12 months before the start date. Any chronic or continuing condition which you already have.</li></ul></ul>";
			var displ = 'true';
		}
	}

	//if yes to impending unemployment checked then display this message
	if (document.getElementById('yes_impending_unemployment'))	{
		if (document.getElementById('yes_impending_unemployment').checked)	{
			err_mess = err_mess + "<ul><li>You are eligible for cover however claims from the following are excluded</li><ul><li>Unemployment you knew to be impending when your policy starts</il><li>Unemployment that starts in the first 60 or 120 days of the policy, see the product summary for more information</li></ul></ul>";
			var displ = 'true';
		}
	}

		//if yes to capital share ticked then display this message
	if (document.getElementById('yes_share_capital'))	{
		if (document.getElementById('yes_share_capital').checked)	{
			err_mess = err_mess + "<ul><li>If you or an immediate member of your family is a company director of the company you work for, your company must have involuntarily ceased trading for you to be able to claim for unemployment benefit.</li></ul>"; 
			var displ = 'true';
		}
	}

			

			//check if any error to display
			if (displ != undefined)	{
				document.getElementById('overlay').innerHTML = err_mess;

				$("#canvas").css({opacity:"0.3"});
				$("#footer").css({opacity:"0.3"});
		
				$("#overlay").appendTo("body")
		
				$("#overlay").css({position:"absolute",zIndex:"500",background:"#FFFFFF",border:"1px solid #CCCCCC",padding:"10px 15px 10px 15px",width:"350px"})
				myLeft = parseInt((document.body.offsetWidth-$("#overlay").width())/2);
				myTop = parseInt((document.body.offsetHeight-$("#overlay").height())/3);
				$("#overlay").css({left:myLeft,top:myTop})
				if (!overlayInitialized){
					$("#overlay").prepend("<p class=\"tar\" style=\"margin-top:0px;\"><a href=\"application-yourdetails.php\">Close</a></p>")
					$("#overlay").append("<p class=\"tac\" style=\"margin-top:20px;\"><a href=\"application-yourdetails.php\"><img src=\"img/buttons/continue.gif\" width=\"80\" height=\"21\" alt=\"Continue\" title=\"Continue\"></a></p>")
					overlayInitialized = true;
				}
				$("#overlay").show();
				return false;
			}

		//if all the above OK then submit form and validate using php
		window.location="application-yourdetails.php";

//})//end of function for overlay on beforeyoustart page
}


	$(".tTip").mouseover(function(event){
		if($(".toolTip")[0]==null || $(".toolTip")[0]=="undefined"){
			$("body").append("<div class=\"toolTip\"><img class=\"wedge\" src=\"img/bg/wedge.gif\" width=\"11\" height=\"22\" alt=\"\" /><p id=\"ttCnt\"></p></div>");
		}
//		$(".toolTip").css({left:event.pageX,top:event.pageY})
		$(".toolTip").css({left:findPosX($(this)[0])+35,top:findPosY($(this)[0])-10})
//		alert($(".toolTip").html());
		theTitle = $(this).attr("title");
		$("#ttCnt").html(theTitle);
		$(".toolTip").show()
	})
	$(".tTip").mouseout(function(event){
		$(".toolTip").hide()
	})
})
function closeMe(){
	$("#canvas").css({opacity:"1"});
	$("#footer").css({opacity:"1"});
	$("#overlay").hide();
	$("#overlay_dd").hide();
}

function findPosY(obj){
	var curtop = 0;
//	if (opr){ curtop = parseInt((document.body.offsetHeight)); }
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}
function findPosX(obj){
	var curleft = 0;
//	if (opr){ curleft = parseInt((document.body.offsetWidth)); }
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}