function em(h,subject,id)
{
  var result = "";
  var string = "";
  var key = "miam";
  for (var i= (h.substr(0, 2)=="0x")?2:0; i<h.length; i+=2) {string += String.fromCharCode (parseInt (h.substr (i, 2), 16));}
  for(i=1; i<=string.length; i++)
  {
     c = string.substr(i-1,1);
     keychar = key.substr((i % key.length)-1,1);
     c = String.fromCharCode(c.charCodeAt(0)-keychar.charCodeAt(0));
     result=result+c;
   }
   if ( subject=="" ) {document.getElementById(id).href="mailto:"+result;}
   else {document.getElementById(id).href="mailto:"+result+"?subject="+subject;}
   return result;
}

function ouvrirpopup(numero){
	
	/*var link = document.createElement("a");
	link.rel = "prettyPhoto";
	link.href= image;
	
	link.title = legende;
	
	$(link).prettyPhoto();*/
	//$(link).click();
	
	$("#imageV-"+numero).click();
};

var formOldSelected = "";

function getFocusField(id){
	id.className = 'texte focus';
	formOldSelected.className = 'texte';
	formOldSelected = id;
}

var nouvelles_photos = 2;

function nouvelle_photo(){
	
	var new_table = document.createElement("table");
	new_table.className = "table_liste paddingTop";
	new_table.cellSpacing = "1";
	
	var new_row = new_table.insertRow(0);
	var newCell = new_row.insertCell(0);
    newCell.innerHTML = '<strong>Nouvelle photo</strong>';
	newCell.className = "td_ligne_ajout";
	newCell.colSpan = "2";
	
	new_row = new_table.insertRow(1);
	
	newCell = new_row.insertCell(0);
    newCell.innerHTML = 'Chemin';
	newCell.className = "td_ligne_titre";
	newCell.width = "200px";
	
	newCell = new_row.insertCell(1);
    newCell.innerHTML = '<input type="file" name="new_photo_'+nouvelles_photos+'" />';
	newCell.width = "500px";
	
	new_row = new_table.insertRow(2);
	
	newCell = new_row.insertCell(0);
    newCell.innerHTML = 'Légende';
	newCell.className = "td_ligne_titre";
	newCell.width = "200px";
	
	newCell = new_row.insertCell(1);
    newCell.innerHTML = '<input type="text"  class="champstxt" name="new_legende_'+nouvelles_photos+'" />';
	newCell.width = "500px";
	
	new_row = new_table.insertRow(3);
	
	newCell = new_row.insertCell(0);
    newCell.innerHTML = 'Position';
	newCell.className = "td_ligne_titre";
	newCell.width = "200px";
	
	var new_select = document.createElement("select");
	new_select.name = "new_position_"+nouvelles_photos;
	for(i=1; i<= 100; i++)
		new_select.options[new_select.options.length] = new Option(i, i);
	
	newCell = new_row.insertCell(1);
    newCell.appendChild(new_select);
	newCell.width = "500px";
	
	
	$("#nouvelles_photos").append(new_table);
	
	nouvelles_photos++;
};

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;
 
    str_data += '';
 
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}
