// JavaScript Document
//globals
var g_txtDate       = "txtDate";
var g_txtFromDate   = "txtFromDate";
var g_txtToDate     = "txtToDate";
var g_txtPort       = "divPort";
var g_txtPortOfCall = "divPortOfCall";

function swapImage(imgSrc,delay)
{        
        command = "swap('"+imgSrc+"');";
        setTimeout(command,delay);
}

function swap(imgSrc)
{
        document.imgBig.src = imgSrc
}

function popup(url)
{
	params = 'width='+screen.width;
	params += ', height='+screen.height;
	params += ', top=0, left=0'
	params += ', fullscreen=no';
	newwin=window.open(url,'windowname4', params);
	if (window.focus) {newwin.focus()}
	return false;
}

//If numeric function
function IsNumeric(strString)
//  check for valid numeric strings	
{
	var strValidChars = "0123456789.+-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function togglediv(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)    //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
function loopSelected(myList)
{
  /* Count selected  */
  var selObj = document.getElementById(myList);
    
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if ((selObj.options[i].selected) && (selObj.options[i].value != "")) {
      count++;
    }
  }
  return count;
}
function showselected(myList)
{
 
  var selObj = document.getElementById(myList);
    
  var i;
  for (i=0; i<selObj.options.length; i++) {
    if ((selObj.options[i].selected) && (selObj.options[i].value != "")) {      
	  return selObj.options[i].value;
    }
  }
  return selObj.options[i].value;
}

function selectDestination(myList,Destination)
{
  
  var selObj = document.getElementById(myList);
  
  var i;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].value == Destination ) {      
	  selObj.options[i].selected = true;
	  return true;
    }
  }
}

function loadItinerary(CRS,CRSLST,FROMSEARCH) {

 var cruiseid = document.getElementById(CRS).value;
 document.location.href="/itinerary.html?CRS="+cruiseid+"&CRSLST="+CRSLST+FROMSEARCH;
		
}

function loadDeck(SHP,FROMSEARCH) {

 var deckcd = document.getElementById("deckid").value;
 document.location.href="/louisvessels.html"+FROMSEARCH+"&DECK="+deckcd;
		
}
/* Scripts For the OnChange */
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text )
{
    /* Function to Add Options in a List */
	var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}
