$(document).ready(function() {
	// Expand Call Me Panel
	$(".call-button").click(function(){
		show_callme_login();
	});
	function show_callme_login(){
		if(document.getElementById('callme_box_div').style.visibility == 'hidden'){
			 document.getElementById('callme_box_div').style.visibility='visible';
		}else{
			document.getElementById('callme_box_div').style.visibility='hidden';
		}
	}
	
	
	
	$(".conflict-of-interest-policy- a").attr("target", "_blank");
	
	
}); 

$(document).ready(function(){
	$("#tabs").tabs();
	$("#accordion").accordion({header: "h2", autoHeight: false, collapsible: true, active: 0});
 
});

function showRequests(formData, jqForm, options) { 
	var form = $('#edit-submitted-name-1').val();
	var callmeName = $('#edit-submitted-name').val();
	var callmeNumber = $('#edit-submitted-number').val();
	
	if(callmeName=='Name' || callmeNumber=='Number'){
		alert('Please enter all fields');
		return false;
	}else{
		return true;
	}
}
function showSuccessful() { 
	alert('Thank you, we will be in contact shortly.');
	return true;
}

function showRequest(formData, jqForm, optionss) { 
	var frm = $('#edit-submitted-name-1').val();
	
	if(frm){
		var callmeName = $('#edit-submitted-name-1').val();
		var callmeNumber = $('#edit-submitted-number-1').val();
	}else{
		var callmeName = $('#edit-submitted-name').val();
		var callmeNumber = $('#edit-submitted-number').val();
	}
	
	if(callmeName=='Name' || callmeNumber=='Number'){
		alert('Please enter all fields');
		return false;
	}else{
		return true;
	}
}
function showSuccessful() { 
	document.getElementById('callme_box_div').style.visibility='hidden';
	alert('Thank you, we will be in contact shortly.');
	return true;
}



function wehearu(){

				var wOpen

				theWidth  = 720;

				theHeight = 650;

				theTop=(screen.availHeight/2)-(theHeight/2)

				theLeft=(screen.availWidth/2)-(theWidth/2)

				features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;



				wOpen = window.open('https://www.wehearu.co.za/ClientSurvey/WebCollectorIntro.aspx?Survey=18&Brand=OLF', 'eSurvey', features);

				wOpen.focus();

}



function formatCurr(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + 'R' + num + '.' + cents);
}


function disclaimerChecked(){
	if($('#disclaimerTick').attr('checked')){
		$('#pdfButton').attr('disabled', false);
	}else{
		$('#pdfButton').attr('disabled', true);
	} 	
}
function downloadPDF(){
	$.unblockUI();
	window.open('http://www.1lifedirect.co.za/Last_Will_and_Testament.pdf','_newtab');
	//$('#disclaimerContent').html('<embed width="100%" height="512px" name="plugin" src="http://www.1lifedirect.co.za/Last_Will_and_Testament.pdf" type="application/pdf">')	
}


function validate() { 
	var name = $("#edit-submitted-name").val();
	var surname = $("#edit-submitted-surname").val();
	var number = $("#edit-submitted-id-number").val();
	if(name=='' || surname=='' || number==''){
		alert('Please enter all fields'); 
    	return false; 
  	} 
    //pop up free will disclaimer  
	$.blockUI({ 
        message: $('#disclaimerContent'), 
        title:    'Will Disclaimer', 
        draggable: true, 
        theme: true,
		focusInput: false
    }); 
	$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI); 
}


$(document).ready(function() {
	$('#disclaimerTick').click(disclaimerChecked);
	$('#pdfButton').click(downloadPDF);
});

$(document).ready(function() {
	$('#dreadcover').blur(function(){
		var dreadCurValue = formatCurr($("#dreadcover").val());
		$("#dreadcover").val(dreadCurValue); 
	});
	$('#disabilitycover').blur(function(){
		var disabilityCurValue = formatCurr($("#disabilitycover").val());
		$("#disabilitycover").val(disabilityCurValue); 
	});
	$('#lifecoverval').blur(function(){
		var lifecoverCurValue = formatCurr($("#lifecoverval").val());
		$("#lifecoverval").val(lifecoverCurValue); 
	});
	$('#incomevalue').blur(function(){
		var incomeCurValue = formatCurr($("#incomevalue").val());
		$("#incomevalue").val(incomeCurValue); 
	});
	
});



$(document).ready(function() {
	$('#webform-client-form-42').ajaxForm( { beforeSubmit: validate } ); 
});


$(document).ready(function(){
	var optionss = { 
        beforeSubmit:  showRequest,
        success:       showSuccessful,
        //clearForm: true
        resetForm: true
    };
	$('#webform-client-form-87').ajaxForm(optionss); 
	 
});

$(document).ready(function(){
	var options = { 
        beforeSubmit:  showRequests,
        success:       showSuccessful,
        //clearForm: true
        resetForm: true
    };
	$('#webform-client-form-33').ajaxForm(options); 
	 
});

/************ ADDED ************/

function callme(){
    var error = '';
    var name = $.trim($(".name").val());
    var tel = $.trim($(".tel").val());
    if(name == "Name:" || name.length == 0){ error += "* Your name.\r\n"; }
    if(tel == "Number:" || tel.length == 0 || tel.length < 10 ){ error += "* Your 10 digit number."; }
    
    if(error.length > 0){ alert("Please fill in the following:\r\n\n" + error); }
    else {
        $(".qform").submit();
        $(".postform").html("<p class='text'>Thank You! A consultant will call you back !</p>\r\n"); 
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	$(window.location).attr('href', sPage+'?status=1');
	
    }
}


function resetForm(){
	$(".postform").html("<p class='text'>Thank You! A consultant will call you back !</p>\r\n"); 
}






