// --------------------------------------------------------------------------------
// variable diverses
// --------------------------------------------------------------------------------
	var msie = navigator.userAgent.indexOf('MSIE') != -1 ? true : false;

// ------------------------------------------------------------------------------------
// 												F O N C T I O N    G L O B A L E 
// ------------------------------------------------------------------------------------

	// ------------------------------------------------------------------------------------
	// renvoi l'objet correspondant en fonction du browner lors de appel : globale
	// ------------------------------------------------------------------------------------

	if(!document.getElementById && document.all){document.getElementById = function(id) {return document.all[id];};}
	else if(!document.getElementById && !document.all){document.getElementById = function(id) {return { style: {} };};}

	function G_obj(objname){
		eval('testObj = document.getElementById("'+objname+'");');
		return testObj;
		}
	
	// ------------------------------------------------------------------------------------
	// Vérifie la syntaxe générale d'un Email 
	// ------------------------------------------------------------------------------------
	function G_bSyntaxeEmail(sMail){
		var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
		return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);
		}

	// ------------------------------------------------------------------------------------
	// L'extension du nom de domaine est-t-elle correcte ?
	// ------------------------------------------------------------------------------------
	function G_bDomainTLD(sMail){
		var re=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|aero|arpa|biz|com|coop|edu|eu|gov|info|int|mil|museum|name|net|org|pro|jobs|travel)$/gi;
		return sMail.substr(sMail.lastIndexOf(".") + 1).match(re)!=null;
		}

	// ------------------------------------------------------------------------------------
	// La fonction globale de test du mail
	// ------------------------------------------------------------------------------------
	function G_testmail(sMail){
		if (!G_bSyntaxeEmail(sMail)){return false;}
	  else if (!G_bDomainTLD(sMail)){return false;}
	  else {return true;}
		}

	// ------------------------------------------------------------------------------------
	// Ajax
	// ------------------------------------------------------------------------------------

	function getXhr(){
		var xhr = null; 
		if(window.XMLHttpRequest){xhr = new XMLHttpRequest();}
		else if(window.ActiveXObject){
			try {xhr = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
			}
		else {alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); xhr = false; } 
  	return xhr
		}

	// ------------------------------------------------------------------------------------
	// La taille du bordel
	// ------------------------------------------------------------------------------------

	function G_getPageSize(){
		var xScroll, yScroll, vScroll, hScroll, windowWidth, windowHeight,pageWidth, pageHeight;
		if (window.innerHeight && window.scrollMaxY) {xScroll = document.body.scrollWidth;yScroll = window.innerHeight + window.scrollMaxY;}
		else if (document.body.scrollHeight > document.body.offsetHeight){xScroll = document.body.scrollWidth;yScroll = document.body.scrollHeight;}
		else {xScroll = document.body.offsetWidth;yScroll = document.body.offsetHeight;}
		if (self.innerHeight){windowWidth = self.innerWidth;windowHeight = self.innerHeight;}
		else if (document.documentElement && document.documentElement.clientHeight) {windowWidth = document.documentElement.clientWidth;windowHeight = document.documentElement.clientHeight;}
		else if (document.body){windowWidth = document.body.clientWidth;windowHeight = document.body.clientHeight;}
		if(yScroll < windowHeight){pageHeight = windowHeight;}else{pageHeight = yScroll;}
		if(xScroll < windowWidth){pageWidth = windowWidth;}else{pageWidth = xScroll;}
		if (self.pageYOffset) {vScroll = self.pageYOffset; hScroll = self.pageXOffset;}
		else if (document.documentElement && document.documentElement.scrollTop){vScroll = document.documentElement.scrollTop;hScroll = document.documentElement.scrollLeft;}
		else if (document.body) {vScroll = document.body.scrollTop;hScroll = document.body.scrollLeft;}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, hScroll , vScroll);
		return arrayPageSize;
		}

	// cache des select
	
	function G_aff_select(visibl){
		if(msie){
			selects = document.getElementsByTagName("select");
	    for (i = 0; i != selects.length; i++) {selects[i].style.visibility = visibl;}
			}
		}

