function formatCurrency(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)?'':'-') + num + '.' + cents);
}

function update()
{
	document.form1.outoftownfee.value = formatCurrency(document.form1.outoftownfee.value);
	document.form1.downpayment.value = formatCurrency(document.form1.downpayment.value);
}

function updateServiceTime()
{
	document.form1.servicestarthour.value = document.form1.eventhour.value;
	document.form1.servicestartminute.value = document.form1.eventminute.value;
	document.form1.servicestartam.value = document.form1.eventam.value;
	addServiceHours();
}

function addServiceHours()
{
	var packageHours;
	var hour = parseInt(document.form1.servicestarthour.value);
	if (hour == 0)
		hour += 12;

	for (var i=0; i<document.form1.package.length; i++)
		if (document.form1.package[i].checked)
			switch(document.form1.package[i].value)
			{
				case 'lite': packageHours = 2; break;
				case 'standard': packageHours = 3; break;
				case 'premium': packageHours = 4; break;
				case 'express': packageHours = 2; break;
				default: packageHours = 0;
			}
	document.form1.serviceendam.value = document.form1.servicestartam.value;		
	hour += packageHours;
	if (hour > 12)
	{
		document.form1.serviceendhour.value = hour - 12;
		
		if (document.form1.serviceendam.value == '0')
			document.form1.serviceendam.value = '12';
		else
			document.form1.serviceendam.value = '0';
	}
	else if (hour == 12)
	{
		document.form1.serviceendhour.value = 0;
		
		if (document.form1.serviceendam.value == '0')
			document.form1.serviceendam.value = '12';
		else
			document.form1.serviceendam.value = '0';
	}
	
	else
		document.form1.serviceendhour.value = hour;


	document.form1.serviceendminute.value = document.form1.servicestartminute.value;

}


function isValidEmail(str)
{
	return (str.lastIndexOf(".") > 2) && (str.indexOf("@") > 0) && (str.lastIndexOf(".") > (str.indexOf("@")+1)) && (str.indexOf("@") == str.lastIndexOf("@"));
}

function isChecked()
{
	
	if (whichStep != 5)
	{
		switchStep(whichStep + 1);
		return false;
	}
	else
	
	{	if (!document.form1.checkbox1.checked)
		{

				alert("Sorry, we require that you agree to the terms and conditions before we accept your reservation.");
				document.form1.checkbox1.focus();
				return false;
				javascript:switchStep(5);
				document.getElementById("agree-label").style.color="#9a0000";				
		}
		else if (document.form1.venue.value==-2)
		{
				if (document.form1.venueother.value == "")
				{
					alert("Missing required field: Other Venue.");
					return false;
					javascript:switchStep(2);
					document.getElementById("venue-label").style.color="#9a0000";	
				}		
		}
		else if (document.form1.contactperson.value==-2)
		{
				alert("contact");
				if (document.form1.coordinatorother.value == "")
				{
					alert("Missing required field: Other Coordinator.");
					return false;
					javascript:switchStep(2);
					document.getElementById("contactperson-label").style.color="#9a0000";
				}			
		}
		else if (document.form1.firstname.value == "")
		{
				alert("Missing required field: First name.");
				javascript:switchStep(1);
				document.form1.firstname.focus();
				return false;
				document.getElementById("firstname").style.color="#9a0000";
				document.getElementById("firstname-label").style.borderColor="#9a0000";
		}
		else if (document.form1.lastname.value == "")
		{
				alert("Missing required field: Last name.");
				javascript:switchStep(1);
				document.form1.lastname.focus();
				return false;
				document.getElementById("lastname").style.color="#9a0000";
				document.getElementById("lastname-label").style.borderColor="#9a0000";	

		}
		else if (document.form1.email.value == "")
		{
				alert("Missing required field: Email.");
				javascript:switchStep(1);
				document.form1.email.focus();
				return false;
				document.getElementById("email").style.color="#9a0000";
				document.getElementById("email-label").style.borderColor="#9a0000";
		}
		else if (document.form1.contactnumber.value == "")
		{
				alert("Missing required field: Contact number.");
				javascript:switchStep(1);
				document.form1.contactnumber.focus();
				return false;
				document.getElementById("contactnumber").style.color="#9a0000";
				document.getElementById("contactnumber-label").style.borderColor="#9a0000";
		}
		else if (document.form1.venue.value == "")
		{
				alert("Missing required field: Venue.");
				javascript:switchStep(2);
				document.form1.venue.focus();
				return false;				
				document.getElementById("venue").style.color="#9a0000";
				document.getElementById("venue-label").style.borderColor="#9a0000";

		}
		else if (!isValidEmail(document.form1.email.value))
		{
				alert("Invalid email address.");
				javascript:switchStep(1);
				document.form1.email.focus();
				return false;				
				document.getElementById("email").style.color="#9a0000";
				document.getElementById("email-label").style.borderColor="#9a0000";
		}
		else
			return true;
	}
		
}

function eventtitle()
{
	document.form1.eventtitle.value = "";
	//document.form1.eventtitle.class = "regular";
}
function changeTitle()
{
	var eventtype = document.form1.eventtype.value;
	if (eventtype == "wedding")
		document.form1.eventtitle.value = "Bailon-Hudson Nuptials";
	else if (eventtype == "debut")
		document.form1.eventtitle.value = "Gaby turns 18";
	else if (eventtype == "birthday")
		document.form1.eventtitle.value = "Raf's 6th Birthday";
	else if (eventtype == "anniversary")
		document.form1.eventtitle.value = "John and Jackie's 20th Wedding Anniversary";
	else if (eventtype == "corporate event")
			document.form1.eventtitle.value = "baiCapture's Photo Booth Expo";
	else if (eventtype == "other")
		document.form1.eventtitle.value = "It's an event!";
}

var whichStep = 1;
function switchStep(step)
{
	Effect.Appear('step'+step, { duration: 1.0 });	
	
	for (var i=1;i<=5;i++)
	if (i != step)
		Effect.Fade('step'+i, { duration:0.1 });
	whichStep = step;
	
	document.getElementById("progressbar").src = "http://baicapture.com/static/img/step"+step+".png";
}