function resultat(){
	alert("pas de r\351sultat");
}

function mask(champs,type){
	var long = champs.value;
	long.toString();
	
	switch (type){
		case 'hour':
	   	if(long.length==1){
			if(champs.value>2){
				champs.value = "0"+long;
			 	champs.value = champs.value + ":";
		  	}
	   	}
	    if(long.length==2){
			if(champs.value<=23){
		  		champs.value = long + ":";
		  	}
			else{
				alert("Veuillez entrer une heure valide");
				champs.value ="";
			}
	    }
	    if(long.length==5){
			long2 = long.slice(3,5);
			//alert(long2);
			if(long2 > 60){
				alert("Le nombre de minute n'est pas valide");
			 	champs.value = long.slice(0,3);
			}
	    }
		
	    break;
		
	    case 'date':
		if(long.length==1){
			if(champs.value>3){
				champs.value = "0"+long;
				champs.value = champs.value + "/";
			}
		}
		if(long.length==2){
			if(champs.value<=31){
				champs.value = champs.value + "/";
			}
			else{
				alert("Veuillez entrer une heure valide");
				champs.value ="";
			}
		}
		if(long.length==4){
			car = long.slice(3,6);
			if(car>1){
				car2 = long.slice(0,3);  
				champs.value = car2+"0"+car;
				champs.value = champs.value + "/";
			}
		}
		if(long.length==5){
			car = long.slice(4,6)
			if(car<=31){
				champs.value = champs.value + "/";
			}
			else{
				alert("Veuillez entrer une heure valide");
				champs.value ="";
			}
		}
	}
}

function submitform(form){
	document.getElementById(form).submit() ;
}

function form_submit(cha,fid,sfor){
	//	alert (fid);
	//	return ;
	var field = document.getElementById(cha);
	var formulaire = document.getElementById(sfor);
	field.value = fid ;
	formulaire.submit();
}

function departement_mod(id){
	document.getElementById('tr_'+id).style.display = 'none';
	document.getElementById('tr_'+id+'_2').style.display = 'block';
}

function mailing_text(){
	alert(document.getElementById('info_text').value);
}

function check_all(){
	{
		count = document.frm.elements.length;
		for (i=0; i < count; i++) 
		{
			if(document.frm.elements[i].checked == 1)
		    	{document.frm.elements[i].checked = 0;
			}
		    else {document.frm.elements[i].checked = 1;
			}
		}
	}
}

function openConfirmDel(form,id,field,phrase){
	Dialog.confirm(phrase, 
	{
		width:300,
		okLabel: "Oui",
		cancelLabel: "Non",
		className: "alphacube",
		id: "myDialogId",
		cancel:function(win) {return false;},
		ok:function(win) {form_submit(field,id,form);; return true;}
	});
}
	
function openConfirmYes(form,id,field,phrase){
	Dialog.confirm(phrase, 
	{
		width:300,
		okLabel: "Oui",
		cancelLabel: "Non",
		className: "alphacube2",
		id: "myDialogId",
		cancel:function(win) {return false;},
		ok:function(win) {form_submit(field,id,form);; return true;}
	});				   
}

function alerte(phrase){
	Dialog.alert(phrase, 
	{
		width:300,
		okLabel: "ok", 
		className:  "alphacube",
		ok:function(win) {debug("validate alert panel"); return true;}
	});
}

function messagerie_public_page(){
	var page = $('pages').value 
	var page = page -1 ;
	window.location="index.php?p=mur&action=list&page=" + page ;	
}

function temoignage_public_page(type){
	var page = $('pages').value 
	var page = page -1 ;
	window.location="index.php?p=temoignage&action="+type+"&page=" + page ;	
}

function checkbox_checked(name){
	$(name).checked = true ;
}

function form_coaching(people,coaching){
	$('coachingid').value = coaching ;
	$('societeid').value = people ;
	$('coachingfrm').submit();
}

