function popUp(page, name, details) {
	var newWin = window.open(page, name, details);
	newWin.focus();
	return false;
}

function showPanofull(mapid) {
	var codestr;
	var swidth = screen.width;
	var win = window.open('http://display.maxvr.com/mapviewer/fullpopup.asp?nc=1&ident=AA369-' + mapid ,'vrxmapviewer','height=470,width=796,menubar=no,top=5,scrollbars=no,resizable=no,left=0');
	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/Map/canmap_01-ImageMap_13_over.gif");
		canmap_01_ImageMap_10_over = newImage("images/Map/canmap_01-ImageMap_10_over.gif");
		canmap_01_ImageMap_11_over = newImage("images/Map/canmap_01-ImageMap_11_over.gif");
		canmap_01_ImageMap_09_over = newImage("images/Map/canmap_01-ImageMap_09_over.gif");
		canmap_01_ImageMap_08_over = newImage("images/Map/canmap_01-ImageMap_08_over.gif");
		canmap_01_ImageMap_07_over = newImage("images/Map/canmap_01-ImageMap_07_over.gif");
		canmap_01_ImageMap_06_over = newImage("images/Map/canmap_01-ImageMap_06_over.gif");
		canmap_01_ImageMap_05_over = newImage("images/Map/canmap_01-ImageMap_05_over.gif");
		canmap_01_ImageMap_04_over = newImage("images/Map/canmap_01-ImageMap_04_over.gif");
		canmap_01_ImageMap_03_over = newImage("images/Map/canmap_01-ImageMap_03_over.gif");
		canmap_01_ImageMap_02_over = newImage("images/Map/canmap_01-ImageMap_02_over.gif");
		canmap_01_ImageMap_01_over = newImage("images/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';
	}
}

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 populateDestination(setDefault) {
    var ddlDestination;
    var index = 0;
    var itemExists;

	ddlDestination = document.forms[1].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[1].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[1].ddlDestination;
	ddlSubdestination = document.forms[1].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[1].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[1].ddlDeparturePort;
    if (ddlDeparturePort!=null)	{
        ddlDestination = document.forms[1].ddlDestination;
	    ddlSubdestination = document.forms[1].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[1].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[1].ddlDestination;
    ddlSubdestination = document.forms[1].ddlSubDestination;
    ddlDeparturePort = document.forms[1].ddlDeparturePort;
    ddlCruiseline = document.forms[1].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[1].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[1].ddlDestination;
    ddlSubdestination = document.forms[1].ddlSubDestination;
    ddlDeparturePort = document.forms[1].ddlDeparturePort;
    ddlCruiseline = document.forms[1].ddlCruiseLine;
    ddlShip = document.forms[1].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[1].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[1].ddlDestination;
    ddlSubDestination = document.forms[1].ddlSubDestination;
    ddlMonth = document.forms[1].ddlMonth;
    ddlMonthTo = document.forms[1].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[1].hiddenMonthYearFrom.value=ddlMonth.value;
	     if (ddlMonthTo!=null){document.forms[1].hiddenMonthYearTo.value=ddlMonthTo.value;}
	}
}


function populateDay() {
	var x;
    var ddlDay;
    var ddlMonth;
    var daysInMonth;

    ddlMonth = document.forms[1].ddlMonth;
    ddlDay = document.forms[1].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[1].hiddenDayFrom.value=ddlDay.value;
    }
}

function populateDayTo() {
	var x;
    var ddlDayTo;
    var ddlMonthTo;
    var daysInMonth;

    ddlMonthTo = document.forms[1].ddlMonthTo;
    ddlDayTo = document.forms[1].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[1].hiddenDayTo.value=ddlDayTo.value;
}

function populateDuration() {
	var index = 0;
	var j;
	var x;
    var ddlDuration;

    ddlDuration = document.forms[1].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[1].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[1].rblDate[1].checked ) {
	    document.forms[1].ddlMonthTo.style.display='';
	    document.forms[1].ddlDayTo.style.display='';
	    document.forms[1].hiddenRange.value = "1"

	    lblFrom.style.display='';
	    lblTo.style.display='';
	    populateDayTo();

    } else {
	    document.forms[1].ddlMonthTo.style.display='none';
	    document.forms[1].ddlDayTo.style.display='none';
	    document.forms[1].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[1].ucPersonal_ddlState.style.display == "") {
		if (document.forms[1].ucPersonal_ddlState.selectedIndex == 0) {
			document.forms[1].ucPersonal_hiddenProvince.value = "";
			document.forms[1].ucPersonal_txtState.value = "";
		} else {
			document.forms[1].ucPersonal_hiddenProvince.value = document.forms[1].ucPersonal_ddlState.options[document.forms[1].ucPersonal_ddlState.selectedIndex].value;
			document.forms[1].ucPersonal_txtState.value = document.forms[1].ucPersonal_ddlState.options[document.forms[1].ucPersonal_ddlState.selectedIndex].value;
		}
	} else {
		document.forms[1].ucPersonal_hiddenProvince.value = document.forms[1].ucPersonal_txtState.value;
	}
}

function setChildListProvince(aListBoxChild, aListBoxParent, aTextBoxChild, aArray) {
	var parentSelected = aListBoxParent.options[aListBoxParent.selectedIndex].text;
	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].text == "Canada" || aListBoxParent.options[aListBoxParent.selectedIndex].text == "United States") {

		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 = "";
	}
	setHiddenProvince();
}