function loadPorts(objId){
	var	country,destination,dateFrom,dateTo,duration,port,portOfCall,ship;
	country = jQuery("#txtFrom option:selected").val();	
	destination = jQuery("#txtDestin option:selected").val();
	duration = jQuery("#txtDurat option:selected").val();
	dateFrom = jQuery("#" + g_txtFromDate).val();
	dateTo = jQuery("#"+ g_txtToDate).val();	
	ship = jQuery("#txtShip").val();
	
	if(objId == "txtDestin"){
		jQuery( "#txtShip" ).attr("disabled", true); 
		jQuery( "#txtPort" ).attr("disabled", true); 
		jQuery( "#txtPortOfCall" ).attr("disabled", true); 
	}
	if(objId == "txtShip"){
		jQuery( "#txtPort" ).attr("disabled", true); 
		jQuery( "#txtPortOfCall" ).attr("disabled", true); 
	}		
	if(objId == "txtPort"){
		jQuery( "#txtPortOfCall" ).attr("disabled", true); 
	}
	if(objId != "txtPort"){
		jQuery( "#txtPort" ).before( '<span id="alp"  style="float:left"><img src="/images2/ajax-loader.gif" alt="" /></span>' );

	}
	if(objId != "txtPortOfCall"){
	    jQuery( "#txtPortOfCall" ).before( '<span id="alpoc" style="float:left"><img src="/images2/ajax-loader.gif" alt="" /></span>' );		
	}
	if(objId != "txtShip"){
	    jQuery( "#txtShip" ).before( '<span id="als" style="float:left"><img src="/images2/ajax-loader.gif" alt="" /></span>' );
	}
	jQuery.post("get-ports-of-call.html",
		{
			txtDestin:destination,
			txtDurat:duration,
			txtFromDate:dateFrom,
			txtToDate:dateTo,
			txtShip:ship
		},
		function(data){			
			if(objId != "txtPort")	 	{ jQuery( "#alp"   ).remove();  }
			if(objId != "txtPortOfCall"){ jQuery( "#alpoc" ).remove();}
			if(objId != "txtShip")		{ jQuery( "#als"   ).remove();  }
			if(data.indexOf('option') != -1 ){
				if(objId == "txtShip"){
					
					jQuery("#txtPort").empty();
					jQuery("<option value=\"\">Any departure port</option>").appendTo("#txtPort");
					jQuery(data).filter(".departure").each(function(){
						if(jQuery(this).val() == jQuery("#departurePort").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtPort");
						}else{
							jQuery(this).appendTo("#txtPort");
						}
					});	
					
					jQuery("#txtPortOfCall").empty();
					jQuery("<option value=\"\">Any port of call</option>").appendTo("#txtPortOfCall");				
					jQuery(data).filter(":not(.ship)").each(function(){
						if(jQuery(this).val() == jQuery("#departurePortOfCall").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtPortOfCall");
						}else{
							jQuery(this).appendTo("#txtPortOfCall");
						}
					});						
					jQuery( "#txtPort" ).removeAttr("disabled"); 					
					jQuery( "#txtPortOfCall" ).removeAttr("disabled"); 
				}
				if(objId == "txtPort"){
					jQuery("#txtPortOfCall").empty();
					jQuery("<option value=\"\">Any port of call</option>").appendTo("#txtPortOfCall");				
					jQuery(data).filter(":not(.ship)").each(function(){
						if(jQuery(this).val() == jQuery("#departurePortOfCall").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtPortOfCall");
						}else{
							jQuery(this).appendTo("#txtPortOfCall");
						}
					});					
					jQuery( "#txtPortOfCall" ).removeAttr("disabled"); 
				}
				
				
				if(objId == "txtDestin"){
					jQuery("#txtShip").empty();
					jQuery("<option value=\"\">Any Ship</option>").appendTo("#txtShip");
					jQuery(data).filter(".ship").each(function(){															   
						if(jQuery(this).val() == jQuery("#ship").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtShip");
						}else{
							jQuery(this).appendTo("#txtShip");
						}				
					});				
				
					jQuery("#txtPort").empty();
					jQuery("<option value=\"\">Any departure port</option>").appendTo("#txtPort");
					jQuery(data).filter(".departure").each(function(){
						if(jQuery(this).val() == jQuery("#departurePort").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtPort");
						}else{
							jQuery(this).appendTo("#txtPort");
						}
					});
				
					jQuery("#txtPortOfCall").empty();
					jQuery("<option value=\"\">Any port of call</option>").appendTo("#txtPortOfCall");				
					jQuery(data).filter(":not(.ship)").each(function(){
						if(jQuery(this).val() == jQuery("#departurePortOfCall").val()){
							jQuery(this).attr("selected","selected").appendTo("#txtPortOfCall");
						}else{
							jQuery(this).appendTo("#txtPortOfCall");
						}
					});	
					jQuery( "#txtShip" ).removeAttr("disabled");										
					jQuery( "#txtPort" ).removeAttr("disabled");
					jQuery( "#txtPortOfCall" ).removeAttr("disabled");
				}
				jQuery("#txtPort").attr("title","Select Departure Port");
				jQuery("#txtPortOfCall").attr("title","Select Port Of Call");
			}else{
				jQuery("#txtPort").html("<option value=\"\">No Port Found</option>");
				jQuery("#txtPort").attr("title","No port found for this search criteria");
				jQuery("#txtPortOfCall").html("<option value=\"\">No port Found</option>");
				jQuery("#txtPortOfCall").attr("title","No port found for this search criteria");
				jQuery( "#txtShip" ).removeAttr("disabled");										
				jQuery( "#txtPort" ).removeAttr("disabled");
				jQuery( "#txtPortOfCall" ).removeAttr("disabled");				
			}
		}
	);
}

