function isValidExtention(filename, validExtentions)
{
 var valid = false;
 for(i = 0;i < validExtentions.length;i++)
 {
 		if(filename == validExtentions[i])
			
			valid = true;
 }
	return valid;

}
function case_rouge(ID)
{
document.getElementById(ID).style.backgroundColor='#F7AFB6';
}
function case_blanche(ID)
{
document.getElementById(ID).style.backgroundColor='#FFFFFF';
}
function case_grise(ID)
{
document.getElementById(ID).style.backgroundColor='#EDEDED';
}
function popupcentree(page,largeur,hauteur,options)
{
	var top= 40 ///(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2; 	
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options).focus();

}
function isEmpty(str) {
  if (str==null || str=="")
    return true;
  return false;
}
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}
function details(id)
{
var mt = document.getElementById(id);
if(mt.style.display=='none') {
		mt.style.display='block';
		document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn2_over.jpg';
		document.getElementById('detail2').src = 'images_ars_slsj/btn6.jpg';	
}
else{
	mt.style.display='none';
 document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn2.jpg';	
}
}
function details2(id)
{
var mt = document.getElementById(id);
if(mt.style.display=='none') {
		mt.style.display='block';
		document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn6_over.jpg';
		document.getElementById('detail1').src = 'images_ars_slsj/btn2.jpg';	
}
else{
	mt.style.display='none';
 document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn6.jpg';	
}
}
function details_on(id)
{
var mt = document.getElementById(id);
 mt.style.display='block';
}
function details_off(id)
{
var mt = document.getElementById(id);
 mt.style.display='none';
}
function image_on2(id)
{
document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn2_over.jpg';
}
function image_off2(id)
{
document.getElementById('detail'+id.substr(0,1)).src = 'images_ars_slsj/btn2.jpg';
}
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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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 valid_document(){
	var $msg='';
	case_blanche('Titre_document');
	case_blanche('Photo1');
	case_blanche('Date1');
	case_blanche('box_rub_id2');
	case_blanche('box_rub_id6');
	case_blanche('box_rub_id7');
	if(isEmpty(document.form1.Titre_document.value))
	{
		$msg+="-> Le titre du document\n";
		case_rouge('Titre_document');
    }
	var validExtention1 = new Array(".doc",".pdf",".jpg",".gif","jpeg",".jpe",".xls",".zip",".pps",".ppt",".txt",".wmn");
	var validExtention2 = new Array(".jpg",".gif","jpeg",".jpe");	
	var extention1 = document.form1.Photo1.value.slice(-4);
	if(!isEmpty(document.form1.Photo1.value))
	{
		if(!isValidExtention(extention1,validExtention1))
		{
			$msg+="-> Le document doit être de format: ( jpg, jpe, jpeg, gif, txt, ppt, pps, zip, xls, wmn, doc, pdf ) \n";
			case_rouge('Photo1');
		}
	
	}		
	if(isEmpty(document.form1.Photo1.value))
	{
		$msg+="-> Le fichier à télécharger\n";
		case_rouge('Photo1');
	}
	
	if(isEmpty(document.form1.Date1.value))
	{
		$msg+="-> La date du document\n";
		case_rouge('Date1');
	}
	
	if((document.form1.Id2.checked==true))
	{
	  if((document.form1.Rub_id2.value=='---')){
		$msg+="-> Le choix de la rubrique Accueil (Horaires)\n";
		case_rouge('box_rub_id2');
		}
	}
		if((document.form1.Id6.checked==true))
	{
	  if((document.form1.Rub_id6.value=='---')){
		$msg+="-> Le choix de la rubrique Documents\n";
		case_rouge('box_rub_id6');
		}
	}
			if((document.form1.Id7.checked==true))
	{
	  if((document.form1.Rub_id7.value=='---')){
		$msg+="-> Le choix de la rubrique Techniques\n";
		case_rouge('box_rub_id7');
		}
	}
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}
function valid_document2(){
	var $msg='';
	case_blanche('Titre_document');
	case_blanche('Date1');
	case_blanche('box_rub_id2');
	case_blanche('box_rub_id6');
	case_blanche('box_rub_id7');
	case_blanche('Photo1');
	if(isEmpty(document.form1.Titre_document.value))
	{
		$msg+="-> Le titre du document\n";
		case_rouge('Titre_document');
    }
	var validExtention1 = new Array(".doc",".pdf",".jpg",".gif","jpeg",".jpe",".xls",".zip",".pps",".ppt",".txt",".wmn");
	var validExtention2 = new Array(".jpg",".gif","jpeg",".jpe");	
	var extention1 = document.form1.Photo1.value.slice(-4);
	if(!isEmpty(document.form1.Photo1.value))
	{
		if(!isValidExtention(extention1,validExtention1))
		{
			$msg+="-> Le document doit être de format: (jpg,jpe,jpeg,gif,txt,ppt,pps,zip,xls,wmn,doc,pdf) \n";
			case_rouge('Photo1');
		}
	
	}
	if(isEmpty(document.form1.Date1.value))
	{
		$msg+="-> La date du document\n";
		case_rouge('Date1');
	}
	
	if((document.form1.Id2.checked==true))
	{
	  if((document.form1.Rub_id2.value=='---')){
		$msg+="-> Le choix de la rubrique Accueil (Horaires)\n";
		case_rouge('box_rub_id2');
		}
	}
		if((document.form1.Id6.checked==true))
	{
	  if((document.form1.Rub_id6.value=='---')){
		$msg+="-> Le choix de la rubrique Documents\n";
		case_rouge('box_rub_id6');
		}
	}
			if((document.form1.Id7.checked==true))
	{
	  if((document.form1.Rub_id7.value=='---')){
		$msg+="-> Le choix de la rubrique Techniques\n";
		case_rouge('box_rub_id7');
		}
	}
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}

