 var mns=0

function selectIndex(id,val){
	 
	Theid =  $(id); 
     Theid.options[val].selected        = true;	 
 }
 
 function selectText(id,val){
	 
	  Theid =  $(id); 
     alert( Theid.options[val].text);	 
 }


function ShowDiv(div,taille){
var Table_Gauche=$(div)


var wrg = ((navigator.appName.substring(0,5)=="Micro") ? parseInt(Table_Gauche.currentStyle.width) : parseInt(getComputedStyle(Table_Gauche, null).getPropertyValue('width')));

if(mns==1){
Table_Gauche.style.width = wrg-10+'px'
if(wrg<=39){
Table_Gauche.style.width = '0px'
mns=0
return false
}
setTimeout('ShowDiv(\''+div+'\',\''+taille+'\')',10)
}

if(mns==0){
Table_Gauche.style.width= wrg+10+'px'
if(wrg>=taille){
mns=1
return false
}
setTimeout('ShowDiv(\''+div+'\',\''+taille+'\')',10)
}



}


function getAjax(file_url,containerid)
{
    //charg e un fichier file_url dans une div
    
	
	var url = file_url.split('?');
 	var url_to_div = 'getpage.php?'+url[1];
	
	
    var page=false;
    requete = ajaxObject(page);
	$(containerid).style.opacity='0.80'; // FF
	
    requete.open('GET', url_to_div, true);
    requete.send(null); 
    requete.onreadystatechange=function()
      {
      if (requete.readyState == 4 && (requete.status==200 || window.location.href.indexOf("http")==-1))
      	{
		
		$(containerid).innerHTML = requete.responseText;		 
		}
      }
 }
//simple ajax
function jxHTML(file_url, containerid, ok_eval) {
    //charg e un fichier file_url dans une div
    
	
	var url = file_url.split('?');
 	var url_to_div = 'getpage.php?'+url[1];
	
	
    var page=false;
    requete = ajaxObject(page);
	$(containerid).style.opacity='0.80'; // FF
	
    requete.open('GET', url_to_div, true);
	$('AjaxLoader').innerHTML = '<span style="background-color:#930000;color:#FFFFFF;padding:4px;">Loading...</span>';
    requete.send(null); 
    requete.onreadystatechange=function()
      {
      if (requete.readyState == 4 && (requete.status==200 || window.location.href.indexOf("http")==-1))
      	{
		
		$('AjaxLoader').innerHTML = '';
	   $(containerid).style.opacity = '1.00'; // FF
		
		
		
		if(ok_eval == 1)
			{
			var Response = requete.responseText.split(':::');
			eval(Response[0]);
			$(containerid).innerHTML = Response[1];
			}
		else
			{
			$(containerid).innerHTML = requete.responseText;
			}		 
		}
      }
 }
 function xPOST(f,NomDiv,filename,ok_eval) { 
	var xhr_object = null;
	var tabCHECK = new Array("checkbox","radio");
	var tabINPUT = new Array("text","hidden","password","submit","button");
	var tabOther = new Array("select","textarea");

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

	var method  = "POST";
	var filename;
	var data =' ';
	
	for(var i=0; i<f.length;i++)
		{
		if(f.elements[i].nodeName == "INPUT")	
			{
			if((Array(f.elements[i].getAttribute("type") in tabCHECK)) && f.elements[i].checked== 1)//
				{
				data +=f.elements[i].name+"="+f.elements[i].value+"&";	
				}
			if(Array(f.elements[i].getAttribute("type") in tabINPUT)) //tabINPUT[f.elements[i].getAttribute("type")]
				{
				data +=f.elements[i].name+"="+f.elements[i].value+"&";	
				}
			}
			
		if(Array(f.elements[i].nodeName in tabOther))	
			{
			data +=f.elements[i].name+"="+f.elements[i].value+"&";
			}
		}
	
	if(method == "GET" && data != null) {
		filename += "?"+data;
		data      = null;
	}
	
	xhr_object.open(method, filename, true);
	$('AjaxLoader').innerHTML = '<span style="background-color:#930000;color:#FFFFFF;padding:4px;">Loading...</span>';
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) 
		{
		$('AjaxLoader').innerHTML = '';
		if(ok_eval == 1)
			{
			var Response = xhr_object.responseText.split(':::');
			eval(Response[0]);
			$(NomDiv).innerHTML = Response[1];
			}
		else
			{
			$(NomDiv).innerHTML = xhr_object.responseText;
			}
		}
	}

	if(method == "POST")
	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //multipart/form-data 
	xhr_object.send(data);
	}
	
	
	
 
 
 function ajaxObject() {
 	var request = false
  	if (window.XMLHttpRequest) // if Mozilla, Safari etc
    request = new XMLHttpRequest()
    else 
     if (window.ActiveXObject)
     { // if IE
      try {
           request = new ActiveXObject("Msxml2.XMLHTTP")
          } 
      catch (e)
       {
        try{
            request = new ActiveXObject("Microsoft.XMLHTTP")
           }
        catch (e){}
       }
      }
    else
     return false
    
    return request;
 }




