function groupvalidate()
{
	//check if the group name is entered
	if (checkFieldBlank(document.grouptripform.gName.value) == false)
	{
		alert("Please enter the Group Name and then click Get Quote.");
		return false;
	}


	//check if destination is entered
	if ((checkFieldBlank(document.grouptripform.gDestination.value) == false) )
	{
		alert("Please enter the Destination and then click Get Quote.");
		return false;
	}
	
	//check if mail id is valid
	checkEmail = document.grouptripform.gMail.value;
	if ((checkEmail.indexOf('@') < 0) || 
	((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
	{
		isEmailValid(document.grouptripform.gMail.value);
		//alert('Please enter a valid email address to help us contact you!');
		document.grouptripform.gMail.focus();
		return false;
	}
	
	//check that selected Departure date is valid
	 if (!validdate( document.grouptripform.gDepartureDay.value, document.grouptripform.gDepartureMonth.value-1, document.grouptripform.gDepartureYear.value))
	 {
		return false;
	 }

	//check that selected Return date is valid
	 if (!validdate( document.grouptripform.gReturnDay.value, document.grouptripform.gReturnMonth.value-1, document.grouptripform.gReturnYear.value))
	 {
		return false;
	 }

	//check that selected Initial Payment date is valid
	 if (!validdate(document.grouptripform.gInitialDay.value, document.grouptripform.gInitialMonth.value-1, document.grouptripform.gInitialYear.value))
	 {
		return false;
	 }

	//check that selected Final Payment date is valid	 
	 if (!validdate(document.grouptripform.gFinalDay.value, document.grouptripform.gFinalMonth.value-1, document.grouptripform.gFinalYear.value))
	 {
		return false;
	 }

	//check that the departure date is a week away from today
	var today=new Date()
	var departureDate=new Date(document.grouptripform.gDepartureYear.value, document.grouptripform.gDepartureMonth.value, document.grouptripform.gDepartureDay.value)
	if (today.getTime() >=departureDate.getTime())
	{
		alert("The departure date has to be atleast a week from today. Please reselect the date and click Get Quote.");
		return false;
	 }

	//check that the return date is after the departure date
	var depDate=new Date(document.grouptripform.gDepartureYear.value, document.grouptripform.gDepartureMonth.value, document.grouptripform.gDepartureDay.value)
	var retDate=new Date(document.grouptripform.gReturnYear.value, document.grouptripform.gReturnMonth.value, document.grouptripform.gReturnDay.value)
	if (depDate.getTime()>=retDate.getTime())
	{
		alert("The return date has to be after the departure date. Please reselect the dates and click Get Quote.");
		return false;
	 }
	 
	//check that the final trip payment date is after the initial trip payment date
	var initialPaymentDate=new Date(document.grouptripform.gInitialYear.value, document.grouptripform.gInitialMonth.value, document.grouptripform.gInitialDay.value)
	var finalPaymentDate=new Date(document.grouptripform.gFinalYear.value, document.grouptripform.gFinalMonth.value, document.grouptripform.gFinalDay.value)
	if (initialPaymentDate.getTime()>=finalPaymentDate.getTime())
	{
		alert("The final payment date has to be after the initial payment date. Please reselect the dates and click Get Quote.");
		return false;
	 }

	if (validEffectiveDate())
	{document.grouptripform.submit();}
	else
		return;
}


function checkFieldBlank(field) 
{
	if (field == "") {return false;}
	else { return true;};
}

function isEmailValid(email) 
{ 
    	alert("Please enter a valid email address to help us contact you!");
    return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email); 

} 
//This function is copyrighted to http://www.aspdev.org/javascript/javascript-trim/
function trimAll(sString)
{
	if (sString.length == 0) return sString;
	while(sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while(sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function validEffectiveDate()
{
	var frmdd = document.grouptripform.gDepartureDay.value;
	var frmmm = document.grouptripform.gDepartureMonth.selectedIndex + 1;
	var frmyy = document.grouptripform.gDepartureYear.value;

	if(validdate(frmdd,frmmm,frmyy)==false)
	{
		alert('Please enter a valid Date');
		return false;
	}

	var effectiveDate = new Date();
	effectiveDate.setFullYear(frmyy, frmmm, frmdd);
	
	var today = new Date();
	today.setFullYear(new Date().getFullYear());

	if(effectiveDate < today )
	{
		alert("Departure date cannot be less than today's date.");
		return false;
	}
	return true;
}