﻿//hook up events

$(document).ready(function() {

    $("#anchAdminUpdatePassword").click(function() {
        $("#spanfrom").show();
        $("#spanUpdated").hide();

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divAdminUpdatePassword' });
    });

    $("#frmUpdatePassword").submit(function() {
        var isValid = true;

        if (GetIfBlankAndAttachErrorMessage('txtPassword', 'Required')) {
            isValid = false;
        } else {
            if ($.trim($("#txtPassword").val()) != $.trim($("#txtPassword2").val())) {
                AttachErrorMessage('txtPassword', 'Passwords must match.');
                isValid = false;
            }
            else
                RemoveErrorMessage('txtPassword');
        }

        if (isValid) {

            $.post($(this).attr("action"), $(this).serialize(), function(response) { //post using ajax
                if (response == "confirm") {
                    $("#spanfrom").hide();
                    $("#spanUpdated").show();
                    setTimeout("CloseFacebox()", 4000);
                }
            });
        };
        // $("#spanMessage").html("You have successfully submitted an order.");
        //$("#spanMessage").fadeIn("fast");
        // $("#spanMessage").fadeOut(3000);



        return false;
    });


    $("#anchShowVideo").click(function() {
        // SWFObject embed
        var flashvars = {
            paramXMLPath: "/assets/video/param.xml",
            initialURL: escape(document.location)
        }
        var params = {
            base: ".",
            bgcolor: "#121212",
            allowfullscreen: "true"
        }
        var attributes = {}
        swfobject.embedSWF("/assets/video/slideshowpro.swf", "flashcontent", "640", "360", "9.0.0", false, flashvars, params, attributes);

        /*
        $.facebox.settings.faceboxHtml = '\
        <div id="facebox" style="display:none;"> \
        <div class="popup"> \
        <table> \
        <tbody> \
        <tr> \
        <td class="tl"/><td class="b"/><td class="tr"/> \
        </tr> \
        <tr> \
        <td class="b"/> \
        <td class="body"> \
        <div id="faceboxContent" class="content2"> \
        </div> \
        <div class="footer"><a href="#" class="close"><img src="/scripts/facebox/closelabel.gif" title="close" class="close_image" /></a></div> \
        </td> \
        <td class="b"/> \
        </tr> \
        <tr> \
        <td class="bl"/><td class="b"/><td class="br"/> \
        </tr> \
        </tbody> \
        </table> \
        </div> \
        </div>'
        */

        


        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'flashcontent' });

        $("#faceboxContent").css({ width: 640, padding: 10, background: "White" });
    });


    $("#anchClientLogin1").click(function() {

        $("#divConfirmMembership").hide();
        $("#divForgotPassword").hide();
        $("#divLogin").show();

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divLoginOrRegister' });
    });

    $("#anchClientLogin2").click(function() {

        $("#divConfirmMembership").hide();
        $("#divForgotPassword").hide();
        $("#divLogin").show();

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divLoginOrRegister' });
    });
    $("#anchClientLogin3").click(function() {

        $("#divConfirmMembership").hide();
        $("#divForgotPassword").hide();
        $("#divLogin").show();

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divLoginOrRegister' });
    });
    $("#anchClientLogin4").click(function() {

        $("#divConfirmMembership").hide();
        $("#divForgotPassword").hide();
        $("#divLogin").show();

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divLoginOrRegister' });
    });
    $("#anchClientLogin").click(function() {

        $("#divConfirmMembership").hide();
        $("#divForgotPassword").hide();
        $("#divLogin").show();

        //alert('called');
        //$.facebox.settings.inited = false;

        
        /*
        $.facebox.settings.faceboxHtml = '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div id="faceboxContent" class="content"> \
                </div> \
                <div class="footer"><a href="#" class="close"><img src="/scripts/facebox/closelabel.gif" title="close" class="close_image" /></a></div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    */

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divLoginOrRegister' });

        $("#faceboxContent").css({ width: 400, padding: 10, background: 'White' });

    });

    $("#anchShowForgotPasswordForm").click(function() {

        $("#divForgotPassword").show();
        $("#spanfrom").show();
        $("#spanEmailSent").hide();

        $("#divLogin").hide();

    });

    $("#anchCloseForgotPasswordForm").click(function() {

        $("#divForgotPassword").hide();
        $("#divLogin").show();

    });


    $("#frmLogin").submit(function() {
        var isValid = true;


        if (GetIfBlankAndAttachErrorMessage('email', 'Please enter an email address.'))
            isValid = false;
        else {
            if (!IsValidEmail($.trim($("#email").val()))) {

                AttachErrorMessage('email', 'Email does not appear to be a valid email address.');
                isValid = false;
            }
            else {
                RemoveErrorMessage('email');
            }

        }

        if (GetIfBlankAndAttachErrorMessage('password', 'Please enter your password.'))
            isValid = false;

        if (isValid) {

            $.post($(this).attr("action"), $(this).serialize(), function(response) { //post using ajax
                if (response == "confirm") {
                    $("#spanConfirmEmail").html($("#email").val());
                    $("#divForgotPassword").hide();
                    $("#divLogin").hide();
                    $("#divConfirmMembership").show();
                    $("#spanLoginError").hide();
                    $("#spanDisabledError").hide();
                    $("#spanLoginError").hide();
                }
                else if (response == "notfound") {
                    $("#spanLoginError").show();
                    $("#spanLoginError").attr("style", "color:Red");
                    $("#spanDisabledError").hide();
                }
                else if (response.indexOf("Your account has been disabled") != -1) {
                    $("#spanDisabledError").show();
                    $("#spanDisabledError").attr("style", "color:Red");
                    $("#spanDisabledError").html(response);
                    $("#spanLoginError").hide();
                }
                else
                    location.href = response;
            });
        };
        return false;
    });

    $("#frmForgetpassword").submit(function() {
        var isValid = true;

        if (GetIfBlankAndAttachErrorMessage('sendPasswordToThisEmail', 'Please input your email address.'))
            isValid = false;
        else {
            if (!IsValidEmail($.trim($("#sendPasswordToThisEmail").val()))) {

                AttachErrorMessage('sendPasswordToThisEmail', 'Email does not appear to be a valid email address.');
                isValid = false;
            }
        }

        if (isValid) {

            $.post($(this).attr("action"), $(this).serialize(), function(response) { //post using ajax
                if (response == "confirm") {
                    $("#spanfrom").hide();
                    $("#spanEmailSent").show();
                    setTimeout("CloseFacebox()", 4000);
                }
                else if (response == "emailnotexists") {
                    $("#spanEmailNotExists").show();
                    $("#spanEmailNotExists").attr("style", "color:Red");
                }
                else
                    location.href = response;
            });
        };
        // $("#spanMessage").html("You have successfully submitted an order.");
        //$("#spanMessage").fadeIn("fast");
        // $("#spanMessage").fadeOut(3000);



        return false;
    });

});



function CloseFacebox() {
    $.facebox.close();
}



