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

//loading popup with jQuery magic!
function loadPopup(){
	document.body.style.overflow = 'hidden';
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		//$("#backgroundPopup").fadeIn("slow");
		$("#backgroundPopup").show();
		//$("#popup").fadeIn("slow");
		$("#popup").show();
		popupStatus = 1;
	}
}

function loadPopupNick(name){
	document.body.style.overflow = 'hidden';
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		//$("#backgroundPopup").fadeIn("slow");
		//$("#popupNick").fadeIn("slow");
		$("#backgroundPopup").show();
		$("#popupNick").show();
		popupStatus = 1;
	}

    var html = $("#popupNick .mcc_tt").html();
	if (popupText == "") popupText = html;

	$("#popupNick .mcc_tt").html(popupText.replace("{nick}", name));
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		//$("#backgroundPopup").fadeOut("slow");
		//$("#popup").fadeOut("slow");
		$("#backgroundPopup").hide();
		$("#popup").hide();
		popupStatus = 0;
	}
	document.body.style.overflow = 'auto';
}

function disablePopupNick(){
	//disables popup only if it is enabled
//	if(popupStatus==1){
//		$("#backgroundPopup").fadeOut("slow");
		//$("#popupNick").fadeOut("slow");
		$("#popupNick").hide();
//		popupStatus = 0;
//	}
//	document.body.style.overflow = 'auto';
}

//centering popup
function centerPopup(){
	var d = dimension_detect();
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	/*$("#popup").css({
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": window.pageYOffset+(d.viewH/2-popupHeight/2),
		"left": windowWidth/2-popupWidth/2
	});*/
	document.getElementById("popup").style.position = 'absolute';
	document.getElementById("popup").style.top = d.top+(d.viewH/2-popupHeight/2) + 'px';
	document.getElementById("popup").style.left = (windowWidth-popupWidth)/2 + 'px';
	//only need force for IE6

	/*$("#backgroundPopup").css({
		"height": windowHeight
	});*/
	document.getElementById("backgroundPopup").style.height = windowHeight + 'px';

}

function centerPopupNick(){
	var d = dimension_detect();
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupNick").height();
	var popupWidth = $("#popupNick").width();
	//centering
	/*$("#popup").css({
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": window.pageYOffset+(d.viewH/2-popupHeight/2),
		"left": windowWidth/2-popupWidth/2
	});*/
	document.getElementById("popupNick").style.position = 'absolute';
	document.getElementById("popupNick").style.top = d.top+(d.viewH/2-popupHeight/2) + 'px';
	document.getElementById("popupNick").style.left = (windowWidth-popupWidth)/2 + 'px';
	//only need force for IE6

	/*$("#backgroundPopup").css({
		"height": windowHeight
	});*/
	document.getElementById("backgroundPopup").style.height = windowHeight + 'px';

}

//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(){
		disablePopupNick();
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupNick();
			disablePopup();
		}
	});

});

function showPopup(img_src){
	$('#video_img').attr('src', '');

	centerPopup();
	loadPopup();

	if (typeof img_src != 'undefined' && img_src != '') {
		$('#video_img').attr('src', img_src);
	}

}

function showPopupNick(name){
	centerPopupNick();
	loadPopupNick(name);
}

function hidePopup(){
	disablePopupNick();
	disablePopup();
}

if(typeof dimension_detect == 'undefined'){
	function dimension_detect(){
		var d={'viewW':0,'viewH':0,'docH':0,'docW':0,'left':0,'top':0};
		if (document.body.scrollHeight>document.body.offsetHeight){
			d.docW=document.body.scrollWidth;
			d.docH=document.body.scrollHeight;
		} else {
			d.docW=document.body.offsetWidth;
			d.docH=document.body.offsetHeight;
		}
		if (self.innerWidth){
			d.viewW=self.innerWidth;
			d.viewH=self.innerHeight;
			d.left=window.pageXOffset;
			d.top=window.pageYOffset;
		} else {
			var ie=(document.compatMode&&document.compatMode!='BackCompat')?document.documentElement:document.body;
			d.viewW=ie.clientWidth;
			d.viewH=ie.clientHeight;
			d.left=ie.scrollLeft;
			d.top=ie.scrollTop;
		}
		return d;
	}
}//init dimension_detect()

var isKtuPopExecuted = false;
function submitEmail(){
	if(typeof popEmailInput == 'undefined') popEmailInput = 'email1';
	ktucheck_nopop(popEmailInput);
	setInterval("if(isKtuPopExecuted){isKtuPopExecuted = false; location.href = 'http://ktu.sv2.biz/exit.php?synergie="+KTU_Params['synergie']+"&lg="+KTU_Params['lg']+"&id="+KTU_Params['id']+"&tracker="+KTU_Params['tracker']+"&exit="+KTU_Params['id_site']+"&cpop=&exitrf="+KTU_Params['id_site']+"';}", 300);
}

