/***************************/
//@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;

//loading popup with jQuery magic!
function loadPopup(name){
	//loads popup only if it is disabled

		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#"+name).fadeIn("slow");
		
		var MSIE = navigator.userAgent.indexOf('MSIE')?true:false;
		var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;	
		if(MSIE && navigatorVersion<=6){
			var x1 = document.getElementsByTagName('select');
			for (var i=0;i<x1.length;i++)
			{
				x1[i].style.visibility='hidden';
			}
		}
}

//disabling popup with jQuery magic!
function disablePopup(name){
	//disables popup only if it is enabled
	
		$("#backgroundPopup").fadeOut("slow");
		$("#"+name).fadeOut("slow");
		
		var MSIE = navigator.userAgent.indexOf('MSIE')?true:false;
		var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;	
		if(MSIE && navigatorVersion<=6){
			var x1 = document.getElementsByTagName('select');
			for (var i=0;i<x1.length;i++)
			{
				x1[i].style.visibility='visible';
			}
		}
}

//centering popup
function centerPopup(name,decalage){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	
	var popupHeight = $("#"+name).height();
	var popupWidth = $("#"+name).width();
	//centering
	$("#"+name).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+decalage,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight+decalage
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
				
	//CLOSING POPUP
	//Click the x event!
	$("#PopupTest5Close").click(function(){
		disablePopup('PopupTest5');
	});
	$("#PopupLocaActClose").click(function(){
		disablePopup('PopupLocaAct');
	});
	$("#PopupTest6Close").click(function(){
		disablePopup('PopupTest6');
	});
	$("#PopupMPTest2Close").click(function(){
		disablePopup('PopupMPTest2');
	});
	$("#PopupBailleurGenreClose").click(function(){
		disablePopup('PopupBailleurGenre');
	});
	$("#PopupLgtNatureParcClose").click(function(){
		disablePopup('PopupLgtNatureParc');
	});	
	$("#PopupDUMClose").click(function(){
		disablePopup('PopupDUM');
	});
	$("#PopupRFR2010Close").click(function(){
		disablePopup('PopupRFR2010');
	});
	$("#PopupRFR2011Close").click(function(){
		disablePopup('PopupRFR2011');
	});
	$("#PopupMatriculeDUMClose").click(function(){
		disablePopup('PopupMatriculeDUM');
	});
	$("#PopupCodeAdherentClose").click(function(){
		disablePopup('PopupCodeAdherent');
	});
	$("#PopupCodePartenaireClose").click(function(){
		disablePopup('PopupCodePartenaire');
	});
	$("#PopupDepensesClose").click(function(){
		disablePopup('PopupDepenses');
	});
	$("#PopupContactClose").click(function(){
		disablePopup('PopupContact');
	});
	$("#PopupDetailClose").click(function(){
		disablePopup('PopupDetail');
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		if(document.getElementById('PopupTest5')!=null){
			disablePopup('PopupTest5');
		}
		if(document.getElementById('PopupLocaAct')!=null){
			disablePopup('PopupLocaAct');
		}
		if(document.getElementById('PopupTest6')!=null){
			disablePopup('PopupTest6');
		}
		if(document.getElementById('PopupMPTest2')!=null){
			disablePopup('PopupMPTest2');
		}
		if(document.getElementById('PopupBailleurGenre')!=null){
			disablePopup('PopupBailleurGenre');
		}	
		if(document.getElementById('PopupLgtNatureParc')!=null){
			disablePopup('PopupLgtNatureParc');
		}		
		if(document.getElementById('PopupDUM')!=null){
			disablePopup('PopupDUM');
		}
		if(document.getElementById('PopupRFR2010')!=null){
			disablePopup('PopupRFR2010');
		}
		if(document.getElementById('PopupRFR2011')!=null){
			disablePopup('PopupRFR2011');
		}
		if(document.getElementById('PopupMatriculeDUM')!=null){
			disablePopup('PopupMatriculeDUM');
		}
		if(document.getElementById('PopupCodeAdherent')!=null){
			disablePopup('PopupCodeAdherent');
		}
		if(document.getElementById('PopupCodePartenaire')!=null){
			disablePopup('PopupCodePartenaire');
		}
		if(document.getElementById('PopupDepenses')!=null){
			disablePopup('PopupDepenses');
		}
		if(document.getElementById('PopupContact')!=null){
			disablePopup('PopupContact');
		}
		if(document.getElementById('PopupDetail')!=null){
			disablePopup('PopupDetail');
		}
		
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27){
			if(document.getElementById('PopupTest5')!=null){
				disablePopup('PopupTest5');
			}
			if(document.getElementById('PopupLocaAct')!=null){
				disablePopup('PopupLocaAct');
			}
			if(document.getElementById('PopupTest6')!=null){
				disablePopup('PopupTest6');
			}
			if(document.getElementById('PopupMPTest2')!=null){
				disablePopup('PopupMPTest2');
			}
			if(document.getElementById('PopupBailleurGenre')!=null){
				disablePopup('PopupBailleurGenre');
			}
			if(document.getElementById('PopupLgtNatureParc')!=null){
				disablePopup('PopupLgtNatureParc');
			}
			if(document.getElementById('PopupDUM')!=null){
				disablePopup('PopupDUM');
			}
			if(document.getElementById('PopupRFR2010')!=null){
				disablePopup('PopupRFR2010');
			}
			if(document.getElementById('PopupRFR2011')!=null){
				disablePopup('PopupRFR2011');
			}
			if(document.getElementById('PopupMatriculeDUM')!=null){
				disablePopup('PopupMatriculeDUM');
			}
			if(document.getElementById('PopupCodeAdherent')!=null){
				disablePopup('PopupCodeAdherent');
			}
			if(document.getElementById('PopupCodePartenaire')!=null){
				disablePopup('PopupCodePartenaire');
			}
			if(document.getElementById('PopupDepenses')!=null){
				disablePopup('PopupDepenses');
			}
			if(document.getElementById('PopupContact')!=null){
				disablePopup('PopupContact');
			}
			if(document.getElementById('PopupDetail')!=null){
				disablePopup('PopupDetail');
			}
		}
	});

});
