//Basic Form validation for Duest details
function fieldsNotBlank() {
  var f = document.guestList;
//  if((f.Title.options[f.Title.selectedIndex].value!="00" || f.FirstName.value!="" || f.LastName.value!="" || f.invitedTo.options[f.invitedTo.selectedIndex].value!="00") && (f.Title.options[f.Title.selectedIndex].value=="00" || f.FirstName.value=="" || f.LastName.value=="" || f.invitedTo.options[f.invitedTo.selectedIndex].value=="00")){
//	alert("Please enter all details for the first guest");
//	return false;
//  }		
  if((f.TitlePartner.options[f.TitlePartner.selectedIndex].value!="00" || f.FirstNamePartner.value!="" || f.LastNamePartner.value!="" || f.InvitedToPartner.options[f.InvitedToPartner.selectedIndex].value!="00") && (f.TitlePartner.options[f.TitlePartner.selectedIndex].value=="00" || f.FirstNamePartner.value=="" || f.LastNamePartner.value=="" || f.InvitedToPartner.options[f.InvitedToPartner.selectedIndex].value=="00")){
	alert("Please enter all details for the partner or leave them all blank");
	return false;
  }		

	if(document.guestList.Title.options[document.guestList.Title.selectedIndex].value == "00")
	{
		alert("Please choose the Guest Title");
		return false;
	}	
	else if(document.guestList.FirstName.value == "")
	{
		alert("Please enter the Guest First Name");
		return false;
	}
	else if(document.guestList.LastName.value == "")
	{
		alert("Please enter the Guest Last Name");
		return false;
	}
	else if(document.guestList.invitedTo.options[document.guestList.invitedTo.selectedIndex].value == "00")
	{
		alert("Please choose where the Guest is invited to");
		return false;
	}
	else if(document.guestList.FirstNamePartner.value != "")
	{
		if(document.guestList.TitlePartner.value == "00")
		{
			alert("Please select the partners title");
			return false;
		}
		return true;
	}
	
	else if(document.guestList.GuestOf.options[document.guestList.GuestOf.selectedIndex].value == "00")
	{
		alert("Please choose Guest Of");
		return false;
	}
	else
	{
		return true;
	}
	
	return false;
}


function checkField()
{
	if(document.weddingAlbumSearch.albumName.value == "")
	{
		alert("Please enter a search phrase");
		return false;
	}
		
	return true;
}
function checkForgot()
{
	if(document.emailGuest.sendTo.value == "")
	{
		alert("Please enter an email address");
		return false;
	}
		
	return true;
}

//validation for default login
function defaultLogin()
{
	if(document.loginDefault.EmailBox.value=="")
	{
		alert("Please enter an email address to log in with");
		return false;
	}
	if(document.loginDefault.PasswordBox.value=="")
	{
		alert("Please enter a Password");
		return false;
	}
}
//function for sending email
function emailNotBlank()
{
	if(document.list.sendername.value=="")
	{
		alert("Please enter a name to send this email from");
		return false;
	}
	else if(document.list.senderemail.value=="")
	{
		alert("Please enter an email to send this email from");
		return false;
	}
	else if(document.list.subject.value=="")
	{
		alert("Please enter a subject");
		return false;
	}
	else if(document.list.message.value=="")
	{
		alert("Please enter a body for the email");
		return false;
	}	

}
//function for sending email to guests
function sendEmail()
{
	if(document.emailGuest.sendTo.value=="")
	{
		alert("Please enter an email address to send this email to");
		return false;
	}
	else if(document.emailGuest.sendername.value=="")
	{
		alert("Please enter a name to send this email from");
		return false;
	}
	else if(document.emailGuest.senderemail.value=="")
	{
		alert("Please enter an email to send this email from");
		return false;
	}
	else if(document.emailGuest.subject.value=="")
	{
		alert("Please enter a subject");
		return false;
	}
}

//function for sending email to everyone


