
var activeFieldValue;
var modifiedFields = "";

function envoi(typ,val){
/*	if (typ != "connexion")	{
		//document.my_form.submitt.focus();
		//alert(nav_v);
		//if (document.getElementById){
		if (nav_v =="moz"){	
			document.getElementById("submitt").focus;	
		} else {
			//document.my_form.submitt.focus();
		}		
	}*/
	//alert(typ);
    if((typ >= 0 &&  typ < 10) || typ == "arbo_del" ){
        if(confirm("Voulez_vous vraiment effacer cet enregistrement ?")){
            document.my_form.submitt.value=typ;
            document.my_form.submitv.value=val;
            document.my_form.submit();
            //return;
        }
    } else {
    	if (typ == "del_sel") {
         	if(confirm("Voulez_vous vraiment effacer les enregistrements sélectionnés ?")){
            	document.my_form.submitt.value=typ;
            	document.my_form.submitv.value=val;
            	document.my_form.submit();
            	//return;
        	}   
	    } else {
	        if (modifiedFields != "" && typ == "nf" ){
	        	document.my_form.modified_fields.value = modifiedFields;
				if (confirm("Voulez_vous vraiment créer une nouvelle fiche sans enregistrer ?")){
	        		document.my_form.submitt.value=typ;
	        		document.my_form.submitv.value=val;
	   				document.my_form.submit();
					//return true;
	 			} else {
				    //return false
				}
	       } else {
	       		//alert(modifiedFields);
	       		document.my_form.modified_fields.value = modifiedFields;      
	        	document.my_form.submitt.value=typ;
	        	document.my_form.submitv.value=val;
	   			document.my_form.submit();
	        }
	    }
    }
}

function on_leave_page_check(dest){
	if ( modifiedFields != ""){
		if (confirm("Voulez_vous vraiment quitter ce formulaire sans enregistrer ?")){
		    window.open(dest, "_self");
			return false;
		} else {
		    return true;
		}
	} else {
	    window.open(dest, "_self");
		window.focus();
		return false;	
	}
}

function confirm_quit(){		
	if ( modifiedFields != ""){		
		return false;
	} 
}

//a mettre dans la page ?*
//<script Language ="JavaScript">
//var SubmitFlag = false;
//function ConfirmQuit() { 
//	if (SubmitFlag == true) 
//		return; 
//	else   	  
//      return "InformationWeek is FREE to qualified IT professionals.  But you must complete the entire form.  If you are selected, you will receive a FREE subscription (others pay $199 per year).";		 
//} 

//function doSubmit() { 
//SubmitFlag = true; 
//return true; 
//}
//-->
//</script>



function save_close_actualise_opener(val){
	envoi('tbl','all');
	timerID=setTimeout('close_actualise_opener(val)',1000);	
}

function orig_val(obj){
    activeField_value=obj.value;
}

function new_val(obj){
	if ( obj.value != activeFieldValue ) {
	    modifiedFields += obj.name+",";
	    //todo : gerer un modifiedRecs (tbl_name__nb_rec, etc...)
	    //alert(modifiedFields);
	   //alert(obj.style.width);
	   obj.style.backgroundColor  = "#ffd094";
	}
}

function new_radio(obj){
	modifiedFields += obj.name+",";
	//alert(obj2.name);
    var obj2_id = obj.name+"_f"; 
    var obj2f = document.getElementById(obj2_id); 	
	obj2f.style.backgroundColor  = "#ffd094";
}

function new_check3(obj, obj2){
	modifiedFields += obj.name+",";
	//alert(obj2.name);
    var obj2_id = obj2.name+"_f"; 
    var obj2f = document.getElementById(obj2_id); 	
	obj2f.style.backgroundColor  = "#ffd094";
}

function changed(obj){
	modifiedFields += obj.name+",";
	obj.style.backgroundColor  = "#ffd094";
	//alert(modifiedFields);
}