function form_delete_coaching(coaching_date){
	$('date_id'). value = coaching_date ;
	$('datedeletefrm').submit();
}

function calcul_tot_gen(name,tot){
	var total = 0 ;
	var max = $('max').value ;
	for(i=0;i<max;i++){
		if(name+i){
			pro = $(name+i).value * 1.0 ;
			total = total + pro ;
		}	
	}
	$(tot).innerHTML = total ;
}

function add_row_coaching(){
	
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	if(day<10){
		day = '0'+day;
	}
	
	var year = currentTime.getFullYear()
	var today = day+'-'+month+'-'+year ;
	
	var t = $('tbl');
	var r = document.createElement('tr');
	var ca = document.createElement('td');
	var cb = document.createElement('td');
	var cc = document.createElement('td');
	var cd = document.createElement('td');
	var ce = document.createElement('td');
	var cf = document.createElement('td');
	var cg = document.createElement('td');
	var ch = document.createElement('td');
	
	var ta = document.createElement('input');
	var tb = document.createElement('input');
	var tc = document.createElement('input');
	var td = document.createElement('input');
	var te = document.createElement('input');
	var tf = document.createElement('input');
	var tg = document.createElement('input');
	var th = document.createElement('input');
	
	ta.name = 'date_'+__ui ;
	ta.id = 'date_'+__ui ; 
	ta.value =today;
	ta.size=10 ;
	
	tb.name='fld1_'+ __ui ; 
	tb.id = 'fld1_'+ __ui ;
	tb.size = 6 ;
	tb.value = 0 ;
	tb.setAttribute("onChange","total_coaching("+__ui+")");
	
	tc.name='fld2_'+ __ui ; 
	tc.id = 'fld2_'+ __ui ;
	tc.size = 6 ;
	tc.value = 0 ;
	tc.setAttribute("onChange","total_coaching("+__ui+")");
	
	td.name='fld3_'+ __ui ; 
	td.id = 'fld3_'+ __ui ;
	td.size = 6 ;
	td.value = 0 ;
	td.setAttribute("onChange","total_coaching("+__ui+")");
	te.name='fld4_'+ __ui ; 
	te.id = 'fld4_'+ __ui ;
	te.size = 6 ;
	te.value = 0 ;
	te.setAttribute("onChange","total_coaching("+__ui+")");
	
	tf.name='fld5_'+ __ui ; 
	tf.id = 'fld5_'+ __ui ;
	tf.size = 6 ;
	tf.value = 0 ;

	tg.name='fld6_'+ __ui ; 
	tg.id = 'fld6_'+ __ui ;
	tg.size = 6 ;
	tg.value = 0 ;
	tg.setAttribute("class","grey2");
	tg.setAttribute("style","padding-left:10px; color:#C30; cursor:default; font-weight:bold;");
	
	th.hname='fld7_'+ __ui ; 
	th.id = 'fld7_'+ __ui ;
	th.size = 6 ;
	
	ca.appendChild(ta);
	cb.appendChild(tb);
	cc.appendChild(tc);
	cd.appendChild(td);
	ce.appendChild(te);
	cf.appendChild(tf);
	cg.appendChild(tg);
	
	r.appendChild(ca);
	r.appendChild(cb);
	r.appendChild(cc);
	r.appendChild(cd);
	r.appendChild(ce);
	r.appendChild(cf);
	r.appendChild(cg);
	
	t.appendChild(r);
	
	__ui++ ;	
}

function total_coaching(id){
	
	var fld1 = $('fld1_'+id).value ;
	fld1 =fld1.replace(',','.');
	
	var fld2 = $('fld2_'+id).value ;
	fld2 = fld2.replace(',','.');
	
	var fld3 = $('fld3_'+id).value ;
	fld3= fld3.replace(',','.');
	
	
	var fld4 = $('fld4_'+id).value ;
	fld4 = fld4.replace(',','.');
	
	
	//$('fld6_'+id).value = ($('fld1_'+id).value*1.0) + ($('fld2_'+id).value*1.0) + ($('fld3_'+id).value*1.0) + ($('fld4_'+id).value*1.0);
	var fld6 = fld1*1.0 + fld2*1.0 + fld3*1.0+ fld4*1.0;
	$('fld6_'+id).value = fld6 ;
	
	
	
}

