
// $Header: /WebSites/library/javascript/validation/cruisesearch.js 6     4/15/08 9:35a Mccusker $
// this function validates the inputs of the ship/port search
function isValidShipPortSearch()
{
	var sname = document.ShipPortForm.shipname;
	var snamevalue = sname.value
	var stype = document.ShipPortForm.type;
	var pname = document.ShipPortForm.port;
	var pnamevalue = pname.value
	var ptype = document.ShipPortForm.ptype;
	var porttype = document.ShipPortForm.porttype;
	
	var space = " ";
	var percent20 = "%20";

    if ((snamevalue.length == 0) && (pnamevalue.length == 0)) {
		alert("Please enter at least one search phrase.");
		sname.focus();
		return false;
	}
    
    if (document.ShipPortForm.shoppingZipCode){
        var szipcode = document.ShipPortForm.shoppingZipCode.value;
        
    	if (isValidZip(szipcode)){
    		hide_inlinemsg('errShowZipMsg');
			
			if  (document.all.EntirePage != undefined){
	        	EntirePage.style.display = "none";
	        	WaitPage.style.display = "block";
			}
			
    		return true;
        }
    	else{
    		display_inlinemsg('errShowZipMsg') ;
    		return false;
        }		
    }

	var invalidchars = "`~!@#$^&*-_=+[{]}\\|;:\'\"<.>/?"; 
	//Note: commas, parentheses & the wildcard (%) are permitted

	for (i=0; i < invalidchars.length; i++) {
		badchar = invalidchars.charAt(i);
		if (snamevalue.indexOf(badchar,0) >= 0){
			alert('Special characters such as periods, ampersands and hyphens are not permitted.\nPlease reenter your search terms and omit any special characters.');
			sname.value = "";
			sname.focus();
			return false;
		}
		if (pnamevalue.indexOf(badchar,0) >= 0) {
			alert('Special characters such as periods, ampersands and hyphens are not permitted.\nPlease reenter your search terms and omit any special characters.');
			pname.value = "";
			pname.focus();
			return false;
		}
	}

	// get rid of all spaces
	for (j=0; j < snamevalue.length; j++) {
		if (snamevalue.indexOf(space,0) >= 0){
			snamevalue = snamevalue.replace(space,percent20);
		} 
		else if (snamevalue.indexOf(space,0) == -1) {
			// if there are no more spaces, get out of the loop
			j=snamevalue.length;
		}
	}
	for (k=0; k < pnamevalue.length; k++) {
		if (pnamevalue.indexOf(space,0) >= 0) {
			pnamevalue = pnamevalue.replace(space,percent20);
		}
		else if (pnamevalue.indexOf(space,0) == -1) {
			// if there are no more spaces, get out of the loop
			k=pnamevalue.length;
		}
	}
	
	// now direct to the page we want to go to
	window.location = "/s/c/results.asp?SType=P&shipname=" + snamevalue + "&type=" + stype.value + "&port=" + pnamevalue + "&ptype=" + ptype.value + "&porttype=" + porttype.value;
	return false;
}	


// this function validates the inputs of the port search with drop down (no ship search)
function isValidPortDropSearch()
{
	var pname = document.ShipPortForm.port;
	var pnamevalue = pname.value
	var ptype = document.ShipPortForm.ptype;
	var porttype = document.ShipPortForm.porttype;
	
	var space = " ";
	var percent20 = "%20";

    if (pnamevalue.length == 0) {
		alert("Please choose a port.");
		pname.focus();
		return false;
	}
    
    if (document.ShipPortForm.shoppingZipCode){
        var szipcode = document.ShipPortForm.shoppingZipCode.value;
        
    	if (isValidZip(szipcode)){
    		hide_inlinemsg('errShowZipMsg');
			
			if  (document.all.EntirePage != undefined){
	        	EntirePage.style.display = "none";
	        	WaitPage.style.display = "block";
			}
			
    		return true;
        }
    	else{
    		display_inlinemsg('errShowZipMsg') ;
    		return false;
        }		
    }

	

	// get rid of all spaces
	
	for (k=0; k < pnamevalue.length; k++) {
		if (pnamevalue.indexOf(space,0) >= 0) {
			pnamevalue = pnamevalue.replace(space,percent20);
		}
		else if (pnamevalue.indexOf(space,0) == -1) {
			// if there are no more spaces, get out of the loop
			k=pnamevalue.length;
		}
	}
	
	// now direct to the page we want to go to
	window.location = "/s/c/results.asp?SType=P&port=" + pnamevalue + "&ptype=" + ptype.value + "&porttype=" + porttype.value;
	return false;
}	