function loadDestinations() {
	
	/* It checks which Departure Port is Selected and Selects its Destinations */
	
	var departurefrom = document.getElementById('txtFrom').value; // Get the selected Departure Port
	var destination_list = document.getElementById('txtDestin'); // Define the Destination Object
	
	
	if(departurefrom == "ALL|All Departure Ports") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Any Destination");
		addOption(destination_list,"WESTMED|West Mediterranean","West Mediterranean");
		addOption(destination_list,"EASTMED|East Mediterranean","East Mediterranean");
		addOption(destination_list,"LIBYA|Libya","Libya");
		addOption(destination_list,"AEGEAN|Greece and Turkey","Greece and Turkey");
		addOption(destination_list,"GREECE|Greek Islands","Greek Islands");
		addOption(destination_list,"EGYPT|Egypt","Egypt");
		addOption(destination_list,"HOLYLAND|The Holy Land","The Holy Land");
		addOption(destination_list,"LEBANON|Lebanon","Lebanon");
		addOption(destination_list,"RHODES|Rhodes","Rhodes");
		addOption(destination_list,"ADRIATIC|Adriatic Sea","Adriatic Sea");
		addOption(destination_list,"NORTHITALY|North Italy","North Italy");
		addOption(destination_list,"BLACKSEA|Black Sea","Black Sea");
		
	} else
	if(departurefrom == "GREECE|Greece") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Any Destination");
		addOption(destination_list,"AEGEAN|Greece and Turkey","Greece and Turkey");
		addOption(destination_list,"BLACKSEA|Black Sea","Black Sea");
            addOption(destination_list,"EGYPT|Egypt","Egypt");
		
	} else
	if(departurefrom == "CYPRUS|Cyprus") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Any Destination");
		addOption(destination_list,"EGYPT|Egypt","Egypt");
		addOption(destination_list,"HOLYLAND|The Holy Land","The Holy Land");
		addOption(destination_list,"SYRIA|Syria","Syria");
		addOption(destination_list,"GREECE|Greek Islands","Greek Islands");
		addOption(destination_list,"RHODES|Rhodes","Rhodes");
        	addOption(destination_list,"LEBANON|Lebanon","Lebanon");
		addOption(destination_list,"BLACKSEA|Black Sea","Black Sea");
		addOption(destination_list,"ADRIATIC|Adriatic Sea","Adriatic Sea");
		addOption(destination_list,"NORTHITALY|North Italy","North Italy");
		
	} else 
	if(departurefrom == "FRANCE|France") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Any Destination");
		addOption(destination_list,"WESTMED|West Mediterranean","West Mediterranean");
		addOption(destination_list,"EASTMED|East Mediterranean","East Mediterranean");
		addOption(destination_list,"LIBYA|Libya","Libya");
				
	} else 
	if(departurefrom == "ITALY|Italy") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Any Destination");
		addOption(destination_list,"WESTMED|West Mediterranean","West Mediterranean");
		addOption(destination_list,"EASTMED|East Mediterranean","East Mediterranean");
		addOption(destination_list,"LIBYA|Libya","Libya");
		}
	else 
	if(departurefrom == "INDIA|India") {
		removeAllOptions(destination_list);
		addOption(destination_list,"ALL|All Destinations","Destination");
		addOption(destination_list,"INDIA|Indian Ocean","Indian Ocean");
	}
	
}
/* Scripts For the OnChange */

/* Function for the map */
function loadmapinfo(FROM,DST) {
	jQuery.post("/loadmapinfo.html",
		{ FROM: FROM, DST:DST },
		function(data){
			jQuery("#cruises-list").html(data);
		} 
	);
}

