// JavaScript Document
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 imgPopup(chemin){
   i1 = new Image;
   i1.src = chemin;
   if(document.all){
		html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD>';
		html += '<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>';
		html += '<CENTER><IMG SRC="'+chemin+'" BORDER="0" NAME="imagePopup" onLoad="window.resizeTo(document.imagePopup.width+14,document.imagePopup.height+32)"></CENTER></BODY></HTML>';
   } else {
	   html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD>';
	   html += '<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0 >';
	   html += '<CENTER><IMG SRC="'+chemin+'" BORDER="0" NAME="imagePopup" id="imagePopup" onLoad="window.resizeTo(this.width+30,this.height+63)"></CENTER></BODY></HTML>';
   }
   popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
   popupImage.document.open();
   popupImage.document.write(html);
   popupImage.document.close();
}

// Menu theme et sous theme
function masqueSousMenu(){
	var nbArg = arguments.length;
	var nb = arguments[0];
	if(nbArg > 1){
		var excepted = arguments[1];
		excepted = parseInt(excepted);
	}
	for(var i = 1; i < nb;i++){
		if(excepted != null){
			if(i != excepted){
				document.getElementById('sousTheme'+i).style.display='none';
			}
		} else {
			document.getElementById('sousTheme'+i).style.display='none';
		}
		
	}
}

function showSousTheme(theObj,theId){
	var sousTheme = document.getElementById('sousTheme'+theId);
	if(sousTheme.style.display == 'none'){
		//affichage du sous theme
		if(document.all){
			sousTheme.style.display = 'block';
		} else {
			sousTheme.style.display = 'table-row';
		}
		
		// changement du style du lien
		theObj.className='themeOpen';
	} else {
		//masquage du sous theme
		sousTheme.style.display = 'none';
		// changement du style du lien
		theObj.className='themeClose';
	}
}

function getSousTheme(){
	var theObj = document.getElementById('theme');
	var selectedTheme = theObj.options[theObj.selectedIndex].value;
	if(selectedTheme == ''){
		resetSousTheme();
		return;
	}
	var xhr_object = getHTTPObject();
	if(!xhr_object){
		document.location='catalogue.php?theme_id='+selectedTheme;
	} else {
		 xhr_object.open("POST", "getSousThemes.php", true);
		 xhr_object.onreadystatechange = function() { 
	     if(xhr_object.readyState == 4) 
	         eval(xhr_object.responseText); 
	   	}
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		var data = "theme_id="+escape(selectedTheme)+"&form=searchForm&target=sousTheme";
		xhr_object.send(data);
	}
}

function resetSousTheme(){
	var s = document.getElementById('sousTheme');
	s.options.length = 0;
	s.options[s.options.length] = new Option("<< Selectionnez","");
}
/** Appel de l'objet XMLhtpprequest javascript
 * @return mixed Retourne l'objet ou false
 */
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
}

