//Start Google Map Script
var map = null;
var geocoder = null;
var marker;
var html;
var positionScroll = 0;
var ns4 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4 && parseFloat(navigator.appVersion) < 5) ? true : false;
var ns6 = (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape") >= 0) ? true : false;
var ns = (document.layers) ? true : false;
var ie = (document.all) ? true : false;

function getElLeft(el) {
    if (ns4) { return el.pageX; }
    else {
        xPos = el.offsetLeft;
        tempEl = el.offsetParent;
        while (tempEl != null) {
            xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
        return xPos;
    }
}
function getElTop(el) {
    if (ns4) { return el.pageY; }
    else {
        yPos = el.offsetTop;
        tempEl = el.offsetParent;
        while (tempEl != null) {
            yPos += tempEl.offsetTop;
            tempEl = tempEl.offsetParent;
        }
        return yPos;
    }
}

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 setChildListProvinceMobile(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", "United States", or "Mexico" is selected
	if (aListBoxParent.options[aListBoxParent.selectedIndex].value == "CA" || 
	    aListBoxParent.options[aListBoxParent.selectedIndex].value == "US" || 
	    aListBoxParent.options[aListBoxParent.selectedIndex].value == "MX") {

		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++;
			}
		}
				
	// Re-fill the State / Province drop down list with Please Select option
	} 
	else {
        aListBoxChild.style.display = "";
		aTextBoxChild.style.display = "none";
		
		for(x = 0; x<aArray.length; x++) {
			aListBoxChild.options[index] = new Option(aArray[x][2],aArray[x][1]);
			index++;
		}
	}
}

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, aShow25Day) {
        if (aIsWithinContestDate == 'True') {
            Show_Contest_ThickBox(aIsECSC, aCulture, aShow25Day);
        }
}

//Check to see if cookie exists
function Show_Contest_ThickBox(aIsECSC, aCulture, aShow25Day) {
    ContestCookie = ReadCookie("ShownThickBox");
    if (DetectMobile() == false) {
                if (ContestCookie == '' || ContestCookie == null) {
       
                    if (aIsECSC == 'False') {
                        if (aShow25Day == 'True') {
                            if (aCulture == 'en-CA')
                                tb_show('dvHiddenModalContentEN', 'TB_inline?height=340&width=520&inlineId=dvHiddenModalContentEN&modal=true', false);
                            else
                                tb_show('dvHiddenModalContentFR', 'TB_inline?height=340&width=520&inlineId=dvHiddenModalContentFR&modal=true', false);
                        }
                        else {
                           
                            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 ShowContest(aCulture, aShow25Day, aEmail) {
    if (aShow25Day == 'True') {
        if (aCulture == 'EN') {
            window.location = 'go.aspx?url=Contest&culture=enCA&email=' + aEmail;
        }
        else
            window.location = 'go.aspx?url=Contest&culture=frCA&email=' + aEmail;
    }
    else {
        if (aCulture == 'EN')
            window.location = 'go.aspx?url=Join&culture=enCA';
        else
            window.location = 'go.aspx?url=Join&culture=frCA';
    }
    
}

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 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 = document.getElementById('ltFrenchLabel1').innerHTML;
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'txtCCNumber').focus();
		document.getElementById(myPrefix + 'txtCCNumber').style.borderColor = "red";
		return document.getElementById('ltFrenchLabel1').innerHTML;
	}

	if (myCardExpiryMonth.length == 0) {
		document.getElementById('divValidator').innerHTML = document.getElementById('ltFrenchLabel2').innerHTML;
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCExpirationMonth').style.borderColor = "red";
		return document.getElementById('ltFrenchLabel2').innerHTML;
	}
	
	if (myCardExpiryYear.length == 0) {
		document.getElementById('divValidator').innerHTML = document.getElementById('ltFrenchLabel3').innerHTML;
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCExpirationYear').style.borderColor = "red";
		return document.getElementById('ltFrenchLabel3').innerHTML;
	}	
	
	if (myCardType == '') {
	    if (myCardNumberType != '') {
	        document.getElementById('divValidator').innerHTML = document.getElementById('ltFrenchLabel4').innerHTML + "  " + (document.getElementById('ltFrenchLabel5').innerHTML).replace("@@@" , myCardNumberType);
	    } else {
	        document.getElementById('divValidator').innerHTML = document.getElementById('ltFrenchLabel4').innerHTML;
	    }
		document.getElementById('divValidator').style.color = "red";
		document.getElementById(myPrefix + 'ddlCCType').style.borderColor = "red";
		return document.getElementById('ltFrenchLabel4').innerHTML + "  " + (document.getElementById('ltFrenchLabel5').innerHTML).replace("@@@" , myCardNumberType);
	}
	
	
	
	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 = ((document.getElementById('ltFrenchLabel6').innerHTML).replace("@@@" , myCardNumberType)).replace("###", myCardType);
		    document.getElementById('divValidator').style.color = "red";
		    return ((document.getElementById('ltFrenchLabel6').innerHTML).replace("@@@" , myCardNumberType)).replace("###", myCardType);	    
	    } else {
		    document.getElementById('divValidator').innerHTML = (document.getElementById('ltFrenchLabel7').innerHTML).replace("@@@" , myCardType);
		    document.getElementById('divValidator').style.color = "green";
		    return (document.getElementById('ltFrenchLabel7').innerHTML).replace("@@@" , myCardType);	    
	    }
	}
	
	return "";
}

