function closePopup() {
				$('#mask, #dialog, #leavingpopup').hide();	
			}

$(document).ready(function() {
	
	//select all the a tag with name equal to modal
	$('a.modal').click(function(event) {
		
		event.preventDefault();
		var link = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').css('position', 'absolute');
		$('#mask').css('top', 0 );
		$('#mask').css('left', 0);
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		$("#dialog iframe").attr("src", $(this).attr("href"));
		
		var ScrollTop = document.body.scrollTop;

		if (ScrollTop == 0) {
		
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		
		$("#dialog").css('top',  winH/2-$("#dialog").height()/2 +ScrollTop );
		$("#dialog").css('left', winW/2-$("#dialog").width()/2);

		$("#dialog").fadeIn(2000); 
	
			
	});
	
	$('#mask').click(function (event) {
		event.preventDefault();		
		closePopup();
	});	
	
});
/*******************************************************************/
$(document).ready(function(){
	$(".attr_group").change(function(){
		var id=$(this).val();
		var dataString = 'id='+ id;

		$.ajax
		({
			type: "POST",
			url: "ajax_attribute_options.php",
			data: dataString,
			cache: false,
			success: function(html){
				$(".attr_option").html(html);
			}
		});
	});

});
/*******************************************************************/
function openWin(url, w, h)
 {
		   var left = (screen.width/2) - (w/2);
			var top = (screen.height/2) - (h/2);
			new_win = window.open(url,'new_win', 'directories=no,fullscreen=no,Venue=no,menubar=no,resizable=no,status=no,toolbar=no,width='+w+',height='+h+',left='+left+',screenX='+left+',top='+top+',screenY='+top+',scrollbars=yes');
			new_win.focus();
 }

function remapPopup( productId )
{
	openWin( "/admin/fe_remap_category.php?pid="+ productId, 1000, 550);
}