function update_multiple_checks(obj_id, new_val, typeAction) { 
    var value_string = ""; 
    var current_values = "";
    var obj = document.getElementById(obj_id);  	
    if (typeof(obj) == "undefined" || obj.value.indexOf("undefined") > 0) {
    	current_values = "";
    	alert("Indefini");
    } else {   
    	current_values = obj.value; 
    }
    if (typeAction == "add"){
    	if (current_values !== ""){
	    	value_string = current_values + "," + new_val; 	
	    	value_string = value_string.replace(",,",",");
    	} else {
    		value_string = new_val; 
    	}	
    } else {  //typeAction = "remove"
    	if (current_values != "" ){
	    	current_values = current_values.replace(",,",",");
	    	if (current_values.indexOf(",") > 0){
		        var arr_val = eval("Array(" + current_values + ");");
		    	var nb_vals = arr_val.length;	    	
		        for (lop=0; lop < nb_vals; lop++) { 
		        	if (arr_val[lop]!= new_val && arr_val[lop]!= "") {		        	 	
		            	value_string = value_string + arr_val[lop] + ",";
		            } 
		        }		        
		        if(value_string.length > 1) value_string = value_string.slice(0,-1); else value_string = "";
	        } else {
	        	value_string = "";
	        }
	    }	       
    } 	
    obj.value = value_string;
} 

//array 
//arrCalcFields[i]['fieldId']=
//arrCalcFields[i]['field1']=
//arrCalcFields[i]['field2']=
//arrCalcFields[i]['operation']=   "+,-,*,/,%"
/*
var nbCalcFields = arrCalcFields.length;

function recalcFields(fieldId){
	var is2calc = false;
	//parcour arr_calc_fields
	
	//TODO g?rer les id compos?s de field_name."_".id
	for (i=0 ; i < nbCalcFields ; i++){
		if (arrCalcFields[i]['fieldId']==fieldId
		|| arrCalcFields[i]['field1']==fieldId
		|| arrCalcFields[i]['field2']==fieldId){
			is2calc = true;
		}
	
		if (is2calc){
			var obj1 = document.getElementById(arrCalcFields[i]['field1']);
			var obj2 = document.getElementById(arrCalcFields[i]['field2']);
			var newval ;
			switch (arrCalcFields[i]['operation']){
				case "+" :	var newval = obj1.value + obj2.value; break;
				case "*" :	var newval = obj1.value * obj2.value; break;
				case "/" :	var newval = obj1.value / obj2.value; break;
				case "%" :	var newval = obj1.value * obj2.value / 100 ; break;												
			}	
			document.getElementById(arrCalcFields[i]['fieldId']).value = newval;						
		}		
	}
	
} */


function close_actualise_opener(val){
	window.opener.focus(); 
	window.opener.document.my_form.submitt.value='sf';
    window.opener.document.my_form.submitv.value=val;
    window.opener.document.my_form.submit();
	self.close();
}

function input_opener_from_assist(opener_field, val){
	eval('window.opener.document.my_form.'+opener_field+'.value="'+val+'"');
	self.close();
}

function def_val(opener_field, val, opener_item, val_item){
	eval('window.opener.document.my_form.'+opener_field+'.value="'+val+'"');
	eval('window.opener.document.my_form.'+opener_item+'.value="'+val_item+'"');	
	//window.opener.document.my_form.modified_fields.value += opener_field;  
	//self.blur();
	window.opener.focus();
	self.close();
}
function update_field(val){         
            window.opener.focus();            
            window.opener.document.my_form.field.value=val;
            window.opener.document.my_form.submitt.value='sf';
            self.close();     
}  
  
function deconnect(){
            document.my_form.submitt.value="logout";
            document.my_form.submit();    
}

function str2float(strNum){
	var str= strNum.replace(" ","");
	str = str.replace(",",".");
	return parseFloat(str);
}      
function to_euro(){
    var x;
    x=document.my_form.val_fr.value/0.0655957;
    x=Math.round(x);
    document.my_form.val_euro.value=x/100;
}

function to_fr(){
    x=document.my_form.val_euro.value*655.957;
    x=Math.round(x);
    document.my_form.val_fr.value=x/100;
}

function fullwin_popup(url, display_win_name, width, height ){
    var pop_up = window.open(url, display_win_name,'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=yes,status=no' );
    pop_up.focus();
}

