/**********************************************
********************setfocus*******************
   Delayed focus setting to get around IE bug
***********************************************/
var global_valfield;
function setFocusDelayed(){
  //global_valfield.focus();
  global_valfield.select();
  //global_valfield.style.backgroundColor = "red";;
}
function setfocus(id){  // save valfield in global variable so value retained when routine exits
  global_valfield = document.getElementById(id);
  if(global_valfield!=null){
    //setTimeout( 'setFocusDelayed()', 100 );
    window.location.hash="#"+id;
  }
}

if(!Array.indexOf){
  Array.prototype.indexOf = function(obj){
   for(var i=0; i<this.length; i++){
    if(this[i]==obj){
     return i;
    }
   }
   return -1;
  }
}

var fAjaxUse=false;
function creeAjax(){
  
         var objetAjax=false;
         try {

          /*! tous sauf  internet explorer*/
          objetAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {

					         /*Pour IExplorer*/
                   objetAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetAjax = false;
          }
         }

         if (!objetAjax && typeof XMLHttpRequest!='undefined') {

          objetAjax = new XMLHttpRequest();
         }
         return objetAjax;
}
// Arguments
// URL : adresse du php à lancer
// div: nom de la div pour afficher ce que renvoir le php (ci-dessus)
// variables :  arguments envoyés au php
// méthode : get ou post
//function FAjax (url,div,variables,methode) // 
function FAjax (url,div,variables,meth) // 
{
	var ajax=creeAjax();
	var divContenantInformations = document.getElementById(div);
	  
	/*methode POST*/
	if(meth.toUpperCase()=='POST'){
		ajax.open ('POST', url, true);		// contrôle si php existe
		ajax.onreadystatechange = function() {
			if (ajax.readyState==1) {
      //  php en cours d exécution
				//divContenantInformations.innerHTML="Loading.......";
			}
			else if (ajax.readyState==4){		//  exécution php terminée
				if(ajax.status==200){			// 200 = ok
						document.getElementById(div).innerHTML=ajax.responseText;
						jQuery('.contentLPanier').effect('bounce');
						//alert ("ok");
					}
					else if(ajax.status==404){	//  404 = erreur URL
						//divContenantInformations.innerHTML = "URL error";
						alert ("URL error");
					}else{
						divContenantInformations.innerHTML = "Error: ".ajax.status;
						alert ("error AJAX");
					}
					delete(ajax);		
			}
		}
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //  execution du php
		ajax.send(variables);
		return;
	}
} 

