function handleEnter (event) {var keyCode=event.keyCode?event.keyCode:event.which?event.which:event.charCode;if(keyCode == 13){return false;}else{return true;}}
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('r 1j(a){3 b=s;$(\'#\'+a+\' :T[4=6]\').1k(r(){9($(H).j(\'U\')==k){b=k}});9(b==k){$.2(\'6\',\'1\',{I:J});$.2(\'w\',K(\'x\',$(\'#\'+a+\' [4=y]\').j(\'7\')),{I:J});$.2(\'z\',K(\'x\',$(\'#\'+a+\' [4=A]\').j(\'7\')),{I:J})}V{$.2(\'6\',l);$.2(\'w\',l);$.2(\'z\',l)}}r 1l(){9($(\'#5\').L==0){$(\'1m\').1n(\'<g m="5" 1o="\'+1p+\'"></g>\');$(\'#5\').1q("<W 1r=\\"1s\\" m=\\"M\\" 4=\\"M\\" N=\\""+X+"?Y=Z&N=y\\">\\n"+"<p><o t=\\"10\\" 8=\\"u: 11;\\">"+1t+" : </o><v q=\\"O\\" 4=\\"y\\" m=\\"10\\" B=\\"12\\" 7=\\"\\" 13=\\"14|C|C\\" 15=\\"16(H);\\" 17=\\"D 18(19);\\" /></p>\\n"+"<p><o t=\\"1a\\" 8=\\"u: 11;\\">"+1u+" : </o><v q=\\"A\\" 4=\\"A\\" m=\\"1a\\" B=\\"12\\" 7=\\"\\" 13=\\"14|C|C\\" 15=\\"16(H);\\" 17=\\"D 18(19);\\" /></p>\\n"+"<p 8=\\"O-P: 1v;\\"><v q=\\"E\\" m=\\"1w\\" 7=\\""+1x+"\\" 1b=\\"1y(\'M\');\\" /> <v q=\\"E\\" 7=\\""+1z+"\\" 1b=\\"$(\'#5\').Q(\'1A\');\\" /></p>\\n"+"<g 8=\\"1c: 1B; u: 1C%;\\"><p 8=\\"1d: 1e;\\"><v q=\\"T\\" 4=\\"6\\" m=\\"6\\" 7=\\"k\\" 8=\\"1D-P: 1E; 1F-R: 1G;\\" /><o t=\\"6\\" B=\\"1H\\">"+1I+"</o></p></g>\\n"+"<g 8=\\"1d: 1e; 1c: R; u: 1J%;\\"><p 8=\\"O-P: R;\\"><a 1K=\\""+X+"?Y=Z&N=1L\\" B=\\"1M\\">"+1N+"</a></p>\\n</g>\\n"+"<g 8=\\"1O: 1P;\\"></g>\\n"+"</W>\\n");$(\'#5\').Q({1Q:s,1R:s,1S:s,1T:k,u:1U});$(\'#5 [q="E"]\').E({1V:s})}9($.2(\'6\')){$(\'#5 [4="6"]\').j(\'U\',k);$(\'#5 [4="y"]\').j(\'7\',S(\'x\',$.2(\'w\')));$(\'#5 [4="A"]\').j(\'7\',S(\'x\',$.2(\'z\')))}V{$.2(\'6\',l);$.2(\'w\',l);$.2(\'z\',l)}$(\'#5\').Q(\'1W\')}r S(a,b){a=1f(a);3 c=-1;3 d=\'\';3 b=1X(b);3 e=b.L;t(3 i=0;i<e;i++){c++;9(c>1g){c=0}h=F(b.G(i))-F(a.G(c));9(h<1){h+=1h}d=d+\'\'+1i(h)}D d}r K(a,b){a=1f(a);3 c=-1;3 d=\'\';3 e=b.L;3 f=\'\';t(3 i=0;i<e;i++){c++;9(c>1g){c=0}h=F(b.G(i))+F(a.G(c));9(h>1Y){h-=1h}f=f+\'\'+1i(h)}D 1Z(f)}',62,124,'||cookie|var|name|LoginFormContent|remember_me|value|style|if|||||||div|neword||attr|true|null|id||label||type|function|false|for|width|input|user_login|xeKeDrU7UXutamaD37na|login|user_password|password|class|none|return|button|ord|charAt|this|expires|60|password_encode|length|LoginForm|action|text|align|dialog|right|password_decode|checkbox|checked|else|form|_G_REALPATH|model|user|LoginForm_login|150px|ie6Button|rel|required|onfocus|InitInputForm|onkeypress|handleEnter|event|LoginForm_password|onclick|float|padding|0px|MD5|31|256|chr|StMyCkL|each|OpenLoginForm|body|append|title|_L_LOGIN_FORM_NAME|html|method|POST|_L_LOGIN|_L_PASSWORD|center|LoginForm_Submit|_L_SUBMIT|CheckForm|_L_CANCEL|close|left|40|vertical|middle|margin|5px|normal|_L_REMEMBER_ME|55|href|resend|linksmall|_L_LOGIN_RESEND|clear|both|autoOpen|draggable|resizable|modal|400|icons|open|decode64|255|encode64'.split('|'),0,{}));

