function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}


function isValidNumber(theNumber){
	return (!isNaN(parseInt(theNumber))) ? false : true;
} 

function isValidDate(theDate){
	var theCurrentDate = new Date();
	theCurrentMonth = theCurrentDate.getMonth()+1;
	theCurrentDay = theCurrentDate.getDate();
	theCurrentYear = theCurrentDate.getFullYear();
	arvCurrentDate = theCurrentYear+theCurrentMonth+theCurrentDay;

	var theDate = new Date(theDate);
	theMonth = theDate.getMonth()+1;
	theDay = theDate.getDate();
	theYear = theDate.getFullYear();
	arvDate = theYear+theMonth+theDay;

	if (theDate < theCurrentDate){
		return false;
	}else{
		return true;
	}
}

function isValidText(theText){
	str = new String(removeSpaces(theText));
	return (str.length > 0) ? false : true;
}


function validateForm(theForm,thePage){	
	if (thePage == "1"){
		if (theForm.name.value == ""){
			alert ("Please enter a Name.");
			theForm.name.focus();
		}else if (theForm.address.value == ""){
			alert ("Please enter an Address.");
			theForm.address.focus();
		}else if (theForm.contact_number.value == ""){
			alert ("Please enter a Contact Number.");
			theForm.contact_number.focus();
		}else if (theForm.email.value == ""){
			alert ("Please enter an E-mail address.");
			theForm.email.focus();
		}else if(((theForm.email.value.indexOf ("@", 0) == -1) || (theForm.email.value.indexOf (".", 0) == -1))){
			alert("Please enter an E-mail address.");
			theForm.email.focus();
		}else if (theForm.groom_name.value == ""){
			alert ("Please enter the Groom's Name.");
			theForm.groom_name.focus();
		}else if (!isValidDate(theForm.date.value)){
			alert("Are you sure that's the date?");			
		}else if (!isValidDate(theForm.alternateDate.value)){
			alert("Are you sure that's the alternate date?");			
		}else{
			theForm.submit();
		}
	}else if (thePage == "2"){
		if (theForm.manyGuest.value == "" || theForm.manyGuest.value == "0"){
			alert ("Please let us know how many guests will be attending.");
			theForm.manyGuest.focus();
		}else if (theForm.hotelRooms[0].checked && (theForm.manyRooms.value == "" || theForm.manyRooms.value == "0")){
			alert ("Please enter the number of rooms.");
			theForm.manyRooms.focus();		
		}else if (theForm.call.value == ""){
			alert ("Please enter the best time to call you.");
			theForm.call.focus();		
		}else if (!theForm.hear_magazine.checked && !theForm.hear_internet.checked && !theForm.hear_television.checked && !theForm.hear_happy_couple.checked && !theForm.hear_other.checked){
			alert ("Please let us know how you heard about us.");
			theForm.magazine.focus();
		}else{
			theForm.submit();
		}

	}else if (thePage == "test1"){
		if (isValidText(theForm.bridename.value)){
			alert ("Please enter the Bride's name.");
			theForm.bridename.value = "";
			theForm.bridename.focus();
		}else if (isValidText(theForm.address.value)){
			alert ("Please enter an address.");
			theForm.address.value = "";
			theForm.address.focus();
		}else if (isValidText(theForm.contactnum.value)){
			alert ("Please enter a contact number.");
			theForm.contactnum.value = "";
			theForm.contactnum.focus();
		}else if (isValidNumber(theForm.contactnum.value)){
			alert ("Please enter a contact number.");
			theForm.contactnum.value = "";
			theForm.contactnum.focus();
		}else if (isValidText(theForm.email.value)){
			theForm.email.value = "";
			alert ("Please enter an E-mail address.");
			theForm.email.focus();
		}else if(((theForm.email.value.indexOf ("@", 0) == -1) || (theForm.email.value.indexOf (".", 0) == -1))){
			alert("Please enter an E-mail address.");
			theForm.email.value = "";
			theForm.email.focus();
		}else if (isValidText(theForm.groom_name.value)){
			theForm.groom_name.value = "";
			alert ("Please enter the Groom's name.");
			theForm.groom_name.focus();
		}else if (!isValidDate(theForm.date.value)){
			alert("Are you sure that's the date?");			
		}else if (!isValidDate(theForm.altdate.value)){
			alert("Are you sure that's the alternate date?");			
		}else{
			theForm.submit();
		}
	}else if (thePage == "test2" || thePage == "test2_end"){
		if (theForm.numguests.value == "" || theForm.numguests.value == "0"){
			alert ("Please enter the Number of Guests Attending.");
			theForm.numguests.focus();
		}else if (theForm.hotelinterest[0].checked && (theForm.numrooms.value == "" || theForm.numrooms.value == "0")){
			alert ("Please enter the Number of Rooms.");
			theForm.numrooms.focus();		
		}else if (theForm.timetocall.value == ""){
			alert ("Please enter the Best Time to Call.");
			theForm.timetocall.focus();		
		}else if (!theForm.hearmagazine.checked && !theForm.hearnet.checked && !theForm.heartelevision.checked && !theForm.hearanothercouple.checked && !theForm.heartheweddinggods.checked){
			alert ("Please let us know how you heard about us.");
			theForm.hearmagazine.focus();
		}else{
			if (thePage == "test2_end"){
				theForm.action = "sendEmail.php";
			}
			theForm.submit();
		}


	}else if (thePage == "3"){
		if (isValidText(theForm.when.value)){
			theForm.when.value = "";
			alert ("Please tell us When You Got Engaged.");
			theForm.when.focus();
		}else{
			theForm.submit();
		}
	}else if (thePage == "4"){
		if (!theForm.optDayDamsels[0].checked && !theForm.optDayDamsels[1].checked && !theForm.optDayDamsels[2].checked && !theForm.optDayDamsels[3].checked){
			alert ("Please select an option (Damsels - Day)");
		}else if (!theForm.optDayBlokes[0].checked && !theForm.optDayBlokes[1].checked && !theForm.optDayBlokes[2].checked && !theForm.optDayBlokes[3].checked){
			alert ("Please select an option (Blokes - Day)");
		}else if (!theForm.optNightDamsels[0].checked && !theForm.optNightDamsels[1].checked && !theForm.optNightDamsels[2].checked){
			alert ("Please select an option (Damsels - Night)");
		}else if (!theForm.optNightBlokes[0].checked && !theForm.optNightBlokes[1].checked && !theForm.optNightBlokes[2].checked){
			alert ("Please select an option (Blokes - Night)");
		}else{
			theForm.submit();
		}
	}else if (thePage == "5"){
		if (!theForm.optMorningDamsels[0].checked && !theForm.optMorningDamsels[1].checked){
			alert ("Please select an option (Damsels - Morning)");
		}else if (!theForm.optMorningBlokes[0].checked && !theForm.optMorningBlokes[1].checked){
			alert ("Please select an option (Blokes - Morning)");
		}else if (!theForm.optAfternoon[0].checked && !theForm.optAfternoon[1].checked && !theForm.optAfternoon[2].checked && !theForm.optAfternoon[3].checked){
			alert ("Please select an option (Afternoon)");
		}else if (!theForm.optEvening[0].checked && !theForm.optEvening[1].checked){
			alert ("Please select an option (Evening)");
		}else{
			theForm.submit();
		}
	}else if (thePage == "6"){
		if (!theForm.optMorningDamsels.checked){
			alert ("Please select an option (Damsels - Morning)");
		}else if (!theForm.optMorningBlokes[0].checked && !theForm.optMorningBlokes[1].checked){
			alert ("Please select an option (Blokes - Morning)");
		}else if (!theForm.optFrolic[0].checked && !theForm.optFrolic[1].checked && !theForm.optFrolic[2].checked && !theForm.optFrolic[3].checked){
			alert ("Please select an option (The Frolic)");
		}else{
			theForm.submit();
		}
	}else if (thePage == "7"){
		if (!theForm.optGoodbye[0].checked && !theForm.optGoodbye[1].checked && !theForm.optGoodbye[2].checked){
			alert ("Please select an option");
		}else{
			theForm.submit();
		}

	}
}