//******************************************************************
function validate() 
{
	//Validates that required fields are present
	var arE=new Array();
	var f=document.thisForm;
	var cnt=f.length;
	var msg, emptyfields;
	var arvday,arvmonth,arvyear,arvdate,today;
	var arArrivalDate;
	var fchk=-1;
	
	//Check the ArrivalDate if present
	if ( ! isblank(f.ArrivalDate.value)) {
		arArrivalDate=f.ArrivalDate.value.split('/')
		if (arArrivalDate.length == 3) {
			arvmonth=arArrivalDate[0];
			arvday=arArrivalDate[1];
			arvyear=arArrivalDate[2];
			arvdate=arvyear + "/" + arvmonth + "/" + arvday;
		}
		//Check the ArrivalDate field for valid date
		if (isDate(arvdate) != true){
			msg="The data was not submitted because the Arrival Date\n";
			msg=msg + f.ArrivalDate.value + " is not a valid date.";
			alert(msg);
			f.ArrivalDate.focus();
			return(false);
		}
		//Check that Date is not in Past
		arvdate=new Date(arvyear,arvmonth-1,arvday,23,59,59)
		today=new Date()		
		if (arvdate < today){
			alert("Your arrival date is in the past.");
			f.ArrivalDate.focus();
			return(false);
		}
	
	}	
	
	
	emptyfields="";
	//Ensure required text fields are completed ( _ prefix)
	for(var i=0; i < cnt; i++) { 
		if (f.elements[i].type=="text")
			if (f.elements[i].name.substr(0,1)=="_" && isblank(f.elements[i].value))
				emptyfields=emptyfields + "\n     " + f.elements[i].name.substr(1);
	}
	
	
	if (emptyfields != "") {
		msg="The data was not submitted because the following\n";
		msg=msg+"required fields were not supplied:\n" + emptyfields;
		alert(msg);
		return(false);
	}
		
	//Ensure valid email
	if (isEmail(f._Email.value) != true) {
		msg="The data was not submitted because the Email\n";
		msg=msg + "address you entered is not valid.";
		alert(msg);
		f._Email.focus();
		return(false);
	}
	
	//Check that at least one Item is checked
	for(var i=0; i < cnt; i++) {
		//Check the checkboxes
		if (f.elements[i].name.substr(0,3)=="chk")	
			if (f.elements[i].checked==true){
				fchk=i; 
				break;
			}
	}
	if(fchk < 0 ){
		alert("You did not select an Activity.");
		return(false);
	}
	
	
}	
//**********************************************************************
function isblank(s)
{
	for(var i=0; i < s.length; i++) {
		var c=s.charAt(i);
		if ((c != ' ' ) && (c != '\n') && (c != '\t' )) return false;
	}
	return true;	
}
//**********************************************************************
function isEmail(s)

// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
{   
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

	
//**********************************************************************
function isDate(mydate)

// mydate is a string in yyyy/mm/dd format
// returns True if s is a valid date

{   
    ar=mydate.split("/");
    //30 Day Months
    if ((ar[1]==4 || ar[1]==6 || ar[1]==9 || ar[1]==11) && ar[2] > 30)
			return(false);
    //Feb non-leap
    if (ar[1]==2 && ((ar[0] % 4 !=0) || (ar[0] % 4 == 0 && ar[0] % 100 == 0 && ar[0] % 400 ==0)) && ar[2] > 28)
			return(false);
    //Feb leap year
    if (ar[1]==2 && ar[2] > 29)
			return(false);
    if (ar[2] > 31)
			return(false);
    if (ar[1] > 12)
			return(false);
    else
			return(true);
}

//**********************************************************************