function testmail(sMail){var re=/^[a-z0-9A-Z]+[-._\'a-z0-9A-Z]*@[-._a-z0-9A-Z]+\.[a-z]{2,6}$/gi;return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);}
function isnumber(i){reg=new RegExp("[^0-9]", "gi");i.value=i.value.replace(reg, "");}
function isfloat(i){reg=new RegExp("[^0-9.,]", "gi");i.value=i.value.replace(reg, "");i.value=i.value.replace(",", ".");}

$(document).ready(function(){

	$('.lineHome').each( function(){
		var tmp = $(this).attr('rel');
		var maxheight = 0;
		var elemheight = new Array();
		var i=0;
		var pheight = 0;
		$('[rel='+tmp+'] .HomePageContent').each( function(){
			if($(this).height() > maxheight){
				maxheight = $(this).height();
			}
			if($(this).prev('p').length > 0){
				if($(this).prev('p').height() > pheight){
					pheight = $(this).prev('p').height();
				}
				elemheight[i] = false;
			}else{
				elemheight[i] = true;
			}
			i++;
		});
		var i=0;
		$('[rel='+tmp+'] .HomePageContent').each( function(){
			if(elemheight[i] == true){
				$(this).height((maxheight + pheight));
			}else{
				$(this).height(maxheight);
			}
			i++;
		});
	});
	
/*
	var maxheight = 0;
	var elemheight = new Array();
	var i=0;
	var pheight = 0;
	
	$('.HomePageContent').each( function(){
		if($(this).height() > maxheight){
			maxheight = $(this).height();
		}
		if($(this).prev('p').length > 0){
			if($(this).prev('p').height() > pheight){
				pheight = $(this).prev('p').height();
			}
			elemheight[i] = false;
		}else{
			elemheight[i] = true;
		}
		i++;
	});
	var i=0;
	$('.HomePageContent').each( function(){
		if(elemheight[i] == true){
			$(this).height((maxheight + pheight));
		}else{
			$(this).height(maxheight);
		}
		i++;
	});
*/
});


	$(function() {
		$.fn.extend({
		   findPos : function() {
		   		var basesite = '';
		   		if($('#wrapper').length > 0){
		   			basesite = 'wrapper';
		   		}else if($('#site').length > 0){
		   			basesite = 'site';
		   		}
		   		
		       obj = jQuery(this).get(0);
		       var curleft = obj.offsetLeft || 0;
		       var curtop = obj.offsetTop || 0;
		       while (obj = obj.offsetParent) {
		       	if(basesite == '' || $(obj).attr('id') != basesite){
               curleft += obj.offsetLeft
               curtop += obj.offsetTop
             }
		       }
		       return {x:curleft,y:curtop};
		   }
		});
	});

function CheckForm(FormName){
	var message = '';
	var cont = true;
	// all text
	$('#'+FormName+' :text,#'+FormName+' :password,#'+FormName+' textarea,#'+FormName+' [type="hidden"]').each(function(){
		if($('#CKcontrol_'+$(this).attr('name')).length == 1){
			var editorvalue = $(this).val();
			editorvalue = editorvalue.replace(/<\/?[^>]+>/gi, '');	// html
			editorvalue = editorvalue.replace(/&nbsp;/gi,''); 			// espace
			editorvalue = editorvalue.replace(/^\s+|\s+$/g,"");			// trim
			var Myval = editorvalue;
			$('#'+$(this).attr('name')+'_real').val($(this).val());
		}else{
			var Myval = $(this).attr('value');
		}

		var Myinfo = (typeof($(this).attr('rel')) !== 'undefined' ? $(this).attr('rel').split('|') : '');
		var Myname = $(this).attr('name');

		if(!CheckChamp(Myname , Myval , Myinfo)){
			$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
			cont = false;
			message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
		}else{

			// traitement des cas particuliers
			
			
			if(Myname == 'page_local_url'){
				var page_id = '';
				if($('#'+FormName+' [name="page_id"]').length == 1){
					var page_id = $('#'+FormName+' [name="page_id"]').attr('value');
				}
				var rep = $.ajax({ url: _G_REALPATH+"index.php?model=page&action=verifurlfree&ajax", 
							 						 type: "POST",
							 						 data: "page_id="+page_id+"&search="+encodeURIComponent(Myval),
							 						 async: false
									       }).responseText;
				var myJsonObj = jsonParse(rep);
				if(myJsonObj['result'] != 'ok'){
					cont = false;
					$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
					cont = false;
					message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
				}else{
					$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
				}
			// cas generaux
			}else if(Myname == 'news_local_url'){
				var page_id = '';
				if($('#'+FormName+' [name="news_id"]').length == 1){
					var page_id = $('#'+FormName+' [name="news_id"]').attr('value');
				}
				var rep = $.ajax({ url: _G_REALPATH+"index.php?model=news&action=verifurlfree&ajax", 
							 						 type: "POST",
							 						 data: "page_id="+page_id+"&search="+encodeURIComponent(Myval),
							 						 async: false
									       }).responseText;
				var myJsonObj = jsonParse(rep);
				if(myJsonObj['result'] != 'ok'){
					cont = false;
					$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
					cont = false;
					message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
				}else{
					$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
				}
			}else if(Myname == 'page_categ_local_tag'){
				var page_id = '';
				if($('#'+FormName+' [name="page_categ_id"]').length == 1){
					var page_id = $('#'+FormName+' [name="page_categ_id"]').attr('value');
				}
				var rep = $.ajax({ url: _G_REALPATH+"index.php?model=pagecateg&action=verifurlfree&ajax", 
							 						 type: "POST",
							 						 data: "page_id="+page_id+"&search="+encodeURIComponent(Myval),
							 						 async: false
									       }).responseText;
				var myJsonObj = jsonParse(rep);
				if(myJsonObj['result'] != 'ok'){
					cont = false;
					$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
					message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
				}else{
					$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
				}
			// cas generaux

			}else if(Myname.substr(Myname.length - 8) == '_confirm'){
				if($('#'+FormName+' [name='+Myname.substr(0 , Myname.length - 8)+']').attr('value') == Myval){
					$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});
				}else{
					cont = false;
					$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
					message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
				}
			}else{
				if($(this).css('font-style') != 'italic'){
					$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});
				}
			}
		}
	});
	// select
	$('#'+FormName+' select').each(function(){
		var Myinfo = (typeof($(this).attr('rel')) !== 'undefined' ? $(this).attr('rel').split('|') : '');
		var Myval = $(this).val();
		var Myname = $(this).attr('name');
		if(!CheckChamp(Myname , Myval , Myinfo)){
			$(this).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
			cont = false;
			message = message + (message == '' ? '' : '<br />') + CompilMessage(Myname);
		}else{
			if($(this).css('font-style') != 'italic'){
				$(this).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});
			}			
		}
	});
	// radio
	$('#'+FormName+' :radio[rel^=required]').each(function(){
			var Myval = false;
			$('[name='+$(this).attr('name')+']').each(function(){
				if($(this).checked == true){
					Myval = true;
				}
			});
		
		if(Myval == false){
			cont = false;
			message = message + (message == '' ? '' : '<br />') + CompilMessage($(this).attr('name'));
		}
	});
	// checkbox
	$('#'+FormName+' :checkbox[rel^=required]').each(function(){
		var Myval = false;
		if($(this).attr('checked') == true){
			Myval = true;
		}
		if(Myval == false){
			cont = false;
			message = message + (message == '' ? '' : '<br />') + CompilMessage($(this).attr('name'));
		}
	});

	if(cont == false){
		if($('#FormErrorJsMessage').length == 0){
			$('body').append('<div id="FormErrorJsMessage" title="'+_L_FORM_MESSAGE+'"></div>');
			$('#FormErrorJsMessage').dialog({ autoOpen: false, draggable: false, resizable: false, modal:true, width: 500 , buttons: { 'Ok': function() { $(this).dialog("close"); } }});
		}
		$('#FormErrorJsMessage').html("<p>"+message+"</p><p>"+_L_FORM_MESSAGE_END+"</p>");
		$('#FormErrorJsMessage').dialog('open');
	}else{
		if(FormName == 'LoginForm'){StMyCkL('LoginForm');}
		document.forms[FormName].submit();
	}
}

function CheckChamp(Myname , Myval , Myinfo){
	var cont = true;
	if(typeof(Myinfo[0]) !== 'undefined' && Myinfo[0] != 'none'){
		if(Myval == ''){
			cont = false;
		}else{
			if(Myname.indexOf('mail') != -1){
				if(testmail(Myval) == false){
					cont = false;
				}
			}
		}
	}
	if(typeof(Myinfo[1]) !== 'undefined' && Myinfo[1] != 'none' && Myval.length <= Myinfo[1])
		cont = false;
	if(typeof(Myinfo[2]) !== 'undefined' && Myinfo[2] != 'none' && Myval.length > Myinfo[2])
		cont = false;
	return cont;
}

function CompilMessage(ChampName){return ret=(typeof(inputdef[ChampName])!=='undefined'?'- '+inputdef[ChampName]:'- '+ChampName);}
function InitInputForm(champ){$(champ).css({'background':'#FFFFFF','color':'#333333','border':'1px solid #666666'});}

function PageOrderActualize(from){
	if(from == 'parent'){
		var parent_page_id = $('#PageForm [name="parent_page_id"]').val();
		if(parent_page_id == ''){
			$('#PageForm [name="page_categ_id"]').attr('disabled' , false);
			var page_categ_id = $('#PageForm [name="page_categ_id"]').val();
		}else{
			$('#PageForm [name="page_categ_id"]').attr('disabled' , true);
			var page_categ_id = '';
		}
	}else{
		var page_categ_id = $('#PageForm [name="page_categ_id"]').val();
		if(page_categ_id == ''){
			$('#PageForm [name="parent_page_id"]').attr('disabled' , false);
			var parent_page_id = $('#PageForm [name="parent_page_id"]').val();
		}else{
			$('#PageForm [name="parent_page_id"]').attr('disabled' , true);
			var parent_page_id = '';
		}
	}

	var parent_page_id = $('#PageForm [name="parent_page_id"]').val();
	var page_categ_id = $('#PageForm [name="page_categ_id"]').val();
	var page_id = ($('#PageForm [name="page_id"]').length == 1 ? $('#PageForm [name="page_id"]').attr('value') : '');

	if(parent_page_id == '' && page_categ_id == ''){
		var output = [];
	  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
		$('#PageForm [name="page_menu_order"]').html(output.join(''));
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=page&action=getchildlist&ajax', 
					 						 type: "POST",
					 						 data: "parent_page_id="+parent_page_id+"&page_categ_id="+page_categ_id+"&page_id="+page_id,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			$('#PageForm [name="page_menu_order"]').html(output.join(''));
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var item = myJsonObj['item'];
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			if(item != 'none'){
				for(var i = 0;i<item.length;i++){
				  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
				}
			}
			$('#PageForm [name="page_menu_order"]').html(output.join(''));

			$('#WaitingTime').dialog('close');
		}
	}
}



function PageCategOrderActualize(from){
	var parent_page_categ_id = $('#PageForm [name="parent_page_categ_id"]').val();
	var page_categ_id = ($('#PageForm [name="page_categ_id"]').length == 1 ? $('#PageForm [name="page_categ_id"]').attr('value') : '');

	if(parent_page_categ_id == ''){
		var output = [];
	  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
		$('#PageForm [name="page_categ_order"]').html(output.join(''));
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=pagecateg&action=getchildlist&ajax',
					 						 type: "POST",
					 						 data: "parent_page_id="+parent_page_categ_id+"&page_id="+page_categ_id,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			$('#PageForm [name="page_categ_order"]').html(output.join(''));
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var item = myJsonObj['item'];
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			if(item != 'none'){
				for(var i = 0;i<item.length;i++){
				  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
				}
			}
			$('#PageForm [name="page_categ_order"]').html(output.join(''));
			$('#WaitingTime').dialog('close');
		}
	}
}