function InnerHTML(containerid){
	
	$(containerid).innerHTML ='';
}

function InesrtHTML(containerid,val){
	
	$(containerid).innerHTML =val;
}

function InesrtValue(containerid,val){
	
	$(containerid).value =val;
}
function InesrtValueII(containerid,containerid2){
	
	$(containerid).value =$(containerid2).value
}
function InesrtValueIII(containerid,containerid2){
	$(containerid).value =$(containerid2).innerHTML;
}
function InesrtCircuit(containerid,val){
	
	$(containerid).value =val;
	$('nom_agence').value =$('N_'+val).innerHTML;
}


function ADDCOM(prix,com){
	
	   com = Number(com)/100;
	  prix = Number(prix) * ( 1+Number(com));
	  
	  return prix;
}



function FormatNumber(val)
 
 {  
    var str = new String();
	   str = Math.floor(val);
	   var virgul = new Number();
	      virgul = Math.round((val - Math.floor(val))*1000);
	

	if(virgul>0){str = Number(str)+1;}
	
    

	return str;
 }
   function CloseDiv(DivId) {
 
   new Effect.toggle(DivId,'blind');
   
}
  function CloseDiv2(DivId) {
 
    if($(DivId).style.display=='block'){
		$(DivId).style.display ='none';
	}else{
		
	$(DivId).style.display='block'	
	}
   
}

 function ChangeStatut(condition,BtnToActive) {
	var tabid =BtnToActive.split(':');
	if($(condition).checked == true)  {
		for(i=0;i<tabid.length;i++){
		$(tabid[i]).disabled = false; 
		}
		}
	if($(condition).checked == false) {
		for(i=0;i<tabid.length;i++){
		$(tabid[i]).disabled = true; 
		}
		}
 }
 
 function PaintError(div,E){


if(E ==0){
$(div).style.background='#930000';	
}else{
$(div).style.background='#FFFFFF';	
}
	
}

 function Checkeds(TheId)
{
	var p = $(TheId);
	if(p.checked ==true)
	{
		p.value =1;
	}
	else
	{
		p.value =0;
	}
}


 function MultiCheckeds(TheId,other)
{
	var p = $(TheId);
	
		p.value =1;

	var tabDiv  = other.split(':');

for(i=0;i<tabDiv.length;i++)
	{  
		
	     var pp = $(tabDiv[i]);
	
		  pp.checked =false;
		  pp.value =0;
	}
	
}

function Disabled(div){
	
	var tabid =div.split(':');

		for(i=0;i<tabid.length;i++){
		$(tabid[i]).disabled = true; 
		}
}
function NoTDisabled(div){
	
	var tabid =div.split(':');

		for(i=0;i<tabid.length;i++){
		$(tabid[i]).disabled = false; 
		}
}

function ExternalPage(page,largeur,hauteur) {
	showWindow = window.open(page, "ExtPg","scrollbars=yes,resizable=no,left=100,top=100,screenX=100,screenY=100,width="+largeur+",height="+hauteur+",");
 }
function ChangeContent(dv1,dv2) {
	$(dv1).style.display = 'none';
	$(dv2).style.display = 'block';
 }
 
 
 function DeleteRow(file_url, containerid, TheQuery,confirmMsg, TheRow, DivConfirm) {
if(confirmThis(TheQuery,confirmMsg))
	{
	 //charge un fichier file_url dans une div
		var url = file_url.split('?');
		var url_to_div = 'getpage.php?'+url[1];
		var reponse;
		var QueryDel ;
		var page=false;
		requete = ajaxObject(page);
		requete.open('GET', url_to_div, true);
		$('AjaxLoader').innerHTML = '<span style="background-color:#930000; color:#FFFFFF; padding:4px;">Loading...</span>';
		requete.send(null);
		requete.onreadystatechange=function()
		  {
			if (requete.readyState == 4 && (requete.status==200 || window.location.href.indexOf("http")==-1))
			   {
				$('AjaxLoader').innerHTML = '';
				reponse = requete.responseText.split(':');

				eval(reponse[1]);
				if(QueryDel=='ok') {
					RowDel(containerid, TheRow);
				}
				$(DivConfirm).innerHTML = '<span style="background-color:#FAD163; padding:6px; color:#000000;">'+reponse[0]+' <a class="lien" onclick="this.parentNode.style.display=\'none\'">ok</a></span>';	
					
			   }
		  }
	} // fin if confirm
 }
 
 function RowDel(TabId,TheRow)
  {
  var i=TheRow.parentNode.parentNode.rowIndex;
  $(TabId).deleteRow(i);
  }

function confirmThis(theQuery,confirmMsg) {
	var is_confirmed = confirm(confirmMsg + ' :\n' + theQuery);
	return is_confirmed;
 }
