/* VARIABLES GLOBALES */
var theLastOrder = "DESC";
var theLastOrderFull = "";
var theLastPage = 1;
var buttoncheck = false;
var GL_top = 35;
var GL_height_diff = 65;
var current_scroll = "";
var codeRetourAjax = "";
var Color_id_bg_color, Color_linkajax, Color_tab_autres;

var iboxOnClose = "";
var iboxOnCloseJS = "";

// IBOX
var div_ibox		= document.getElementById("ibox");
var div_ibox_content 	= document.getElementById("ibox_content");
var div_ibox_inner 	= document.getElementById("ibox_inner");
var div_ibox_menu 	= document.getElementById("ibox_menu");
var div_ibox_menu_inner	= document.getElementById("ibox_menu_inner");

//DND
var tabSort;

// Simule un POST en Ajax
// Attend l'id du <form>
function admiPostForm(id_form, lien, args)
	{
	var i, nom, val, tmp;
	
	var formu 	= document.getElementById(id_form);
	var inputs 	= formu.getElementsByTagName("input");	
	for (i=0; i<inputs.length; i++)
		{
		nom = inputs[i].name;
		val = escape(inputs[i].value);
		typ = inputs[i].type;
		
		if (nom != "")
			{
			if (typ == "radio" || typ == "checkbox")
				{
				if (inputs[i].checked == true)	tmp+= "&" + nom + "[]=" + val;
				}
			else	
				{
				tmp+= "&" + nom + "=" + unescape(val);
				}
			}
		}

	var selects 	= formu.getElementsByTagName("select");	
	for (i=0; i<selects.length; i++)
		{
		nom = selects[i].name;
		val = escape(selects[i].value);
		
		if (nom != "")	{ tmp+= "&" + nom + "=" + val;}
		}

	var textareas 	= formu.getElementsByTagName("textarea");	
	for (i=0; i<textareas.length; i++)
		{
		nom = textareas[i].name;
		val = escape(textareas[i].value);
		
		if (nom != "")	{ tmp+= "&" + nom + "=" + val;}
		}

	if (args != null)	tmp+= "&"+args;
	if (lien == null)	lien = ici + "&preaction=content";
	
	admiAjax(lien, tmp);
	}

function show_hide(id, toujours) 
	{
       	var objet=dei(id);
       	if (objet != null)
       		{
	      	if (objet.style.display=='none') 	{ objet.style.display='';}
	      	else if (toujours == null)	      	{ objet.style.display='none';}
	      	}
    	}
    	
function main_event(e)
	{
	if (e.keyCode == 27)	{admi_close_bulle(); return false;}
	if (e.keyCode == 119)	{window.open(rootzine); return false;}
	}

function dei(ido)
	{
	return document.getElementById(ido);
	}

function protected_mail(email)
	{
	var pattern = '!SPAM!';
	goodmail = email.replace(pattern, "@");
	a = window.open("mailto:"+goodmail);
	if (a != null) a.close();
	}
	
function getWindowHeight()
	{
    	var windowHeight=0;
    	if (typeof(window.innerHeight)=='number')
    		{
        	windowHeight=window.innerHeight;
    		}
    	else
    		{
     		if (document.documentElement && document.documentElement.clientHeight)
     			{
         		windowHeight = document.documentElement.clientHeight;
    			}
    		else
    			{
     			if (document.body&&document.body.clientHeight)
     				{
         			windowHeight=document.body.clientHeight;
      				}
     			}
    		}
    return windowHeight;
}

function getScrollTop() {
    var scrollTop = (document.documentElement&&document.documentElement.scrollTop
                                ?document.documentElement.scrollTop
                                :document.body.scrollTop);
    return scrollTop;
}

function getScrollLeft() {
    var scrollLeft = (document.documentElement&&document.documentElement.scrollLeft
                                ?document.documentElement.scrollLeft
                                :document.body.scrollLeft);
    return scrollLeft;
}
   	   	
function findPosX(obj) {
	    var curleft = 0;
	    if (obj && obj.offsetParent) {
		    while (obj.offsetParent) {
			    curleft += obj.offsetLeft;
			    obj = obj.offsetParent;
		    }
	    } else if (obj && obj.x) curleft += obj.x;
	    return curleft;
}

