// Travel Search Widget
// Package Type Vendor Constants
var g_vendor = "HDT";
var g_SKEDVendor = "AH01";
var g_SBTAirOnlyVendor = "F01";
var g_SBTHotelOnlyVendor = "H01";
var g_TARS = false;
var g_PAXCount = "0";
var g_SBTSearch = "http://res.harley-davidson.com/search/search.aspx";
var g_AirHotel = "AH";
var g_AirHotelOVM = "B";
var g_AirOnly = "F";
var g_HotelOnly = "H";
var g_Referrer = "";
var g_PLCode = "";
var g_PostCartID = "";
var g_PostActivePkgSeq = "";

var	skinDirStr	= "";
var objXML;
var hasXML = false;
var hasVB  = false;
var	haveRideDateCheckToClear = false;
expandCollapseImgs = new Array;
expandCollapseImgs[0] = new Image();
expandCollapseImgs[0].src = "/en_US/media/images/shared/layout/plus.gif";
expandCollapseImgs[1] = new Image();
expandCollapseImgs[1].src = "/en_US/media/images/shared/layout/minus.gif";

IE4=(document.all);
if(IE4){
	// We are IE, so use the ActiveX objects for XML
	objXML = new ActiveXObject("Msxml2.DOMDocument.3.0");
	objXML.validateOnParse = true;
	objXML.loadXML( "<xml><test>TEST</test></xml>" );
	if (objXML.parseError.errorCode == 0) {
		hasXML = true;
	}
}
// Travel Search Widget
var weekend = [0,6];
//not currently utilized
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;
var dtCh= "/";
var gNow = new Date();
var haveEventDateCheckToClear = true;
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
CALMON = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEV"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

// Package functions
function doLoad(){
	hideListBoxes();
}
function getLists(obj){
    var packageType = document.resTool.PackageType.options[document.resTool.PackageType.selectedIndex].value;
    
    occupancyTest();
	hideListBoxes();

	if ((TRIM(document.resTool.gsOriginHidden.value) != "") && (packageType != g_HotelOnly && packageType != g_AirOnly)){
		convertOrigin();
	}

	if (TRIM(document.resTool.gsDestinationHidden.value) != ""){
		convertDestination();
	}

	if( packageType == g_AirHotel){	
		showOrigin();
		hideAirSelection();
	}else {
		FIND("trOriginWarning").style.display = "none";
		hideOrigin();
		hideAirSelection();
		
	}
}
function showOrigin(){
	FIND("DepartDate").value = "mm/dd/yy";
	FIND("ReturnDate").value = "mm/dd/yy";
	
	FIND("trOrigin").style.display = "block";
	FIND("trOrigin1").style.display = "block";
	FIND("trDepartLabel").style.display = "block";
	FIND("trToLabel").style.display = "none";
	FIND("trReturnLabel").style.display = "block";
	FIND("trFromLabel").style.display = "none";
}
function hideOrigin(){	
	var today = new Date((new Date()).valueOf() + 86400000);
	var month = today.getMonth() + 1
	if (month <= 9) month = "0" + month;
	//month = CALMON[month-1];
	var day = today.getDate()
	if (day <= 9) day = "0" + day;
	var str = today.getFullYear()+"";
	var year = str.substring(2, 4);
	FIND("DepartDate").value = month + "/" + day + "/" + year;

	var todayPlus = new Date(today.valueOf() + 432000000);
	var monthPlus = todayPlus.getMonth() + 1
	if (monthPlus <= 9) monthPlus = "0" + monthPlus;
	//monthPlus = CALMON[monthPlus-1];
	var dayPlus = todayPlus.getDate()
	if (dayPlus <= 9) dayPlus = "0" + dayPlus;
	var strPlus = todayPlus.getFullYear()+"";
	var yearPlus = str.substring(2, 4);
	FIND("ReturnDate").value = monthPlus + "/" + dayPlus + "/" + yearPlus;
	
	FIND("trOrigin").style.display = "none";
	FIND("trOrigin1").style.display = "none";
	FIND("trDepartLabel").style.display = "none";
	FIND("trToLabel").style.display = "block";
	FIND("trReturnLabel").style.display = "none";
	FIND("trFromLabel").style.display = "block";
}
function hideAirSelection(){
	FIND("trDestinationWarning").style.display = "none";
}
function hideListBoxes(){
	FIND("trOriginClientF").style.display = "none";
	FIND("trOriginClientH").style.display = "none";
	FIND("trOriginClientAH").style.display = "none";
	FIND("trDestinationClientF").style.display = "none";
	FIND("trDestinationClientH").style.display = "none";
	FIND("trDestinationClientAH").style.display = "none";
}
function FIND(item) {
	if (document.all) 
		return(document.all[item]);
	if (document.getElementById) 
		return(document.getElementById(item));
	return(false);
}

function validate(){
	var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;
	var validForm = validateDes();
	
	if ((packageType != g_HotelOnly) && (packageType != g_AirOnly)){
		validForm = validateOrg() && validForm;
	}
	validForm = validateDepartureDateSubmit() && validForm;
	validForm = validateReturnDateSubmit() && validForm;
	validForm = occupancyTest() && validForm;
	if (validForm){
		_swPageView( "widget_travel_search", "/Experience/SuperWidget/Travel/Search" );
		if(packageType == g_AirHotel){
			submitSBT(g_SKEDVendor, g_TARS)
		}else if (packageType == g_AirOnly){
			submitSBT(g_SBTAirOnlyVendor, g_TARS);
		}else if (packageType == g_HotelOnly){
			submitSBT(g_SBTHotelOnlyVendor, g_TARS);
		}
	}
	return false;
}

