var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caractères maximum.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

function ajout_lien(i) {
	document.getElementById(i).innerHTML += '<tr><td colspan="3">&nbsp;</td></tr>';
	document.getElementById(i).innerHTML += '<tr><td class="champ"><span class="titre_box_ligne">Nom du lien</span></td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="lien_nom[]"></td></tr>';
	document.getElementById(i).innerHTML += '<tr><td class="champ"><span class="titre_box_ligne">URL du lien</span></td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="lien_url[]"></td></tr>';
}

function Delete_Ligne( obj_){
  var Parent;
  var Obj = obj_;
  if( Obj){
    //-- tant que pas la balise <TR>
    do{
       Obj = Obj.parentNode;
    }while( Obj.tagName != "TR")
    //-- Recup du parent
    Parent = Obj.parentNode;
    //-- Suppression de la ligne
    if( Parent){
		Parent.deleteRow( Obj.rowIndex-3)
		Parent.deleteRow( Obj.rowIndex-2)
		Parent.deleteRow( Obj.rowIndex-1)
		Parent.deleteRow( Obj.rowIndex)
    }
  }
}

function Create_Ligne(i){
  //-- Get objet tableau
  var O_Table = document.getElementById(i);
  //-- Get nombre de ligne du tableau
  var NbrLigne = O_Table.rows.length;
  //-- Position d'insertion
  var Pos = NbrLigne;
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+1);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">Nom du lien</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="lien_nom[]">';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+2);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">URL du lien</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="lien_url[]">';
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="mark" onmouseout="cache();" onmouseover="montre(\'Votre url doit commencer par http://\');" style="cursor: pointer; padding-top:5px;" alt="" src="/tpl/default/design/images/toto/quotaaation_mark.png" />';
   //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+3);
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une autre cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<b><a onclick="Delete_Ligne(this)" style="cursor:pointer;">Supprimer le lien</a></b>';
}

function ajout_source(i) {
	document.getElementById(i).innerHTML += '<tr><td colspan="3">&nbsp;</td></tr>';
	document.getElementById(i).innerHTML += '<tr><td class="champ">URL du lien</td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><input type="text" name="lien_url[]"></td></tr>';
}

function Create_Source(i){
  //-- Get objet tableau
  var O_Table = document.getElementById(i);
  //-- Get nombre de ligne du tableau
  var NbrLigne = O_Table.rows.length;
  //-- Position d'insertion
  var Pos = NbrLigne;
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+1);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">URL du lien</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="lien_url[]">';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+2);
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une autre cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<b><a onclick="Delete_Source(this)" style="cursor:pointer;">Supprimer le lien</a></b>';
}

function Delete_Source( obj_){
  var Parent;
  var Obj = obj_;
  if( Obj){
    //-- tant que pas la balise <TR>
    do{
       Obj = Obj.parentNode;
    }while( Obj.tagName != "TR")
    //-- Recup du parent
    Parent = Obj.parentNode;
    //-- Suppression de la ligne
    if( Parent){
		Parent.deleteRow( Obj.rowIndex-2)
		Parent.deleteRow( Obj.rowIndex-1)
		Parent.deleteRow( Obj.rowIndex)
    }
  }
}

function ajout_eqp_ranking(i, number) {
	number++;
	
	document.forms["equipes"].elements["ajout"].onclick = function () { ajout_eqp_ranking('equipe',number); };
	
	var elem = document.createElement("input");
	elem.setAttribute("type", "input");
	elem.setAttribute("name", "equipe[]");
	elem.setAttribute("id", "equipe_" + number);
	
	var div = document.createElement("div");
	div.setAttribute("id", "equipe_update_" + number);
	div.setAttribute("class", "update");
	
	var td_champ = document.createElement("td");
	td_champ.setAttribute("class", "champ");
	
	var td_separ = document.createElement("td");
	td_separ.setAttribute("class", "separ");
	
	var td_bar = document.createElement("td");
	td_bar.setAttribute("class", "bar");
	
	var td_valeur = document.createElement("td");
	td_valeur.setAttribute("class", "valeur");
	
	var span_joueur = document.createElement("span");
	span_joueur.setAttribute("class", "titre_box_ligne");
	
	var span_separ = document.createElement("span");
	span_separ.setAttribute("class", "titre_box_ligne");
	
	var img = document.createElement("img");
	img.setAttribute("class", "input_left_contact");
	img.setAttribute("src", "/tpl/default/design/images/toto/input_left.gif");
	
	span_joueur.appendChild(document.createTextNode("Accronyme équipe"))
	td_champ.appendChild(span_joueur);
	span_separ.appendChild(document.createTextNode(": "));
	td_separ.appendChild(span_separ);
	td_bar.appendChild(img);
	
	var tr = document.createElement("tr");
	tr.appendChild(td_champ);
	tr.appendChild(td_separ);
	tr.appendChild(td_bar);
	tr.appendChild(td_valeur);
	td_valeur.appendChild(elem);
	td_valeur.appendChild(div);
	document.getElementById(i).appendChild(tr);
	new Ajax.Autocompleter ("equipe_" + number,
														"equipe_update_" + number,
														'/eqp_completion.php',
														{
															method: 'post',
															paramName: 'eqp',
															afterUpdateElement: ac_return
														});
	
}