// ------------------------------------------------------------------------------------
// le div InfoBulle suit la souris
// ------------------------------------------------------------------------------------

	function followmouse(e){
		var xcoord=0, ycoord=0, arrayPageSize = G_getPageSize();
		var mouseX = (typeof e != "undefined") ? e.pageX - arrayPageSize[4]: event.clientX;
	  var mouseY = (typeof e != "undefined") ? e.pageY - arrayPageSize[5]: event.clientY;
	  var divWidth = G_obj('InfoBulle').clientWidth;
	  var divHeight = G_obj('InfoBulle').clientHeight;
	  var scrollL = arrayPageSize[4];
	  var scrollT = arrayPageSize[5];
		var docwidth = arrayPageSize[0];
		var docheight = arrayPageSize[1];
	  var top = mouseY; 
	  var bottom = docheight - mouseY;
	  var left = mouseX;
	  var right = docwidth - mouseX;
	  if (right > divWidth + 10){xcoord = scrollL + mouseX + 10;}
	  else if (left > divWidth + 10){xcoord = mouseX + scrollL - divWidth - 10;}
	  else{if (left > right){xcoord = mouseX + scrollL - divWidth - 10;}else{xcoord = scrollL+mouseX + 10;}}
	  if ( bottom > divHeight + 10){ycoord += scrollT + mouseY + 10;}else{ycoord += scrollT + mouseY + 10;}
		if (xcoord + divWidth > docwidth  + scrollL){xcoord = docwidth + scrollL - divWidth;}
		if (ycoord + divHeight > docheight + scrollT){ycoord = docheight + scrollT - divHeight;}
		if (ycoord - scrollT < 0){ycoord = scrollT;}
		if (xcoord - scrollL < 0){xcoord = scrollL;}
		G_obj('InfoBulle').style.left=xcoord+"px";
		G_obj('InfoBulle').style.top=ycoord+"px";
		if (G_obj('InfoBulle').style.display=="none"){G_obj('InfoBulle').style.display="inline";}
		}

// --------------------------------------------------------------------------------
// Affichage des infos bulles
// --------------------------------------------------------------------------------

	function F_show(tips_number){
		G_obj('InfoBulle').innerHTML = '' + tips[tips_number] + '';
		document.onmousemove = followmouse;
		G_obj('InfoBulle').style.display = "block";
		G_obj('InfoBulle').style.visibility = "visible";
		G_aff_select('hidden');
		}

