var svObjName = new Array();
var svObj = new Array();

function retDiv(div)
{
        return retDiv_(div,1)
}
function retDiv_(div,cache)
{
        if(cache)
        for(o=0;o<svObjName.length;o++)
                if(svObjName[o]==div)
                        return svObj[o];

        if (document.getElementById)
                obj= eval("document.getElementById('"+div+"')");
        else
                obj= eval("document.all["+div+"]");

        svObjName[svObjName.length]=div;
        svObj[svObj.length]=obj;
        return obj;
}

function getW()
{     
                if(document.innerWidth)                         return document.innerWidth;
        else    if(document.documentElement.clientWidth)        return document.documentElement.clientWidth;
        else    if(document.body)                               return document.body.clientWidth;
}
function getH()
{
	var h;
                if(document.innerHeight)                        h= document.innerHeight;
        else    if(document.documentElement.clientHeight)       h= document.documentElement.clientHeight;
        else    if(document.body)                               h= document.body.clientHeight;
	return h;
/*
	s=document.body.scrollHeight;
alert("s="+s+" h="+h);
	return (s-h);
*/
}
/*
function actu_iframe1(d)
{
debugJS(retDiv(d))
alert(document.getElementById(d).scrollHeight);
alert(document.getElementById(d).offsetHeight);
	if(navigator.appName=="Microsoft Internet Explorer" ){
		if(document.all) document.all.id_iframe.style.height = document.frames(d).document.body.scrollHeight;
		else document.getElementById(d).style.height = document.getElementById(d).contentDocument.body.scrollHeight;
	}
	else
	{
		document.getElementById(d).style.height = document.getElementById(d).contentDocument.body.offsetHeight+"px";
	}
}
function actu_iframe2(d)
{
	if(document.all) document.all.iframe.style.height = document.frames(d).document.body.scrollHeight;
	else document.getElementById(d).style.height = document.getElementById(d).contentDocument.body.scrollHeight;
}
*/
function retHdiv(d,t)
{
	doc=retDiv(d);
		     if(t=='h') return doc.scrollHeight;
		     if(t=='h') return doc.offsetHeight;
	if (document.all) // ok I.E 
	{
		     if(t=='h') return doc.currentStyle.height;
		else if(t=='p') return doc.currentStyle.left;
	}
	else // ok firefox.0.9.2 , pas mozilla.1.0 ni netscape.7.02 
	{
		     if(t=='h') return document.defaultView.getComputedStyle(doc, null).height;
		else if(t=='p') return document.defaultView.getComputedStyle(doc, null).left;
	}
	//alert('hauteur = '+ H + ' ; ' +  P + ' de la gauche');
}
function trim(string,d,f)
{
        if(d  && !f)    return string.replace(/(^[ \n\r ]+)/g,'');
        if(!d  && f)    return string.replace(/(\s*$)/g,'');
        if(d  && f)     return string.replace(/(^\s*)|(\s*$)/g,'');
        return string;
}
function setInnerHTML(divContent, HTML) // attention avec IE si HTML debute par <script>... il ne sera pas pris en compte
{					// il faut mettre avant par exemple un <br style="line-height:0px;"> avant
	if(trim(HTML,1,0).toLowerCase().substr(0,7)=="<script")
		HTML="<br style=\"line-height:0px;\">"+HTML; // POUR BUG IE

      divContent.innerHTML=HTML;

      var All=divContent.getElementsByTagName("*");
      for (var i=0; i<All.length; i++)
      {
        All[i].id=All[i].getAttribute("id")
        All[i].name=All[i].getAttribute("name")
//        All[i].className=All[i].getAttribute("class")
      }
      var AllScripts=divContent.getElementsByTagName("script")
      for (var i=0; i<AllScripts.length; i++)
      {
         var s=AllScripts[i];

	if(!s) continue;
/*
         if (s.src && s.src!="")
         {
            // Précédement asynchrone, mis en synchrone pour éviter des problèmes de dépendances de scripts
alert(s.src);
            eval(getFileContent(s.src))
         }
         else
         {
//alert(s.innerHTML);
            eval(s.innerHTML)
         }
*/
		if(!(script=s.innerHTML))
			continue;
                if(window.execScript)
                    window.execScript(script);
                else 
		if(navigator.userAgent.indexOf('KHTML') != -1) 
		{ //safari, konqueror..
                    var s = document.createElement('script');
                    s.type = 'text/javascript';
                    s.innerHTML = script;
                    document.getElementsByTagName('head')[0].appendChild(s);
                } 
		else
                    window.eval(script);
      }
}
/*
HsAjax.prototype.loadHTML = function() {
        var s = this.xmlHttp.responseText;
        if (!hs.ie || hs.ieVersion() >= 5.5) {
                s = s.replace(/\s/g, ' ');
                if (this.iframe) {
                        s = s.replace(new RegExp('<link[^>]*>', 'gi'), '');
                        s = s.replace(new RegExp('<script[^>]*>.*?</script>', 'gi'), '');
                        var doc = this.iframe.contentDocument || this.iframe.contentWindow.document;
                        doc.open();
                        doc.write(s);
                        doc.close();
                        try { s = doc.getElementById(this.id).innerHTML; } catch (e) {
                                try { s = this.iframe.document.getElementById(this.id).innerHTML; } catch (e) {} // opera
                        }
                        hs.container.removeChild(this.iframe);
                } else {
                        s = s.replace(new RegExp('^.*?<body[^>]*>(.*?)</body>.*?$', 'i'), '$1');
                }

        }
        hs.identifyContainer(this.content, 'highslide-body').innerHTML = s;
        this.onLoad();
};
*/
function replaceDiv(div,txt)
{
        if(!(elem=retDiv(div))) return 0;
        setInnerHTML(elem,txt);
        return 1;
}       
/*
function addLoadEvent(func)
{
        var oldonload = window.onload;

        if (typeof window.onload != 'function')
                window.onload = func;
        else
                window.onload = function() {
                                            oldonload();
                                            func();
                                        }
}
*/
function addLoadEvent(func)
{       
        addEvent('onload',func);
}
function addEvent(fctEvent,func)
{       
        var svfct = window[fctEvent];
        
        if (typeof window[fctEvent] != 'function')      window[fctEvent] = func;
        else                                            window[fctEvent] = function() { svfct(); func(); }
}


