<!--//
/*
This file contains common javascript library code that will be used throughout
the site. It will be added to and modified throughout the project.
*/

/*
The following image functions can be called with one or two parameters. If there
is only one parameter it is assumed that the image is loose in the /images/
directory and we are simply calling the function with the image short name. If
there are two parameters then we are passing the image name and the path off of
the /images/ directory that the image resides in.

Primarily for nav type image routines - otherwise the code can just be inline.
*/
/*
20061190_mwm_emailsignup_change
increased the width of the popup
*/

/**
 * Change log
 * 05/13/05	aup	QueryString_Parse	Added try catch block to catch 
 *						permission denied error 
 * 
 */
 /**
 20070254_mwm_url_change
 changed the emailsignup function to accept a param
 */
function imgOn() {
    var a = 0;
    a = arguments.length;
    imgToSwap = arguments[0];
//  alert("ImgOn" +imgToSwap);
    if (document.images)
    {
        if (a == 1) {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+imgToSwap+"_r.gif";
            }
        } else {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+arguments[1]+imgToSwap+"_r.gif";
            }
        }
    }
}

function imgOff() {
    var a = 0;
    a = arguments.length;
    imgToSwap = arguments[0];

    if (document.images)
    {
//      alert("ImgOn" +Num);
        if (a == 1) {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+imgToSwap+"_n.gif";
            }
        } else {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+arguments[1]+imgToSwap+"_n.gif";
            }
        }
    }
}

function imgSelect() {
    var a = 0;
    a = arguments.length;
    imgToSwap = arguments[0];
    if (document.images)
    {
//      alert("ImgOn" +Num);
        if (a == 1) {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+imgToSwap+"_s.gif";
            }
        } else {
            if (document.images[imgToSwap] != null) {
                document.images[imgToSwap].src = "/images/"+arguments[1]+imgToSwap+"_s.gif";
            }
        }
    }
}


// preload nav images
function MM_preloadImages() {
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//PRINT FUNCTION
function wPrint()
{
    if (window.print) window.print();
}


//
// QueryString - parses url values into objects. Should be replaced with JSP code
// to accomplish the same thing...
//

function QueryString(key)
{
    var value = null;
    for (var i=0;i<QueryString.keys.length;i++)
    {
        if (QueryString.keys[i]==key)
        {
            value = QueryString.values[i];
            break;
        }
    }
    return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	try
	{
	    var query = window.location.search.substring(1);
	    var pairs = query.split("&");

	    for (var i=0;i<pairs.length;i++)
	    {
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
		    var argname = pairs[i].substring(0,pos);
		    var value = pairs[i].substring(pos+1);
		    QueryString.keys[QueryString.keys.length] = argname;
		    QueryString.values[QueryString.values.length] = value;
		}
	    }
	}catch(e){}
}

QueryString_Parse();

//Simple array of all destinations, for misc usage.
var allDestinations = new Array();
allDestinations = ["ac","at","av","cb","cs","ce","eu","hi","mx","pc","pn","sa","wv"];


//Utility function to convert destination codes to human readable...
function destTextConvert(destination) {
    destPage = "";
    switch (destination.toLowerCase()){
        case "ac":
            destPage = "Alaska Cruises";
            break;
        case "ap":
            destPage = "Asia Pacific";
            break;
        case "at":
            destPage = "Alaska &amp; the Yukon CruiseTours";
            break;
        case "av":
            destPage = "Alaska Land Vacations";
            break;
        case "cb":
            destPage = "Caribbean";
            break;
        case "ce":
            destPage = "Canada/<br>New England";
            break;
        case "cs":
            destPage = "Coastals";
            break;
        case "eu":
            destPage = "Europe";
            break;
        case "mx":
            destPage = "Mexico";
            break;
        case "hi":
            destPage = "Hawaii";
            break;
        case "pc":
            destPage = "Panama Canal";
            break;
        case "pn":
            destPage = "Pacific Northwest";
            break;
        case "sa":
            destPage = "South America";
            break;
        case "wv":
            destPage = "World Voyages";
            break;
        default:
            destPage = "";
            break;
    }
    return destPage;
}