function findPosY(obj){
	    var curtop = 0;
	    if (obj && obj.offsetParent) {
		    while (obj.offsetParent) {
			    curtop += obj.offsetTop;
			    obj = obj.offsetParent;
		    }
	    } else if (obj && obj.y) curtop += obj.y;
	    return curtop;
}

function cursorPos(e)
 	{
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft + getScrollLeft();
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop + getScrollTop();
	
	return new Array(x, y);
	}

function main_opacity(val)
	{
	var bod = document.getElementsByTagName('body')[0];
	/*	
	bod.style.backgroundColor = 'black';
	*/
	
	lis = bod.getElementsByTagName('li');
	imgs = bod.getElementsByTagName('img');

 	obj = dei('main');
 	if (val == 1)
 		{
 		// Pour IE
 		if (navigator.userLanguage)
 			{
			for (i=0;i<lis.length;i++)	lis[i].style.visibility = "hidden";
			//for (i=0;i<imgs.length;i++)	imgs[i].style.visibility = "hidden";
	  		obj.style.filter = "alpha(opacity:5)";
	  		obj.style.opacity = "0.05";
	 		obj.style.height = getWindowHeight()+"px";
	  		obj.style.overflowY = 'auto';
	  		}
	  	else
	  		{
	  		obj.style.display = 'none';	
	  		}
 		}
 	else
 		{
  		// Pour IE
 		if (navigator.userLanguage)
 			{
	 		for (i=0;i<lis.length;i++)	lis[i].style.visibility = "visible";
	 		//for (i=0;i<imgs.length;i++)	imgs[i].style.visibility = "visible";
	  		obj.style.filter = "alpha(opacity:100)";
	  		obj.style.opacity = "1"; 
	  	 	obj.style.height = 'auto';
	  	 	}
	 	  else
	  		{
	  		obj.style.display = '';	
	  		}
 		}
 		

	}

function admi_ibulle(ObjClique)
	{
	admi_close_bulle();
	var DivBulle = dei("bulle_perso");
		
	DivBulle.style.top = (findPosY(ObjClique) + 10) + "px";
        DivBulle.style.left = (findPosX(ObjClique) - 35) + "px"; 
        
	var new_src = "/_admin/css/images/tooltip_1.png";
	
	DivBulle.style.background = "url("+new_src+")";
	
	// IE
	if (navigator.userLanguage) { DivBulle.style.background = "transparent";}
	dei("bulle_perso_filter").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='" + new_src + "')";
	
	
	DivBulle.style.display = '';
	var inputs = DivBulle.getElementsByTagName('input');
	if (inputs[0])	inputs[0].focus();
	}
			
function admi_close_bulle()
	{
	if(dei("bulle_perso") != null)	{dei("bulle_perso").style.display = "none";}
	if(dei("ibox") != null)		
		{
		if (dei("ibox").style.display != 'none')
			{
			dei("ibox").style.display = "none";
			main_opacity(0);
			
		   	// On remet les selectbox (bug d'IE)
		   	var selects = document.getElementsByTagName('select');
		   	for (i=0;i<selects.length;i++)	{selects[i].style.visibility='visible';}

		 	// On remet les iframes
		    	var iframes = document.getElementsByTagName('iframe');
		   	for (i=0;i<iframes.length;i++)	{iframes[i].style.visibility='visible';}
			   	
			if (current_scroll != "")	{ window.scroll(0, current_scroll);}
			document.documentElement.style.overflowY = 'auto';	
			
			codeRetourAjax = "";
			theCallback = "";

			if (iboxOnClose != "")		admiAjax(iboxOnClose);
			if (iboxOnCloseJS != "")	eval (iboxOnCloseJS);
			}
		}
	close_popup();
	}
	
