﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {

    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $_("#backgroundPopup").css({
            "opacity": "0.3"
        });
        $_("#backgroundPopup").fadeIn("fast");
        $_("#popup").fadeIn("fast");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $_("#backgroundPopup").fadeOut("slow");
        $_("#popup").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $_("#popup").height();
    var popupWidth = $_("#popup").width();
    //centering
    var parentHeight = $_("#popup").parent().height();
    var clientHeight = $_("#popup").height();
    var scrollTop = $_("#popup").parent().scrollTop();

    var parentWidth = $_("#popup").parent().width();
    var clientWidth = $_("#popup").width();
    var scrollLeft = $_("#popup").parent().scrollLeft();

    //centering
    $_("#popup").css({
        "position": "fixed",
        "top": (windowHeight / 2) - (clientHeight / 2) + scrollTop,
        "left": (windowWidth / 2) - (clientWidth / 2) + scrollLeft

    });
    //only need force for IE6

    $_("#backgroundPopup").css({
        "height": windowHeight
    });

}

function ShowPopup(val) {
    //centering with css
    $_('#frmlogin').attr('src', RootPath + "/Member/MemberLogin.aspx?Type="+val);
    //$_('#frmlogin').load().fadeIn("fast");
    centerPopup();
    //load popup
    loadPopup();
}

function ShowFirstTimeLoginPopUp(path) {
    //centering with css
    $_('#frmlogin').attr('src', path);
    //$_('#frmlogin').load().fadeIn("fast");
    centerPopup();
    //load popup
    loadPopup();
}

function ShowPopupPassword() {
    //centering with css
    $_('#frmlogin', window.parent.document).attr('src', RootPath + "/Member/ResetPassword.aspx");
    $_('#frmlogin', window.parent.document).load().fadeIn("fast");
//    window.parent.$_('#frmlogin').attr('src', RootPath + "/Member/ResetPassword.aspx");
//    window.parent.$_('#frmlogin').load().fadeIn("fast");
    centerPopup();
    //load popup
    loadPopup();
}

function JoinMedeFile()
{
    location.href = RootPath + "/Member/MemberRegister/Join.aspx";
}

//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function() {

    //CLOSING POPUP
    //Click the x event!
    jQuery("#popupClose").click(function() {
        disablePopup();
    });

    //Press Escape event!
    jQuery(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});