jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};;
/** https://github.com/martinkr/jCookie - Copyright (c) 2008-2011 Martin Krause - Dual licensed under the MIT and GPL licenses. */
jQuery.jCookie=function(i,b,l,j){if(!navigator.cookieEnabled){return false}var j=j||{};if(typeof(arguments[0])!=="string"&&arguments.length===1){j=arguments[0];i=j.name;b=j.value;l=j.expires}i=encodeURI(i);if(b&&(typeof(b)!=="number"&&typeof(b)!=="string"&&b!==null)){return false}var e=j.path?"; path="+j.path:"";var f=j.domain?"; domain="+j.domain:"";var d=j.secure?"; secure":"";var g="";if(b||(b===null&&arguments.length==2)){l=(l===null||(b===null&&arguments.length==2))?-1:l;if(typeof(l)==="number"&&l!="session"&&l!==undefined){var k=new Date();k.setTime(k.getTime()+(l*24*60*60*1000));g=["; expires=",k.toGMTString()].join("")}document.cookie=[i,"=",encodeURI(b),g,f,e,d].join("");return true}if(!b&&typeof(arguments[0])==="string"&&arguments.length==1&&document.cookie&&document.cookie.length){var a=document.cookie.split(";");var h=a.length;while(h--){var c=a[h].split("=");if(jQuery.trim(c[0])===i){return decodeURI(c[1])}}return undefined}if(!document.cookie||!document.cookie.length){return undefined}return false};
/** https://github.com/martinkr/jStorage - Copyright (c) 2011 Martin Krause - Dual licensed under the MIT and GPL licenses. */
(function(a){a.storage=function(){var d={localStorage:("localStorage" in window&&window.localStorage!==null)?"localStorage":"cookie",sessionStorage:("sessionStorage" in window&&window.sessionStorage!==null)?"sessionStorage":"cookie",cookie:"cookie",data:"data",status:"status",options:"options"};var c={sType:"data"};var g=function(){if(!jQuery.jCookie){throw new Error("[jQuery.storage] missing jQuery.jCookie. Get jcookie.min.js from https://github.com/martinkr/jCookie/")}if(!JSON){throw new Error("[jQuery.storage] missing JSON parser. Get json2.js from https://github.com/douglascrockford/JSON-js and / or visit json.org ")}}();var f=function(i,j){if(typeof(i)=="object"&&!i.type){i.type=c.sType}var k=typeof(i)=="string"?i:i.type;if(k.indexOf("Storage")!==-1&&d[k]=="cookie"){i.expires=(k=="sessionStorage")?"session":365}if(j){c.sType=d[k]}return{sType:d[k],sName:i.name||null,expires:i.expires||"session",secure:i.secure?true:false,path:i.path||false,domain:i.domain||false}};var e=function(m,i){var j=f(i);var k=j.sType;switch(k){case"options":return c[m];case"status":return d[m];case"data":if(jQuery(window).data("jStorage")===undefined){return undefined}return jQuery(window).data("jStorage")[m];case"cookie":m=["jStorage_",m].join("");var l=jQuery.jCookie(m);if(l){return JSON.parse(jQuery.jCookie(m))}else{return l}case"sessionStorage":case"localStorage":return window[k].getItem(m)}return undefined};var b=function(o,k,i){var n=(k===null)?false:true;var j=f(i||{type:c.sType},n);var m=j.sType;switch(m){case"data":var l=jQuery(window).data("jStorage")||{};if(k===null){return delete (l[o])}l[o]=k;jQuery(window).data("jStorage",l);return true;case"cookie":o=["jStorage_",o].join("");if(k===null){jQuery.jCookie(o,null);return true}jQuery.jCookie(o,JSON.stringify(k),j.expires,j);return true;case"sessionStorage":case"localStorage":if(k===null){window[m].removeItem(o);return true}window[m].setItem(o,k);return true}return false};var h=function(i){var l=f(i||{type:c.sType},false);var o=l.sType;var j=0;var n,m;switch(o){case"data":m=jQuery(window).data("jStorage")||{};for(n in m){j++}break;case"cookie":_aData=document.cookie.split(";")||{};var k=_aData.length;while(k--){if(_aData[k].indexOf("jStorage_")!==-1){j++}}break;case"sessionStorage":case"localStorage":j=window[o].length;break}return j};return{getItem:function(j,i){return e(j,i)},setItem:function(k,j,i){b(k,j,i)},removeItem:function(j,i){b(j,null,i)},length:function(i){return h(i)}}}()})(jQuery);;
/**
 * The code herein is exposed to both carnival.com and the booking engine.  The
 * intent is this is the repository for global functions and values throughout.
 * @module Carnival.Globals
 * @requires jQuery
 * @namespace Carnival
 */

/**
 * A utility function that creates namespaces.
 * @method InitializeCarnivalGlobal
 */