function Delete_Mirroir( obj_){
  var Parent;
  var Obj = obj_;
  if( Obj){
    //-- tant que pas la balise <TR>
    do{
       Obj = Obj.parentNode;
    }while( Obj.tagName != "TR")
    //-- Recup du parent
    Parent = Obj.parentNode;
    //-- Suppression de la ligne
    if( Parent){
		Parent.deleteRow( Obj.rowIndex-3)
		Parent.deleteRow( Obj.rowIndex-2)
		Parent.deleteRow( Obj.rowIndex-1)
		Parent.deleteRow( Obj.rowIndex)
    }
  }
}

function Create_Mirroir(i){
  //-- Get objet tableau
  var O_Table = document.getElementById(i);
  //-- Get nombre de ligne du tableau
  var NbrLigne = O_Table.rows.length;
  //-- Position d'insertion
  var Pos = NbrLigne;
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+1);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">Nom du mirroir</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="mirroir[]">';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+2);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">URL du mirroir</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" alt="" src="/tpl/default/design/images/toto/input_left.gif"/><input id="lien" type="text" name="url_mirroir[]">';
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos+3);
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
   //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;';
  //-- Insertion d'une autre cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<center><b><a onclick="Delete_Mirroir(this)" style="cursor:pointer;">Supprimer le mirroir</a></b></center>';
}

function ajout_mirroir(i) {
	document.getElementById(i).innerHTML += '<tr><td colspan="3">&nbsp;</td></tr>';
	document.getElementById(i).innerHTML += '<tr><td class="champ">Nom mirroir</td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><input type="text" name="mirroir[]"></td></tr>';
	document.getElementById(i).innerHTML += '<tr><td class="champ">URL mirroir</td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><input type="text" name="url_mirroir[]"></td></tr>';
	
}


function ajout_poll(i, number) {
	if (number != 10) {
		number++;
		var restant=10-number;
		document.forms["myForm"].elements["ajout"].value = "Ajouter une réponse (restant " + restant + ")";
		document.forms["myForm"].elements["ajout"].onclick = function () { ajout_poll('poll',number); };
		document.getElementById(i).innerHTML += '<tr><td class="champ">Réponse ' + number + '</td><td class="separ">&nbsp;:&nbsp;</td><td class="valeur"><input type="text" name="reponse[]"></td></tr>';
	}
	if (number == 10) {
		document.forms["myForm"].elements["ajout"].value = "Nombre maximum atteint (10)";
		document.forms["myForm"].elements["ajout"].disabled = "disabled";
	}
}

function delete_rep( obj_){
  var Parent;
  var Obj = obj_;
  if( Obj){
    //-- tant que pas la balise <TR>
    do{
       Obj = Obj.parentNode;
    }while( Obj.tagName != "TR")
    //-- Recup du parent
    Parent = Obj.parentNode;
    //-- Suppression de la ligne
    if( Parent){
		Parent.deleteRow( Obj.rowIndex)
    }
  }
}

function add_rep(i){
  //-- Get objet tableau
  var O_Table = document.getElementById(i);
  //-- Get nombre de ligne du tableau
  var NbrLigne = O_Table.rows.length;
  //-- Position d'insertion
  var Pos = NbrLigne;
  //-- Insertion d'une ligne
  O_Row  = O_Table.insertRow(Pos);
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">Réponse</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<span class="titre_box_ligne">&nbsp;:&nbsp;</span>';
  //-- Insertion d'une cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '<img class="input_left_contact" src="/tpl/default/design/images/toto/input_left.gif" alt=""/><input id="question" type="text" name="reponse[]">';
  //-- Insertion d'une autre cellule
  O_Cell = O_Row.insertCell(-1);
  O_Cell.innerHTML = '&nbsp;<b><a onclick="delete_rep(this)" style="cursor:pointer;">Supprimer la réponse</a></b>';
}

