// compareCruises.js
// OLD JS FILE FOR COMPARED CRUISES
// WITH NEW SEARCH REDESIGN THIS FILE IS NO LONGER USED
//

	var	browserName = navigator.appName;   // detect browser 
    var browserVer = parseInt(navigator.appVersion);
    
	//var compareBtnGrey = "img/btn/cor_comparecruises_btn_grey.gif";
	//var compareBtn = "img/btn/cor_comparecruise_btn.gif";
	
	function validateSelectedCompareCruisesForm(compareform) {
	
		var selectedCruisesCount = getCheckboxCount(compareform);
		
		if (selectedCruisesCount < minimumToCompare)
			alert(minNumberMsg);
			
		return (selectedCruisesCount >= minimumToCompare);
	}
	
	function setButtonState(checkbox, compareform) {
	
		var selectedCruisesCount = getCheckboxCount(compareform);
			
		setSubmitButtonVisibility(selectedCruisesCount);
		
		if (selectedCruisesCount > maximumToCompare) {
			alert(maxNumberMsg + " " + maximumToCompare);
			checkbox.checked = false;
		}
	}
	
	function setSubmitButtonVisibility(selectedCruisesCount) {
	
		//if (browserName == "Netscape")  {
			//NS requires div tag for getElementById
		//	compare = document.getElementById('compareDiv');
		//}
		//else
		//	compare = document.getElementById('compare');

		//if (compare != null) {
			//NS will use the img name tag, IE will use the img id tag,
			//so both must be present for cross-browser support
			submitButtonTop = document.getElementById('submitButtonTop');
			submitButtonBottom = document.getElementById('submitButtonBottom');

			if (selectedCruisesCount >= minimumToCompare) {
				submitButtonTop.src = compareBtn;
				submitButtonBottom.src = compareBtn;
				submitButtonTop.disabled = false;
				submitButtonBottom.disabled = false;
				
			}
			else {
				submitButtonTop.src = compareBtnGrey;
				submitButtonBottom.src = compareBtnGrey;
				submitButtonTop.disabled = true;
				submitButtonBottom.disabled = true;
			}

		//}
	}
	
	function getCheckboxCount(compareform) {
	
		var selectedCruisesCount = 0
		
		if (compareform.compare != undefined && compareform.compare != null ) {
		
			for (var i=0; i < compareform.compare.length; i++) {
				if (compareform.compare[i].checked == true)
					selectedCruisesCount++ ;
			}
		}
		
		// read the hidden values			
		if (compareform.compareFromOtherPage != undefined) {
			if (compareform.compareFromOtherPage.length == undefined)
				selectedCruisesCount++ ;
			else
				for (var i=0; i < compareform.compareFromOtherPage.length; i++) {
					selectedCruisesCount++;
				}
		}
		
		return selectedCruisesCount
	}
