function SetXMLDate(strField){

	var arrDate;
	var strReservationDate;

	arrDate = document.PSForm.elements[strField+'Month'].options[document.PSForm.elements[strField+'Month'].selectedIndex].value.split("/");
	strReservationDate = arrDate[0]+"/"+document.PSForm.elements[strField+'Day'].options[document.PSForm.elements[strField+'Day'].selectedIndex].value+"/"+arrDate[1];
	document.PSForm.elements[strField].value = strReservationDate;
}

function sGo(input) {
	var submit = validateForm();

	if (submit == true)
	{
		document.PSForm.wassub.value = 1 ;
		document.PSForm.submit();
	}

}

function SetCheckOutDate(objForm) {
	var arrMonthYear = objForm.elements['CheckinDateMonth'].options[objForm.elements['CheckinDateMonth'].selectedIndex].value.split("/");
	var strMonth = arrMonthYear[0];
	var strDay = objForm.elements['CheckinDateDay'].options[objForm.elements['CheckinDateDay'].selectedIndex].value
	var strYear = arrMonthYear[1];
	var dtmCheckIn = new Date();
	var blnDateLimit = false;

	dtmCheckIn.setMonth(strMonth-1);
	dtmCheckIn.setDate(strDay);
	dtmCheckIn.setYear(strYear);

	dtmCheckIn.setTime(dtmCheckIn.getTime());
	if (dtmCheckIn.getMonth() != (strMonth - 1)) {
		dtmCheckIn.setDate(1);
		if (objForm.elements['CheckinDateMonth'].selectedIndex < (objForm.elements['CheckoutDateMonth'].length-1)) {
			objForm.elements['CheckoutDateMonth'].selectedIndex= objForm.elements['CheckinDateMonth'].selectedIndex;
		} else {
			objForm.elements['CheckoutDateMonth'].selectedIndex= objForm.elements['CheckinDateMonth'].selectedIndex;
			blnDateLimit = true;
		}
	} else {
		objForm.elements['CheckoutDateMonth'].selectedIndex= objForm.elements['CheckinDateMonth'].selectedIndex;
	}

	if (blnDateLimit) {
		objForm.elements['CheckoutDateDay'].selectedIndex = objForm.elements['CheckinDateDay'].selectedIndex;
	} else {
		objForm.elements['CheckoutDateDay'].selectedIndex = (dtmCheckIn.getDate()-1);
	}
}

function CheckAccess(field){
	nIndex=field.selectedIndex;
	nAccessPoint=field.options[nIndex].value;

	if (nAccessPoint==0){
		document.PSForm.LaunchPointID.length=0;
		document.PSForm.LaunchPointID.options[0] = new Option('',0);
		for (var i=0; i< avAccessPoints.length; i++){
			if (avAccessPoints[i].launchpoint==1){
			 	if (avAccessPoints[i].recommended==1){
					nIndex=document.PSForm.LaunchPointID.options.length;
					document.PSForm.LaunchPointID.options[nIndex]=new Option(avAccessPoints[i].name + " (" + avAccessPoints[i].segmentname + ")", avAccessPoints[i].accessid);
					/*if (avAccessPoints[i].passage ==1){	document.PSForm.LaunchPointID.options[nIndex].style.backgroundColor = "#ffcc33" ;
					}
					else*/ if (avAccessPoints[i].restricted ==1){	document.PSForm.LaunchPointID.options[nIndex].style.backgroundColor = "#ff9999" ;
					}
					else { 				document.PSForm.LaunchPointID.options[nIndex].style.backgroundColor = "#00ff99" ;
					}
				}
			}
		}
		document.PSForm.TakeoutPointID.length=0;
		document.PSForm.TakeoutPointID.options[0] = new Option('',0);
		for (var i=0; i< avAccessPoints.length; i++){
			if (avAccessPoints[i].launchpoint==0){
				if (avAccessPoints[i].recommended==1){
					nIndex=document.PSForm.TakeoutPointID.options.length;
					document.PSForm.TakeoutPointID.options[nIndex]=new Option(avAccessPoints[i].name + " (" + avAccessPoints[i].segmentname + ")", avAccessPoints[i].accessid);
					/*if (avAccessPoints[i].passage ==1){ document.PSForm.TakeoutPointID.options[nIndex].style.backgroundColor = "#ffcc33" ;
					}
					else*/ if (avAccessPoints[i].restricted ==1){	document.PSForm.TakeoutPointID.options[nIndex].style.backgroundColor = "#ff9999" ;
					}
					else { 				document.PSForm.TakeoutPointID.options[nIndex].style.backgroundColor = "#00ff99" ;
					}
				}
			}
		}
	}
}
function isEmpty(inputStr){
	if (inputStr==null || inputStr==""){
			return true
	}
	return false	
}