popupWins = new Array();
function win_popup(url, name, width, height ) {
	if ( typeof( popupWins[name] ) != "object" ){		
		popupWins[name] = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no,status=no');
	} else {
		if (!popupWins[name].closed){	
		} else {
			popupWins[name] = window.open(url, name,'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no,status=no');
		}
	}
	popupWins[name].focus();
}

function win_pop(url, display_win_name, width, height ){
    var pop_up = window.open(url, display_win_name,'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no,status=no' );
    pop_up.focus();
}
  
function open_win(pop_url){
         var pop_up = window.open(pop_url);                         
         pop_up.focus();    
}  

function popup_validation(val){         
            window.opener.focus();            
            self.close();     
}    

function act_menu(menu_item){
     document.my_form.action_menu.value=menu_item;
     document.my_form.niv.value=menu_item;
     document.my_form.submit();
}

function hide_layer(lay){
	if (document.all) {
		if (lay!="") {document.all[lay].style.visibility="hidden";}
	}
	if (document.layers ) {
	  	if (lay!="") {document.layers[lay].visibility="hide";}
	}
	if (document.getElementById){
		if (lay!="") {document.getElementById(lay).style.visibility="hidden";}	
	}
}
function show_layer(lay){
    if (document.all) {
		if (lay!="") {document.all[lay].style.visibility="visible";}
	}
	if (document.layers ) {
		if (lay!="") {document.layers[lay].visibility="show";}
	}
	if (document.getElementById){
		if (lay!="") {document.getElementById(lay).style.visibility="visible";}	
	}
}

function show_msg (msg){
	alert(msg);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function out_of_frame(){
	if (parent.frames.length < 1){
		document.location.href = '../index.htm';
	}
}

function get_mysql_date(obj){
	var ObjetDate = new Date(); 
//	var JourDeLaSemaine = ObjetDate.getDay() ; 
	//var NomJours = TableJours[JourDeLaSemaine];
	var Jour = ObjetDate.getDate();
	var Mois = ObjetDate.getMonth()+1;
	var Annee = ObjetDate.getFullYear();
//	var Heure = ObjetDate.getHours();
//	var Minute = ObjetDate.getMinutes();
//	var Seconde = ObjetDate.getSeconds();
	var d_day = Jour+"-"+Mois+"-"+Annee;
	obj.value = d_day ;
//	return d_day;

}

function get_mysql_date_time(obj){
	//alert("toto");
	var ObjetDate = new Date(); 
//	var JourDeLaSemaine = ObjetDate.getDay() ; 
	//var NomJours = TableJours[JourDeLaSemaine];
	var Jour = ObjetDate.getDate();
	var Mois = ObjetDate.getMonth()+1;
	var Annee = ObjetDate.getFullYear();
	var Heure = ObjetDate.getHours();
	var Minute = ObjetDate.getMinutes();
	var Seconde = ObjetDate.getSeconds();
	var d_day = Jour+"-"+Mois+"-"+Annee+" "+Heure+":"+Minute+":"+Seconde;
	obj.value = d_day ;	
	return true;
//	return d_day;

}

function date_time_fr_2_en(dfr){
	var den = dfr.substr(6,4)+"-"+dfr.substr(3,2)+"-"+dfr.substr(0,2)+dfr.substr(10,9);
	//alert(den);
	return den;
}

function get_time_interval(field1,field2){
	var debut_fr = eval("document.my_form."+field1+".value");
	var debut_en = date_time_fr_2_en(debut_fr);
	var debut = new Date(debut_en);
	//alert(new Date);
	var fin_fr = eval("document.my_form."+field2+".value");
	var fin_en = date_time_fr_2_en(fin_fr);
	alert(fin_en);
	var fin = new Date(fin_en);
	alert(fin);
	var milli_debut = debut.getTime();
	var milli_fin = fin.getTime();
	var interval_sec = (milli_fin - milli_debut)/1000;
	var interval_min = interval_sec/60;
	return interval_min;
}

function update_interv(fieldfrom, fieldto, thisfield){
	//var interv = get_time_interval(fieldfrom, thisfield);
	//alert(interv);
	//eval("document.my_form."+fieldto+".value = "+interv);
}
