/*  Fonctions
 *  (c) 2009 Emmanuel
 *
 *------------------------------*/
 
 	function ouvreM(fichier){
		var monfich = window.open(fichier,'maillot','width=300,height=250,scrollbars=YES');
		monfich.focus();
	}
	function ouvreAchatJou(fichier){
		var monfichAchatJou = window.open(fichier,'AchatJoueur','width=550,height=300,scrollbars=YES');
		monfichAchatJou.focus();
	}
	function ouvre(fichier){
		var monfich = window.open(fichier,'detail','width=870,height=800,scrollbars=YES');
		monfich.focus();
	}
	
    //
    //  getPageSize()
    //
    function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}

	
	function reset() {
		document.getElementById('supjou').innerHTML='';
		document.getElementById('suphist').innerHTML='';
		document.getElementById('supjou').style.visibility='hidden';
		document.getElementById('suphist').style.visibility='hidden';
		document.getElementById('transp').style.visibility='hidden';
	}
	
	function ouvrirCalendrier(id) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('suphist').style.visibility='visible';
		new Ajax.Updater(
			'suphist',
			'../calendrier/index-v.php',
			{
				method: 'post',
				parameters: {id: id},
				evalScripts: true
			}
		);
	}

	function deplacerCalendrier(anneeJ,moisJ,jourJ,qui) {
		new Ajax.Updater(
			'calendrier',
			'../calendrier/calend-v.php',
			{
				method: 'post',
				parameters: {annee: anneeJ,mois: moisJ,jour: jourJ,id: qui},
				evalScripts: true
			}
		);
	}
	
	function deplacerCalendrierEvent(anneeJ,moisJ,jourJ,qui) {
		new Ajax.Updater(
			'evenement',
			'../calendrier/event-v.php',
			{
				method: 'post',
				parameters: {annee: anneeJ,mois: moisJ,jour: jourJ,id: qui},
				evalScripts: true
			}
		);
	}
	
	function ouvrirMessage(ide) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('suphist').style.visibility='visible';
		new Ajax.Updater(
			'suphist',
			'envoiMP.php',
			{
				method: 'post',
				parameters: {id: ide},
				evalScripts: true
			}
		);
	}

	function ouvrirJoueur(ide) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('supjou').style.visibility='visible';
		new Ajax.Updater(
			'supjou',
			'joueurFiche.php',
			{
				method: 'post',
				parameters: {id: ide}
			}
		);
	}
	
	function ouvrirTransfert(ide) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('suphist').style.visibility='visible';
		new Ajax.Updater(
			'suphist',
			'acheterJoueur.php',
			{
				method: 'post',
				parameters: {id: ide}
			}
		);
	}

	function ouvrirHisto(ide) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('suphist').style.visibility='visible';
		new Ajax.Updater(
			'suphist',
			'historique.php',
			{
				method: 'post',
				parameters: {id: ide}
			}
		);
	}
	
	function ouvrirTrophees(ide) {
		document.getElementById('transp').style.visibility='visible';
		document.getElementById('suphist').style.visibility='visible';
		new Ajax.Updater(
			'suphist',
			'trophees.php',
			{
				method: 'post',
				parameters: {id: ide}
			}
		);
	}


	var i=false;
	function move(e) {
	  if(i) {
	    if (navigator.appName!="Microsoft Internet Explorer") {
	    $("curseur").style.left=e.pageX + 5+"px";
	    $("curseur").style.top=e.pageY + 10+"px";
	    }
	    else {
	    $("curseur").style.left=window.event.clientX + 5+document.documentElement.scrollLeft+"px";
	    $("curseur").style.top=window.event.clientY + 10 + document.documentElement.scrollTop+"px";
	    }
	  }
	}
	
	function show_popup(urlimage) {
	  if(i==false) {
	  $("curseur").style.visibility="visible";
	  $("curseur").innerHTML = '<img src='+urlimage+'>';
	  i=true;
	  }
	}
	function hide_popup() {
		if(i==true) {
		$("curseur").style.visibility="hidden";
		i=false;
		}
	}
	document.onmousemove=move;

	function envoiMessage() {

		var desti = document.formmess.desti.value;
		var sujet = document.formmess.sujet.value;
		var message = document.formmess.message.value;

		new Ajax.Request('envoiMP.post.php',
			{
				asynchronous: true,
				method: 'post',
				parameters: {destinat: desti, suj: sujet, mes: message},
				onLoading: function(xhr){
					$('indicateur-chargement').show();
				}, 
				onSuccess: function(transport){
	
				//alert(transport.responseText);
	
				if(transport.responseText == "ok"){
						$('messageCadre').innerHTML='Message envoyé';
				}
				else {
						$('messageCadre').innerHTML=transport.responseText;		
				}
					
	
				},
				onComplete: function(xhr){
					$('indicateur-chargement').hide();
				}
			}
		);
	}

	function infosJoueur(idj,typeinfo,position){
		//Placer Menu coordonnées clic
	
		if(position == 0){
			var coordX = $('jou-'+idj).offsetLeft+80;
			var coordY = $('jou-'+idj).offsetParent.offsetTop;
			if(coordY > 100) coordY+=26;
			if(coordX > 400) coordX-=322;
		}
		else if(position == 1){
			var coordX = 285;
			var coordY = $('jou-'+idj).offsetTop+26;
		}
		else if(position == 2){
			var coordX = $('jou-'+idj).offsetParent.offsetLeft+100;
			var coordY = $('jou-'+idj).offsetParent.offsetTop;
			if(coordX > 400) coordX-=322;
		}
		
		$('infos-joueur').style.top = coordY+'px';
		$('infos-joueur').style.left = coordX+'px';
		
		$('indicateur-chargement').style.top = coordY+'px';
		$('indicateur-chargement').style.left = coordX+'px';
		
		new Ajax.Updater(
		'infos-joueur',
		'../joueurs/fcts/infosJoueurEq.php',
		{
			asynchronous: true,
			method: 'post',
			parameters: {id: idj,type: typeinfo,qui: position},
			evalScripts: true,
			onLoading: function(xhr){
				$('indicateur-chargement').show();
			},
			onSuccess: function(transport){
				$('infos-joueur').show();
			},
			onComplete: function(xhr){
				$('indicateur-chargement').hide();
				$('indicateur-chargement').style.top = '100px';
				$('indicateur-chargement').style.left = '100px';
			}
		}
		);	
	}
	
	function afficherGrille(idEq,qui){
		new Ajax.Updater(
		'joueursfondcorps',
		'../joueurs/fcts/grille.chargerEq.php',
		{
			method: 'post',
			parameters: {id: idEq,joueurs: qui},
			evalScripts: true,
			onLoading: function(xhr){
				$('indicateur-chargement').show();
			},
			onComplete: function(xhr){
				$('indicateur-chargement').hide();
			}
		}
		);
	}