//** BEGIN Animated Collapsible DIV -- for Mobile Adder
var animatedcollapse={
    divholders: {}, //structure: {div.id, div.attrs, div.$divref, div.$togglerimage}
    divgroups: {}, //structure: {groupname.count, groupname.lastactivedivid}
    lastactiveingroup: {}, //structure: {lastactivediv.id}
    preloadimages: [],

    show:function(divids){ //public method
        if (typeof divids=="object"){
            for (var i=0; i<divids.length; i++)
                this.showhide(divids[i], "show")
        }
        else
            this.showhide(divids, "show")
    },

    hide:function(divids){ //public method
        if (typeof divids=="object"){
            for (var i=0; i<divids.length; i++)
                this.showhide(divids[i], "hide")
        }
        else
            this.showhide(divids, "hide")
    },

    toggle:function(divid){ //public method
        if (typeof divid=="object")
            divid=divid[0]
        this.showhide(divid, "toggle")
    },

    addDiv:function(divid, attrstring){ //public function
        this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring})
        this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object
            var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
            return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found
        }
        this.currentid=divid //keep track of current div object being manipulated (in the event of chaining)
        return this
    },

    showhide:function(divid, action){
        var $divref=this.divholders[divid].$divref //reference collapsible DIV
        if (this.divholders[divid] && $divref.length==1){ //if DIV exists
            var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any)
            if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group
                if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set
                    this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first
                    this.slideengine(divid, 'show')
                targetgroup.lastactivedivid=divid //remember last active DIV
            }
            else{
                this.slideengine(divid, action)
            }
        }
    },

    slideengine:function(divid, action){
        var $divref=this.divholders[divid].$divref
        var $togglerimage=this.divholders[divid].$togglerimage
        if (this.divholders[divid] && $divref.length==1){ //if this DIV exists
            var animateSetting={height: action}
            if ($divref.attr('fade'))
                animateSetting.opacity=action
            $divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500, function(){
                if ($togglerimage){
                    $togglerimage.attr('src', ($divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
                }
                if (animatedcollapse.ontoggle){
                    try{
	                    animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display'))
                    }
                    catch(e){
	                    alert("An error exists inside your \"ontoggle\" function:\n\n"+e+"\n\nAborting execution of function.")
                    }
                }
            })
            return false
        }
    },

    generatemap:function(){
        var map={}
        for (var i=0; i<arguments.length; i++){
            if (arguments[i][1]!=null){ //do not generate name/value pair if value is null
                map[arguments[i][0]]=arguments[i][1]
            }
        }
        return map
    },

    init:function(){
        var ac=this
        jQuery(document).ready(function($){
            animatedcollapse.ontoggle=animatedcollapse.ontoggle || null
            var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc])
            var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc')
            var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined
            if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet)
                persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids
            groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted
            jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object
                this.$divref=$('#'+this.id)
                if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){ //if this div carries a user "persist" setting, or belong to a group with at least one div that does
                    var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none'
                }
                else{
                    var cssdisplay=this.getAttr('hide')? 'none' : null
                }
                if (urlparamopenids[0]=="all" || jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains the single array element "all", or this div's ID
                    cssdisplay='block' //set div to "block", overriding any other setting
                }
                else if (urlparamopenids[0]=="none"){
                    cssdisplay='none' //set div to "none", overriding any other setting
                }
                this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay]))
                this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')]))
                if (this.getAttr('group')){ //if this DIV has the "group" attr defined
                    var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in
                    targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group
                    if (jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains this div's ID
	                    targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings
	                    targetgroup.overridepersist=1 //Indicate to override persisted div that would have been expanded
                    }
                    if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block" && typeof targetgroup.overridepersist=="undefined") //if this DIV was open by default or should be open due to persistence								
	                    targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded)
                    this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now
                }
            }) //end divholders.each
            jQuery.each(ac.divgroups, function(){ //loop through each group
                if (this.lastactivedivid && urlparamopenids[0]!="none") //show last "active" DIV within each group (one that should be expanded), unless url param="none"
                    ac.divholders[this.lastactivedivid].$divref.show()
            })
            if (animatedcollapse.ontoggle){
                jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object and fire ontoggle event
                    animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display'))
                })
            }
            //Parse page for links containing rel attribute
            var $allcontrols=$('a[rel]').filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]"
            $allcontrols.each(function(){ //loop though each control link
                this._divids=this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc]
                if (this.getElementsByTagName('img').length==1 && ac.divholders[this._divids]){ //if control is an image link that toggles a single DIV (must be one to one to update status image)
                    animatedcollapse.preloadimage(this.getAttribute('data-openimage'), this.getAttribute('data-closedimage')) //preload control images (if defined)
                    $togglerimage=$(this).find('img').eq(0).data('srcs', {open:this.getAttribute('data-openimage'), closed:this.getAttribute('data-closedimage')}) //remember open and closed images' paths
                    ac.divholders[this._divids].$togglerimage=$(this).find('img').eq(0) //save reference to toggler image (to be updated inside slideengine()
                    ac.divholders[this._divids].$togglerimage.attr('src', (ac.divholders[this._divids].$divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
                }
                $(this).click(function(){ //assign click behavior to each control link
                    var relattr=this.getAttribute('rel')
                    var divids=(this._divids=="")? [] : this._divids.split(',') //convert 'div1,div2,etc' to array 
                    if (divids.length>0){
	                    animatedcollapse[/expand/i.test(relattr)? 'show' : /collapse/i.test(relattr)? 'hide' : 'toggle'](divids) //call corresponding public function
	                    return false
                    }
                }) //end control.click
            })// end control.each

            $(window).bind('unload', function(){
                ac.uninit()
            })
        }) //end doc.ready()
    },

    uninit:function(){
        var opendivids='', groupswithpersist=''
        jQuery.each(this.divholders, function(){
            if (this.$divref.css('display')!='none'){
                opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc'
            }
            if (this.getAttr('group') && this.getAttr('persist'))
                groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
        })
        opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '')
        groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '')
        this.setMobileAdderCookie('acopendivids', opendivids)
        this.setMobileAdderCookie('acgroupswithpersist', groupswithpersist)
    },

    getCookie:function(Name){ 
        var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setMobileAdderCookie:function(name, value, days){
        if (typeof days!="undefined"){ //if set persistent cookie
            var expireDate = new Date()
            expireDate.setDate(expireDate.getDate()+days)
            document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString()
        }
        else //else if this is a session only cookie
            document.cookie = name+"="+value+"; path=/"
    },

    urlparamselect:function(){
        window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
        return (RegExp.$1!="")? RegExp.$1.split(",") : []
    },

    preloadimage:function(){
        var preloadimages=this.preloadimages
        for (var i=0; i<arguments.length; i++){
            if (arguments[i] && arguments[i].length>0){
                preloadimages[preloadimages.length]=new Image()
                preloadimages[preloadimages.length-1].src=arguments[i]
            }
        }
    }

}
//** END Animated Collapsible DIV