//Basic Form validation for Guest details
function editGuestNotBlank() {
  var f = document.editGuest;
//  if((f.Title.options[f.Title.selectedIndex].value!="" || f.FirstName.value!="" || f.LastName.value!="" || f.invitedTo.options[f.invitedTo.selectedIndex].value!="") && (f.Title.options[f.Title.selectedIndex].value=="" || f.FirstName.value=="" || f.LastName.value=="" || f.invitedTo.options[f.invitedTo.selectedIndex].value=="")){
//	alert("Please enter all details for the first guest");
//	return false;
//  }		
  if((f.TitlePartner.options[f.TitlePartner.selectedIndex].value!="" || f.FirstNamePartner.value!="" || f.LastNamePartner.value!="" || f.InvitedToPartner.options[f.InvitedToPartner.selectedIndex].value!="") && (f.TitlePartner.options[f.TitlePartner.selectedIndex].value=="" || f.FirstNamePartner.value=="" || f.LastNamePartner.value=="" || f.InvitedToPartner.options[f.InvitedToPartner.selectedIndex].value=="")){
	alert("Please enter all details for the partner or leave them all blank");
	return false;
  }		

	if(document.editGuest.Title.options[document.editGuest.Title.selectedIndex].value == "00")
	{
		alert("Please choose the Guest Title");
		return false;
	}
	else if(document.editGuest.FirstName.value == "")
	{
		alert("Please enter the Guest First Name");
		return false;
	}
	else if(document.editGuest.FirstNamePartner.value != "")
	{	
		
		if(document.editGuest.TitlePartner.value == "")
		{
			alert("Please select the partners title");
			return false;
		}
		return true;
	}
	else if(document.editGuest.LastName.value == "")
	{
		alert("Please enter the Guest Last Name");
		return false;
	}
	else if(document.editGuest.invitedTo.options[document.editGuest.invitedTo.selectedIndex].value == "00")
	{
		alert("Please choose where the Guest is invited to");
		return false;
	}




	else if(document.editGuest.GuestOf.options[document.editGuest.GuestOf.selectedIndex].value == "00")
	{
		alert("Please choose Guest Of");
		return false;
	}
	else
	{
		return true;
	}
	
	return false;
}



//Function to add children form elements depending on the
//number of children specified
function displayChildrenInput()
{
	var noChildren;
		
	noChildren = document.guestList.kids.value;
	
	
	if(isNaN(noChildren) || noChildren == "" || noChildren == 0)
	{
		alert("Please enter a number greater than zero");
	}
	
	else
	{
		var newitem;
		
		newitem = "Child's Full Name(s):";
		newitem += "<img src='/images/spacer.gif' height='1' width='100'>";		
		newitem += "Invited To:<br>";
		
		div = document.getElementById("items");
		//marker=document.getElementById("add");
		span = document.getElementById("replace");
		
		//alert(div.children.length);
		
		for(i=1; i<=noChildren; i++)
		{
			newitem += "<table cellpadding='0' cellspacing='2' width='418'><tr><td width='218'><table width='188' border='0' cellspacing='0' cellpadding='0'>\r\n";
            newitem += "<tr>\r\n";
            newitem += "<td width='6'><img src='/images/forms/input_bg_left.gif' /></td>\r\n";
            newitem += "<td style='background-image:url(/images/forms/input_bg.gif); background-repeat:repeat-x;'><input name='child" + i + "' type='text' class='input-box1' style='width:188px;' id='Address' maxlength='100' /></td>\r\n";
            newitem += "<td width='6'><img src='/images/forms/input_bg_right.gif' /></td>\r\n";
            newitem += "</tr>\r\n";
            newitem += "</table></td>\r\n";
			newitem += "<td width='200'><select name='childSelect" + i + "' style='width:200px' class='normal'>\r\n";
			newitem += "<option selected value='00'>?</option>\r\n";
			newitem += "<option value='Ceremony Only'>Ceremony Only</option>\r\n";
			newitem += "<option value='Reception Only'>Reception Only</option>\r\n";
			newitem += "<option value='Bux Party Only'>Bux Party Only</option>\r\n";
			newitem += "<option value='Hens Party Only'>Hens Party Only</option>\r\n";
			newitem += "<option value='Ceremony / Reception'>Ceremony / Reception</option>\r\n";
			newitem += "<option value='Hens Party / Ceremony / Reception'>Hens Party / Ceremony / Reception</option>\r\n";
			newitem += "<option value='Bux Party / Ceremony / Reception'>Bux Party / Ceremony / Reception</option>\r\n";
			newitem += "</select></td></tr></table>\r\n";
		}
		
		//alert(newitem);
		
		span.innerHTML=newitem;
		
		//div.appendChild(span);
		
		newitem = "";	
	}
}

