function ActiverChampsNewPwrd(objModifPwrd){
	var objChampPwrd = document.getElementById('idTxtPwrd');
	var objChampPwrd2 = document.getElementById('idTxtPwrd2');
	if (objModifPwrd.checked){
		objChampPwrd.disabled = false;
		objChampPwrd2.disabled = false;
	}else{
		objChampPwrd.disabled = true;
		objChampPwrd2.disabled = true;
	}
}




// FONCTIONS RELATIVES A LA GESTION D'ANENOMETRES
function ModifierAnenometre(){
	var arrArgs = ModifierAnenometre.arguments;
	window.open('scripts/anenometreConfig.php?user='+arrArgs[0]+'&windmeter='+arrArgs[1]+'&new=0','anenometreConfig','width=375,height=575');
	
}
function SupprimerAnenometre(){
	var arrArgs = SupprimerAnenometre.arguments;
	if(confirm("Voulez-vous supprimer cet anénomètre de vos favoris?")){
		AjaxRequest("scripts/ajax.php?method=supprimerAnenometre&user="+arrArgs[0]+"&windmeter="+arrArgs[1],"supprimerAnenometre");
	}
}
function AjouterAnenometre(){
	var arrArgs = AjouterAnenometre.arguments;
	var dropdownIndex = document.getElementById('idSelAneno').selectedIndex;
	var dropdownValue = document.getElementById('idSelAneno')[dropdownIndex].value;
	AjaxRequest("scripts/ajax.php?method=ajouterAnenometre&user="+arrArgs[0]+"&windmeter="+dropdownValue+"&new=1","ajouterAnenometre");
}

function AfficherAiguilleDefaut(arrDir){
	var cpt = 0;
	var arrAiguilleId = new Array("aiN", "aiNNE", "aiNE", "aiENE", "aiE", "aiESE", "aiSE", "aiSSE", "aiS", "aiSSW", "aiSW", "aiWSW", "aiW", "aiWNW", "aiNW", "aiNNW");
	while (cpt < arrDir.length){
		if (arrDir[cpt] == "1"){
			document.getElementById(arrAiguilleId[cpt]).style.display = "inline";
		}
		cpt++;
	}
}

function AfficherAiguille(obj){
	var strObjId = obj.id;
	var strDirection = "ai"+strObjId.substr(2,strObjId.length-2);
	var strCssValue = getStyle(strDirection,'display');
	if (strCssValue == "none"){
		document.getElementById(strDirection).style.display = "inline";
	}else{
		document.getElementById('idSelectAll').checked = false;
		document.getElementById(strDirection).style.display = "none";
	}
}

function AnnulerConfig(){
	if(confirm("Voulez-vous quitter la configuration de l'anénomètre sans enregistrer?")){
		window.location.href = "account.anenometre.php";
	}
}

function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function InverserSelection(){
	if (document.frmConfigAneno.selectAll.checked == true){
		SelectAllAiguille();
	}else{
		UnselectAllAiguille();
	}
}

function SelectAllAiguille(){
	var cpt = 0;
	var arrAiguilleId = new Array("aiN", "aiNNE", "aiNE", "aiENE", "aiE", "aiESE", "aiSE", "aiSSE", "aiS", "aiSSW", "aiSW", "aiWSW", "aiW", "aiWNW", "aiNW", "aiNNW");
	var arrCheckboxId = new Array("idN", "idNNE", "idNE", "idENE", "idE", "idESE", "idSE", "idSSE", "idS", "idSSW", "idSW", "idWSW", "idW", "idWNW", "idNW", "idNNW");
	while (cpt < arrAiguilleId.length){
		document.getElementById(arrAiguilleId[cpt]).style.display = "inline";
		document.getElementById(arrCheckboxId[cpt]).checked = true;
		cpt++;
	}
}

function UnselectAllAiguille(){
	var cpt = 0;
	var arrAiguilleId = new Array("aiN", "aiNNE", "aiNE", "aiENE", "aiE", "aiESE", "aiSE", "aiSSE", "aiS", "aiSSW", "aiSW", "aiWSW", "aiW", "aiWNW", "aiNW", "aiNNW");
	var arrCheckboxId = new Array("idN", "idNNE", "idNE", "idENE", "idE", "idESE", "idSE", "idSSE", "idS", "idSSW", "idSW", "idWSW", "idW", "idWNW", "idNW", "idNNW");
	while (cpt < arrAiguilleId.length){
		document.getElementById(arrAiguilleId[cpt]).style.display = "none";
		document.getElementById(arrCheckboxId[cpt]).checked = false;
		cpt++;
	}
}

function FermerPopup(){
	var arrArgs = FermerPopup.arguments;
	if (arrArgs[1] == "prompt"){
		if(confirm("Voulez-vous quitter la configuration de l'anénomètre sans enregistrer?")){
			if (arrArgs[2] == "1"){
				AjaxRequest("ajax.php?method=supprimerAnenometreNew&user="+arrArgs[3]+"&windmeter="+arrArgs[4],"supprimerAnenometreNew");
			}else{
				window.close(arrArgs[0]);
				window.opener.location.href = window.opener.location.href;
			}
		}
	}else{
		window.close(arrArgs[0]);
		window.opener.location.href = window.opener.location.href;
	}
}

function AjaxRequest() {
	var arrArgs = AjaxRequest.arguments;
    var httpRequest = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
            // Voir la note ci-dessous à propos de cette ligne
        }
    }
    else if (window.ActiveXObject) { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {}
        }
    }
    if (!httpRequest) {
        alert('Abandon :( Impossible de cr&eacute;er une instance XMLHTTP');
        return false;
    }
    httpRequest.onreadystatechange = function() { AjaxContents(httpRequest,arrArgs[1]); };
    httpRequest.open('GET', arrArgs[0], true);
    httpRequest.send(null);

}

function AjaxContents(httpRequest,action) {
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            //alert(httpRequest.responseText);
            switch(action){
            	case "supprimerAnenometre":
            		window.location.reload();
            		break;
            	case "supprimerAnenometreNew":
            		window.close('anenometreConfig');
					window.opener.location.href = window.opener.location.href;
            		break;
            	case "ajouterAnenometre":
            		var strReponse = httpRequest.responseText;
            		var arrReponse = strReponse.split("_");
            		window.open('scripts/anenometreConfig.php?user='+arrReponse[0]+'&windmeter='+arrReponse[1]+'&new=1','anenometreConfig','width=375,height=575');
            		break;
            }
        } else {
            alert('Un problème est survenu avec la requête.');
        }
    }
}