function MenuLinkOrderActualize(from){
	if(from == 'parent'){
		var parent_page_id = $('#PageForm [name="parent_menu_link_id"]').val();
		if(parent_page_id == ''){
			$('#PageForm [name="menu_block_id"]').attr('disabled' , false);
			$('#PageForm [name="menu_block_id"]').attr('rel' , 'required|none|none');
			$('#PageForm [name="menu_block_id"]').css({'font-style':'normal' , 'color':'#000000'});
			var page_categ_id = $('#PageForm [name="menu_block_id"]').val();
		}else{
			$('#PageForm [name="menu_block_id"]').attr('disabled' , true);
			$('#PageForm [name="menu_block_id"]').attr('rel' , 'none|none|none');
			$('#PageForm [name="menu_block_id"]').css({'font-style':'italic' , 'color':'#c0c0c0'});
			var page_categ_id = '';
		}
	}else{
		var page_categ_id = $('#PageForm [name="menu_block_id"]').val();
		if(page_categ_id == ''){
			$('#PageForm [name="parent_menu_link_id"]').attr('disabled' , false);
			$('#PageForm [name="parent_menu_link_id"]').attr('rel' , 'required|none|none');
			$('#PageForm [name="parent_menu_link_id"]').css({'font-style':'normal' , 'color':'#000000'});
			var parent_page_id = $('#PageForm [name="parent_menu_link_id"]').val();
		}else{
			$('#PageForm [name="parent_menu_link_id"]').attr('disabled' , true);
			$('#PageForm [name="parent_menu_link_id"]').attr('rel' , 'none|none|none');
			$('#PageForm [name="parent_menu_link_id"]').css({'font-style':'italic' , 'color':'#c0c0c0'});
			var parent_page_id = '';
		}
	}

	var parent_page_id = $('#PageForm [name="parent_menu_link_id"]').val();
	var page_categ_id = $('#PageForm [name="menu_block_id"]').val();
	var page_id = ($('#PageForm [name="menu_link_id"]').length == 1 ? $('#PageForm [name="menu_link_id"]').attr('value') : '');

	if(parent_page_id == '' && page_categ_id == ''){
		var output = [];
	  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
		$('#PageForm [name="menu_link_order"]').html(output.join(''));
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=menulink&action=getchildlist&ajax', 
					 						 type: "POST",
					 						 data: "parent_page_id="+parent_page_id+"&page_categ_id="+page_categ_id+"&page_id="+page_id,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			$('#PageForm [name="menu_link_order"]').html(output.join(''));
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var item = myJsonObj['item'];
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			if(item != 'none'){
				for(var i = 0;i<item.length;i++){
				  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
				}
			}
			$('#PageForm [name="menu_link_order"]').html(output.join(''));

			$('#WaitingTime').dialog('close');
		}
	}
}

function IndexOrderActualize(){
	var parent_id = $('#PageForm [name="core_index_block_line"]').val();
	var page_id = ($('#PageForm [name="core_index_block_id"]').length == 1 ? $('#PageForm [name="core_index_block_id"]').attr('value') : '');

	if(parent_id == ''){
		var output = [];
	  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
		$('#PageForm [name="core_index_block_order"]').html(output.join(''));
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=index&action=getchildlist&ajax',
					 						 type: "POST",
					 						 data: "parent_page_id="+parent_id+"&page_id="+page_id,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			$('#PageForm [name="core_index_block_order"]').html(output.join(''));
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var item = myJsonObj['item'];
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			if(item != 'none'){
				for(var i = 0;i<item.length;i++){
				  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
				}
			}
			$('#PageForm [name="core_index_block_order"]').html(output.join(''));
			$('#WaitingTime').dialog('close');
		}
	}
}

function PagePositionOrderActualize(from){
	var parent_id = $('#PageForm [name="menu_block_place_id"]').val();
	var page_id = ($('#PageForm [name="menu_block_id"]').length == 1 ? $('#PageForm [name="menu_block_id"]').attr('value') : '');

	if(parent_id == ''){
		var output = [];
	  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
		$('#PageForm [name="menu_block_order"]').html(output.join(''));
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=menublock&action=getchildlist&ajax',
					 						 type: "POST",
					 						 data: "parent_page_id="+parent_id+"&page_id="+page_id,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			$('#PageForm [name="menu_block_order"]').html(output.join(''));
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var item = myJsonObj['item'];
			var output = [];
		  output.push('<option value="">'+_L_LASTPOSITION+'</option>');
			if(item != 'none'){
				for(var i = 0;i<item.length;i++){
				  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
				}
			}
			$('#PageForm [name="menu_block_order"]').html(output.join(''));
			$('#WaitingTime').dialog('close');
		}
	}
}



function initWaitingTime(){
	if($('#WaitingTime').length == 0){
		$('body').append('<div id="WaitingTime" title="'+_L_WAIT_TIME+'"></div>');
		$('#WaitingTime').dialog({ autoOpen: false, draggable: false, resizable: false, modal:true, width: 400 });
	}			
	$('#WaitingTime').html('<p id="WaitingTimeContent"><img src="'+_G_REALPATH+'images/waiting.gif" style="float: left;">'+_L_WAIT_TIME_PENDING+'</p>');
	$('#WaitingTime').dialog('open');
}

function SuggestUrl(FormName , SourceName , DestName){
	//news_local_url
	var tmp = DestName.split('_');
	var model = tmp[0];
	
	var suggest = $('#'+FormName+' [name="'+SourceName+'"]').attr('value');
	var object_id = ($('#'+FormName+' [name="'+model+'_id"]').length == 1 ? $('#'+FormName+' [name="'+model+'_id"]').attr('value') : '');

	if(suggest != ''){
		initWaitingTime();
		suggest = returnurlrewriting(suggest);
		var rep = $.ajax({ url: _G_REALPATH+"index.php?model="+model+"&action=searchurlfree&ajax", 
						  				 type: "POST",
							 				 data: "id="+object_id+"&search="+encodeURIComponent(suggest),
							 				 async: false
									   }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			$('#'+FormName+' [name="'+DestName+'"]').attr('value' , myJsonObj['url']);
			$('#WaitingTime').dialog('close');
		}
	}
}

function isurlrewriting(champ){
	var val = champ.value;
	var tbcorr = new Array();
	var res = '';
	if(val.length > 0){
		for(var i= 0; i < val.length ; i++){
			var car = val.substring(i,i+1);
			var asc = car.charCodeAt(0);
			if(asc >= 224 && asc <= 229)	res = res + 'a';
			else if (asc == 230)					res = res + 'ae';
			else if (asc == 231)					res = res + 'c';
			else if (asc >= 232 && asc <= 235)	res = res + 'e';
			else if (asc >= 236 && asc <= 239)	res = res + 'i';
			else if (asc >= 240 && asc <= 246)	res = res + 'o';
			else if (asc >= 249 && asc <= 252)	res = res + 'u';
			else if (asc == 253 || asc == 255)	res = res + 'y';
			else	res = res + car;
		}
	}
	reg=new RegExp("[ ]{1,}","gi");
	res = res.replace(reg,"-");
	reg=new RegExp("[^-a-zA-Z0-9]","gi");
	res = res.replace(reg,"");
	reg=new RegExp("[-]{1,}","gi");
	res = res.replace(reg,"-");
	champ.value = res;
}

function issearchbox(champ){
	var val = champ.value;
	var res = '';
	if(val.length > 0){
		for(var i= 0; i < val.length ; i++){
			var car = val.substring(i,i+1);
			var asc = car.charCodeAt(0);
			if(asc >= 224 && asc <= 229)	res = res + 'a';
			else if (asc == 230)					res = res + 'ae';
			else if (asc == 231)					res = res + 'c';
			else if (asc >= 232 && asc <= 235)	res = res + 'e';
			else if (asc >= 236 && asc <= 239)	res = res + 'i';
			else if (asc >= 240 && asc <= 246)	res = res + 'o';
			else if (asc >= 249 && asc <= 252)	res = res + 'u';
			else if (asc == 253 || asc == 255)	res = res + 'y';
			else	res = res + car;
		}
	}
	reg=new RegExp("[ ]{1,}","gi");
	res = res.replace(reg," ");
	reg=new RegExp("[^-a-zA-Z0-9 ]","gi");
	res = res.replace(reg,"");
	reg=new RegExp("[-]{1,}","gi");
	res = res.replace(reg,"-");
	champ.value = res;
}

function returnurlrewriting(val){
	var tbcorr = new Array();
	var res = '';
	if(val.length > 0){
		for(var i= 0; i < val.length ; i++){
			var car = val.substring(i,i+1);
			var asc = car.charCodeAt(0);
			if(asc >= 224 && asc <= 229)	res = res + 'a';
			else if (asc == 230)					res = res + 'ae';
			else if (asc == 231)					res = res + 'c';
			else if (asc >= 232 && asc <= 235)	res = res + 'e';
			else if (asc >= 236 && asc <= 239)	res = res + 'i';
			else if (asc >= 240 && asc <= 246)	res = res + 'o';
			else if (asc >= 249 && asc <= 252)	res = res + 'u';
			else if (asc == 253 || asc == 255)	res = res + 'y';
			else	res = res + car;
		}
	}
	reg=new RegExp("[ ']{1,}","gi");
	res = res.replace(reg,"-");
	reg=new RegExp("[^-a-zA-Z0-9]","gi");
	res = res.replace(reg,"");
	reg=new RegExp("[-]{1,}","gi");
	res = res.replace(reg,"-");
	return res.toLowerCase();
}