//Function to add children form elements depending on the
//number of children specified
function editGuestChildren()
{
	var noChildren;
		
	noChildren = document.editGuest.kids.value;
	
	
	if(isNaN(noChildren) || noChildren == "" || noChildren == 0)
	{
		alert("Please enter a number greater than zero");
	}
	
	else
	{
		var newitem;
		
		newitem = "<table class='gray-medium-text' width='100%' border='0' cellpadding='2' cellspacing='0'><tr><td width='36%'>Child's Full Name(s):</td>";
		newitem += "<td width='64%'>Invited To:</td></tr></table>";
		div = document.getElementById("items");
		//marker=document.getElementById("add");
		span = document.getElementById("replace");
		
		//alert(div.children.length);

		for(i=1; i<=noChildren; i++)
		{
			newitem += "<table width='100%' border='0' cellpadding='2' cellspacing='0'>  ";
			newitem += "<tr><td width='36%'><input type='text' class='formbox' name='child" + i + "' maxlength='50'></td> ";
			newitem += "<td width='64%'><select class='formbox' name='childSelect" + i + "'> ";
			newitem += "<option selected value='00'>?</option>";
			newitem += "<option value='Ceremony Only'>Ceremony Only</option>";
			newitem += "<option value='Reception Only'>Reception Only</option>";
			newitem += "<option value='Bux Party Only'>Bux Party Only</option>";
			newitem += "<option value='Hens Party Only'>Hens Party Only</option>";
			newitem += "<option value='Ceremony / Reception'>Ceremony / Reception</option>";
			newitem += "<option value='Hens Party / Ceremony / Reception'>Hens Party / Ceremony / Reception</option>";
			newitem += "<option value='Bux Party / Ceremony / Reception'>Bux Party / Ceremony / Reception</option>";
			newitem += "</select></td></tr></table>";				
		}
		//alert(newitem);		
		span.innerHTML=newitem;		
		//div.appendChild(span);		
		newitem = "";	
	}
}




function hasSelectedGuest(selectGroup)
{
	//check to see if there are tables and or tables
	if(document.seatingPlanForm.elements[selectGroup] == null)
	{
		alert("Please choose a Guest or Table")
		return false;
	}
		
	//Check to see if a Guest is selected
	if(document.seatingPlanForm.elements[selectGroup].selectedIndex < 0)
	{
		alert("Please choose a Guest") 
		return false;
	}
	
	if(document.seatingPlanForm.currentTable.value == "")
	{
		alert("You cannot assign a Guest to a table that does not exist");
		return false;
	}
	
	if(selectGroup == "availableGuests" && document.seatingPlanForm.noRemainingSeats.value == 0)
	{
		alert("You cannot assign any more Guests to this table.\n Please choose another table");
		return false;
	}
	
	return true;	
}

//Check is user has entered a non zero numeric value when creating a table
function hasInputSeats()
{
	if(document.seatingPlanForm.newTableSeats.value == "" || document.seatingPlanForm.newTableSeats.value <= 0 || isNaN(document.seatingPlanForm.newTableSeats.value))
	{
		alert("Please enter the number of seats you require for this table");
		return false;
	}
	
	return true;
}

var i;
	
i = 1;
	
