﻿$(function() {
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();        
        var id = $(this).attr('href');//Get the A tag

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });//Set heigth and width to mask to fill up the whole screen

        //transition effect
        $('#mask').fadeIn("fast");
        $('#mask').fadeTo("fast", 1);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', 100);//$(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', 0);//$(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $('#divFMsg').html('');
        $('#txtfemail').val('');
        $(id).fadeIn("fast");
    });

    //if close button is clicked
    $('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function() {$(this).hide();$('.window').hide();});

    $('#btnsubmit').click(function() {
        if (checkFPassword()) {
            $('#imgFLoading').show();
            alert($('#btnsubmit').data('usertype'));
            var strPostURL =WebSiteUrl + "Include/MemLoginHandler.ashx?type=forgotpassword&usertype="+$('#btnsubmit').data('usertype');
            $.ajax({ type: "POST", data: "txtfemail=" + $('#txtfemail').val(), url: strPostURL, success: function(resp) {
                $('#imgFLoading').hide();
                if (resp == "-1"){
                    $('#divFMsg').html('<b>Invalid Username or Email Address.</b>');
                } else if (resp == "0") {
                    $('#divFMsg').html('<b>Failure sending email.</b>');
                } else if (resp == "1") {
                    $('#divFMsg').html('<b>Password has been sent successfully to your email address.</b>');
                }
            }
            });
        }
        return false;
    });

});
function checkFPassword() {
    if ($('#txtfemail').val() == "") {alert("- Please enter email address.");return false;}    
    return true;
}
