// Fonctions.js (v3.0)
// Feuille de scripts JavaScript - Front-Office
// Copyright 1999-2003 Versus Studio

// 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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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

<!-- Autres fonctions -->

// Fonctions permettant de grer les vnements de chargement et de dchargement des pages

function VS_loadPage() { //v1.0
	if(typeof(VS_boolInitPage) != "undefined") VS_initPage();
}

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_adjustHeight() {
	var args=VS_adjustHeight.arguments;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non IE
    winHeight = window.innerHeight;
  } else {
    if( document.documentElement && document.documentElement.clientHeight ) {
        //IE 6+ in 'standards compliant mode'
        winHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && document.body.clientHeight ) {
        //IE 4 compatible
        winHeight = document.body.clientHeight;
      }
    }
  }
	for(i=0;i<(args.length-1);i+=2) {
	  if ((eltTag=MM_findObj(args[i]))!=null) {
  	  eltTag.height=winHeight-args[i+1];
		}
	}
}

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

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

function VS_jumpMenu(selObj){ //v3.0
	window.open(selObj.options[selObj.selectedIndex].value,'','');
}

function VS_openPicture(imgName, imgWidth, imgHeight, imgTitle, imgX, imgY, imgBgColor) { //v1.0
  newWindow=window.open('','newWindow','width='+imgWidth+',height='+imgHeight+',left='+imgX+',top='+imgY);
  newWindow.document.open();
  newWindow.document.write('<html><title>'+imgTitle+'</title><body bgcolor="'+imgBgColor+'" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
  newWindow.document.write('<img src="'+imgName+'" width="'+imgWidth+'" height="'+imgHeight+'" alt="'+imgTitle+'">'); 
  newWindow.document.write('</body></html>');
  newWindow.document.close();
  newWindow.focus();
}

// Visualisation d'une photo ou d'une animation flash dans un DIV
function VS_openView(photoPath_P, photoWidth_P, photoHeight_P, photoType_P, closeText_P) {
	var isSWF = (photoType_P == 'application/x-shockwave-flash');
	var fenetreScrollTop = document.body.scrollTop;
	var fenetreScrollLeft = document.body.scrollLeft;
	var topDiv = fenetreScrollTop + document.body.clientHeight/2 - photoHeight_P/2 - 22; // le -25 correspondant à la taille de la bordure et du padding
	var leftDiv = fenetreScrollLeft + document.body.clientWidth/2 - photoWidth_P/2 - 6; // le -10 correspondant à la taille de la bordure et du padding
	var divView = document.createElement('DIV');
	with(divView) 
	{
		id = 'divView';
		style.position = 'absolute';
		style.width = photoWidth_P;
		style.height = photoHeight_P;
		style.top = topDiv;
		style.left = leftDiv;
		style.zIndex = 1;
		style.backgroundColor = '#666666';
		style.visibility = 'visible';
	}
	var innerHtml = '<div style="background-color: #CCCCCC; border:#000000 1px solid; padding: 5px 5px 10px 5px; height: ' + (photoHeight_P+15) + 'px; width: ' + photoWidth_P + 'px;"><div style="background-color: #F5F5F5; height: ' + photoHeight_P + 'px; width: ' + photoWidth_P + 'px;">';
	// Cas d'une image
	if(!isSWF) innerHtml += '<img src="'+ photoPath_P +'" width="' + photoWidth_P + '" height="' + photoHeight_P + '" alt="Visualisation">';
	// Cas d'une animation FLASH
	else {
		innerHtml += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,28,0" width="' + photoWidth_P + '" height="' + photoHeight_P + '">';
    innerHtml += '<param name=movie value="' + photoPath_P + '">';
    innerHtml += '<param name=quality value=high>';
    innerHtml += '<embed src="' + photoPath_P + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + photoWidth_P + '" height="' + photoHeight_P + '">';
    innerHtml += '</embed>'; 
    innerHtml += '</object>';
	}
	innerHtml += '</div><div style="height: 15px; width: ' + photoWidth_P + 'px;"><p class="right"><a href="javascript:void(0);" onClick="VS_closeView()" title="&gt; ' + closeText_P + '">' + closeText_P + '</a><img src="../../images/croix.gif" name="imgCloseView" width="20" height="10" border="0" align="absmiddle" id="imgCloseView"></p></div></div>';
	divView.innerHTML = innerHtml;
	document.body.appendChild(divView);
}

// Fermeture de la visualisation
function VS_closeView()
{
	var divView = document.getElementById('divView');
	document.body.removeChild(divView);
}

// Instanciation et rcupration 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;
}