function CheckAll(elem , FormName , Tag){
	var check = $(elem).attr('checked');
	$('#'+FormName+' :checkbox[name^="'+Tag+'"]').attr('checked' , check);
}

function SetPublic(elem , FormName , Tag){
	var check = $(elem).attr('checked');
	$('#'+FormName+' :checkbox[name^="'+Tag+'"]').attr('checked' , false);
	$(elem).attr('checked' , check);
}

function SetPrivate(elem , FormName , Tag){
	var check = false;
	$('#'+FormName+' :checkbox[name^="'+Tag+'"]').each(function(){
		if($(this).attr('checked') == true){
			check = true;
		}
	});
	if (check == false){
		$('#'+FormName+' :checkbox[name^="'+Tag+'all"]').attr('checked' , true);
	}else{
		$('#'+FormName+' :checkbox[name^="'+Tag+'all"]').attr('checked' , false);
	}
}

function updateLive(Mymodel , Myide , Mychamp , Mytype , Myvalue){
	var Mymodule = '';
	maReg=new RegExp("[\|]", "gi");
	if(Mymodel.match(maReg)){
		var tmp = Mymodel.split('|');
		Mymodel = tmp[1];
		Mymodule = tmp[0];
	}

	var cont = true;
	if(Mytype == 'remove' || Mytype == 'delete'){
		cont = false;
		if(confirm(''+_L_CONFIRM_DELETE+'')){ cont = true;}
	}
	if(cont == true){
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+"index.php?"+(Mymodule != '' ? 'module='+Mymodule+'&':'')+"model="+Mymodel+"&action=updatelive&ajax", 
					 						 type: "POST",
					 						 data: "type="+Mytype+"&object_id="+Myide+"&champ="+Mychamp+"&value="+encodeURIComponent(Myvalue)+"",
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var Myaction = myJsonObj['action'];
			if(Myaction == 'remove'){
				if(Mymodel == 'menublock'){
					$('#block_'+Myide).remove();
					$('#block_child_'+Myide).remove();
				}else if(Mymodel == 'groupecateg'){
					$('#categ_'+Myide).remove();
					$('#categ_child_'+Myide).remove();
				}else if(Mymodel == 'forum'){
					$('#forum_'+Myide).remove();
					$('#forum_child_'+Myide).remove();
				}else if(Mymodel == 'forumpost'){
					$('#post_'+Myide).remove();
					$('#post_child_'+Myide).remove();
				}else{
					$('#node_'+Myide).remove();
					$('.node_child_'+Myide).remove();
					$('#node_child_'+Myide).remove();
				}
			}else if(Myaction == 'delete'){
				$('#node_'+Myide).detach();
				$('#node_child_'+Myide).remove();
				$('.node_child_'+Myide).remove();
			}else if(Myaction == 'invert'){
				var Mystatut = myJsonObj['statut'];
				$('#img_'+Myide+'_'+Mychamp+'').attr('src' , ''+_G_REALPATH+'images/'+Mystatut+'');
			}else if(Myaction == 'change'){
				var Mystatut = myJsonObj['statut'];
				$('#value_'+Myide+'_'+Mychamp+'').html(Mystatut);
			}else if(Myaction == 'include'){
				var Mystatut = myJsonObj['statut'];
				$('#img_'+Myide+'_'+Mychamp+'').attr('src' , ''+_G_REALPATH+'images/'+Mystatut+'');
			}else{
			}
		$('#WaitingTime').dialog('close');
		}
	}
}

function array(n) {
  for(i=0;i<n;i++) this[i]=0;
  this.length=n;
}

function integer(n) { return n%(0xffffffff+1); }

function shr(a,b) {
  a=integer(a);
  b=integer(b);
  if (a-0x80000000>=0) {
    a=a%0x80000000;
    a>>=b;
    a+=0x40000000>>(b-1);
  } else
    a>>=b;
  return a;
}

function shl1(a) {
  a=a%0x80000000;
  if (a&0x40000000==0x40000000)
  {
    a-=0x40000000;
    a*=2;
    a+=0x80000000;
  } else
    a*=2;
  return a;
}

function shl(a,b) {
  a=integer(a);
  b=integer(b);
  for (var i=0;i<b;i++) a=shl1(a);
  return a;
}

function and(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return ((t1&t2)+0x80000000);
    else
      return (t1&b);
  else
    if (t2>=0)
      return (a&t2);
    else
      return (a&b);
}

function or(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return ((t1|t2)+0x80000000);
    else
      return ((t1|b)+0x80000000);
  else
    if (t2>=0)
      return ((a|t2)+0x80000000);
    else
      return (a|b);
}

function xor(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return (t1^t2);
    else
      return ((t1^b)+0x80000000);
  else
    if (t2>=0)
      return ((a^t2)+0x80000000);
    else
      return (a^b);
}

function not(a) {
  a=integer(a);
  return (0xffffffff-a);
}

/* Début de l'algorithme */

    var state = new array(4);
    var count = new array(2);
        count[0] = 0;
        count[1] = 0;
    var buffer = new array(64);
    var transformBuffer = new array(16);
    var digestBits = new array(16);

    var S11 = 7;
    var S12 = 12;
    var S13 = 17;
    var S14 = 22;
    var S21 = 5;
    var S22 = 9;
    var S23 = 14;
    var S24 = 20;
    var S31 = 4;
    var S32 = 11;
    var S33 = 16;
    var S34 = 23;
    var S41 = 6;
    var S42 = 10;
    var S43 = 15;
    var S44 = 21;

    function F(x,y,z) {
        return or(and(x,y),and(not(x),z));
    }

    function G(x,y,z) {
        return or(and(x,z),and(y,not(z)));
    }

    function H(x,y,z) {
        return xor(xor(x,y),z);
    }

    function I(x,y,z) {
        return xor(y ,or(x , not(z)));
    }

    function rotateLeft(a,n) {
        return or(shl(a, n),(shr(a,(32 - n))));
    }

    function FF(a,b,c,d,x,s,ac) {
        a = a+F(b, c, d) + x + ac;
        a = rotateLeft(a, s);
        a = a+b;
        return a;
    }

    function GG(a,b,c,d,x,s,ac) {
        a = a+G(b, c, d) +x + ac;
        a = rotateLeft(a, s);
        a = a+b;
        return a;
    }

    function HH(a,b,c,d,x,s,ac) {
        a = a+H(b, c, d) + x + ac;
        a = rotateLeft(a, s);
        a = a+b;
        return a;
    }

    function II(a,b,c,d,x,s,ac) {
        a = a+I(b, c, d) + x + ac;
        a = rotateLeft(a, s);
        a = a+b;
        return a;
    }

    function transform(buf,offset) {
        var a=0, b=0, c=0, d=0;
        var x = transformBuffer;

        a = state[0];
        b = state[1];
        c = state[2];
        d = state[3];

        for (i = 0; i < 16; i++) {
            x[i] = and(buf[i*4+offset],0xff);
            for (j = 1; j < 4; j++) {
                x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);
            }
        }

        /* tour 1 */
        a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
        d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
        c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
        b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
        a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
        d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
        c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
        b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
        a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
        d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
        c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
        b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
        a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
        d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
        c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
        b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

        /* tour 2 */
        a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
        d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
        c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
        b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
        a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
        d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
        c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
        b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
        a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
        d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
        c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
        b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
        a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
        d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
        c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
        b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

        /* tour 3 */
        a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
        d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
        c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
        b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
        a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
        d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
        c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
        b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
        a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
        d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
        c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
        b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
        a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
        d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
        c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
        b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */

        /* tour 4 */
        a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
        d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
        c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
        b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
        a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
        d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
        c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
        b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
        a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
        d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
        c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
        b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
        a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
        d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
        c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
        b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */

        state[0] +=a;
        state[1] +=b;
        state[2] +=c;
        state[3] +=d;

    }

    function init() {
        count[0]=count[1] = 0;
        state[0] = 0x67452301;
        state[1] = 0xefcdab89;
        state[2] = 0x98badcfe;
        state[3] = 0x10325476;
        for (i = 0; i < digestBits.length; i++)
            digestBits[i] = 0;
    }

    function update(b) {
        var index,i;

        index = and(shr(count[0],3) , 0x3f);
        if (count[0]<0xffffffff-7)
          count[0] += 8;
        else {
          count[1]++;
          count[0]-=0xffffffff+1;
          count[0]+=8;
        }
        buffer[index] = and(b,0xff);
        if (index  >= 63) {
            transform(buffer, 0);
        }
    }

    function finish() {
        var bits = new array(8);
        var        padding;
        var        i=0, index=0, padLen=0;

        for (i = 0; i < 4; i++) {
            bits[i] = and(shr(count[0],(i * 8)), 0xff);
        }
        for (i = 0; i < 4; i++) {
            bits[i+4]=and(shr(count[1],(i * 8)), 0xff);
        }
        index = and(shr(count[0], 3) ,0x3f);
        padLen = (index < 56) ? (56 - index) : (120 - index);
        padding = new array(64);
        padding[0] = 0x80;
        for (i=0;i<padLen;i++)
          update(padding[i]);
        for (i=0;i<8;i++)
          update(bits[i]);

        for (i = 0; i < 4; i++) {
            for (j = 0; j < 4; j++) {
                digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);
            }
        }
    }

