function tri (nb) {
	document.getElementById('tri').value = nb;
	document.getElementById('formulaire').submit();
}

function dotodo(koi, valeur) {
	document.getElementById('todo').value = koi;
	document.getElementById('valeur').value = valeur;
	document.getElementById('formulaire').submit();
}

function exportCSV() {
	document.getElementById('exportCSV').value = 1;
	document.getElementById('formulaire').submit();
}

function exportXLS() {
	document.getElementById('exportXLS').value = 1;
	document.getElementById('formulaire').submit();
}

function exportTXT() {
	document.getElementById('exportTXT').value = 1;
	document.getElementById('formulaire').submit();
}

// verifie un champ date au format jj/mm/aa
function isDate(d) {
	if (d.length != 8) return false;
	if (!isNum(d.substring(0,2))) return false;
	if (!isNum(d.substring(3,5))) return false;
	if (!isNum(d.substring(6,8))) return false;
	if (d.substring(2,3) != '/') return false;
	if (d.substring(5,6) != '/') return false;
	return true;
}

// verifie un champ date au format jjmmaa
function isShortDate(d) {
	if (d.length != 6) return false;
	if (!isNum(d.substring(0,6))) return false;
	return true;
}

// verifie un champ heure au format hh:mm
function isHeure(d) {
	if (d.length != 5) return false;
	if (!isNum(d.substring(0,2))) return false;
	if (!isNum(d.substring(3,5))) return false;
	if (d.substring(2,3) != ':') return false;
	return true;
}

// verifie un champ heure au format hhmm
function isShortHeure(d) {
	if (d.length != 4) return false;
	if (!isNum(d.substring(0,4))) return false;
	return true;
}


// verifie qu'un champ est est entier
function isNum(passedVal) {
      	if (passedVal == '') {
 	     return false;
      	}
      	for (i=0; i<passedVal.length; i++) {
      		if (passedVal.charAt(i) < '0') {
            		return false;
            	}
	       	if (passedVal.charAt(i) > '9') {
 		        	return false;
    	 	}
   		}
      return true;
}

// verifie qu'un champ est est reel
function isFloat(passedVal) {
      	if (passedVal == '') {
 	     return false;
      	}
      	for (i=0; i<passedVal.length; i++) {
      		if (passedVal.charAt(i) == '.') continue;
      		if (passedVal.charAt(i) < '0') {
            		return false;
            	}
	       	if (passedVal.charAt(i) > '9') {
 		        	return false;
    	 	}
   		}
      return true;
}

function reformatDate(objet) {
	if (isShortDate(objet.value)) {
		d = objet.value;
		objet.value = d.substring(0,2) + "/" + d.substring(2,4) + "/" + d.substring(4,6);  
	}
}

function verifierDate(objet) {
	reformatDate(objet);
	if (objet.value.length != 0 && !isDate(objet.value)) {
		alert(' Date invalide ! (JJMMAA ou JJ/MM/AA)');
	}
}

function reformatHeure(objet) {
	if (isShortHeure(objet.value)) {
		d = objet.value;
		objet.value = d.substring(0,2) + ":" + d.substring(2,4);  
	}
}

function verifierHeure(objet) {
	reformatHeure(objet);
	if (objet.value.length != 0 && !isHeure(objet.value)) {
		alert(' Heure invalide ! (HHMM ou HH:MM)');
	}
}

function verifierNum(objet) {
	if (objet.value.length != 0 && !isNum(objet.value)) {
		alert(' Nombre invalide !');
	}
}

function verifierFloat(objet) {
	if (objet.value.length != 0 && !isFloat(objet.value)) {
		alert(' Nombre invalide !');
	}
}

function listeClic() {
	var currentcpt = document.forms["PTOP"].elements['file'].selectedIndex;
	var tmp = document.forms["PTOP"].elements['file'].options[currentcpt].value;
	parent.frames["selectionSuccess.php"].window.location="selection?file=" + tmp + "&currentcpt=" + currentcpt;
	parent.frames["pdfSuccess.php"].window.location="pdf";
	parent.frames["affichageOtSuccess.php"].window.location="affichageOt";
}

function prevClic() {
	var tmp = -1;
	parent.frames["selectionSuccess.php"].window.location="selection?pn=" + tmp;
	parent.frames["pdfSuccess.php"].window.location="pdf";
	parent.frames["affichageOtSuccess.php"].window.location="affichageOt";
}
		
function nextClic() {
	var tmp = 1;
	parent.frames["selectionSuccess.php"].window.location="selection?pn=" + tmp;
	parent.frames["pdfSuccess.php"].window.location="pdf";
	parent.frames["affichageOtSuccess.php"].window.location="affichageOt";
}  		
		 		
function deleteClic() {

 		if (confirm("Suppression du fichier")) {
 			parent.frames["selectionSuccess.php"].window.location="selection?act=Supprimer";
		parent.frames["pdfSuccess.php"].window.location="pdf";
		parent.frames["affichageOtSuccess.php"].window.location="affichageOt";	  			
 		}  		
}
	  	
function oldClic() {
 		if (confirm("Transfert du fichier vers l'ancien systeme ?")) {
 			parent.frames["selectionSuccess.php"].window.location="selection?act=Old";
		parent.frames["pdfSuccess.php"].window.location="pdf";
		parent.frames["affichageOtSuccess.php"].window.location="affichageOt";	  			
 		}   				
}
 	
function waitClic() {
			parent.frames["selectionSuccess.php"].window.location="selection?act=Attente";
	parent.frames["pdfSuccess.php"].window.location="pdf";
	parent.frames["affichageOtSuccess.php"].window.location="affichageOt";
}
		
function checkboxClic(chk) {
	if (chk.checked) {	
		parent.frames["selectionSuccess.php"].window.location="selection?mode=attente";
	} else {
		parent.frames["selectionSuccess.php"].window.location="selection?mode=traitement";
	}
		parent.frames["pdfSuccess.php"].window.location="pdf";
	parent.frames["affichageOtSuccess.php"].window.location="affichageOt";
}	


function getDate(strDate){	  
    day = strDate.substring(0,2);
	month = strDate.substring(3,5);
	year = strDate.substring(6,10);
	d = new Date();
	d.setDate(day);
	d.setMonth(month);
	d.setFullYear(year); 
	return d;  
}
  
function convertDateEng(strDate) {
    var day = strDate.substring(0,2);
	var month = strDate.substring(3,5);
	var year = strDate.substring(6,10);

	return month+"/"+day+"/"+year;	  
}


function adjustDate(limit) {
 	var obj = document.getElementById("dateE");
 	var obj2 = document.getElementById("dateS"); 
 	var end = Date.parse(convertDateEng(obj.value));
 	var start = Date.parse(convertDateEng(obj2.value));
	var d = start + (3600000*24*limit); //(3600000*24*30);
	if ( end < start) {
			obj.value= obj2.value;
			return;
	} 
	if (d < end) {
		//alert(start+ "|" + d + "|" + end);
		var datE = new Date();
		datE.setTime(d);
		var dd = datE.getDate();
		var mm = datE.getMonth() + 1;
		var yyyy = datE.getFullYear();
		if (mm < 10)
			mm = "0" + mm;
		
		if (dd < 10)
			dd = "0" + dd;
			
		var result = dd + "/" + mm + "/" + yyyy;
		obj.value = result;
	}	 
}
