var popupStatus1 = 0;
var popupStatus2 = 0;
var popupStatus3 = 0;

function loadPopup(id) {
    //loads popup only if it is disabled
    if (popupStatus1==0) {
        jQuery("#" + id).fadeIn("slow");
        popupStatus1 = 1;
    }
}

function loadPopup2(id) {
    //loads popup only if it is disabled
    if (popupStatus1==1) {
        jQuery("#" + id).fadeIn("slow");
        popupStatus2 = 1;
    }
}

function loadPopup3(id) {
    //loads popup only if it is disabled
    if (popupStatus3==0) {
        jQuery("#" + id).fadeIn("slow");
        popupStatus3 = 1;
    }
}


function disablePopup(id1, id2) {
    //disables popup only if it is enabled  
    if (popupStatus2==1) {
        jQuery("#" + id1).fadeOut("fast");
        jQuery("#" + id2).fadeOut(8000);
        popupStatus1 = 0;
        popupStatus2 = 0;
    }  
}

function disablePopup2(id1) {
    //disables popup only if it is enabled  
    if (popupStatus3==1) {
        jQuery("#" + id1).fadeOut("fast");
        popupStatus3 = 0;
    }  
}

function getScrollY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    return scrOfY;
}

function positionPopup(event, id) {
    var posx = 0;
    var posy = 0;
    if (!event) var event = window.event;
    if (event.pageX || event.pageY) {
        posx = event.pageX;
        posy = event.pageY;
    } else if (event.clientX || event.clientY) 	{
        posx = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    var windowHeight = document.documentElement.clientHeight;
    var vertscroll = getScrollY();
    
    if ((posy + 350 - vertscroll) > windowHeight) {
        posy = vertscroll + windowHeight - 250;
    }
    

    //centering
    jQuery("#" + id).css({
        "position": "absolute",
        "top": posy,
        "left": posx + 100
    });
}

function showPopup(event, id) {

    //centering with css
    positionPopup(event, id);
    //load popup
    loadPopup(id);
}

function showPopup2(event, id) {

    //centering with css
    positionPopup(event, id);
    //load popup
    loadPopup2(id);
}

function showPopup3(event, id) {

    //centering with css
    positionPopup(event, id);
    //load popup
    loadPopup3(id);
}
