<!--
// Validators
function IsEmpty(ctl)
{
	str = ctl.value;
	return (str == null || str == "");
}

function IsCCNum(ctl)
{
	str = ctl.value;
	var pattern = /[^\d\s-]/;
		
	return !pattern.test(str);
}

function IsChecked(ctl)
{
	return ctl.checked;
}

// Control data
function FormControl(name, type, friendlyName, required, minLen, maxLen, dataType, validator)
{
	this.name = name;
	this.type = type;
	this.friendlyName = friendlyName;
	this.required = required;
	this.minLen = minLen;
	this.maxLen = maxLen;
	this.dataType = dataType;
	this.validator = validator;
}
var validatedCtls = new Array();
// (name, type, friendlyName, required, minLen, maxLen, dataType, validator)
// Client Info
validatedCtls.push(new FormControl("Client_Fname", "text", "First Name", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Lname", "text", "Last Name", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Add1", "text", "Address", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_City", "text", "City", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_State", "text", "State/Prov", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Zip", "text", "Zip/Postal", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Country", "text", "Country", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Phone1", "text", "Phone", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Client_Email", "text", "Your Email", true, "0", "0", "text", ""));

// Pickup Info
validatedCtls.push(new FormControl("PU_Airport_Add1", "text", "Street Address or Airport Name", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("PU_ArrivingFrom_City", "text", "City or Arriving From", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("PU_FlightNo_State", "text", "State/Province or Flight No.", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("PU_ArrivalTime_Zip", "text", "Zip/Postal Code or Arrival Time", true, "0", "0", "text", ""));

// Dropoff and trip info
validatedCtls.push(new FormControl("Dest_Dest", "select", "Destination", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Dest_CarType", "select", "Type of Car", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Dest_Date", "text", "Date of Pickup", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Dest_PickupTime", "select", "Time of Pickup", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("Dest_City", "text", "Destination City", true, "0", "0", "text", ""));

// Credit Card info
validatedCtls.push(new FormControl("CCInfo_CCType", "select", "Credit Card Type", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("CCInfo_CCNumb", "num", "Credit Card Number", true, "0", "0", "ccnum", ""));
validatedCtls.push(new FormControl("CCInfo_Expiry", "text", "Credit Card Expiration", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("CCInfo_Name", "text", "Name on Credit Card", true, "0", "0", "text", ""));
validatedCtls.push(new FormControl("CCInfo_Phone", "text", "Card Holder's Phone Number", true, "0", "0", "text", ""));

// Terms and Conditions agreement
validatedCtls.push(new FormControl("Client_Agree", "checkbox", "I AGREE", true, "0", "0", "bool", ""));

function ValidateFormEntries(form)
{
	var errFound = 0;
	var errMsg = "Please address the following problems with your submission:\n\n";
	var focusSet = false;

	// Verify required fields
	for (var element in validatedCtls)
	{
		ctl = validatedCtls[element];
		ctlRef = eval("form." + ctl.name);
		if(ctl.required)
		{
			if(ctl.type == "text")
			{
				if(IsEmpty(ctlRef))
				{
					errMsg += "Please fill in the " + ctl.friendlyName + " field.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						focusSet = true;
					}					
				}
			}
			
			if(ctl.type == "num")
			{
				if(IsEmpty(ctlRef))
				{
					errMsg += "Please fill in the " + ctl.friendlyName + " field.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						focusSet = true;
					}
				}
				
				if(ctl.dataType == "int")
				{
					errMsg += "Please enter only numbers (0 - 9) in the " + ctl.friendlyName + " field.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						ctlRef.select();
						focusSet = true;
					}
				}
				
				if(ctl.dataType == "ccnum" && !IsCCNum(ctlRef))
				{
					errMsg += "Please enter a valid credit card number in the " + ctl.friendlyName + " field.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						ctlRef.select();
						focusSet = true;
					}
				}
			}
			
			if(ctl.type == "checkbox")
			{
				if(!IsChecked(ctlRef))
				{
					errMsg += "Please check the " + ctl.friendlyName + " checkbox.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						focusSet = true;
					}					
				}
			}
			
			if(ctl.type == "select")
			{
				if(ctlRef.options[ctlRef.selectedIndex].value == ctl.validator)
				{
					errMsg += "Please select an option from the " + ctl.friendlyName + " list.\n";
					errFound++;
					if(!focusSet)
					{
						ctlRef.focus();
						focusSet = true;
					}					
				}
			}
		}
	}

	if(errFound)
	{
		alert(errMsg);
		return(false);
	}
	
	return(true);

}

//-->