function debugJS(o)
{
	var s = "\n-----------------------------\n";
	alert(debugJS_(o,s,""));
}
function debugJS_(o,s,pere)
{
   for (var x in o) 
   {
                	if (typeof o[x]=="iobject")
                       		s=debugJS_(o[x],s,pere+x+".");
                else	
		{
Expression = new RegExp("height","i")
if(!Expression.test(pere+x))
	continue;
			if (typeof o[x]=="function")
                 		s+=pere+x+" -function-\n";
                	else 	s+=pere+x+" ["+ o[x]+"]\n";
		}
   }
   return s;    
}
//---------------------------------------------
//---------------------------------------------
//---------------------------------------------
function ctrl(f,chp,format,lib,m) 
{
        var controle = f[chp];
        
             if(format=="EMAIL") { RE = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/;} // EMAIL : email
        else if(format=="A")     { RE = /^([A-Za-zàâäéèêëîïôùûç']+[ ]*[-]*[A-Za-zàâäéèêëîïôùûç']*)+$/;}   // A : alphabétique
        else if(format=="TEL")   { RE = /^\d{10}$/;}                     
        else if(format=="CP")    { RE = /^\d{5}$/;}                     

        r=1;
        if (controle.value.length > 0) 
        {
        //      if ( format == "EMAIL" ) 
        //              controle.value= controle.value.replace("'"," ");

                if (!RE.test(controle.value))
                {
                        r=0;
                        if(m) extAlertSec('Champ "'+lib+'" incorrect!',2);
                      //  bloque(f,chp);
                }
        }
        return r;
}
function autoFocus(form,cle) // positionne le focus sur le premier input editable
{
        for(i=0,j=-1;i<form.length;i++)
        {
                if(form[i].type!="text")
                        continue;
                if(j<0)
                {
                        j=i;
                        if(cle=='') break;
                }
                if(cle!="" && form[i].name=="valeur[0]["+cle+"]")
                {       
                        j=i;
                        break;
                }
        }
        if(j>=0) form[j].focus();
        document.body.style.cursor = "default";
}  