function validateForm() {

	SetXMLDate('CheckinDate');
	SetXMLDate('CheckoutDate');
	var mxdys = 7 ;
	var clerk = valvclerk() ;
	if (clerk == false) {
		return clerk;
	}
	var validatepass = valpass() ;
	//alert(validatepass);
	var enfrcpast = true ;
	if (validatepass == false) {
		return validatepass;
	}
	else if (validatepass === undefined) {
		enfrcpast = false ;
	}
	
	if (document.PSForm.LaunchPointID.value==0){
		alert("You must enter a Launch Point.")
		document.PSForm.LaunchPointID.focus()
		return false
	}

	if (document.PSForm.TakeoutPointID.value==0){
		alert("You must enter a Takeout Point.")
		document.PSForm.TakeoutPointID.focus()
		return false
	}

	if (! isDate(document.PSForm.elements['CheckinDate'].value)){
		return false;
	}
	if (! isDate(document.PSForm.elements['CheckoutDate'].value)){
		return false;
	}
	var oneDay= 1000 * 60 * 60 * 24;
	var checkout=new Date(document.PSForm.elements['CheckoutDate'].value);
	var checkin=new Date(document.PSForm.elements['CheckinDate'].value);
	var today=new Date();
	var todayDate=new Date(today.getFullYear(),today.getMonth(),today.getDate())
	//alert(enfrcpast +" /n" + checkin.getTime()-todayDate.getTime())
	if (checkin.getTime()-todayDate.getTime() < 0  && enfrcpast){
		alert("Trip Start Date must be greater than or equal to today!");
		document.PSForm.CheckinDateDay.focus();
		return false;
	}
	if (checkout.getTime()-checkin.getTime() < 0 ){
		alert("Trip End Date must be greater than or equal to the Trip Start Date!");
		document.PSForm.CheckoutDateDay.focus();
		return false;
	}
	if (checkout.getTime()-checkin.getTime() > (mxdys-1) * oneDay){
		alert("Maximum trip duration is " +mxdys+" days!");
		document.PSForm.CheckoutDateDay.focus();
		return false;
	}
	/* guide ID selection drop down replaced the guide name input box 7/7/2008
	if (! document.PSForm.Guided[1].checked) {
		var inputstr=document.PSForm.GuideName1.value
		if (inputstr.length > 0){
			alert("Is this trip Guided? If not, do not enter a Guide Name.");
			return false;
		}
	}
	if (document.PSForm.Guided[1].checked) {
		if (isEmpty(document.PSForm.GuideName1.value)){
			alert("The Guide Name is required if this is a guided trip.")
			document.PSForm.GuideName1.focus()
			document.PSForm.GuideName1.select()
			return false
		}
	}*/
	if (! document.PSForm.Guided[1].checked) {
		if (document.PSForm.GuideID.selectedIndex > 0){
			alert("Is this trip Guided? If not, do not enter a Guide Name.");
			return false;
		}
	}
	if (document.PSForm.Guided[1].checked) {
		if (document.PSForm.GuideID.selectedIndex == 0){
			alert("The Guide Name is required if this is a guided trip.");
			document.PSForm.GuideID.focus();
			return false;
		}
	}
	if (isEmpty(document.PSForm.FirstName.value)){
		alert("You must enter the Group Leader's First Name.")
		document.PSForm.FirstName.focus()
		document.PSForm.FirstName.select()
		return false
	}
	if (isEmpty(document.PSForm.LastName.value)){
		alert("You must enter the Group Leader's Last Name.")
		document.PSForm.LastName.focus()
		document.PSForm.LastName.select()
		return false
	}
	if (isEmpty(document.PSForm.DateofBirth.value)){
		alert("You must enter the Group Leader's Date of Birth.")
		document.PSForm.DateofBirth.focus()
		document.PSForm.DateofBirth.select()
		return false
	}
	if (! isDate(document.PSForm.DateofBirth.value)){
		alert("The Group Leader's Date of Birth must be in the form mm/dd/yyyy.")
		document.PSForm.DateofBirth.focus()
		document.PSForm.DateofBirth.select()
		return false
	}
	var DateofBirth=new Date(document.PSForm.DateofBirth.value);
	var thisYear=DateofBirth.getFullYear();
	if (thisYear < 0 || (thisYear >100 && thisYear < 1900)){
		alert("The Group Leader's Date of Birth is incorrect.")
		document.PSForm.DateofBirth.focus()
		document.PSForm.DateofBirth.select()
		return false
	}	
	if (isEmpty(document.PSForm.Address1.value)){
		alert("You must enter the Group Leader's Mailing Address.")
		document.PSForm.Address1.focus()
		document.PSForm.Address1.select()
		return false
	}
	if (isEmpty(document.PSForm.City.value)){
		alert("You must enter the Group Leader's Mailing City.")
		document.PSForm.City.focus()
		document.PSForm.City.select()
		return false
	}
	if (isEmpty(document.PSForm.ZipCode.value)){
		alert("You must enter the Group Leader's Zip Code.")
		document.PSForm.ZipCode.focus()
		document.PSForm.ZipCode.select()
		return false
	}
	var strZipCode;
	var oneChar;
	strZipCode=document.PSForm.ZipCode.value;
	/*for (var i=0; i < strZipCode.length; i++){
		oneChar=strZipCode.charAt(i)
		if (i==5 && oneChar=="-"){
			continue
		}
		if (oneChar < "0" || oneChar > "9"){
			alert("The Group Leader's Zip Code is invalid.")
			document.PSForm.ZipCode.focus()
			document.PSForm.ZipCode.select()
			return false
		}	
	}
	if (strZipCode.length < 5){
		alert("The Group Leader's Zip Code is invalid.")
		document.PSForm.ZipCode.focus()
		document.PSForm.ZipCode.select()
		return false
	}
	if (strZipCode.length > 5){
		if (strZipCode.length < 10){
			alert("The Group Leader's Zip Code is invalid.")
			document.PSForm.ZipCode.focus()
			document.PSForm.ZipCode.select()
			return false
		}	
	}	*/
	if (! isEmpty(document.PSForm.AltFirstName.value)){
	if (isEmpty(document.PSForm.AltFirstName.value)){
		alert("You must enter the Alternate Leader's First Name.")
		document.PSForm.AltFirstName.focus()
		document.PSForm.AltFirstName.select()
		return false
	}
	if (isEmpty(document.PSForm.AltLastName.value)){
		alert("You must enter the Alternate Leader's Last Name.")
		document.PSForm.AltLastName.focus()
		document.PSForm.AltLastName.select()
		return false
	}
	if (isEmpty(document.PSForm.AltDateofBirth.value)){
		alert("You must enter the Alternate Leader's Date of Birth.")
		document.PSForm.AltDateofBirth.focus()
		document.PSForm.AltDateofBirth.select()
		return false
	}
	if (! isDate(document.PSForm.AltDateofBirth.value)){
		alert("The Alternate Leader's Date of Birth must be in the form mm/dd/yyyy.")
		document.PSForm.AltDateofBirth.focus()
		document.PSForm.AltDateofBirth.select()
		return false
	}
	DateofBirth=new Date(document.PSForm.AltDateofBirth.value);
	thisYear=DateofBirth.getFullYear();
	if (thisYear < 0 || (thisYear >100 && thisYear < 1900)){
		alert("The Alternate Leader's Date of Birth is incorrect.")
		document.PSForm.AltDateofBirth.focus()
		document.PSForm.AltDateofBirth.select()
		return false
	}	
	if (isEmpty(document.PSForm.AltAddress1.value)){
		alert("You must enter the Alternate Leader's Mailing Address.")
		document.PSForm.AltAddress1.focus()
		document.PSForm.AltAddress1.select()
		return false
	}
	if (isEmpty(document.PSForm.AltCity.value)){
		alert("You must enter the Alternate Leader's Mailing City.")
		document.PSForm.AltCity.focus()
		document.PSForm.AltCity.select()
		return false
	}
	if (isEmpty(document.PSForm.AltZipCode.value)){
		alert("You must enter the Alternate Leader's Zip Code.")
		document.PSForm.AltZipCode.focus()
		document.PSForm.AltZipCode.select()
		return false
	}
	/*strZipCode=document.PSForm.AltZipCode.value;
	for (var i=0; i < strZipCode.length; i++){
		oneChar=strZipCode.charAt(i)
		if (i==5 && oneChar=="-"){
			continue
		}
		if (oneChar < "0" || oneChar > "9"){
			alert("The Alternate Leader's Zip Code is invalid.")
			document.PSForm.AltZipCode.focus()
			document.PSForm.AltZipCode.select()
			return false
		}	
	}
	if (strZipCode.length < 5){
		alert("The Alternate Leader's Zip Code is invalid.")
		document.PSForm.AltZipCode.focus()
		document.PSForm.AltZipCode.select()
		return false
	}
	if (strZipCode.length > 5){
		if (strZipCode.length < 10){
			alert("The Alternate Leader's Zip Code is invalid.")
			document.PSForm.AltZipCode.focus()
			document.PSForm.AltZipCode.select()
			return false
		}	
	}	*/
	}
	return valExtraAlts() ;
}