function admi_ibox_callback(tabjssrc)
	{
	// Que faire quand la page ajax est arrivée ----------------------------------------	
	dei('ibox_inner').innerHTML = theLastAjax;	

	// IE
	if (navigator.userLanguage)
		{
		dei('ibox_title').style.backgroundImage = "url(/_theme/images/ibox_bg_top.gif)";
		dei('ibox_menu').style.backgroundImage = "url(/_theme/images/ibox_bg_inner.gif)";
		dei('ibox_content').style.backgroundImage = "url(/_theme/images/ibox_bg_inner.gif)";
		dei('close_ibox').src = "/_theme/images/close_ibox.gif";
		dei('close_ibox2').src = "/_theme/images/close_ibox.gif";
		}
		
	if (tabjssrc)
		{
		for(i=0; i<tabjssrc.length; i++)
			{
			var SCRIPT = document.createElement("script");
			SCRIPT.type = "text/javascript";
			SCRIPT.src  = "/_vfruits/javascript/" + tabjssrc[i];
			HEAD = document.getElementsByTagName("head");
			HEAD[0].appendChild(SCRIPT); 
			}
		}

	dei('ibox_content').scrollTop = 0;
	eval(codeRetourAjax);
	}

function admi_ibox_change_content(lien, qui, combien)
	{
	// Que faire quand un lien du menu est cliqué -------------------------------------
	admiAjax(lien);
	for(i=0; i<combien; i++)
		{
		var divQui = dei("iboxMenu"+i);
		if(i == qui) 	{ divQui.className = 'selected'; 	} // Le séléctionné
		else		{ divQui.className = '';	} // Un autre
		}
	}

function admi_ibox(title, lien, withtab, tabliens, tabtitres, height, tabjssrc, jscode, menu_sel, onclose, onclosejs)
	{
	var menu_temp		= "";

	admi_close_bulle();

	iboxOnClose = onclose;
	iboxOnCloseJS = onclosejs;
		
	// Si c'est un tabeleau de lien, crééons le menu ---------------------------------
	if(withtab == 1)
		{
		for(i=0; i<tabliens.length; i++)
			{
			if (i == menu_sel) 	cls = "class='selected'";
			else			cls = "";
			
			if (tabliens[i].charAt(0) == "<" && tabliens[i].charAt(1) == "a")
				{
				tabliens[i].replace("&quot;", '"');
				menu_temp+= "<div class='menu'>" + tabliens[i] + "</div>\n";
				}
			else
				menu_temp+= "<div class='menu'><a id='iboxMenu"+i+"' "+cls+" href=\"javascript:void(0)\" onclick=\"admi_ibox_change_content('"+tabliens[i]+"', '"+i+"', '"+tabliens.length+"')\">"+tabtitres[i]+"</a></div>\n";
			}	
		dei('ibox_menu_inner').innerHTML = menu_temp;
		dei('ibox_menu').display = '';
		}

	
	// Defini la fonction Javascript a appeller une fois la page ajax chargée --------
	var JS_tabjssrc = "";
	if (tabjssrc != null)
		{
		var cpt = 0;
		for(i=0; i<tabjssrc.length; i++)
			{
			cpt++;
			JS_tabjssrc+= "'" + tabjssrc[i] + "'";
			if(cpt != tabjssrc.length) {JS_tabjssrc+=",";}	
			}
		
		}
	
	codeRetourAjax = jscode;
	theCallback = "admi_ibox_callback(new Array(" + JS_tabjssrc + "))";	

	// Appelle la page ajax ----------------------------------------------------------
	admiAjax(lien);
	
	admi_affiche_ibox(title, withtab, height);
	}

function admi_affiche_ibox(title, withtab, height)
	{	
	// Le titre
	dei('ibox_title').innerHTML = "<table style='width:100%;height:27px' cellpadding='0' cellspacing='0'><tr><td style='width:30px'><a href='javascript:void(0)' onclick='admi_close_bulle()'><img id='close_ibox' src='/_theme/images/close_ibox.gif' alt='' /></a></td><td>" + title + "</td><td style='text-align:right; vertical-align: middle; position: relative;'><a href='javascript:void(0)' onclick='admi_close_bulle()'><img id='close_ibox2' src='/_theme/images/close_ibox.gif' alt='' /></a></td></tr></table>";
	
	// Affiche la boboxe -------------------------------------------------------------
	if (withtab == 0)
		{
		dei('ibox_menu').style.display='none';
		dei('ibox_content').style.width='950px';	
		}
	else
		{
		dei('ibox_menu').style.display='';	
		dei('ibox_content').style.width='725px';
		}
   	dei('ibox').style.height = height + "px";
   	dei('ibox_content').style.height = (height - 33) + "px";
   	dei('ibox_content').style.overflowX='hidden';
   	dei('ibox_menu').style.overflowX='hidden';
   	dei('ibox_menu').style.height = (height - 33) + "px";
   	dei('ibox').style.top = (getWindowHeight() - height)/2 + "px";
   	
   	// On enleve les selectbox (bug d'IE)
   	var selects = document.getElementsByTagName('select');
   	for (i=0;i<selects.length;i++)	{selects[i].style.visibility='hidden';}
 
 	// On enleve les iframes
    	var iframes = document.getElementsByTagName('iframe');
   	for (i=0;i<iframes.length;i++)	{iframes[i].style.visibility='hidden';}

	current_scroll = getScrollTop();      	  	
	
   	main_opacity(1);
	dei('ibox').style.display = '';
	
	document.documentElement.style.overflowX='hidden';
	document.documentElement.style.overflowY='hidden';
	window.scroll(0, 0);	
	}
	