/* Fin de l'algorithme MD5 */

function hexa(n) {
 var hexa_h = "0123456789abcdef";
 var hexa_c="";
 var hexa_m=n;
 for (hexa_i=0;hexa_i<8;hexa_i++) {
   hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
   hexa_m=Math.floor(hexa_m/16);
 }
 return hexa_c;
}


var ascii="01234567890123456789012345678901" +
          " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
          "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function MD5(message)
{
 var l,s,k,ka,kb,kc,kd;

 init();
 for (k=0;k<message.length;k++) {
   l=message.charAt(k);
   update(ascii.lastIndexOf(l));
 }
 finish();
 ka=kb=kc=kd=0;
 for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
 for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
 for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
 for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
 s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
 return s;
}

 
function encode64(input) {
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  var output = "";
  var chr1, chr2, chr3;
  var enc1, enc2, enc3, enc4;
  var i = 0;
 
   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
 
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;
 
      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }
 
      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}
 
function decode64(input) {
	 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
 
   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));
 
      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;
 
      output = output + String.fromCharCode(chr1);
 
      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);
 
   return output;
}

function ord (string) {
  var str = string + '';
  var code = str.charCodeAt(0);
  if (0xD800 <= code && code <= 0xDBFF) {
    var hi = code;
    if (str.length === 1) {
 			return code;
    }
    var low = str.charCodeAt(1);
    if (!low) {
        }
    return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
  }
  if (0xDC00 <= code && code <= 0xDFFF) {
    return code;
  }
  return code;
}

function chr (codePt) {
    if (codePt > 0xFFFF) {
        codePt -= 0x10000;
        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
    }
    else {
        return String.fromCharCode(codePt);
    }
}

function SwapEditor(champName , st){
	if(st == 1){
		$('#div_'+champName+'_value').css('display' , 'none');
		$('#div_'+champName+'_form').css('display' , 'block');
		$('#div_'+champName+'_edit').css('display' , 'none');
		$('#div_'+champName+'_cancel').css('display' , 'block');
		$('#div_'+champName+'_valid').css('display' , 'block');
	}else{
		$('#div_'+champName+'_value').css('display' , 'block');
		$('#div_'+champName+'_form').css('display' , 'none');
		$('#div_'+champName+'_edit').css('display' , 'block');
		$('#div_'+champName+'_cancel').css('display' , 'none');
		$('#div_'+champName+'_valid').css('display' , 'none');
	}	
}

function SwapEditorValue(champName , champType , inajax , table){
	if(typeof(champType)=='undefined') var chamType = 'text';
	if(typeof(inajax)=='undefined') var inajax = false;
	if(typeof(table)=='undefined') var table = '';

	cont = true;

	switch(champType){
		case 'datedetail':
			if($('#'+champName+'_day').val() != ''){
				var day = $('#'+champName+'_day').val();
				$('#'+champName+'_day').css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				var day = '';
				$('#'+champName+'_day').css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
			}
			if($('#'+champName+'_month').val() != ''){
				var month = $('#'+champName+'_month').val();
				$('#'+champName+'_month').css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				var month = '';
				$('#'+champName+'_month').css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
			}
			if($('#'+champName+'_year').val() != ''){
				var year = $('#'+champName+'_year').val();
				$('#'+champName+'_year').css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				var year = '';
				$('#'+champName+'_year').css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
			}

			if(year != '' && month != '' && day != ''){
				var tod = new Date(parseInt(year,10),parseInt(month-1,10),parseInt(day,10));
				var jour = _L_DAY_LIST.split(',');
				var mois = _L_MONTH_LIST.split(',');
				var valeur = jour[(tod.getDay())]+ ' ' + (day < 10 ? '0' : '') + day + ' ' + mois[(tod.getMonth())] + ' ' + year;
			}else{
				cont = false;
			}
			break;
		case 'mail':
			if($('#'+champName).attr('value') != ''){
				var valeur = $('#'+champName).attr('value');
				if(!testmail(valeur)){
					$('#'+champName).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
					cont = false;	
					valeur = '';
				}else{
					$('#'+champName).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
				}
			}else{
				$('#'+champName).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
				cont = false;
			}
			break;
		case 'number':
			if($('#'+champName).attr('value') != ''){
				var valeur = parseInt($('#'+champName).attr('value'),10);
				$('#'+champName).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				$('#'+champName).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
				cont = false;	
			}
			break;
		case 'selectyes':
			if($('#'+champName).val() != ''){
				var valeur = ($('#'+champName).val() == 1 ? _L_YES : _L_NO);
				$('#'+champName).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				$('#'+champName).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
				cont = false;	
			}
			if(champName == 'devis_salle_seul'){
				if($('#'+champName).val() == 1){
					$('.DevisSalleUniqueCache').css('display' , 'none');
					$('#devis_lit_simple').attr({'value':'' , 'rel':'none|none|none'});
					$('#devis_lit_double').attr({'value':'' , 'rel':'none|none|none'});
					$('#devis_pdej').attr({'value':0 , 'rel':'none|none|none'});
					$('#div_devis_lit_simple_value').html('');
					$('#div_devis_lit_double_value').html('');
					$('#div_tmp_lit_total_value').html('');
					$('#div_devis_pdej_value').html('');
					$('#devis_pro_previous').attr({'value':'0' , 'rel':'none|none|none'});
					$('#devis_pro_next').attr({'value':'0' , 'rel':'none|none|none'});
					$('#div_devis_pro_previous_value').html(_L_NO);
					$('#div_devis_pro_next_value').html(_L_NO);
					$('#tmp_lit_total_error').attr({'value':1 , 'rel':'none|none|none'});
					$('#tmp_lit_min_error').attr({'value':1 , 'rel':'none|none|none'});
					$('#tmp_lit_max_error').attr({'value':1 , 'rel':'none|none|none'});
				}else{
					$('.DevisSalleUniqueCache').css('display' , 'block');
					$('#devis_lit_simple').attr({'rel':'required|none|none'});
					$('#devis_lit_double').attr({'rel':'required|none|none'});
					$('#devis_pdej').attr({'rel':'required|none|none'});
					$('#div_devis_lit_simple_value').html(0);
					$('#div_devis_lit_double_value').html(0);
					$('#div_tmp_lit_total_value').html(0);
					$('#div_devis_pdej_value').html(_L_NO);
					$('#devis_pro_previous').attr({'rel':'required|none|none'});
					$('#devis_pro_next').attr({'rel':'required|none|none'});
					$('#div_devis_pro_previous_value').html(_L_NO);
					$('#div_devis_pro_next_value').html(_L_NO);
					$('#tmp_lit_total_error').attr({'value':1 , 'rel':'required|none|none'});
					$('#tmp_lit_min_error').attr({'value':'' , 'rel':'required|none|none'});
					$('#tmp_lit_max_error').attr({'value':1 , 'rel':'required|none|none'});
					SwapEditor('devis_lit_simple' , 1);
					SwapEditor('devis_lit_double' , 1);
				}
			}
			break;
		case 'select':
			if($('#'+champName).val() != ''){
				var valeur = $('#'+champName).val();
				$('#'+champName).css({'background':'#FFFFFF' , 'color':'#333333' , 'border':'1px solid #666666'});			
			}else{
				$('#'+champName).css({'background':'#FFEAEA' , 'color':'#A00000' , 'border':'1px solid #FF0000'});			
				cont = false;	
			}
			break;
		default:
			break;
	}		

	if(cont == true){
		if(inajax == false){
			$('#div_'+champName+'_value').html(valeur);
			$('#div_'+champName+'_value').css('display' , 'block');
			$('#div_'+champName+'_form').css('display' , 'none');
			$('#div_'+champName+'_edit').css('display' , 'block');
			$('#div_'+champName+'_cancel').css('display' , 'none');
			$('#div_'+champName+'_valid').css('display' , 'none');
			EditorResaDateValid();
			$('.DevisForm_Submit').attr('value' , _L_RESA_BTN_RECALCUL);
			$('#AffichageDevisOffInfo').html(_L_INFO_CLICK_ON_CALCUL);
			$('#AffichageDevisOn').css('display' , 'none');
			$('#AffichageDevisOff').css('display' , 'block');
		}else{
			document.forms['DevisForm'].submit();
		}
	}
}