function toggleListBox(arg){
	var trow;
	var trow2;
	var SearchForm = FIND("resTool");
	var packageType =  SearchForm.PackageType[SearchForm.PackageType.selectedIndex].value;

	if(arg == 'org'){
		trow = FIND('trOriginClient' + packageType);
		trow2 = FIND('trDestinationClient' + packageType);
		desttext = document.forms.resTool.gsDestination;
		destimg = document.images.DestinationInquire;
		
		if(trow.style.display == "none"){
			trow.style.display = "inline";
			trow2.style.display = "none";
			desttext.style.display = "none"; // fix overlap problem in ie7
			destimg.style.display = "none";
		}else{
			trow.style.display = "none";
			desttext.style.display = "inline";
			destimg.style.display = "inline";
		}
	}else{	
		trow = FIND('trDestinationClient' + packageType);
		trow2 = FIND('trOriginClient' + packageType);
		if(trow.style.display == "none"){
			trow.style.display = "inline";
			trow2.style.display = "none";
		}else{
			trow.style.display = "none";
		}	
	}
}
function validateOrg(){
	var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;

	if (packageType == g_AirHotel){
		var orgSel = TRIM(document.resTool.gsOrigin.value).toUpperCase();
		
		if (orgSel == "" || orgSel == "DEPARTURE CITY"){
			document.resTool.gsOriginHidden.value = "";
		}else{
			document.resTool.gsOriginHidden.value = orgSel;
		}
		if (orgSel == "DEPARTURE CITY"){
			orgSel = "";
		}

		var originRow;
		var orgFound = false;

		if(orgSel.length > 3) {
			for(var x = 0; x < document.resTool.originsLBoxAH.options.length; x++){
				var searchStr = TRIM(document.resTool.originsLBoxAH.options[x].text);
				searchStr = searchStr.toUpperCase();
		
				if(searchStr.match(orgSel) != null || searchStr == orgSel){
					orgFound = true;
					document.resTool.gsOrigin.value = TRIM(document.resTool.originsLBoxAH.options[x].text);
					document.resTool.gsOriginHidden.value = document.resTool.originsLBoxAH.options[x].value;				
					break;
				}		
			}
		}else{		
			for(var x = 0; x < document.resTool.originsLBoxAH.options.length; x++){
				var searchStrValue = document.resTool.originsLBoxAH.options[x].value;
										  
				if(searchStrValue == orgSel){
					document.resTool.gsOriginHidden.value = document.resTool.originsLBoxAH.options[x].value;				
					orgFound=true;
				}			
			}		
		}
		originWarn = FIND('trOriginWarning');
		originRow = FIND('trOriginClientAH');
		/*if(!orgFound && orgSel != ""){
			originWarn.style.display = "block"; originRow.style.display = "block"; flipExpandCollapse('originInquire'); 
		}
		else{
			originWarn.style.display = "none"; originRow.style.display = "none"; //document.resTool.gsOriginHidden.value = orgSel; 
		}*/
		if(orgFound){
			return true;
		}else{
			return true;
		}
	}else if (packageType == g_AirOnly){
	  	var orgSel = TRIM(document.resTool.gsOrigin.value).toUpperCase();	  
	  	if (orgSel == "DEPARTURE CITY"){
			orgSel = "";
		}else{
			document.resTool.gsOriginHidden.value = orgSel;
		}
		var originWarn
		var originRow
		var orgFound = false;

	  if(orgSel.length > 3) {
			for(var x = 0; x < document.resTool.originsLBoxF.options.length; x++){
				var searchStr = TRIM(document.resTool.originsLBoxF.options[x].text);
				searchStr = searchStr.toUpperCase();
								  
				if(searchStr.match(orgSel) != null || searchStr == orgSel){
					orgFound = true;
					document.resTool.gsOrigin.value = TRIM(document.resTool.originsLBoxF.options[x].text);
					document.resTool.gsOriginHidden.value = document.resTool.originsLBoxF.options[x].value;				
					break;
				}		
			}
	  }else{	
		for(var x = 0; x < document.resTool.originsLBoxF.options.length; x++){
			var searchStrValue = document.resTool.originsLBoxF.options[x].value;
									  
			if(searchStrValue == orgSel){
				document.resTool.gsOriginHidden.value = document.resTool.originsLBoxF.options[x].value;				
				orgFound=true;
			}			
		}		
	  }
		originWarn = FIND('trOriginWarning');
		originRow = FIND('trOriginClientF');
		/*if(!orgFound && orgSel != ""){
			originWarn.style.display = "block"; originRow.style.display = "block"; flipExpandCollapse('originInquire'); 
		}
		else{
			originWarn.style.display = "none"; originRow.style.display = "none"; //document.resTool.gsOriginHidden.value = orgSel; 
		}*/ 
	   if(orgFound)
			return true;
	   else
			return true;
	}else if (packageType == g_HotelOnly){
	  	var orgSel = TRIM(document.resTool.gsOrigin.value).toUpperCase();	
		if (orgSel == "DEPARTURE CITY"){
			orgSel = "";
		}else{
			document.resTool.gsOriginHidden.value = orgSel;
		}
		var originWarn
		var originRow
		var orgFound = false;

	  if(orgSel.length > 3) {
			for(var x = 0; x < document.resTool.originsLBoxH.options.length; x++){
				var searchStr = TRIM(document.resTool.originsLBoxH.options[x].text);
				searchStr = searchStr.toUpperCase();

				if(searchStr.match(orgSel) != null || searchStr == orgSel){
					orgFound = true;
					document.resTool.gsOrigin.value = TRIM(document.resTool.originsLBoxH.options[x].text);
					document.resTool.gsOriginHidden.value = document.resTool.originsLBoxH.options[x].value;				
					break;
				}		
			}
	  }else{	
		for(var x = 0; x < document.resTool.originsLBoxA.options.length; x++){
			var searchStrValue = document.resTool.originsLBoxH.options[x].value;
									  
			if(searchStrValue == orgSel){
				document.resTool.gsOriginHidden.value = document.resTool.originsLBoxH.options[x].value;				
				orgFound=true;
			}			
		}		
	  }
		originWarn = FIND('trOriginWarning');
		originRow = FIND('trOriginClientH');
		/*if(!orgFound && orgSel != ""){
			originWarn.style.display = "block"; originRow.style.display = "block"; flipExpandCollapse('originInquire'); 
		}
		else{
			originWarn.style.display = "none"; originRow.style.display = "none"; //document.resTool.gsOriginHidden.value = orgSel; 
		}*/
	   if(orgFound)
			return true;
	   else
			return true;
	}
}
function convertOrigin(){
    if (validateOrg()){
		var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;
		var lstOrigins = FIND("originsLBox" + packageType);
		var SearchForm = FIND("resTool");
		var sOriginCode = "";
		var i = 0;

		sOriginCode = SearchForm.gsOriginHidden.value;

		for (i = 0; i < lstOrigins.length; i++){
			if (lstOrigins.options[i].value == sOriginCode){
				SearchForm.gsOrigin.value = lstOrigins.options[i].text;
			}
		}
	}
}
function validateDes(){
	var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;
	var destFound = false;
	

	if(packageType == g_AirHotel){
		var desSel = TRIM(document.resTool.gsDestination.value).toUpperCase();
		if (desSel == "DESTINATION"){
			desSel = "";
		}else{
			document.resTool.gsDestinationHidden.value = desSel;
		}
		var destWarn
		var destRow
		
	  	if(desSel.length > 3) {
			for(var x = 0; x < document.resTool.destLBoxAH.options.length; x++){
				var searchStr = document.resTool.destLBoxAH.options[x].text.toUpperCase();
				var searchStrValue = document.resTool.destLBoxAH.options[x].value;
				if(searchStr.match(desSel) != null || searchStr == desSel){
					destFound = true;
					document.resTool.gsDestination.value = document.resTool.destLBoxAH.options[x].text;
					document.resTool.gsDestinationHidden.value = document.resTool.destLBoxAH.options[x].value;				
					break;
				}		
			}			
	   	}else{	
			for(var x = 0; x < document.resTool.destLBoxAH.options.length; x++){
				var searchStrValue = document.resTool.destLBoxAH.options[x].value;
										  
				if(searchStrValue == desSel){
					document.resTool.gsDestinationHidden.value = document.resTool.destLBoxAH.options[x].value;				
					destFound=true;
				}			
			}		
	  	}
		destWarn = FIND('trDestinationWarning');
		destRow = FIND('trDestinationClientAH');

		if(!destFound && desSel != ""){
			if ( (desSel == "0CB") || (desSel == "0DR") || (desSel == "0JA") || (desSel == "NEG") || (desSel == "OCJ") || (desSel == "SIG") || (desSel == "0CN") || (desSel == "LIR") || (desSel == "SJO") || (desSel == "0EU") || (desSel == "0MX") || (desSel == "NVR") || (desSel == "YYZ") || (desSel == "WAS") || (desSel == "TVL") || (desSel == "0NV") || (desSel == "MKK") || (desSel == "0HI") || (desSel == "SPE") || (desSel == "SAR") || (desSel == "KYL") || (desSel == "FMY") || (desSel == "CLW") || (desSel == "0FL") || (desSel == "ANH") || (desSel == "0CA") || (desSel == "0CD")  ) {
				document.resTool.gsDestinationHidden.value = "";
				document.resTool.gsDestination.value = "";
				destFound=true;
			}/*else{
				destWarn.style.display = "block"; destRow.style.display = "block"; flipExpandCollapse('DestinationInquire'); 
			}*/
		}
		/*else if (desSel == ""){
			destWarn.style.display = "block"; destRow.style.display = "block"; flipExpandCollapse('DestinationInquire'); 
		}*/
		else{				
		  destWarn.style.display = "none"; destRow.style.display = "none"; 
		}
		if(destFound)
			return true;
		else
			return true;	  

	}else if (packageType == g_AirOnly){
		var desSel = TRIM(document.resTool.gsDestination.value).toUpperCase();
		document.resTool.gsDestinationHidden.value = desSel;
		var destWarn;
		var destRow;
	  if(desSel.length > 3) {
			for(var x = 0; x < document.resTool.destLBoxF.options.length; x++){
				var searchStr = document.resTool.destLBoxF.options[x].text.toUpperCase();
				var searchStrValue = document.resTool.destLBoxF.options[x].value;
				if(searchStr.match(desSel) != null || searchStr == desSel){
					destFound = true;
					document.resTool.gsDestination.value = document.resTool.destLBoxF.options[x].text;
                    document.resTool.gsDestinationHidden.value = document.resTool.destLBoxF.options[x].value;				
					break;
				}		
			}			
	   } else {	
		for(var x = 0; x < document.resTool.destLBoxF.options.length; x++){
			var searchStrValue = document.resTool.destLBoxF.options[x].value;
									  
			if(searchStrValue == desSel){
				document.resTool.gsDestinationHidden.value = document.resTool.destLBoxF.options[x].value;				
				destFound=true;
			}			
		}		
	  }
	   destWarn = FIND('trDestinationWarning');
	   destRow = FIND('trDestinationClientF');

		if(!destFound && desSel != ""){
			if ( (desSel == "0CB") || (desSel == "0DR") || (desSel == "0JA") || (desSel == "NEG") || (desSel == "OCJ") || (desSel == "SIG") || (desSel == "0CN") || (desSel == "LIR") || (desSel == "SJO") || (desSel == "0EU") || (desSel == "0MX") || (desSel == "NVR") || (desSel == "YYZ") || (desSel == "WAS") || (desSel == "TVL") || (desSel == "0NV") || (desSel == "MKK") || (desSel == "0HI") || (desSel == "SPE") || (desSel == "SAR") || (desSel == "KYL") || (desSel == "FMY") || (desSel == "CLW") || (desSel == "0FL") || (desSel == "ANH") || (desSel == "0CA")   || (desSel == "0CD")  ) {
				document.resTool.gsDestinationHidden.value = "";
				document.resTool.gsDestination.value = "";
				destFound=true;
			}
			/*else{
				destWarn.style.display = "block"; destRow.style.display = "block"; flipExpandCollapse('DestinationInquire'); 
			}*/
		}
		/*else if (desSel == ""){
			destWarn.style.display = "block"; destRow.style.display = "block"; flipExpandCollapse('DestinationInquire'); 
		}*/
		else{				
		  destWarn.style.display = "none"; destRow.style.display = "none"; //document.resTool.gsDestinationHidden.value = desSel; 
		}
	   if(destFound)
			return true;
	   else
			return true;	  

	}else if (packageType == g_HotelOnly){
		var hType = document.resTool.selectHotel[document.resTool.selectHotel.selectedIndex].value;
		if( hType == "A" ) {
			var desSel = TRIM(document.resTool.hoCity.value).toUpperCase();
			if(desSel == 'CITY IS REQUIRED' || desSel == '') {
				FIND("hoCityError").style.visibility="visible";
				return false;
			} 
			FIND("hoCityError").style.visibility="hidden";
			var desHidden = desSel;
			var desState = document.resTool.hoState[document.resTool.hoState.selectedIndex].value;
			if( desState != "" ) {
				desHidden = desHidden + "," + desState;
			}
			FIND("hoDestinationHidden").value=desHidden;
					

		}
		if( hType == "B" ) {
			var desSel = TRIM(document.resTool.hCity.value).toUpperCase();
			if(desSel == 'CITY IS REQUIRED' || desSel == '') {
				FIND("hCityError").style.visibility="visible";
				return false;
			} 
			FIND("hCityError").style.visibility="hidden";
		}
		return true;
	}
}
function convertDestination(){
	if (validateDes()){
		var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;
		var lstDestinations = FIND("destLBox" + packageType);
		var SearchForm = FIND("resTool");
		var sDestinationCode = "";
		var i = 0;

		sOriginCode = SearchForm.gsDestinationHidden.value;
		for (i = 0; i < lstDestinations.length; i++){
			if (lstDestinations.options[i].value == sOriginCode){
				SearchForm.gsDestination.value = lstDestinations.options[i].text;
			}
		}
	}
}
function TRIM(s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){
    s = s.substring(1,s.length);
  }
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){
    s = s.substring(0,s.length-1);
  }
  return s;
}
function flipExpandCollapse(img){
	/*
	if(document.images[img].src == expandCollapseImgs[1].src) {
		document.images[img].src = expandCollapseImgs[0].src;
	} else { 
		document.images[img].src = expandCollapseImgs[1].src; 
	}
	*/
}
function clearRideDates(){
	if((document.rideform.rideDateFrom.value == "mm/dd/yyyy")||(document.rideform.rideDateTo.value == "mm/dd/yyyy")){
		document.rideform.rideDateFrom.value = "";
		document.rideform.rideDateTo.value = "";
	}
	document.forms['rideform'].submit();
}
function validateRideDate(whichField){
	document.rideform.rideDate.checked = false;
	var dateFrom = document.rideform.rideDateFrom.value;
	var dateTo = document.rideform.rideDateTo.value;
	var dateFromTo;
	var warning;
	if(whichField == "from"){
		dateFromTo = document.rideform.rideDateFrom.value;
		warning = FIND("errFrom");
	}
	else{
		dateFromTo = document.rideform.rideDateTo.value;
		warning = FIND("errTo");
	}
	var myDate = new Date(dateFromTo);
	var dtoday = new Date();
	var retnVal = true;
	myDate = adjustYear(myDate);
	if (dateFromTo != "mm/dd/yyyy"){
		if (myDate == "NaN" || !validateDateFormat(dateFromTo)){
		   warning.innerHTML = "<br/>Please enter a date in dd/mm/yyyy format"
		   retnVal = retnVal && false;
		}else {
			warning.innerHTML = ""
			retnVal = retnVal && true;
		}
		if (myDate != "NaN" && validateDateFormat(dateFromTo)){
			if (myDate < dtoday){
				warning.innerHTML = "<br/>Please enter a future date"
				retnVal = retnVal && false;
			}else{
				warning.innerHTML = ""
				retnVal = retnVal && true;
			}
		}
		dateFrom = new Date(dateFrom);
		dateTo = new Date(dateTo);
		if((dateFrom != "NaN" && validateDateFormat(dateFrom)) && (dateTo != "NaN" && validateDateFormat(dateTo))){
			if((dateTo < dateFrom) || (dateTo == dateFrom)){
				warning.innerHTML = "<br />The From date must be earlier than the To date";
			}
		}
	}else{
		retnVal = false;
	}
	if (retnVal == true){
		warning.innerHTML = ""
	}
	return retnVal;
}
function validateDepartureDate(whichForm){
	
	var departDateString;
	var warning;
	var warningPast;
	var dateField;
	
	if(whichForm == "resTool"){
		dateField=document.resTool.DepartDate;
		departDateString = dateField.value;
		warning = FIND("trDepartureWarning");
		warningPast = FIND("trDepartureWarningPast");
	} else {	
		dateField=FIND("hCheckinDate");
		departDateString = dateField.value;
		var warning = FIND("hDepartureWarning");
		var warningPast = FIND("hDepartureWarningPast");
	}		
	
	var departDate = new Date(departDateString);
	if(departDate.getFullYear()<2000) departDate.setYear(2000+departDate.getYear());
	departDate = new Date(departDateString);

	var today = new Date();
	var retVal = true;

	departDate = adjustYear(departDate);
	if (departDateString != "mm/dd/yy"){
		if (departDate == "NaN" || !validateDateFormat(departDateString)){
		   warning.style.display = "block"
		   retVal = retVal && false;
		}else {
			warning.style.display = "none"
			retVal = retVal && true;
		}
		if (departDate != "NaN" && validateDateFormat(departDateString)){
			if (departDate < today){
				warningPast.style.display = "block"
				retVal = retVal && false;
			}else{
				warningPast.style.display = "none"
				retVal = retVal && true;
			}
		}else{
			warningPast.style.display = "none";
		}
	}else{
		retVal = false;
	}
	if (retVal == true){
		//reset the date...
		dateField.value = ((departDate.getMonth()+1)<10?"0":"") + (departDate.getMonth()+1) + 
											"/" +
											(departDate.getDate()<10?"0":"") + departDate.getDate() + 
											"/" +
											departDate.getFullYear();
		warning.style.display = "none";
		warningPast.style.display = "none";
	}
	return retVal;

}
function validateDepartureDateSubmit(){
	 var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;

	var departDateString;
	if( packageType != g_HotelOnly) {
		departDateString = document.resTool.DepartDate.value;
	}
	else {
		departDateString = document.resTool.hoCheckinDate.value;
	}
  var departDate = new Date(departDateString);
	var today = new Date();
	var retVal = true;
	
	departDate = adjustYear(departDate);

  var warning;
	var warningPast;
	
	if( packageType != g_HotelOnly) {
		warning = FIND("trDepartureWarning");
		warningPast = FIND("trDepartureWarningPast");
	}
	else {
		warning = FIND("hoDepartureWarning");
		warningPast = FIND("hoDepartureWarningPast");
	}
	

	if (departDate == "NaN" || !validateDateFormat(departDateString)){
	   warning.style.display = "block"
	   retVal = retVal && false;
	}else {
		warning.style.display = "none"
		retVal = retVal && true;
	}

	if (departDate != "NaN" && validateDateFormat(departDateString)){
		if (departDate < today){
		warningPast.style.display = "block"
		retVal = retVal && false;
		}else{
			warningPast.style.display = "none"
			retVal = retVal && true;
		}
	}else{
		warningPast.style.display = "none";
	}
	return retVal;
}
function validateReturnDate(whichForm){
	
	var returnFld;
	var returnDateString;
	var warning;
	var warning2;
	var warningPast;
	var departDate;
	
	if(whichForm == 'resTool'){
		returnFld=document.resTool.ReturnDate;
		returnDateString = returnFld.value
		departDate = new Date(document.resTool.DepartDate.value);
		warning = FIND("trReturnWarning");
		warning2 = FIND("trReturnWarning2");
		warningPast = FIND("trReturnWarningPast");
	} else {
		returnFld=FIND("hCheckoutDate");
		returnDateString = returnFld.value;
		departDate = new Date(FIND("hCheckinDate").value);
		warning = FIND("hReturnWarning");
		warning2 = FIND("hReturnWarning2");
		warningPast = FIND("hReturnWarningPast");
	}

	var returnDate = new Date(returnDateString);
	if(returnDate.getFullYear()<2000) returnDate.setYear(2000+returnDate.getYear());
	returnDate = new Date(returnDateString);

	var today = new Date();;
	var retVal = true;
	
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);
	

	if (returnDateString != "mm/dd/yy"){
		if (returnDate == "NaN" || !validateDateFormat(returnDateString)){
		   warning.style.display = "block"    
			retVal = retVal && false;
		}else{
		   warning.style.display = "none"    
			retVal = retVal && true;
		}
		if (returnDate != "NaN" && validateDateFormat(returnDateString)){
			if (returnDate < today){
				warning2.style.display = "block"
				retVal = retVal && false;
			}else{
				warning2.style.display = "none"
				retVal = retVal && true;
			}
		}else{
			warning2.style.display = "none";
		}	
		if (returnDate != "NaN" && validateDateFormat(returnDateString)){
			if (returnDate > today){		
				if ((departDate >= returnDate) && (departDate != "NaN")){
					warning.style.display = "none";
					warning2.style.display = "none";
					warningPast.style.display = "block";
					retVal = retVal && false;
				}else{
					warningPast.style.display = "none";
					retVal = retVal && true;
				}
			}else{
				warningPast.style.display = "none";
			}
		}else{
			warningPast.style.display = "none";
		}
	}else{
		retVal = false;
	}

	if (retVal == true){
		returnFld.value = ((returnDate.getMonth()+1)<10?"0":"") + (returnDate.getMonth()+1) + 
											"/" +
											(returnDate.getDate()<10?"0":"") + returnDate.getDate() + 
											"/" +
											returnDate.getFullYear();
		warning.style.display = "none";
		warning2.style.display = "none";
		warningPast.style.display = "none";
	}
	return retVal;
	
}
function validateReturnDateSubmit(){
	 var packageType = document.resTool.PackageType[document.resTool.PackageType.selectedIndex].value;
	var returnDateString;
	var departDate; 
	if( packageType != g_HotelOnly) {
		returnDateString = document.resTool.ReturnDate.value;
		departDate = new Date(document.resTool.DepartDate.value);
	}
	else {
		returnDateString = document.resTool.hoCheckoutDate.value;
		departDate = new Date(document.resTool.hoCheckinDate.value);
	}
  var returnDate = new Date(returnDateString);

	var today = new Date();
	var retVal = true;

	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);
   
	var warning;
	var warning2;
	var warningPast;
	if( packageType != g_HotelOnly) {
    warning = FIND("trReturnWarning");
    warning2 = FIND("trReturnWarning2");
    warningPast = FIND("trReturnWarningPast");
	}
	else {
    warning = FIND("hoReturnWarning");
    warning2 = FIND("hoReturnWarning2");
    warningPast = FIND("hoReturnWarningPast");
	}
 
	if (returnDate == "NaN" || !validateDateFormat(returnDateString)){
	   warning.style.display = "block"    
		retVal = retVal && false;
	}else{
	   warning.style.display = "none"    
		retVal = retVal && true;
	}
	if (returnDate != "NaN" && validateDateFormat(returnDateString)){
		if (returnDate < today){
			warning2.style.display = "block"
			retVal = retVal && false;
		}else{
			warning2.style.display = "none"
			retVal = retVal && true;
		}
	}else{
		warning2.style.display = "none";
	}
	if (returnDate != "NaN" && validateDateFormat(returnDateString)){
		if (returnDate > today){		
			if ((departDate >= returnDate) && (departDate != "NaN")){
				warning.style.display = "none";
				warning2.style.display = "none";
				warningPast.style.display = "block";
				retVal = retVal && false;
			}else{
				warningPast.style.display = "none";
				retVal = retVal && true;
			}
		}else{
			warningPast.style.display = "none";
		}
	}else{
		warningPast.style.display = "none";
	}
	return retVal;
}
function adjustYear(date){
	if (parseInt(date.getFullYear(),10) < 2000){
		date.setFullYear(2000 + date.getYear());
		return date;
	}else{
		return date;
	}
}
function validateDateFormat( inDate ) {
	if (inDate.length==10){
		var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	}else if (inDate.length==7){
		var objRegExp = /^\d{1,2}\w{3}\d{2}$/;
	}else{
		var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;
	}
	if(!objRegExp.test(inDate)){
		return false; 
	}else{
		// Normalize date
		if (inDate.length==7){
			var month = 0;
			var sMonth = inDate.substring(2,5);
			for(i = 1; i <= 12; i++){
				if (sMonth == CALMON[i]) month = i+1;
			}
			if (month <=9) month = "0" + month;
			inDate = month + "/" + inDate.substring(0,2) + "/" + inDate.substring(5,7);
		}
		var sSeparator = findSeperator(inDate);
		var arrayDate = inDate.split(sSeparator);
		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		var intDay = parseInt(arrayDate[1],10);

		if(arrayLookup[padAge(arrayDate[0])] != null) {
			if(intDay <= arrayLookup[padAge(arrayDate[0])] && intDay != 0)
				return true; 
		}
		var intMonth = parseInt(arrayDate[0],10);
		if (intMonth == 2) { 
		   var intYear = parseInt(arrayDate[2],10);
		   if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
			  return true; 
		}
	}
  	return false; 
}
function occupancyTest(){
  var packageType = document.resTool.PackageType.options[document.resTool.PackageType.selectedIndex].value;
  var hotelType = document.resTool.selectHotel.options[document.resTool.selectHotel.selectedIndex].value;
	var retVal = true;
	var warn, warn2, warn3;
	var Adults;
	var Passengers;
	var Children = 0;
	var gsAge1;
	var gsAge2;
	var gsAge3;
	var gsAge4;
	var gsAge5;
	if( packageType != g_HotelOnly) {
 		Adults = document.resTool.Adults.value;
 		Passengers= document.resTool.Adults.value;
 		gsAge1 = TRIM(document.resTool.ChildAge1.value.toUpperCase());
		gsAge2 = TRIM(document.resTool.ChildAge2.value.toUpperCase());
		gsAge3 = TRIM(document.resTool.ChildAge3.value.toUpperCase());
		gsAge4 = "";
		gsAge5 = "";
	}
	else if(hotelType == "A"){
 		Adults = document.resTool.hoAdultsNum.value;
 		Passengers= document.resTool.hoAdultsNum.value;
 		gsAge1 = TRIM(document.resTool.hoAge1.value.toUpperCase());
		gsAge2 = TRIM(document.resTool.hoAge2.value.toUpperCase());
		gsAge3 = TRIM(document.resTool.hoAge3.value.toUpperCase());
		gsAge4 = TRIM(document.resTool.hoAge4.value.toUpperCase());
		gsAge5 = TRIM(document.resTool.hoAge5.value.toUpperCase());
		
	} else {
 		Adults = document.resTool.hAdultsNum.value;
 		Passengers= document.resTool.hAdultsNum.value;
 		gsAge1 = TRIM(document.resTool.hAge1.value.toUpperCase());
		gsAge2 = TRIM(document.resTool.hAge2.value.toUpperCase());
		gsAge3 = TRIM(document.resTool.hAge3.value.toUpperCase());
		gsAge4 = TRIM(document.resTool.hAge4.value.toUpperCase());
		gsAge5 = TRIM(document.resTool.hAge5.value.toUpperCase());
	}
	
		if (gsAge1 !="" && gsAge1.toUpperCase() != "N/A"){
			Passengers++;
		}
		if (gsAge2 !="" && gsAge2.toUpperCase() != "N/A"){ 
			Passengers++;
		}
		if (gsAge3 !="" && gsAge3.toUpperCase() != "N/A"){
			Passengers++;	
		}
		if (gsAge4 !="" && gsAge4.toUpperCase() != "N/A"){
			Passengers++;	
		}
		if (gsAge5 !="" && gsAge5.toUpperCase() != "N/A"){
			Passengers++;	
		}
	
	g_PAXCount = Passengers;
	if( packageType == g_HotelOnly) {
			 if(hotelType == "A"){
				warn = FIND('hoNBPassWarning');
				warn2 = FIND('hoNBPassWarning2');
				warn3 = FIND('hoNBPassWarning3');
			 }
			 else {
				warn = FIND('BWIPassWarning');
				warn2 = FIND('BWIPassWarning2');
				warn3 = FIND('BWIPassWarning3');
			 }
	}
	else if(packageType != g_HotelOnly){
		warn = FIND('trPassWarning');
		warn2 = FIND('trPassWarning2');
		warn3 = FIND('trPassWarning3');
	}

	if((Adults == "5" && Adults == "6" && Adults == "7" && Adults == "8") || Passengers >= 5){
		warn.style.display = "block";
		warn2.style.display = "none";
	}else{
		warn.style.display = "none";
	}	
	if(Passengers > 8){
		warn2.style.display = "block";
		warn.style.display = "none";
		retVal = false;
	}else{
		warn2.style.display = "none";
	}	
	if(Adults == "0"){
		warn3.style.display = "block";
		retVal = false;
	}else{
		warn3.style.display = "none";
	}
	return retVal;
}
function padAge(age){
	if (age.length < 2 && age != 0){
		age = '0' + age;
	}
	return age;
}
function trimAge(age){
	if (age.length >= 2 && age.substr(0,1) == '0'){
		age = age.substr(1, age.substr.length - 1);
	}
	return age;
}
function submitSBT(vendor, TARSFlag){
	var SBTForm = FIND("SBTresTool");
	var SearchForm = FIND("resTool");
	var packageType =  SearchForm.PackageType[SearchForm.PackageType.selectedIndex].value;
    var returnDateStr;
    var departDateStr;
    var returnDate;
    var departDate;
		if( packageType != g_HotelOnly ) { 
		 departDateStr = document.resTool.DepartDate.value;
		 returnDateStr = document.resTool.ReturnDate.value;
		}
		else {
		 departDateStr = document.resTool.hoCheckinDate.value;
		 returnDateStr = document.resTool.hoCheckoutDate.value;
		}
		
	returnDate = new Date(departDateStr);
	departDate = new Date(returnDateStr);
		
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);

	// LATER: If TARSFlag then some other URL
	SBTForm.action = g_SBTSearch;

	SBTForm.gsVendor.value = g_vendor;
	SBTForm.gsVacationType.value = vendor;
	if( packageType != g_HotelOnly ) { 
		SBTForm.gsDestination.value = SearchForm.gsDestinationHidden.value;
	}

	if ((packageType != g_HotelOnly) && (packageType != g_AirOnly)){
		SBTForm.gsOrigin.value = SearchForm.gsOriginHidden.value;
	}else{
		SBTForm.gsOrigin.value = "XXX";
		SBTForm.hoRadius.value = SearchForm.hoRadius.value;
	}

	if( packageType == g_HotelOnly ) { 
		SBTForm.gsDestination.value = SearchForm.hoDestinationHidden.value;
		SBTForm.hoRadius.value = SearchForm.hoNonBWHRadius.value;
	}
	SBTForm.gsNumberOfTravelers.value = trimAge(g_PAXCount);
	SBTForm.gsDepartureDate.value = departDateStr;
	SBTForm.hoCheckInDate.value = departDateStr;
	SBTForm.coPickUpDate.value = departDateStr;
	SBTForm.gsReturnDate.value = returnDateStr;
	SBTForm.hoCheckOutDate.value = returnDateStr;
	SBTForm.coDropOffDate.value = returnDateStr;
	//SBTForm.gsLengthOfStay.value = diffDays(returnDate, departDate);
	if( packageType != g_HotelOnly ) { 
		SBTForm.gsAge1.value = checkAge(SearchForm.ChildAge1.value);
		SBTForm.gsAge2.value = checkAge(SearchForm.ChildAge2.value);
		SBTForm.gsAge3.value = checkAge(SearchForm.ChildAge3.value);
		SBTForm.gsAge4.value = "";
		SBTForm.gsAge5.value = "";
	}
	else {
		//make sure we have a valid number between 0 and 17 for each age...
		var fld=FIND("hoKidsNum");
		var retVal=true;  //true=submit/false=errors
		var childCount = parseInt(fld.options[fld.selectedIndex].value);
		var ageError=false;
		var over17error=false;
		if(childCount>0) {
			for(r=1;r<=childCount;r++) {
				age=parseFloat(FIND("hoAge" + r).value);
				if(isNaN(age) || age<0) ageError=true;
				if(isNaN(age) || age>17) over17error=true;
			}
		}
	
		if(ageError) {
			FIND("bwoAgeError").innerHTML="Enter an age for each child.";
			FIND("hoChildAgeWarning").style.visibility="visible";
			retVal=false;
		} else if(over17error) {
			FIND("bwoAgeError").innerHTML="Enter ages 18+ as adult.";
			FIND("hoChildAgeWarning").style.visibility="visible";	
			retVal=false;
		} else {
			FIND("hoChildAgeWarning").style.visibility="hidden";	
		}
			
		if(!retVal) return;  //Errors on page
	
		if(!isNaN(FIND("hoAge1").value)) SBTForm.gsAge1.value= (FIND("hoAge1").value=="0" ? "<1" : FIND("hoAge1").value);
		if(!isNaN(FIND("hoAge2").value)) SBTForm.gsAge2.value= (FIND("hoAge2").value=="0" ? "<1" : FIND("hoAge2").value);
		if(!isNaN(FIND("hoAge3").value)) SBTForm.gsAge3.value= (FIND("hoAge3").value=="0" ? "<1" : FIND("hoAge3").value);
		if(!isNaN(FIND("hoAge4").value)) SBTForm.gsAge4.value= (FIND("hoAge4").value=="0" ? "<1" : FIND("hoAge4").value);
		if(!isNaN(FIND("hoAge5").value)) SBTForm.gsAge5.value= (FIND("hoAge5").value=="0" ? "<1" : FIND("hoAge5").value);

	}
	SBTForm.gsPromotionCode.value = SearchForm.gsPromotionCode.value;
	SBTForm.foDepartureTime.value = SearchForm.DepartureTime.value;
	SBTForm.foReturnTime.value = SearchForm.ReturnTime.value;
 
	SBTForm.hasXML.value = hasXML;
	SBTForm.hasVB.value = hasVB;
	if(g_Referrer != ""){
		SBTForm.Referrer.value = g_Referrer;
	}
	if(g_PLCode != ""){
	    SBTForm.plCode.value = g_PLCode;
	}
	if((g_PostCartID != "") && (g_PostActivePkgSeq != "")){
	    SBTForm.ActivePkgSeq.value = g_PostActivePkgSeq
	    SBTForm.CartID.value = g_PostCartID;
	}
	SBTForm.submit();
  return false;
}
function findSeperator(inDate){
	var i;
	var retVal = "";

	for (i = 0; i < inDate.length; i++){
		if (isNaN(inDate.substr(i,1))){
			retVal = inDate.substr(i,1);
		}
	}
	return retVal;
}
function diffDays(d1, d2){
	return Math.round((d1 - d2)/864e5);
}
function checkAge(age){
	var retVal = "";
	if ( age.toUpperCase() != "N/A"){
		retVal = age;
	}
	return retVal;
}
// Date Picker functions
function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	//not currently utilized
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];
	
		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode = vCode + "<table width=\"207\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	vCode = vCode + "</table>";
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCal.document.open();

	//this is the mode currently utilized, so it has been reformatted to requested look & feel
	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Harley-Davidson Event Calendar</title>");
	
	//style tag used instead of linked external file due to IE5 Mac
	this.wwrite("<style type=\"text/CSS\"><!--");
	this.wwrite("body { background-color: #FFFFFF; color: #000000; margin: 0px }");
	this.wwrite("a { color: #000000; }");
	this.wwrite("a.gray { color: #cccccc; }");
	this.wwrite(".small, td, select { font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 10px; }");
	this.wwrite("--></style>");
	
	this.wwrite("</head><body marginheight=\"0\" marginwidth=\"0\" topmargin=\"0\" leftmargin=\"0\"><form>");
	this.wwrite("<div align=\"center\">");
	
	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	this.wwrite("<table width=\"223\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	this.wwrite("<tr><td align=\"left\"><img src=\"/en_US/media/images/shared/layout/img_logo.gif\" width=\"29\" height=\"31\"></td>");
	
	
	//display correct graphic	
	if (document.SBTresTool.CalForm.value == "en") {
		this.wwrite("<td align=\"left\"><img src=\"/en_US/media/images/shared/layout/nav_spacer.gif\" width=\"117\" height=\"31\"></td>");
		this.wwrite("<td align=\"left\"><a href=\"javascript:self.close();\"><img src=\"/en_US/media/images/shared/layout/popup_closewindow.gif\" width=\"77\" height=\"31\" border=\"0\"></a></td></tr>");
		}
	
	this.wwrite("<tr><td align=\"left\"><img src=\"/en_US/media/images/Shared/Layout/spacer.gif\" width=\"1\" height=\"16\"></td></tr></table>");
	this.wwrite("<table width=\"207\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	this.wwrite("<tr><td><img src=\"/en_US/media/images/Shared/Layout/spacer.gif\" width=\"4\" height=\"4\"><br>");
	this.wwrite("<select style=\"font-weight: bold\" onchange=\"window.opener.Build('" + this.gReturnItem + "', this.options[this.selectedIndex].value, '" + this.gYear + "', '" + this.gFormat + "')\">");
	for (var monthCount = 0; monthCount < 12; monthCount++) {
		this.wwrite("<option value=\"" + monthCount + "\"");
		if (monthCount == this.gMonth) {
			this.wwrite(" selected");
		}
			
		if (document.SBTresTool.CalForm.value == "en") {
			this.wwrite(">" + Calendar.Months[monthCount] + "</option>");
		}
	}
	
	this.wwrite("</select></td>");
	this.wwrite("<td align=\"right\" valign=\"bottom\" class=\"small\">");
	
	if (!((parseInt(this.gYear)) < vNowYear)) {
		this.wwrite("<a href=\"" +
			"javascript:window.opener.Build(" + 
			"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
			");" +
			"\"><img src=\"/en_US/media/images/shared/layout/img_arrow_pageleft_sm.gif\" width=\"4\" height=\"7\" border=\"0\"></a>");
	} else {
		//this.wwrite("<img src=\"/en_US/media/images/Shared/Layout/spacer.gif\" width=\"4\" height=\"7\" border=\"0\"></a>");
	}
	this.wwrite("<b>" + this.gYear + "</b>");
	this.wwrite("<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><img src=\"/en_US/media/images/shared/layout/img_arrow_pageright_sm.gif\" width=\"4\" height=\"7\" border=\"0\"></a>");
	this.wwrite("</td></tr></table>");
	
	this.wwrite("<img src=\"/en_US/media/images/Shared/Layout/onepix_rule.gif\" width=\"207\" height=\"1\" vspace=\"4\"><br>");
	
	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);
	
	this.wwrite("</div>");
	this.wwrite("</form></body></html>");
	this.gWinCal.document.close();
}

