//Start Google Map Script
var map = null;
var geocoder = null;
var marker;
var html;
var positionScroll = 0;


function initialize(address, addressbubble, centername, city, brand) {
    if (brand != "HomeBased") {
        if (brand != "VoyageEnDirect") {
            var AddressResult = address.replace(/apstrph/gi, "'")
            var AddressBubbleResult = addressbubble.replace(/apstrph/gi, "'")
            var CityResult = city.replace(/apstrph/gi, "'")
            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map"));
                geocoder = new GClientGeocoder();
            }
            map.setMapType(G_NORMAL_MAP); // G_NORMAL_MAP on by default
            showAddress(AddressResult, AddressBubbleResult, centername, CityResult);
        }
    }
}

function showAddress(address, addressbubble, centername, city) {
    if (geocoder) {
        geocoder.getLatLng(address, function(point) {
            if (!point) {
                showCity(city, addressbubble, centername);
                //alert(address + " not found");
	        } else {
	            map.setCenter(point, 15);  // second param sets zoom level
	            createMarker(point, addressbubble, centername);
	            mapfeatures();
	        }
        });
    }
}

function showCity(city, addressbubble, centername) {
    if (geocoder) {
        geocoder.getLatLng(city, function(point) {
            map.setCenter(point, 15);
            createMarker(point, addressbubble, centername);
            mapfeatures();
        });
    }
}

function mapfeatures() {
    map.enableGoogleBar();
    map.enableDoubleClickZoom();
    map.enableContinuousZoom();
    map.enableScrollWheelZoom();
    map.enableDragging();
    map.addControl(new GSmallZoomControl());
    map.enableInfoWindow();
}
	
function createMarker(point, addressbubble, centername) {
    //alert("the point is: " + point);
    var thePoint = String(point);
    var thePointLength = thePoint.length;
    var thePointComma = thePoint.indexOf(",");
    var theLat = thePoint.substring(1,thePointComma-1);
    var theLon = thePoint.substring(thePointComma+2,thePointLength-1);
    var addressresult = addressbubble.replace(/apstrph/gi, "'")
    //
    marker = new GMarker(new GLatLng(theLat, theLon));
    //marker = new GMarker(new GLatLng(thePoint));
    //var theLat = new GLatLng.lat();
    map.addOverlay(marker);
    marker.setImage('images/logos/roses.png');
    map.setCenter(point, 15);
    //
}
//End Google Map Script

function popUp(page, name, details) {
	var newWin = window.open(page, name, details);
	newWin.focus();
	return false;
}

function showPanofull(mapid,pid) {
	var codestr;
	var swidth = screen.width;
	if (mapid <= 0)
	{
		var win = window.open('http://delivery.vrxstudios.com/50195/Frame.htm?id=' + pid ,'vrxmapviewer','height=720,width=600,menubar=no,top=5,scrollbars=yes,resizable=no,left=0');
	}
	else
	{
		var win = window.open('http://display.maxvr.com/vrxstudios/integration.asp?mapid=' + mapid ,'vrxmapviewer','height=720,width=567,menubar=no,top=5,scrollbars=no,resizable=no,left=0');
	}
	
	win.focus();
}

function showPanofullPrincess(pid) {
    if (pid > 100) {
        var win = window.open('http://delivery.vrxstudios.com/50195/Frame.htm?id=' + pid ,'vrxmapviewer','height=720,width=600,menubar=no,top=5,scrollbars=yes,resizable=no,left=0');
    } else {
        var win = window.open('http://delivery.vrxstudios.com/csc/vrxFrame.asp?id=' + pid ,'VrxStudiosPopUpFrame','height=766,width=600,scrollbars=yes,toolbar=no,menubar=no, resizable=yes');
    }
    win.focus();
}

function openVRXThumbFrame(ShipID)
{
    var win = window.open('http://delivery.vrxstudios.com/csc/vrxFrame.asp?id=' + ShipID,'VrxStudiosPopUpFrame','height=766,width=600,scrollbars=no,toolbar=no,menubar=no');
    win.focus();
}

function openVRXThumbFrameUpdated(ShipID)
{
    var win = window.open('http://delivery.vrxstudios.com/50195/frame.htm?id=' + ShipID + '&VrxFrameHeight=900&VrxFrameWidth=600','VrxStudiosPopUpFrame','height=900,width=600,scrollbars=yes,toolbar=no,menubar=no');
    win.focus();
}

function setURL(page, qs) {
    var url;
    if (qs == "") {
        url = page;
    }
    else {
        url = page + "?" + qs;
    }
    
	window.navigate(url);
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		canmap_01_ImageMap_13_over = newImage("images/generic/Map/canmap_01-ImageMap_13_over.gif");
		canmap_01_ImageMap_10_over = newImage("images/generic/Map/canmap_01-ImageMap_10_over.gif");
		canmap_01_ImageMap_11_over = newImage("images/generic/Map/canmap_01-ImageMap_11_over.gif");
		canmap_01_ImageMap_09_over = newImage("images/generic/Map/canmap_01-ImageMap_09_over.gif");
		canmap_01_ImageMap_08_over = newImage("images/generic/Map/canmap_01-ImageMap_08_over.gif");
		canmap_01_ImageMap_07_over = newImage("images/generic/Map/canmap_01-ImageMap_07_over.gif");
		canmap_01_ImageMap_06_over = newImage("images/generic/Map/canmap_01-ImageMap_06_over.gif");
		canmap_01_ImageMap_05_over = newImage("images/generic/Map/canmap_01-ImageMap_05_over.gif");
		canmap_01_ImageMap_04_over = newImage("images/generic/Map/canmap_01-ImageMap_04_over.gif");
		canmap_01_ImageMap_03_over = newImage("images/generic/Map/canmap_01-ImageMap_03_over.gif");
		canmap_01_ImageMap_02_over = newImage("images/generic/Map/canmap_01-ImageMap_02_over.gif");
		canmap_01_ImageMap_01_over = newImage("images/generic/Map/canmap_01-ImageMap_01_over.gif");
		preloadFlag = true;
	}
}

