
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var lgn_popupStatus = 0;
var lgn_currPop="AddInfo";
//loading popup with jQuery magic!
function lgn_loadPopup(popdiv){
    //loads popup only if it is disabled
    //
    lgn_currPop=popdiv;
    lgn_centerPopup();
    if(lgn_popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPop").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#backgroundPop").fadeIn("slow");
        $("#"+popdiv).fadeIn("slow");
        lgn_popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function lgn_disablePopup(){
    //disables popup only if it is enabled
    if(lgn_popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#backgroundPop").fadeOut("slow");
        $("#"+lgn_currPop).fadeOut("slow");
        lgn_popupStatus = 0;
    }
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

//centering popup
function lgn_centerPopup(){
    //request data for centering
	//$('#postPopUp').css('top',f_scrollTop()+150);
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#"+lgn_currPop).height();
    var popupWidth = $("#"+lgn_currPop).width();
    //centering
    $("#"+lgn_currPop).css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2+f_scrollTop(),
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6
    
    $("#backgroundPopup").css({
        "height": windowHeight
    });
    
}

//Click out event!
$("#backgroundPopup").click(function(){
    lgn_disablePopup();
});
//Press Escape event!
/*$(document).keypress(function(e){
    if(e.keyCode==27 && lgn_popupStatus==1){
        lgn_disablePopup(lgn_currPop);
    }
});*/