jQuery.namespace = function ()
{
    var o = null;
    var i, j, d;
    for (i = 0; i < arguments.length; i = i + 1)
    {
        d = arguments[i].split(".");
        o = window;
        for (j = 0; j < d.length; j = j + 1)
        {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
    return o;
};

// ------------- Create Carnival's namespaces ----------
$.namespace('Carnival.BookingEngine.Stateroom');
$.namespace('Carnival.BookingEngine.SailingSearch');
$.namespace('Carnival.Web.Specials');
$.namespace('Carnival.Globals');
$.namespace('Carnival.SiteCore.LandingPage');
$.namespace('Carnival.SiteCore.FindACruise');
$.namespace('Carnival.AppResources');
$.namespace('Carnival.Web.Generic');
// -----------------------------------------------------


/**
 * Returns the cclUserCookie if it exists
 * @method Carnival.Globals.cclUserCookie
 * @example <caption>Invoking without param.</caption>
 * // returns {FirstName: "person", LastName: "last", Email: "someone@somewhere.com", PastGuestNumber: "2234", TierCode: "00"}
 * Carnival.Globals.cclUserCookie();
 * @example <caption>Specific property in propName param</caption>
 * // returns "2234"
 * Carnival.Globals.cclUserCookie("PastGuestNumber");
 * @param {string} propName - The name of the property to return
 * @return object if no propName specified, otherwise the value of the cclUser[propName]
 */
Carnival.Globals.cclUserCookie = function (propName) {
    if (propName)
        return (JSON.parse(decodeURIComponent($.cookie("cclUser") || "{}")))[propName] || $.cookie(propName);
    return JSON.parse(decodeURIComponent($.cookie("cclUser") || "{}"));
};

/**
 * Returns the cclSessionCookie if it exists
 * @method Carnival.Globals.cclSessionCookie
 * @example <caption>Invoking without param.</caption>
 * // returns {BookingNumber: 'abc', SailDate: '2/22/2016', VifpNumberOfDays: '5', TierCode: '01', IsAuthenticated: true}
 * Carnival.Globals.cclSessionCookie();
 * @example <caption>Specific property in propName param</caption>
 * // returns "2234"
 * Carnival.Globals.cclUserCookie("BookingNumber");
 * @param {string} propName - The name of the property to return
 * @param {string} legacyName - The name of the old cookie to fallback to
 * @return object if no propName specified, otherwise the value of the cclUser[propName] or value of legacy cookie
 */
Carnival.Globals.cclSessionCookie = function (propName, legacyName) {
    if (propName)
        return (JSON.parse(decodeURIComponent($.cookie("cclSession") || "{}")))[propName] || $.cookie(legacyName);
    return JSON.parse(decodeURIComponent($.cookie("cclSession") || "{}"));
};

/**
 * Returns the past guest number if it exists.
 * @method Carnival.Globals.UserIsLoggedIn
 * @return string
 */
Carnival.Globals.GetProfilePastGuestNumber = function GetProfilePastGuestNumber()
{
    return Carnival.Globals.cclUserCookie('PastGuestNumber');
};

/**
 * Returns true only if user is fully logged in.
 * @method Carnival.Globals.UserIsFullyLoggedIn
 * @return bool
 */
Carnival.Globals.UserIsFullyLoggedIn = function UserIsFullyLoggedIn()
{
    return Carnival.Globals.cclSessionCookie('IsAuthenticated', 'MSCSAuth');
};

/**
* This function allows JavaScript to load external scripts.
* @method Carnival.Globals.AppendScript
* @return null
*/
Carnival.Globals.AppendScript = function _AppendScript(asSrc)
{
    try
    {
        var loScript = document.createElement('script');
        loScript.type = "text/javascript";
        loScript.src = asSrc;
        document.getElementsByTagName('head')[0].appendChild(loScript);
    }
    catch (aoXcp)
    {}
};

// Originally these settings were hardcoded in ~\common\CCLUS\js\header\Carnival.Live.js being
// appended with Carnival.Globals.AppendScript above. Presumably due to faster search, timing
// issues appeared thus we moved the declaration to inline here.
Carnival.Live =
{
	"ShowTargetedOffers": "true",
	"FareViewerCaptchaOn": "true",
	"FareViewerNumberOfInvalidCaptchaAttempts": 5,
	"SearchResultsInsertTheLowestPriceAtTop": "true",
	"PrimaryGuestQasEmailValidationOn": "false",
	"PrimaryGuestQasEmailValidationLevel": 1,
	"ShowPastGuestOfferInSpecialsPage": "true",
	"ParallelProcessPassThruPorts": "false",
	"InvalidRoutesHandlingOn": "true",
	"InvalidRoutes": [
		").css(",
		");f=e.css(",
		");this.elem.style.display=a"
	],
	"Payment2DefaultDisplayTripDetails": "true"
};

// utility to parse url from string
String.prototype.toLocation = function () {
    var a = document.createElement('a');
    a.href = this;
    return a;
};


//code to prevent document.write after page load
var base_document_write = document.write;
var bodyLoaded = false;

document.write = function (str) {
    if (!bodyLoaded) {
        base_document_write.call(document, str);
    }
}

$(document).ready(function () {
    bodyLoaded = true;
});
;