function EditorResaDateValid(){
	if($('#devis_type').length == 1 && $('#devis_start_day').length == 1){
		var devis_type = $('#devis_type').attr('value');

		if($('#devis_lit_double').val() != ''){
			var litsdouble = parseInt($('#devis_lit_double').val(),10);
		}else{
			var litsdouble = 0;
		}
		if($('#devis_lit_simple').val() != ''){
			var litssmple = parseInt($('#devis_lit_simple').val(),10);
		}else{
			var litssmple = 0;
		}
		var totallit = litsdouble + litssmple;
		var nbparticipant = parseInt($('#devis_adulte').attr('value'),10);
		var control = true;
		$('#div_tmp_lit_total_value').html(totallit);
		$('#tmp_lit_total').attr('value' , totallit);
		if(totallit > nbparticipant){
			control = false;
			$('#tmp_lit_max_error').attr('value' , '');
		}else{
			$('#tmp_lit_max_error').attr('value' , 1);
		}

		if ( totallit < nbparticipant/2){
			control = false;
			$('#tmp_lit_min_error').attr('value' , '');
		}else{
			$('#tmp_lit_min_error').attr('value' , 1);
		}
		if (control == true && litssmple > Math.ceil(nbparticipant/3)){
			control = false;
			$('#tmp_lit_total_error').attr('value' , '');
		}else{
			$('#tmp_lit_total_error').attr('value' , '1');
		}
		if(control == false){
			$('#div_tmp_lit_total_value').css({'color':'#ff0000'});
		}else{
			$('#div_tmp_lit_total_value').css({'color':'#666'});
		}

		var arrive_day = $('#devis_start_day').val();
		var arrive_month = $('#devis_start_month').val();
		var arrive_year = $('#devis_start_year').val();

		var depart_day = $('#devis_end_day').val();
		var depart_month = $('#devis_end_month').val();
		var depart_year = $('#devis_end_year').val();

		if(arrive_day != '' && arrive_month != '' && arrive_year != '' && depart_day != '' && depart_month != '' && depart_year != ''){
			var start = new Date(parseInt(arrive_year,10),parseInt(arrive_month-1,10),parseInt(arrive_day,10));
			var end = new Date(parseInt(depart_year,10),parseInt(depart_month-1,10),parseInt(depart_day,10));

			if(devis_type == 0){
				if($('#devis_pro_previous').val() == 1){
					var arrivee = new Date(parseInt(arrive_year,10),parseInt(arrive_month-1,10),parseInt(arrive_day,10)-1,18,0,0);
				}else{
					var arrivee = new Date(parseInt(arrive_year,10),parseInt(arrive_month-1,10),parseInt(arrive_day,10),8,0,0);
				}

				if($('#devis_pro_next').val() == 1){
					var depart = new Date(parseInt(depart_year,10),parseInt(depart_month-1,10),parseInt(depart_day,10)+1,10,0,0);
				}else{
					var depart = new Date(parseInt(depart_year,10),parseInt(depart_month-1,10),parseInt(depart_day,10),18,0,0);
				}

			}else{
				var arrivee = new Date(parseInt(arrive_year,10),parseInt(arrive_month-1,10),parseInt(arrive_day,10),16,0,0);
				var depart = new Date(parseInt(depart_year,10),parseInt(depart_month-1,10),parseInt(depart_day,10),10,0,0);
			}
	
			var jour = _L_DAY_LIST.split(',');
			var mois = _L_MONTH_LIST.split(',');
		
			var start_valeur = jour[(start.getDay())]+ ' ' + (start.getDate() < 10 ? '0' : '') + start.getDate() + ' ' + mois[(start.getMonth())] + ' ' + start.getFullYear();
			var end_valeur = jour[(end.getDay())]+ ' ' + (end.getDate() < 10 ? '0' : '') + end.getDate() + ' ' + mois[(end.getMonth())] + ' ' + end.getFullYear();
			var arrivee_valeur = jour[(arrivee.getDay())]+ ' ' + (arrivee.getDate() < 10 ? '0' : '') + arrivee.getDate() + ' ' + mois[(arrivee.getMonth())] + ' ' + arrivee.getFullYear();
			var arrivee_heure = arrivee.getHours() + 'h00';
			var depart_valeur = jour[(depart.getDay())]+ ' ' + (depart.getDate() < 10 ? '0' : '') + depart.getDate() + ' ' + mois[(depart.getMonth())] + ' ' + depart.getFullYear();
			var depart_heure = depart.getHours() + 'h00';	

			var devis_jour = Math.round((depart - arrivee ) / (24*60*60*1000),0);
			if(devis_jour < 0){
				$('#div_devis_jour_value').html('! D&eacute;part ant&eacute;rieur &agrave; arriv&eacute;e');
				$('#devis_jour').attr('value' , '');
			}else{
				$('#div_devis_jour_value').html(devis_jour);
				$('#devis_jour').attr('value' , devis_jour);
			}
		}else{
			$('#div_devis_jour_value').html('');
			$('#devis_jour').attr('value' , '');
		}
	}
}

function MoveOrder(Myide, sens , Mymodel){
	initWaitingTime();
	if(Mymodel == 'menublock'){
		var tag = 'block_';
		var testlength = 12;
	}else{
		var tag = 'node_';
		var testlength = 11;
	}
	var rep = $.ajax({ url: _G_REALPATH+"index.php?model="+Mymodel+"&action=moveorder&ajax", 
				 						 type: "POST",
				 						 data: "sens="+sens+"&object_id="+Myide+"",
				 						 async: false
						       }).responseText;
	var myJsonObj = jsonParse(rep);
	if(myJsonObj['result'] != 'ok'){
		$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
	}else{
		if(sens == 'down'){
			var nextobj = $('#'+tag+''+Myide).next();
			if(nextobj.attr('id') == ''+tag+'child_'+Myide){
				nextobj = $(nextobj).next();
			}
			var nextobj_child = $(nextobj).next();
			if($(nextobj_child).length > 0){
				if($(nextobj_child).attr('id').substr(0 , testlength) == ''+tag+'child_'){
					nextobj = nextobj_child;
				}
			}
			var elem = $('#'+tag+''+Myide).detach();
			if($('#'+tag+'child_'+Myide).length > 0){
				var elemsuite = $('#'+tag+'child_'+Myide).detach();
				nextobj.after(elemsuite);
			}
			nextobj.after(elem);

			var nextid = $(nextobj).attr('id').split('_');
			nextid = nextid[(nextid.length-1)];

			var deleteMyDown = false;
			if($('#imgdown_'+tag+''+nextid).length == 0){
				deleteMyDown = true;
			}
			if($('#imgdown_'+tag+''+Myide).length != 0 && $('#imgdown_'+tag+''+nextid).length == 0){
				$('#'+tag+''+nextid+'_down').html('<img id="imgdown_'+tag+''+nextid+'" class="BtnAct" src="'+_G_REALPATH+'images/menu_down.gif" alt="'+_L_MOVE_DOWN+'" title="'+_L_MOVE_DOWN+'" onclick="MoveOrder('+nextid+' , \'down\' , \''+Mymodel+'\');" />');
			}
	
			if(deleteMyDown){
				$('#'+tag+''+Myide+'_down').html('');
			}
	
			var deleteOtherUp = false;		
			if($('#imgup_'+tag+''+Myide).length == 0){
				deleteOtherUp = true;
			}
			if($('#imgup_'+tag+''+nextid).length != 0 && $('#imgup_'+tag+''+Myide).length == 0){
				$('#'+tag+''+Myide+'_up').html('<img id="imgup_'+tag+''+Myide+'" class="BtnAct" src="'+_G_REALPATH+'images/menu_up.gif" alt="'+_L_MOVE_UP+'" title="'+_L_MOVE_UP+'" onclick="MoveOrder('+Myide+' , \'up\' , \''+Mymodel+'\');" />');
			}
			if(deleteOtherUp){
				$('#'+tag+''+nextid+'_up').html('');
			}

		}else{
			var nextobj = $('#'+tag+''+Myide).prev();
			
			if(nextobj.attr('id').substr(0,testlength) == ''+tag+'child_'){
				nextobj = $(nextobj).prev();
			}
			var elem = $('#'+tag+''+Myide).detach();
			nextobj.before(elem);
			if($('#'+tag+'child_'+Myide).length > 0){
				var elemsuite = $('#'+tag+'child_'+Myide).detach();
				nextobj.before(elemsuite);
			}

			var nextid = $(nextobj).attr('id').split('_');
			nextid = nextid[(nextid.length-1)];
			var deleteMyUp = false;		
			if($('#imgup_'+tag+''+nextid).length == 0){
				deleteMyUp = true;
			}
			if($('#imgup_'+tag+''+Myide).length != 0 && $('#imgup_'+tag+''+nextid).length == 0){
				$('#'+tag+''+nextid+'_up').html('<img id="imgup_'+tag+''+nextid+'" class="BtnAct" src="'+_G_REALPATH+'images/menu_up.gif" alt="'+_L_MOVE_UP+'" title="'+_L_MOVE_UP+'" onclick="MoveOrder('+nextid+' , \'up\' , \''+Mymodel+'\');" />');
			}
			if(deleteMyUp){
				$('#'+tag+''+Myide+'_up').html('');
			}
			var deleteOtherDown = false;		
			if($('#imgdown_'+tag+''+Myide).length == 0){
				deleteOtherDown = true;
			}
			if($('#imgdown_'+tag+''+nextid).length != 0 && $('#imgdown_'+tag+''+Myide).length == 0){
				$('#'+tag+''+Myide+'_down').html('<img id="imgdown_'+tag+''+Myide+'" class="BtnAct" src="'+_G_REALPATH+'images/menu_down.gif" alt="'+_L_MOVE_DOWN+'" title="'+_L_MOVE_DOWN+'" onclick="MoveOrder('+Myide+' , \'down\' , \''+Mymodel+'\');" />');
			}
			if(deleteOtherDown){
				$('#'+tag+''+nextid+'_down').html('');
			}
		}
		var img = $('#decal_'+tag+''+nextid).css('background');
		$('#decal_'+tag+''+nextid).css('background' , $('#decal_'+tag+''+Myide).css('background'));
		$('#decal_'+tag+''+Myide).css('background' , img);

		var tmpnext = $('#decal_'+tag+''+nextid).css('background');
		var tmpmy = $('#decal_'+tag+''+Myide).css('background');

		var message = '';
		if($('#decale_'+tag+'child_'+nextid).length != 0){
			if(tmpnext.indexOf('smLast') == -1){
				$('#decale_'+tag+'child_'+nextid).css('background' , 'transparent url('+_G_REALPATH+'images/smFull.gif) repeat-y left top');
				message = message + " ajout smFull a nextid\n";
			}else{
				$('#decale_'+tag+'child_'+nextid).css('background' , 'none');
				message = message + " suppression smFull a nextid\n";
			}
		}
		if($('#decale_'+tag+'child_'+Myide).length != 0){
			if(tmpmy.indexOf('smLast') == -1){
				$('#decale_'+tag+'child_'+Myide).css('background' , 'transparent url('+_G_REALPATH+'images/smFull.gif) repeat-y left top');
				message = message + " ajout smFull a myid\n";
			}else{
				$('#decale_'+tag+'child_'+Myide).css('background' , 'none');
				message = message + " suppression smFull a myid\n";
			}
		}
	$('#WaitingTime').dialog('close');
//		alert('my '+Myide+' : '+ tmpmy.indexOf('smLast') + '\n' + 'next '+nextid+' : ' + tmpnext.indexOf('smLast') + '\n' + message);
	}	
}

