﻿var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#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;
	}
	//alert(window.yoffset)
	parent.scrollTo(0, window.yoffset);
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": "1%",
		"left":"50%",
		"margin-left": -popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		/*"height": windowHeight*/
	});
	
}

function initpopup(){
	//centering with css
		//window.yoffset = window.pageYOffset;
		
		if(typeof pageYOffset!= 'undefined'){
			//most browsers
			window.yoffset = window.pageYOffset;
		}
		else{
			var B= document.body; //IE 'quirks'
			var D= document.documentElement; //IE with doctype
			D= (D.clientHeight)? D: B;			
			window.yoffset = D.scrollTop;
		}
		
		
		
        parent.scrollTo(0, 0);
		centerPopup();
		//load popup
		loadPopup();
		//alert('to run after 10s')
}

function getvalidate2(){
	
	
	//alert('sssss');
	if($('#inf_option_Signmeupforthenewsletter').is(':checked')){		
		return true;
	}
	else{	
		var popupHeight2 = $("#currentId").height();
		var popupWidth2 = $("#currentId").height();
		
		var popupHeight3 = $("#currentId2").height();
		var popupWidth3 = $("#currentId2").height();
		
		$("#currentId2").css({
			"left": popupHeight2/2 - popupHeight3/2,
			"top": popupWidth2/2 - popupWidth3/2
		});
		
		$("#backgroundPopup2").css({
			"opacity": "0.6",
			"height": popupHeight2
		});
		$('#currentId2').fadeIn("slow");                    
		$('#backgroundPopup2').fadeIn("slow"); 
		
		
		
		return false;
	}
	
}

//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();
	});
	
	$("#popupContactClose2").click(function(){
		$('#currentId2').fadeOut("slow");                    
		$('#backgroundPopup2').fadeOut("slow"); 		
	});
	
	$("#backgroundPopup2").click(function(){
		$('#currentId2').fadeOut("slow");                    
		$('#backgroundPopup2').fadeOut("slow"); 		
	});
	
	//Click out event!
	/*$("#backgroundPopup").click(function(){
		disablePopup();
	});*/
	
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	
	var cook=$.cookie('showed');
	if(cook == null || cook ==''){
		setTimeout('initpopup()', timedelay);	
		$.cookie('showed', 'yes');
	}

});
