function getWindowMeasurements() {
  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 new Array(myWidth,myHeight);
}


function getScrollsPosition()
{

	var x = 0;
	var y = 0;

	if( typeof( window.pageYOffset ) == 'number' )
	{
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	return new Array(x,y);

}


function closePopup()
{
	disablePopup();
	//document.getElementById('popupContact').style.display='none';
	document.getElementById('popupMiddle').innerHTML='<br /><br /><br /><br /><br /><center><div class="font12">Czytam dane, proszę czekać...</div></center>';

	document.getElementById('popupTopTitle').innerHTML="";
}

function showPopup()
{
	loadPopup();
	centerPopup();
}

function reloadPopUpForHTML(title, wid)
{
	if(document.getElementById(wid))
	{
		document.getElementById("popupTopTitle").innerHTML=title;

		var html=document.getElementById(wid).innerHTML;
		document.getElementById("popupMiddle").innerHTML=html;
		
		showPopup();
	}
}

function reloadPopUpForPageId(pageid)
{
	
	$.ajax({
	type: "POST",
	url: "/ajax/reload_popup_for_page_id.php",
   
	data: "pageid="+pageid,

	success: function(msg)
	{
		if(msg)
		{
			if(document.getElementById("popupContact"))
			{
				msg=msg.split("}@#@{");
				document.getElementById("popupMiddle").innerHTML=msg[1];
				document.getElementById("popupTopTitle").innerHTML=msg[0];

				showPopup();
			}
		}
	}
	});

}

function openPopUp(pageid)
{
	reloadPopUpForPageId(pageid);
}

function showPopupHomePage()
{
	$.ajax({
	type: "POST",
	url: "/ajax/show_popup_homepage.php",
   	success: function(msg)
	{
		if(msg)
		{
			if(document.getElementById("popupContact"))
			{
				msg=msg.split("}@#@{");
				document.getElementById("popupMiddle").innerHTML=msg[1];
				document.getElementById("popupTopTitle").innerHTML=msg[0];
				showPopup();
			}
		}
	}
	});
}

function reloadPopUpForVideoId(vid)
{
	
	$.ajax({
	type: "POST",
	url: "/ajax/reload_popup_for_video_id.php",
   
	data: "vid="+vid,

	success: function(msg)
	{
		if(msg)
		{
			if(document.getElementById("popupContact"))
			{
				msg=msg.split("}@#@{");
				document.getElementById("popupMiddle").innerHTML=msg[1];
				document.getElementById("popupTopTitle").innerHTML=msg[0];

				showPopup();
			}
		}
	}
	});

}

function reloadPopUpForFAQVideoId(vid, colnr)
{
	
	$.ajax({
	type: "POST",
	url: "/ajax/reload_popup_for_faq_video_id.php",
   
	data: "vid="+vid+"&colnr="+colnr,

	success: function(msg)
	{
		if(msg)
		{
			if(document.getElementById("popupContact"))
			{
				msg=msg.split("}@#@{");
				document.getElementById("popupMiddle").innerHTML=msg[1];
				document.getElementById("popupTopTitle").innerHTML=msg[0];

				showPopup();
			}
		}
	}
	});

}

/***************************/
//@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(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.5"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

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

//centering popup
function centerPopup(){

	if(popupStatus)
	{
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popupContact").height();
		var popupWidth = $("#popupContact").width();


		var scrollsPosition=new Array();
		scrollsPosition=getScrollsPosition();
		var scrollY = scrollsPosition[1];

		var newheight=(windowHeight/2-popupHeight/2)+scrollY;
		//centering
		$("#popupContact").css({
			"position": "absolute",
			"top": newheight,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		$("#backgroundPopup").css({
			"height": windowHeight
		});
	}
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});


