
$(document).ready(function() {
    var loginPanel = $('a[name=modal]');

    //select all the a tag with name equal to modal
    loginPanel.click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        openLoginWindow(this);
    });

    //if close button is clicked
    $('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        hideLoginPanel();
    });

    //if mask is clicked
    $('#mask').click(function() {
        hideMaskedPopups();
        $('.window').hide();
    });

});

function winPop(id) {
    //Get the A tag
    var id = "#" + id;  //$(element).attr('href');

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect		
    $('#mask').fadeTo("slow", 0.5);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top', 125);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    //transition effect
    $(id).fadeIn(300);
}

function hidePanel(id) {
    $('#mask').hide();
    $('#' + id).hide();
}

function hideMaskedPopups() {
    $('.maskedPopup').hide();
    $('#mask').hide();
}

function hideLoginPanel() {
    $('#mask').hide();
    $('.window').hide();
}

function openLoginPanel() {
    var loginPanel = $('a[name=modal]');
    openLoginWindow(loginPanel);
}

function openLoginWindow(element) {

    //Get the A tag
    var id = $(element).attr('href');
    if ($(element).length > 2) {
        id = $(element)[1].hash;
    }

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect		
    $('#mask').fadeTo("slow", 0.5);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top', 125);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    //transition effect
    $(id).fadeIn(300);

    try {
        txtBranchId().focus();
    }
    catch (ex) { }
}


function openEmailSuccessWindow() {

    //Get the A tag
    var id = "#emailSuccessDialog";  //$(element).attr('href');

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect		
    $('#mask').fadeTo("slow", 0.5);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top', 125);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    //transition effect
    $(id).fadeIn(300);

}
function onRegistrationClick() {
    var extender = $find("ctl00_extender_modal");
    var iframe = $get("frame_modal");
    iframe.src = "../../PopupPages/DataTraceRegistrationUC.aspx" ;
    iframe.style.width = "550px";
    iframe.style.height = "500px";
    iframe.style.left = "auto";
    iframe.style.top = "125px";
    extender.initialize();
    extender.show();

}
function onResetClick() {

    document.getElementById("dialog2").style.display = "none";
    var extender = $find("ctl00_extender_modal");
    var iframe = $get("frame_modal");
    iframe.src = "../../PopupPages/ForgotPassword.aspx";
    iframe.style.width = "496px";
    iframe.style.height = "400px";
    iframe.style.left = "auto";
    iframe.style.top = "125px";
    extender.initialize();
    extender.show();

}


function IframeChgSource(path) {
    var iframe = $get("frame_modal");
    var rv = null;
    if (iframe.contentDocument) {
        if (iframe.contentDocument.location.pathname !== "/blank" && iframe.contentDocument.location.href !== "about:blank") {
            //var path = iframe.contentDocument.location.pathname;
           // iframe.contentDocument.location.href = "about:blank";
            iframe.contentDocument.location = path;
            //            var path = iframe.contentDocument.location.href;
            //            iframe.contentDocument.location.href = "";
            //            iframe.contentDocument.location.href = path;

        }

    }
    else {
        rv = document.frames['frame_modal'].document;
        if (rv.location.pathname !== "/blank" && rv.location.href !== "about:blank") {
            //var path = rv.location.pathname;
            //rv.location = "about:blank";
            //rv.location = path;
            //            var path = rv.location.href;
            //rv.location.href = "about:blank";
            rv.location = path;
        }

    }
}