//this mode has not been reformatted since it is not currently utilized
Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;
	
	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11)	vr = 3;
		
		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("Year : " + this.gYear);

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.wwrite("<table width=\"207\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\">");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/a>]</td><td align=\"center\">");
	this.wwrite("[<a href=\"javascript:window.print();\">Print</a>]</td><td align=\"center\">");
	this.wwrite("[<a href=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/a>]</td></tr></table><br>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<div id=\"layer" + i + "\" class=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<layer id=\"layer" + i + "\" class=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<br>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</div>");
		else if (isNav)
			this.wwrite("</layer>");
	}

	this.wwrite("</body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<tr>";
	vCode = vCode + "<td width=\"30\" align=\"center\" class=\"small\"><b>S</b></td>";
	vCode = vCode + "<td width=\"29\" align=\"center\" class=\"small\"><b>M</b></td>";
	vCode = vCode + "<td width=\"30\" align=\"center\" class=\"small\"><b>T</b></td>";
	vCode = vCode + "<td width=\"29\" align=\"center\" class=\"small\"><b>W</b></td>";
	vCode = vCode + "<td width=\"30\" align=\"center\" class=\"small\"><b>T</b></td>";
	vCode = vCode + "<td width=\"29\" align=\"center\" class=\"small\"><b>F</b></td>";
	vCode = vCode + "<td width=\"30\" align=\"center\" class=\"small\"><b>S</b></td>";
	vCode = vCode + "</tr>";
	
	return vCode;
}