function valid_texte(){
	var $msg='';
	case_blanche('Titre');
	case_blanche('Date1');
	case_blanche('Texte_en');
	case_blanche('Photo1');
	if(isEmpty(document.form1.Titre.value))
	{
		$msg+="-> Le titre\n";
		case_rouge('Titre');
    }
	var validExtention1 = new Array(".doc",".pdf",".jpg",".gif","jpeg",".jpe",".xls",".zip",".pps",".ppt",".txt",".wmn");
	var validExtention2 = new Array(".jpg",".gif","jpeg",".jpe");	
	var extention1 = document.form1.Photo1.value.slice(-4);
	if(!isEmpty(document.form1.Photo1.value))
	{
		if(!isValidExtention(extention1,validExtention2))
		{
			$msg+="-> La photographie doit être de format: ( jpg, jpe, jpeg, gif ) \n";
			case_rouge('Photo1');
		}
	
	}
	if(isEmpty(document.form1.Date1.value))
	{
		$msg+="-> La date\n";
		case_rouge('Date1');
	}
	if(isEmpty(document.form1.Texte_en.value))
	{
		$msg+="-> Le texte\n";
		case_rouge('Texte_en');
	}
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}


function AddTextE(startTag,defaultText,endTag) 
{
   with(document.form1)
   {
      if (Texte_en.createTextRange) 
      {
         var text;
         Texte_en.focus(Texte_en.caretPos);
         Texte_en.caretPos = document.selection.createRange().duplicate();
         if(Texte_en.caretPos.text.length>0)
         {
            //gère les espace de fin de sélection. Un double-click sélectionne le mot
            //+ un espace qu'on ne souhaite pas forcément...
            var sel = Texte_en.caretPos.text;
            var fin = '';
            while(sel.substring(sel.length-1, sel.length)==' ')
            {
               sel = sel.substring(0, sel.length-1)
               fin += ' ';
            }
            Texte_en.caretPos.text = startTag + sel + endTag + fin;
         }
         else
            Texte_en.caretPos.text = startTag+defaultText+endTag;
      }
      else Texte_en.value += startTag+defaultText+endTag;
   }
}
function popupcentree(page,largeur,hauteur,options)
{
var top=(screen.height-hauteur)/2;
var left=(screen.width-largeur)/2;
window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
function insertcode(type,var3,var1,var2) {
   with(document.form1)
   {
     if(var1 != null){
      if(var2 == null){ var2='  '; }

	switch(type) {
		case 'link':
			code = '<a href="' +var1+ '" target=_blank>' +var2+ '</a>';
			break;
	   case 'mail':
			code = '<a href="' +var1+ '">' +var2+ '</a>';
			break;
		default:
	}
        	code = ' ' + code + ' ';

	switch(var3) {
		case 'Texte_fr':
			Texte_fr.value +=code;
			break;
		case 'Texte_en':
			Texte_en.value +=code;
			break;
		case 'Autre_fr':
			Autre_fr.value +=code;
			break;
		case 'Autre_en':
			Autre_en.value +=code;
			break;
	}
   }
            
      }
	}
function valid_match(){
	var $msg='';
	case_blanche('Nomatch');
	case_blanche('Equipe1');
	case_blanche('Equipe2');
	if(isEmpty(document.form1.Nomatch.value))
	{
		$msg+="-> Le numéro de la partie\n";
		case_rouge('Nomatch');
    }
	//var validExtention1 = new Array(".doc",".pdf",".jpg",".gif","jpeg",".jpe",".xls",".zip",".pps",".ppt",".txt",".wmn");
	//var validExtention2 = new Array(".jpg",".gif","jpeg",".jpe");	
	//var extention1 = document.form1.Photo1.value.slice(-4);
	
	if(document.form1.Equipe1.value==document.form1.Equipe2.value)
	{
			$msg+="-> Deux équipes différentes dans cette catégorie\n";
			case_rouge('Equipe1');
			case_rouge('Equipe2');
	}
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}	

function valid_carton(){
	var $msg='';
	case_blanche('Id_joueur');
	case_blanche('Nb_jaune');
	case_blanche('Nb_rouge');
	if(isEmpty(document.form1.Id_joueur.value))
	{
		$msg+="-> Le joueur à sanctionner\n";
		case_rouge('Id_joueur');
    }
	
	if(document.form1.Nb_jaune.value==0 && document.form1.Nb_rouge.value==0)
	{
			$msg+="-> Combien de carton jaune ou rouge\n";
			case_rouge('Nb_jaune');
			case_rouge('Nb_rouge');
	}
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}

function valid_joueur(){
	var $msg='';
	case_blanche('Nomjoueur');
	case_blanche('Nochandail');
	case_blanche('Tel');
	if(isEmpty(document.form1.Nomjoueur.value))
	{
		$msg+="-> Le prénom et le nom du joueur(euse) ou entraîneur(euse)\n";
		case_rouge('Nomjoueur');
    }
	
	if(isEmpty(document.form1.Nochandail.value))
	{
		$msg+="-> Le numéro du chandail\n";
		case_rouge('Nochandail');
    }
	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}
function valid_equip(){
	var $msg='';
	case_blanche('Noequipe');
	if(isEmpty(document.form1.Noequipe.value))
	{
		$msg+="-> Le numéro de l'équipe \n";
		case_rouge('Noequipe');
    }

	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
	
}

function valid_ville(){
	var $msg='';
	case_blanche('Nomville');
	if(isEmpty(document.form1.Nomville.value))
	{
		$msg+="-> Le nom de la ville \n";
		case_rouge('Nomville');
    }	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
}


function valid_cat(){
	var $msg='';
	case_blanche('Nomcat');
	if(isEmpty(document.form1.Nomcat.value))
	{
		$msg+="-> Le nom de la catégorie \n";
		case_rouge('Nomcat');
    }	
	if (!isEmpty($msg)){
		alert('Les informations suivantes sont obligatoires: \n'+$msg)
		return false;
	}
	document.form1.Submit.disabled='true';
	return true;
}