function layer(id){
	var res;
	if(document.getElementById) {
		res = document.getElementById(id);
	}
	if(document.all) {
		res = document.all[id];
	}
	if (res) {
		return res.style;
	} else {
		return null;
	}
}

var nsx;
var nsy;

if (!document.all) {
	document.captureEvents(Event.MOUSEMOVE);	
	document.onmousemove = get_mouse;
}

function get_mouse(e) {
	nsx = e.pageX - 10;
	nsy = e.pageY + 5;
}

function ShowToolTip(myID) {
	var hlp=layer("TIP" + myID);
	if (hlp) {
		if (document.all) {
			nsy=event.y+document.body.scrollTop;
			nsx=event.x+document.body.scrollLeft;
		}
		hlp.top=nsy+10;
		hlp.left=(nsx>710?nsx-150:440);
		hlp.visibility='visible';
	}
}


/* The absolute y direction */
function ShowToolTipMove(myID, myTop) {
	var hlp=layer("TIP" + myID);
	if (hlp) {
		if (document.all) {
			nsy=event.y+document.body.scrollTop;
			nsx=event.x+document.body.scrollLeft;
		}
		hlp.top=myTop;
		hlp.left=(nsx>610?nsx-350:140);
		hlp.visibility='visible';
	}
}

function HideToolTip(myID) {
	var hlp=layer("TIP" + myID);
	if(hlp) {
		hlp.visibility='hidden';
	}
}

function setChildList(aListBoxChild, aListBoxParent, aArray, aShowAllDefault, aDefaultText, aDefaultValue) {
	var parentSelected = aListBoxParent.options[aListBoxParent.selectedIndex].value;
	var index = 0;
	var indexOffset = 0;

	for(x = aListBoxChild.options.length; x >= 0; x--) {
		aListBoxChild.options[x] = null;
	}
	
	if (aListBoxParent.selectedIndex > 0) {
		aListBoxChild.options[indexOffset] = new Option(aDefaultText, aDefaultValue);
		indexOffset++;
	}
	
	if (aShowAllDefault == 1 && aListBoxParent.selectedIndex == 0) {
	
		for(x = 0; x<aArray.length; x++) {
			aListBoxChild.options[index + indexOffset] = new Option(aArray[x][1],aArray[x][1]);
			index++;
		}
		
	} else if (aShowAllDefault == 1 && parentSelected == "Both") {
		
		for(x = 0; x<aArray.length; x++) {
			if (aArray[x][0] == "Celebrity Cruises" || aArray[x][0] == "Royal Caribbean International") {
				aListBoxChild.options[index + indexOffset] = new Option(aArray[x][1],aArray[x][1]);
				index++;
			}
		}		
	
	} else {
	
		for(x = 0; x<aArray.length; x++) {
			if (parentSelected == aArray[x][0]) {
				aListBoxChild.options[index + indexOffset] = new Option(aArray[x][1],aArray[x][1]);
				index++;
			}
		}
	}
}

//Section - Cruise Search dropdowns functionality
function populateTravellers(aDDL1, aDDL2, aFirstValue) {
    var selectedValue;
    var defaultValue
    var maxValue;
    
    selectedValue = aDDL1.value
    defaultValue = aDDL2.value
    maxValue = 5 - selectedValue - aFirstValue;
    
    aDDL2.options.length = 0;
    
    for(x = 0; x <= maxValue; x++) {
        aDDL2.options[x] = new Option(x + aFirstValue, x + aFirstValue);
    }
    
    aDDL2.value = defaultValue
}

function PopulateDDLBirthDay(aDDL, aHiddenDay, aSelectedMonth, aSelectedYear) {
    var selectedDay;
    var selectedMonth;
    var selectedYear;
    var date = new Date();
    var maxDay = 0
    
    selectedDay = aDDL.value
    
    if (aSelectedMonth != '') {
        selectedMonth = parseInt(aSelectedMonth)    
    }
    else {
        selectedMonth = 0
    }
    
    if (aSelectedYear != '') {
        selectedYear = parseInt(aSelectedYear)
    }
    else {
        selectedYear = date.getFullYear()
    }
    
    date.setFullYear(selectedYear, selectedMonth, 0)
    maxDay = date.getDate()
    aDDL.options.length = 0;
    aDDL.options[0] = new Option('- Select -', '')
    
    for(x = 1; x <= maxDay; x++) {
        aDDL.options[x] = new Option(x, x);
    }
    
    aDDL.value = selectedDay
    aHiddenDay.value = selectedDay
}

function populateDestination(setDefault) {
    var ddlDestination;
    var index = 0;
    var itemExists;
    
	ddlDestination = document.forms[0].ddlDestination;  
	
	ddlDestination.options.length = 0; 	
	
    ddlDestination.options[index] = new Option(aArray[index][0],"");
	index++;
		
	for(x = 2; x<aArray.length; x++) {
	    itemExists = 0;			    
        for(j = ddlDestination.options.length; j >= 0; j--) {
		    if (ddlDestination.options[j]!=null){
		        if (ddlDestination.options[j].value == aArray[x][0]){
		            itemExists = 1;	
		            break;	                    
		        }
		    }
	    }
        if (itemExists == 0 ) {
            ddlDestination.options[index] = new Option(aArray[x][0],aArray[x][0]);
	        index++;
	    }		
	}	
	if (aDefaults[0][0]!="" && setDefault == 1){
	    ddlDestination.value = aDefaults[0][0];	    
	}
	
	document.forms[0].hiddenDestination.value=ddlDestination.value;	
}