function addAttendants()
{
	var span;
	var newItems;
	var attendantList;
	var strTempItems;
	var name;
	var role;
	var strTempHiddenItemValue;
	var hiddenInput;		
		
	//name = document.weddingPlan.NameBox.value;
	role = document.weddingPlan.Role.options.value;
	name = document.getElementById("NameBox").value;
	var cboRole = document.getElementById("Role");
	var roleIndex = cboRole.selectedIndex;
	role = cboRole.options[roleIndex].value;
	
	if(name == "")
	{
		alert("Please enter a Name");
		return false;
	}
	//replace double quotes with single quotes
	var dubQuot = /\"/g;
	name = name.replace(dubQuot, "'"); 
			
	if(role == "00")
	{
		alert("Please enter a Role for " + name);
		return false;
	}
		
	span = document.getElementById("attendants");
	attendantList = document.getElementById("attendantList");	
	hiddenInput = document.getElementById("hiddenInput");
		
	//alert("here 0");
		
	if(attendantList != null)
	{
		//alert("here 1 if");			
			
		if(hiddenInput != null)
		{
			//alert("here 2 if if");
			strTempItems = attendantList.innerHTML;
			strTempHiddenItemValue = hiddenInput.value;
			
			newItems = "<select id=\"attendantList\" name=\"attendantList\" style=\"width:300px;height:100px\" size=\"5\">\n"
						+ strTempItems
						+ "\n<option id=\"" + name + " - " + role + "\" value=\"" + name + " - " + role + "\">" + name + " - " + role + "</option>"
						+ "\n</select>"
						+ "\n<input type=\"hidden\" id=\"hiddenInput\" name=\"hiddenInput\" value=\"" + strTempHiddenItemValue + "," + name + " - " + role + "\">";
				
			//alert(newItems);
			
			i++;
					
			document.weddingPlan.NameBox.value = "";
			document.weddingPlan.Role.value = "";	
		}
	}
		
	else
	{			
		newItems = "<select id=\"attendantList\" name=\"attendantList\" style=\"width:300px;height:100px\" size=\"5\">"
					+ "\n<option id=\"" + name + " - " + role + "\" value=\"" + name + " - " + role + "\">" + name + " - " + role + "</option>\n"
					+ "</select>\n"
					+ "<input type=\"hidden\" id=\"hiddenInput\" name=\"hiddenInput\" value=\"" + name + " - " + role + "\">";
						
		//alert("here 1 else");
			
		//alert(newItems);
									
		i++;
			
		document.weddingPlan.NameBox.value = "";
		document.weddingPlan.Role.value = "";
	}
		
	span.innerHTML = newItems;
		
	return false;
}
	
function removeAddedAttendant()
{
	var attendantList;
	var hiddenInput;
	var selectedAttendant;
	var selectedAttendantListIndex;
	var nodeToRemove;
	var strTempHiddenItemValue;
	var attendantListLength;
		
	attendantList = document.getElementById("attendantList");	
	hiddenInput = document.getElementById("hiddenInput");
		
	//alert("hello 0");
		
	//alert(attendantList != null);
	//alert(hiddenInput != null); 
		
	if(attendantList != null && hiddenInput != null)
	{
		selectedAttendantListIndex = attendantList.selectedIndex;	
		//alert(selectedAttendantListIndex);
			
		if(selectedAttendantListIndex > -1)
		{
			selectedAttendant = attendantList.options[selectedAttendantListIndex].value;
			strTempHiddenItemValue = "";
				
			//alert(selectedAttendant);
			//alert(strTempHiddenItemValue);				
				
			//nodeToRemove = document.getElementById(selectedAttendant);
			//attendantList.removeChild(nodeToRemove);
			attendantList.remove(selectedAttendantListIndex);
				
			attendantListLength = attendantList.options.length;	
			//alert(attendantListLength);
				
			if(attendantListLength == 0)
			{
				document.getElementById("attendants").innerHTML = "";
			}
				
			else
			{
				if(attendantListLength == 1)
				{
					strTempHiddenItemValue = attendantList.options[0].value;
				}
					
				else
				{
					strTempHiddenItemValue = attendantList.options[0].value;
						
					for(i=1; i<attendantListLength; i++)
					{
						strTempHiddenItemValue += "," + attendantList.options[i].value;
					}
				}
					
				//alert(strTempHiddenItemValue);
					
				hiddenInput.value = strTempHiddenItemValue
			}		
		}
			
		else
		{
			alert("Please choose an Attendant to remove");
		}
	}
		
	else
	{
		alert("No Attendants are avialable");
	}
		
}

function passwordCheck()
{
	if (document.updateWed.NewPasswordBox.value != document.updateWed.VerifyPasswordBox.value)
	{
	    alert("Password entered does not match");
	    return false;
	}
}
function blah()
{	
	
	if(document.addCheck.CheckDescription.value=="")
	{
		alert("Please enter a Description");
		return false;
	}
	else if(document.addCheck.Category.selectedIndex=="00")
	{
		alert("Please enter a Category");
		return false;
	}
}