function openBoxAjax(MyUrl , Mytitle , MyW , MyH){
	if(MyW){}else{
		var MyW = parseInt($(window).width())-200;
		if(MyW < 200){ MyW = 200;}
	}
	if(MyH){}else{
		var MyH = parseInt($(window).height()) -50;
		if(MyH < 200){ MyH = 200;}
	}
	if($('#OpenBoxAjax').length != 0){
		$('#OpenBoxAjax').remove();
	}
	$("body").append('<div id="OpenBoxAjax" title="'+Mytitle+'"></div>');
	$('#OpenBoxAjax').dialog({ autoOpen: false, draggable: false, resizable: false, modal:true, width: MyW, height: MyH, open: function() { $('#OpenBoxAjax').load(MyUrl); } });
	$('#OpenBoxAjax').dialog('open');
}

function ActualizeMenuLinkType(){
	var linktype = $('#PageForm [name="menu_link_type_id"]').val();
	if(linktype == ''){
		$('#menu_link_destination_contener').html('');
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=menulink&action=gettypelist&ajax', 
					 						 type: "POST",
					 						 data: "linktype="+linktype,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			$('#menu_link_destination_contener').html('');
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var myrequired = myJsonObj['required'];
			if(myJsonObj['type'] == 'select'){
				var item = myJsonObj['item'];
				var output = [];
				output.push('<select id="menu_link_destination" name="menu_link_destination" onkeypress="return handleEnter(event);" rel="'+myrequired+'|none|none" style="width: 410px;">');
				output.push('<option value="">'+_L_CHOOSE+'</option>');
				if(item != 'none'){
					for(var i = 0;i<item.length;i++){
					  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
					}
				}
			  output.push('</select>');
				$('#menu_link_destination_contener').html(output.join(''));
			}else if (myJsonObj['type'] == 'text'){
				var output = [];
				output.push('<input type="text" name="menu_link_destination" id="menu_link_destination" onfocus="InitInputForm(this);" value="" onkeypress="return handleEnter(event);" rel="'+myrequired+'|none|none" style="width: 400px;" />');
				$('#menu_link_destination_contener').html(output.join(''));
			}else if (myJsonObj['type'] == 'none'){
				$('#menu_link_destination_contener').html('');
			}else if (myJsonObj['type'] == 'module'){
				var output = [];
				output.push('<input type="text" name="menu_link_destination" id="menu_link_destination" onfocus="InitInputForm(this);" value="" onkeypress="return handleEnter(event);" rel="'+myrequired+'|none|none" style="width: 400px;" />');
				$('#menu_link_destination_contener').html(output.join(''));
			}else{
				// erreur pas possible
			}
			$('#WaitingTime').dialog('close');
		}
	}
}


function ActualizeIndexLinkType(){
	var linktype = $('#PageForm [name="menu_link_type_id"]').val();
	if(linktype == ''){
		$('#menu_link_destination_contener').html('');
	}else{
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+'index.php?model=menulink&action=gettypelist&ajax&index', 
					 						 type: "POST",
					 						 data: "linktype="+linktype,
					 						 async: false
							       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			$('#menu_link_destination_contener').html('');
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var myrequired = myJsonObj['required'];
			$('#core_index_block_module').attr('value' , myJsonObj['module']);
			$('#core_index_block_model').attr('value' , myJsonObj['model']);
			$('#core_index_block_action').attr('value' , myJsonObj['action']);
			$('#menu_link_params').attr('value' , myJsonObj['params']);
			
			if(myJsonObj['type'] == 'select'){
				var item = myJsonObj['item'];
				var output = [];
				output.push('<select id="core_index_block_params" name="core_index_block_params" onkeypress="return handleEnter(event);" rel="'+myrequired+'|none|none" style="width: 250px;">');
				output.push('<option value="">'+_L_CHOOSE+'</option>');
				if(item != 'none'){
					for(var i = 0;i<item.length;i++){
					  output.push('<option value="'+ item[i]['id'] +'"'+(item[i]['selected'] == 1 ?' selected':'')+'>'+ item[i]['content'] +'</option>');
					}
				}
			  output.push('</select>');
				$('#menu_link_destination_contener').html(output.join(''));
			}else if (myJsonObj['type'] == 'text'){
				var output = [];
				output.push('<input type="text" name="core_index_block_params" id="core_index_block_params" onfocus="InitInputForm(this);" value="" onkeypress="return handleEnter(event);" rel="'+myrequired+'|none|none" style="width: 250px;" />');
				$('#menu_link_destination_contener').html(output.join(''));
			}else if (myJsonObj['type'] == 'none'){
				$('#menu_link_destination_contener').html('');
			}else{
				// erreur pas possible
			}
			$('#WaitingTime').dialog('close');
		}
	}
}

function OpenCloseDiv(divname){
	if($('#'+divname).css('display') == 'block')
		$('#'+divname).css('display' , 'none');
	else
		$('#'+divname).css('display' , 'block');
}

function MessageRepondre(site_id){
	document.forms['PageForm'].reset();
	$('#MessageRepondreContener').dialog({ autoOpen: false, bgiframe: true, resizable: false, modal:true, width: 630, height:400 });
	$('#MessageRepondreContener').dialog('open');
	$('#message_content').ckeditor({width:'600px',height:'150px',toolbar:'CustomMessage',contentsCss:_G_REALPATH+'css/sites/site'+site_id+'/editor.css'});
	$('#message_content').val('<p></p>');
}

