// Fonctions.js (v2.0)
// Feuille de scripts JavaScript - Front-Office

// Scripts communs à toutes les pages

// Fonctions Macromedia Dreamweaver - Copyright Macromedia, Inc. All rights reserved.

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_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; }
}

<!-- Autres fonctions -->

function VS_submitForm( frmObjet_P ) {
	if( document.forms[frmObjet_P] ) document.forms[frmObjet_P].submit() ;
}

function VS_changeImgSrc() { //v1.0
 var args=VS_changeImgSrc.arguments;
 if ((img = MM_findObj(args[0])) != null && !img.VS_init) {
   img.VS_init = true;
   if (args[2] == args[0]) {
     img.src = args[1];
   }
 }
}

function VS_printWindow() { //v1.0
  window.print();
}

function VS_addFavorite() { //v1.0
	var agt=navigator.userAgent.toLowerCase();
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) {
		window.external.AddFavorite(location.href, document.title);
	} else {
		alert('Cette fonctionnalité n\'est pas supportée par votre navigateur.\nVous devrez donc ajouter manuellement notre site dans vos favoris.\nMerci de votre compréhension.')
	}
}

function VS_submitForm( frmObjet_P ) {
	if( document.forms[frmObjet_P] ) document.forms[frmObjet_P].submit() ;
}

function VS_confirmDeletion( frmMsg_P, frmUrl_P ) { //v1.0
	if( frmMsg_P!="" && frmUrl_P!="" ) {
		if ( confirm(frmMsg_P) ) window.location.href = frmUrl_P ;
	}
}

function VS_swapStyle( objName_P, strStyle_P ) { //v1.0
	objName_P.className = strStyle_P ;
}

function VS_unloadPage() {
	if( typeof(VS_fermeturePage) != "undefined" ) FermeturePage() ;
}

function VS_jumpMenu( url, frmName_P, selObj ) { //v1.0
  var strTEMP = "window.location.href = '"+ url + frmName_P + "=" + selObj.options[selObj.selectedIndex].value+"'" ;	
  eval(strTEMP);
}

function VS_clearField( strForm_P, strElement_P, strOldValue_P ) { //v1.0
	if( document.forms[strForm_P].elements[strElement_P].value == strOldValue_P )
		document.forms[strForm_P].elements[strElement_P].value = "" ;
}

function VS_fillField( strForm_P, strElement_P, strOldValue_P ) { //v1.0
	if( document.forms[strForm_P].elements[strElement_P].value == "" )
		document.forms[strForm_P].elements[strElement_P].value = strOldValue_P ;
}

// Instanciation et récupération de l'objet XmlHttpRequest
function VS_getXHR()
{
    var objXHR = null;
    if(window.XMLHttpRequest) objXHR = new XMLHttpRequest();
		else if(window.ActiveXObject)
		{
        try
				{
            objXHR = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch(e)
				{
            objXHR = new ActiveXObject('Microsoft.XMLHTTP');
				}
    }
		else
		{
        alert('Votre navigateur ne supporte pas les objets XMLHttpRequest...');
        objXHR = false;
    }
		return objXHR;
}

function VS_getSousTypes()
{
	var selectType = MM_findObj('frm_type_acteur');
	if(selectType.options[selectType.selectedIndex].value == 'Organisme') MM_findObj('trSousType').style.display = '';
}

function VS_getSousSousTypes()
{
	var selectSousType = MM_findObj('frm_soustype_acteur');
	var selectSousSousType = MM_findObj('frm_sous_soustype_acteur');
	var trSousSousType = MM_findObj('trSousSousType');
	if(selectSousType.selectedIndex != 0) 
	{
		var sousType = selectSousType.options[selectSousType.selectedIndex].value;
		var objXHR = VS_getXHR(); 
		objXHR.onreadystatechange = function() 
																{
																	//alert('readyState = ' + objXHR.readyState + '\r\nstatus = ' + objXHR.status);
																	if(objXHR.readyState == 4 && 
																	objXHR.status == 200)
																	{
																		//alert(objXHR.responseText);
																		var xml = objXHR.responseXML;
																		if(xml != null)
																		{
																			xml = objXHR.responseXML.documentElement;
																			objXHR.abort();
																			var intitulesXML = xml.getElementsByTagName('intitule'); 
																			var nbIntitulesXML = intitulesXML.length;
																			selectSousSousType.options.length = nbIntitulesXML + 1;
																			selectSousSousType.options[0].value = '';
																			selectSousSousType.options[0].text = ' - Sélectionnez un sous sous-type - ';
																			for(var i = 1; i <= nbIntitulesXML; i++)
																			{
																				var intitule = intitulesXML[(i - 1)].firstChild.nodeValue;
																				selectSousSousType.options[i].value = intitule;
																				selectSousSousType.options[i].text = intitule;
																			}
																			trSousSousType.style.display = '';
																		}
																		else trSousSousType.style.display = 'none';
																	}
																};
		objXHR.open('POST',
								'../xmldata/liste-sous-sous-types-acteurs.xml.php',
								true);
		objXHR.setRequestHeader('Content-Type',
														'application/x-www-form-urlencoded');
		objXHR.send('soustype=' + sousType);
	} 
	else
	{
		selectSousSousType.selectedIndex = null;
		trSousSousType.style.display = 'none';		
	}
}