function DisplayFeedBackRequest() {
    document.getElementById('lblSummary').innerText = '';
    if (document.getElementById('rblRequestType_0').checked) {
        if (document.getElementById('rblClassification_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_0').value;
        
        if (document.getElementById('rblClassification_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_1').value;
            
        if (document.getElementById('rblClassification_2').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_2').value;
            
        if (document.getElementById('rblClassification_3').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_3').value;
            
        if (document.getElementById('rblClassification_4').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_4').value;
    }
    
    if (document.getElementById('rblRequestType_1').checked) { 
        if (document.getElementById('rblClassification_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_0').value;
        
        if (document.getElementById('rblClassification_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_1').value;
            
        if (document.getElementById('rblClassification_2').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_2').value;
            
        if (document.getElementById('rblClassification_3').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_3').value;
            
        if (document.getElementById('rblClassification_4').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_4').value;
    }
}

function DisplayFeedBackClassification() {
    document.getElementById('lblSummary').innerText = '';
    if (document.getElementById('rblClassification_0').checked) {
        if (document.getElementById('rblRequestType_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_0').value;
            
        if (document.getElementById('rblRequestType_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_0').value;
    }
    
    if (document.getElementById('rblClassification_1').checked) { 
        if (document.getElementById('rblRequestType_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_1').value;
            
        if (document.getElementById('rblRequestType_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_1').value;
    }
    
    if (document.getElementById('rblClassification_2').checked) { 
        if (document.getElementById('rblRequestType_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_2').value;
            
        if (document.getElementById('rblRequestType_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_2').value;
    }
    
    if (document.getElementById('rblClassification_3').checked) { 
        if (document.getElementById('rblRequestType_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_3').value;
            
        if (document.getElementById('rblRequestType_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_3').value;
    }
    
    if (document.getElementById('rblClassification_4').checked) { 
        if (document.getElementById('rblRequestType_0').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
                + ':  ' + document.getElementById('rblClassification_4').value;
            
        if (document.getElementById('rblRequestType_1').checked)
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
                + ':  ' + document.getElementById('rblClassification_4').value;
    }
}

function FeedBackSubjectDisplay() {

    if (document.getElementById('rblRequestType_0') != null) {
        if ((document.getElementById('rblRequestType_0').checked) && (document.getElementById('rblClassification_0').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
            + ':  ' + document.getElementById('rblClassification_0').value;
        }
        
         if ((document.getElementById('rblRequestType_0').checked) && (document.getElementById('rblClassification_1').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
            + ':  ' + document.getElementById('rblClassification_1').value;
        } 
        
         if ((document.getElementById('rblRequestType_0').checked) && (document.getElementById('rblClassification_2').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
            + ':  ' + document.getElementById('rblClassification_2').value;
        } 
        
         if ((document.getElementById('rblRequestType_0').checked) && (document.getElementById('rblClassification_3').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
            + ':  ' + document.getElementById('rblClassification_3').value;
        } 
        
         if ((document.getElementById('rblRequestType_0').checked) && (document.getElementById('rblClassification_4').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_0').value 
            + ':  ' + document.getElementById('rblClassification_4').value;
        } 
        
         if ((document.getElementById('rblRequestType_1').checked) && (document.getElementById('rblClassification_0').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
            + ':  ' + document.getElementById('rblClassification_0').value;
        } 
        
         if ((document.getElementById('rblRequestType_1').checked) && (document.getElementById('rblClassification_1').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
            + ':  ' + document.getElementById('rblClassification_1').value;
        } 
        
         if ((document.getElementById('rblRequestType_1').checked) && (document.getElementById('rblClassification_2').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
            + ':  ' + document.getElementById('rblClassification_2').value;
        } 
        
         if ((document.getElementById('rblRequestType_1').checked) && (document.getElementById('rblClassification_3').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
            + ':  ' + document.getElementById('rblClassification_3').value;
        } 
        
         if ((document.getElementById('rblRequestType_1').checked) && (document.getElementById('rblClassification_4').checked)) {
            document.getElementById('lblSummary').innerText = document.getElementById('rblRequestType_1').value 
            + ':  ' + document.getElementById('rblClassification_4').value;
        } 
    } else {
        document.getElementById('lblSummary').innerText = 'Question / Support:  Technology'
    }
}

function setPostalZipMaxLength(aTxtPostalZip, aCountry) {
    if (aCountry.toLowerCase() == 'us') {
        aTxtPostalZip.maxLength = 5
    }
    else if (aCountry.toLowerCase() == 'ca') {
        aTxtPostalZip.maxLength = 7
    }
    else {
        aTxtPostalZip.maxLength = 10
    }
}

function DestinationRedirect(aDestination, aSubDestination, aVarDateFrom, aVarDateTo, aSelectedStateroom, aSelectedDuration, aSelectedCruiseline) {
    location.replace('go.aspx?ds=' + aDestination + '&sds=' + aSubDestination + '&drd=' + aVarDateFrom + '&url=cruise&Stateroom=' + aSelectedStateroom + '&dr=' + aSelectedDuration + '&cl=' + aSelectedCruiseline + '&dyr=999');
}

function BestBuyRedirect(aDestination, aVarDateFrom) {
    location.replace('go.aspx?ds=' + aDestination + '&url=cruise&drd=' + aVarDateFrom + '&dr=3&dyr=30');
}

function setHiddenProvince7SNew() {
    try {
        if (document.forms[0].ddlState.style.display == "") {
            if (document.forms[0].ddlState.selectedIndex == 0) {
                document.forms[0].hiddenProvince.value = "";
                document.forms[0].txtState.value = "";
            } else {
                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;
        }
    } catch (err) {

    }
}

function setHiddenProvince2(aHiddenProvince, aDdlState, aTxtState) {
    if (aDdlState.style.display == "") {
        if (aDdlState.selectedIndex == 0) {
            aHiddenProvince.value = "";
            aTxtState.value = "";
        } else {
            aHiddenProvince.value = aDdlState.options[aDdlState.selectedIndex].value;
            aTxtState.value = aDdlState.options[aDdlState.selectedIndex].value;
        }
    } else {
        aHiddenProvince.value = aTxtState.value;
    }
}

function ShowTerms(aPromotionID) {
    window.open('TermsConditions.aspx?item=' + aPromotionID, 'newwin', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,height=400,width=400');
}

function ShowToolTipScreenCenter(aID) {
    var hlp = $("div.findWrapper").find("span#TIP" + aID);
    if (hlp) {
        hlp.css("top", (($(window).height()) / 2) + $(window).scrollTop() - 350 + "px");
        hlp.css("left", (($(window).width()) / 2) + $(window).scrollLeft() - 350 + "px");
        hlp.css("position", "absolute");
        hlp.css("visibility", "visible");
        hlp.css("display", "block");
        hlp.fadeIn();
        hlp.css("z-index", "9999");

        $('body').append('<div id="fade" ></div>');
        $('#fade').css({ 'filter': 'alpha(opacity=70)' }).fadeIn();
    }
}
