﻿///<reference path="jquery-1.4.1-vsdoc.js

function popupWindow(sender) {
    var url = sender.options[sender.selectedIndex].value;
    if (url != "")
        window.open(url, "newwindow");
}

function selfWindow(sender) {
    var url = sender.options[sender.selectedIndex].value;
    if (url != "")
        location.href = url;
}

$(document).ready(function() {


    //amend all relative and external hyperlinks. So anything beginning with http change target to new window, within site is self 
    //////////////////////////////////////////////////////////////
    $("a[href^=http]").attr("target", "_blank");
    $("a[href]").not("[href^=http]").not(".jqueryOverride").attr("target", "_self");
    //////////////////////////////////////////////////////////////

    //disable submit button after submitting - !!prevents postback so disabled for now!!
    //////////////////////////////////////////////////////////////
    /*
    $("form").submit(function() {
    $(":submit", this).attr("disabled", "disabled");
    });
    */
    //////////////////////////////////////////////////////////////

    //Menu navigation
    //////////////////////////////////////////////////////////////
    var timeout = 500;
    var closetimer = 0;
    var ddmenuitem = 0;

    function jsddm_open() {
        jsddm_canceltimer();
        jsddm_close();
        ddmenuitem = $(this).find('ul').css('visibility', 'visible');
    }

    function jsddm_close()
    { if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

    function jsddm_timer()
    { closetimer = window.setTimeout(jsddm_close, timeout); }

    function jsddm_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }

    $(document).ready(function() {
        $('#menuDropDown > li').bind('mouseover', jsddm_open)
        $('#menuDropDown > li').bind('mouseout', jsddm_timer)
    });

    document.onclick = jsddm_close;
    //////////////////////////////////////////////////////////////

    //confirm postback action
    //////////////////////////////////////////////////////////////
    $(".confirm").click(function() {
        return confirm("Are you sure?");
    });
    //////////////////////////////////////////////////////////////

    //Only allow numerics
    //////////////////////////////////////////////////////////////
    $(".numeric").keydown(function(event) {
        if (event.keyCode == 46 || event.keyCode == 8) {
        } else {
            if (event.keyCode < 95) {
                if (event.keyCode < 48 || event.keyCode > 57) {
                    event.preventDefault();
                }
            } else {
                if (event.keyCode < 96 || event.keyCode > 105) {
                    event.preventDefault();
                }
            }
        }
    });
    //////////////////////////////////////////////////////////////




    //submit buttons - assign CSS and hover CSS
    /*
    $('input[type=submit]').hover(function() {
    $(this).addClass('stripe1');
    }
    ,
    function() {
    $(this).removeClass('stripe1');
    }

            ).addClass('stripe');

*/

    //event testing for onclick on buttons
    /* 
    $('input[type=submit]').each(function() {
    var button = this;
    button.onclick = function(event) {
    //IE tricks to fill event and target variables
    if (!event) event = window.event;
    var target = (event.target) ? event.target : event.srcElement;

            //test action
    alert(target.id);
    return false;
    }
    });
    */
    //assign table row hover
    /*    
    $('table tr').hover(
    function() {
    $(this).addClass('tableRowHover');
    }
    ,
    function() {
    $(this).removeClass('tableRowHover');
    }
    );

    //apply css to all even rows
    $(document).ready(function() {
    $('table tr:nth-child(even)').addClass("tableRowStripe");
    });
    */
});



//Create and Read Cookies
//////////////////////////////////////////////////////////////
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;
}
//////////////////////////////////////////////////////////////


//Set site font-size
//////////////////////////////////////////////////////////////
function resizeText() {
    if (readCookie('fontSize') == null) {
        createCookie('fontSize', '0.7', 7);
    }

    if (document.body.style.fontSize == "") {
        document.body.style.fontSize = "0.7em";
    }
    document.body.style.fontSize = readCookie('fontSize') + 'em';
    return false;
}

function setText(fontvalue) {
    createCookie('fontSize', fontvalue, 7);
    return false;
}
//////////////////////////////////////////////////////////////