function populateSubdestination(setDefault) {	
	var index = 0;
	var j = 0;
	
	var ddlDestination;
	var ddlSubdestination;
	
	var itemExists;
	var arrSubDest = new Array();
	
    ddlDestination = document.forms[0].ddlDestination;   
	ddlSubdestination = document.forms[0].ddlSubDestination;   		    		
	if (ddlSubdestination!=null)
	{
	    ddlSubdestination.options.length = 0; 
    	
	    if (ddlDestination.selectedIndex==0){
            ddlSubdestination.options[index] = new Option(aArray[0][1],"");   	    
	    }
        else
        { 
            ddlSubdestination.options[index] = new Option(aArray[1][1],"");         
            
            for(x = 2; x<aArray.length; x++) {      
                if (ddlDestination.value == aArray[x][0]) {  
		            itemExists = 0;			    
                    for(j = 0; j < arrSubDest.length; j++) {
			            if (arrSubDest[j]!=null){
		                    if (arrSubDest[j] == aArray[x][1]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
			            }
	                }			    
		            if (itemExists == 0) {		       		            
			            arrSubDest[index] = aArray[x][1];
			            index++;		             
		            }	                	                    
                }
            }	        
           
            arrSubDest.sort();
            for(j = 0; j < arrSubDest.length; j++) {	        
	            ddlSubdestination.options[j+1] = new Option(arrSubDest[j],arrSubDest[j]);			
            }	
        }
	    if (aDefaults[0][1]!="" && setDefault == 1){
	        ddlSubdestination.value = aDefaults[0][1];
	    }	
	    document.forms[0].hiddenSubDestination.value=ddlSubdestination.value;	
	}	
}


function populatePort(setDefault) {	
	var index = 0;
	var j = 0;
		
	var ddlDestination;	
	var ddlSubdestination;	
	var ddlDeparturePort;
	
	var itemExists;  
    var arrPorts = new Array();
        
    ddlDeparturePort = document.forms[0].ddlDeparturePort;   		   
    if (ddlDeparturePort!=null)	{
        ddlDestination = document.forms[0].ddlDestination;   
	    ddlSubdestination = document.forms[0].ddlSubDestination;   		

	    ddlDeparturePort.options.length = 0; 
    	    	
	    if (ddlDestination.selectedIndex==0 ){
            ddlDeparturePort.options[index] = new Option(aArray[0][2],"");
	    }
	    else{
	        ddlDeparturePort.options[index] = new Option(aArray[1][2],"");       
            
            for(x = 2; x<aArray.length; x++) {      
                if ((ddlDestination.value == aArray[x][0]) && (ddlSubdestination.value == aArray[x][1] || ddlSubdestination.selectedIndex == 0)) {
                
		            itemExists = 0;			    
                    for(j = 0; j < arrPorts.length; j++) {
			            if (arrPorts[j]!=null){
		                    if (arrPorts[j] == aArray[x][2]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
			            }
	                }			    
		            if (itemExists == 0) {		       		            
			            arrPorts[index] = aArray[x][2];
			            index++;		             
		            }	                	                    
                }
            }	               
    	    
            arrPorts.sort();
            for(j = 0; j < arrPorts.length; j++) {	        
	            ddlDeparturePort.options[j+1] = new Option(arrPorts[j],arrPorts[j]);			
            }	
	    }
        
        if (aDefaults[0][2]!=""  && setDefault == 1){
	        ddlDeparturePort.value = aDefaults[0][2]
	    }	
	    document.forms[0].hiddenDeparture.value=ddlDeparturePort.value;   
	}
}

function populateCruiseline(setDefault) {	
	var index = 0;
	var j = 0;
	
    var ddlDestination;
    var ddlSubdestination;
    var ddlDeparturePort;
	var ddlCruiseline;		
	
	var arrCruiseline = new Array();	
	
	var itemExists;
    
    ddlDestination = document.forms[0].ddlDestination;   	
    ddlSubdestination = document.forms[0].ddlSubDestination;   	    
    ddlDeparturePort = document.forms[0].ddlDeparturePort;
    ddlCruiseline = document.forms[0].ddlCruiseLine;   
    	
	ddlCruiseline.options.length = 0; 	   	
    ddlCruiseline.options[index] = new Option(aArray[index][3],"");
	
    for(x = 2; x<aArray.length; x++) {      
        if (ddlSubdestination!=null && ddlDeparturePort!=null) {
            if (((ddlDestination.value == aArray[x][0] || ddlDestination.selectedIndex == 0) && (ddlSubdestination.value == aArray[x][1] || ddlSubdestination.value == "") && (ddlDeparturePort.value == aArray[x][2] || ddlDeparturePort.value=="")) ||  x==0 || ddlDestination.options.length == 0) {			   		    
            
		        itemExists = 0;			    
                for(j = 0; j < arrCruiseline.length; j++) {
			        if (arrCruiseline[j]!=null){
		                if (arrCruiseline[j] == aArray[x][3]){
		                    itemExists = 1;	
		                    break;	                    
		                }
			        }
	            }			    
		        if (itemExists == 0) {		       		            
			        arrCruiseline[index] = aArray[x][3];
			        index++;		             
		        }	                	                    
            }        
        }
        else{
            if (((ddlDestination.value == aArray[x][0] || ddlDestination.selectedIndex == 0) ) ||  x==0 || ddlDestination.options.length == 0) {			   		    
            
		        itemExists = 0;			    
                for(j = 0; j < arrCruiseline.length; j++) {
			        if (arrCruiseline[j]!=null){
		                if (arrCruiseline[j] == aArray[x][3]){
		                    itemExists = 1;	
		                    break;	                    
		                }
			        }
	            }			    
		        if (itemExists == 0) {		       		            
			        arrCruiseline[index] = aArray[x][3];
			        index++;		             
		        }	                	                    
            }            
        }
        
        
    }	               
	    
    arrCruiseline.sort();
    for(j = 0; j < arrCruiseline.length; j++) {	        
	    ddlCruiseline.options[j+1] = new Option(arrCruiseline[j],arrCruiseline[j]);			
    }		

    if (aDefaults[0][3]!=""  && setDefault == 1){
	    ddlCruiseline.value = aDefaults[0][3];
	}
	
	document.forms[0].hiddenCruiseline.value=ddlCruiseline.value;	
}

function populateShip(setDefault) {	
	var index = 0;
	var j = 0;
	
    var ddlDestination;
    var ddlSubdestination;
    var ddlDeparturePort;
	var ddlCruiseline;	
	var ddlShip;	
		
	var arrShip = new Array();
	var itemExists;
   
    ddlDestination = document.forms[0].ddlDestination;   	
    ddlSubdestination = document.forms[0].ddlSubDestination;   	    
    ddlDeparturePort = document.forms[0].ddlDeparturePort;
    ddlCruiseline = document.forms[0].ddlCruiseLine;   
    ddlShip = document.forms[0].ddlShip;   
  
	ddlShip.options.length = 0; 
	
	if (ddlCruiseline.selectedIndex <=0){
    	ddlShip.options[index] = new Option(aArray[0][4],"");	
	}
	else{
	   ddlShip.options[index] = new Option(aArray[1][4],"");	
        
       for(x = 0; x<aArray.length; x++) {    
           if (ddlSubdestination!=null && ddlDeparturePort!=null){
                if ((ddlDestination.value == aArray[x][0] || ddlDestination.value == "") && (ddlSubdestination.value == aArray[x][1] || ddlSubdestination.value == "") && (ddlDeparturePort.value == aArray[x][2] || ddlDeparturePort.value == "") && ddlCruiseline.value == aArray[x][3]) {			   	

	                itemExists = 0;			    
                    for(j = 0; j < arrShip.length; j++) {
		                if (arrShip[j]!=null){
		                    if (arrShip[j] == aArray[x][4]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
		                }
	                }			    
	                if (itemExists == 0) {		       		            
		                arrShip[index] = aArray[x][4];
		                index++;		             
	                }	               	                    
                }
           }
           else{ 
            
            if ((ddlDestination.value == aArray[x][0] || ddlDestination.value == "")  && ddlCruiseline.value == aArray[x][3]) {			   	

	                itemExists = 0;			    
                    for(j = 0; j < arrShip.length; j++) {
		                if (arrShip[j]!=null){
		                    if (arrShip[j] == aArray[x][4]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
		                }
	                }			    
	                if (itemExists == 0) {		       		            
		                arrShip[index] = aArray[x][4];
		                index++;		             
	                }	               	                    
                }
            }
        }	     
    	arrShip.sort();
        for(j = 0; j < arrShip.length; j++) {	        
	        ddlShip.options[j+1] = new Option(arrShip[j],arrShip[j]);			
        }			
	
	    if (aDefaults[0][4]!="" && setDefault == 1){	   
		    ddlShip.value = aDefaults[0][4];
	    }			
	    document.forms[0].hiddenShip.value=ddlShip.value;
   }      	
}

function populateMonth() {
	var index = 0;	
	var x;j;
    var ddlDestination;
    var ddlSubDestination;
    var ddlMonth;
    var ddlMonthTo;
    
    var arrMonth = new Array();
    
    var itemExists;
    
    ddlDestination = document.forms[0].ddlDestination;   	
    ddlSubDestination = document.forms[0].ddlSubDestination;   	
    ddlMonth = document.forms[0].ddlMonth;   
    ddlMonthTo = document.forms[0].ddlMonthTo;   
    
	if (ddlMonth!=null){	
	    ddlMonth.options.length = 0; 
	    if (ddlMonthTo!=null){ddlMonthTo.options.length = 0;}	    
    	
	    ddlMonth.options[0] = new Option(aMonth[0][2],"");
        if (ddlMonthTo!=null){ddlMonthTo.options[0] = new Option(aMonth[0][2],"");}              

        for(x = 1; x<aMonth.length; x++) {
            if (ddlSubDestination!=null){
                if ((ddlDestination.value == aMonth[x][0] || ddlDestination.selectedIndex == 0) && (ddlSubDestination.value == aMonth[x][1] || ddlSubDestination.selectedIndex == 0)) {	        
		            itemExists = 0;			    
                    for(j = 0; j < arrMonth.length; j++) {
			            if (arrMonth[j]!=null){
		                    if (arrMonth[j] == aMonth[x][2]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
			            }
	                }			    
		            if (itemExists == 0) {		                		            
			            arrMonth[index] = aMonth[x][2];			    
			            index++;		             
		            }	                	                    
                }            
        }
        
         else{
                if (ddlDestination.value == aMonth[x][0] || ddlDestination.selectedIndex == 0 ) {	        
		            itemExists = 0;			    
                    for(j = 0; j < arrMonth.length; j++) {
			            if (arrMonth[j]!=null){
		                    if (arrMonth[j] == aMonth[x][2]){
		                        itemExists = 1;	
		                        break;	                    
		                    }
			            }
	                }			    
		            if (itemExists == 0) {		                		            
			            arrMonth[index] = aMonth[x][2];			    
			            index++;		             
		            }	                	                    
                }                        
            }            
        }	     
         
        for(j = 0; j < arrMonth.length; j++) {	        
	        ddlMonth.options[j+1] = new Option(arrMonth[j],arrMonth[j]);	    	 
	         if (ddlMonthTo!=null){ddlMonthTo.options[j+1] = new Option(arrMonth[j],arrMonth[j]);}
	    }
	    document.forms[0].hiddenMonthYearFrom.value=ddlMonth.value;      
	     if (ddlMonthTo!=null){document.forms[0].hiddenMonthYearTo.value=ddlMonthTo.value;}
	}   
}


function populateDay() {
	var x;
    var ddlDay;
    var ddlMonth;    
    var daysInMonth;
    
    ddlMonth = document.forms[0].ddlMonth;   
    ddlDay = document.forms[0].ddlDay;   
    if (ddlDay!=null){
    
	    ddlDay.options.length = 0;
    	
        ddlDay.options[0] = new Option(aMonth[0][3],"");
        
        if (ddlMonth.selectedIndex > 0){       
            for(x = 0; x<aMonth.length; x++) {
		        if (ddlMonth.value == aMonth[x][2]) {	
		            daysInMonth = aMonth[x][3];
		            break;				   			
		        }    				   			
	        }
	        for(x = 1; x<=daysInMonth; x++) {		
                ddlDay.options[x] = new Option(x,x);
	        }      	
        }		   	
        document.forms[0].hiddenDayFrom.value=ddlDay.value;
    }
}

function populateDayTo() {
	var x;
    var ddlDayTo;
    var ddlMonthTo;
    var daysInMonth;
    
    ddlMonthTo = document.forms[0].ddlMonthTo;   
    ddlDayTo = document.forms[0].ddlDayTo;      

	ddlDayTo.options.length = 0;	
    ddlDayTo.options[0] = new Option(aMonth[0][3],"");

    if (ddlMonthTo.selectedIndex > 0){   
        for(x = 0; x<aMonth.length; x++) {
		    if (ddlMonthTo.value == aMonth[x][2]) {	
		        daysInMonth = aMonth[x][3];
		        break;				   			
		    }    				   			
	    }   	
	    for(x = 1; x<=daysInMonth; x++) {		
            ddlDayTo.options[x] = new Option(x,x);
	    }         
    }	
    document.forms[0].hiddenDayTo.value=ddlDayTo.value;
}

function populateDuration() {
	var index = 0;	
	var j;
	var x;
    var ddlDuration;    
    
    ddlDuration = document.forms[0].ddlDuration;          		
    if (ddlDuration!=null){
        
	    ddlDuration.options.length = 0;
    	
        ddlDuration.options[index] = new Option(aDuration[index][0],aDuration[index][1]);
	    index++;
    	
	    for(x = 0; x<aDuration.length; x++) {	
	        ddlDuration.options[x] = new Option( aDuration[x][0], aDuration[x][1]);						   			
	    }      
        document.forms[0].hiddenDuration.value=ddlDuration.value;
    }
}
 

//Section - Cruise Search dropdowns - Cascading refresh of dropdowns with dependencies
function RefreshDestination(setdefault) {       
    
    populateDestination(setdefault);
    populateSubdestination(setdefault);    
    populatePort(setdefault);
   
    populateDuration();    
   
    populateMonth();     
    populateDay();      
    
    populateCruiseline();
    
    populateShip();  
}

function RefreshSubDestination() {
   
    populateSubdestination();
    populatePort();
        
    populateCruiseline();
    populateShip();
    
    populateMonth();    
}

function RefreshPort() {
    
    populatePort();
    populateCruiseline();
    populateShip();
    
    populateMonth();    
}

function RefreshCruiseline() {    
    populateCruiseline();
    populateShip();    
}


//

function HideShowRange() {
    var lblFrom;
    var lblTo;
    lblFrom = document.getElementById("lblFrom"); 
    lblTo = document.getElementById("lblTo"); 
    
    if (document.forms[0].rblDate[1].checked ) {
	    document.forms[0].ddlMonthTo.style.display='';
	    document.forms[0].ddlDayTo.style.display='';
	    document.forms[0].hiddenRange.value = "1"	   	   
	       
	    lblFrom.style.display='';	    
	    lblTo.style.display='';
	    populateDayTo();
	    
    } else {
	    document.forms[0].ddlMonthTo.style.display='none';
	    document.forms[0].ddlDayTo.style.display='none';
	    document.forms[0].hiddenRange.value = "0";
	    
	    lblFrom.style.display='none';	    
	    lblTo.style.display='none';
	    	   
    }
    return 1;
}
    


function ClearCTLVKey()
 {
     if (window.event.ctrlKey && window.event.keyCode == 86)
         {    
           window.event.keyCode=0;            
         }   
 }
 
 function ClearRightMouseKey(ctrlID)
 {
     if (event.button == 2)
         {   
            
           var txt;           
           txt = document.getElementById(ctrlID);   
         
           if (txt!=null){
            txt.oncontextmenu=new Function('return false;');           
           }          
           
         }   
}
 
function setHiddenProvince() {
	if (document.forms[0].ucPersonal_ddlState.style.display == "") {
		document.forms[0].ucPersonal_hiddenProvince.value = document.forms[0].ucPersonal_ddlState.options[document.forms[0].ucPersonal_ddlState.selectedIndex].value;
		document.forms[0].ucPersonal_txtState.value = document.forms[0].ucPersonal_ddlState.options[document.forms[0].ucPersonal_ddlState.selectedIndex].value;
	} else {
		document.forms[0].ucPersonal_hiddenProvince.value = document.forms[0].ucPersonal_txtState.value;
	}
}

function setHiddenProvinceBook(aDdlProvince, aTxtProvince, aHiddenProvince) {
	if (aDdlProvince.style.display == "") {
		aHiddenProvince.value = aDdlProvince.options[aDdlProvince.selectedIndex].value;
		aTxtProvince.value = aDdlProvince.options[aDdlProvince.selectedIndex].value;
	} else {
		aHiddenProvince.value = aTxtProvince.value;
	}
}

function setHiddenProvinceJoin() {
	if (document.forms[0].ddlState.style.display == "") {
		document.forms[0].hiddenProvince.value = document.forms[0].ddlState.options[document.forms[0].ddlState.selectedIndex].value;
		document.forms[0].txtState.value = document.forms[0].ddlState.options[document.forms[0].ddlState.selectedIndex].value;
	} else {
		document.forms[0].hiddenProvince.value = document.forms[0].txtState.value;
	}
}

function setChildListProvince(aListBoxChild, aListBoxParent, aTextBoxChild, aArray) {
	var parentSelected = aListBoxParent.options[aListBoxParent.selectedIndex].value;
	var index = 0;
	
	// Clear the list
	for(x = aListBoxChild.options.length; x >= 0; x--) {
		aListBoxChild.options[x] = null;
	}
	
	// "Canada" or "United States" is selected
	if (aListBoxParent.options[aListBoxParent.selectedIndex].value == "CA" || aListBoxParent.options[aListBoxParent.selectedIndex].value == "US") {

		aListBoxChild.style.display = "";
		aTextBoxChild.style.display = "none";
		
		for(x = 0; x<aArray.length; x++) {
			if (parentSelected == aArray[x][0]) {
				aListBoxChild.options[index] = new Option(aArray[x][2],aArray[x][1]);
				index++;
			}
		}
				
	// Any other country is selected.  Hide the list, show the textbox
	} else {
		aTextBoxChild.value = "";
		aListBoxChild.style.display = "none";
		aTextBoxChild.style.display = "";
	}
}

function setChildListProvinceBook(aListBoxChild, aListBoxParent, aTextBoxChild, aArray, aDefaultText, aDefaultValue) {
	var parentSelected = aListBoxParent.options[aListBoxParent.selectedIndex].value;
	var index = 0;
	
	// Clear the list
	for(x = aListBoxChild.options.length; x >= 0; x--) {
		aListBoxChild.options[x] = null;
	}
	
	// "Canada" or "United States" is selected
	if (aListBoxParent.options[aListBoxParent.selectedIndex].value == "CA" || aListBoxParent.options[aListBoxParent.selectedIndex].value == "US") {

		aListBoxChild.style.display = "";
		aTextBoxChild.style.display = "none";
		
		aListBoxChild.options[0] = new Option(aDefaultText, aDefaultValue);
		index++;
		
		for(x = 0; x<aArray.length; x++) {
			if (parentSelected == aArray[x][0]) {
				aListBoxChild.options[index] = new Option(aArray[x][2],aArray[x][1]);
				index++;
			}
		}
				
	// Any other country is selected.  Hide the list, show the textbox
	} else {
		aTextBoxChild.value = "";
		aListBoxChild.style.display = "none";
		aTextBoxChild.style.display = "";
	}
}

function allowNumbers(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    } else {   
        return true;
    }
} 

function ValidateCustCard(sender, args) {
    var myCustNum = document.getElementById(sender.controltovalidate).value;
    var myLen = myCustNum.length;
    var myRetVal = (myLen == 0);
    var mySum = 0;
    var myMul = 1; 
    var myDigit = 0;
    var myProduct = 0;
    
    if (myLen == 9 || myLen == 16) {
        for (i = 0; i < myLen; i++)  {
            myDigit = myCustNum.substring(myLen - i - 1, myLen - i);
            myProduct = parseInt(myDigit, 10) * myMul;
            if (myProduct >= 10)
                mySum += (myProduct % 10) + 1;
            else
                mySum += myProduct;
            if (myMul == 1) { myMul++; } else { myMul--; }
        }
        myRetVal = ((mySum % 10) == 0);
    }          
    args.IsValid = myRetVal;
}

/* The absolute position away from the mouse */
function ShowToolTipAbsoluteRelative(myID, myTop, myLeft) {
	var hlp=layer("TIP" + myID);
	if (hlp) {
		if (document.all) {
			nsy=event.y+document.body.scrollTop;
			nsx=event.x+document.body.scrollLeft;
		}
		hlp.top=nsy+myTop;
		hlp.left=nsx+myLeft;
		hlp.visibility='visible';
	}
}

function setChildListProvinceJoinForm(aValue, aListBoxChild, aDefault, aArray) 
{
    var parentSelected = aValue
    var index = 1;
	
    // Clear the list
    for(x = aListBoxChild.options.length; x >= 0; x--) 
    {
        aListBoxChild.options[x] = null;
    }
	
	       	
    // "Canada" or "United States" is selected
    aListBoxChild.options[0] = new Option(aDefault, aDefault);
    
        for(x = 0; x<aArray.length ; x++) 
        {
	        if (parentSelected == aArray[x][0]) 
	        {
		        aListBoxChild.options[index] = new Option(aArray[x][2],aArray[x][1]);
		        index++;
	        }
        }
				
    // Any other country is selected.  Hide the list, show the textbox
	//document.getElementById('a').style.width = "50%"
	aListBoxChild.style.width = "256"
}

function StateValid(server, args) {
    if (document.getElementById('ddlState').selectedIndex == 0) {
        args.IsValid = false;
    } else {
        args.IsValid = true;
    }
}

function setInterestListVisible(aControl) {
    var myTR = document.getElementById('trHome');
    if (aControl == 'CA') {
        myTR.style.display='none';
    } else {
        myTR.style.display='';
    }
}

// Postal Code User Control support
function postalCodeCountryChange(aControl, aCountryCode)
{
    var valPostalCodeCanadian = document.getElementById(aControl + "_valPostalCodeCanadian");
    var valPostalCodeUS = document.getElementById(aControl + "_valPostalCodeUS");
    var valPostalCodeIntl = document.getElementById(aControl + "_valPostalCodeIntl");
    
    var hidPostalCodeCanadianEnabled = document.getElementById(aControl + "_hidPostalCodeCadEnabled");
    var hidPostalCodeUsEnabled = document.getElementById(aControl + "_hidPostalCodeUsEnabled");
    var hidPostalCodeIntlEnabled = document.getElementById(aControl + "_hidPostalCodeIntlEnabled");
    
    switch(aCountryCode)
    {
        case "CA":
            ValidatorEnable(valPostalCodeCanadian, true);
            hidPostalCodeCanadianEnabled.value = "true";
            ValidatorEnable(valPostalCodeUS, false);
            hidPostalCodeUsEnabled.value = "false";
            ValidatorEnable(valPostalCodeIntl, false);
            hidPostalCodeIntlEnabled.value = "false";
            break;
        case "US":
            ValidatorEnable(valPostalCodeCanadian, false);
            hidPostalCodeCanadianEnabled.value = "false"
            ValidatorEnable(valPostalCodeUS, true);
            hidPostalCodeUsEnabled.value = "true";
            ValidatorEnable(valPostalCodeIntl, false);
            hidPostalCodeIntlEnabled.value = "false";
            break;
        default:
            ValidatorEnable(valPostalCodeCanadian, false);
            hidPostalCodeCanadianEnabled.value = "false"
            ValidatorEnable(valPostalCodeUS, false);
            hidPostalCodeUsEnabled.value = "false";
            ValidatorEnable(valPostalCodeIntl, true);
            hidPostalCodeIntlEnabled.value = "true";
    }
}

var ContestCookie;

function CheckContestThickBoxDate(aIsWithinContestDate, aIsECSC, aCulture) {
    if (aIsWithinContestDate == 'True') {
        Show_Contest_ThickBox(aIsECSC, aCulture);
    }
}

//Check to see if cookie exists
function Show_Contest_ThickBox(aIsECSC, aCulture) {
    ContestCookie = ReadCookie("ShownThickBox");
    if (DetectMobile() == false) {
        if (ContestCookie == '' || ContestCookie == null) {
            if (aIsECSC == 'False') {
                if (aCulture == 'en-CA') 
                    tb_show('dvHiddenModalContentEN', 'TB_inline?height=300&width=520&inlineId=dvHiddenModalContentEN&modal=true', false);
                else
                    tb_show('dvHiddenModalContentFR', 'TB_inline?height=300&width=520&inlineId=dvHiddenModalContentFR&modal=true', false);
            }
        }
    }
}

function DetectMobile() {
    var deviceIphone = "iphone";
    var deviceIpod = "ipod";
    var devicePalm = "palm";
    var deviceBB = "blackberry";
    var deviceWinMob = "windows ce";
    var deviceAndroid = "android";
    var deviceS60 = "series60";
    var deviceSymbian = "symbian";
    var engineWebKit = "webkit";

    var uagent = navigator.userAgent.toLowerCase();
    
    if (uagent.search(deviceIpod) > -1)
        return true;
    else if (uagent.search(deviceIphone) > -1)
        return true;
    else if (uagent.search(devicePalm) > -1)
        return true;
    else if (uagent.search(deviceBB) > -1)
        return true;
    else if (uagent.search(deviceWinMob) > -1)
        return true;
    else if (uagent.search(deviceAndroid) > -1)
        return true;
    else if (uagent.search(engineWebKit) > -1) {
        if ((uagent.search(deviceS60) > -1 || uagent.search(deviceSymbian) > -1))
            return true;
        else
            return false;
    }
    else
       return false;
}

function ReadCookie(n) {
    var cookiecontent = new String();
    if(document.cookie.length > 0) {
	    var cookiename = n+ '=';
	    var cookiebegin = document.cookie.indexOf(cookiename);
	    var cookieend = 0;
	    if(cookiebegin > -1) {
		    cookiebegin += cookiename.length;
		    cookieend = document.cookie.indexOf(";",cookiebegin);
		    if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		    cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		    }
	    }
    return unescape(cookiecontent);
}

function SetCookie() { //NAME, COOKIE, DAYS
    if(arguments.length < 2) { return; }
    var n = arguments[0];
    var v = arguments[1];
    var d = 0;
    if(arguments.length > 2) { d = parseInt(arguments[2]); }
    var exp = '';
    if(d > 0) {
    	var now = new Date();
    	then = now.getTime() + (d * 24 * 60 * 60 * 1000);
    	now.setTime(then);
    	exp = '; expires=' + now.toGMTString();
	}
    document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
}

function ShowContest(aCulture) {
    if (aCulture == 'EN')
        window.location = 'go.aspx?url=Join&culture=enCA';
    else 
        window.location = 'go.aspx?url=Join&culture=frCA';
}

function Contest_AddCookie(Condition) {
    SetCookie (Condition, "Selected", 14);
}

function EnterKeyPressFunction(aCulture) {
    getEvent = event.keyCode;
    if (getEvent == "13")
        ShowContest(aCulture);
}

function detectBrowser()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	if ((browser=="Microsoft Internet Explorer") && (version<=6)) {
		return true;
	}
}

function CheckCardType(aCardNumber) {
    var myCardName;
    var myCardLength;
    
    myCardName = "";
    myCardLength = aCardNumber.length;

	if ((aCardNumber.substring(0, 2) == '34') || 
	    (aCardNumber.substring(0, 2) == '37')) {
	    if (myCardLength == 15) {
	        myCardName = 'Amex';
	    }
	}
	
	if ((aCardNumber.substring(0, 2) == '51') || 
	    (aCardNumber.substring(0, 2) == '52') ||
	    (aCardNumber.substring(0, 2) == '53') ||
	    (aCardNumber.substring(0, 2) == '54') ||
	    (aCardNumber.substring(0, 2) == '55')) {
	    if (myCardLength == 16) {
	        myCardName = 'Master Card';
	    }
	}		
	
	if (aCardNumber.substring(0, 1) == '4') {
	    if ((myCardLength == 16) || (myCardLength == 13)) {
    	    myCardName = 'Visa';
    	}
	}
	
	if ((aCardNumber.substring(0, 4) == '6011') ||
	    (aCardNumber.substring(0, 2) == '65')) {
	    if (myCardLength == 16) {
	        myCardName = 'Discover';
	    }
	}	
	
	if ((aCardNumber.substring(0, 2) == '30') || 
	    (aCardNumber.substring(0, 2) == '36') ||
	    (aCardNumber.substring(0, 2) == '38')) {
	    myCardName = 'Diners Club';
	}
	
	return myCardName;
}

// Credit Card Validation
function CheckCardNumber(isCSC) {

	var myCardType;
	var myCardNumber;
	var myCardNumberType;
	var myCardNumberLength;
	var myCardExpiryMonth;
	var myCardExpiryYear;
	
	var myPrefix;
	myPrefix = 'ucPayment_';
	
	if (isCSC == 1) {
	    return '';
	}
	
	myCardType = document.getElementById(myPrefix + 'ddlCCType').options[document.getElementById(myPrefix + 'ddlCCType').selectedIndex].value;
	myCardExpiryMonth = document.getElementById(myPrefix + 'ddlCCExpirationMonth').options[document.getElementById(myPrefix + 'ddlCCExpirationMonth').selectedIndex].value;
	myCardExpiryYear = document.getElementById(myPrefix + 'ddlCCExpirationYear').options[document.getElementById(myPrefix + 'ddlCCExpirationYear').selectedIndex].value;
	myCardNumber = document.getElementById(myPrefix + 'txtCCNumber').value;
	myCardNumberLength = document.getElementById(myPrefix + 'txtCCNumber').value.length;
	myCardNumberType = CheckCardType(myCardNumber);	
	
	document.getElementById(myPrefix + 'txtCCNumber').style.borderColor = "";
	document.getElementById(myPrefix + 'ddlCCExpirationMonth').style.borderColor = "";
	document.getElementById(myPrefix + 'ddlCCExpirationYear').style.borderColor = "";
	document.getElementById(myPrefix + 'ddlCCType').style.borderColor = "";
	document.getElementById('divValidator').innerHTML = "";
	document.getElementById('divValidator').style.color = "green";
	
	if ((document.getElementById(myPrefix + 'txtCCNumber').value.length == 0) &&
	    (myCardExpiryMonth.length == 0) &&
	    (myCardExpiryYear.length == 0) &&
	    ((myCardType == ''))) {
	    return '';    
    }    

	if (document.getElementById(myPrefix + 'txtCCNumber').value.length == 0) {
		document.getElementById('divValidator').innerHTML = "Please enter a Card Number.";
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'txtCCNumber').focus();
		document.getElementById(myPrefix + 'txtCCNumber').style.borderColor = "red";
		return "Please enter a Card Number.";
	}

	if (myCardExpiryMonth.length == 0) {
		document.getElementById('divValidator').innerHTML = "Please enter the Expiration Month.";
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCExpirationMonth').style.borderColor = "red";
		return "Please enter the Expiration Month.";
	}
	
	if (myCardExpiryYear.length == 0) {
		document.getElementById('divValidator').innerHTML = "Please enter the Expiration Year.";
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCExpirationYear').style.borderColor = "red";
		return "Please enter the Expiration Year.";
	}	
	
	if (myCardType == '') {
	    if (myCardNumberType != '') {
	        document.getElementById('divValidator').innerHTML = "Please select the Form of Payment.  This card looks like a <b>" + myCardNumberType + "</b> card number.";
	    } else {
	        document.getElementById('divValidator').innerHTML = "Please select the Form of Payment.";
	    }
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCType').style.borderColor = "red";
		return "Please select the Form of Payment.  This card looks like a " + myCardNumberType + " card number.";
	}
	
	
	
	if (myCardType == 'AX') {
	    myCardType = 'Amex';
	}
	if (myCardType == 'DC') {
	    myCardType = 'Diners Club';
	}
	if (myCardType == 'DS') {
	    myCardType = 'Discover';
	}
	if (myCardType == 'MC') {
	    myCardType = 'Master Card';
	}
	if (myCardType == 'VI') {
	    myCardType = 'Visa';
	}				
	
	if ((myCardNumberType != myCardType) &&
	        (   (myCardType == 'Amex') || 
	            (myCardType == 'Master Card') || 
	            (myCardType == 'Visa') || 
	            (myCardType == 'Discover') || 
	            (myCardType == 'Diners Club'))) {
	    if (myCardNumberType != '') {
		    document.getElementById('divValidator').innerHTML = "This looks like a <b>" + myCardNumberType + "</b> number, not a <b>" + myCardType + "</b> number.";
		    document.getElementById('divValidator').style.color = "red";
		    return "This looks like a " + myCardNumberType + " number, not a " + myCardType + " number.";	    
	    } else {
		    document.getElementById('divValidator').innerHTML = "Please confirm the credit card number matches this <b>" + myCardType + "</b> form of payment.";
		    document.getElementById('divValidator').style.color = "green";
		    return "Please confirm the credit card number matches this " + myCardType + " form of payment.";	    
	    }
	}
	
	return "";
}