window.hasFlash = 0;

function deb(t) {
	gid("debug").innerHTML = t+"<br/>"+gid("debug").innerHTML;
}

function gid(t) {
	return document.getElementById(t);
}


function doblank (atag) {
	window.open(atag.href);
	return false;
}

function doBlank (atag) {
	return doblank(atag);
}


function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}


function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}



function getElementHeight(Elem) {

		if(typeof Elem != 'string') {
			var elem = Elem;
			
		} else
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		} else {
			return;
		}
		xPos = elem.offsetHeight;
		
		return xPos;
	
}

function getElementWidth(Elem) {

		if(typeof Elem != 'string') {
			var elem = Elem;
		} else 
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		} else {
			return;
		}

		xPos = elem.offsetWidth;
		
		return xPos;
	
}

function checkSize() {
 		if (self.innerWidth)
	    {
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	    }

	    else if (document.documentElement && document.documentElement.clientWidth)

	    {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	    }

	    else if (document.body)

	    {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	    }
	    //deb(frameWidth+" : "+frameHeight);
}

function goBack() {
	window.history.go(-1);
	return false;
}

function smallPopup(obj) {
	var a = window.open(obj.href,'popup','width=280,height=340,scrollbars=1');
	return false;
}


function popup(hrefe,w,h) {
	var a = window.open(hrefe,'popup','width='+w+',height='+h+'');
	return false;
}
function dopopup(obje,w,h) {
	return popup(obje.href,w,h);
}


linkedBlank = 0;
function linkBlank(atag) {
	linkedBlank++;
	window.open(atag.href,'link_blank_'+linkedBlank);
	return false;
}


function swapImg(url,obj) {
	obj.oldsrc=obj.src;
	obj.src=url;
}

function swapRestore(obj) {
	obj.src = obj.oldsrc;
}

function showhide(ide) {
	var obj = gid(ide);

	if(obj.style.display=="none" || obj.style.display=="") {
		if(obj.style.oldDisplay) {
			obj.style.display=obj.style.oldDisplay;
		} else {
			obj.style.display='block';
		}
	} else {
		obj.style.oldDisplay=obj.style.display;
		obj.style.display='none';
	}

}


function show(ide) {
	var obj = gid(ide);	
	
	obj.style.display='block';
}

function hide(ide) {
	
	if(gid(ide)){
		var obj = gid(ide);
		obj.style.display='none';
	}
}



function XHR(url, paramsUrl, divToFill,dosomethingelse,obj) {

	if(window.XMLHttpRequest) // Firefox
		var http = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		var http = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non support矰ar le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}



	http.open("GET", url+paramsUrl, true);

	http.onreadystatechange = function()
	  {



	    if (http.readyState == 4)
	    {


		
		if ( typeof divToFill == 'string') {
			if(divToFill == 'none') {

				return;
			} else if(divToFill == 'javascript_eval') {
				eval(http.responseText);
				return;
			}
	        if(gid(divToFill))
				divToFill = gid(divToFill);
		}

		divToFill.innerHTML = http.responseText;

		if(typeof dosomethingelse == 'string') {
			if(dosomethingelse.length > 0) {
				//alert(dosomethingelse);
				eval(dosomethingelse);
			}
		}
	    }
	  };
  			http.send(null);
}



function showPhotos(diapora,ide,lien) {
	 gid('diapo_sel').id = '';
	 lien.id = 'diapo_sel';
	 gid('m_photo_'+currentPhoto[diapora]).style.display='none';
	 gid('m_photo_'+ide).style.display='block';
	 currentPhoto[diapora] = ide;
}



function popupAdmin(obj,table,id,field) {
	//obj.innerHTML = '<textarea type="text">'+obj.innerHTML+"</textarea>";
	/*
	var h = getElementHeight(obj.id);
	var l = getElementWidth(obj.id);
	*/
	/*var ifra = gid('iframeadmin');
	ifra.style.left = findPosX(obj)+"px";
	ifra.style.top = findPosY(obj)+"px";
	ifra.style.width = getElementWidth(obj.id)+"px";
	ifra.style.height = getElementHeight(obj.id)+"px";
	*/
	var src = '/h/admin/index.php?gfa=1&curTable='+table+"&curId="+id+"&field="+field;
	
	window.open(src,'','width=600,height=200');
}

