﻿    
    function GetUserInfo()  {
    
        //debugger; 
        var ShowLastOrderPopup = true;
        
        var needDeals = PageNeedsDeals();
        
        jQuery('.noThanks, .close, #modalBackground').click(function(){
            deleteCookie("_qoord");
        });
        
        if (getCookie("_qouid"))
        {
            // cookied user
            var base64info = getCookie("_qouid");
            var userValue = base64_decode(base64info);

            if($get("welcomeLI") == null) return false;

            if (userValue != "~~~~~~~~~~") //Null cookie
             { 
                UpdateNavigation(true); 
                IsCookied = "Y";
                var userInfo =  userValue.split("~", 11);
                var deliveryType = userInfo[5];
                if (deliveryType == null || deliveryType == "undefined")
                    deliveryType = "D";
                        
                    
                    if(userInfo[7] == "" || userInfo[7] == null)
                    {
                       if($get('signOutLI') == null) return false;
                       $get('signOutLI').innerHTML = " | ";
                    }
                    
                    //Signs user out
                    jQuery("#signOutLI, .signOutUser").click(function() {
                        deleteCookie("_qouid");
                        deleteCookie("_auth");
                        deleteCookie("_qoord");
                        deleteCookie("qoRedirect");
                        deleteCookie("_qosessid");
                        setCookieNonPersistant("_qologout", "");

                        window.location = "/"
                    });
					
					
					//Guest sign in and directs to login page
					jQuery("#guestSignInLI").click(function(){
					
						window.location = baseQuickOrderLoginURL;
					
					});
					
					
                    //jQuery("#welcomeMessage").html('Welcome, ');           
                    //jQuery("#guestCopy").html('Here are some great <strong>DEALS</strong> <br /> at your Pizza Hut.');
                    
                    //Style yeti elements for cookie user
                    jQuery("#yetiFlash").css('padding-bottom', '100px');
                    
                    
                    //Test Banners
                    jQuery('#onlineOrderingBenefit a').removeClass('lightbox');
                    jQuery('#onlineOrderingBenefit a').click(function(){
                        this.setAttribute('href',locationUrl);
                     });
                    
                    if ((userInfo[7] == null) || (userInfo[7] == ""))
                    {
                        deleteCookie("_auth");
                        $get("welcomeLI").innerHTML = "Welcome, Guest! ";
                        $get("guestSignInLI").innerHTML = "(Sign In)&nbsp; | ";
						$get("signOutLI").innerHTML = "";
                        jQuery('.username').html('Guest');
                        jQuery("#guestName").html('Guest');   
                        ShowLastOrderPopup = false;         
                        $get("signInLI").style.display = "none";
                    }
                    else
                    {
                        $get("welcomeLI").innerHTML = "Welcome, " + userInfo[7].substring(1).toUpperCase();  + userInfo[7].substring(2, userInfo[7].length).toLowerCase();  + "!";
                        jQuery('.username').html(userInfo[7]);
                        jQuery("#guestName").html(userInfo[7]);
                        ShowLastOrderPopup = true;
                    }
                    

                    if (getCookie("_auth"))
                    {
                        $get("signOutLI").innerHTML = "| Sign Out |";
                        $get("registerLI").style.display = "none";
                        $get("signInLI").style.display = "none";
                    }
                    else if(userInfo[7] != null)
                    {
                        $get("signOutLI").innerHTML = "(<span class='notUser'>Not " + userInfo[7] + "?</span>) |";
                        $get("signInLI").style.display = "none";
                    }

                    if (userInfo[10] == "N") {
                        $get("registerLI").style.display = "none";
                    }
                    
                    //Remove lightbox class if cookied
                    if(jQuery('.orderNowBtn') != null)
                    {
                        jQuery('#orderNowBtn').removeClass();
                        jQuery('#orderNowBtn').click(function(){
                            if (deliveryType =="C" && ShowLastOrderPopup == false) //If it is a Carryout and Guest user...Goto StoreLocator page.
                            {
                              window.location = baseQuikOrderLocator;
                            }
                            else
                            {
                               window.location = locationUrl;
                            }
                        });
                    }

                    // Need to popup last order here and addItemToCart("LASTORD","1", "lastOrder"); 
                    
                   //Create Sample Sample Cooke to test Last Order
                   //Store~Order~OrderDate~OrderTime~Orderoccasion~Orderdescription
                    //  var lastordervalue = "744105~30901399320391923~20090401~2035~D~1 Medium Hand-Tossed Pizza – Supreme, 1 Pepsi 2-Liter…";
                     // var b64Encodevalue = base64_encode(lastordervalue);
                      //setCookie( "_qolastord", b64Encodevalue , 10000);
                       
                   //Show Last order    
                    
                    if (ShowLastOrderPopup == true)
                    {
                        if (!getCookie("_showlastorder"))
                        {
                   
                            //Read the Cookie("_qolastord") for Last Order Information
                             if (getCookie("_qolastord"))
                             {
                                var base64info1 = getCookie("_qolastord");
                                var lastorderValue = base64_decode(base64info1);
                                var lastorderInfo =  lastorderValue.split("~", 9); 
                                
                              if (lastorderValue != '~~~~~')
                                {
                                    var lastorderDesc  = lastorderInfo[5].split(",");
                                    var lastorderDescFormatted = "";

                                    for ( i = 0; i < lastorderDesc.length; i++) 
                                    {
                                         lastorderDescFormatted += "<li>" + lastorderDesc[i] + "</li>";
                                    }

                                    jQuery(function(){
                                        CreateOverlay();
                                        Center(jQuery('#lastOrderPopup'));
                                        //jQuery(window).resize(AdjustOverlay);
                                        jQuery('#modalBackground').fadeIn(500, function(){jQuery('#lastOrderPopup').show();});
                                        //Here Populate the LighBox with Last Order Information.
                                        jQuery("#Store").html(lastorderInfo[0]);  
                                        jQuery("#Order").html(lastorderInfo[1]);  
                                        jQuery("#OrderDate").html(lastorderInfo[2]);  
                                        jQuery("#OrderTime").html(lastorderInfo[3]);  
                                        jQuery("#Orderoccasion").html(lastorderInfo[4]);  
                                        jQuery("#Orderdescription").html(lastorderDescFormatted);  
                                        jQuery(window).resize(Center(jQuery('#lastOrderPopup')));
                                        jQuery(window).scroll(Center(jQuery('#lastOrderPopup')));
                                    });
                                    
                                    //Set the FLAG NOT to show this LightBox again for this Session. (non-persistant cookie);
                                    setCookieNonPersistant( "_showlastorder", "showlastorder");
                                }
                             }
                         }
                        //End of Last order   
                    }            

                    if (needDeals)
                    {
                    
                        //debugger;
                        if ((userInfo[4] == null) || (userInfo[4] == ""))
                        {
                            // no store number ## CHANGE THIS TO NATIONAL DEALS FOR PRODUCTION ##
                           //GetDealsHTML("997", "L", "0");
                        }
                        else
                        {
                            // get local deal for user's store number
                            //GetDealsHTML(userInfo[4], "L", userInfo[9]);
                        }
                    }
                    else
                    {
                        // need to redirect cookied users that are not on home page to appropriate page
                    
                    }
                    
                     if (getCookie("_qouid"))
                    {
                         if ((userInfo[7] == null) || (userInfo[7] == ""))
                        {
                            $get("welcomeLI").innerHTML = "Welcome, Guest! ";
                            $get("guestSignInLI").innerHTML = "(Sign In)&nbsp; | ";
							$get("signOutLI").innerHTML = "";
                            jQuery('.username').html('Guest');
                            jQuery("#guestName").html('Guest');            
                            //jQuery("#userName").html('Guest');
                        }
                        else
                        {
                            $get("welcomeLI").innerHTML = "Welcome, " + userInfo[7] + "!";
                            jQuery('#myAccountLI').html('<a href="' + myAccount + '" >My Account</a>&nbsp; | ');
                            jQuery('.username').html(userInfo[7]);
                            jQuery("#guestName").html(userInfo[7]);
                            //jQuery("#userName").html(userInfo[7]);
                        }
                    }
           }
           else
           {
            // non-cookied visitor
            IsCookied = "N";
            UpdateNavigation(false);
            if (needDeals)
            {
                //GetDealsHTML("1", "N", "0"); 
            }
           }
        }
        else
        {
            // non-cookied visitor
            IsCookied = "N";
            UpdateNavigation(false);
            if (needDeals)
            {
                //GetDealsHTML("1", "N", "0"); 
            }
        }
          
    }
    
   function PageNeedsDeals() {
      
        var path = window.location.pathname;
        var page = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
        //var needDeals = ((page.indexOf("yeti") >= 0) || (page.indexOf("slinky") >= 0) || (page.length == 0));
        
        return true;
   }

    
   function Login(userID, userPW, isDelivery) {
        
       // var userID = "mtest997"; 
       // var userPW =  "test"; 
       //        var userID = document.getElementById("<%= ReturnUsernameLL.ClientID %>").value; 
       //        var userPW = document.getElementById("<%= ReturnPasswordLL.ClientID %>").value;         
        //debugger;
        
        //Gomez Tracking for Login SUBMIT
        GomezStartInterval("LOGIN_SUBMIT");
        
        DeliveryFlagForUser = isDelivery;
        
        PizzaHut.Web.WS.AEPersonalizationWS.Login(userID, userPW, OnWSRequestLoginComplete, OnWSRequestFailed);
        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
    }
    
    function OnWSRequestLoginComplete(result) {
         //debugger; 
         if (result != null)
         {
              if (result.indexOf("<error>") > 0)
              { 
                jQuery('#invalidAccountWD, #invalidAccountLL, #invalidAccountMH, #invalidAccountDE').slideDown();
              }
              else if (result == "") 
              {
                 //Any Exception on Login WebService. Still push to Quick Order site.
                    window.location = baseQuickOrderLoginURL;
              }
             else
             {
                
                WriteUserCookie(result);
                closeLightbox();  
             }
         }
         else
         {
            window.location = baseQuickOrderLoginURL;
         }
    }    
    
    function closeLightbox()
    {
        jQuery('#loginLightboxWrapper, #orderNowForm, #lastOrderPopup').hide();
        jQuery('#modalBackground').fadeOut(500);
    }

    function UpdateNavigation(isAuthenticated) {
        //var user = User(null);
        if (isAuthenticated) {
            
            PizzaHut.Web.WS.AEPersonalizationWS.GetNavigationReplacers(OnNavigationRequestComplete, OnWSRequestFailed);
        }
        else {
            deleteCookie("_auth");
            if($get("welcomeLI") == null) return false;
            if($get("signOutLI") == null) return false;
           $get("welcomeLI").innerHTML = "";
           $get("signOutLI").innerHTML = "";
        }
    }

    function OnNavigationRequestComplete(navigationReplacers) {
        if (navigationReplacers != null) {
            for (var navigationReplacer in navigationReplacers) {
                var link = document.getElementById(navigationReplacers[navigationReplacer].HrefID);
                if (link != null) {
                    if (link.href != null)
                        link.href = navigationReplacers[navigationReplacer].AuthenticatedUrl;
                }
            }
        }
    }    
    