//Convert shipcodes to display names
function shipTextConvert(ship) {
    shipPage = "";

    switch (ship.toLowerCase()){
        case "am":
            shipPage = "ms Amsterdam";
            break;
        case "ma":
            shipPage = "ms Maasdam";
            break;
        case "no":
            shipPage = "ms Noordam";
            break;
        case "os":
            shipPage = "ms Oosterdam";
            break;
        case "pr":
            shipPage = "ms Prinsendam";
            break;
        case "rt":
            shipPage = "ms Rotterdam";
            break;
        case "ry":
            shipPage = "ms Ryndam";
            break;
        case "sa":
            shipPage = "ms Statendam";
            break;
        case "ve":
            shipPage = "ms Veendam";
            break;
        case "vo":
            shipPage = "ms Volendam";
            break;
        case "we":
            shipPage = "ms Westerdam";
            break;
        case "za":
            shipPage = "ms Zaandam";
            break;
        case "zu":
            shipPage = "ms Zuiderdam";
            break;
        default:
            shipPage = "";
            break;
    }
    return shipPage;
}
// array of all shipcodes. used in js in multiple places. If a new ship is added,
// the code should be put into this array and the full name should be put into
// the shipTextConvert function...
var all_ships = new Array("am","ma","no","os","pr","rt","ry","sa","ve","vo","we","za","zu");

//utility arrays of monthname/monthnumber, ie: month = month_long["3"] returns "March"...
var month_long = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var month_short = new Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