function verify_herbaid(){
	var id = $('herbaid').value ;
	
	new Ajax.Request('ajax/stock.php?p=14&societe='+id ,
			  {
			    method:'get',
			    onSuccess: function(xhr){
				var response = xhr.responseText ;
				
				if(response=='true'){
					$('btnok').disabled=false ;
				}
				
				
	},
	onFailure: function(){ alert('Something went wrong...') }
	});
}
function add_user_album(societe,album){
	var val = $('soc_'+societe).checked ;
	//alert(val);
	new Ajax.Request('ajax/stock.php?p=20&societe='+societe+'&album='+album+'&val='+val,
			 {
			    method:'get',
			    onSuccess: function(xhr){
				var response = xhr.responseText ;
				//alert(response);
		},
		onFailure: function(){ alert('Something went wrong...') }
		});
	
}

function add_share_album(societe,album){
	var val = $('socsh_'+societe).checked ;
	//alert(val);
	
	new Ajax.Request('ajax/stock.php?p=22&societe='+societe+'&album='+album+'&val='+val,
			 {
			    method:'get',
			    onSuccess: function(xhr){
				var response = xhr.responseText ;
				//alert(response);
		},
		onFailure: function(){ alert('Something went wrong...') }
		});
	
}

function ask_for_album(album,user,distri){
	new Ajax.Request('ajax/stock.php?p=21&societe='+user+'&album='+album+'&distri='+distri,
			 {
			    method:'get',
			    onSuccess: function(xhr){
				var response = xhr.responseText ;
				
				alert('Votre demande a \351t\351 envoy\351e \340 votre sponsor');
		},
		onFailure: function(){ alert('Something went wrong...') }
		});
}

function check_domaine(type){
	$('error').style.display='none';
	$('valid').style.display='none';
	var domaine = $('domaine').value ;
	//var dom = domaine.split('.');
	switch (type){
	case 'act':
			var car= detect(domaine);
			if(car == true){
				new Ajax.Request('ajax/stock.php?p=24&domaine='+domaine+'&type=activite',
						 {
						    method:'get',
						    onSuccess: function(xhr){
							var response = xhr.responseText ;
							//alert(response);
							if(response=='NOK'){
								//alert('Ce domaine existe d\351j\340');
								$('error').style.display='block';
							} else {
								$('valid').style.display='block';
							}
					},
					onFailure: function(){ alert('Something went wrong...') }
					});
				
			} else {
				alert('Caract\350re interdis') ;	
			}
		
		break ;
	case 'prod':
		var car= detect(domaine);
		if(car == true){
			new Ajax.Request('ajax/stock.php?p=24&domaine='+domaine+'&type=produit',
					 {
					    method:'get',
					    onSuccess: function(xhr){
						var response = xhr.responseText ;
						//alert(response);
						if(response=='NOK'){
							//alert('Ce domaine existe d\351j\340');
							$('error').style.display='block';
						} else {
							$('valid').style.display='block';
						}
				},
				onFailure: function(){ alert('Something went wrong...') }
				});
			
		} else {
			alert('Caract\350re interdis') ;	
		}
		break ;
	}
	
	//alert(dom[1]);
}

function detect(chaine) {
	result = true ;
	if ( /[^A-Za-z\d]/.test(chaine)) {
        //alert("Please enter only letter and numeric characters");
        //document.formname.txt.focus();
       result = false
    }
	
	return result ;

}

function goUrl(url) {
	url =$(url).value ;
	location=url ;
}