function ajout_player(i, number) {
	number++;
	document.forms["myFormeqp"].elements["ajout"].onclick = function () { ajout_player('joueur',number); };
	
	var elem = document.createElement("input");
	elem.setAttribute("type", "text");
	elem.setAttribute("name", "player[]");
	elem.setAttribute("id", "player_" + number);
	
	var div = document.createElement("div");
	div.setAttribute("id", "player_update_" + number);
	div.setAttribute("class", "update");
	
	var td_champ = document.createElement("td");
	td_champ.setAttribute("class", "champ");
	
	var td_separ = document.createElement("td");
	td_separ.setAttribute("class", "separ");
	
	var td_bar = document.createElement("td");
	td_bar.setAttribute("class", "bar");
	
	var td_valeur = document.createElement("td");
	td_valeur.setAttribute("class", "valeur");
	
	var span_joueur = document.createElement("span");
	span_joueur.setAttribute("class", "titre_box_ligne");
	
	var span_separ = document.createElement("span");
	span_separ.setAttribute("class", "titre_box_ligne");
	
	var img = document.createElement("img");
	img.setAttribute("class", "input_left_contact");
	img.setAttribute("src", "/tpl/default/design/images/toto/input_left.gif");
	
	span_joueur.appendChild(document.createTextNode("Joueur"))
	td_champ.appendChild(span_joueur);
	span_separ.appendChild(document.createTextNode(" : "))
	td_separ.appendChild(span_separ);
	td_bar.appendChild(img);

	var tr = document.createElement("tr");
	tr.appendChild(td_champ);
	tr.appendChild(td_separ);
	tr.appendChild(td_bar);
	tr.appendChild(td_valeur);
	td_valeur.appendChild(elem);
	td_valeur.appendChild(div);
	document.getElementById(i).appendChild(tr);
	new Ajax.Autocompleter ("player_" + number,
														"player_update_" + number,
														'/eqp_completion.php',
														{
															method: 'post',
															paramName: 'pseudo',
															afterUpdateElement: ac_return
														});
}


function RepComment(i, number, numero, hide, iddiv)
{
    document.forms["myForm"].elements["reponse"].value = number;	
    var mess = document.getElementById(i);
    
    if (hide=='1')
    {
        document.getElementById(iddiv).style.display='none'
        document.getElementById(iddiv).innerHTML='';
        document.forms["myForm"].elements["reponse"].value = '';
        document.forms["myForm"].elements["numero"].value = '';
    }
    else
    {
        document.getElementById(iddiv).style.display='';
        document.getElementById(iddiv).innerHTML='Vous répondez actuellement à #'+numero+' - <a href=\"javascript:RepComment(\''+ mess +'\',\''+ number +'\',\''+ numero +'\',\'1\',\'' + iddiv +'\')\"><img src=\"/images/icones/delete.png\" border=\"0\" title=\"Supprimer la réponse\" alt=\"Supprimer la réponse\" align=\"absmiddle\"> Supprimer</a>';
        document.forms["myForm"].elements["reponse"].value = number;
        document.forms["myForm"].elements["numero"].value = numero;
    }
	
    mess.focus(); 
}        

function RepCommentIrcAward(i, number, numero, hide, iddiv)
{
    document.forms[1].elements["reponse"].value = number;	
    var mess = document.getElementById(i);
    
    if (hide=='1')
    {
        document.getElementById(iddiv).style.display='none'
        document.getElementById(iddiv).innerHTML='';
        document.forms[1].elements["reponse"].value = '';
        document.forms[1].elements["numero"].value = '';
    }
    else
    {
        document.getElementById(iddiv).style.display='';
        document.getElementById(iddiv).innerHTML='Vous répondez actuellement à #'+numero+' - <a href=\"javascript:RepComment(\''+ mess +'\',\''+ number +'\',\''+ numero +'\',\'1\',\'' + iddiv +'\')\"><img src=\"/images/icones/delete.png\" border=\"0\" title=\"Supprimer la réponse\" alt=\"Supprimer la réponse\" align=\"absmiddle\"> Supprimer</a>';
        document.forms[1].elements["reponse"].value = number;
        document.forms[1].elements["numero"].value = numero;
    }
	
    mess.focus(); 
}  

function addTag(i, instext) {
                 
	 var mess = document.getElementById(i);
            mess.value = mess.value + instext;
            mess.focus();
    
        }


function close_open(id)
{ 
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+(365*24*3600*1000));
	if (document.getElementById(id).style.display == "") {  
		document.getElementById(id).style.display = "none";
		document.cookie = "eqp["+id+"]=0;expires="+date_exp.toGMTString();
	} else {  
		document.getElementById(id).style.display = "";
		document.cookie = "eqp["+id+"]=1;expires="+date_exp.toGMTString();
    }
}
