﻿var ErrorFound = false; // francois

function getAbsolutePos(el) {	
	var r = { x: el.offsetLeft, y: el.offsetTop };

	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

function hideWindowsComponents(obj,spanName) {	
	var tags = new Array("select");
		
	if (spanName != null)
	  {
	    var s = { x: spanName.offsetLeft - 8, y: spanName.offsetTop - 3};
	  } else {
	    var s = { x: 0, y: 0};
	  }
	  
    
	var p = { x: obj.offsetLeft, y: obj.offsetTop};
	p.x = p.x + s.x;
	p.y = p.y + s.y;

	var EX1 = p.x;
	var EX2 = obj.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = obj.offsetHeight + EY1;
	
	
	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;

		for (var i = ar.length; i > 0;) {
			cc = ar[--i];

			p = getAbsolutePos(cc);
			var CX1 = p.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p.y;
			var CY2 = cc.offsetHeight + CY1;

			if (cc.getAttribute("autohide")!="false") {
			  if (obj.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				  cc.style.visibility = "visible";
			  } else {
				  cc.style.visibility = "hidden";
			  }
			}
		}
	}
}

//Ouverture d'un menu
function openMenuIONIK(obj,spanName){		
	try {
			var tags = new Array("select");		
			for (var k = tags.length; k > 0; ) {
			var ar = document.getElementsByTagName(tags[--k]);
			var cc = null;
			
			
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];
			
			    cc.style.visibility = "hidden";
			    }
		}
		window.event.returnValue=false;
		obj.style.visibility='visible';
		return false;
		}
	catch(ex){
			 obj.style.visibility='visible';
			 return false;
			 }
}

//Fermeture d'un menu
function closeMenuIONIK(obj){
	try {	
		obj.style.visibility='hidden';
		var tags = new Array("select");	
		for (var k = tags.length; k > 0; ) {
			var ar = document.getElementsByTagName(tags[--k]);
			var cc = null;
	
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];			
		    	cc.style.visibility = "visible";
		    }
		}
		window.event.returnValue=false;
		return false;
		}
	catch(ex){
			 return false;
			 }
}

//Fermeture de tous les menus
/*function closeAllMenuIONIK(place){
	try {
		var tags = new Array("select");	
		for (var k = tags.length; k > 0; ) {
			var ar 
			if (place = 1) {
				ar = parent.ionikFrame.document.getElementsByTagName(tags[--k]);
			}else{
				ar = document.getElementsByTagName(tags[--k]);
				}
			var cc = null;
	
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];			
		    	cc.style.visibility = "visible";
		    }
		}
		    
		var tags2 = new Array("div");	
		for (var k2 = tags2.length; k2 > 0; ) {
			var ar2 
			if (place = 1) {
				ar2 = parent.document.getElementsByTagName(tags2[--k2]);
			}else{
				ar2 = document.getElementsByTagName(tags2[--k2]);
				}
			var cc2 = null;
	
			for (var i2 = ar2.length; i2 > 0;) {
				if (ar2[i2-1].getAttribute("close")){
					cc2 = ar2[--i2];
					cc2.style.visibility = "hidden";
					}else{
					i2--
					}
		    }
		}
		window.event.returnValue=false;
		return false;
		}
	catch(ex){
			 return false;
			 }
}*/

//Ouverture du menu contextuel
function openContextIONIK(obj,spanName){
	contextIONIK(obj.id);
	obj.style.visibility='visible';
}

//Positionnement du menu contextuel
function contextIONIK(DivID){
	var obj = document.all[DivID];
	
	var posX = (event.clientX + document.body.scrollLeft);
	var posY = (event.clientY + document.body.scrollTop);
	var posW = (obj.offsetWidth);
	var posH = (obj.offsetHeight);
	var screenW = (screen.availWidth + document.body.scrollLeft)
	var screenH = (screen.availHeight + document.body.scrollTop)
	
	if (posX > (screenW - (posW + 10))){
	  posX = (posX - posW)
	}
	
	if (posY > (screenH - (posH + 150))){
	  posY = (posY - posH)
	}
	
	obj.style.left = posX
	obj.style.top = posY
	hideWindowsComponents(obj);
}

