function selectDrapeau(identifiant,drapeau){
  try{
	  document.getElementById('Drap'+identifiant).value=drapeau;
	  document.getElementById('imgTitre'+identifiant).src=drapeau;
	  document.getElementById('imgTexte'+identifiant).src=drapeau;
	  document.getElementById('imgUrl'+identifiant).src=drapeau;
	  document.getElementById('imgFile'+identifiant).src=drapeau;
	  document.getElementById('frameDrapeau').parentNode.removeChild(document.getElementById('frameDrapeau'));
  }
  catch (e){
	  document.getElementById('frameDrapeau').parentNode.removeChild(document.getElementById('frameDrapeau'));
  }
}

function removeDrapeau(identifiant){
	//alert('Remove'+identifiant);
	if(identifiant!='0'){
		document.getElementById('eff'+(identifiant-1)).src="./_images/supprimer.png";
	}
	var tbl = document.getElementById('tblSample_titre');
	var row = tbl.deleteRow(identifiant);
	var tbl = document.getElementById('tblSample_description');
	var row = tbl.deleteRow((identifiant*2));
	var row = tbl.deleteRow((identifiant*2));
	var tbl = document.getElementById('tblSample_url');
	var row = tbl.deleteRow(identifiant);
	var tbl = document.getElementById('tblSample_file');
 	var row = tbl.deleteRow(identifiant);
}


