/* Get JQuery full error message */
function GetjQueryErrorMessage(request, status, error) {
    return ("status: " + status + ", error: " + error + ", request.status: " + request.status + ",request.readyState: " + request.readyState);
}


/* Slideshow code - ported from current site */
var slideimages, whichimage, imageholder;
var ie55 = window.createPopup;
var slideCount = 1;

function slideshow(dir, NumOfSlides) {
    if (!document.images) return;
    numberSlides = NumOfSlides; // how many slides
    slideCount += dir;
    if (slideCount < 1) slideCount = 1;
    if (slideCount > numberSlides) slideCount = numberSlides;
    document.images.slide.src = eval('slide' + slideCount);
}


function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}


function flipSortOrder(sortOrder) {
    var s = ""
    if (sortOrder == "desc") {
        s = "asc"
    }
    else {
        s = "desc"
    }
    return s
}

function validEmail(s) {
    //cheap email address check
    if (s == "") {
        return false;
    }
    if ((s.length > 10) && (s.indexOf("@") > 0) && (s.indexOf(".") > 0)) {
        return true;
    }
    else {
        return false;
    }
}


function enterKey() {

    $(window).keypress(function (e) {
        if (e.keyCode == 13) {
            return true;
        }
        else {
            return false;
        }
    });
}

function openSpotlightPrint(id) {
    popupwindow = window.open('spotlightPrint.aspx?ID=' + id, 'spotlightPrint', 'location=yes,scrollbars=yes,width=682,height=550,top=20,left=20');
    if (window.focus) { popupwindow.focus() }
}

function openCatalogPrint(id) {
    popupwindow = window.open('catalogPrint.aspx?ID=' + id, 'spotlightPrint', 'location=yes,scrollbars=yes,width=682,height=550,top=20,left=20');
    if (window.focus) { popupwindow.focus() }
}

function openNewsPrint(id) {
    popupwindow = window.open('newsPrint.aspx?ID=' + id, 'newsPrint', 'location=yes,scrollbars=yes,width=682,height=550,top=20,left=20');
    if (window.focus) { popupwindow.focus() }
}


String.prototype.left = function (n) {
    if (n <= 0) {
        return "";
    }
    else if (n > this.length) {
        return this;
    }
    else {
        return this.substring(0, n);
    }
}

String.prototype.right = function (n) {
    if (n <= 0) {
        return "";
    }
    else if (n > this.length) {
        return this;
    }
    else {
        return this.substring(this.length, this.length - n);
    }
}
