//	isIE = document.all;
//	isNN = document.layers;
//	document.getElementById -- IE4.0+ : NN6.0+

//	0 = old version
//	1 = cruise tab setup
//	2 = package tab setup
//	3 = tour tab setup
//	4 = lodging tab setup

	var TabLen = 2;

	function qsInitialize(SearchType, tmpTTF, selTextDestination, selWhen, selLength, selBudget) {
		CheckBrowser(SearchType, tmpTTF);
	}

	function qsInitializeExpanded(SearchType, tmpTTF, txtDestination, selTextDestination, selWhen, selLength, selBudget, txtSupplier, txtDepartureLocation, txtShipName, txtFlexDays, txtSpecDate) {
		CheckBrowser(SearchType, tmpTTF);
		RepopulateQuickSearch(SearchType, tmpTTF, txtDestination, selTextDestination, selWhen, selLength, selBudget, txtSupplier, txtDepartureLocation, txtShipName, txtFlexDays, txtSpecDate);
	}

	function CheckBrowser(SearchType, tmpTTF) {
		// determine default tab
		if (SearchType == '') {
			if ((tmpTTF.indexOf('*3*') != -1) || (tmpTTF == '')) {
				SearchType = 'Cruise';
			}
			if (tmpTTF.indexOf('*23*') != -1) {
				SearchType = 'Package';
			}
			if (tmpTTF.indexOf('*21*') != -1) {
				SearchType = 'Package';//'Tour';
			}
			if (tmpTTF.indexOf('*2*') != -1) {
				SearchType = 'Package';//'Lodging';
			}
		}

		if (document.getElementById) {
			switch (SearchType) {
				case 'Cruise':
					SwitchTabs(1);
					break;
				case 'Package':
					SwitchTabs(2);
					break;
				default:
					break;
			}
		}	
	}

	function SwitchTabs(CurrTab) {
		// blank out all div sections to start (including old version section [0])
		//for (i = 0; i <= TabLen; i++) {
		for (i = 1; i <= TabLen; i++) {
			eval('document.getElementById(\'Tab' + i + '\').style.display = \'none\'');
		}
		// turn on the desired tab to be displayed
		eval('document.getElementById(\'Tab' + CurrTab + '\').style.display = \'block\'');
	}

	function ReloadTabs(elem) {
		var SearchType = '';
		switch (elem) {
			case 'Tab1' :
				SearchType = 'Cruise';
				break;
			case 'Tab2' :
				SearchType = 'Package';
				break;
			case 'Tab3' :
				SearchType = 'Lodging';
				break;
		}
		document.location = 'FeaturePage.asp?TabElem=' + elem + '&SearchType=' + SearchType;
	}

	function ReloadTabsAP(elem) { // agent port version
		var SearchType = '';
		switch (elem) {
			case 'Tab1' :
				SearchType = 'Cruise';
				break;
			case 'Tab2' :
				SearchType = 'Package';
				break;
			case 'Tab3' :
				SearchType = 'Lodging';
				break;
		}
		document.location = 'main.asp?TabElem=' + elem + '&SearchType=' + SearchType;
	}
	
	function PopulateList(SearchType, FormItem, ListName) {
		// remove all spaces from name
		SearchType = SearchType.replace(' ','');
		// take passed in values and create objects to be used
		var arrName = eval('arr' + SearchType);
		var arrLength = eval('arr' + SearchType + '.length');
		// call clear function to clear previous list
		ClearList(FormItem, ListName);
		// populate list with new contents from new array
		for (var i = 0; i < arrLength; i++) {
			FormItem.options[i+1] = arrName[i];
		}
	}

	function ClearList(FormItem, ListName) {
		// clear the entire list contents to allow for different sized lists
		var i = 0;
		var o = FormItem.options;
		for (i = o.length; i >= 0; --i)
			o[i] = null;
//		while (FormItem.options.length > 0) FormItem.options[FormItem.options.length-1] = null;

		// repopulate the default list item
		FormItem.options[0] = new Option('Select ' + ListName,'');

		// make sure the default is selected
		FormItem.selectedIndex = null;
		FormItem.selectedIndex = -1;
		FormItem.selectedIndex = 0;
	}

	function RepopulateQuickSearch(SearchType, tmpTTF, CurrtxtDestination, CurrselTextDestination, CurrWhen, CurrLength, CurrBudget, CurrSupplier, CurrDepartureLocation, CurrShipName, CurrFlexDays, CurrSpecDate) {
		if (SearchType == '') {
			if ((tmpTTF.indexOf('*3*') != -1) || (tmpTTF == '')) {
				SearchType = 'Cruise';
			}
			if (tmpTTF.indexOf('*23*') != -1) {
				SearchType = 'Package';
			}
			if (tmpTTF.indexOf('*21*') != -1) {
				SearchType = 'Package';//'Tour';
			}
			if (tmpTTF.indexOf('*2*') != -1) {
				SearchType = 'Package';//'Lodging';
			}
		}

		switch (SearchType) {
			case 'Cruise':
				var objForm = document.frmQuickCruise;
				break;
			case 'Package':
				var objForm = document.frmQuickPackage;
				break;
			case 'Lodging':
				var objForm = document.frmQuickLodging;
				break;
			default:
				var objForm = document.frmQuickOldVer;
		}

		var i;
		
		if (CurrtxtDestination != '' && objForm.txtDestination && CurrselTextDestination == "") {
			objForm.txtDestination.value = CurrtxtDestination;
		}
		
		if (CurrSpecDate != '' && objForm.txtSpecDate ) {
			objForm.txtSpecDate.value = CurrSpecDate;
		}

		if (CurrFlexDays != '' && objForm.txtFlexDays) {
		for (i = 0; i < objForm.txtFlexDays.length; i++) {
				if (objForm.txtFlexDays(i).value == CurrFlexDays) {
					objForm.txtFlexDays(i).selected = true;
				}
			}
		}
		
	
		
		if (CurrselTextDestination != '' && objForm.selTextDestination) {
			for (i = 0; i < objForm.selTextDestination.length; i++) {
				if (objForm.selTextDestination(i).value == CurrselTextDestination) {
					objForm.selTextDestination(i).selected = true;
				}
			}
		}
		if (CurrWhen != '' && objForm.selWhen) {
			for (i = 0; i < objForm.selWhen.length; i++) {
				if (objForm.selWhen(i).value == CurrWhen) {
					objForm.selWhen(i).selected = true;
				}
			}
		}
		if (CurrLength !='' && objForm.selLength) {
			for (i = 0; i < objForm.selLength.length; i++) {
				if (objForm.selLength(i).value == CurrLength) {
					objForm.selLength(i).selected = true;
				}
			}
		}
		if (CurrBudget != '' && objForm.selBudget) {
			for (i = 0; i < objForm.selBudget.length; i++) {
				if (objForm.selBudget(i).value == CurrBudget) {
					objForm.selBudget(i).selected = true;
				}
			}
		}

  	if (CurrSupplier != '' && objForm.txtSupplier) {
			objForm.txtSupplier.value = CurrSupplier;
		}

		if (CurrDepartureLocation != '' && objForm.txtDepartureLocation) {
			objForm.txtDepartureLocation.value = CurrDepartureLocation;
		}
		
		if (CurrShipName != '' && objForm.txtShipName) {
			objForm.txtShipName.value = CurrShipName;
		}
				
	}
	

	function ClearQuickSearch(SearchType) {
		switch (SearchType) {
			case 'Cruise':
				var objForm = document.frmQuickCruise;

		    if (objForm.selTextDestination) {
  		    objForm.selTextDestination[0].selected = true;
		    }

		    if (objForm.txtDestination) {
			    objForm.txtDestination.value = "Type in Destination";
		    }

		    if (objForm.selWhen) {
		    //alert("selTextDestination");
  		    objForm.selWhen[0].selected = true;
		    }

		    if (objForm.selLength) {
  		    objForm.selLength[0].selected = true;
		    }

		    if (objForm.selBudget) {
  		    objForm.selBudget[0].selected = true;
		    }
    		
		    if (objForm.txtDepartureLocation) {
			    objForm.txtDepartureLocation.value = "Any Departure Port";
		    }

  	    if (objForm.txtSupplier) {
			    objForm.txtSupplier.value = "Any Cruise Line";
		    }

		    if (objForm.txtShipName) {
			    objForm.txtShipName.value = "Any Ship";
		    }

			 if (objForm.txtFlexDays) {
  		    objForm.txtFlexDays[0].selected = true;
		    }
			 
			 if (objForm.txtSpecDate) {
  		    objForm.txtSpecDate.value = "";
		    }
				break;
				
			case 'Package':
				var objForm = document.frmQuickPackage;

		    if (objForm.selTextDestination) {
  		    objForm.selTextDestination[0].selected = true;
		    }

		    if (objForm.txtDestination) {
			    objForm.txtDestination.value = "Type in Destination";
		    }

		    if (objForm.selWhen) {
  		    objForm.selWhen[0].selected = true;
		    }

		    if (objForm.selBudget) {
  		    objForm.selBudget[0].selected = true;
		    }
    		
		    if (objForm.selLength) {
  		    objForm.selLength[0].selected = true;
		    }
			 
			
				break;
		}

	}

	function ClearHiddenQuickSearch(SearchType) {
		switch (SearchType) {
			case 'Cruise':
				var objForm = document.frmQuickCruise;

		    if (objForm.selBudget) {
  		    objForm.selBudget[0].selected = true;
		    }
  	    if (objForm.txtSupplier) {
			    objForm.txtSupplier.value = "Any Cruise Line";
		    }

		    if (objForm.txtDepartureLocation) {
			    objForm.txtDepartureLocation.value = "Any Departure Port";
		    }
		    if (objForm.txtShipName) {
			    objForm.txtShipName.value = "Any Ship";
		    }
				break;
			case 'Package':
				var objForm = document.frmQuickPackage;

		    if (objForm.selLength) {
  		    objForm.selLength[0].selected = true;
		    }
				break;
		}
	}

	function ValidateQuickCruise() {
		var msg = '';
		
//		if (document.frmQuickCruise.selTextRegion != undefined) {
		if (typeof(document.frmQuickCruise.selTextDestination) == 'object') {
			if ((document.frmQuickCruise.selTextDestination.value == '' ||
				document.frmQuickCruise.selTextDestination.value == 'null')
				&& 
				(document.frmQuickCruise.txtDestination.value == '' ||
				document.frmQuickCruise.txtDestination.value == 'null')
				) {
				msg = 'Please select a Destination.\n\n';
			}
		}
		if (msg == '') {
			return true;
		}
		else {
			alert(msg);
			document.frmQuickCruise.selTextDestination.focus();
			return false;
		}
	}

	function ValidateQuickPackage() {
		var msg = '';
		
//		if (document.frmQuickPackage.selTextRegion != undefined) {
		if (typeof(document.frmQuickPackage.selTextDestination) == 'object') {
			if (
				(document.frmQuickPackage.selTextDestination.value == '' || 
					document.frmQuickPackage.selTextDestination.value == 'null') 
				&&
				(document.frmQuickPackage.txtDestination.value == '' ||
				 document.frmQuickPackage.txtDestination.value == 'null')
				 
				) {
				msg = 'Please select a Destination:\n\n';
			}
		}
		if (msg == '') {
			return true;
		}
		else {
			alert(msg);
			document.frmQuickPackage.selTextDestination.focus();
			return false;
		}
	}

	function ValidateQuickLodging() {
		var msg = '';
		
//		if (document.frmQuickLodging.selTextRegion != undefined) {
		if (typeof(document.frmQuickLodging.selTextDestination) == 'object') {
			if (
				(document.frmQuickLodging.selTextDestination.value == '' || 
					document.frmQuickLodging.selTextDestination.value == 'null') &&
				(document.frmQuickLodging.txtDestination.value == '' || 
				document.frmQuickLodging.txtDestination.value == 'null')) {
				msg = 'Please select a Destination:\n\n';
			}
		}
		if (msg == '') {
			return true;
		}
		else {
			alert(msg);
			document.frmQuickLodging.selTextDestination.focus();
			return false;
		}
	}

	function ValidateQuickOldVer() {
		var selTextDestination;// = document.frmQuickOldVer.selTextRegion;
		var selTextDestination;// = document.frmQuickOldVer.selTextDestination;
		var txtDestination = document.frmQuickOldVer.txtDestination;
		var SearchType;// = document.frmQuickOldVer.SearchType.value;
		var msg = '';

		if (typeof(document.frmQuickOldVer.selTextDestination) == 'object') {
			selTextDestination = document.frmQuickOldVer.selTextDestination;
		}
		if (typeof(document.frmQuickCruise.selTextDestination) == 'object') {
			selTextDestination = document.frmQuickOldVer.selTextDestination;
		}
		if (typeof(document.frmQuickOldVer.SearchType) == 'object') {
			SearchType = document.frmQuickOldVer.SearchType.value;
		}
		if (typeof(selTextDestination) == 'object') {
			if ((selTextDestination.options[selTextDestination.selectedIndex].value == '' ||
				selTextDestination.options[selTextDestination.selectedIndex].value == 'null' ||
				selTextDestination.options[selTextDestination.selectedIndex].value == null)
				&& txtDestination.value == '') {
				msg = 'Please select a Destination.\n\n';
			}
		}
		if (SearchType == 'Cruise') {
			if ((selTextDestination.options[selTextDestination.selectedIndex].value == '' ||
				selTextDestination.options[selTextDestination.selectedIndex].value == 'null' ||
				selTextDestination.options[selTextDestination.selectedIndex].value == null)
				&& txtDestination.value == '') {
				msg += 'Please select a destination.\n\n';
			}
		}

		if (msg == '') {
			return true;
		}
		else {
			alert(msg);
			return false;
		}
	}
