/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup(){
	//alert(0);
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").show();
		$("#popup").show();
		popupStatus = 1;
	}
		
}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	
	$("#popup").html('')
	if(popupStatus==1){
		$("#backgroundPopup").hide();
		$("#popup").hide();

		popupStatus = 0;
	}

}




//centering popup
function centerPopup(name,w,h,yid){

	//request data for centering
	
	var bHeight=document.documentElement.scrollHeight;
	var winH,winW;  
	if(window.innerHeight && window.scrollMaxY) {    // Mozilla 
	winH = window.innerHeight + window.scrollMaxY;
	winW = window.innerWidth + window.scrollMaxX;
	ifrtop=document.frames["topnavindex"].document         //document.getElementById(id).contentDocument || document.frames[id].document;
	
	} 
	else if(document.body.scrollHeight > document.body.offsetHeight){
	 //all but IE Mac
	winH = document.body.scrollHeight;
	winW = document.body.scrollWidth;
	} 
	else if(document.body) { // IE Mac
	winH = document.body.offsetHeight;
	winW = document.body.offsetWidth;
	} 




	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	if(winH<windowHeight&&windowHeight>668){
		winH=windowHeight;
	}
	
	var popupHeight = h;
	var popupWidth = w;
	//centering
    
	if(windowHeight<668){
		
		if(name=='flashupdateok'){
			
			$("#popup").css({
			"position": "absolute",
			"top": 20,
			"left": winW/2-popupWidth/2
			});	
			$("#backgroundPopup").css({
				"height":winH+winH*0.35,
				"width":winW,
				"zIndex":"990"
			});
			
		}else{
			
			$("#popup").css({
			"position": "absolute",
			"top": winH/2-popupHeight/2,
			"left": winW/2-popupWidth/2
			});
			$("#backgroundPopup").css({
				"height":winH,
				"width":winW,
				"zIndex":"990"
			});
			
		}	
		
	
	
	}else{
		
		if(name=='flashupdateok'){
			$("#popup").css({
			"position": "absolute",
			//"top": windowHeight/2-popupHeight/2,
			"top": 20,
			"left": winW/2-popupWidth/2
			});
			$("#backgroundPopup").css({
				"height":winH+winH*0.15,
				"width":winW,
				"zIndex":"990"
			});	
		}else{
			$("#popup").css({
			"position": "absolute",
			//"top": windowHeight/2-popupHeight/2,
			"top": winH/2-popupHeight/2,
			"left": winW/2-popupWidth/2
			});
			$("#backgroundPopup").css({
				"height":winH,
				"width":winW,
				"zIndex":"990"
			});	
		}
		
		
	}
	//only need force for IE6
}


//CONTROLLING EVENTS IN jQuery

function popup(name,w,h,yid){
	
	   //notIe = -[1,];  
	
	if(name=='login'){
	   $("#popup").html('<iframe scrolling="no" width="439" height="283" src="regist/login.php" frameborder="0" id="login" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('login').location.reload(true)
		//}
	}
	
	if(name=='loginsina'){
		   $("#popup").html('<iframe scrolling="no" name="loginsina" width="400" height="283" src="login.php" frameborder="0" id="login" allowtransparency="true"></iframe>');
		   window.parent.loginsina.location.reload();
		    //if(notIe){ 
			//}else{  
			//document.frames('login').location.reload(true)
			//}
	}	
	
	if(name=='bemember'){
		//alert($("#backgroundPopup").height())
	   $("#popup").html('<iframe scrolling="no" width="528" height="395" src="bemember.php" frameborder="0" id="ifrlog" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('ifrlog').location.reload(true)
		//}
	}
	
	if(name=='updateok'){
	   $("#popup").html('<iframe scrolling="no" width="528" height="734" src="updateok.php" frameborder="0" id="ifrstart" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('ifrstart').location.reload(true)
		//}
	}
	
	if(name=='flashupdateok'){
	   $("#popup").html('<iframe scrolling="no" width="790" height="520" src="regist/updateok.php" frameborder="0" id="ifrstart" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('ifrstart').location.reload(true)
		//}
	}
	
	if(name=='allinfook'){
		//alert($("#backgroundPopup").height())
	   $("#popup").html('<iframe scrolling="no" width="528" height="220" src="regist/allinfook.php" frameborder="0" id="ifrlog" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('ifrlog').location.reload(true)
		//}
	}
	
	if(name=='addpointok'){
	   $("#popup").html('<iframe scrolling="no" width="528" height="220" src="popup_addpointok.html" frameborder="0" id="printimg" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('printimg').location.reload(true)
		//}
	}
	
	if(name=='print'){
	   $("#popup").html('<iframe scrolling="no" width="673" height="555" src="setCoupon.php" frameborder="0" id="printimg" allowtransparency="true"></iframe>');
		//if(notIe){ 
		//}else{  
		//document.frames('printimg').location.reload(true)
		//}
	}
	
	centerPopup(name,w,h,yid);
	loadPopup();
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

}
