﻿var popupEventInfoStatus = 0;
var windowHeight = document.documentElement.clientHeight;

function loadEventInfoPopup(){
	if(popupEventInfoStatus==0){
		$("#backgroundSearchPopup").css({"opacity": "0.2"});
		$("#backgroundSearchPopup").fadeIn("fast");
		$("#popupEventInfo").show();
		popupEventInfoStatus = 1;
	}
}
function disableEventInfoPopup(){
	if(popupEventInfoStatus==1){
		$("#backgroundSearchPopup").fadeOut("normal");
		$("#popupEventInfo").fadeOut("normal");
		popupEventInfoStatus = 0;
		$("#fixedTime,#typeAndNumber,#typeAndNumber,#dispatchOptions,#discountOptions").hide();	
		$("#ticketTable,#dispatchTable,#discountOptions,#discountTokenHide").html("");
		$("ul.collectText, .nextStage").hide().remove();
		$(".processLoader").remove();
		thisDateList.remove();
		thisTimeList.remove();
		$("#popupEventInfo .NumberOfTicketsContainer").slideUp();
		$("#popupEventInfo #popupButtons").slideDown();
	}
}
 
function getScrollXY() { 
	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 {X:scrOfX, Y:scrOfY}; 
} 

function getWindowSize() { 
	var myWidth = 0, myHeight = 0; 
 	if( typeof( window.innerWidth ) == 'number' ) { 
 		//Non-IE 
   		myWidth = window.innerWidth; 
   		myHeight = window.innerHeight; 
 	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
   		//IE 6+ in 'standards compliant mode' 
   		myWidth = document.documentElement.clientWidth; 
   		myHeight = document.documentElement.clientHeight; 
 	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
   		//IE 4 compatible 
   		myWidth = document.body.clientWidth; 
   		myHeight = document.body.clientHeight; 
 	} 
 	return{X:myWidth, Y:myHeight} 
} 

function centerEventInfoPopup(){ 
	var windowDim = getWindowSize(); 
	var myHeight = window.top.document.body.scrollHeight;
	var popupEventInfoHeight = $("#popupEventInfo").height(); 
	var popupEventInfoWidth = $("#popupEventInfo").width(); 
	var scroll = getScrollXY(); 
	$("#popupEventInfo").css({"position" : "absolute", "top" : "20%", "left" : windowDim.X/2-popupEventInfoWidth/2 + scroll.X-15}); 
	$("#backgroundSearchPopup").css({"height" : myHeight+50 }); 
	//window.alert("\npopup.Height="+popupHeight+"\nInner Height="+windowDim.Y); 
}

$(document).ready(function(){
	$(".buttonEventInfoPopup").click(function(){
		centerEventInfoPopup();
		loadEventInfoPopup();
		$("#timeBox,#fixedTime,#typeAndNumber,#typeAndNumber,#dispatchOptions,#discountOptions").hide();	
		$("#ticketTable,#dispatchTable,#discountOptions,#discountTokenHide").html("");
		$("ul.collectText, .nextStage").hide().remove();
		$(".processLoader").remove();
	});
	
	$("#popupEventInfoClose").click(function(){
		disableEventInfoPopup();
		
	});
	$("#backgroundSearchPopup").click(function(){
		disableEventInfoPopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupEventInfoStatus==1){
			disableEventInfoPopup();
		}
	});
	
});
