function stepaction(action,i)
{
	document.wizard.step_action.value = action;
	document.wizard.step_nb.value = i;
	document.wizard.submit();
}


function popup(url, type, h, w)
{
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - w)/2;
	top = (document.body.clientHeight - h)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - w)/2;
	top = (self.innerHeight - h)/2;
  } 
  if(DEBUG)
  {
  	var status=1;
  }else
  {
  	var status=0;
  }
  wintype="toolbar=no,menubar=no,location=no,status="+status+",scrollbars=1,resizable=0,top="+top+",left="+left+",height="+h+",width="+w;
  var newwin = window.open(url,type,wintype);
  newwin.focus();
}

function popupResizable(url, type, h, w)
{
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - w)/2;
	top = (document.body.clientHeight - h)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - w)/2;
	top = (self.innerHeight - h)/2;
  } 
  wintype="toolbar=no,menubar=no,location=no,status=1,scrollbars=1,resizable=1,top="+top+",left="+left+",height="+h+",width="+w;
  var newwin = window.open(url,type,wintype);
  newwin.focus();
}
function popupResizableCenter(url, type, h, w)
{
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - w)/2;
	top = (document.body.clientHeight - h)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - w)/2;
	top = (self.innerHeight - h)/2;
  } 
  var haut=(screen.height-h)/2;
  var Gauche=(screen.width-w)/2;
  wintype="toolbar=no,menubar=no,location=no,status=1,scrollbars=1,resizable=0,top="+top+",left="+left+",height="+h+",width="+w;
  var newwin = window.open(url,type,wintype);
  newwin.focus();
}
function popupMenuEnabled(url, type, h, w)
{
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - w)/2;
	top = (document.body.clientHeight - h)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - w)/2;
	top = (self.innerHeight - h)/2;
  } 
  wintype="toolbar=yes,menubar=yes,location=no,status=1,scrollbars=1,resizable=1,top="+top+",left="+left+",height="+h+",width="+w;
  var newwin = window.open(url,type,wintype);
  newwin.focus();
}

function setFormActionSubmit(url,form)
{
	if( ! form)
	{
		form="wizard";
	}
	eval("var formObj=document."+form);
	if(formObj)
	{
		formObj.action=url;
		postwizard(formObj.name);
	}else
	{
		alert(form+" n'existe pas.");
	}
}

function setFormActionWithoutSubmit(url,form)
{
	if( ! form)
	{
		form="wizard";
	}
	eval("var formObj=document."+form);
	if(formObj)
	{
		formObj.action=url;
		formObj.submit();
	}else
	{
		alert(form+" n'existe pas.");
	}
}

function setFormAction(url,form)
{
	if( ! form)
	{
		form="wizard";
	}
	eval("var formObj=document."+form);
	if(formObj)
	{
		formObj.action=url;
	}else
	{
		alert(form+" n'existe pas.");
	}
}


//gtharreau le 19/01/2006 - mantis OEMS 31
//modifie l'action du formulaire si nom_champ à la valeur valeur_champ
//valable uniquement pour les champ de type radio button
function checkActionDependingRadioValue(form,nom_champ,valeur_champ,new_url_action){
	var radio_value;

	eval("var champ=document."+form+"."+nom_champ);
	radio_value = getSelectedRadioValue(champ);
	
	if(nom_champ=!"" && radio_value==valeur_champ){
		setFormAction(new_url_action,form);
	}
}

//renvoie la valeur selectionnée dans un radio button
function getSelectedRadioValue (radiobutton){
	
    var returnValue = "";

    if (radiobutton.length == 1){
        returnValue = radiobutton.value;
    } else {
    	for (i=0;i<radiobutton.length;i++){
            if (radiobutton[i].checked==true) {
                returnValue=radiobutton[i].value;
            }
        }
    }
    return returnValue;
} 

function webEditor(field)
{
	window.open('/services/webeditor/word.php?name='+field,'WebEditor','personalbar=no,toolbar=no,status=yes,scrollbars=no,location=no,resizable=yes,menubar=no,titlebar=no,Top='+20+',Left='+20+',Width='+770+',Height='+620);
}

function webColor(value)
{
	return showModalDialog('/services/color/color.htm',value,'status=no,scroll:no;resizable:no;dialogWidth:250px;dialogHeight:370px');
}

function webCalendar(name,hidden,init)
{
	if( ! init)
	{
		init="";
	}
	window.open('/services/calendar/calendar.php?name='+name+'&hidden='+hidden+'&dt='+init,'calendar_'+name,'status=no,toolbar=no,scrollbars=yes,resizable=yes,width=200,height=180');
}

function webCalendarMultiLang(name,hidden,init,lang)
{
	if( ! init)
	{
		init="";
	}
	window.open('/services/calendar/calendar.php?name='+name+'&hidden='+hidden+'&dt='+init+'&lang='+lang,'calendar_'+name,'status=no,toolbar=no,scrollbars=yes,resizable=yes,width=200,height=180');
}

//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;
		}
		vareval = "document.wizard."+field2+".value=\""+var3+"\";";
		eval(vareval);
	}
}

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;
	}
}