/* When the page is fully loaded  */
function changephoto(swfname) {

 jQuery.post("/cgi-bin/demo.sh/changephoto.html", 
		{ swfname: swfname }, 
		function(data){ 
			jQuery("#homediv").html(data);
		} 
	);
		
}

/*
 * Date Format 1.2.2
 * (c) 2007-2008 Steven Levithan <stevenlevithan.com>
 * MIT license
 * Includes enhancements by Scott Trenda <scott.trenda.net> and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */
var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date();
		if (isNaN(date)) throw new SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

function isValidDate(dateStr) {
// Date validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) 
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(dateStr + " Date is not in a valid format.")
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}

function isValidTime(timeStr) {
// Time validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute < 0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

function dateDiff( firstdate, seconddate ) {
var temp   = firstdate.split( "/" );
var a      = new Date(temp[2],temp[1],temp[0]);
    temp   = seconddate.split("/");
var b      = new Date(temp[2],temp[1],temp[0]);
var oneday = 86400000;
var days   = Math.ceil( ( b - a ) / ( oneday ) );
return days;
}

/* When the page is fully loaded  */
jQuery(document).ready(function() {
								
//	jQuery('#accordion').hide();
								
	/* Code Starts Here */
	/*
	var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var today = new Date();
	var lastDayOfMonth = new Date();
	lastDayOfMonth.setDate(MonthDays[lastDayOfMonth.getMonth()-1]);
	if(jQuery("#" + g_txtDate).length){
		jQuery("#" + g_txtDate).daterangepicker({
			presetRanges:[{ text:'Current Month', dateStart:function(){return today;}, dateEnd:function(){return lastDayOfMonth;} }],
			presets:{dateRange: 'Pick dates'},
			dateFormat:'dd/mm/yy',
			arrows:true,
			dateStart:Date(),
			prevLinkText:'',
			nextLinkText:'',
			datepickerOptions:{
				minDate:    new Date( today.getFullYear(),     today.getMonth(), today.getDate() ),
				defaultDate: +7
			}
		});
	} 
	*/
	/*set datepicker on search */
	
	var todaysdate  = new Date();
	var pickUpDate  = jQuery("#" + g_txtFromDate);
	var dropOffDate = jQuery("#" + g_txtToDate);    
    jQuery.datepicker.setDefaults( {minDate:new Date( todaysdate.getFullYear(), todaysdate.getMonth(), todaysdate.getDate() ),
                               maxDate:new Date( todaysdate.getFullYear() + 1, todaysdate.getMonth() + 6, todaysdate.getDate() ),
                               yearRange:todaysdate.getFullYear() + ':' + todaysdate.getFullYear() + 1,                               
                               dateFormat:'dd/mm/yy'} );
	if( pickUpDate.length ){
		jQuery(function(){
			pickUpDate.datepicker({							
				onSelect:function(dateText,inst){ 
							if ( dropOffDate.length ){  
								var new_date  = new Date();
								var datearray = dateText.split("/");
								new_date.setFullYear( datearray[ 2 ], datearray[ 1 ] - 1, datearray[ 0 ] );
								new_date.setDate( new_date.getDate() + 15 );
								//TODO find a better way to do the next line, since we already have reference to it through $ var.
								//if( document.getElementById( g_txtToDate ).value == "" || document.getElementById( g_txtToDate ).value == "To Date"){
									document.getElementById( g_txtToDate ).value = dateFormat( new_date, "%DD/%MM/%YYYY" );
									dropOffDate.datepicker( "disable" ); //hack to avoid showing the datepicker on setDate
									dropOffDate.datepicker( "setDate", new_date );
									dropOffDate.datepicker( "enable" ); //hack to avoid showing the datepicker on setDate
								//}
								jQuery("#errMsg").html("");
								if(jQuery("#" + g_txtPort).is(":hidden")){jQuery("#" + g_txtPort).show();}
								if(jQuery("#" + g_txtPortOfCall).is(":hidden")){jQuery("#" + g_txtPortOfCall).show();}
								//loadPorts();
							}
							return true;
						 }
			});
		});
	}
	///////////also besides onSelect of datepickers, also bind on blur
	//var old = (element.onclick) ? element.onclick : function () {};
	//element.onclick = function () {old(); spyOnUser()};	

	//////////
	
	if(dropOffDate.length ){ 
		jQuery(function() {	
			dropOffDate.datepicker({
				onSelect:function(dateText,inst){
					if(jQuery("#" + g_txtPort).is(":hidden")){jQuery("#" + g_txtPort).show();}
					if(jQuery("#" + g_txtPortOfCall).is(":hidden")){jQuery("#" + g_txtPortOfCall).show();}		
					//loadPorts();
				}
			}); 
		}); 
		/*
		dropOffDate.bind("blur", function(e){
			jQuery("#errMsg").html("");
			if(jQuery("#" + g_txtPort).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPort).show();}
			if(jQuery("#" + g_txtPortOfCall).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPortOfCall).show();}		
			//loadPorts();									  
		});
		jQuery("#txtDestin").bind("blur", function(e){		
			if(jQuery("#" + g_txtPort).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPort).show();}
			if(jQuery("#" + g_txtPortOfCall).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPortOfCall).show();}		
			//loadPorts();									  
		});	
		jQuery("#txtDurat").bind("blur", function(e){		
			if(jQuery("#" + g_txtPort).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPort).show();}
			if(jQuery("#" + g_txtPortOfCall).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPortOfCall).show();}		
			//loadPorts();									  
		});	
		jQuery("#txtShip").bind("blur", function(e){		
			if(jQuery("#" + g_txtPort).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPort).show();}
			if(jQuery("#" + g_txtPortOfCall).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPortOfCall).show();}		
			//loadPorts();									  
		});	
		jQuery("#txtFrom").bind("blur", function(e){		
			if(jQuery("#" + g_txtPort).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPort).show();}
			if(jQuery("#" + g_txtPortOfCall).is(":hidden") && jQuery(this).val() != ""){jQuery("#" + g_txtPortOfCall).show();}		
			//loadPorts();									  
		});		
		*/
	}
	

	if(document.getElementById('txtFrom') != null)
	{
		
		selectedDestination = showselected('txtDestin');
		loadDestinations();
		selectDestination('txtDestin',selectedDestination);
	}
	/* Code Ends Here */
	
	 if (document.images)
    {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "/images2/hospitality_floatinghotel_big1.jpg";
      image_url[1] = "/images2/hospitality_floatinghotel_big2.jpg";
      image_url[2] = "/images2/hospitality_floatinghotel_big3.jpg";
      image_url[3] = "/images2/hospitality_floatinghotel_big4.jpg";
	  image_url[4] = "/images2/hospitality_relax_big1.jpg";
      image_url[5] = "/images2/hospitality_relax_big2.jpg";
      image_url[6] = "/images2/hospitality_activities_big1.jpg";
      image_url[7] = "/images2/hospitality_activities_big2.jpg";
      image_url[8] = "/images2/hospitality_activities_big3.jpg";
      image_url[9] = "/images2/hospitality_activities_big4.jpg";

       var i = 0;
       for(i=0; i<=9; i++) {		   
         preload_image_object.src = image_url[i];
	   }
    }
	
	if(jQuery("txtDestin:selected").val() !== ""){
		loadPorts("txtDestin");
	}
});

function validate(){
	var tday;
	tday = new Date();
	if( jQuery("#" + g_txtFromDate).val() == '' || $("#" + g_txtToDate).val() == '' ){
		jQuery("#errMsg").html("Dates set for 30 days");
		jQuery("#txtFromDate").val($.datepicker.formatDate('dd/mm/yy', new Date()) );
		jQuery("#txtToDate").val(  $.datepicker.formatDate('dd/mm/yy', new Date(tday.getFullYear(),     tday.getMonth(), tday.getDate() + 31)));
	}
}