﻿/* ******************************************************************************************* */
/* jQuery Support */
/* ******************************************************************************************* */
$(document).ready(
    function() {
        var after_type_cast = {};
        var before_type_cast = {};
        var cached = false;

        jQuery.query = function(cast) {
            if (!cached) {
                // remove leading ? and trailing &
                var q = location.search.replace(/^\?/, '').replace(/\&$/, '').split('&');
                for (var i = q.length - 1; i >= 0; i--) {
                    var p = q[i].split('='), key = p[0], val = p[1];
                    before_type_cast[key] = val;
                    // convert floats
                    if (/^[0-9.]+$/.test(val))
                        val = parseFloat(val);
                    // convert booleans
                    if (/^(true|false)$/.test(val))
                        val = (val == 'true');
                    // ingnore empty values
                    if (val)
                        after_type_cast[key] = val;
                }
                cached = true;
            }
            return cast === false ? before_type_cast : after_type_cast;
        };
        if ($("input#ctl00_txtSearch").html() != null) {
            $("input#ctl00_txtSearch").val($.query().q);

            $("input#ctl00_txtSearch").bind("onkeydown", function(e) {
                var key = 0;
                e = (window.event) ? event : e;
                key = (e.keyCode) ? e.keyCode : e.charCode;
                var obj = document.getElementById('ctl00_txtSearch');
                if (e.keyCode == 13) {
                    obj.focus();
                    var v = $("input#ctl00_txtSearch");
                    window.location = "/search-results.aspx?q=" + v.val();
                }
                return false;
            });

        }
        $("input#ctl00_ibtnSearch").bind("click", function(e) {
            var v = $("input#ctl00_txtSearch");
            window.location = "/search-results.aspx?q=" + v.val();
            return false;
        });

        $(".FAQ a.Question").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.Answer").toggle();
            return false;
        });
        $(".DMSSearch a.DMSAdvancedSearchLink").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.DMSAdvancedSearchOptions").toggle();
            return false;
        });

        $("a.photoGallery").bind("click", function(e) {
            var flashvars = {};
            flashvars.paramXMLPath = "/app_common/flash/param.xml";
            flashvars.xmlFilePath = $(this).attr("href");

            var params = {};

            params.mediaPlayerScale = "100";
            params.contentAreaBackgroundAlpha = "100";
            params.contentAreaBackgroundColor = "0x000000";
            params.galleryBackgroundColor = "0x000000";
            params.allowfullscreen = "true";

            var attributes = {};

            swfobject.embedSWF("/app_common/flash/slideshowpro.swf", "photogallery", "808px", "456px", "9.0.0", false, flashvars, params, attributes);
            tb_show('', '#TB_inline?width=808&height=486&inlineId=galleryContent&modal=true');
            return false;
        });
        $("a.calculator").bind("click", function(e) {
            var href = $(this).attr("href");
            var title = $(this).attr("title");
            tb_show(title, href);
            return false;
        });
        $("input#SearchResultState1").bind("click", function(e) {
            $("tr.ResultItem").show();
        });
        $("input#SearchResultState2").bind("click", function(e) {
            $("tr.ResultItem").hide();
        });
        $("a.CloseDialog").bind("click", function(e) {
            //var htmlData = '<div id="galleryContent" style="background-color: #000;"><div id="TB_caption">Photo Gallery</div><div id="TB_closeWindow"><a href="#" id="TB_closeWindowButton" title="Close" class="CloseDialog">close</a></div><div id="photogallery"></div></div>';
            //$("div#galleryContainer").html(htmlData);
        });

    }
);

/* ******************************************************************************************* */
/* General Support */
/* ******************************************************************************************* */
function OnChangeQuicklinks(dropdown)
{
    top.location.href = dropdown.value;
    return true;
}

function detectOnState(ele, className) {
    var onObject = document.getElementById(ele);
    if (navigator.appName.indexOf("Microsoft") != -1)
        onObject.className = className;
    else
        onObject.setAttribute("class", className);
}
function detectOffState(ele, className) {
    var OffObject = document.getElementById(ele);
    if (navigator.appName.indexOf("Microsoft") != -1)
        OffObject.className = className;
    else
        OffObject.setAttribute("class", className);
}