﻿// Module pattern using anonymous function
(function() {

    // Current url
    var Url = location.href.toLowerCase();
    var Referrer = document.referrer.toLowerCase();
    
    // Configuration
    var config = {
        // Login status
        loginID: '#'+ BaseMasterPageUniqueID + 'hdnLoggedIn'
    };                 
    
    // Set language
    if(Omniture_culture)
    {
        s.prop23 = Omniture_culture.split('-')[0];
    }

    /********* FOR LOGIN*********/
    if ($(config.loginID) != null)
    {
        if ($(config.loginID).attr("value").split('|')[0] == 'LoggedIn')
        {
            var isDC = $(config.loginID).attr("value").split('|')[1] == 'DC' ? true : false;

            if (isDC) s.events = "event5";
            else s.events = "event7";                    
        }
    }
    /******** FOR LOGIN ********/          
    
    
    /******** CUSTOMER FEEDBACK ********/
    if(Url.indexOf('/contact-us/thank-you.aspx') != -1 || 
        Url.indexOf('/contacto/gracias.aspx') != -1 ||
        Url.indexOf('/contacts/merci.aspx') != -1 || 
        Url.indexOf('/contact-opnemen/bedankt.aspx') != -1)
    {   
        // thank you page is only reached after submitted website feedback form                    
        s.eVar22="website feedback";                     
    }
    /******** CUSTOMER FEEDBACK ********/ 
    
               
    /******** FOR DIAMOND CLUB SIGN UP ********/
  
    if(Url.indexOf('/my-account/manage-my-account.aspx') != -1 && Referrer.indexOf('/my-account/join-diamond-club.aspx') != -1 || 
        Url.indexOf('/mon-compte/gerer-mon-compte.aspx?conftype=diamondclubnew') != -1 ||
        Url.indexOf('/mi-cuenta/mi-cuenta.aspx?conftype=diamondclubnew') != -1 || 
        Url.indexOf('/mijn-account/account-bijwerken.aspx?conftype=diamondclubnew') != -1)               
    {           
        s.events="event4";    
    }
    /******** FOR DIAMOND CLUB SIGN UP ******/
    
    
    /******** FOR NEWSLETTER/NEW ACCOUNT SIGN UP ********/
    if(Url.indexOf('/my-account/manage-my-account.aspx') != -1 && Referrer.indexOf('/my-account/sign-up-for-emails.aspx') != -1 || 
        Url.indexOf('/mon-compte/gerer-mon-compte.aspx?conftype=profilenew') != -1 ||
        Url.indexOf('/mi-cuenta/mi-cuenta.aspx?conftype=profilenew') != -1 || 
        Url.indexOf('/mijn-account/account-bijwerken.aspx?conftype=profilenew') != -1)               
    {
        s.events="event8,event6";                   
        s.eVar21="newsletter type"; 
    }
    /******** FOR NEWSLETTER/NEW ACCOUNT SIGN UP ********/           
    
    // Page needs to be fully loaded to track these 
    $(function() {            
        /********* FOR ONLINE CHECK-IN*********/
        if (Url.indexOf('/manage-my-booking/online-check-in.aspx') != -1 ||
            Url.indexOf('/gerer-ma-reservation/enregistrement-en-ligne.aspx') != -1 ||
            Url.indexOf('/gestionar-su-reserva/facturacion-a-traves-de-la-web.aspx') != -1 ||
            Url.indexOf('/boeking-bijwerken/online-check-in.aspx') != -1)
        {
            // Find the first item on the breadcrumb
            var olckiBreadCrumb = $("div.progressBox ul li:first").get(0);
            
            // If it exists
            if (olckiBreadCrumb)
            {   
                // If that first item is selected, then its the first step, so track
                if (olckiBreadCrumb.className == 'Selected')                    
                {
                    s.events="event14"; 
                    // Trigger manual tag
                    var s_code=s.t();if(s_code)document.write(s_code);
                }
                                       
            }                    
        }           
        /********* FOR ONLINE CHECK-IN*********/
        
        /******** CUSTOMER RELATIONS ********/
        if(Url.indexOf('/contact-us/customer-relations.aspx') != -1 || 
            Url.indexOf('/contact-opnemen/customer-relations.aspx') != -1 ||
            Url.indexOf('/contacts/relations-clientele.aspx') != -1 || 
            Url.indexOf('/contacto/atencion-al-cliente.aspx') != -1)
        {
            
            // If we get a success message, then we have submitted a form
            if ($("span div.Success").size() != 0)
            {
                s.eVar23="customer relations feedback";
                // Trigger manual tag
                var s_code=s.t();if(s_code)document.write(s_code);
            }
        }
        /******** CUSTOMER RELATIONS ********/
    });             
        

})();