function showDrapeau(identifiant){
  var adiv = document.createElement("div");

  adiv.setAttribute('name', 'frameDrapeau');
  adiv.setAttribute('id', 'frameDrapeau');
  adiv.style.position = "absolute";
  adiv.style.left = "13px";
  adiv.style.top = 210+(identifiant*60)+"px";
  adiv.width = "360px";
  adiv.height = "15px";
  adiv.style.border = "1px solid #000000";
  adiv.style.backgroundColor = "#FD6F00";
  adiv.style.visibility = "visible";

  var aImg = document.createElement('br');
  adiv.appendChild(aImg);

  var textNode = document.createTextNode(' Choisissez la langue de votre pétition : ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapfr');
  aImg.setAttribute('id', 'drapfr');
  aImg.setAttribute('src', './_images/drap-fr.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-fr.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-fr.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapebe');
  aImg.setAttribute('id', 'drapbe');
  aImg.setAttribute('src', './_images/drap-be.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-be.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-be.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapqb');
  aImg.setAttribute('id', 'drapqb');
  aImg.setAttribute('src', './_images/drap-qb.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-qb.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-qb.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapsu');
  aImg.setAttribute('id', 'drapsu');
  aImg.setAttribute('src', './_images/drap-su.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-su.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-su.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);  
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapma');
  aImg.setAttribute('id', 'drapma');
  aImg.setAttribute('src', './_images/drap-ma.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-ma.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-ma.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'draptu');
  aImg.setAttribute('id', 'draptu');
  aImg.setAttribute('src', './_images/drap-tu.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-tu.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-tu.gif')");  
  adiv.appendChild(aImg);
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('img');
  aImg.setAttribute('name', 'drapar');
  aImg.setAttribute('id', 'drapar');
  aImg.setAttribute('src', './_images/drap-ar.gif');
  aImg.setAttribute('onclick', 'selectDrapeau(' + identifiant + ',"./_images/drap-ar.gif")');
  aImg.onclick = new Function("selectDrapeau(" + identifiant + ",'./_images/drap-ar.gif')");  
  adiv.appendChild(aImg);  
  var textNode = document.createTextNode(' ');
  adiv.appendChild(textNode);
  var aImg = document.createElement('br');
  adiv.appendChild(aImg);
  var aImg = document.createElement('br');
  adiv.appendChild(aImg);

  document.body.appendChild(adiv);
  return adiv;
}

function addRowToTable()
{
  // ////////// titre0 ////////// //
  var tbl = document.getElementById('tblSample_titre');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var el = document.createElement('input');
  el.setAttribute('type', 'hidden');
  el.setAttribute('name', 'Drap' + iteration);
  el.setAttribute('id', 'Drap' + iteration);
  cellLeft.appendChild(el);
  var el = document.createElement('img');
  el.setAttribute('name', 'imgTitre' + iteration);
  el.setAttribute('id', 'imgTitre' + iteration);
//mod drap
  el.setAttribute('src', './_images/drap-fr.gif');
  el.style.cursor = "hand";
  el.setAttribute('onclick', 'showDrapeau(' + iteration + ')');
  el.onclick = new Function("showDrapeau(" + iteration + ")");
  cellLeft.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(1);
  cellRight.setAttribute('className','tablo');
  cellRight.setAttribute('class','tablo');

  var textNode = document.createTextNode('Titre : ');
  cellRight.appendChild(textNode);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('className','input');
  el.setAttribute('class','input');
  el.setAttribute('name', 'titre' + iteration);
  el.setAttribute('id', 'titre' + iteration);
  el.setAttribute('size', '80');
  cellRight.appendChild(el);
  var textNode = document.createTextNode(' ');
  cellRight.appendChild(textNode);

  if(iteration!='0'){
	  document.getElementById('eff'+(iteration-1)).src="./_images/vide.gif"
  }

  var el = document.createElement('img');
  el.setAttribute('name', 'eff' + iteration);
  el.setAttribute('id', 'eff' + iteration);
  el.setAttribute('src', './_images/supprimer.png');
  el.style.cursor = "hand";
  el.setAttribute('onclick', 'removeDrapeau(' + iteration + ')');
  el.onclick = new Function("removeDrapeau(" + iteration + ")");
  cellRight.appendChild(el);
  // ////////////////////////// //

  // //////// text0 ////////// //
  var tbl = document.getElementById('tblSample_description');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow/2;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var el = document.createElement('img');
  el.setAttribute('name', 'imgTexte' + iteration);
  el.setAttribute('id', 'imgTexte' + iteration);
//mod drap
  el.setAttribute('src', './_images/drap-fr.gif');
  cellLeft.appendChild(el);

  // right cell
  var cellRight = row.insertCell(1);
  var textNode = document.createTextNode(' Description de votre pétition');
  cellRight.appendChild(textNode);

  var row = tbl.insertRow(lastRow+1);  

  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(' ');
  cellLeft.appendChild(textNode);
  // right cell
  var cellRight = row.insertCell(1);
  cellRight.appendChild(textNode);
  var el = document.createElement('textarea');
  el.setAttribute('name', 'text' + iteration);
  el.setAttribute('id', 'text' + iteration);
  el.setAttribute('className', 'input_textarea');
  el.setAttribute('class', 'input_textarea');
  el.setAttribute('cols', '90');
  el.setAttribute('rows', '7');
  cellRight.appendChild(el);
  // ////////////////////////// //

  // //////// url 0 ////////// //
  var tbl = document.getElementById('tblSample_url');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var el = document.createElement('img');
  el.setAttribute('name', 'imgUrl' + iteration);
  el.setAttribute('id', 'imgUrl' + iteration);
//mod drap
  el.setAttribute('src', './_images/drap-fr.gif');
  cellLeft.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(1);
  cellRight.setAttribute('className','tablo');
  cellRight.setAttribute('class','tablo');

  var textNode = document.createTextNode(' URL : ');
  cellRight.appendChild(textNode);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('className','input');
  el.setAttribute('class','input');
  el.setAttribute('name', 'url' + iteration);
  el.setAttribute('id', 'url' + iteration);
  el.setAttribute('size', '80');
  el.setAttribute('value', 'http://');
  cellRight.appendChild(el);
  // ////////////////////////// //

  // //////// file 0 ///////// //
  var tbl = document.getElementById('tblSample_file');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var el = document.createElement('img');
  el.setAttribute('name', 'imgFile' + iteration);
  el.setAttribute('id', 'imgFile' + iteration);
//mod drap
  el.setAttribute('src', './_images/drap-fr.gif');
  cellLeft.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(1);
  cellRight.setAttribute('className','tablo');
  cellRight.setAttribute('class','tablo');

  var textNode = document.createTextNode(' Fichier joint : ');
  cellRight.appendChild(textNode);
  var el = document.createElement('input');
  el.setAttribute('type', 'file');
  el.setAttribute('className','input');
  el.setAttribute('class','input');
  el.setAttribute('name', 'file' + iteration);
  el.setAttribute('id', 'file' + iteration);
  el.setAttribute('size', '60');
  cellRight.appendChild(el); 
  // ////////////////////////// // 
}