//POPUP FUNCTION FOR GENERAL SIZE
function openPopup(dest,width,height)
{
    if ( "undefined" == typeof width )
    {
        width = 495;
    }

    if ( "undefined" == typeof height )
    {
        height = 525;
    }

    thePopup = window.open(dest,'popupWindow','scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',left=50,top=10');

    if(thePopup.opener == null)
    {
        thePopup.opener = window;
    }
	try
	{		
		thePopup.focus();
		
	}
	catch (e)
	{
		// nothing to do.
	}
}

function eBrochurePopup(dest,width,height)
{
    if ( "undefined" == typeof width )
    {
        width = 1024;
    }

    if ( "undefined" == typeof height )
    {
        height = 800;
    }

    thePopup = window.open(dest,'eBrocPopupWindow','directories=no,location=yes,menubar=yes,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',left=50,top=10');

    if(thePopup.opener == null)
    {
        thePopup.opener = window;
    }
	try
	{		
		thePopup.focus();
		
	}
	catch (e)
	{
		// nothing to do.
	}
}

function printItiny(dest)
{
    thePopup = window.open(dest,'popupWindow','scrollbars=yes,resizable=yes,width=525,height=525,left=50,top=10');
    if(thePopup.opener == null)
    {
        thePopup.opener = window;
    }
    thePopup.focus();
}

function openSharePopup(dest)
{
    thePopup = window.open(dest,'popupWindow','scrollbars=yes,resizable=yes,width=420,height=460');
    if(thePopup.opener == null)
    {
        thePopup.opener = window;
    }
    thePopup.focus();
}

function popup(dest)
{
  window.open( dest, 'popup', 'directories=no,location=yes,menubar=yes,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,height=500,width=547');
}


function cpAbrochurePopup( target )
{
    window.open( target, "Popup", "toolbar=yes,width=425,height=550,resizable=yes,scrollbars=yes" );
}


function popUpFleet( fn ) {
    window.open(fn,'popper','directories=no,location=no,menubar=yes,toolbar=no,status=no,scrollbars=yes,resizable=yes,height=500,width=547')
}


var NS4 = false;
if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) { NS4 = true; }

/* dynamic select list stuff...
 Author: Matt Kruse <matt@mattkruse.com>
 WWW: http://www.mattkruse.com/
 See: http://www.mattkruse.com/javascript/dynamicoptionlist/source.html for example and documentation.
 Using this to build the relational dynamic select lists in the Itinerary Search module (/dest/ac/ac.htm for example).
*/

function DynamicOptionList(){if(arguments.length < 2){alert("Not enough arguments in DynamicOptionList()");}this.target = arguments[0];this.dependencies = new Array();for(var i=1;i<arguments.length;i++){this.dependencies[this.dependencies.length] = arguments[i];}this.form = null;this.dependentValues = new Object();this.defaultValues = new Object();this.options = new Object();this.delimiter = "|";this.longestString = "";this.numberOfOptions = 0;this.addOptions = DynamicOptionList_addOptions;this.populate = DynamicOptionList_populate;this.setDelimiter = DynamicOptionList_setDelimiter;this.setDefaultOption = DynamicOptionList_setDefaultOption;this.printOptions = DynamicOptionList_printOptions;this.init = DynamicOptionList_init;}
function DynamicOptionList_setDelimiter(val){this.delimiter = val;}
function DynamicOptionList_setDefaultOption(condition, val){if(typeof this.defaultValues[condition] == "undefined" || this.defaultValues[condition]==null){this.defaultValues[condition] = new Object();}for(var i=1;i<arguments.length;i++){this.defaultValues[condition][arguments[i]]=1;}}
function DynamicOptionList_init(theform){this.form = theform;this.populate();}
function DynamicOptionList_addOptions(dependentValue){if(typeof this.options[dependentValue] != "object"){this.options[dependentValue] = new Array();}for(var i=1;i<arguments.length;i+=2){if(arguments[i].length > this.longestString.length){this.longestString = arguments[i];}this.numberOfOptions++;this.options[dependentValue][this.options[dependentValue].length] = arguments[i];this.options[dependentValue][this.options[dependentValue].length] = arguments[i+1];}}
function DynamicOptionList_printOptions(){if((navigator.appName == 'Netscape') &&(parseInt(navigator.appVersion) <= 4)){var ret = "";for(var i=0;i<this.numberOfOptions;i++){ret += "<OPTION>";}ret += "<OPTION>"
for(var i=0;i<this.longestString.length;i++){ret += "_";}document.writeln(ret);}}
function DynamicOptionList_populate(){var theform = this.form;var i,j,obj,obj2;this.dependentValues = new Object;var dependentValuesInitialized = false;for(i=0;i<this.dependencies.length;i++){var sel = theform[this.dependencies[i]];var selName = sel.name;if(!dependentValuesInitialized){dependentValuesInitialized = true;for(j=0;j<sel.options.length;j++){if(sel.options[j].selected){this.dependentValues[sel.options[j].value] = true;}}}else{var tmpList = new Object();var newList = new Object();for(j=0;j<sel.options.length;j++){if(sel.options[j].selected){tmpList[sel.options[j].value] = true;}}for(obj in this.dependentValues){for(obj2 in tmpList){newList[obj + this.delimiter + obj2] = true;}}this.dependentValues = newList;}}var targetSel = theform[this.target];var targetSelected = new Object();for(i=0;i<targetSel.options.length;i++){if(targetSel.options[i].selected){targetSelected[targetSel.options[i].value] = true;}}targetSel.options.length = 0;for(i in this.dependentValues){if(typeof this.options[i] == "object"){var o = this.options[i];for(j=0;j<o.length;j+=2){var text = o[j];var val = o[j+1];targetSel.options[targetSel.options.length] = new Option(text, val, false, false);if(typeof this.defaultValues[i] != "undefined" && this.defaultValues[i]!=null){for(def in this.defaultValues[i]){if(def == val){targetSelected[val] = true;}}}}}}targetSel.selectedIndex=-1;for(i=0;i<targetSel.options.length;i++){if(targetSelected[targetSel.options[i].value] != null && targetSelected[targetSel.options[i].value]==true){targetSel.options[i].selected = true;}}}

function resSpecialistPopup()
{
  window.open( 'https://crm.hollandamerica.com/broadbaseema/ha3051/cpa.jsp?srce=cpb', "resSpecPopup", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}

function specialOffersPopup()
{
  window.open( 'http://www.viewandverandah.com', "specialOffersPopup", "toolbar=yes,width=605,height=550,resizable=yes,scrollbars=yes" );
}

function brochurePopup()
{
  window.open( 'https://crm.hollandamerica.com/broadbaseema/ha3051/brochurerequest.jsp', "brochurePopup", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}

function orderVideoPopup()
{
  window.open( 'http://www.orderport.net/hollandamerica', "orderVideo", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}


function marinerNumberLookup()
{
  window.open( 'http://mariners.vcrm2.com/lookup', "marinerNumber", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}

function emailSignUp(source)
{   
  var input = '';
  if(source) input = source
  else input = 'erh';  //erh -- default
  var url = 'https://crm.hollandamerica.com/broadbaseema/hd6148/survey.jsp?srce=' + input;
  window.open( url, "emailSignUp", "toolbar=yes,width=526,height=530,resizable=yes,scrollbars=yes" );
}

function shopHAL()
{
  window.open( 'http://www.hollandamericashop.com/index.cfm', "shopHAL", "toolbar=yes,width=850,height=650,resizable=yes,scrollbars=yes" );
}

function specialOffersSignUp()
{
  window.open( 'https://crm.hollandamerica.com/broadbaseema/HA4120/survey.jsp', "emailSignUp", "toolbar=yes,width=545,height=380,resizable=yes,scrollbars=yes" );
}

function emailOptOut()
{
  window.open( 'https://crm.hollandamerica.com/broadbaseema/ha3066/optout.jsp', "emailOptOut", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}

function emailAddressChange()
{
  window.open( 'https://halsurvey2.vcrm2.com/broadbaseema/global/change_email_std.jsp', "emailaddressChange", "toolbar=yes,width=545,height=550,resizable=yes,scrollbars=yes" );
}

function getDocObj(docObjId)
{
    var docObj = null;

    if (document.all)
    {
        docObj = document.all(docObjId);
    }
    else if (document.getElementById)
    {
        docObj = document.getElementById(docObjId);
    }

    return docObj;
}

function toggleLayer(layerId, visibility)
{
    var layerObj = getDocObj(layerId);

    if (layerObj)
    {
        layerObj.style.display="block";
        layerObj.style.visibility=visibility;
    }
}

function confirmEmail (email,confemail,emailErrLayer)
{
    var emailLength = email.value.length;
    var confemailLength = confemail.value.length;
    var emailContainsAllWhiteSpace = email.value.match(/^\s+$/);
    var confemailContainsAllWhiteSpace = confemail.value.match(/^\s+$/);
    var toggleError = false;
    var visibility = "hidden";
    var rval = false;

    if ( ( emailLength == 0 || emailContainsAllWhiteSpace )  &&
         ( confemailLength == 0 || confemailContainsAllWhiteSpace ) )
    {
       rval = true;
    }
    else if ( ( emailLength > 0 && !emailContainsAllWhiteSpace ) &&
              ( confemailLength == 0 || confemailContainsAllWhiteSpace ) )
    {
        confemail.focus();
    }
    else if ( ( emailLength == 0 || emailContainsAllWhiteSpace ) &&
              ( confemailLength > 0 && !emailContainsAllWhiteSpace ) )
    {
        email.focus();
        toggleError = true;
        visibility = "visible";
    }
    else if ( email.value != confemail.value )
    {
        confemail.focus();
        toggleError = true;
        visibility = "visible";
    }
    else
    {
        rval = true;
        toggleError = true;
    }

    if (toggleError)
    {
        toggleLayer(emailErrLayer,visibility);
    }

    return rval;
}

function confirmNextUrl(msg,url)
{
    if(confirm(msg))
    {
        window.location=url;
    }
}

function getAnchor(anchor)
{

    var sLoc = document.location.href;
    var nLoc = "";
    var pound = sLoc.indexOf('#',0);

    if (pound != -1) {  //there is an old anchor

    nLoc = sLoc.substring(0, sLoc.length - (sLoc.length- pound));   //strip out the old anchor

    self.location.href = nLoc+anchor;   //add the new anchor

    }

    else {              //there isn't an old anchor

    self.location.href = sLoc+anchor;   //add the new anchor

    }
}

function onLoadPagePosistion(whatPosistion)
{
    if(whatPosistion != null)
    {
        jumpToPort(whatPosistion);
    }

}


// THE FOLLOWING FUNCTIONS ARE FOR BASIC COOKIE SUPPORT

// These functions and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com

function GetCookie (name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            return getCookieVal (j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function SetCookie (name, value)
{
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "0" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

function onlineCinema(dest) 
{
	var cinemaURL = "http://experience.hollandamerica.com/";
	
	// If we're not linking to a specific page, open the home page
	if (dest == null) {
		onlineCinemaWindow = window.open(cinemaURL,'popupWindow','scrollbars=auto,location=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes,width=760,height=540,left=50,top=10');
	} else {
		onlineCinemaWindow = window.open(dest,'popupWindow','scrollbars=auto,location=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes,width=700,height=540,left=50,top=10');
	}

	if(onlineCinemaWindow.opener == null)
	{
		onlineCinemaWindow.opener = window;
	}
	onlineCinemaWindow.focus();

}

function popup_content(dest, name)
{
		window.open(dest, name, 'scrollbars=yes,resizable=yes,width=680,height=400');
}


function writePersistentCookie (CookieName, CookieValue, periodType, offset) 
{

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) 
  {
    case "years":
      expireDate.setYear(expireDate.getFullYear()+offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth()+offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate()+offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours()+offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes()+offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}
//-->