function cb_admi_ibox_menu(req)
	{
	// IE
	if (navigator.userLanguage)
		{
		dei('ibox_title').style.backgroundImage = "url(/_theme/images/ibox_bg_top.gif)";
		dei('ibox_menu').style.backgroundImage = "url(/_theme/images/ibox_bg_inner.gif)";
		dei('ibox_content').style.backgroundImage = "url(/_theme/images/ibox_bg_inner.gif)";
		dei('close_ibox').src = "/_theme/images/close_ibox.gif";
		dei('close_ibox2').src = "/_theme/images/close_ibox.gif";
		}
	}

function admi_ibox_menu(title, lien_menu, lien_contenu, height, cpt)
	{
	admi_affiche_ibox(title, 1, height);	
	
	dei('ibox_inner').style.paddingTop = "10px";
	
	new Ajax.Updater(dei('ibox_menu_inner'), lien_menu + "&preaction=content", {evalScripts:true, onSuccess:cb_admi_ibox_menu});
	new Ajax.Updater(dei('ibox_inner'), lien_contenu + "&preaction=content");
	}

function show_item_content(new_item)
 {
 	new Ajax.Updater(dei('ibox_inner'), '/?q=show_item_content&id_item=' + new_item + '&preaction=content');
  
  var obj = dei('summary_item_' + old_item);  if (obj != null)    obj.className = "menu readed";  

  var obj = dei('summary_item_' + new_item);  if (obj != null)    obj.className = "menu selected";
  
  old_item = new_item;
 }

function keydown_menu(ev, cpt, nb_tot)
 {
	var key_code = ev.keyCode;
	
	if(key_code != 33 && key_code != 34 && key_code != 40 && key_code != 38) return;
	
	if(key_code == 33) new_cpt = 0;//premier
	if(key_code == 34) new_cpt = nb_tot - 1;//dernier
	if(key_code == 40) new_cpt = cpt + 1;//suivant
	if(key_code == 38) new_cpt = cpt - 1;//precedent
	
	if(dei('summary_' + new_cpt) != null)
		{
		dei('summary_' + new_cpt).focus();
		var tab = dei('summary_' + new_cpt).name.split('_');
		show_item_content(tab[2]);
		}
	}

function admi_auto_refresh(id_tableau, sep, code_js)
	{
	if(typeof sep == "undefined") sep = "code";
	var MyResult = theLastAjax;
	
	var expr = new RegExp("id=[\"']" + id_tableau + "[\"']");
	
	var TabMyResult1  	= MyResult.split(expr);
	var TabMyResult2  	= TabMyResult1[1].split("</"+ sep + ">");
	var TabMyResult3  	= TabMyResult2[0].split("<"+ sep + ">");
	MyResult     		= TabMyResult3[1];
	
	document.getElementById(id_tableau).innerHTML = MyResult;
	
	if (code_js != "")
		{
		code_js = code_js.replace(/&quot;/g, '"');
		code_js = code_js.replace(/&lt;/g, '<');		
		code_js = code_js.replace(/&gt;/g, '>');
		code_js = code_js.replace(/&amp;/g, '&');
		eval(code_js);
		}
	}
	
function trim(s) {
	return s.replace(/^\s+/, '').replace(/\s+$/, '');
}