function checkDate(i_month, i_day, i_year)
{
	var c_month = i_month;
	var c_day = i_day;
	var c_year = i_year;
	var currentDate = gNow.getDate();
	var currentMonth = gNow.getMonth();
	var currentYear = gNow.getFullYear().toString();
	
	if (c_year > currentYear)
	{
		return true;
	}
	else if (c_year < currentYear)
	{
		return false;
	}
	else	// same year, need to test month
	{
		if (c_month > currentMonth)
		{
			return true;
		}
		else if (c_month < currentMonth)
		{
			return false;
		}
		else
		{
			if (c_day >= currentDate)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}// end function checkDate

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/

	var useHref = true;
	
	vCode = vCode + "<tr>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<td align=\"center\" class=\"small\" " + this.write_weekend_string(i) + "></td>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++)
	{
		useHref = checkDate(this.gMonth, vDay, this.gYear);
		
		if (!haveEventDateCheckToClear)
		{
			vCode = vCode + "<td height=\"22\" align=\"center\" class=\"small\" " + this.write_weekend_string(j) + ">";
				if (useHref) 
				{ 
						vCode = vCode + "<a href=\"#\" " + 
						"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
						this.format_data(vDay) + 
						"';window.close();\">" + 
						this.format_day(vDay) + 
					"</a>"
				}
				else
				{
					vCode = vCode + "<a href=\"#\" " +
						"class=\"gray\" " +
						"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
						this.format_data(vDay) + 
						"';window.close();\">" + 
						this.format_day(vDay) + 
					"</a>"
				}
				vCode = vCode + "</td>";
		}
		else
		{
			templink = "javascript:self.opener.document." + this.gReturnItem + ".value='" + this.format_data(vDay) + "';window.close();";
			
			
			vCode = vCode + "<td height=\"22\" align=\"center\" class=\"small\" " + this.write_weekend_string(j) + ">";
				if (useHref) 
				{ 
				vCode = vCode + "<a href=\"" + templink + "\">" + 
					this.format_day(vDay) + 
				"</a>";
				}
				else
				{
				vCode = vCode + "<a href=\"" + templink + "\" class=\"gray\">" + 
					this.format_day(vDay) + 
				"</a>";
				}
				
				vCode = vCode + "</td>";
		}
		
		vDay=vDay + 1;
	}
	vCode = vCode + "</tr>";

	// Write the rest of the weeks
	for (k=2; k<7; k++)
	{
		vCode = vCode + "<tr>";

		for (j=0; j<7; j++)
		{
			useHref = checkDate(this.gMonth, vDay, this.gYear);
			if (!haveEventDateCheckToClear)
			{
				vCode = vCode + "<td height=\"22\" align=\"center\" class=\"small\" " + this.write_weekend_string(j) + ">";
					if (useHref)
					{
						vCode = vCode + "<a href='#' " + 
						"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
						this.format_data(vDay) + 
						"';window.close();\">" + 
					this.format_day(vDay) + 
					"</a>"
					}
					else
					{
						vCode = vCode + "<a href='#' " + 
						"class=\"gray\" onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
						this.format_data(vDay) + 
						"';window.close();\">" + 
					this.format_day(vDay) + 
					"</a>"
					}
					
					vCode = vCode + "</td>";
			}
			else
			{
				templink = "javascript:self.opener.document." + this.gReturnItem + ".value='" + this.format_data(vDay) + "';window.close();";
			
				vCode = vCode + "<td height=\"22\" align=\"center\" class=\"small\" " + this.write_weekend_string(j) + ">";
					if (useHref)
					{
						vCode = vCode + "<a href=\"" + templink + "\">" + 
						this.format_day(vDay) + 
						"</a>"
					}
					else
					{
						vCode = vCode + "<a href=\"" + templink + "\" class=\"gray\">" + 
						this.format_day(vDay) + 
						"</a>"
					}
					vCode = vCode + "</td>";
			}
	
			vDay = vDay + 1;
			
			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}
	
		if (j == 6)
			vCode = vCode + "</tr>";
			
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<td " + this.write_weekend_string(j+m) + 
			"></td>";
		else
			vCode = vCode + "<td align=\"center\" class=\"ltGreyTextSmall\"" + this.write_weekend_string(j+m) + 
			"></td>";
	}
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();
	
	//add formatting here if current day is to be visually emphasized
	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return (vday);
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			//return (" bgcolor=\"" + weekendColor + "\"");
			return "";
	}
	
	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
	//switch ("DD-MONTH-YYYY"){
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;
		case "DDMONYY" : // BY REG to mimic Trisepts
			vData = vDD + vMon + vY2;
			break;
		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}
	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}


