function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup(url, type, height, width){
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - width)/2;
	top = (document.body.clientHeight - height)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - width)/2;
	top = (self.innerHeight - height)/2;
  }
  
  wintype="toolbar=\'no\',menubar=\'no\',location=\'no\',scrollbars="+type+",resizable=0,top=0,left=0";
  wintype=wintype + ",height=" + height + ",width=" + width + ",top=" + top + ",left=" + left;
  var newwin = window.open(url,"Assistant"+type,wintype);
}

function search(obj,value)
{
	for (i=0; i < obj.length; i++)
	{
		if(obj[i].value==value)
		return i;
	}
}


function postform()
{
	postwizard();
}


function webeditor(field)
{
	window.open('kernel/services/webeditor/word.php?name='+field,'WebEditor','personalbar=no,toolbar=no,status=no,scrollbars=no,location=no,resizable=yes,menubar=no,titlebar=no,Top='+20+',Left='+20+',Width='+770+',Height='+620);
}

function webColor(value)
{
	return showModalDialog('kernel/services/color/color.htm',value,'status=no,scroll:no;resizable:no;dialogWidth:250px;dialogHeight:370px');
}

function webcalendar(name,hidden)
{
	window.open('kernel/services/calendar/calendar.php?name='+name+'&hidden='+hidden,'calendar_'+name,'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=200,height=180,left=20,top=20');
}

function validation()
{
	alert(document.form.webeditor.value);
}


function imageGallery(obj,img)
{
  document.wizard.obj.value=img;
}

function display()
{
	var name = document.wizard.template.value;
	if(name) document.image.src = "layers/images/"+name+".gif";
	else document.image.src = "layers/images/empty.gif";
}

//function replace
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

//Paste the textareavalue in another area value field1 => field2
function paste(field1, field2, size){
	var2 = eval("document.wizard."+field2+".value");
	if(var2 == ""){
		var1 = eval("document.wizard."+field1+".value");
		var1 = replace(var1,'"',"''");
		var1 = replace(var1,'\r',"<br>");
		var1 = replace(var1,'\n',"<br>");
		if(size!=""){
			if(var1.length > size){
				var3 = var1.substring(0,size-4)+"...";
			}
			else{
				var3 = var1;
			}
		}
		else{
			var3 = var1;
		}
		//var3 = replace(var3,"'","/'");
		vareval = "document.wizard."+field2+".value=\""+var3+"\";";
		eval(vareval);

		//alert(var3.length+" &&& "+var1.length);
	}

}


//format the date of the art_date_begin of the day if null
function formatdatebegin(){
	//var datebegin,daY,daM,daD;
	var today = new Date();

	datebegin = document.wizard.art_date_begin.value;
	if (datebegin == ""){
		daY = today.getYear();
		daM = today.getMonth()+1;
		daD = today.getDate();
		if(daM < 10){
      	daM ="0" + daM;
   	}
   	if(daD < 10){
      	daD ="0" + daD;
   	}
		document.wizard.art_date_begin.value = daY+"-"+daM+"-"+daD;
	}
}
//format the date of the art_date_begin of the day if null
function formatdateend(){
	var dateend;
	dateend = document.wizard.art_date_end.value;
	if (dateend == ""){
		document.wizard.art_date_end.value = "2030-12-31";
	}
}


function listBoxValid()
{
  var rub = document.wizard.dir_name.value;
  var tem = document.wizard.art_form.value;
  if (rub != "" && tem != ""){
  	document.wizard.submit();
  }
  else{
  	alert("Le gabarit ou la rubrique ne sont pas sélectionnés");
  }
}

//format the number if the value is a number
function formatNumeric(fieldname){
	var val = StrString = eval("document.wizard."+ fieldname +".value");
	valreturn = "";
	//alert(val);
	if(numericValid(val)){
		if(val == 0 || val == "00" || val == "0 " || val == " 0"){
			valreturn = '';
			eval("document.wizard."+ fieldname +".value=\'\';")
		}
		else{
			if(val < 10 && val.length==1){
				valreturn = "0"+val;
			}
			else{
				valreturn = val;
			}
			//alert();
			eval("document.wizard."+ fieldname +".value=\'"+valreturn+"\';")
		}
	}
}



function getRadioIndex(obj)
{
	for (i=0; i < obj.length; i++)
	{
		if(obj[i].checked==true)
		return i;
	}
	return -1;
}



//add your validation function here
function myValid(value)
{
    if(value=="")
    {
        return false;
    }
    else
    {
        return true;
    }
}
//END OF FORM VALIDATION

//SUBMIT forms
//list_rubrik
function postformrubrik(action)
{
	document.list_rubrik.action = action;
	document.list_rubrik.submit();
}

function checkallsearch(formulaire,chaine)
{
var nom_champ = chaine.substring(0,chaine.length - 1);
var init_field = formulaire.elements[nom_champ];

for (var i=0; i<formulaire.elements.length; i++)
  {
    var e = formulaire.elements[i];
    if (e.name.search(chaine) != -1)
	  {
		if( init_field.checked>0  )
		  {
			e.checked = 1;
		  }
		else e.checked = 0;
		
	  }
   }
}

function checkRights(formulaire,init_field,tab_id)
{
	for (i=0;i<tab_id.length;i++)
	{
		var e = formulaire.elements[tab_id[i]];
		if( formulaire.elements[init_field].checked>0  )
			e.checked = 1;
		else
			e.checked = 0;
	}
}