function sha1Hash(msg)
{
	// constants [4.2.1]
	var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
	
	// PREPROCESSING 
	msg += String.fromCharCode(0x80); // add trailing '1' bit to string [5.1.1]
	
	// convert string msg into 512-bit/16-integer blocks arrays of ints [5.2.1]
	var l = Math.ceil(msg.length/4) + 2;  // long enough to contain msg plus 2-word length
	var N = Math.ceil(l/16);              // in N 16-int blocks
	var M = new Array(N);
	for (var i=0; i<N; i++)
	{
		M[i] = new Array(16);
		for (var j=0; j<16; j++)
		{// encode 4 chars per integer, big-endian encoding
				M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) | 
			  (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
		}
	}
	
	// add length (in bits) into final pair of 32-bit integers (big-endian) [5.1.1]
	M[N-1][14] = ((msg.length-1) >>> 30) * 8;
	M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;
	
	// set initial hash value [5.3.1]
	var H0 = 0x67452301;
	var H1 = 0xefcdab89;
	var H2 = 0x98badcfe;
	var H3 = 0x10325476;
	var H4 = 0xc3d2e1f0;
	
	// HASH COMPUTATION [6.1.2]
	var W = new Array(80); var a, b, c, d, e;
	for (var i=0; i<N; i++)
	{
		// 1 - prepare message schedule 'W'
		for (var t=0;  t<16; t++) W[t] = M[i][t];
		for (var t=16; t<80; t++) W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
		
		// 2 - initialise five working variables a, b, c, d, e with previous hash value
		a = H0; b = H1; c = H2; d = H3; e = H4;
		
		// 3 - main loop
		for (var t=0; t<80; t++) {
		var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants
		var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
		e = d;
		d = c;
		c = ROTL(b, 30);
		b = a;
		a = T;
		}
		
		// 4 - compute the new intermediate hash value
		H0 = (H0+a) & 0xffffffff;  // note 'addition modulo 2^32'
		H1 = (H1+b) & 0xffffffff; 
		H2 = (H2+c) & 0xffffffff; 
		H3 = (H3+d) & 0xffffffff; 
		H4 = (H4+e) & 0xffffffff;
	}
	
	return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
}

// function 'f' [4.1.1]
function f(s, x, y, z) 
{
  switch (s)
  {
  case 0: return (x & y) ^ (~x & z);
  case 1: return x ^ y ^ z;
  case 2: return (x & y) ^ (x & z) ^ (y & z);
  case 3: return x ^ y ^ z;
  }
}

// rotate left (circular left shift) value x by n positions [3.2.5]
function ROTL(x, n)
{
	return (x<<n) | (x>>>(32-n));
}

