// JavaScript Document

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function readOnly(evt,obj) {
	if(evt.charCode) evt.preventDefault(); else evt.returnValue=false;	
}

function numsOnly(evt,obj,checkpoint) {
	code=evt.charCode?evt.charCode:evt.keyCode;
	if(code==46 && checkpoint)
	{
		if (obj.value.indexOf('.')>=0){
			if(evt.charCode) evt.preventDefault(); else evt.returnValue=false;	
		}
		
	}else if (!(code>=48 && code <= 57)) {
		if(evt.charCode) evt.preventDefault(); else evt.returnValue=false;
	}
} 

function alphaOnly(evt,space) {
	code=evt.charCode?evt.charCode:evt.keyCode;
	if(code==32 && space)
	{
		/////// allowed
	}
	else if (!((code>=65 && code <= 90) || (code>=97 && code <= 122)) ) {
		if(evt.charCode) evt.preventDefault(); else evt.returnValue=false;
	}
} 

function emailCheck(who){
	var email=/^[A-Za-z0-9][\w-.]*[A-Za-z0-9]*@[A-Za-z0-9]*([\w-.]*[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	var res=email.test(who);
	return(res);
}

function validate_form(){

err="";

if (emailCheck(document.form1.Email.value) == false){
	err = "Email filed is required!\n";
}

if (err!=""){
	alert (err);
	return false;
}
else{
		return true;
}

}

function CalSingleCottage()
{
	var SingleCottagePerson=document.getElementById("SingleCottagePerson");
	var SingleCottageNights=document.getElementById("SingleCottageNights");
	var SingleCottageTotal=document.getElementById("SingleCottageTotal");
	SingleCottageTotal.value='$'+roundNumber(SingleCottagePerson.value*SingleCottageNights.value*124.99,2);
	CalAllTotals();
}

function CalDoubleCottage()
{
	var DoubleCottagePerson=document.getElementById("DoubleCottagePerson");
	var DoubleCottageNights=document.getElementById("DoubleCottageNights");
	var DoubleCottageTotal=document.getElementById("DoubleCottageTotal");
	DoubleCottageTotal.value='$'+roundNumber(DoubleCottagePerson.value*DoubleCottageNights.value*89.99,2);
	CalAllTotals();
}

function CalTripleCottage()
{
	var TripleCottagePerson=document.getElementById("TripleCottagePerson");
	var TripleCottageNights=document.getElementById("TripleCottageNights");
	var TripleCottageTotal=document.getElementById("TripleCottageTotal");
	TripleCottageTotal.value='$'+roundNumber(TripleCottagePerson.value*TripleCottageNights.value*79.99,2);
	CalAllTotals();
}

function CalLunch()
{
	var Lunch=document.getElementById("Lunch");
	var LunchDays=document.getElementById("LunchDays");
	var LunchTotal=document.getElementById("LunchTotal");
	LunchTotal.value='$'+roundNumber(Lunch.value*LunchDays.value*12,2);
	CalAllTotals();
}

function CalMasseuse()
{
	var Masseuse=document.getElementById("Masseuse");
	var MasseuseDays=document.getElementById("MasseuseDays");
	var MasseuseTotal=document.getElementById("MasseuseTotal");
	MasseuseTotal.value='$'+roundNumber(Masseuse.value*MasseuseDays.value*55,2);
	CalAllTotals();
}

function CalTables()
{
	var Tables=document.getElementById("Tables");
	var IsTables=document.getElementById("IsTables");
	var TablesTotal=document.getElementById("TablesTotal");
	if(IsTables.selectedIndex==0) TablesTotal.value='$'+roundNumber(Tables.value*10,2); else TablesTotal.value='$0';
	CalAllTotals();
}

function CalTV()
{
	var TV=document.getElementById("TV");
	var IsTV=document.getElementById("IsTV");
	var TVTotal=document.getElementById("TVTotal");
	if(IsTV.selectedIndex==0) TVTotal.value='$'+roundNumber(TV.value*75,2); else TVTotal.value='$0';
	CalAllTotals();
}

function CalBigProjector()
{
	var BigProjector=document.getElementById("BigProjector");
	var IsBigProjector=document.getElementById("IsBigProjector");
	var BigProjectorTotal=document.getElementById("BigProjectorTotal");
	if(IsBigProjector.selectedIndex==0) BigProjectorTotal.value='$'+roundNumber(BigProjector.value*45,2); else BigProjectorTotal.value='$0';
	CalAllTotals();
}

function CalSmallProjector()
{
	var SmallProjector=document.getElementById("SmallProjector");
	var IsSmallProjector=document.getElementById("IsSmallProjector");
	var SmallProjectorTotal=document.getElementById("SmallProjectorTotal");
	if(IsSmallProjector.selectedIndex==0) SmallProjectorTotal.value='$'+roundNumber(SmallProjector.value*15,2); else SmallProjectorTotal.value='$0';
	CalAllTotals();
}

function CalCoffieTea()
{
	var CoffieTea=document.getElementById("CoffieTea");
	var IsCoffieTea=document.getElementById("IsCoffieTea");
	var CoffieTeaTotal=document.getElementById("CoffieTeaTotal");
	if(IsCoffieTea.selectedIndex==0) CoffieTeaTotal.value='$'+roundNumber(CoffieTea.value*50,2); else CoffieTeaTotal.value='$0';
	CalAllTotals();
}

function CalCoffieTeaUnder14()
{
	var CoffieTeaUnder14=document.getElementById("CoffieTeaUnder14");
	var IsCoffieTeaUnder14=document.getElementById("IsCoffieTeaUnder14");
	var CoffieTeaUnder14Total=document.getElementById("CoffieTeaUnder14Total");
	if(IsCoffieTeaUnder14.selectedIndex==0) CoffieTeaUnder14Total.value='$'+roundNumber(CoffieTeaUnder14.value*30,2); else CoffieTeaUnder14Total.value='$0';
	CalAllTotals();
}

function CalIsLargeConHall()
{
	var IsLargeConHall=document.getElementById("IsLargeConHall");
	var IsLargeConHall2=document.getElementById("IsLargeConHall2");
	var IsLargeConHallTotal=document.getElementById("IsLargeConHallTotal");
	if(IsLargeConHall.selectedIndex==0) IsLargeConHallTotal.value='$1000'; else IsLargeConHallTotal.value='$0';
	CalAllTotals();
}

function CalIsSmallConHall()
{
	var IsSmallConHall=document.getElementById("IsSmallConHall");
	var IsSmallConHall2=document.getElementById("IsSmallConHall2");
	var IsSmallConHallTotal=document.getElementById("IsSmallConHallTotal");
	if(IsSmallConHall.selectedIndex==0) IsSmallConHallTotal.value='$500'; else IsSmallConHallTotal.value='$0';
	CalAllTotals();
}

function CalIsChapelHill()
{
	var IsChapelHill=document.getElementById("IsChapelHill");
	var IsChapelHill2=document.getElementById("IsChapelHill2");
	var IsChapelHillTotal=document.getElementById("IsChapelHillTotal");
	if(IsChapelHill.selectedIndex==0) IsChapelHillTotal.value='$700'; else IsChapelHillTotal.value='$0';
	CalAllTotals();
}

function CalAllTotals()
{
	
	
	var SingleCottageTotal=document.getElementById("SingleCottageTotal").value;
	SingleCottageTotal=SingleCottageTotal.length==0?0:parseFloat(SingleCottageTotal.substr(1,SingleCottageTotal.length-1));

	var DoubleCottageTotal=document.getElementById("DoubleCottageTotal").value;
	DoubleCottageTotal=DoubleCottageTotal.length==0?0:parseFloat(DoubleCottageTotal.substr(1,DoubleCottageTotal.length-1));

	var TripleCottageTotal=document.getElementById("TripleCottageTotal").value;
	TripleCottageTotal=TripleCottageTotal.length==0?0:parseFloat(TripleCottageTotal.substr(1,TripleCottageTotal.length-1));
	
	
	var LunchTotal=document.getElementById("LunchTotal").value;
	LunchTotal=LunchTotal.length==0?0:parseFloat(LunchTotal.substr(1,LunchTotal.length-1));

	var MasseuseTotal=document.getElementById("MasseuseTotal").value;
	MasseuseTotal=MasseuseTotal.length==0?0:parseFloat(MasseuseTotal.substr(1,MasseuseTotal.length-1));

	
	var TablesTotal=document.getElementById("TablesTotal").value;
	TablesTotal=TablesTotal.length==0?0:parseFloat(TablesTotal.substr(1,TablesTotal.length-1));
	
	
	var TVTotal=document.getElementById("TVTotal").value;
	TVTotal=TVTotal.length==0?0:parseFloat(TVTotal.substr(1,TVTotal.length-1));
	
	var BigProjectorTotal=document.getElementById("BigProjectorTotal").value;
	BigProjectorTotal=BigProjectorTotal.length==0?0:parseFloat(BigProjectorTotal.substr(1,BigProjectorTotal.length-1));

	var SmallProjectorTotal=document.getElementById("SmallProjectorTotal").value;
	SmallProjectorTotal=SmallProjectorTotal.length==0?0:parseFloat(SmallProjectorTotal.substr(1,SmallProjectorTotal.length-1));


	var CoffieTeaTotal=document.getElementById("CoffieTeaTotal").value;
	CoffieTeaTotal=CoffieTeaTotal.length==0?0:parseFloat(CoffieTeaTotal.substr(1,CoffieTeaTotal.length-1));

	var CoffieTeaUnder14Total=document.getElementById("CoffieTeaUnder14Total").value;
	CoffieTeaUnder14Total=CoffieTeaUnder14Total.length==0?0:parseFloat(CoffieTeaUnder14Total.substr(1,CoffieTeaUnder14Total.length-1));

	var IsLargeConHallTotal=document.getElementById("IsLargeConHallTotal").value;
	IsLargeConHallTotal=IsLargeConHallTotal.length==0?0:parseFloat(IsLargeConHallTotal.substr(1,IsLargeConHallTotal.length-1));

	var IsSmallConHallTotal=document.getElementById("IsSmallConHallTotal").value;
	IsSmallConHallTotal=IsSmallConHallTotal.length==0?0:parseFloat(IsSmallConHallTotal.substr(1,IsSmallConHallTotal.length-1));

	var IsChapelHillTotal=document.getElementById("IsChapelHillTotal").value;
	IsChapelHillTotal=IsChapelHillTotal.length==0?0:parseFloat(IsChapelHillTotal.substr(1,IsChapelHillTotal.length-1));


	var SubTotal=SingleCottageTotal+DoubleCottageTotal+TripleCottageTotal;
	SubTotal+=LunchTotal+MasseuseTotal;
	SubTotal+=TablesTotal+TVTotal+BigProjectorTotal+SmallProjectorTotal+CoffieTeaTotal+CoffieTeaUnder14Total;
	SubTotal+=IsLargeConHallTotal+IsSmallConHallTotal+IsChapelHillTotal;

	document.getElementById("SubTotal").value='$'+roundNumber(SubTotal,2);
	document.getElementById("TaxTotal").value='$'+roundNumber(SubTotal*10/100,2);
	document.getElementById("Total").value='$'+roundNumber((SubTotal+(SubTotal*10/100)),2);
	
}