// JavaScript Document

	var usermenuPubTimeout;
	var userInfoTimeout;

	//Script exécuté à la fin du chargement de la page
	$(document).ready(function() {
							   
		if(USERDEFINED_VAR_MSG_ERROR!=""){
			alert(USERDEFINED_VAR_MSG_ERROR);	   
		}
		
		if(LAYOUT_DISABLE_VERTICAL_PUB){
			
		} else {
			usermenuPubTimeout = setTimeout ("loadAdds()", 1200);
		} 
		
		if(USERDEFINED_CHECK_MESSAGE){
			userInfoTimeout = setTimeout ("checkUserOnlineInfo()", 300000);
		}
		
		$("img.user_icon").tooltip({ 
			tip: '#demotip',
        	offset: [0, 0] ,
			position: 'center right',
			onBeforeShow: function(){
				var memberId = this.getTrigger().attr('memberId');
				
				$("div#demotip div#tooltip_content").hide();
				$("div#demotip div#tooltip_loading").show();
				
				$.post(
					"ajax/ajax.site.tooltip.php", 
					{'memberId': memberId },
					function(data){
						if(data!="false"){
							$("div#demotip div#tooltip_loading").hide();
							$("div#demotip div#tooltip_content").empty().append(data).show();
						}
					}, 
					"html"
				);
			}
			
		});
		
		$("img.user_icon_top").tooltip({ 
			tip: '#demotip_top',
        	offset: [25, 0] ,
			position: 'top center',
			onBeforeShow: function(){
				var memberId = this.getTrigger().attr('memberId');
				
				$("div#demotip_top div#tooltip_content").hide();
				$("div#demotip_top div#tooltip_loading").show();
				
				$.post(
					"ajax/ajax.site.tooltip.php", 
					{'memberId': memberId },
					function(data){
						if(data!="false"){
							$("div#demotip_top div#tooltip_loading").hide();
							$("div#demotip_top div#tooltip_content").empty().append(data).show();
						}
					}, 
					"html"
				);
			}
			
		});
		
	});


	function unloadTimers()
	{		
		clearTimeout(userInfoTimeout);
		clearTimeout(usermenuPubTimeout);
	}

	function checkUserOnlineInfo()
	{
		$.post("ajax/ajax.user.checkMessage.php", { },
		  function(data){
				$("div#userMenuCountUnreadMessages").empty().append(data.message);
				//userInfoTimeout = setTimeout ("checkUserOnlineInfo()", 300000);
		 }, 
		 "json");
	}

	function loadAdds(){
		var cellPubHeight = $("td.submenu").height();
		var submenuHeight = $("div#submenu").height();
		
		var leftHeight = cellPubHeight-submenuHeight-15;
		$("table#pub").height(leftHeight);
		
		$.post("ajax/ajax.usermenu.pub.php", { height: leftHeight },
		  function(data){
			  if(data!="false"){
				  $("table#pub tr td").empty().append(data).show();
			  }
		 }, "html");
		
	}
	
	
	
	function onUserLogin(){
		if($('input#localisation:checked').length==1){

			$("div#user_login_submenu").block({
				message: 'Localisation en cours...',
				overlayCSS:  { 
					backgroundColor: '#000', 
					opacity:         0.8 
				}, 
				css: { 
					width: '85%',  
					border: 'none', 
					padding: '5px', 
					backgroundColor: '', 
					opacity: 1.0, 
					color: '#fff' 
				}
				
			});
			
			navigator.geolocation.getCurrentPosition(
				function(position) {
					$("input#m2localisation").val("0");
					$("input#m2latitude").val(position.coords.latitude);
					$("input#m2longitude").val(position.coords.longitude);
					$("input#m2accuracy").val(position.coords.accuracy);
					$("form#userLogin").submit();
	
				}, 
				function(error) {
			  		$("input#m2localisation").val(error.code);
					$("form#userLogin").submit();
				}
			);
		}else{
			
			$("div#user_login_submenu").block({
				message: 'Chargement en cours...',
				overlayCSS:  { 
					backgroundColor: '#000', 
					opacity:         0.8 
				}, 
				css: { 
					width: '85%',  
					border: 'none', 
					padding: '5px', 
					backgroundColor: '', 
					opacity: 1.0, 
					color: '#fff' 
				}
				
			});
			
			$("input#m2localisation").val("-1");
			$("form#userLogin").submit();
			
		}
		//
		
		return false;
	}
	
	
	
	function showModal(elem, data, size){
			$.unblockUI();	
			
			var interface = $(elem).attr("interface");

			data.width = size[0];
			data.height = size[1];		

			$.ajax({
				type: "GET",
				url: "ajax/interface."+interface+".php",
				'data': data,
				success: function(msg){
					
					$.blockUI({ 
						message: msg, 
						fadeIn: 300, 
						fadeOut: 150, 
						showOverlay: true,
						css: { 
							width: data.width+"px",
							height: data.height+"px",
							top: ((getClientHeight() - data.height)/2)+"px",
							left: ((getClientWidth() - data.width)/2)+"px",
							border: '10px solid white', 
							padding: '0px',
							background: 'none',
							'-webkit-border-radius': '5px', 
							'-moz-border-radius': '5px', 
							opacity: 1.0, 
							color: '#000000',
							textAlign:      'left', 
							cursor:         'normal'
						} 
					}); 
					
					modalPopupDidLoad();
				},
				error: function(msg){
					alert("Erreur lors du chargement");	
				}
			});
		
	}
	
	
	
		function modalLink(interface, data, size){
			$.unblockUI();	
			
			data.width = size[0];
			data.height = size[1];		

			$.ajax({
				type: "GET",
				url: "ajax/interface."+interface+".php",
				'data': data,
				success: function(msg){
					
					$.blockUI({ 
						message: msg, 
						fadeIn: 300, 
						fadeOut: 150, 
						showOverlay: true,
						css: { 
							width: data.width+"px",
							height: data.height+"px",
							top: ((getClientHeight() - data.height)/2)+"px",
							left: ((getClientWidth() - data.width)/2)+"px",
							border: '10px solid white', 
							padding: '0px',
							background: 'none',
							'-webkit-border-radius': '5px', 
							'-moz-border-radius': '5px', 
							opacity: 1.0, 
							color: '#000000',
							textAlign:      'left', 
							cursor:         'normal'
						} 
					}); 
					
					modalPopupDidLoad();
				},
				error: function(msg){
					alert("Erreur lors du chargement");	
				}
			});
		
	}
	
	
	
	function getClientHeight() {
	  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 myHeight;
}

	function getClientWidth() {
	  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 myWidth;
}


	function popMemberPicture(picId, picWidth, picHeight){		
			var top=(screen.height-picHeight)/2;    
			var left=(screen.width-picWidth)/2; 
			
			window.open(CONST_SITE_DOMAIN+'/members/picture.php?pictureId='+picId, 'picMember','top='+top+', left='+left+', height='+picHeight+', width='+picWidth+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');		
	}
	
	function popModelPicture(picId, picWidth, picHeight){		
			var top=(screen.height-picHeight)/2;    
			var left=(screen.width-picWidth)/2; 
			
			window.open(CONST_SITE_DOMAIN+'/models/picture.php?pictureId='+picId, 'picModel','top='+top+', left='+left+', height='+picHeight+', width='+picWidth+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');		
	}
