
function validateQuoteControl() {
	var bolSubmit = true;

	//Get DIVs for Valiation Error Messages
	var destValidator = document.getElementById('validateDestinationGateway');
	var dateValidator = document.getElementById('validateDepartureDate');
	var childValidator = document.getElementById('validateChildAges');
	var emailValidator = document.getElementById('validateEmailAddress');

	//Test for Chosen Destination
	var destination = document.getElementById('ctl00_cph1_Inc_iq1_destination');
	if (destination.options[destination.selectedIndex].value == 0) {
		destValidator.style.display = 'inline';
		bolSubmit = false;	
	}
	else{destValidator.style.display = 'none'}

	//=============================================================================
	
	//Test for Valid Depart Date
	var departDate = document.getElementById('ctl00_cph1_Inc_iq1_date_input1').value;
	var errorText = '';
	var b = isDate(departDate);
	var s = 0;

	if (b) {
		//s = isValidDate(departDate);
		d = dateDiff('d', Date(), departDate, 1, 1);
		
		if (d <= 0) {s = 1;}
		if (d < 3) {s = 2;}
		if (d > 331) {s = 3;}

		switch (s) {
			case 1:
			//In the past (< today)
			errorText = 'Date must be in the future!';
			break;
			case 2:
			//Too short (today -> today + 3)
			errorText = 'Date must be atleast 3 days away.';
			break;
			case 3:
			//Too Far (today + 331)
			errorText = 'Date can not be more than 331 days away.';
			break;
		}
	}

	if (b && s > 0) {
		dateValidator.innerHTML = errorText;
		dateValidator.style.display = 'inline';
		bolSubmit = false;	
	}
	else if (!b) {
		dateValidator.innerHTML = 'Enter a valid Date!';
		dateValidator.style.display = 'inline';
		bolSubmit = false;
	}		
	else{dateValidator.style.display = 'none';}
	
	//=============================================================================
	
	//Test that Ages are specified for Children if Children > 0
	var childCount = parseInt(document.getElementById('ctl00_cph1_Inc_iq1_childrenNum').value);

	var childError = false;
	var childAge1 = parseInt(document.getElementById('ctl00_cph1_Inc_iq1_child11').selectedIndex);
	var childAge2 = parseInt(document.getElementById('ctl00_cph1_Inc_iq1_child21').selectedIndex);
	
	if (childCount > 0){
		switch (childCount){
			case 1:
				if (childAge1 == 0){childError=true;}
				break;
			case 2:
				if (childAge1 == 0 || childAge2 == 0){childError=true;}
				break;
		}
	}

	if (childError) {
		childValidator.style.display = 'inline';
		bolSubmit = false;	
	}
	else{childValidator.style.display = 'none'}

	//=============================================================================
	
	//Test Valid formulated Email Address	
	var firstName = document.getElementById('ctl00_cph1_Inc_iq1_firstName').value;	
	var lastName = document.getElementById('ctl00_cph1_Inc_iq1_lastName').value;	
	var emailAddress = document.getElementById('ctl00_cph1_Inc_iq1_emailAddress').value;
	var errorFirst = 'First';
	var errorLast = 'Last';
	var errorEmail = 'Email Address';
	var errorCheck = 0;
	var errorText = '';

	if (firstName.length == 0) {
		errorCheck += 1;			
	}


	if (lastName.length == 0) {
		errorCheck += 2;		

	}


	if (emailAddress.length == 0 || InStr(emailAddress, "@") == -1 || InStr(emailAddress, ".") == -1) {
		errorCheck += 4;		

	}

	switch (errorCheck){
		case 1:
			errorText = 'Provide First Name';
			break;
		case 2:
			errorText = 'Provide Last Name';
			break;
		case 3:
			errorText = 'Provide First & Last Name';
			break;
		case 4:
			errorText = 'Provide Valid Email Address';
			break;
		case 5:
			errorText = 'Provide First Name & Email';
			break;
		case 6:
			errorText = 'Provide Last Name & Email';
			break;
		case 7:
			errorText = 'Provide First, Last & Email';
			break;
	}

	if (errorCheck > 0){
		emailValidator.innerHTML = errorText;
		emailValidator.style.display = 'inline';
		bolSubmit = false;}
	else{emailValidator.style.display = 'none';}

	return bolSubmit;
}

function isValidDate(validateDate){
	today = Date();
	depart = Date(validateDate);
	

	return(depart-today);

}

function InStr(strSearch, charSearchFor){
	var ret = -1;
	for (i=0; i < strSearch.length; i++)
	{
		ret = ret++
		if (charSearchFor == Mid(strSearch, i, 1))
		{ret = i;}
	}
	return ret;
}

function Mid(str, start, len){
	if (start < 0 || len < 0){return "";}
	var iEnd, iLen = str.length;
	
	if ((start + len) > iLen){iEnd = iLen;}
	else{iEnd = start + len;}
	return str.substring(start,iEnd);

}