﻿var base = "http://www.mesoweb.com/resources/bibliography.html#";
var base2 = "http://www.mesoweb.com/";
var base3 = "http://";
var base4 = "http://www.mesoweb.com/encyc/";
var base6 = "http://www.mesoweb.com/rubbings/resources/";

var base7 = "http://www.mesoweb.com/biblio/index.asp?display=author&author=";
var base8 = "http://www.mesoweb.com/biblio/index.asp?display=search";
var base9 = "http://www.mesoweb.com/biblio/index.asp?display=authordate&author=";

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}




function open_window(name) {
    url = name;
    openwin =
window.open(name, '_blank', 'toolbar=yes, location=yes, menubar=yes, width=700, height=440, status=yes, scrollbars=yes, resizable=yes');
}

function launch2(name) {
    url = base6 + name;
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,menubar=no,width=500,height=440,status=no,scrollbars=auto,resizable=yes');
}

//function launch(name)
//{
//  url=base+name;
//  openwin = window.open(url,'_blank','toolbar=no,location=no,menubar=no,width=500,height=440,status=no,scrollbars=auto,resizable=yes');
//}

function launch(name) {
    url = base + name;
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,width=500,height=640,status=no,scrollbars=yes,resizable=yes');
}

function biblio(name) {
    url = base7 + URLEncode(name);
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,width=900,height=750,status=no,scrollbars=yes,resizable=yes');
}

function biblio2(name, dateletter) {
    url = base9 + URLEncode(name) + "&dateletter=" + dateletter;
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,width=900,height=750,status=no,scrollbars=yes,resizable=yes');
}


function biblio3(search, searchand, searchnot, exactMatch) {
    url = base8 + "&strSearch=" + search + "&strSearchAnd=" + searchand + "&strSearchAndNot=" + searchnot;
    if (exactMatch != null) {
        if (exactMatch == true) {
            //setCookie("biblio_exactmatch", "y");
            url += "&passexact=y"
        } else {
            url += "&passexact=n"
            //setCookie("biblio_exactmatch", "n");
        }
    }
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,width=900,height=750,status=no,scrollbars=yes,resizable=yes');
}


function biblio_orig(name) {
    url = base + name;
    openwin = window.open(url, '_blank', 'toolbar=no,location=no,width=500,height=640,status=no,scrollbars=yes,resizable=yes');
}

function encyc(firstname, lastname) {
    url1 = base4 + "index.asp?passcall=sitenosearch&passWord=" + lastname + "&passwordAND=" + firstname
    openwin = window.open(url1, '_blank', 'toolbar=yes,location=yes,width=700,height=440, status=yes,scrollbars=yes,resizable=yes');
}

function encyc_search(strSearch) {
    url = base4 + "index.asp?passcall=site&passS=" + strSearch + "&id2=0&expert=y"
    openwin =
window.open(url, '_blank', 'toolbar=yes,location=yes,menubar=no,width=700,height=440,status=yes,scrollbars=yes,resizable=yes');
}

function site(name, w, h) {
    url = base2 + name;
    openwin =
window.open(url, '_blank', 'toolbar=yes,location=yes,width=' + w + ',height=' + h + ',status=yes,scrollbars=yes,resizable=yes');
}

function simple(name, w, h) {
    url = base2 + name;
    openwin =
window.open(url, '_blank', 'toolbar=no,location=no,width=' + w + ',height=' + h + ',status=no,scrollbars=no,resizable=yes');
}

function web(name, w, h) {
    url = base3 + name;
    openwin =
window.open(url, '_blank', 'toolbar=yes,location=yes,width=' + w + ',height=' + h + ',status=yes,scrollbars=yes,resizable=yes');
}

if (document.images) {

    no_returnarrow = new Image
    yes_returnarrow = new Image

    no_returnarrow.src = "media/ReturnGlyph.gif"
    yes_returnarrow.src = "media/ReturnGlyphOver.gif"
}

function chgImg(imgField, newImg) {
    if (document.images) {
        document[imgField].src = eval(newImg + ".src")
    }
}


function getCookie(name) { // use: getCookie("name");
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
}

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

function setCookie(name, value) { // use: setCookie("name", value);
    document.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}

function setSessionCookie(name, value) { // use: setCookie("name", value);
    document.cookie = name + "=" + escape(value)
}

function ToggleExactMatchCookie() {
    if (getCookie("encyc_exactmatch") == "y") {

        setCookie("encyc_exactmatch", "n");

    } else {

        setCookie("encyc_exactmatch", "y");
    }

}

function open_window(name) {
    url = name;
    openwin =
window.open(name, '_blank', 'toolbar=yes, location=yes, menubar=yes, width=700, height=440, status=yes, scrollbars=yes, resizable=yes');
}