function monthFunc(d_month)
{

	//NEW DATE FORMAT CODE
	var intel;
	if(document.SBTresTool.CalIntel.value == 1) {
		intel = 1
	} else {
		intel = 2
	}

	
	dtStr = d_month;
	dtStr = dtStr.replace (/\s/gi, "");	// remove all spaces from the string
	
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	if (pos1==-1 || pos2==-1)
	{
		month = null;
		return month;
	}
	
	//var daysInMonth = DaysArray(12)
	//NEW DATE FORMAT CODE
	if(intel==1)
		{
		var strMonth=dtStr.substring(0,pos1)
		}
	else
		{
		var strMonth=dtStr.substring(3,pos2)
		}
	
	//var strMonth=dtStr.substring(0,pos1)
	
	//international
	//var strMonth=dtStr.substring(3,pos2)

	if (strMonth.charAt(0)=="0" && strMonth.length>1)
		strMonth=strMonth.substring(1)

	month=parseInt(strMonth)
	
	month = ((month>12) || (month<1)) ? (gNow.getMonth()+1) : month; //--JDS/GSD - 23-MAR-2005
	
	month = month -1;
	return month;
	
}

function yearFunc(d_year)
{
	dtStr = d_year;
	dtStr = dtStr.replace (/\s/gi, "");	// remove all spaces from the string

	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	if (pos1==-1 || pos2==-1)
	{
		year = null;
		return year;
	}
	
	var strYear=dtStr.substring(pos2+1)
	
	strYr=strYear

	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1)
			strYr=strYr.substring(1)
	}
	//year=strYr;
	year=parseInt(strYr)
	return year;
}