//Fermeture du menu contextuel
function closeContextIONIK(obj,spanName){
	obj.style.top=(-400);
	obj.style.left=(-400);
	obj.style.visibility='hidden';
	hideWindowsComponents(obj,spanName);
}

//Fonction qui active/désactive un textbox selon l'état de son checkbox lié.
var OriginalClass="";

function EnableDisable(aCheckBox,aTextBox)
{
	var MyTextBox;
	MyTextBox=document.getElementById(aTextBox);
	MyTextBox.readOnly=!(aCheckBox.checked);
	if(MyTextBox.readOnly)	
	{
		OriginalClass=MyTextBox.getAttribute('className');
		MyTextBox.className=MyTextBox.getAttribute('classRO');
		MyTextBox.disabled=true;
		MyTextBox.value="";
	}
	else
	{
		if(OriginalClass!="") 
			MyTextBox.className=OriginalClass;			
		MyTextBox.disabled=false;
		MyTextBox.focus();
	}
}


function init_hsrc() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var MouseOverHappened;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
	if (imgarr[i].getAttribute('hsrc')) {
		imgTemp[i] = new Image();
		imgTemp[i].src = imgarr[i].getAttribute('hsrc');
		imgarr[i].onmouseover = function() {
			imgOriginSrc = this.getAttribute('src');			
			this.setAttribute('src',this.getAttribute('hsrc'));
			MouseOverHappened=true;
		}
		imgarr[i].onmouseout = function() {
			if(MouseOverHappened)
				this.setAttribute('src',imgOriginSrc);
		}
	}
  }
}


function keyevent(){
  return true;
}

function context_menu(){
	return false;
}

function init_custom_tags(){
	init_hsrc();
	init_status();
	init_status_td();
	init_status_tr();
	init_status_div();
}