//    function OnWSRequestUserInfoComplete(userInfo) {    
//    
//         debugger; 
//         if (userInfo != null)
//         {
//              var role = userInfo.Role;
//              if (role == 0)  // non-cookied visitor
//              {
//                GetDealsHTML("1", "N"); 
//              }
//              else if ((userInfo.LastStoreNumber == null) || (userInfo.LastStoreNumber == ""))
//              {
//                GetDealsHTML("997", "L");
//              }
//              else
//              {
//                GetDealsHTML(userInfo.LastStoreNumber, "L");
//              }
//              
//         }
//    }  
     

    // The valid parameters (subject to change) are: 
    //      unitID: 1 (not get line item detail for offer) 997 [store number to pull data for (#997 is default test store)] 
    //      locale: N L or N,L
    //      template: Vertical or Carousel
    //      filter: pizza_offer, wingstreet_offer, meal_deal_offer, catering_offer (or comma delimited list if multiple offers are requested)
    function GetDealsHTML(unitID, locale, totalorders) {
        var template = GetHomePage();   
        
         //GoMez: StartTracking - Deals
         var cookieOriginValue = getCookie("www-origin");
        
        if (cookieOriginValue == null)
            cookieOriginValue = "yeti";
            
         //TrackGomez(GomezEnvironment, cookieOriginValue +  "-HomePage", "Deals");
         
         GomezStartInterval("Deals");


        PizzaHut.Web.WS.AEPersonalizationWS.GetDealsHTML(unitID, locale, null, template, totalorders, OnWSRequestDealsComplete, OnWSRequestFailed);
        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
    }
        
    function OnWSRequestDealsComplete(featuredDealsHTML) {
    
         if (featuredDealsHTML != null)
         {
            if(!$get("DealsRepeaterPlaceholder")){return false};
            jQuery("#DealsRepeaterPlaceholder").html(featuredDealsHTML);
             //$get("DealsRepeaterPlaceholder").innerHTML = featuredDealsHTML;

            GomezEndInterval("Deals");
            
            GomezEndInterval("DefaultPage");
              //GoMez: EndTracking - Deals

         } 
    }
    
    function GetHomePage() {
        //debugger;
        if(!$get("hiddenSpan")){return false};
        //return  $get("hiddenSpan").innerText;
        var hiddenSpan = $get("hiddenSpan");
        var span_text = hiddenSpan.firstChild.data;
        return span_text;
    }
    
    function ShowItem(itemType, itemCode, redirectKey) {
        //debugger;
        addItemToCart(itemType, itemCode, redirectKey);
        if (getCookie("_qouid"))
        {
            // cookied user so pop up confirmation lightbox
            // on confirm do redirect
            window.location = getQuickOrderRedirectURL();
        }             
         
        else
        {
            CreateOverlay();
            Center(jQuery('#loginLightboxWrapper'));
            //jQuery(window).resize(AdjustOverlay);
            jQuery(window).resize(Center(jQuery('#loginLightboxWrapper')));
            jQuery(window).scroll(Center(jQuery('#loginLightboxWrapper')));
            jQuery(modalBack).fadeIn(500, function(){jQuery('#loginLightboxWrapper').show();});
        }
     }       
    
    
    function addItemToCart(itemType, tabCode, itemCode, redirectKey, tracking) {
          if(tracking == null || tracking == undefined)
          {
            tracking = "";
          }
          
          var value = itemType + "~" + tabCode + "~" + itemCode;
          var expires = 10;
          setCookie( "_qoord", value, expires);
          
          //alert(redirectKey + "rrr " +tracking+"yes");
          var url = mapRedirectURL(redirectKey, tracking);
          //alert(url);
          //setCookie( "qoRedirectTest", url, expires);
          var b64value = base64_encode(url);
          setCookie( "qoRedirect", b64value, expires);
          
          
//        var itemType = "PIZZA"; 
//        var itemCode = "MIA"; 
//        PizzaHut.Web.WS.AEPersonalizationWS.AddMenuItemToCart(itemType, itemCode, OnWSComplete);
//        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
        
    }
    
    function ProcessLastOrder() {
        //debugger;
        //Get Coupon Code
        if (getCookie("_qolastord"))
        {
            var base64info1 = getCookie("_qolastord");
            var lastorderValue = base64_decode(base64info1);
            var lastorderInfo =  lastorderValue.split("~", 9); 
            var lastordernumber  = lastorderInfo[1];
            //function addItemToCart(itemType, tabCode, itemCode, redirectKey, tracking) 
            addItemToCart("LASTORD", lastordernumber, '', 'lastOrder');
            if (getCookie("_qouid"))
            {
                window.location = getQuickOrderRedirectURL();
            }             
        }
     }
    function OnWSComplete()
   {
        if (getCookie("test1"))
        {
        
        }
   }
    
    function getQuickOrderRedirectURL() {
    
        // Look in PersonalizationVars.js for Default URL value.
        
        if (getCookie("qoRedirect"))
        {    
            var base64URL = getCookie("qoRedirect");
            QuickOrderRedirectURL = base64_decode(base64URL);
            //setCookie("_qoredirecttest", QuickOrderRedirectURL, 10);
        }
        
        return QuickOrderRedirectURL;
    }
    
    
    function sendToQuikorder()
    {       
        window.location = getQuickOrderRedirectURL() + webTrendCode;                
        return false;
    }

    
    function WriteSeemlessCookie(userAddress, userZip, userCity, userState, isDelivery) {
        //debugger; 
//        var userAddress = document.getElementById("<%= NewAddressLL.ClientID %>").value; 
//        var userZip = document.getElementById("<%= NewZipLL.ClientID %>").value; 
//        var rdo = document.getElementById('<%=NewDeliveryLL.ClientID%>');
//        var userCity = null;
//        var userState = null;
        if (userCity == "Enter your City")
        {
            userCity = "";
        }
        
            
        var cookieValue = ( (userAddress) ? escape( userAddress ) : " " ) +
               ( ( userZip ) ? "~" + userZip : "~" ) +
               ( ( userCity ) ? "~" + userCity : "~" ) +
               ( ( userState ) ? "~" + userState : "~" ) +   "~" +                           
               ( ( isDelivery ) ? "~D" : "~C"  ) + "~~~~~Y";
        var b64value = base64_encode(cookieValue);
        setCookie( "_qouid", b64value, 10);
        //setCookie( "_qouidseemless", cookieValue, 10);
        
        window.location = getQuickOrderRedirectURL() + webTrendCode;
                       
    }    
    
    function WriteSeemlessCookieWingStreet(userAddress, userZip, userCity, userState, ActionType, Action)
    {
//debugger; 
//        var userAddress = document.getElementById("<%= NewAddressLL.ClientID %>").value; 
//        var userZip = document.getElementById("<%= NewZipLL.ClientID %>").value; 
//        var rdo = document.getElementById('<%=NewDeliveryLL.ClientID%>');
//        var userCity = null;
//        var userState = null;
        if (userCity == "Enter your City")
        {
            userCity = "";
        }
        
            
        var cookieValue = ( (userAddress) ? escape( userAddress ) : " " ) +
               ( ( userZip ) ? "~" + userZip : "~" ) +
               ( ( userCity ) ? "~" + userCity : "~" ) +
               ( ( userState ) ? "~" + userState : "~" ) +   "~" +                           
                 ActionType   + "~~~~~Y";
                 

        if (Action == "NewFAL")
        {       
            cookieValue = ( (userAddress) ? escape( userAddress ) : " " ) +
                   ( ( userZip ) ? "~" + userZip : "~" ) +
                   ( ( userCity ) ? "~" + userCity : "~" ) +
                   ( ( userState ) ? "~" + userState : "~" ) +   "~~"  +
                     ActionType   + "~~~~~SL";
        }
        else
        {
             cookieValue = ( (userAddress) ? escape( userAddress ) : " " ) +
                   ( ( userZip ) ? "~" + userZip : "~" ) +
                   ( ( userCity ) ? "~" + userCity : "~" ) +
                   ( ( userState ) ? "~" + userState : "~" ) +   "~" +                           
                   ( ( ActionType ) ? "~D" : "~C"  ) + "~~~~~Y";
        
        }           
              
        var b64value = base64_encode(cookieValue);
        setCookie( "_qouid", b64value, 10);
        //setCookie( "_qouidseemless", cookieValue, 10);

        if (Action == "NewFAL")
        {       
        window.location = QOEnvironmaneURL;
         
        }
        else
        {
            window.location = getQuickOrderRedirectURL() + webTrendCode;
        }
    
    }
    
    function WriteUserCookie(userInfo) {
        
        //debugger; 
        PizzaHut.Web.WS.AEPersonalizationWS.GetQOuidCookieValue(userInfo, DeliveryFlagForUser, OnWSRequestCookieValue, OnWSRequestFailed);
        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
        
    }
    
    function OnWSRequestCookieValue(value) {
        //debugger; 
        //        
        var userInfo =  value.split("sessiontoken", 2);
       
        setCookie("_qosessid", userInfo[1], 10);
        setCookie( "_qouid", userInfo[0], 10);
        var usercookievaluetest = base64_decode(userInfo[0]);
        //setCookie( "_qouidtest", usercookievaluetest, 10);
        
        setCookieNonPersistant("_auth", "auth");
        //Write Session Cookie
         
        //Gomez Tracking for LOGIN_SUBMIT. END
        GomezEndInterval("LOGIN_SUBMIT");
        
        window.location = getQuickOrderRedirectURL() + authenticatedWebTrendCode;
    }    
    
    function setCookie( name, value, expires, domain, secure) {
        // set time, it's in milliseconds, parameter is in seconds
        // domain defaults to quikorder.pizzahut.com if none is supplied
        //debugger;
        var today = new Date();
        today.setTime( today.getTime() );

        if ( expires )
        {
            expires = (expires * 60) * 1000;
        }
        else
        {
            expires = (10 * 60) * 1000;
        }
        
        var expires_date = new Date( today.getTime() + (expires) );
        
        if (name == "_qouid")
        {
            expires_date.setDate(expires_date.getDate() + 30);
        }
        
        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ";path=/;domain=" +
        ( ( domain ) ? domain : DefaultDomain ) + 
        ( ( secure ) ? ";secure=" + secure : "" );

    
//        document.cookie = name + "=" +escape( value ); //+
//        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ";path=/";
         
    }
    
    
    function setCookieNonPersistant( name, value) {

        document.cookie = name + "=" +escape( value ) +  ";path=/;domain=" + DefaultDomain;
         
         
    }
    
    function getCookie( check_name ) {
	    // first we'll split this cookie up into name/value pairs
	    // note: document.cookie only returns name=value, not the other components
	    var a_all_cookies = document.cookie.split( ';' );
	    var a_temp_cookie = '';
	    var cookie_name = '';
	    var cookie_value = '';
	    var b_cookie_found = false; // set boolean t/f default f

	    for ( i = 0; i < a_all_cookies.length; i++ )
	    {
		    // now we'll split apart each name=value pair
		    a_temp_cookie = a_all_cookies[i].split( '=' );


		    // and trim left/right whitespace while we're at it
		    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		    // if the extracted name matches passed check_name
		    if ( cookie_name == check_name )
		    {
			    b_cookie_found = true;
			    // we need to handle case where cookie has no value but exists (no = sign, that is):
			    if ( a_temp_cookie.length > 1 )
			    {
				    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			    }
			    // note that in cases where cookie is initialized but no value, null is returned
			    return cookie_value;
			    break;
		    }
		    a_temp_cookie = null;
		    cookie_name = '';
	    }
	    if ( !b_cookie_found )
	    {
		    return null;
	    }
    }
    
    // this deletes the cookie when called
    function deleteCookie( name ) {
        if ( getCookie( name ) ) 
        {
//            document.cookie = name + "=" + ";path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
            document.cookie = name + "= " + ";expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;domain=" + DefaultDomain;
            
        }
    }
    
    function base64_encode( data ) {
        var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];
     
        if (!data) {
            return data;
        }
     
        data = utf8_encode(data+'');
        
        do { // pack three octets into four hexets
            o1 = data.charCodeAt(i++);
            o2 = data.charCodeAt(i++);
            o3 = data.charCodeAt(i++);
     
            bits = o1<<16 | o2<<8 | o3;
     
            h1 = bits>>18 & 0x3f;
            h2 = bits>>12 & 0x3f;
            h3 = bits>>6 & 0x3f;
            h4 = bits & 0x3f;
     
            // use hexets to index into b64, and append result to encoded string
            tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
        } while (i < data.length);
        
        enc = tmp_arr.join('');
        
        switch( data.length % 3 ){
            case 1:
                enc = enc.slice(0, -2) + '==';
            break;
            case 2:
                enc = enc.slice(0, -1) + '=';
            break;
        }
 
    return enc;
    }
    
    
    function base64_decode( data ) {

        var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
     
        if (!data) {
            return data;
        }
     
        data += '';
     
        do {  // unpack four hexets into three octets using index points in b64
            h1 = b64.indexOf(data.charAt(i++));
            h2 = b64.indexOf(data.charAt(i++));
            h3 = b64.indexOf(data.charAt(i++));
            h4 = b64.indexOf(data.charAt(i++));
     
            bits = h1<<18 | h2<<12 | h3<<6 | h4;
     
            o1 = bits>>16 & 0xff;
            o2 = bits>>8 & 0xff;
            o3 = bits & 0xff;
     
            if (h3 == 64) {
                tmp_arr[ac++] = String.fromCharCode(o1);
            } else if (h4 == 64) {
                tmp_arr[ac++] = String.fromCharCode(o1, o2);
            } else {
                tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
            }
        } while (i < data.length);
     
        dec = tmp_arr.join('');
        dec = utf8_decode(dec);
     
        return dec;
    }
    
    function utf8_decode ( str_data ) {
   
        var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
        
        str_data += '';
        
        while ( i < str_data.length ) {
            c1 = str_data.charCodeAt(i);
            if (c1 < 128) {
                tmp_arr[ac++] = String.fromCharCode(c1);
                i++;
            } else if ((c1 > 191) && (c1 < 224)) {
                c2 = str_data.charCodeAt(i+1);
                tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = str_data.charCodeAt(i+1);
                c3 = str_data.charCodeAt(i+2);
                tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
     
        return tmp_arr.join('');
    } 
    
    function utf8_encode ( string ) {
    
        string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
     
        var utftext = "";
        var start, end;
        var stringl = 0;
     
        start = end = 0;
        stringl = string.length;
        for (var n = 0; n < stringl; n++) {
            var c1 = string.charCodeAt(n);
            var enc = null;
     
            if (c1 < 128) {
                end++;
            } else if((c1 > 127) && (c1 < 2048)) {
                enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
            } else {
                enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
            }
            if (enc != null) {
                if (end > start) {
                    utftext += string.substring(start, end);
                }
                utftext += enc;
                start = end = n+1;
            }
        }
     
        if (end > start) {
            utftext += string.substring(start, string.length);
        }
     
        return utftext;
    }

    function User(cookieVal) {
        
        if (cookieVal != null) {
        }
    
        return {
            IsAuthenticated: false
        };    
        
    }
    
    function Center(popup)
    {
        var windowWidth = jQuery(window).width();
        var windowHeight = jQuery(window).height();
        var scrollLeft = jQuery(window).scrollLeft();
        var scrollTop = jQuery(window).scrollTop();
        var popupWidth = popup.width();
        var popupHeight = popup.height();
        if(jQuery.browser.safari)
        {

              windowHeight = document.documentElement.clientHeight; 

        }
        var leftPos = (windowWidth - popupWidth) / 2 + scrollLeft;
        var topPos = (windowHeight - popupHeight) / 2 + scrollTop;         
        
        popup.css({
            "left" : leftPos,
            "top" : topPos                    
        })         
    }
    
	function CreateOverlay()
    {
        if(!jQuery('#modalBackground').length)
        {
            var modalBack = document.createElement('div');
            var modalId = "modalBackground";
            modalBack.setAttribute("id", modalId);
            document.body.appendChild(modalBack);
            jQuery(modalBack).css({"display": "none", "background-color": modalBackground, "opacity": opacity, "z-index": "50"});
        }
    }       
    
    function AdjustOverlay()
    {
        var windowWidth = jQuery('body').width();
        var windowHeight = jQuery('body').height();
        //jQuery('#modalBackground').css({"width":windowWidth, "height":windowHeight});
    }     
     
    
    function redirect(redirectKey, tracking)
    {
        if(tracking == null || tracking == undefined)
        {
            tracking = "";
        }
        var url = mapRedirectURL(redirectKey, tracking);
        window.location=url;
        return;
    }
    
    function VerifyUrl(Imc2url, qikorderUrl)
    {
        if (IsCookied == "Y")
        {
            window.location = qikorderUrl;
        }
        else
        {
            if(Imc2url != '')
            {
                window.location = Imc2url;  
            }
        }
    }

    function mapRedirectURL(redirectKey, tracking) {        
        // Look in PersonalizationVars.JS for Default Value
        switch (redirectKey){

        case "myhut": 
        return baseQuickOrderURL + PageMyHut + tracking;
        break;
        
        case "pizza": 
        return baseQuickOrderURL + PagePizza + tracking;
        break;
        
        case "pasta": 
        return baseQuickOrderURL + PagePasta + tracking;
        break;
        
        case "wings": 
        return baseQuickOrderURL + PageWings + tracking;
        break;
        
        case "pzone": 
        return baseQuickOrderURL + PagePZone + tracking;
        break;
        
        case "sides": 
        return baseQuickOrderURL + PageSides + tracking;
        break;
        
        case "drinks": 
        return baseQuickOrderURL + PageDrinks + tracking;
        break;
        
        case "deals": 
        return baseQuickOrderURL + PageDeals + tracking;
        break;
        
        case "moreDeals": 
        return baseQuickOrderURL + PageMoreDeals + tracking;
        break;        
        
        case "lastOrder":
        return lastorderLink;
        break;
        
        case "value":
        return baseQuickOrderURL + valueMenu + tracking;
        break;
                                            
        case "ROLL":                
        return baseQuickOrderURL + valueMenu + tracking;
        break;
                                                                           
        default : 
        return baseQuickOrderURL + PageMyHut;
        
        }
    }    
    
    function TrackGomez(Environment, PageID, GroupID)
    {
        //debugger;
        var bPath = jQuery('body').attr('class');
         if (bPath.toLowerCase() == "slinky" || bPath.toLowerCase() == "yeti")
         { 
            //alert("AcctID:" + acctId + "\n" + "PageID:" + pgID + "\n" + "GroupID:" + grpID);
             gomez.acctID= 'BD1D5F';
             gomez.pgId = Environment + PageID;
             gomez.grpId = GroupID;
          }      
      // gomez.nameEvent("AcctID:" + acctId + "|" + "PageID:" + pgID + "|" + "GroupID:" + grpID); //
    }
    
    function GomezStartInterval(IntervalName)
    {
        //debugger;
       var bPath = jQuery('body').attr('class');
       if (bPath.toLowerCase() == "slinky" || bPath.toLowerCase() == "yeti")
       { 
          if (GomezEnvironment == "PRODUCTION")
          {
            gomez.startInterval(IntervalName);
           }
       }
    }
    
    function GomezEndInterval(IntervalName)
    {
        //debugger;
       var bPath = jQuery('body').attr('class');
       if (bPath.toLowerCase() == "slinky" || bPath.toLowerCase() == "yeti")
       { 
            if (GomezEnvironment == "PRODUCTION")    
            {
                gomez.endInterval(IntervalName);
            }
        }
    }