function show_calendar() {
	//NEW DATE FORMAT CODE
	var intel=1;
	
	if(document.SBTresTool.CalIntel.value == 2){
		intel = 2
	}else	{
		intel = 1
	}

	var fromDate = "";
	var toDate = "";
	
	p_item = arguments[0];
	
	if((p_item == "rideform.rideDateTo")||(p_item == "rideform.rideDateFrom")){
		document.rideform.rideDate.checked = false;
	}

	if(p_item =="resTool.ReturnDate" || p_item =="resTool.DepartDate") {
		if (p_item =="resTool.ReturnDate"){ //resTool.ReturnDate
			toDate = document.resTool.DepartDate.value;
		} else{
			fromDate = document.resTool.ReturnDate.value;
		}
	} else {
		if (p_item =="resTool.hCheckoutDate"){ //resTool.ReturnDate
			toDate = FIND("hCheckinDate").value;
		} else{
			fromDate = FIND("hCheckoutDate").value;
		}
	}
	

	
	var month=null;
	var year = null;
	if (fromDate.length > 1)
	{
		month= monthFunc(fromDate);
		year = yearFunc(fromDate);
	}

	if (toDate.length > 1 && toDate.length != 8){
		month = monthFunc(toDate);
		year = yearFunc(toDate);
	}else if (toDate.length == 8){
		month = monthFunc(toDate);
		year = 2000+yearFunc(toDate);
	}

	if (year > gNow.getFullYear()){
			// done & happy
	}else if (year < gNow.getFullYear()-1){
			if(year == null){
				month=null;
				year=null;
			}else{
				month=null;
				year=null;
			}
	}else{// same year, need to test month
		if (month > gNow.getMonth()){
			// done & happy
		}else if (month < gNow.getMonth()){
			//month=null;
			//year=null;
		}
	}

	if (month == null || isNaN(month)){ //(arguments[1] == null)
		p_month = new String(gNow.getMonth());
	}else{
		p_month = month;//arguments[1];
	}
	if (year == null || isNaN(year))//(arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = year.toString();//arguments[2];
	if (arguments[3] == null)
		
		//NEW DATE FORMAT CODE
		if(intel==1) {
				if(p_item =="rideform.rideDateTo" || p_item =="rideform.rideDateFrom"
					|| p_item=="resTool.hCheckinDate" || p_item=="resTool.hCheckoutDate"){
					p_format = "MM/DD/YYYY";
				}
				else {
					p_format = "MM/DD/YY";
				}
			//p_format = "DDMONYY";
			}
		else
			{
			p_format = "DD/MM/YYYY";
			}
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar", "width=220,height=220,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}

