function changeCarType(type,examples,features,seats,bags,mpg){
  document.getElementById("carTypeName").innerHTML = type;
  document.getElementById("examples").innerHTML = examples;
  document.getElementById("features").innerHTML = features;
  document.getElementById("seats").innerHTML = seats;
  document.getElementById("bags").innerHTML = bags;
  document.getElementById("mpg").innerHTML = mpg;
}


function carSearchValidate(form) {
  var Search = new FormField(form.search1);
  var Dept = new FormField(form.dept1);
  var DeptDate = new FormField(form.deptdate1);
  var DeptTime = new FormField(form.depttime1);
  var DestDate = new FormField(form.destdate1);
  var DestTime = new FormField(form.desttime1);
  var Vendor =  new FormField(form.vendor1);
  var now = new Date();
  var today = new Date(now.getFullYear(),now.getMonth(),now.getDate()).getTime();

  if(!Search.valNotEmpty("Please select an option for the \"Pick-up location\" field.")) return false;
  if(!Search.valMaxLength(99,"Please limit your search to 99 characters in the \"Pick-up location\" field.")) return false; 
  if(!Dept.valNotEmpty("Please select an option for the \"Pick-up location\" field.")) return false;
  if(!Dept.valMaxLength(3,"Invalid input. The system administrator has been notified")) return false; 
  if(!DeptDate.valDate("Please enter dates in MM/DD/YYYY format.")) return false;
  if(!DeptTime.valMaxLength(4,"Invalid input. The system administrator has been notified.")) return false;
  if(!DestDate.valDate("Please enter dates in MM/DD/YYYY format.")) return false;
  if(!DestTime.valMaxLength(4,"Invalid input. The system administrator has been notified.")) return false;
  deptDateArray = DeptDate.fieldValue.split("/");
  destDateArray = DestDate.fieldValue.split("/");
  deptStamp = new Date(deptDateArray[2],deptDateArray[0]-1,deptDateArray[1]).getTime();
  destStamp = new Date(destDateArray[2],destDateArray[0]-1,destDateArray[1]).getTime();
  if(deptStamp > destStamp) {
    alert("You cannot drop-off the car before you pick it up."); return false;
  }
  if(deptStamp < today) {
    alert("Please enter a pick-up date that is in the future"); return false;
  }
  if(!Vendor.valAlphaNum("Invalid input. The system administrator has been notified.")) return false;
  if(!Vendor.valMaxLength(2,"Invalid input. The system administrator has been notified.")) return false;  

  return true;
}


function clearSearches() {
  document.getElementById("dept1").value = "";
  document.getElementById("search1").value = "";
}


function showMatrixCars(link,carrier,stops) {
  resetHighlight();
  var cell = link.parentNode;
  var carBoxen = document.getElementsByName("mat[]");

  for(var h=0, len=carBoxen.length; h<len; h++){
    var carId = carBoxen[h].id.substr(3,carBoxen[h].id.length);
    var arr = carBoxen[h].value.split("|");
    var carCompare = new Dynamic("defaultResultId" + carId);

    if((arr[0] == carrier || carrier == -1) && (arr[1] == stops || stops == -1)) {
      carCompare.showBlock();
      carBoxen[h].checked = true;
    } else {
      carCompare.collapse();
    }
  }
  Page.showAllCorner.showBlock();
  var cellid = cell.id.substr(1,cell.id.length);
  highlight(cellid,true);
}


function highlight(cellId,setid) {
  var cell = (cellId) ? document.getElementById("m" + cellId) : false;
  if(setid) {
    Page.hlCellId = cellId;
  }

  if(Page.cellHighlight) {
    stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(Page.cellHighlight,"#fff","#ffffe0");
  }
  if(Page.rowHighlight) {
    var hlString = Page.rowHighlight.id.substr(1,Page.rowHighlight.id.length);
    var hlArray = hlString.split(":");
    var hlRow = hlArray[0];
    for(var c=Page.Matrix.minCell; c<Page.Matrix.visCells; c++) {
      var rowCell = Page.Matrix.el.rows[hlRow].cells[c];
      stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(rowCell,"#fff","#ffffe0");
    }
  }
  if(Page.colHighlight) {
    var hlCol = false;
    for(var g=0; g<Page.Matrix.el.rows[0].cells.length; g++) {
      if(Page.Matrix.el.rows[0].cells[g] == Page.colHighlight) {
        hlCol = g;
      }
    }
    if(hlCol) {
			for(var u=1, len=Page.Matrix.el.rows.length; u<len; u++) {
        var colCell = Page.Matrix.el.rows[u].cells[hlCol];
        stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(colCell,"#fff","#ffffe0");
      }
    }
  }
  if(cell) {
    var hlArray = cellId.split(":");
    var hlRow = hlArray[0];
    var hlCol = hlArray[1];
    if(hlRow != 0 && hlCol != 0) {
      cell.style.backgroundColor="#ffffe0";
      cell.onmouseover = function(){ cell.style.backgroundColor='#ffffe0'; }
      cell.onmouseout = function(){ cell.style.backgroundColor='#ffffe0'; }
      Page.cellHighlight = cell;
    } else if(hlRow != 0 && hlCol == 0) {
      for(var c=Page.Matrix.minCell; c<Page.Matrix.visCells; c++) {
        var rowCell = Page.Matrix.el.rows[hlRow].cells[c];
        stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(rowCell,"#ffffe0","#ffffe0");
      }
      Page.rowHighlight = cell;
    } else if(hlRow == 0 && hlCol != 0) {
			for(var g=0, len=Page.Matrix.el.rows[0].cells.length; g<len; g++) {
        if(Page.Matrix.el.rows[0].cells[g] == cell) {
          hlCol = g;
        }
      }
      for(var u=1, len=Page.Matrix.el.rows.length; u<len; u++) {
       			var colCell = Page.Matrix.el.rows[u].cells[hlCol];
        stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(colCell,"#ffffe0","#ffffe0");
      }
      Page.colHighlight = cell;
    }
  }
}

function stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(cel,normColor,overColor) {
  cel.style.backgroundColor = normColor;
  cel.onmouseover = function() { cel.style.backgroundColor = overColor; }
  cel.onmouseout = function() { cel.style.backgroundColor = normColor; }
}
  

function resetHighlight() {
  if(Page.hlCellId) {
    if(Page.cellHighlight) {
      stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(Page.cellHighlight,"#fff","#e2e6f2");
      Page.cellHighlight = null;
    }
    if(Page.rowHighlight) {
      var hlString = Page.rowHighlight.id.substr(1,Page.rowHighlight.id.length);
      var hlArray = hlString.split(":");
      var hlRow = hlArray[0];
      for(var c=Page.Matrix.minCell; c<Page.Matrix.visCells; c++) {
        var rowCell = Page.Matrix.el.rows[hlRow].cells[c];
        stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(rowCell,"#fff","#e2e6f2");
      }
      Page.rowHighlight = null;
    }
    if(Page.colHighlight) {
      var hlCol = false;
      for(var g=0, len=Page.Matrix.el.rows[0].cells.length; g<len; g++) {
        if(Page.Matrix.el.rows[0].cells[g] == Page.colHighlight) {
          hlCol = g;
        }
      }
      if(hlCol) {
				for(var u=1, len=Page.Matrix.el.rows.length; u<len; u++) {
          var colCell = Page.Matrix.el.rows[u].cells[hlCol];
          stupidNecessityBecauseOfJavascriptsHorrifyinglyDaftScopingProblemsIHateThis(colCell,"#fff","#e2e6f2");
        }
      }
      Page.colHighlight = null;
    }
  }
}


function valCarsCheckout(i) {
	var tripName = new FormField(document.getElementById("tripName"));
	if(!tripName.valNotEmpty("Please enter a valid trip name.")) return false;
	if(!tripName.valMaxLength(125,"The trip name you entered is longer than the 125 characters allowed.")) return false;

	var Email = new FormField(document.getElementById("email"));
	if(!Email.valEmail("Please enter a valid email address.")) return false;
	if(!Email.valMaxLength(80,"The email address you entered is longer than the 80 characters allowed")) return false;

	if(!valName(i)) return false;
	if(!valCard(i)) return false;
	if(!valBillAddress(i)) return false;
	if(document.getElementById("shipAddressLink").checked == true){
		if(!valShipAddress(i)) return false;
	}
	if(!valAgree()) return false;

  return true;
}


function selectAirport() {
		var selectedItem = this.currResults[this.focusKey] ? this.currResults[this.focusKey] : false;
		if(selectedItem) {
				this.Input.el.value = selectedItem.code + ": " + selectedItem.airport + " - " + selectedItem.city + ", " + selectedItem.loc;
				document.getElementById(this.outputIds.hiddenInput).value = selectedItem.code;
		}
}


function selectCity() {
		var selectedItem = this.currResults[this.focusKey] ? this.currResults[this.focusKey] : false;
		if(selectedItem) {
				this.Input.el.value = selectedItem.code + ": " + selectedItem.city + ", " + selectedItem.loc;
				document.getElementById(this.outputIds.hiddenInput).value = selectedItem.code;
		}
}


function switchToCitySearch(radio) {
		if(radio.checked) {
				Page.type = 'C';
				CitySearch.turnOn();
				ArptSearch.turnOff();
				Page.searchBoxes = [CitySearch];
				clearSearches();
		}
}


function switchToAirportSearch(radio) {
		if(radio.checked) {
				Page.type = 'T';
				ArptSearch.turnOn();
				CitySearch.turnOff();
				Page.searchBoxes = [ArptSearch];
				clearSearches();
		}
}