﻿$(document).ready(function () {
    $("#emailPageLink").addClass('thickbox').addClass('email');
    $("#emailPageLink").attr('href', '#TB_inline?height=350&width=370&inlineId=tb_email');
    tb_init('a.thickbox');   

    $('#leftsearchbox').keypress(function(event) {
        if (event.keyCode == '13') {
            event.preventDefault();
            window.location.href='/search/results/?txtSearchText='+escape($('#txtsearchresources').attr('value'));
        }
    });
    $('#leftsearchboxsearch').click(function() {
        window.location.href='/search/results/?txtSearchText='+escape($('#txtsearchresources').attr('value'));
    });
    $('#sitesearchgreenbackground').keypress(function(event) {
        if (event.keyCode == '13') {
            event.preventDefault();
            window.location.href='/search/site/?start=0&q='+escape($('#txtsearchsite').attr('value'));
        }
    });
    $('#btnsitesearch').click(function() {
        window.location.href='/search/site/?start=0&q='+escape($('#txtsearchsite').attr('value'));
    });
    $('#adlitsearchbox').keypress(function(event) {
        if (event.keyCode == '13') {
            event.preventDefault();
            window.location.href='/adlit/search/?start=0&dir=adlit&q='+escape($('#txtadlitsearch').attr('value'));
        }
    });
    $('#btnadlitsearch').click(function() {
        window.location.href='/adlit/search/?start=0&dir=adlit&q='+escape($('#txtadlitsearch').attr('value'));
    });
});

    function ajSend() {
        var smsg = 'Your message was successfully sent.';
        var fmsg = 'There was a problem sending your email, check the email addresses you entered and try again.';
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/webServices/SendEmail.asmx/Message",
            data: "{t:'"+$("#txtEmailTo").attr("value").replace('\'','\\\'')+"',f:'"+$("#txtEmailFrom").attr("value").replace('\'','\\\'')+"',n:'"+$("#txtEmailName").attr("value").replace('\'','\\\'')+"',m:'"+$("#txtEmailMessage").attr("value").replace('\'','\\\'')+"',u:'"+location.href+"',ti:'"+document.title+"',c:'"+$("#chkEmailCC").attr("checked")+"'}",
            dataType: "json",
            success: function(msg) {if (msg.d=='True') {$("#divRMsg").html(smsg)} else {$("#divRMsg").html(fmsg)}}
        })
    };    
    function masterpreloader () {
        if (document.images) {
            var i = 0;
            imageObj = new Image();
            images = new Array();
            images[0]="/graphics/header/disciplines/nav_science.gif"
            images[1]="/graphics/header/disciplines/nav_math.gif"
            images[2]="/graphics/header/disciplines/nav_ela.gif"
            images[3]="/graphics/header/disciplines/nav_science_on.gif"
            images[4]="/graphics/header/disciplines/nav_math_on.gif"
            images[5]="/graphics/header/disciplines/nav_ela_on.gif"
            
            for(i=0; i<=5; i++) { imageObj.src=images[i]; }
        }
    }
    function printwindow() {
        parseUri.options.strictMode = true;
        myurl = parseUri(location.href)
        /* alert(myurl.anchor.length); */
        
        if (myurl.anchor.length == 0 && myurl.query.length == 0) {
            newurl = location.href+'?printpage=print';
        }
        else if (myurl.anchor.length == 0 && myurl.query.length > 0) {
            newurl = location.href+'&printpage=print';
        }
        else if (myurl.anchor.length > 0 && myurl.query.length == 0) {
            newurl=location.href.replace('#','?printpage=print#')
        }
        else {
            newurl=location.href.replace('?','?printpage=print&')
        }
        printwin=window.open(newurl,'formwin','top=100,left=100,height=500,width=695,scrollbars=yes,resizable=yes');
        if (window.focus) {printwin.focus()}
        
    }
            /*
                parseUri 1.2.1
                (c) 2007 Steven Levithan <stevenlevithan.com>
                MIT License
            */

        function parseUri (str) {
            var	o   = parseUri.options,
	        m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
	        uri = {},
	        i   = 14;
            while (i--) uri[o.key[i]] = m[i] || "";
                uri[o.q.name] = {};
                uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
                if ($1) uri[o.q.name][$1] = $2;
            });
            return uri;
        };
        parseUri.options = {
            strictMode: false,
            key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
            q:   {
                name:   "queryKey",
                parser: /(?:^|&)([^&=]*)=?([^&]*)/g
                },
            parser: {
                strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
                loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
            }
        };