function son(s)
{
        retDiv("musique").src='/sons/'+s;
} 
function ecrit(div,txt,n,step)
{
        if(!(elem=retDiv(div))) return 0;
        l=txt.length; 
        for(i=0,b=0;i<l && (i<n || b==1);i++)
        {
                c=txt.substr(i,1); 
                        if(c=='<') b=1;
                else    if(c=='>') b=0;
        }               
        n=i;
        elem.innerHTML=txt.substr(0,n);
  
        if(n<l) 
        { 
                var exp = new RegExp("[\"]","gi");
                txt=txt.replace(exp,"\\\"");
                var exp = new RegExp("[']","gi");
                txt=txt.replace(exp,"\\'");
                var exp = new RegExp("[\n]","gi");
                setTimeout("ecrit('"+div+"',\""+txt.replace(exp,'')+"\","+(n+step)+","+step+");",1);
        }
        return 1;
} 
//if (window.self!=window.top) top.location.href=self.location.href;
function lib_bwcheck()
{ //Browsercheck (needed)       
        this.ver=navigator.appVersion
        this.agent=navigator.userAgent
        this.dom=document.getElementById?1:0
        this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
        this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
        this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
        this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
        this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
        this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
        this.ie =(this.ver.indexOf("MSIE ")>-1 && this.dom && !this.opera5)?1:0;
        this.mac=this.agent.indexOf("Mac")>-1
        this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
        this.ns4=(document.layers && !this.dom)?1:0;
        this.bw=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 ||
this.ns4 || this.ns6 || this.opera5)
        return this
}
var bw=new lib_bwcheck()

function ecrit(div,txt,n,step)
{
        if(!(elem=retDiv(div))) return 0;
        l=txt.length; 
        for(i=0,b=0;i<l && (i<n || b==1);i++)
        {
                c=txt.substr(i,1); 
                        if(c=='<') b=1;
                else    if(c=='>') b=0;
        }               
        n=i;  
        elem.innerHTML=txt.substr(0,n);
        
        if(n<l) 
        {
                var exp = new RegExp("[\"]","gi");
                txt=txt.replace(exp,"\\\"");
                var exp = new RegExp("[']","gi");
                txt=txt.replace(exp,"\\'");
                var exp = new RegExp("[\n]","gi");
                setTimeout("ecrit('"+div+"',\""+txt.replace(exp,'')+"\","+(n+step)+","+step+");",1);
        }
        return 1;
}
function makeGETquery(f,q)
{
	objets=f.elements;
	for(i=0;i<objets.length;i++) 
	{
                if(objets[i].type=="submit"
		||(objets[i].type=='radio' && !objets[i].checked))
                        continue;
                     if(objets[i].type=='checkbox')  val=(objets[i].checked?1:0);
                else if(objets[i].type=='select')    val=objets[i][objets[i].selectedIndex].value;
                else  	                             val=objets[i].value;
                q+=objets[i].name+"="+escape(val)+"&";
        }
	return q;
}
function submit_request(f,idName,action)
{
        var tmp="";

/*
        for(objets = document.getElementsByTagName("input"),i=0;i<objets.length;i++)
        {
                if(objets[i].type=='radio' && !objets[i].checked)
                        continue;
                if(objets[i].type=='checkbox')  val=(objets[i].checked?1:0);
                else                            val=objets[i].value;
                tmp+=objets[i].name+"="+escape(val)+"&";
        }
        for(objets = document.getElementsByTagName("select"),i=0;i<objets.length;i++)
                tmp+=objets[i].name+"="+escape(objets[i][objets[i].selectedIndex].value)+"&";
        for(objets = document.getElementsByTagName("textarea"),i=0;i<objets.length;i++)
                tmp+=objets[i].name+"="+escape(objets[i].value)+"&";
*/
	tmp=makeGETquery(f,'');

        //-HttpRequest-------------------------------         
        var xhr_object = null;

        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;
        }

        xhr_object.open("POST", action, true);

        xhr_object.onreadystatechange = function anonymous()
        {
                if(xhr_object.readyState == 4)
                {
                        if(xhr_object.responseText.substr(0,8)=='errMess:')
                        {
                                son("b3.mp3");
                                if(!ecrit("errMess",xhr_object.responseText.substr(8),10,5))
                                        alert('le calque nommé "errMess" n a pas été trouve !');
                        }
                        else
                        {
                                son("b1.mp3");
                                if(!replaceDiv(idName,xhr_object.responseText))
                                 alert('???');
                        }
                }
        }
        xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1;");
        xhr_object.send(tmp);
        //---------------------------------------------   
}


