//function submitForm(f, w, a)
//function continueprob()
//function popupLauncher(form, windowname, action, features)
//function disableit(v)

function submitForm(f, w, a)
{
   if (f)
   {
      if(a) f.action=a;
      if(w) f.target=w;
      f.submit();
//      if(w=="n" || !w) {f.submit();}
//      if(w=="y")
//      {
//         newwind=self.open('f.submit();','new','toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no,width=629,height=511');
//         newwind.focus();
//      }
   }
   else
   {
      if(w=="n" || !w) 
      {
         self.location.href=a;
      }
      else
      {
         newwind=self.open(a,'new','toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no,width=629,height=511');
         newwind.focus();
      }
   }
   return ((navigator) && (navigator.org == 'netscape'));
}

function popupLauncher(form, windowname, action, features)
{
   // Name: mixedOpenTarget(form:form object, windowname: target window name,  action: form action or URL, features:target window features,)
   // Goal : Can submit form in the active window/a new window or can just open a popup window.
   // - To launch the result of a form in the current page : form=form object / windowname=set to null / features= set to null / action= action parameter of the form object (can be omited)
   // - To launch the result of a form in a new window : form=form object / windowname= name of the new window (required) / features= features of the new window (can be omited) / action= action parameter of the form object (can be omited)
   // - To launch a popup window without any form validation : form= set no null / windowname= name of the new window (required) / features= features of the new window (can be omited) / action= URL of the new window(required)
   var launch= new Boolean(true);
   if (!features) 
   {
      features='toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no,width=480,height=500';
   }
   if (form)
   {
      saveaction = form.action;
      savetarget = form.target;
      if (action)
      {
         form.action=action;
      }
      if(windowname)
      {
         window.name=windowname; 
         windowname="launch_"+windowname;
         savetarget = window.name;
         form.target=windowname;
         open('', windowname, features);
      }
      form.submit();
      window.setTimeout("window.document."+form.name+".target = '"+savetarget+"';", 1000);
      form.action = saveaction;
      form.target = savetarget;
   }
   else 
   {
      if (!action && !windowname) return false;
      if (windowname) {window.name=windowname;windowname="launch_"+windowname;}
      open (action, windowname, features);
   }

//   if (form)
//   {
//      if (action)
//      {
//         saveaction = form.action;
//         form.action=action; action='';
//      }
//      if(!windowname)
//      {
//         launch=false;
//         form.submit();
//      } 
//      else 
//      {
//         form.target=windowname;
//         action="javascript:document."+form.name+".submit();";
//      }
//   }
//   else 
//   {
//      if (!action && !windowname) return false;
//      if (windowname) {window.name=windowname;windowname="launch_"+windowname;}
//   }
//   if (launch) 
//   {
//      open('', windowname, features);
//      form.submit();
//   }
//   if (launch) {open (action, windowname, features);}
//   if (action && form) {opener.form.action=saveaction;}
}


function disableit(v) {
if (document.all) {viewall="visible"; hideall="hidden"} else {viewall="show"; hideall="hide"}
if (v) v=viewall; else v=hideall;
document.all.D0.style.visibility=v;
}

function validstate(s, f, n){
if (s.selectedIndex==0){responsehide(f,n,"false"); }else {responsehide(f,n);}
}

function responsehide(f,n, y){
   for (i=1; i<=parseInt(n,10); i++)
   {
   element=eval("f.response"+i)
   element.disabled=!y;
   if (!y) {disable(element);} else {enable(element);}
   }
}

function disable(elem) { // elem: form element to be disabled
  elem.onfocus=elem.blur;
}
function enable(elem) { // elem: form element to be reenabled
  elem.onfocus=null;
}

function isnum(o,min, max,integer)
{
   return isnum_msg(o, min, max, integer, "Vous devez saisir un nombre.", "Vous devez saisir un nombre positif.", "Veuillez saisir un nombre compris entre "+min+" et "+max+".");
}

function isnum_lang(o,min, max,integer, message)
{
   return isnum_msg(o, min, max, integer, message, message, message);
}

function isnum_msg(o,min, max,integer, msg1, msg2, msg3)
{
if (integer==null) integer=true;
var x=chkNumeric(o);
        if (x==0) // not numerical value
        {	
                alert(msg1);
                o.value="";
                o.select();
                o.focus();
                return false;
        }
        else
        {	if (x==3) // negative value
                {
                    alert(msg2);
                    o.value="";
                    o.select();
                    o.focus();
                    return false;
                }
                if (x==1 && integer) // integer value
                {
                       range=isinrange(o,min, max);
                       if(range>0)  
                       {
                          alert(msg3);
                          o.value="";
                          o.select();
                          o.focus();
                          return false;
                       }
                       return true;
                }
                else
                {	
                        if (integer==false && x>=1) //float value
                        {
                           range=isinrange(o,min, max);
                           if(range>0)  
                           {
                              alert(msg3);
                              o.value="";
                              o.select();
                              o.focus();
                              return false;
                           }
                           return true;
                        }
                        alert(msg1);
                        o.value="";
                        o.select();
                        o.focus();				
                        return false;
                }
        }
}

function isinrange(o, min, max)
{

val=parseFloat(o.value);
if (min && max){ if (val<min || val>max) return 1;}
else if (min){ if (val<min) return 3;}
    else if (max) {if (val>max) return 4;}
return 0;
}

function chkNumeric(o)
{
var valueOK  = "0123456789.,";
var checkStr = o.value;
var allValid = true;
var comma    = false;
var start    = 0;

//check if signed numeric ?
if (checkStr.charAt(0)=="-") {return 3;}
if (checkStr.charAt(0)=="." || checkStr.charAt(0)==","){
                checkStr="0."+checkStr.substring(1,checkStr.length);
        }
//check the string
for (i = start;  i < checkStr.length;  i++)
{
        for (j = 0;  j < valueOK.length;  j++)	if (checkStr.charAt(i) == valueOK.charAt(j)) break;
        if (j == valueOK.length)
        {
                allValid = false;
                break;
        }
        if (checkStr.charAt(i) == ",") 
        {
                tmpstr=checkStr.substring(0,i);
                checkStr=tmpstr+"."+checkStr.substring(i+1,checkStr.length);
        }
        if (checkStr.charAt(i) == ".")	
                // only one comma !
                if (comma) {allValid = false; break;}
                else comma=true;
}
if (!allValid) return 0;
o.value=checkStr;
if (comma) return 2;
return 1;
}

function select_all(f)
{
for(var i = 0; i < f.length; i++) 
    {
    var e = f.elements[i];
    if (e.type=="checkbox")
        {
        e.checked=true;
        }
    }

}

function unselect_all(f)
{
for(var i = 0; i < f.length; i++) 
    {
    var e = f.elements[i];
    if (e.type=="checkbox")
        {
        e.checked=false;
        }
    }

}

function checkPipingQuestionTag(s, t)
{
   sText = t.value;
   if (s.selectedIndex == 0) {
      pos = sText.indexOf("<#answertext#>");
      if (pos != -1)
         sText = sText.substr(0, pos) + sText.substr(pos+14);
   } else {
      if (sText.indexOf("<#answertext#>") == -1)
         sText = sText + " <#answertext#>";
   }
   t.value = sText;
}