/*Set Best Western default dates
	Default check in date is 24 hours.
*/
function setBWIDefaultDates() {
	var curDate = new Date();

	var checkInDay = curDate.getDate() + 1;
	var checkInDate = new Date(curDate.getFullYear(), curDate.getMonth(), checkInDay);
	
	var month = checkInDate.getMonth()+1;
	if(month<=9) month = "0"+month;
	var day = checkInDate.getDate();
	if(day<=9) day="0"+day;
	var curCheckIn = FIND("hCheckinDate").value;
	if(curCheckIn==null || curCheckIn=="") {
		FIND("hCheckinDate").value=month + "/" + day + "/" + checkInDate.getFullYear();
	}
	curCheckIn = FIND("hoCheckinDate").value;
	if(curCheckIn==null || curCheckIn=="") {
		FIND("hoCheckinDate").value=month + "/" + day + "/" + checkInDate.getFullYear();
	}
	
	var checkOutDay = curDate.getDate() + 2;
	var checkOutDate = new Date(curDate.getFullYear(), curDate.getMonth(), checkOutDay);
	month = checkOutDate.getMonth()+1;
	if(month<=9) month = "0"+month;
	day = checkOutDate.getDate();
	if(day<=9) day="0"+day;
	var curCheckOut = FIND("hCheckoutDate").value;
	if(curCheckOut==null || curCheckOut=="") {
		FIND("hCheckoutDate").value=month + "/" + day + "/" + checkOutDate.getFullYear();
	}
	curCheckOut = FIND("hoCheckoutDate").value;
	if(curCheckOut==null || curCheckOut=="") {
		FIND("hoCheckoutDate").value=month + "/" + day + "/" + checkOutDate.getFullYear();
	}
}

