$(document).ready(function(){
    $("#showpopup").click(function(){
	    couponscenterPopup();
	    couponsloadPopup();
    });
    
    $("#couponsPopupContactClose").click(function(){
	    couponsdisablePopup();
    });
    
    $(document).keypress(function(e){
	    if(e.keyCode==27 && popupStatus==1){
		    couponsdisablePopup();
	    }
    });
    
    $(window).resize(function(){
        couponscenterPopup();
    });
    
    $("#couponsPopupContact").easydrag();
    $("#couponsPopupContact").setHandler("couponsPopupHead");

});

var popupStatus = 0;

function couponsloadPopup(){
    if(popupStatus==0){
	    $("#backgroundPopup").css({
		    "opacity": "0.3"
	    });
	    $('#size').hide();
	    $('#tr_hide').hide();
	    $("#backgroundPopup").fadeIn("fast");
	    $("#couponsPopupContact").fadeIn("fast");
	    popupStatus = 1;
    }
}

function couponsdisablePopup(){
    if(popupStatus==1){
	    $('#size').show();
	    $('#tr_hide').show();
	    $("#backgroundPopup").fadeOut("fast");
	    $("#couponsPopupContact").fadeOut("fast");
	    popupStatus = 0;
    }
}

function couponscenterPopup(){
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var documentWidth = $(document).width();
    var documentHeight = $(document).height();
    var popupHeight = $("#couponsPopupContact").height();
    var popupWidth = $("#couponsPopupContact").width();
    $("#couponsPopupContact").css({
	    "position": "absolute",
	    "top": 10,
	    "left": windowWidth/2-popupWidth/2
    });
	
    $("#backgroundPopup").css({
	    "height": documentHeight,
	    "width": documentWidth
    });/**/
}