 $(function(){
		$("a[rel^='box']").each(function(){$rel=$(this).attr("rel");$width=$rel.substring($rel.indexOf('(')+1,$rel.indexOf(','));var $offset=$rel.indexOf(',')+1;$height=$rel.substring($rel.indexOf(',')+1,$rel.indexOf(',',$offset));$iframe=$rel.substring($rel.indexOf(',',$offset)+1,$rel.indexOf(')'));});
	    $("#submitLifeCal").click(function(){
	       //var valid = ValidateForm();
		   //if(valid){
	    	if(nFCheck()==false){
	    		valid=false;
	    	}else{
			   calIncomeResult();
	    	}
		   //}
		})
	})

    var isSingle= '';
	function setType(type){
		isSingle = 'single';
	}

    function isNumeric(val){
    	return(parseFloat(val,10)==(val*1));
	}

	function calIncomeResult(){

			var coverType = "single";
			//if(document.getElementsByName('coverType')[0].checked){coverType = "single";} else {coverType = "couple"}
			var mortageAndDebt = $("#mortgageLoans").val();
			var grossAnnIncApp = $("#income1").val();
			var grossAnnIncSps = $("#age").val();
			var hostUrl="";
			if(window.location.host == "www.testiselect.com.au"){
				hostUrl="http://life.iselect.com.au";
			}

			$.post(""+hostUrl+"/life-insurance-australia/LifeInsuranceCalc.action","coverType=" + coverType + "&mortageAndDebt=" + mortageAndDebt + "&grossAnnIncApp=" + grossAnnIncApp + "&grossAnnIncSps=" + grossAnnIncSps, function(msg){
		var obj=eval(msg);
		var coverApplicant=obj["calculatedValue"].coverApplicant;
		var coverSpouse=obj["calculatedValue"].coverSpouse;
		var singleValue = '<p><strong>Based on the figures you have entered into  the calculator;</strong></p><p id="singleBase"><strong>We estimate you may require: <span id="singleOutcome" style="font-size:14px; padding-right:5px;"></span>cover.</strong></p>																																																			<p style="font-size: 11px;">This figure is based as an estimation only. We  recommend you talk to one of our financial advisers to confirm these results. </p><p style="font-size: 11px;">Contact us now: 1300 887 299</p><br/><a href="incomeProtectionCalculator.jsp"><img src="/images/b-income-protection-calculator.gif" alt="Income Protection Calculator" border="0" /></a><a href="'+hostUrl+'/life-insurance-australia/home.action"><img src="/images/_life/b-get-quote.gif" alt="Income Protection Calculator" border="0" /></a>';
		$("#lifeCalForm").html(singleValue);																																																								$("#singleOutcome").html(coverApplicant);
$("#main-content").css("height", "200px");
		if(coverSpouse != "null"){
			var partnerValue = '<p><strong>and your partner may require: <span style="font-size:14px;padding-right:5px;">'+coverSpouse +'</span>cover.</strong></p>';
			$("#singleBase").after(partnerValue);
		}
			});
	 }

    function nFCheck(){
	   var field=document.getElementById("mortgageLoansField");
	   var field2=document.getElementById("mortgageLoansField2");
	   var error=document.getElementById("mortgageLoansInputError");
	   var mortgageLoans=document.getElementById("mortgageLoans").value;
	   var validd=true;
	   if(!isNumeric(mortgageLoans)){
		   field.style.background="#F1D2B6";
		   field.style.borderColor="";
		   field.style.borderStyle="";
		   field.style.BorderStyleRight="hidden";
		   field2.style.background="#F1D2B6";
		   field2.style.borderColor="";
		   field2.style.borderStyle="";
		   field2.style.BorderStyleRight="hidden";
		   error.innerHTML="<br><p style=\"font-size:11px;\">Please enter numbers only</p>";
		   validd=false
		}else{
			field.style.background="#FFFFFF";
			field.style.borderColor="#ffffff";
			field.style.borderStyle="none solid solid none";
			field.style.borderWidth="medium 0px 2px medium";
			field2.style.background="#FFFFFF";
			field2.style.borderColor="#ffffff";
			field2.style.borderStyle="none solid solid none";
			field2.style.borderWidth="medium 0px 2px medium";
			error.innerHTML=""
		}

	   var income1Field=document.getElementById("income1Field");
	   var income1Field2=document.getElementById("income1Field2");
	   var income2Field=document.getElementById("ageField");
	   var income1InputError=document.getElementById("income1InputError");
	   var ageInputError=document.getElementById("ageInputError");
	   var income1=document.getElementById("income1").value;
	   var income2=document.getElementById("age").value;
	   //if(isSingle=='couple'){
		   //var coverTypeTD=document.getElementById("coverTypeField");
		   //var coverTypeError=document.getElementById("coverTypeInputError");
		   //coverTypeTD.style.background="#FFFFFF";coverTypeTD.style.borderColor="";
		   //coverTypeTD.style.borderStyle="";coverTypeError.innerHTML="";
		   if(!isNumeric(income1)){
			   income1Field.style.background="#F1D2B6";
			   income1Field.style.borderColor="";
			   income1Field.style.borderStyle="";
			   income1Field2.style.background="#F1D2B6";
			   income1Field2.style.borderColor="";
			   income1Field2.style.borderStyle="";
			   income1InputError.innerHTML="<br><p style=\"font-size:11px;\">Please enter numbers only</p>";
			   validd=false
		 }else{
			   income1Field.style.background="#FFFFFF";
			   income1Field.style.borderColor="#ffffff";
			   income1Field.style.borderStyle="none solid solid none";
			   income1Field.style.borderWidth="medium 0px 2px medium";
			   income1Field2.style.background="#FFFFFF";
			   income1Field2.style.borderColor="#ffffff";
			   income1Field2.style.borderStyle="none solid solid none";
			   income1Field2.style.borderWidth="medium 0px 2px medium";
			   income1InputError.innerHTML=""
		}
		if(!isNumeric(income2)){
			income2Field.style.background="#F1D2B6";
			income2Field.style.borderColor="";
			income2Field.style.borderStyle="";
			ageInputError.innerHTML="<br><p style=\"font-size:11px;\">Please enter numbers only</p>";
			validd=false
		}else{
			income2Field.style.background="#FFFFFF";
			income2Field.style.borderColor="#ffffff";
			income2Field.style.borderStyle="none solid solid none";
			income2Field.style.borderWidth="medium 0px 2px medium";
			ageInputError.innerHTML=""
		}

		return validd;
		}



	 function ValidateForm(){
		var valid=true;
		//var isSingleChecked=$("#coverTypeSingle").attr("checked");var isCoupleChecked=$("#coverTypeCouple").attr("checked");if(!isSingleChecked&&!isCoupleChecked){var field=document.getElementById("coverTypeField");var field2=document.getElementById("coverTypeField2");var error=document.getElementById("coverTypeInputError");field.style.background="#F1D2B6";field.style.borderColor="";field.style.borderStyle="";error.innerHTML="<br>Required Field";valid=false}else{var field=document.getElementById("coverTypeField");var field2=document.getElementById("coverTypeField2");var error=document.getElementById("coverTypeInputError");field.style.background="#FFFFFF";field.style.borderColor="";field.style.borderStyle="";error.innerHTML="";valid=true}if(valid!=false){if(nFCheck()==false){valid=false}}if(valid){valid=true}
		return valid;
	 }

	 function submitForm(){
		   document.lifeInsuranceCalculator.submit();
	 }