/*Hide or display the age fields based on the number of children selected from the ddlb*/
function checkChildCount(fld) {
	var childCount = parseInt(fld.options[fld.selectedIndex].text,8);
	if(childCount>0) {
		FIND("hChildAges").style.display="inline";
		for(r=1;r<=5;r++) {
			if(r<=childCount) {
				FIND("hAge" + r).style.visibility="visible";  //use visibility to preserve the spacing.
			} else {
				FIND("hAge" + r).style.visibility="hidden";
			}
		}
	} else {
		FIND("hChildAges").style.display="none";
	}
}

/*Hide or display the age fields based on the number of children selected from the ddlb*/
function checkNonBWChildCount(fld) {
	var childCount = parseInt(fld.options[fld.selectedIndex].text,8);
	if(childCount>0) {
		FIND("hoChildAges").style.display="inline";
		for(r=1;r<=5;r++) {
			if(r<=childCount) {
				FIND("hoAge" + r).style.visibility="visible";  //use visibility to preserve the spacing.
			} else {
				FIND("hoAge" + r).style.visibility="hidden";
			}
		}
	} else {
		FIND("hoChildAges").style.display="none";
	}
}


/*
	Check input, populate the Best Western form and send the search to their site.
*/
function submitBWI() {
	retVal=true;  //true=submit/false=errors

	//Make sure we have a city...
	var hCity=FIND("hCity").value;
	if(hCity=="" || TRIM(hCity)=="" || TRIM(hCity.toLowerCase())=="city is required") {
		FIND("hCityError").style.visibility="visible";
		retVal=false;
	} else {
		FIND("hCityError").style.visibility="hidden";
	}
	
	//Make sure we have a country...
	var hCountry=FIND("hCountry");
	if(hCountry.selectedIndex==0 || hCountry.options[hCountry.selectedIndex].value=="--") {
		FIND("hCountryError").style.visibility="visible";
		retVal=false;
	} else {
		FIND("hCountryError").style.visibility="hidden";
	}

	//Make sure we have a state...
	var hState=FIND("hState");
	if(hState.selectedIndex==0 || hState.options[hState.selectedIndex].value=="--") {
		if( hCountry.options[hCountry.selectedIndex].value=="USA") {
			$("hStateError").innerHTML = "Please enter a state.";
		}
		if( hCountry.options[hCountry.selectedIndex].value=="CA") {
			$("hStateError").innerHTML = "Please enter a province.";
		}
		FIND("hStateError").style.visibility="visible";
		retVal=false;
	} else {
		FIND("hStateError").style.visibility="hidden";
		$("hStateError").innerHTML = "";
	}
	
	if(!validateDepartureDate("BWISearch")) retVal=false;  
	if(!validateReturnDate("BWISearch")) retVal=false;

	//make sure we have a valid number between 0 and 17 for each age...
	var fld=FIND("hKidsNum");

	var childCount = parseInt(fld.options[fld.selectedIndex].value);
	var ageError=false;
	var over17error=false;
	if(childCount>0) {
		for(r=1;r<=childCount;r++) {
			age=parseFloat(FIND("hAge" + r).value);
			if(isNaN(age) || age<0) ageError=true;
			if(isNaN(age) || age>17) over17error=true;
		}
	}


	if(ageError) {
		FIND("bwAgeError").innerHTML="Enter an age for each child.";
		FIND("hChildAgeWarning").style.visibility="visible";
		retVal=false;
	} else if(over17error) {
		FIND("bwAgeError").innerHTML="Enter ages 18+ as adult.";
		FIND("hChildAgeWarning").style.visibility="visible";	
		retVal=false;
	} else {
		FIND("hChildAgeWarning").style.visibility="hidden";	
	}
		
	if(!retVal) return;  //Errors on page
	
	var frm=FIND("BWISearch");

	frm.city.value=hCity;
	frm.stateCode.value=hState.options[hState.selectedIndex].value;
	frm.countryCode.value=hCountry.options[hCountry.selectedIndex].value;
	frm.checkInDate.value=FIND("hCheckinDate").value;
	frm.checkOutDate.value=FIND("hCheckoutDate").value;
	
	fld=FIND("hAdultsNum");
	var adultCount = parseInt(fld.options[fld.selectedIndex].text);
	frm.numAdults.value=adultCount;
	frm.numChildren.value=childCount;
	

	if(!isNaN(FIND("hAge1").value)) frm.childAge1.value= (FIND("hAge1").value=="0" ? "<1" : FIND("hAge1").value);
	if(!isNaN(FIND("hAge2").value)) frm.childAge2.value= (FIND("hAge2").value=="0" ? "<1" : FIND("hAge2").value);
	if(!isNaN(FIND("hAge3").value)) frm.childAge3.value= (FIND("hAge3").value=="0" ? "<1" : FIND("hAge3").value);
	if(!isNaN(FIND("hAge4").value)) frm.childAge4.value= (FIND("hAge4").value=="0" ? "<1" : FIND("hAge4").value);
	if(!isNaN(FIND("hAge5").value)) frm.childAge5.value= (FIND("hAge5").value=="0" ? "<1" : FIND("hAge5").value);
	_swPageView( "widget_travel_search", "/Experience/SuperWidget/Travel/Search" );
	frm.submit();
}
