/** Declarations **/
// Call Back Debug - Set Debug flag for successfull returns from JQuery AJAX calls.
var callBackDebug = false;

/** cookie functions **/
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name,"",-1);
}
/** query string functions **/
function getQueryString(key) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == key) return pair[1];
    }
    return null;
}
function setQueryString(query, key, value) {
    var vars = query.split("&");
    var found = false;
    query = "";
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] != "") {
            if (pair[0] == key) {
                query += (query == "" ? "" : "&") + key + "=" + value;
                found = true;
            }
            else query += (query == "" ? "" : "&") + pair[0] + "=" + pair[1];
        }
    }
    if (!found) query += (query == "" ? "" : "&") + key + "=" + value;
    return query;
}
/** object functions **/
function getObject(id) {
    if (document.getElementById) return document.getElementById(id);
    else if (document.layers) return eval("document.layers['" + id + "']");
    else if (document.all) return eval("document.all." + id);
}
/* image swap */
function swapNavImage(img, on) {
    if (on) return img.src = img.src.replace("_off.gif", "_on.gif");
    else return img.src = img.src.replace("_on.gif", "_off.gif");
}
/* snip div swap */
function swapDvVw(dvid, onoff) {
    var snipdv = document.getElementById('s' + dvid);
    var fulldv = document.getElementById('d' + dvid);

    if (onoff == "0") {
        snipdv.style.display = "block";
        fulldv.style.display = "none";
    }
    if (onoff == "1") {
        snipdv.style.display = "none";
        fulldv.style.display = "block";
    }
}
function swapArtVw(dvid, un, onoff, isnew) {
    var snipdv = document.getElementById('s' + dvid);
    var fulldv = document.getElementById('d' + dvid);

    if (onoff == "0") {
        snipdv.style.display = "block";
        fulldv.style.display = "none";
    }
    if (onoff == "1") {
        $.post('LogHandler/PartContent.aspx', { ContentId: dvid, Un: un, IsNew: isnew }, function(data, textStatus) {
            myLoggerCallBack(data, textStatus);
        });
        //$.get('LogHandler/PartContent.aspx', { ContentId: dvid, Un: un }, function(data, textStatus) {
        //    myLoggerCallBack(data, textStatus);
        //});

        if (isnew == "1") {
            var artNewFlag = document.getElementById('new' + dvid);
            artNewFlag.style.display = "none";

            var asnipref = document.getElementById('as' + dvid);
            asnipref.href = asnipref.href.replace(/\,\'1\'\)/, ",'0')")
        }
        snipdv.style.display = "none";
        fulldv.style.display = "block";
    }
}
function myLoggerCallBack(data, textStatus) {
    if (textStatus != "success") {
        alert("Communication with the server, disrupted");
        //alert("Done " + textStatus + "\r\n" + data);
    }
    else {
        if (callBackDebug)
            alert("Done " + textStatus + "\r\n" + data);
    }
}
