var cookieval = "";
var agentname = '';
var LCStatus = "";
var LCSPriority = "";
var CustomerName = "";
var CustomerCode = "";


function GetCookie(cookiename) {
    cookieval = $.cookies.get(cookiename);
    return cookieval;
}



function Get_CookieStudent(check_name) {

    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;
    for (i = 0; i < a_all_cookies.length; i++) {
        a_temp_cookie = a_all_cookies[i].split('=');
        if (a_temp_cookie != null) {
            if (a_temp_cookie.length > 1) {
                cookie_name = a_temp_cookie[1].replace(/^\s+|\s+$/g, '');
            }
        }
        if (cookie_name == check_name) {
            b_cookie_found = true;
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[2].replace(/^\s+|\s+$/g, ''));
            }
            return cookie_value;
            break;
        }
        a_temp_cookie = null; cookie_name = '';
    } if (!b_cookie_found) { return null; }
}

/* Monitoring Tag */

function MonitorTag() {

    agentname = GetCookie('salesAgentName');
    LCStatus = GetCookie('LCStatus');
    LCSPriority = GetCookie('LCSPriority');
    CustomerName = GetCookie('CustomerName');

    CustomerCode = Get_CookieStudent('STUDENTCODE');

    if (LCStatus == null) {
        LCStatus = "Unknown Customer" + ' - ' + "Signup Pending";
        LCSPriority = "3c"
    }

    
    setSessionVar();
}


/* Setting Variables for Session of Skill and Operator */

function setSessionVar() {

    if (typeof (lpMTagConfig.sessionVar) == "undefined") {
        lpMTagConfig.sessionVar = new Array();
    }
    if (agentname != null && agentname != "") {
        lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = 'skill=' + agentname;
    }

    if (LCStatus != null && LCStatus != "") {
        lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = 'Life Cycle Status=' + LCStatus;
    }

    if (LCSPriority != null && LCSPriority != "") {
        lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = 'LC Status Priority=' + LCSPriority;

    }

    if (CustomerName != null && CustomerName != "") {
        lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = 'Customer Name=' + CustomerName;
        lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = 'identifier=' + CustomerName;
    }
}


MonitorTag();

