var utmb = get_utm_value(document.cookie, '__utmb=', ';');
var utmc = get_utm_value(document.cookie, '__utmc=', ';');
var pageview_count = get_utm_value2(utmb, utmc);
if(pageview_count<=1)
{
    set_customer_type('just-looking');
}


function set_customer_type(customer_type)
{
    //pageTracker._setCustomVar(1, 'visitor-type', customer_type, 2);
    //pageTracker._trackPageview();
    _gaq.push(['_setCustomVar',1, 'visitor-type', customer_type, 2]);
    _gaq.push(['_trackPageview']);
}

//This function extracts the '_utmb' and '_utmc' string from the cookies set by Google Analytics
function get_utm_value(l,n,s)
{
    if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
    var i, i2, i3, c='-';
    i=l.indexOf(n);
    i3=n.indexOf('=')+1;
    if (i > -1)
    {
        i2=l.indexOf(s,i);
        if (i2 < 0)
        {
            i2=l.length;
        }
        c=l.substring((i+i3),i2);
    }
    return c;
}
//This function extracts the 'pageview count' value from the _utmb cookie
function get_utm_value2(utmb,utmc)
{
    var i, j, k;
    var utmc=utmc+'.';
    i=utmc.length;
    j=utmb.indexOf('.', i);
    k=utmb.substring(i,j);
    return k;
}

function trigger_main_action(action)
{
    // change the visitor type
    //pageTracker._setCustomVar(
    //      1,                   // This custom var is set to slot #1
    //      "visitor-type",           // The top-level name for your online content categories
    //      "perform-main-action",      // Sets the value of "Section" to "Life & Style" for this particular aricle
    //      2                    // Sets the scope to session-level
    //   );
    _gaq.push(['_setCustomVar',1, 'visitor-type', 'perform-main-action', 2]);

    // save the main action performed
    //pageTracker._setCustomVar(
    //      4,                   // This custom var is set to slot #4
    //      "main-action",       // The top-level name for your online content categories
    //      action,              // the action performed
    //      3                    // Sets the scope to page-level
    //   );

    _gaq.push(['_setCustomVar',4, 'main-action', action, 3]);

    //pageTracker._trackPageview();
    _gaq.push(['_trackPageview']);
}


// trace main action when the page is loaded
$(document).ready( function(){
    // trace menu usage
    $("#express_booking").click( function(){
        trigger_main_action("using_express_booking_menu");
    });

    $("#search_restaurant").click( function(){
        trigger_main_action("using_search_restaurant_menu");
    });

    // trace main action in different pages
    if ( typeof(trace_main_action) == "function")
    {
        trace_main_action();
    }
} );