// extend Number class with a tailored hex-string method 
//   (note toString(16) is implementation-dependant, and 
//   in IE returns signed numbers when used on full words)
Number.prototype.toHexStr = function()
{
	var s="", v;
	for (var i = 7; i >= 0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
	return s;
}

function generate_login(mail, dest)
{
	if(verif_mail(mail.value, true) && dei(dest) && dei(dest).value == "")
	{
		var tab = mail.value.split('@');
		var login = tab[0].replace(/^(_)*|([^a-z0-9_])/g, "");
		dei(dest).value = login;
	}
}

function verify_new_user()
{
	ok = true;
	
	if(verif_pass(dei('new_pass').value, true))
	{
		set_ok('new_pass');
		if(dei('new_pass').value == dei('new_pass_confirm').value)
		{
			set_ok('new_pass_confirm');
		}
		else
		{
			set_error('new_pass_confirm', LOGIN_14);
			ok = false;
		}
	}
	else
	{
		set_error('new_pass', LOGIN_12);
		ok = false;
	}
	
	if(verif_login(dei('new_login').value, true))
		set_ok('new_login');
	else
	{
		set_error('new_login', LOGIN_11);
		ok = false;
	}
	
	if(verif_mail(dei('new_email').value, true))
		set_ok('new_email');
	else
	{
		set_error('new_email', LOGIN_10);
		ok = false;
	}

	if(dei('new_id_pays').value != "")
		set_ok('new_id_pays');
	else
	{
		set_error('new_id_pays', LOGIN_19);
		ok = false;
	}
		
	if(dei('cgu').checked)
		set_ok('div_cgu', 1);
	else
	{
		set_error('div_cgu', LOGIN_18, 1);
		ok = false;
	}
	
	if(ok) search_user_exist();
	return false;
}



function verif_mail(mail, required)
{
 var re = /^[a-z0-9\-_\.]+@[a-z0-9\-_]+(\.[a-z0-9]{2,})+$/i;
  
 if(!required && mail == "") return true;
 if(re.test(mail)) return true;
 
 return false;
}

function verif_login(login, required)
{
	var re = /^[a-zA-Z0-9][a-zA-Z0-9_]{3,15}$/i;
	
	if(!required && login == "") return true;
	if(re.test(login)) return true;
	
	return false; 	
}

function verif_pass(pass, required)
{
	var re = /^[a-zA-Z0-9][a-zA-Z0-9_]{3,31}$/i;
	
	if(!required && pass == "") return true;
	if(re.test(pass)) return true;
	
	return false; 	
}

  
function search_user_exist()
{
	var lurl = "/?q=form_account&preaction=data&action=search_user_exist&mail=" + sha1Hash(dei('new_email').value) + "&login=" + sha1Hash(dei('new_login').value) + "&crypto=" + dei('new_code').value;
	new Ajax.Request(lurl, {asynchronous:false, onSuccess:function(t)
	{
		var rep = t.responseText;
		if(rep == "mail_exist") 	set_error('new_email', LOGIN_16); 		else set_ok('new_email');
		if(rep == "login_exist") 	set_error('new_login', LOGIN_17); 		else set_ok('new_login');
		if(rep == "bad_code") 		set_error('new_code', LOGIN_15); 		else set_ok('new_code');
		if(rep == "ok") 		dei('form_new_user').submit();
	}});
} 


function set_error(id_field, mess, noclass)
{
	if(typeof noclass == "undefined") noclass = 0;
	
	if(dei(id_field) && !dei("error" + id_field) && mess != null) new Insertion.After(dei(id_field), "<div id='error" + id_field + "' class='error'>" + mess + "</div>");
	if(noclass!= 1) if(dei(id_field)) dei(id_field).className = "form_error inner";
	dei(id_field).focus();
}

function set_ok(id_field, noclass)
{
	if(typeof noclass == "undefined") noclass = 0;
	
	if(dei("error" + id_field)) Element.remove(dei("error" + id_field));
	if(noclass!= 1) if(dei(id_field)) dei(id_field).className = "form inner";
}

function verify_login()
{
	var ident = sha1Hash(dei('login').value + '@' + dei('pass').value);
	var lurl = "/?q=form_account&preaction=data&action=test_signin&ident=" + ident;
	new Ajax.Request(lurl, {asynchronous:false, onSuccess:function(t)
	{
		var res = t.responseText;
		if(res != "pas_ok" && res != "null")
  {
	   dei('form_signin').setAttribute("action", "/" + res + "/");
	   dei('signin_ident').value = ident;
	   dei('form_signin').submit();
	  }
	  else
	  {
	   alert(ERROR_LOGIN);
	  }
	 }});
}

function verify_profile(id)
{
	ok = true;

	if(verif_pass(dei('profile_pass').value, true))
	{
		set_ok('profile_pass');
		if(dei('profile_pass').value == dei('profile_pass_confirm').value)
		{
			set_ok('profile_pass_confirm');
		}
		else
		{
			set_error('profile_pass_confirm', LOGIN_14);
			ok = false;
		}
	}
	else
	{
		set_error('profile_pass', LOGIN_12);
		ok = false;
	}
	
	if(verif_mail(dei('profile_email').value, true))
		set_ok('profile_email');
	else
	{
		set_error('profile_email', LOGIN_10);
		ok = false;
	}
	
	if(ok) search_mail_exist(id);
	return false;
}

function search_mail_exist(id)
{
	var lurl = "/?q=form_profile&preaction=data&action=search_mail_exist&mail=" + sha1Hash(dei('profile_email').value) + "&id=" + id;
	new Ajax.Request(lurl, {asynchronous:false, onSuccess:function(t)
			{
			var rep = t.responseText;
			if(rep != "ok")
				set_error('profile_email', LOGIN_16);
			else
			{
				set_ok('profile_email');
				dei('form_profile').submit();
			}
		}});
} 

function verify_fields()
{
	ok = true;

	if(dei('spec2').value == '')
	{
		set_error('spec2');
		ok = false;
	}
	
	if(dei('title').value == '')
	{
		set_error('title');
		ok = false;
	}
	
	if(dei('description').value == '')
	{
		set_error('description');
		ok = false;
	}

	if (ok == true) dei('form_service').submit();
	return true;
}


function verify_feed(i, val)
{
	if ((val.search("http://") != -1 || val.search("https://") != -1) && val.length > 7)
	{
		dei('rss_img_' + i).src = "/_theme/images/ajax-loader.gif";
		var lurl = "/?q=service&preaction=data&action=verify_feed&feed=" + val;
		new Ajax.Request(lurl, {onComplete:function(t)
			{
			var rep = t.responseText;
			if(rep != "ok")
				dei('rss_img_' + i).src = "/_theme/images/rssminidisabled.gif";
			else
				dei('rss_img_' + i).src = "/_theme/images/rssmini.gif";
			}, onFailure:function(t)
			{
			dei('rss_img_' + i).src = "/_theme/images/rssminidisabled.gif";	
			}
		});
	}
	else
	{
		dei('feed_' + i).value = "http://";
		dei('rss_img_' + i).src = "/_theme/images/rssminidisabled.gif";
	}
} 

function add_input_text(id, i)
	{
	if (dei(id + '_' + i).style.color != '')
		{
		dei(id + '_' + i).style.color = '';
		dei(id + '_' + i).style.borderColor = '';
		if (dei(id + '_' + (i + 1)))	dei('div_' + id + '_' + (i + 1)).style.display = '';
		}
	dei(id + '_' + i).select();
	}
	
function fade (opac, id)
	{
	var passed = parseInt(opac);
	var newOpac = parseInt(passed+10);
	obj = dei(id);
	
	if( newOpac < 80 )
		{
		obj.style.opacity = '.'+newOpac;
		obj.style.filter = "alpha(opacity:"+newOpac+")";
		opacity_service = setTimeout ("fade('" + newOpac + "', '" + id + "')", 30);
		}
	else
		{ 
		obj.style.opacity = '1';
		obj.style.filter = "alpha(opacity:100)";
		}
	}

function change_voix(obj, val)
	{
	for (var i=0; i<obj.length; i++)
		{
		dei('voix_'+obj[i].value).style.display='none';
		}	
	dei('voix_'+val).style.display='';

	}
	
function change_status(id)
{
	var lurl = "/?q=service&preaction=data&action=change_status&id=" + id;
	new Ajax.Request(lurl, {asynchronous:false, onSuccess:function(t)
			{
			var rep = t.responseText;
			if(rep == 0)
				{
				dei('status_' + id).className='public';
				dei('status_' + id).innerHTML = MY_2;
				}
			else
				{
				dei('status_' + id).className='prive';
				dei('status_' + id).innerHTML = MY_3;
				}
		}});
} 

function change_imob(id)
{
	var lurl = "/?q=service&preaction=data&action=change_imob&id=" + id;
	new Ajax.Request(lurl, {asynchronous:false, onSuccess:function(t)
			{
			var rep = t.responseText;
			if(rep == 1)
				{
				dei('imob_' + id).className='public';
				dei('imob_' + id).innerHTML = MY_18;
				}
			else
				{
				dei('imob_' + id).className='prive';
				dei('imob_' + id).innerHTML = MY_19;
				}
		}});
} 

function refresh_credits(login)
	{
	if (login)
		{
		var lurl = "/"+login+"/?preaction=data&action=get_credits";
		new Ajax.Updater(dei('nb_credits'), lurl);
		}
	setTimeout("refresh_credits('" + login + "')", 60000);
	}

function check_all_lang(id_container, id_all, obj)
	{
	var no_all = false;
	var no_chk = true;
	
	var list = dei(id_container).getElementsByTagName('input');
	for (var i=0; i<list.length; i++)
		{
		if (list[i].id != id_all)
			{
			if (obj.id == id_all)		list[i].checked = false;
			else if (list[i].checked)	no_all = true;
			else if (!list[i].checked)	no_chk = false;
			}
		}

	// Si toutes les langues cochées on les decoche puis on coche "Tous"
	if (no_chk)
		{
		for (var i=0; i<list.length; i++)	{ if (list[i].id != id_all) list[i].checked = false;}
		no_all = false;
		}
	
	if (no_all)	dei(id_all).checked = false;
	else		dei(id_all).checked = true;
	}