$(document).ready(function () {

    // header search events
    $("#search-button").click(SiteSearch);
    $('#search-text').keypress(function (event) {
        if (event.keyCode == '13') SiteSearch();
    });

});

function spmd(domain, name, subject, body) {
    var qs = "?1=1";
    if (subject != "")
        qs += "&subject=" + subject;
    if (body != "")
        qs += "&body=" + body;
    if (qs == "?1=1")
        qs = "";
    location.href = 'mailto:' + name + '@' + domain + qs;
}

// ---------------------------
// function to prevent email being spidered
function noEspam(theName, theDomain, theLink, theExtras) {

    if (theLink.length == 0) {
        theLink = theName + '@' + theDomain
    }
    document.write('<a href="mailto:' + theName + '@' + theDomain + theExtras + '">' + theLink + '</a>');

}

// ---------------------------
// minimap display (on homepage)

function ShowMap(ii) {
    var offset = (ii * 290) * -1;
    $("#minimap").css("background-position", offset + "px 0px");
}

function ResetMap() {
    $("#minimap").css("background-position", "0 0");
}



// ---------------------------
// Site search functions
function SiteSearch() {

    var zoom_query = $('#search-text').val();

    if (zoom_query.length >= 3) {        
        location.href = "/search/results.html?zoom_per_page=10&zoom_and=1&zoom_query=" + encodeURIComponent(zoom_query);
    }

    return false;
}

// --------------------------------
// function to retrieve qs param (used in search)
var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
        urlParams[d(e[1])] = d(e[2]);
})();




/*
* jQuery JavaScript plugin
*
* URLDecode/Encode
* (used in search)
*
* http://0061276.netsolhost.com/tony/testurl.html
*
*/

$.extend({ URLEncode: function (c) {
    var o = ''; var x = 0; c = c.toString(); var r = /(^[a-zA-Z0-9_.]*)/;
    while (x < c.length) {
        var m = r.exec(c.substr(x));
        if (m != null && m.length > 1 && m[1] != '') {
            o += m[1]; x += m[1].length;
        } else {
            if (c[x] == ' ') o += '+'; else {
                var d = c.charCodeAt(x); var h = d.toString(16);
                o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase();
            } x++;
        }
    } return o;
},
    URLDecode: function (s) {
        var o = s; var binVal, t; var r = /(%[^%]{2})/;
        while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b); o = o.replace(m[1], t);
        } return o;
    }
});


// ---------------------------
// Returns true if the browser is Internet Explorer, false otherwise.
function isIE6() {
    return ($.browser.msie && $.browser.version == 6);
}