function getOpacity(div){
new Effect.Opacity(div, {duration:2, fps:25, from:1.0, to:0.0});
 // new Effect.Opacity(div, {duration:2, fps:25, from:1.1, to:1.1});
}
function onlyNumbers(champ) {	
	var chiffres = new RegExp("[0-9.]"); //a{1}
	var verif;
	for(x = 0; x < champ.value.length; x++)
		{
		verif = chiffres.test(champ.value.charAt(x));
			if(verif == false)
				{
					champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); 
					x--;
				}
		}
 }
 
 function onlyIntger(champ) {	
	var chiffres = new RegExp("[0-9]"); //a{1}
	var verif;
	for(x = 0; x < champ.value.length; x++)
		{
		verif = chiffres.test(champ.value.charAt(x));
			if(verif == false)
				{
					champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); 
					x--;
				}
		}
 }
 
 function SwitchDisplayII(OtherDiv,TheDiv) {
	var DivNames = OtherDiv.split('-');
	compt=0;
	
	while(compt<DivNames.length) {
		
		document.getElementById(DivNames[compt]).style.display='none'; // la rubrique
		
		compt++;
	}
	document.getElementById(TheDiv).style.display = 'block'; // 
	
	
 }
 function ControlForms(forms,msg){
	CloseDiv2('divBody');
	 var error ='';
	 var f =document.getElementById(forms);
	 
	 for(i=0;i<f.length;i++){
		 
		 if(f.elements[i].value==''){
			  error ='ok';
		 }
	 }
	if(error !=''){CloseDiv2('divBody');
		alert(msg);
		return false;
	}
	else{CloseDiv2('idhchargement');return true;}
}

function MultiCloseInnerHtml(TheDiv,SepDiv)
{       
	
	var tabDiv  = TheDiv.split(SepDiv);

for(i=0;i<tabDiv.length;i++)
	{
		InnerHTML(tabDiv[i]);
	     //setTimeout('getOpacity(\''+tabDiv[i]+'\')',1000);
	
		 //setTimeout('InnerHTML(\''+tabDiv[i]+'\')',5000);
	}
	
	
}

function display(id_disp,id_mask)
{  		
		document.getElementById(id_disp).style.display = 'block';
		document.getElementById(id_mask).style.display = 'none';
}

function clearTxt(id,txt) {
  if ($(id).value == txt)
    $(id).value="" ;
  return ;
}
function fillTxt(id,txt) {
  if ( $(id).value == "" )
    $(id).value=txt;
  return ;
}


function hideFaceBox(div)
{
	$(div).style.visibility="hidden";
}

function ShowFaceBox(div,div2)
{
		if (document.body)
		{
		var larg = (document.body.clientWidth);
		var haut = (document.body.clientHeight);
		
		}
		
		
		else
		{
		var larg = (window.innerWidth);
		var haut = (window.innerHeight);
		
		}
		
			if(document.getElementById) // pour IE
			{
			$(div).style.width = larg + "px";
			$(div).style.height = haut + "px";
			}
		else
			if(document.all) // pour les autre navigateur qui gère pas la balise getElementById
			{
			document.all[div].style.width = larg + "px";
			document.all[div].style.height = haut + "px";
			}
		
		
	pops = Number(haut)/2;
	 var tops = new String();
	 tops = Math.floor(Number(pops));
	
	 newtops = tops-150;
	
	
	$(div2).style.top=newtops+"px";
	
	$(div).style.visibility="visible";
	
	
}


function NewjxHTML(file_url, containerid, ok_eval) {
    //charg e un fichier file_url dans une div
    
	
	var url = file_url.split('?');
 	var url_to_div = 'getpage.php?'+url[1];
	
	
    var page=false;
    requete = ajaxObject(page);
	$(containerid).innerHTML='<img src="../agntest/images/loader.gif"/>' // FF
	
    requete.open('GET', url_to_div, true);

    requete.send(null); 
    requete.onreadystatechange=function()
      {
      if (requete.readyState == 4 && (requete.status==200 || window.location.href.indexOf("http")==-1))
      	{
		
	
	   //$(containerid).style.opacity = '1.00'; // FF
		
		
		
		if(ok_eval == 1)
			{
			var Response = requete.responseText.split(':::');
			eval(Response[0]);
			$(containerid).innerHTML = Response[1];
			}
		else
			{
			$(containerid).innerHTML = requete.responseText;
			}		 
		}
      }
 }

function CloseDiv3(div){
	 
new Effect.Squish(div);	 

 }
 
 
 function SwitchMenu(OtherDiv,TheDiv,ON,OFF,val) {
	var DivNames = OtherDiv.split(':');
	compt=0;
	document.getElementById(TheDiv).className = ON; //
	if(val==1){
	document.getElementById(TheDiv+'1').className = 'commBtConexR BtSelectR'; 	
	}
	while(compt<DivNames.length) {
		
		document.getElementById(DivNames[compt]).className=OFF; // la rubrique
		if(val==1){
	document.getElementById(DivNames[compt]+'1').className = 'commBtConexR BtNoSelectR'; 	
	}
		compt++;
	}
	 
	
	
 }
