//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  

//loading popup with jQuery magic!  
function loadPopup2(){  
//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup2").css({  
		"opacity": "0.7"  
	});  
	$("#backgroundPopup2").fadeIn("slow");  
	$("#popupWeight").fadeIn("slow");  
	popupStatus = 1;  
}  
}  

//disabling popup with jQuery magic!  
function disablePopup2(){  
//disables popup only if it is enabled  
if(popupStatus==1){  
	$("#backgroundPopup2").fadeOut("slow");  
	$("#popupWeight").fadeOut("slow");  
	popupStatus = 0;  
}  
}  

//centering popup  
function centerPopup2(){  

	//request data for centering  
	var top = 5; 
	var headerHeight = 349;
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#popupWeight").height();  
	var popupWidth = $("#popupWeight").width();  
	//centering  
	$("#popupWeight").css({  
	"position": "absolute",  
	"top": windowHeight/2-popupHeight/2,  
	"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup").css({  
 
});  
  
}  

$(document).ready(function(){  
	//CLOSING POPUP  
	//Click the x event!  
	$("#backgroundPopup2").click(function(){  
		disablePopup2();  
	});
	//Press Escape event!  
	$(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup2();  
		}  
	}); 
}); 

// ========================= FIRST =========================================
function showPopup(name, params) {
	document.getElementById("popupWeight").innerHTML = '<div class="formloading"><div class="popuploading"></div></div>';
	$.get("/popup/" + name, params, onLoadedPopup);

}

function onLoadedPopup(data) {
	document.getElementById("popupWeight").innerHTML = data; 
}