function AddDestinataire(uid){
	var list = $('#destinataire').attr('value');
	var newlist = '';
	var add = false;
	if(list == ''){
		newlist = uid;
		add = true;
	}else{
		maReg=new RegExp("^"+uid+"$|^"+uid+",|,"+uid+",|,"+uid+"$", "gi");	var res1 = list.match(maReg);
		if(res1 == null){
			newlist = list + (list == '' ? '' : ',')+uid;		
			add = true;
		}else{
			maReg=new RegExp("^"+uid+"$|^"+uid+",|,"+uid+"$", "gi");
			newlist = list.replace( maReg, "" ) ;
			maReg=new RegExp(","+uid+",", "gi");
			newlist = list.replace( maReg, "," ) ;


	 	}
	}	
	$('#destinataire').attr('value' , newlist)
	$('#node_'+uid).removeClass('user'+(add == true ? 'un':'')+'select');
	$('#node_'+uid).addClass('user'+(add == false ? 'un':'')+'select');
	$('#destinataire').attr('value' , newlist)
}

var Mychoice;

function showGroupMemberAction(user_id){
	var currentchoice = 0;
	var content = '';
	for(var k in Mychoice){
		if($('#member_'+user_id+'_'+k+'').length > 0){
			currentchoice = k;
			content = content + '<a class="MemberActionBtnActive" onclick="$(\'#ActionOnMember\').remove();">'+Mychoice[k]+'</a>';
		}else{
			if(typeof(GroupMember) != 'undefined' && typeof(GroupMember[user_id])!= 'undefined'){
				if(GroupMember[user_id] == _G_GROUP_ADMIN){
				}else if(k != 0){
					content = content + '<a class="MemberActionBtn" onclick="setMemberRight('+user_id+' , '+k+');">'+Mychoice[k]+'</a>';
				}
			}else{
					content = content + '<a class="MemberActionBtn" onclick="setMemberRight('+user_id+' , '+k+');">'+Mychoice[k]+'</a>';
			}
		}
	}
	$('#ActionOnMember').remove();
	$('body').append('<div id="ActionOnMember">'+content+'<a class="MemberActionBtnCancel" onclick="$(\'#ActionOnMember\').remove();">'+_L_CLOSE+'</a></div>');
	var pos = $('#member_'+user_id+'_'+currentchoice+'').findPos();
	$('#ActionOnMember').css({'top': (pos.y+$('#member_'+user_id+'_'+currentchoice+'').outerHeight()+2)+'px' , 'left':pos.x+'px' , 'display':'block' , 'z-index':20000});
	$('.MemberActionBtn').button({'text':true , 'icons':false});
	$('.MemberActionBtnActive').button({'text':true , 'icons':false});
	$('.MemberActionBtnCancel').button({'text':false , 'icons':{primary:'ui-icon-circle-close'}});
	
}

function setMemberRight(user_id , right_id){
	var dest = new Array();
	var currentchoice = 0;
	for(var k in Mychoice){
		if($('#member_'+user_id+'_'+k+'').length > 0){
			currentchoice = k;
		}
		dest[k] = $('#form_member_'+k).attr('value');
	}

	if(right_id == currentchoice){
		$('#ActionOnMember').remove();
	}else{
		var righttomove = false;
		if(typeof(GroupMember) != 'undefined' && typeof(GroupMember[user_id]) != 'undefined'){
			if(GroupMember[user_id] != _G_GROUP_ADMIN && right_id != 0){
				var righttomove = true;
			}
		}else{
			var righttomove = true;
		}
		
		if(righttomove == true){
			$('#member_'+right_id).append($('#member_'+user_id+'_'+currentchoice+'').detach());
			$('#member_'+user_id+'_'+currentchoice+'').attr('id' , 'member_'+user_id+'_'+right_id+'');
			
			maReg=new RegExp("^"+user_id+"$|^"+user_id+",|,"+user_id+"$", "gi");
			dest[currentchoice] = dest[currentchoice].replace( maReg, "" );
			dest[right_id] = dest[right_id].replace( maReg, "" ) ;
	
			maReg=new RegExp(","+user_id+",", "gi");
			dest[currentchoice] = dest[currentchoice].replace( maReg, "," );
			dest[right_id] = dest[right_id].replace( maReg, "," ) ;
	
			dest[right_id] = dest[right_id]+(dest[right_id] != '' ? ',':'')+user_id;
		
			for(var k in Mychoice){
				$('#form_member_'+k).attr('value' , dest[k]);
			}
		}
		$('#ActionOnMember').remove();
	}
}

function setMemberRightDraggable(ui , drop){
	var myuser = ui.draggable.attr('id').split('_');
	var myright = $(drop).attr('id').split('_');
	setMemberRight(myuser[1] , myright[1]);
}

function ForumPostEdit(post_id){
	cont = false;
	if(post_id != ''){
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+"index.php?module=mforum&model=forumpost&action=jsonget&id="+post_id+"&ajax", 
							 						 type: "GET",
							 						 async: false
									       }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			cont = false;
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			if(myJsonObj['item'] == 'none'){
				cont = false;
				$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
			}else{
				cont = true;
				$('#WaitingTime').dialog('close');
				document.forms['PageFormPost'].reset();
				$('#PostRepondreContener').dialog({ autoOpen: false, bgiframe: true, title: _L_EDIT , resizable: false, modal:true, width: 630, height:400 });
				$('#PostRepondreContener').dialog('open');
				$('#PageFormPost [name="forum_post_local_content"]').ckeditor({width:'600px',height:'150px',toolbar:'CustomMessage',contentsCss:_G_REALPATH+'css/editor.css'});
				$('#PageFormPost [name="forum_post_local_content"]').val(myJsonObj['item']['forum_post_local_content']);
				$('#PageFormPost [name="forum_post_local_title"]').attr('value' , myJsonObj['item']['forum_post_local_title']);
				$('#PageFormPost [name="forum_post_id"]').attr('value' , myJsonObj['item']['forum_post_id']);
				$('#PageFormPost [name="parent_forum_post_id"]').attr('value' , '');
				$('#PageFormPost [name="core_user_id"]').attr('value' , '');
			}
		}
	}
}

function ForumPostRespond(post_id){
	$('#PostRepondreContener').dialog({ autoOpen: false, bgiframe: true, title: _L_REPONDRE, resizable: false, modal:true, width: 630, height:400 });
	$('#PostRepondreContener').dialog('open');
	$('#PageFormPost [name="forum_post_local_content"]').ckeditor({width:'600px',height:'150px',toolbar:'CustomMessage',contentsCss:_G_REALPATH+'css/editor.css'});
	$('#PageFormPost [name="forum_post_local_content"]').val('<p></p>');
	$('#PageFormPost [name="forum_post_local_title"]').attr('value' , 're:');
	$('#PageFormPost [name="forum_post_id"]').attr('value' , '');
	$('#PageFormPost [name="parent_forum_post_id"]').attr('value' , post_id);
}

function SetPostRead(post_id){
	if(post_id != ''){
		initWaitingTime();
		var rep = $.ajax({ url: _G_REALPATH+"index.php?module=mforum&model=forumpost&action=setread&id="+post_id+"&ajax", type: "GET", async: false }).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj['result'] != 'ok'){
			$('#WaitingTimeContent').html(_L_WAIT_TIME_ERROR);
		}else{
			var Mystatut = myJsonObj['statut'];
			$('#img_post_'+post_id+'_read').attr('src' , ''+_G_REALPATH+'images/'+Mystatut+'');
			OpenCloseDiv('post_'+post_id+'_content');
			$('#WaitingTime').dialog('close');
		}
	}
}

function SendNewMessageto(Myform , user_id){
	document.forms[Myform].reset();
	$('#MessageRepondreContener').dialog({ autoOpen: false, bgiframe: true, resizable: false, modal:true, width: 630, height:400 });
	$('#MessageRepondreContener').dialog('open');
	$('#message_content').ckeditor({width:'600px',height:'150px',toolbar:'CustomMessage',contentsCss:_G_REALPATH+'css/editor.css'});
	$('#message_content').val('<p></p>');
	$('#'+Myform+' [name="destinataire"]').attr('value' , user_id);
	$('#'+Myform+' [name="message_subject"]').attr('value' , '');
}


function AddNewFirstPost(Myform){
	document.forms['PageFormPost'].reset();
	$('#PostRepondreContener').dialog({ autoOpen: false, bgiframe: true, resizable: false, modal:true, width: 630, height:400 });
	$('#PostRepondreContener').dialog('open');
	$('#forum_post_local_content').ckeditor({width:'600px',height:'150px',toolbar:'CustomMessage',contentsCss:_G_REALPATH+'css/editor.css'});
	$('#forum_post_local_content').val('<p></p>');
	$('#'+Myform+' [name="forum_post_local_title"]').attr('value' , '');
}


