 function formatNumber(myNum, numOfDec)
{
var decimal = 1
for(i=1; i<=numOfDec;i++)
decimal = decimal *10

var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec)
return(myFormattedNum)
} 

function validate_me()
{
    //STEP ONE VALIDATION STARTS HERE
    if(document.form1.fname.value == "")
    {
        alert("Please fill in the 'First Name' box.");
		document.form1.fname.focus();
        return false;
    }

    if(document.form1.lname.value == "")
    {
        alert("Please fill in the 'Last Name' box.");
		document.form1.lname.focus();
        return false;
    }
	
	if(document.form1.tel.value == "" && document.form1.email.value == "")
    {
        alert("Please fill in either Tel or Email");
		document.form1.tel.focus();
        return false;
    }
	
	if(document.form1.tel.value!='')
	{
	strng1=document.form1.tel.value;	
	var stripped = strng1.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped)))
		{
		alert("The phone number contains illegal characters.");
		document.form1.tel.focus();
		return false;
		}
  	}

	if(document.form1.email.value!='')
	{
	var str=document.form1.email.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			if (!filter.test(str))
			{
			alert("Please enter a valid email address!");
			document.form1.email.focus();
			return false;
			}
	}
			
	if(document.form1.addrproperty.value == "")
    {
        alert("Please fill in the 'Address of the Property' box.");
		document.form1.addrproperty.focus();
        return false;
    }
	//STEP ONE VALIDATION ENDS HERE
    
	//STEP TWO VALIDATION STARTS HERE
	if(document.form1.planE.checked)
	{
		if (document.form1.aedcontent.value=="" && document.form1.aedbelonging.value=="") 
		{
		document.form1.aedcontent.focus();
		alert("Please enter the values for Contents and/or Personal Belongings");
		document.form1.aedcontent.focus();
		}
		
		else if (document.form1.aedbelonging.value!="" && document.form1.aedcontent.value=="") 
		{
		document.form1.aedcontent.focus();
		alert("Personal Belongings cover only available along with Contents cover. Please enter a value for Contents.");
		document.form1.aedcontent.focus();
		}
		//else document.form1.aedbelonging.focus();
		return false;	
		
	}
		
	return true;
	
	
	//IF EVERYTHING PASSED SUBMIT THE FORM
}//END OF FUNCTION VALIDATE

function calculate()
{
	
	if(isNaN(document.form1.aedcontent.value))
		{
		alert("Only numbers allowed for Contents value.");
		document.form1.aedcontent.focus();
		return false;
		}
	
	if(isNaN(document.form1.aedbelonging.value))
		{
		alert("Only numbers allowed for Belongings value.");
		document.form1.aedbelonging.focus();
		return false;
		}

						if (document.form1.aedcontent.value || document.form1.aedbelonging.value)
								{		
										var contents=document.form1.aedcontent.value;
										var belongs=document.form1.aedbelonging.value;
										var a=contents*(0.4/100);
										var b=belongs*(1.4/100);
										if (a<250 && document.form1.aedcontent.value!="") a=250;
										if (b<250 && document.form1.aedbelonging.value!="") b=250;	
										
										var Annual_Premium =formatNumber((a + b), 2);
										var Premium_PerDay = formatNumber((Annual_Premium/365),2);
										document.form1.aedpremium.value=Annual_Premium;
										document.form1.aedperday.value=Premium_PerDay;
									}	
							else {document.form1.aedpremium.value=""; document.form1.aedperday.value=""; }
						
 }



function selectradio()
{
	document.getElementById('planE').checked=true;
}

function clearPlanE()
{
	document.form1.aedcontent.value="";
	document.form1.aedbelonging.value="";
	document.form1.aedpremium.value="";
	document.form1.aedperday.value="";
	
}



