﻿$(document).ready(function()
{
    $(window).resize(function()
    {
        centerPopup();
    });
});

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(name) {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        if (name == ".popupContact") {
            $(name).fadeIn("slow", function() { $("#login #popupContacta").focus(); });
            $(".error_msg").css({ color: '#000' });
        }else {
            $(name).fadeIn("slow");
            $(".backgroundPopup").css({"opacity": "0.1", "-moz-opacity":"10%"});
            $(".backgroundPopup").fadeIn("slow");
        }
        popupStatus = 1;
    }
    centerPopup(name);
}

//disabling popup with jQuery magic!
function disablePopup()
{
    //disables popup only if it is enabled
    if (popupStatus == 1)
    {
        $(".popupContact").fadeOut("slow");
        popupStatus = 0;
        $('.error_msg').css('display', 'none');
        $("#login .username").focus();
    }
    return false;
}

//centering popup
function centerPopup(name) {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(name).height();
    var popupWidth = $(name).width();

    var top = windowHeight / 2 - (popupHeight / 2);
    var left;
    if (name == ".popupContact1") 
        left = ((windowWidth / 2) + 80) - popupWidth / 2;
    else 
        left = windowWidth / 2 - popupWidth / 2;
    
    //centering
    $(name).css({
        "position": "absolute",
        "top": parseInt(top),
        "left": parseInt(left)
    });
}


