// JS Document

function getInfo($pParam) {
	switch ($pParam) {
		case 'identCont':
		document.getElementById('identCont').style.visibility = 'visible';	
		document.getElementById('pwdCont').style.visibility = 'hidden';	
		document.getElementById('captchaCont').style.visibility = 'hidden';	
		break;
		case 'pwdCont':
		document.getElementById('identCont').style.visibility = 'hidden';	
		document.getElementById('pwdCont').style.visibility = 'visible';	
		document.getElementById('captchaCont').style.visibility = 'hidden';	
		break;		
		case 'captchaCont':
		document.getElementById('identCont').style.visibility = 'hidden';	
		document.getElementById('pwdCont').style.visibility = 'hidden';	
		document.getElementById('captchaCont').style.visibility = 'visible';	
		break;				
		default :
		document.getElementById('identCont').style.visibility = 'hidden';	
		document.getElementById('pwdCont').style.visibility = 'hidden';	
		document.getElementById('captchaCont').style.visibility = 'hidden';	
		break;			
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function Deplacer(l1,l2) {
if (l1.options.selectedIndex>=0) {
o=new Option(l1.options[l1.options.selectedIndex].text,l1.options[l1.options.selectedIndex].value);
l2.options[l2.options.length]=o;
l1.options[l1.options.selectedIndex]=null;
}
}

function selectAll(selectBox,selectAll) {
	// have we been passed an ID
	if (typeof selectBox == "string") {
		selectBox = document.getElementById(selectBox);
	}
	// is the select box a multiple select box?
	if (selectBox.type == "select-multiple") {
		for (var i = 0; i < selectBox.options.length; i++) {
			selectBox.options[i].selected = selectAll;
		}
	}
}

function Init_tinyMCE(field,readonly){
tinyMCE.init({
	// General options
	mode : "exact",
	elements : field,
	readonly : readonly ,
	
	theme : "advanced",
	plugins : "",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
	theme_advanced_buttons2 : "fontselect,fontsizeselect",
	theme_advanced_buttons3 : "bullist,numlist,|,undo,redo,|,forecolor,backcolor,|,sub,sup,|,emotions",
	//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	//theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false,

	// Example word content CSS (should be your site CSS) this one removes paragraph margins
	content_css : "css/word.css",

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "lists/template_list.js",
	external_link_list_url : "lists/link_list.js",
	external_image_list_url : "lists/image_list.js",
	media_external_list_url : "lists/media_list.js",

	// Replace values for the template plugin
	template_replace_values : {
	username : "Some User",
	staffid : "991234"
	}
});
}

function showDiv(anId) {
	node = document.getElementById(anId);
	node.style.visibility = "visible";
	node.style.height = "auto";	
}

function hideDiv(anId) {
		node = document.getElementById(anId);
		node.style.visibility = "hidden";
		node.style.height = "0";			
}

function showMedia(name,number,max) {
var d = document.getElementById(name+number);
		 for (var i = 0; i<=max; i++) {
		 		 if (document.getElementById(name+i)) {document.getElementById(name+i).style.display='none';}
		 }
if (d) {d.style.display='block';}
}

function showBtn(name,number,max) {

var d = document.getElementById(name+number);
		 for (var i = 0; i<=max; i++) {
		 		 if (document.getElementById(name+i)) {document.getElementById(name+i).style.display='block';document.getElementById(name+i).className='videoStyleGal';}
		 }
if (d) {d.style.display='none';}
}

function updateStatVideo(id_video, num_video){
    var url = '../components/updateStatVideo.php';
    var myAjax = new Ajax.Request(
        url, { 
				method: 'get', 
				parameters: {id: id_video},
				onComplete: function(){showMedia('smenuvideo',num_video,200), showBtn('videoBtn',num_video,200)}
			} ); 

} 

function popupcentree(page,largeur,hauteur,options) {     
var top=(screen.height-hauteur)/2;     
var left=(screen.width-largeur)/2;    
window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options); 
} 

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

//Fonction pour Roll Over Menu IE6
sfHover = function() {
	var sfEls = document.getElementById("menuHangarG").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

//Fonction pour vérifier si une entrée en un nombre decimal ou pas
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }

function FilterModels(id_categorie_produit, id_categorie_equipement, id_type_equipement, url_www) {

  var OAjax;
  if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
  else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
  OAjax.open('POST',url_www + "/components/_filterModels.php",true);

  OAjax.onreadystatechange = function()
  {
      if (OAjax.readyState == 4 && OAjax.status==200)
      {
            
			document.getElementById('DIVmodel_'+id_categorie_equipement+'_'+id_type_equipement).innerHTML=OAjax.responseText;
	
      }
	  
  }
  OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  sel = document.getElementById('fabricant_'+id_categorie_equipement+'_'+id_type_equipement);
  var id_fabricant = sel.options[sel.selectedIndex].value;

  OAjax.send('id_fabricant='+id_fabricant+'&id_categorie_produit='+id_categorie_produit+'&id_categorie_equipement='+id_categorie_equipement+'&id_type_equipement='+id_type_equipement);         

}

function infoSearch() {
	document.getElementById("info").style.visibility = "hidden";
}

function formCallbackCommentaire(url_www,url2reload) {
  document.getElementById('ajaxMsg').innerHTML='<img src="'+url_www+'/img/lightbox/loading.gif" border="0" class="noBorder">';
  var id_produit = document.commentaireForm.id_produit.value;
  var id_photo = document.commentaireForm.id_photo.value;
  var id_video = document.commentaireForm.id_video.value;
  var nom_produit = document.commentaireForm.nom_produit.value;
  var id_membre_destinataire = document.commentaireForm.id_membre_destinataire.value;
  var type_commentaire = document.commentaireForm.type_commentaire.value;
  var identifiant = document.commentaireForm.identifiant.value;
  var pwd = document.commentaireForm.pwd.value;
  var commentaire = document.commentaireForm.commentaire.value;
  var url = document.commentaireForm.url.value;
 
  document.commentaireForm.submit.disabled = true;

  var OAjax;
  if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
  else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
  OAjax.open('POST',url_www+"/components/sendCommentaire.php",true);

  OAjax.onreadystatechange = function()
  {
      if (OAjax.readyState == 4 && OAjax.status==200)
      {
            document.commentaireForm.submit.disabled = false;
			document.getElementById('ajaxMsg').innerHTML='<p class="orange bold">'+OAjax.responseText+'</p>';
			//Faire un reload de la page si responseText est VIDE!
			if(OAjax.responseText==''){
				document.location.href=url2reload;
				document.location.reload();
			}				

      }
  }
  OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  OAjax.send('id_produit='+id_produit+'&id_photo='+id_photo+'&id_video='+id_video+'&nom_produit='+nom_produit+'&id_membre_destinataire='+id_membre_destinataire+'&type_commentaire='+type_commentaire+'&identifiant='+identifiant+'&pwd='+pwd+'&commentaire='+commentaire+'&url='+url);         

}

function formCallbackContact(url_www, urlModele) {
  document.getElementById('ajaxCtMsg').innerHTML='<img src="'+url_www+'/img/lightbox/loading.gif" border="0" class="noBorder">';
  var id_sender = document.contactForm.id_sender.value;
  var id_proprio = document.contactForm.id_proprio.value;
  var urlModele = document.contactForm.urlModele.value;  
 
  document.contactForm.submit.disabled = true;

  var OAjax;
  if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
  else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
  OAjax.open('POST',url_www+"/components/sendContact.php",true);

  OAjax.onreadystatechange = function()
  {
      if (OAjax.readyState == 4 && OAjax.status==200)
      {
            document.contactForm.submit.disabled = false;
			document.getElementById('ajaxCtMsg').innerHTML='<p>'+OAjax.responseText+'</p>';
			/*if(OAjax.responseText==''){
				document.getElementById('ajaxCtMsg').innerHTML='<p class="orange bold">Message envoyé</p>';
			}	*/			

      }
  }
  OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  OAjax.send('id_sender='+id_sender+'&id_proprio='+id_proprio+'&urlModele='+urlModele);         

}