﻿
$(document).ready(function() {

    //show loader when save button is clicked on any page
    $("[id$=btnSave]").live('click', function(e) {
        showLoad();
    });

    $("[id$=quoteSave]").live('click', function(e) {
        showLoad();
    });

    $("[id$=quoteConfSave]").live('click', function(e) {
        showLoad();
    });

    $("[id$=btnAdd]").live('click', function(e) {
        showLoad();
    });


    //select all the a tag with name equal to modal
    $('a[name=modal]').live('click', function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height() - 25;
        var maskWidth = $(window).width() - 25;

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn("fast");
        $('#mask').fadeTo("fast", 0.5);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        var scrollY = $(window).scrollTop();

        //Set the popup window to center
        $(id).css('top', (winH / 2 - $(id).height() / 2) + scrollY);
        $(id).css('left', winW / 2 - $(id).width() / 2);


        //transition effect
        $(id).fadeIn("fast");

    });

    //if close button is clicked
    $('#infoOK').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        $(window.location).attr('href', 'quote.aspx');
        $('#mask, .window').hide();


    });

    //if cancel is clicked
    $('#infoCancel').click(function() {
        $('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function() {
        $(this).hide();
        $('.window').hide();
    });

    //when postback complete
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {
        $('#mask').hide();
        $('#preLoader').hide();
    });

    //function to show loader
    function showLoad() {
        //Get the screen height and width
        var maskHeight = $(document).height() - 1;
        var maskWidth = $(window).width() - 1;

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn("fast");
        $('#mask').fadeTo("fast", 0.5);

        //show loader
        var id = $('#preLoader');

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        var scrollY = $(window).scrollTop();

        //Set the popup window to center
        $(id).css('top', (winH / 2 - $(id).height() / 2) + scrollY);
        $(id).css('left', winW / 2 - $(id).width() / 2);
        $(id).fadeIn("fast");


    };

});