function gfa_roll() {
	return;
}

function gfa(obj,table,id,champ) {
	
	//XHR('/h/admin/?xhr=gfa&amp;field='+champ,'','','dogfa(http.responseText,obj)',obj);
	var x = findPosX(obj);
	var y = findPosY(obj);
	
	if(!gid('gfa_item')) {
		var div = document.createElement("iframe");
		div.id = 'gfa_item';
		document.body.appendChild(div);	
	} else {
		div = gid('gfa_item');
	}
		
	var h = getElementHeight(obj);
	var w = getElementWidth(obj);
	h = h < 100 ? 100 : h+50;
	w = w < 50 ? 50 : w+20;
	
	div.style.left = x+"px";
	div.src = '/h/admin/?gfa=1&field='+champ+"&curTable="+table+"&curId="+id;
	div.style.width = w+"px";
	div.style.height = h+"px";
	div.style.top = y+"px";
	

}

function dogfa(e,obj) {
	
	var x = findPosX(obj);
	var y = findPosY(obj);
	if(!gid('gfa_item')) {
		var div = document.createElement("div");
		div.id = 'gfa_item';
	} else {
		div = gid('gfa_item');
	}
	div.style.left = x+"px";
	div.innerHTML = e;
	div.firstChild.style.width = getElementWidth(obj)+"px";
	div.firstChild.style.height = getElementHeight(obj)+"px";
	div.style.top = y+"px";
	
	if(!gid('gfa_item')) {
		document.body.appendChild(div);	
	}
}

function dom_getElements(node, elt) {
    var list = node.getElementsByTagName(elt);
    return list;
    return (list.length) ? list : node.getElementsByTagNameNS("*", elt); 
}

function doNiceSubmit() {
	
	//var tags = document.getElementsByTagName('input');
	var tags = dom_getElements(document,'input');

	//for(var p in tags) {
	for (i = 0; i != tags.length; i++) {      
		
		var inp =tags[i];
		
		
		if (inp.type == 'submit' && inp.className == 'submit' && inp.className.indexOf('cacher') < 0) {	
			
			var mydiv = document.createElement('div');
			mydiv.className = 'div_nice_submit';
			myFormToSubmit = inp.parentNode;
			
			while(myFormToSubmit.nodeName.toLowerCase() != "form" ) {
				
				if(myFormToSubmit.parentNode) {
					myFormToSubmit = myFormToSubmit.parentNode;	
				} else {
					break;
				}
			}
			
			mydiv.innerHTML = '<div><span class="div_nice_submit_left">&nbsp;</span><a class="div_nice_submit_right" onclick="myFormToSubmit.submit()" >'+(inp.value)+'</a>	</div>';
			
			inp.parentNode.parentNode.insertBefore(mydiv,inp.parentNode);
			inp.parentNode.className += " cacher";
		}
	}
	
}


// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

// Call the following with your function as the argument

//SafeAddOnload();


function getSelectedOption(obj) {
	return obj.options[obj.selectedIndex].value;
}


window.lastIMG = false;
function showSubImgOld(obj) {

	if(window.lastIMG) {
		window.lastIMG.style.display = 'none';
	}
	var res = obj.getElementsByTagName('img');
	var im = res[0];

	if(im && im != window.lastIMG) {
		im.style.display ='block';
		window.lastIMG = im;
		im.onclick = function() {
			this.style.display='none';
		}
	}else {
		window.lastIMG = false;
	}
	
}

function showSubImg(img,obj) {
	
	
	var img = gid(img);

	if(img == window.lastIMG) {
		hideSubImg();
		return;
	}
	
	if(window.lastIMG) {
		window.lastIMG.style.display='none';
	}
	img.style.top = findPosY(obj)+'px';
	img.style.left = '350px';
	img.style.display = 'block';
	img.onclick = hideSubImg;
	window.lastIMG = img;
	
}

function hideSubImg() {
	window.lastIMG.style.display='none';
	window.lastIMG = false;
}

/* Fonction qui permet d'ajouter une fonction à exécuter lors du chargement de la page */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function doOnLoad(){
	
	hide('submit_liste_equipes');
	hide('btnSubmitActualiserCommande');
	
}