// --------------------------------------------------------------------------------
// On cache les infos bulles
// --------------------------------------------------------------------------------

	function F_hide(){
		document.onmousemove = "";
		G_obj('InfoBulle').style.display = "none";
		G_obj('InfoBulle').style.visibility = "hidden";
		G_obj('InfoBulle').style.left="-1000px";
		G_obj('InfoBulle').innerHTML = " ";
		G_aff_select('visible');
		}

	function validation_puce(objet , statut){
		if(G_obj(objet)){G_obj(objet).src='./images/led-'+statut+'.gif';}
		else{alert(objet);}
		}
	
	function getPageScroll(){
		var yScroll;
		if (self.pageYOffset) {yScroll = self.pageYOffset;}
		else if (document.documentElement && document.documentElement.scrollTop){yScroll = document.documentElement.scrollTop;}
		else if (document.body) {yScroll = document.body.scrollTop;}
		arrayPageScroll = new Array('',yScroll) 
		return arrayPageScroll;
		}

	function pause(numberMillis) {
		var now = new Date();
		var exitTime = now.getTime() + numberMillis;
		while (true) {
			now = new Date();
			if (now.getTime() > exitTime)
				return;
			}
		}

	function getKey(e){
		if (e == null) {keycode = event.keyCode;} else {keycode = e.which;}
		key = String.fromCharCode(keycode).toLowerCase();
		if(key == 'x'){ hideLightbox(); }
		}
	
	function showLightbox(nodossier , noclient , Mylg){
//		G_obj('lightboxFrame').src = 'http://www.strasmaster.com/cgi-bin/traducta.cgi?idd=' +nodossier+ '&idc='+noclient+'&sourceScript=clientfichier&Mylg='+Mylg+'';
		G_obj('lightboxFrame').src = 'http://www.strasmaster.com/traducta/uploader/index.php?idd=' +nodossier+ '&idc='+noclient+'&sourceScript=clientfichier&Mylg='+Mylg+'';

		pause(500);
		var arrayPageSize = G_getPageSize();
		var arrayPageScroll = getPageScroll();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		G_obj('overlay').style.display = 'block';
		G_obj('lightbox').style.height = "500px";
		G_obj('lightboxFrame').style.height = "470px";
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 500) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - 550) / 2);
		G_obj('lightbox').style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		G_obj('lightbox').style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		if (navigator.appVersion.indexOf("MSIE")!=-1){pause(250);} 
		G_aff_select('hidden');
		G_obj('lightbox').style.display = 'block';
		arrayPageSize = G_getPageSize();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		}	

	function showLightboxDoc(nodossier , noclient , Mylg){
	
//		G_obj('lightboxFrame').src = 'http://www.strasmaster.com/cgi-bin/traducta.cgi?idd=' +nodossier+ '&idc='+noclient+'&sourceScript=clientglossaire&Mylg='+Mylg+'';
		G_obj('lightboxFrame').src = 'http://www.strasmaster.com/traducta/uploader/index.php?idd=' +nodossier+ '&idc='+noclient+'&sourceScript=clientglossaire&Mylg='+Mylg+'';

		pause(500);
		var arrayPageSize = G_getPageSize();
		var arrayPageScroll = getPageScroll();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		G_obj('overlay').style.display = 'block';
		G_obj('lightbox').style.height = "80px";
		G_obj('lightboxFrame').style.height = "40px";
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 80) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - 550) / 2);
		G_obj('lightbox').style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		G_obj('lightbox').style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		if (navigator.appVersion.indexOf("MSIE")!=-1){pause(250);} 
		G_aff_select('hidden');
		G_obj('lightbox').style.display = 'block';
		arrayPageSize = G_getPageSize();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		}	

	function showLightboxDocModif(nodossier , noclient , iddoc){
		G_obj('lightboxFrame').src = 'retour-script-upload.php?idd='+nodossier+'&idc='+noclient+'&sourceScript=clientfichier&iddoc='+iddoc+'&action=maj';
		pause(500);
		var arrayPageSize = G_getPageSize();
		var arrayPageScroll = getPageScroll();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		G_obj('overlay').style.display = 'block';
		G_obj('lightbox').style.height = "500px";
		G_obj('lightboxFrame').style.height = "470px";
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 500) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - 550) / 2);
		G_obj('lightbox').style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		G_obj('lightbox').style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		if (navigator.appVersion.indexOf("MSIE")!=-1){pause(250);} 
		G_aff_select('hidden');
		G_obj('lightbox').style.display = 'block';
		arrayPageSize = G_getPageSize();
		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		}	

	function hideLightbox(){
		G_obj('overlay').style.display = 'none';
		G_obj('lightbox').style.display = 'none';
		G_aff_select('visible');
		G_obj('lightboxFrame').src = '';
		}
			
	function initLightbox(){
		// <div id="overlay">
		//	</div>
		// <div id="lightbox">
		//		<div id="lightboxFrame">
		//		</div>
		// </div>
	
		var objBody = document.getElementsByTagName("body").item(0);
		// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
//	objOverlay.onclick = function () {hideLightbox(); return false;}
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '90';

		var Nom = navigator.appName;
		var Version = navigator.appVersion;
		ie = (Nom == 'Microsoft Internet Explorer') ? 1:0
		if (ie) {var arrayPageSize = G_getPageSize(); objOverlay.style.width = arrayPageSize[0] + 'px';}
		else{	 	 objOverlay.style.width = '100%';}

		objBody.insertBefore(objOverlay, objBody.firstChild);
		var arrayPageSize = G_getPageSize();
		var arrayPageScroll = getPageScroll();

		// create lightbox div, same note about styles as above
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objLightbox.style.position = 'absolute';
		objLightbox.style.zIndex = '100';	
		objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
		// create image
		var objFrame = document.createElement("iframe");
		objFrame.setAttribute('id','lightboxFrame');
		objLightbox.appendChild(objFrame);

		var objLink = document.createElement("div");
		objLink.setAttribute('id','lightboxClose');
		objLightbox.appendChild(objLink);

		var objLink1 = document.createElement("input");
		objLink1.setAttribute('id','CloseBoutonlt');
		objLink1.setAttribute('type','button');
		objLink1.setAttribute('class','activate');
		objLink1.setAttribute('value','Annuler');
		objLink1.onclick = function () {hideLightbox(); return false;}
		objLink.appendChild(objLink1);
		}		

	function urlencode(str) {
    return escape(str.replace(/%/g, '%25').replace(/\+/g, '%2B')).replace(/%25/g, '%');
		}

	function URLDecode (encodedString) {
	  var output = encodedString;
	  var binVal, thisString;
	  var myregexp = /(%[^%]{2})/;
	  while ((match = myregexp.exec(output)) != null
	             && match.length > 1
	             && match[1] != '') {
	    binVal = parseInt(match[1].substr(1),16);
	    thisString = String.fromCharCode(binVal);
	    output = output.replace(match[1], thisString);
	  }
	  output = output.replace("+", " ");
	  return output;
		}
