﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />



$(document).ready(function() {

    $('#loading-indicator').hide();

    /*bind function to resize event*/
    $(window).wresize(ResizeContent);
    /*call on load*/
    ResizeContent();

    /*setup gloabl ajax vaiable settings*/
    $('#loading-indicator')
    .bind('ajaxStart', function() {
        $(this).css("visibility", "visible");
    })
    .bind('ajaxComplete', function() {
        $(this).css("visibility", "hidden");
    });
    $.ajaxSetup({
        cache: true,
        error: function(xhr, status, error) {
            alert('An error occurred: ' + error);
        },
        timeout: 60000, // Timeout of 60 seconds
        type: 'POST',
        url: 'AjaxDefault.htm'
    }); // Close $.ajaxSetup()


    if ($.browser.msie && $.browser.version < 8) {
        /*fix transparent png backgound problem in older IE*/
        $(document).pngFix();
    }

    /*apply grid style*/
    $(".grid-pager").find("table").css("width", "200");
    ColorCodeTable();

    if (!$.browser.msie) {
        $("div#login-box div:first").corner();
        $(".grid-mask").corner("round 4px");   
    }
    else {
        $("input[id$='Login1_UserName']").css("width", "170");
        $("input[id$='Login1_Password']").css("width", "170");
    }

    /*Add style to new record button*/
    $("a[id$='HyAddNewItem']").addClass("ui-default ui-content ui-corner add");
    $("a[id$='HyAddNewItem']").parent().css("height", "30px");
    $("input[id$='ExportAndPrint2_hyExportToExcel']").removeClass("ui-default ui-content ui-corner");
    $("input[id$='hyExportToWord']").removeClass("ui-default ui-content ui-corner");
});   // Close .ready

function ResizeContent() {
    var windowheight = $(window).height();
    var windowwidth = $(window).width();   // returns height of browser viewport
    var contentheight = $("#main-content").height();
    var menuheight = $("#side-menu").height();

    /*handle width*/
    if (windowwidth <= 1179) {
        //alert($("#side-menu").html());
        if ($("#side-menu").html() == null)
            $("#main-content").css("width", 920);
        else
            $("#main-content").css("width", 740);
    }
    else {
        $("#main-content").css("width", windowwidth - $("#side-menu").width() - 235);
    }

    /*handle height*/
    if (contentheight > menuheight) {
        if (contentheight > 650) {
            //alert(adjustmentFactor);
            $("#content-area").css("height", contentheight + 65);
        } else {
            $("#content-area").css("height", 650);
            $("#main-content").css("height", 625);
        }
    }
    else {
        if (menuheight > 650) {
            $("#content-area").css("height", menuheight);
        } else {
            $("#content-area").css("height", 650);
            $("#main-content").css("height", 625);
        }
    }
}

/*this fix the hidden dialog height problem when called at end of the page with hidden jQuery UI dialog div's*/
function ApplyHeightFix() {
/*
    var contentheight = $("#main-content").height();
    var menuheight = $("#side-menu").height();
    /*handle height/
    if (contentheight > menuheight) {
        if (contentheight > 650) {
            //alert(adjustmentFactor);
            $("#content-area").css("height", contentheight + 65);
        } else {
            $("#content-area").css("height", 650);
            $("#main-content").css("height", 625);
        }
    }
    else {
        if (menuheight > 650) {
            $("#content-area").css("height", menuheight);
        } else {
            $("#content-area").css("height", 650);
            $("#main-content").css("height", 625);
        }
    }*/
    
}

/*color codes the data grid view output table*/
function ColorCodeTable() {
    $("tr.gridview-column-left:even").addClass("even");
    $("tr.gridview-column-left:odd").addClass("odd");
    $("tr.HeaderRow").addClass("table-header");

    $("tr.gridview-column-left").hover(function() {
        $(this).toggleClass("hover");
    },
    function() {
        $(this).toggleClass("hover");
    });

    $("tr.gridview-column-left").click(function() {
        $(this).toggleClass("selected");
    });
}

/*color codes the application deatils table*/
function ColorCodeSteps() {
    $("#application-steps tr:even").addClass("even-step");
    $("#application-steps tr:odd").addClass("odd-step");

    $("#application-steps tr").hover(function() {
        $(this).toggleClass("hover");
    }, function() { $(this).toggleClass("hover"); });
}

