function GetDomain() {
    var domain = $.url(true).attr('host');
    return domain[0] == '.' ? domain : '.' + domain;
    //return domain
};

function CreateCookie() {
    var domain = GetDomain();
    
    $.cookie('cookieAgreement', 'True', { path: '/', domain: domain });
};

function DeleteCookie(){
    var domain = GetDomain();

    $.cookie('cookieAgreement', 'True', { path: '/', expires: -1, domain: domain });
}

// Check if cookieAgreement's value is True
function CheckCookie() {
    var cookievalue = $.cookie('cookieAgreement');
    
    if (cookievalue == "True") {
        return true;
    }

    return false;
}

// Check if URL is for a subcategory of /Services
function CheckURL() {
    //If Agreement Cookie is present - No need to check url
    if (CheckCookie()) {
        return;     
    }
    
    var url = window.location.pathname; 

    var spliturl = url.toLowerCase().split("/");
    
    if ((spliturl[1] == "services") || (spliturl[1] == "on-the-record")) {
        // If the URL contains /Services & addresses a subcateogry after (eg. /Services/Client-Focus) - Return true
        if ((spliturl[2] != "videos") && (spliturl[2] != null && spliturl[2] != "" && spliturl[2] != undefined)) {
            $('#disclaimer_dialog').dialog('open');
        }
        else {

        }
    }
}

// Check Link URL & Check if it addresses a subcategory of /Services
function CheckLinkURL(url) {
    //If Agreement Cookie is present - return false
    if (CheckCookie()){return false;}
    
    var spliturl = "";
    
    if(url != undefined) {
        spliturl = url.split("/");
    }
    
    if ((spliturl[1] == "services") || (spliturl[1] == "on-the-record")) {
        // If the URL contains /Services & addresses a subcateogry after (eg. /Services/Client-Focus) - Return true
        if ((spliturl[2] != "videos") && (spliturl[2] != null && spliturl[2] != "" && spliturl[2] != undefined)) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }  
}

// Redirect to Services - Usually in the case a subcategory of /Services was open directly without navigating to it
function Redirect() {
  if ((window.location.pathname).split("/")[1].toString().toLowerCase() == "services"){
    window.location = "/Services";
     }
    if ((window.location.pathname).split("/")[1].toString().toLowerCase() == "on-the-record"){
    window.location = "/on-the-record";
    }
}