function stringTrim (s) {
  return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
String.prototype.trim = stringTrim;

function IsInteger(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   if(sText.trim()=="") return false;
    
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
//Change le texte de la status bar sur le OnMouseOver des Tags "a" ! (Utiliser l'attribut status='xxx')
function init_status() {
  if (!document.getElementById) return
  var statusarr = document.getElementsByTagName('a');
  var temparr = new Array();
  
  for (var i = 0; i < statusarr.length; i++) {
	temparr[i]=new String()
	temparr[i]=statusarr[i].getAttribute('status');	
	if (statusarr[i].getAttribute('status')) {					
		statusarr[i].onmouseover = function() {			
			window.status = this.getAttribute('status');
			return true;
		}
		statusarr[i].onmouseout = function() {
			window.status = NOM_CLIENT;
			return true;
		}
	}
  }
}

function init_status_td() {
  if (!document.getElementById) return
  var statusarr = document.getElementsByTagName('td');
  var texte
  var temparr = new Array();
  var temparr2 = new Array();

    for (var i = 0; i < statusarr.length; i++) {	
	temparr[i]=new String();
	temparr[i]=statusarr[i].getAttribute('status');	
	
	temparr2[i]=new String();
	temparr2[i]=statusarr[i].getAttribute('over');
	
	if (statusarr[i].getAttribute('status')) {					
		statusarr[i].onmouseover = function() {			
			
			eval(this.getAttribute('over'));			
			window.status = this.getAttribute('status');
			return true;
		}
		statusarr[i].onmouseout = function() {
			eval(this.getAttribute('out'));
			window.status = NOM_CLIENT;
			return true;
		}
	}
  }
}

function init_status_tr() {
  if (!document.getElementById) return
  var statusarr = document.getElementsByTagName('tr');
  var texte
  var temparr = new Array();
  var temparr2 = new Array();

    for (var i = 0; i < statusarr.length; i++) {	
	temparr[i]=new String();
	temparr[i]=statusarr[i].getAttribute('status');	
	
	temparr2[i]=new String();
	temparr2[i]=statusarr[i].getAttribute('over');
	
	if (statusarr[i].getAttribute('status')) {					
		statusarr[i].onmouseover = function() {			
			
			eval(this.getAttribute('over'));			
			window.status = this.getAttribute('status');
			return true;
		}
		statusarr[i].onmouseout = function() {
			eval(this.getAttribute('out'));
			window.status = NOM_CLIENT;
			return true;
		}
	}
  }
}

function init_status_div() {
  if (!document.getElementById) return
  var statusarr = document.getElementsByTagName('div');
  var texte
  var temparr = new Array();
  var temparr2 = new Array();

    for (var i = 0; i < statusarr.length; i++) {	
	temparr[i]=new String();
	temparr[i]=statusarr[i].getAttribute('status');	
	
	temparr2[i]=new String();
	temparr2[i]=statusarr[i].getAttribute('over');
	
	if (statusarr[i].getAttribute('status')) {					
		statusarr[i].onmouseover = function() {			
			
			eval(this.getAttribute('over'));			
			window.status = this.getAttribute('status');
			return true;
		}
		statusarr[i].onmouseout = function() {
			eval(this.getAttribute('out'));
			window.status = NOM_CLIENT;
			return true;
		}
	}
  }
}

function replace(string,text,by) {
 // Replaces text with by in string
     var i = string.indexOf(text);
     var newstr = '';
     if ((!i) || (i == -1)) return string;
     newstr += string.substring(0,i) + by;

     if (i+text.length < string.length)
         newstr += replace(string.substring(i+text.length,string.length),text,by);
     
     return newstr;
 }   

function OpenDlgCenter(aPage,aName,aWidth,aHeight)
{
	var LeftPos = screen.availWidth/2-(aWidth/2);
	var TopPos  = screen.availHeight/2-(aHeight/2);
	return window.showModalDialog(aPage,self,"status:no;dialogWidth:" + aWidth + "px;dialogHeight:" + aHeight + "px;dialogHide:true;help:no;scroll:no;left:" + LeftPos + "px;top:" + TopPos + "px");	
}

function OpenPopupCenter(aPage,aName,aWidth,aHeight)
{
	var LeftPos = screen.availWidth/2-(aWidth/2);
	var TopPos  = screen.availHeight/2-(aHeight/2);
	window.open(aPage,aName,"status=no,location=no,scrollbars=yes,resize=no,directories=no,toolbar=no,menubar=no,copyhistory=no,width=" + aWidth + ",height=" + aHeight + ",left=" + LeftPos + ",top=" + TopPos);return false;
}

function AllowTabCharacter()
{   
	if (event != null) {      
		if (event.srcElement) {         
			if (event.srcElement.value) {            
				if (event.keyCode == 9) {  // tab character               
					if (document.selection != null) {                  
						document.selection.createRange().text = '\t';                  
						event.returnValue = false;               
					}               
					else {                  
							event.srcElement.value += '\t';                  
							return false;               
						}            
					}          
				}      
			}   
		}
}

function autoJumpKeyDown(aTB)
{
	document.getElementById(aTB).lastValue = document.getElementById(aTB).value;
	return true;
}

function autoJumpKeyUp(initialTB,targetTB,MaxLength)
{				
	var tb1;
	var tb2;		
	tb1=document.getElementById(initialTB);
	tb2=document.getElementById(targetTB) 
	if(tb1.value.length == MaxLength && tb1.value!=tb1.lastValue && tb1.lastValue!=null)
	{
		tb2.focus();
		//tb2.select();
		tb1.lastValue=tb1.value;
		tb1.value = tb1.value.toUpperCase();
	}
	return true;
}

onload=init_custom_tags;

function Fn_FindObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=Fn_FindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Fn_SousMenu() { //v6.0
  var i,p,v,obj,args=Fn_SousMenu.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=Fn_FindObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
	document.onkeydown = keyevent;