// JavaScript Document

function SwitchDiv(ParamDiv){
	EtatDisplay = document.getElementById(ParamDiv).style.display;
	if(EtatDisplay=="none" || EtatDisplay==null || EtatDisplay==""){
		document.getElementById(ParamDiv).style.display = "block";
	}else{
		document.getElementById(ParamDiv).style.display = "none";
	}
}
function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	if (strType=="console") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth+",left=0,top=0";
	window.open(strURL, '', strOptions);
}
function supprimerProduit(id_produit){
	var val_groupe = confirm("Voulez vous definitivement supprimer ce produit ?");
	if (val_groupe == true){
	window.location = "gerer-formulaires.php?action=supprimer_produit&id="+id_produit+"";
	}
}

function supprImg(id_photo){
	document.formAjout.idPhotoSup.value += id_photo;
	par = document.getElementById("images"); 
	enf = document.getElementById("imgUpl"); 
	par.removeChild(enf);
}

function supprFiche(id_fiche){
	var valider = confirm("Pour supprimer definitivement le fichier il faudra ensuite cliquez sur le bouton \"Modifier\" !");
	if(valider){
		var li = 'li-'+id_fiche;
		var form = document.getElementById('formAjout');
		var input = document.createElement('input'); //Input contenant la categorie du fichier
		input.setAttribute('type', 'hidden');
		input.name = 'idFichesSup[]';	
		input.value = id_fiche; 
		form.appendChild(input);
		
		par = document.getElementById("fiches"); 
		enf = document.getElementById(li); 
		par.removeChild(enf);
	}
}

function checkAll(){
	var form = document.getElementById("formActivation");
	var checkbox = form.getElementsByTagName("input");
	for(i=0;i<checkbox.length;i++){
		var id_test=checkbox[i].id;
		if(id_test !="th_checkbox"){
			if(checkbox[i].checked==true){
					checkbox[i].checked=false;
			}else{
				checkbox[i].checked=true;
			}
		}
	}
}
	
function activerProduits(msg,actif){
	var val_groupe = confirm("Voulez vous mettre "+msg+" tous les produits selectionnés ?");
	document.formActivation.actif.value = actif;
	if (val_groupe == true){
		document.forms['formActivation'].submit();
	}
}

function ajouterFicheExistante(id_fiche,nom){
		var form = document.getElementById('formAjout');
		var input = document.createElement('input'); //Input contenant la categorie du fichier
		input.setAttribute('type', 'hidden');
		input.name = 'idFichesEx[]';	
		input.value = id_fiche; 
		form.appendChild(input);
		var ul = document.getElementById("fiches");
		var li = document.createElement('li');
		var texte_li = document.createTextNode(nom);
		li.appendChild(texte_li);
		ul.appendChild(li);
}

function sendData(data, page, method,loc)
{
	
    if(document.all)
    {
        //Internet Explorer
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
    }//fin if
    else
    {
        //Mozilla
        var XhrObj = new XMLHttpRequest();
    }//fin else
    
    //définition de l'endroit d'affichage:
    var content = document.getElementById(loc);
    
    //si on envoie par la méthode GET:
    if(method == "GET")
    {
        if(data == 'null')
        {
            //Ouverture du fichier sélectionné:
            XhrObj.open("GET", page);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data);
        }//fin else
    }//fin if
    else if(method == "POST")
    {
        //Ouverture du fichier en methode POST
        XhrObj.open("POST", page);
    }//fin elseif

    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
        if (XhrObj.readyState == 4 && XhrObj.status == 200)
            content.innerHTML = XhrObj.responseText ;			
    }    

    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
	
}//fin fonction SendData 

//fonction sendData sans affichage pour le login
function sendData_log(data, page, method)
{	
    if(document.all)
    {
        //Internet Explorer
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
    }//fin if
    else
    {
        //Mozilla
        var XhrObj = new XMLHttpRequest();
    }//fin else
   
    //si on envoie par la méthode GET:
    if(method == "GET")
    {
        if(data == 'null')
        {
            //Ouverture du fichier sélectionné:
            XhrObj.open("GET", page);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data);
        }//fin else
    }//fin if
    else if(method == "POST")
    {  //Ouverture du fichier en methode POST
        XhrObj.open("POST", page);
    }//fin elseif

    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
        if (XhrObj.readyState == 4 && XhrObj.status == 200)
            return XhrObj.responseText;
    }    

    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
	
}//fin fonction SendData 