var CCILP_PROJECT_CONFIRMDELETE = "Do you really want to delete this project?";
var EDITORSTARTDATEAFTERENDDATE = "The end date is earlier than the start date";
var BLOBVIEWER_INVALIDFILEPATH = "File path is invalid";
var EDITORMANDATORYFIELD = "Mandatory field";
var CCIL_USEREDITOR_MANDATORYFIELD = "(a value must be provided)";
var CCILAD_NETWORKEDITOR_INVALIDLOCAFR = "The french name is invalid";
var EDITORSHOUDBEANUMBER = "must contain a number";
var CCILP_LAUNCHACTIONS_ALERTMESSAGE2 = "characters.";
var CCILP_LAUNCHACTIONS_ALERTMESSAGE1 = "Your message length must not exceed";
var CCILAN_FEEDBACKSPAGE_EMPTYLIST = "At least one feedback needs to be selected";
var EDITORTOOMANYDECIMALS = "has too many decimals. Maximum is:";
var CCILP_LAUNCH_CONFIRMMULTIDELETEACTION = "Do you really want to delete these documents?";
var CCIL_USEREDITOR_XMLVALIDITY = "(it must start either with a letter, '_' or ':', and may contain any letter, digit, '.' or '-')";
var CCILP_PROJECT_INSERTNODOC = "You must select at least one document";
var EDITORMAXSIZE = "is too large, maximum number of characters:";
var CCILP_NOTEEDITORS_CONFIRMDELETESECTION = "Do you really want to delete this section?";
var CCILAN_ADVMONITORINGCONFIG_INVALIDDATE = "does not contain a valid date.";
var CCILP_PROJECTUSERS_ALERTSELECTUSERS = "Select users to add to the project";
var CCILP_PROJECTUSERS_CONFIRMREMOVEWRITERS = "Do you really want the selected users to be removed from the writers list?";
var CCILAD_MARKETINGBATCHUSERDEL_CANNOTDELETEBLOBS = "Cannot delete this user.";
var CCILP_QUESTIONSEDITOR_MAXSIZE = "Text to long to fit";
var EDITORSELECTASECTIONFIRST = "Select a section to add.";
var MYTASKSDOCMUSTBESELECTED = "At least one document must be selected";
var CCILAD_PRODUCTEDITOR_INVALIDLOCAFR = "The french name is invalid";
var CCILP_DATEEDITOR_INVALIDDATE = "Date is invalid";
var CCILAD_PRODUCT_NOCONTEXTSELECTED = "Select at least one context to add topic from.";
var CCILAD_NETWORKEDITOR_INVALIDLOCAEN = "The english name is invalid";
var CCILP_PROJECTUSERS_CONFIRMREMOVEREADERS = "Do you really want the selected users to be removed from the readers list?";
var CCIL_USEREDITOR_INVALIDFIRSTNAME = "The firstname is invalid";
var CCILAN_DOCUMENTSTATUSDASHBOARD_REMINDERDELETECONFIRM = "Do you really want to delete the selected reminder?";
var CCILAN_ADVMONITORINGCONFIG_TWODIMSMAX = "Select no more than 2 dimensions.";
var CCILAD_NETWORKEDITOR_INVALIDADDRESS = "The address is invalid";
var CCILAD_MARKETINGUSEREDITOR_CONFIRMQUIT = "Your modifications will be lost. Are you sure you want to quit?";
var MYTASKSDELSECTIONCONFIRM = "Do you really want to delete this section?";
var CCILAD_NETWORKEDITOR_MAXSIZETOOBIG = "(content size is too big)";
var CCIL_USEREDITOR_INVALIDDESCRIPTION = "The comments is invalid";
var CCIL_USEREDITOR_PASSWORDDONTMATCH = "Password field and password confirmation field have different values";
var CCILAD_PRODUCTEDITOR_INVALIDLOCAEN = "The english name is invalid";
var CCILP_QUESTIONSEDITOR_SELECTTOMODIFY = "Select the answer to modify";
var CCIL_USEREDITOR_INVALIDLASTNAME = "The lastname is invalid";
var CCILP_PROJECTEDITOR_INVALIDNAME = "The name is invalid";
var CCILAD_PRODUCT_NOCHANNELSELECTED = "Select at least one center to add topic from.";
var EDITORSECTIONDELETECONFIRM = "Are you sure you want to remove this section ?";
var CCILP_PROJECTUSERS_ALERTLEADERNOTREMOVABLE = "Impossible to remove leader from managers list";
var CCILP_PROJECTUSERS_CONFIRMREMOVEMANAGERS = "Do you really want the selected users to be removed from the managers list?";
var CCILAD_PRODUCTEDITOR_HTMLVALIDITY = "(it can contain any character except '<', '>' and double quotes)";
var CCILAD_PRODUCTEDITOR_MANDATORYFIELD = "(a value must be provided)";
var EDITORCONFIRMQUIT = "Your modifications since the last save will be lost. Are you sure you want to quit ?";
var CCIL_USEREDITOR_INVALIDPASSWORD = "The password is invalid";
var FILTERWRONGDATE = "Invalid date in your filter.";
var CCILP_DOCEDITOR_CONFIRMCHANGEBEFOREPREVIEW = "Do you want to save your changes before previewing?";
var CCILP_FIELDEDITOR_CONFIRMQUIT = "Your modifications will be lost. Are you sure you want to quit?";
var CCILAD_NETWORKEDITOR_INVALIDLOCAJA = "The japanese name is invalid";
var MYTASKSALERTDELETEDOCSCONFIRM = "Are you sure you want to delete these documents?";
var CCIL_USEREDITOR_INVALIDLOGIN = "The login is invalid";
var CCILAN_ADVMONITORINGCONFIG_STARTDATE_AFTER_ENDDATE = "The end date is earlier than the start date";
var CCILAN_ADVMONITORINGCONFIG_ONEDIMMIN = "Select at least one dimension.";
var EDITORPOSITIONMANDATORY = "Setting a position for this document is mandatory";
var CCILAD_PRODUCTEDITOR_MAXSIZETOOBIG = "(content size is too big)";
var CCILP_PROJECTUSERS_ALERTSELECTMANAGERS = "Select managers to remove from list";
var CCILP_QUESTIONSEDITOR_MAXSIZEHELP = "Max size:";
var CCILAD_CONTEXTEDITOR_CONFIRMDELETION = "Do you really want to delete this working context?";
var CCILP_QUICKEDITOR_ALERTDOCDEFEMPTY = "Type of content must be defined";
var CCILP_PROJECTUSERS_ALERTSELECTREADERS = "Select readers to remove from list";
var CCILAD_PRODUCTEDITOR_INVALIDNAME = "The search criteria code is invalid";
var CCILP_QUESTIONSEDITOR_NOTEXTFORANSWER = "No text found for new answer";
var EDITORWRONGDATE = "does not contain a valid date";
var CCILFO_FEEDBACK_POPUPEMPTYMESSAGE = "You cannot send an empty feedback field";
var CCILP_QUESTIONSEDITOR_SELECTTOREMOVE = "Select the answer to remove";
var CCILP_PROJECTUSERS_ALERTSELECTWRITERS = "Select writers to remove from list";
var CCILAD_PRODUCTEDITOR_INVALIDLOCAJA = "The japanese name is invalid";
var CCILAD_NETWORKEDITOR_INVALIDCODE = "The code is invalid";
var CCILAD_NETWORKEDITOR_HTMLVALIDITY = "(it can contain any character except '<', '>' and double quotes)";
var CCIL_USEREDITOR_MAXSIZETOOBIG = "(content size is too big)";
var FILESYSTEMVALIDITY_INFOMESSAGE = "(it can contain any character except '*', '?', '|', '>', '<' and double quotes)";
var CCILP_LAUNCH_NODOCUMENTMESSAGE = "No document selected";
var CCIL_USEREDITOR_INVALIDPHONENUMBER = "The phone number is invalid";
var CCILAD_NETWORKEDITOR_INVALIDTEL = "The extension is invalid";
var MYTASKSALERTREMOVEMULTIPLEDOCSCONFIRM = "Are you sure you want to remove these documents from the project?";
var CCILP_LAUNCHACTIONS_ALERTSELECT2 = "users";
var CCILP_LAUNCHACTIONS_ALERTSELECT1 = "You must select";
var EDITORMINVALUE = "minimum value is";
var CCILP_MYTASKS_TASKDELCONFIRM = "Do you really want to delete this task ?";
var CCILAD_NETWORKEDITOR_MANDATORYFIELD = "(a value must be provided)";
var CCIL_USEREDITOR_HTMLVALIDITY = "(it can contain any character except '<', '>' and double quotes)";
var CCILP_DOCEDITOR_CHANGESECTIONCONFIRM = "The modifications will be lost. Are you sure you do not want to save before changing sections?";
var EDITORSECTIONACTIONCONFIRM = "The document will be saved before executing this action, continue ?";
var EDITORAUDIENCEMANDATORY = "Setting an audience for each section is mandatory";
var CCILP_QUICKEDITOR_ALERTTITLEEMPTY = "Title cannot be empty";
var EDITORMAXVALUE = "maximum value is";
var CCILP_PROJECTEDITOR_MANDATORYFIELD = "(a value must be provided)";
var CCIL_USEREDITOR_INVALIDPASSWORDCHECK = "The password confirmation is invalid";
var EDITORINVALIDCHAR = "contains an invalid character";
var CCILAD_MARKETINGBATCHUSERDEL_NOELEMENTSELECTED = "You should select at least one element in the list to be processed";
var CCILAD_PRODUCTEDITOR_XMLVALIDITY = "(it must start either with a letter, '_' or ':', and may contain any letter, digit, '.' or '-')";
var CCILP_PROJECTEDITOR_HTMLVALIDITY = "(it can contain any character except '<', '>' and double quotes)";
var EDITORWRONGTIME = "does not contain a valid time";
var CCILFO_FRONT_FAVORITESDELALL = "Do you really want to remove all content from your bookmarks?";
var EDITORCONFIRMWORKFLOW = "The current document will be saved before executing this action. Do you want to continue ?";
var MYTASKSDELCONFIRM = "Do you really want to delete this document?";
var CCILAD_MARKETINGUSERS_USERNAMEMODIFIED = "Actions will act on user:";
var EDITORSHOUDBEANINTEGER = "must contain an integer";
var CCIL_USEREDITOR_INVALIDEMAIL = "The e-mail is invalid";
var CCIL_FAVORITESDELETEALL = "Do you really want to remove all content from your favorites?";
var MYTASKSALERTREMOVESINGLEDOCCONFIRM = "Are you sure you want to remove this document from the project?";
var CCILAD_NETWORKEDITOR_CONFIRMQUIT = "Your modifications will be lost. Are you sure you want to quit?";
var CCILAD_NETWORKEDITOR_DIMSNOTSET = "A value must be provided for each dimension.";
var INSTRASERVLET_URL = "/surewest/com.instranet.InstraServlet";
var WEBAPP_URL = "/surewest/";

/* used by filterContainer */

var winDimChooserStatus = 0;
var winDimChooser = null;
var DimChooserHeight    = 500;
var DimChooserWidth     = 400;

function filterDimChooserClose() {
   if (winDimChooserStatus == 1) {
      winDimChooserStatus = 0;
      winDimChooser.close();
   }
}
function filterDimChooserIsClosed() {
   winDimChooserStatus = 0;
}
function filterDimChooserIsOpened() {
   winDimChooserStatus = 1;
}

function filterDimChooserClicked() {

   winDimChooser = window.open("", "winDimChooser", 'width=' + DimChooserWidth + ',height=' + DimChooserHeight + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
	winDimChooser.focus();
}


function filterCheckFilter(formName, filterName) {
   var objElement;
   var strRoot;
	var field, strFieldName, strRealValue;
   var loopEl;
   var tmpElem;
   var form = eval("document."+formName);

   for (loopEl=0; loopEl<form.length; loopEl++) {
      objElement = form.elements[loopEl];

      if (objElement.name.indexOf(filterName)!=0) {
			continue;
		}

      if (objElement.name.length>7 && objElement.name.lastIndexOf("_Custom")==objElement.name.length-7) {
			strFieldName = objElement.value;
			strFieldValue =  eval("document."+formName+"."+strFieldName+".value");
         strRoot = objElement.name.substr(0, objElement.name.length-7);
			field = eval("document."+formName+"."+strRoot);
			field.value = strFieldValue;
      }
	}

   return true;
}

/* used by filterKeywordSearchIn */

function filterKeywordOnClick(checkBox, formName, fieldName) {
   var field = eval("document."+formName+"."+fieldName);
   if (checkBox.checked == false) {
      field.value='false';
   } else {
      field.value='true';
   }
}

var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function _filterGetDays(month, year) {
   // Test for leap year when February is selected.
   if (1 == month)
      return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28;
   else
      return daysInMonth[month];
}


function filterCheckDate(strFormName, strRoot) {
   var nYear, nMonth, nDay;

   var field = eval("document."+strFormName+"."+strRoot+"_Y");
   if (field!=null) {
      nYear = field.value;
      if (isNaN(nYear)) {
         alert(FILTERWRONGDATE);
         field.focus();
         return false;
      }
   }

   field = eval("document."+strFormName+"."+strRoot+"_M");
   if (field!=null) {  
      nMonth = field.value;
      nMonth = nMonth - 1;
      if ((isNaN(nMonth)) || nMonth<0 || nMonth>11) {
         alert(FILTERWRONGDATE);
         field.focus();
         return false;
      }
   }

   field = eval("document."+strFormName+"."+strRoot+"_D");
   if (field!=null) {
      nDay = eval("document."+strFormName+"."+strRoot+"_D").value;
      if ((isNaN(nDay)) || nDay<1 || nDay>_filterGetDays(nMonth, nYear)) {
         alert(FILTERWRONGDATE);
         field.focus();
         return false;
      }     
   }
   return true;
}
var m_bFormDebug = false;

var MAXLENGTH_SUFFIX="_MaxLength";
var MINLENGTH_SUFFIX="_MinLength";

var VERIFYSTRING_NOTEMPTY              = 1 << 0;
var VERIFYSTRING_COMPATIBLEXML         = 1 << 1;
var VERIFYSTRING_COMPATIBLEHTML        = 1 << 2;
var VERIFYSTRING_COMPATIBLEFILESYSTEM  = 1 << 3;
var VERIFYSTRING_MAXSIZE               = 1 << 4;
var VERIFYSTRING_MINSIZE               = 1 << 5;

var m_temp_Popups;
var m_tempParentFormName;

function formGetForm(strFormName) {
   if (strFormName == null || strFormName == "") {
      var currentForm;
      var i;
      for (i=0; i<document.forms.length; i++) {
         currentForm = document.forms[i];
         if (_formCheckFieldExist(currentForm.Origin))
            return currentForm;
      }
      return null;
   }
   return document.forms[strFormName];
}

function formRefresh(strFormName) {
   var form;
   form=formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (formRefresh)");
      return false;
   }

   form.action = form.Origin.value;
   form.target = "_self";
   // If popups must be closed, must do it now
   if (m_bClosePopupsOnUnload == true)
      _popupParentCloseAllPopups(strFormName);
   _popupPrepareFormForSubmit(strFormName);
   form.submit();
   return false;
}

function formSubmitExecuteCommand(strFormName, command, redirect, target) {
   var form;

   form=formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (formSubmitExecuteCommand)");
      return false;
   }

   form.action = INSTRASERVLET_URL;
   form.target = target;
   form.Command.value = command;
   form.Redirect.value = redirect;
   // If popups must be closed, must do it now
   if (m_bClosePopupsOnUnload == true)
      _popupParentCloseAllPopups(strFormName);
   _popupPrepareFormForSubmit(strFormName);
   _formPushContext(strFormName, target);
   form.submit();
   _formPopContext(strFormName, target);
   return false;
}

function formSubmitUrl(strFormName, url, target) {
   var form;

   form=formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (formSubmitUrl)");
      return false;
   }

   form.action = url;
   form.target = target;
   // If popups must be closed, must do it now
   if (m_bClosePopupsOnUnload == true)
      _popupParentCloseAllPopups(strFormName);
   _popupPrepareFormForSubmit(strFormName);
   _formPushContext(strFormName, target);
   form.submit();
   _formPopContext(strFormName, target);
   return false;
}

function formCheckAll(strFormName, strPrefix) {
   _formSetChecked(strFormName, strPrefix, true);
}

function formUncheckAll(strFormName, strPrefix) {
   _formSetChecked(strFormName, strPrefix, false);
}

function _formSetChecked(strFormName, strPrefix, bSetChecked) {
   var form;
   var i;
   var currentElement;

   form=formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (_formSetChecked)");
      return false;
   }
   for (i=0; i<form.elements.length; i++) {
      currentElement = form.elements[i];
      if (currentElement.type == "checkbox" && currentElement.name.indexOf(strPrefix) == 0)
         currentElement.checked = bSetChecked;
   }
}

function formCheckFieldContent(strFormName, strFieldName, bitField) {
   var form;
   form=formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (formCheckFieldContent)");
      return false;
   }

   var bIsCompliant;
   var checkedField = eval("form." + strFieldName);

   if (!_formCheckFieldExist(strFormName, checkedField)) {
      _formFatal("Cannot find the field " + strFieldName);
      return false;
   }

   if (bitField & VERIFYSTRING_COMPATIBLEXML) {
      bIsCompliant = _formCheckFieldContentXmlCompliant(strFormName, checkedField);
      if (!bIsCompliant)
         return false;
   }
   if (bitField & VERIFYSTRING_COMPATIBLEHTML) {
      bIsCompliant = _formCheckFieldContentHtmlCompliant(strFormName, checkedField);
      if (!bIsCompliant)
         return false;
   }
   if (bitField & VERIFYSTRING_MAXSIZE) {
      bIsCompliant = _formCheckFieldContentMaxSize(strFormName, checkedField);
      if (!bIsCompliant)
         return false;
   }
   if (bitField & VERIFYSTRING_MINSIZE) {
      bIsCompliant = _formCheckFieldContentMinSize(strFormName, checkedField);
      if (!bIsCompliant)
         return false;
   }
   return true;
}

function _formCheckFieldContentHtmlCompliant(strFormName, checkedField) {
   if (checkedField.value.indexOf('"') != -1
      || checkedField.value.indexOf('<') != -1
      || checkedField.value.indexOf('>') != -1) {
      return false;
   }
   return true;
}

function _formCheckFieldContentXmlCompliant(strFormName, checkedField) {
   if (checkedField.value.indexOf('"') != -1
      || checkedField.value.indexOf('<') != -1
      || checkedField.value.indexOf('>') != -1
      || checkedField.value.indexOf("'") != -1
      || checkedField.value.indexOf(' ') != -1) {
      return false;
   }
   return true;
}

function _formCheckFieldContentFileSystemCompliant(strFormName, checkedField) {
   if (checkedField.value.indexOf('*') != -1
      || checkedField.value.indexOf('?') != -1
      || checkedField.value.indexOf('"') != -1
      || checkedField.value.indexOf('<') != -1
      || checkedField.value.indexOf('>') != -1
      || checkedField.value.indexOf('|') != -1) {
      return false;
   }
   return true;
}

function _formCheckFieldContentMaxSize(strFormName, checkedField) {
   var form;
   var maxSizeField;
   var nMaxSize;
   var nCheckedFieldSize;

   form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (_formCheckFieldContentMaxSize)");
      return false;
   }

   nCheckedFieldSize = checkedField.value.length;

   maxSizeField = eval("form." + checkedField.name + MAXLENGTH_SUFFIX);
   if (!_formCheckFieldExist(maxSizeField)) {
      _formFatal("Cannot find the hidden field " + checkedField.name + MAXLENGTH_SUFFIX + ": it is a mandatory field to check max size");
      return false;
   }
   nMaxSize = parseInt(maxSizeField.value);

   if (isNaN(nMaxSize))
      _formFatal("The field " + maxSizeField.name + " must contain a valid integer as value");

   if (nCheckedFieldSize > nMaxSize) {
      return false;
   }


   return true;
}

function _formCheckFieldContentMinSize(strFormName, checkedField) {
   var form;
   var minSizeField;
   var nMinSize;
   var nCheckedFieldSize;

   form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (_formCheckFieldContentMinSize)");
      return false;
   }

   nCheckedFieldSize = checkedField.value.length;

   minSizeField = eval("form." + checkedField.name + MINLENGTH_SUFFIX);
   if (!_formCheckFieldExist(minSizeField)) {
      _formFatal("Cannot find the hidden field " + checkedField.name + MINLENGTH_SUFFIX + ": it is a mandatory field to check min size");
      return false;
   }
   nMinSize = parseInt(minSizeField.value);

   if (isNaN(nMinSize))
      _formFatal("The field " + minSizeField.name + " must contain a valid integer as value");

   if (nCheckedFieldSize < nMinSize) {
      return false;
   }

   return true;
}

function formCheckFieldExist(strFormName, strFieldName) {
   var form;
   var field;

   form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form in the parent. Probably because some fields are missing (formCheckFieldExist)");
      return false;
   }

   field = eval('form.'+strFieldName);

   return _formCheckFieldExist(field);
}

function _formCheckFieldExist(field) {
   if (field == null)
      return false;

   return true;
}

function _formPushContext(strFormName, targetName) {
   var form = formGetForm(strFormName);

   if (targetName != "_self") {
      // if there is a _Popups field in the specified form, don't pass its value to the target, because the target could possibly behave also like a parent
      if (form._Popups != null) {
         m_temp_Popups = form._Popups.value;
         form._Popups.value = "";
      }
      // if there is a ParentFormName field in the specified form, don't pass its value to the target, because the target could possibly behave also like a parent
      if (form.ParentFormName != null) {
         m_tempParentFormName = form.ParentFormName.value;
         form.ParentFormName.value = form.name;
      }
   }
}

function _formPopContext(strFormName, targetName) {
   var form = formGetForm(strFormName);

   if (targetName != "_self") {
      if (form._Popups != null) {
         form._Popups.value = m_temp_Popups;
      }
      if (form.ParentFormName != null) {
         form.ParentFormName.value = m_tempParentFormName;
      }
   }
}

function _formFatal(strMessage) {
   if (m_bFormDebug)
      alert("***DEBUG ERROR***\n" + strMessage);
}

function _formError(strMessage) {
   if (m_bFormDebug)
      alert(strMessage);
}

// Popup methods and variables //

var m_bPopupDebug = false;

var m_bPopupForceClose = false;
var m_bClosePopupsOnUnload = true;

function popupExecuteOnLoad(strFormName, parentFormName) {
   var form = formGetForm(strFormName);

   if (form == null) {
      _popupFatal("Cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   if (form._CloseOnLoad == null) {
      _popupFatal("A hidden field named '_CloseOnLoad' must exist in the popup window");
      return;
   }
   if (form._CloseOnLoad.value == "true")
      window.opener._popupParentDereferencePopup(strFormName, this, this.name);

   if (form._ReloadParentOnLoad == null) {
      _popupFatal("A hidden field named '_ReloadParentOnLoad' must exist in the popup window");
      return;
   }
   if (form._ReloadParentOnLoad.value == "true")
      window.opener.popupParentReloadAndKeepPopups(parentFormName);
   if (form._CloseOnLoad.value == "true"){
      m_bPopupForceClose = true;
      if (!window.closed)
         window.close();
   }
}

function popupExecuteOnUnload(strFormName, parentFormName) {
   var form = formGetForm(strFormName);
   var popup;

   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   if (!m_bPopupForceClose) {
      if (form._CloseOnUnload == null) {
         _popupFatal("An hidden field named '_CloseOnUnload' must exist in the popup window");
         return;
      }
      if (form._CloseOnUnload.value == "true" || form._CloseOnUnload.value == "") {
         try {
            popup = window.opener._popupParentDereferencePopup(strFormName, this, this.name);
            if (popup == null) {
               _popupAddCookie("Closed", this.name);
            }
         } catch (e) {
            _popupAddCookie("Closed", this.name);
         }
      }

      if (form._ReloadParentOnUnload == null) {
         _popupFatal("An hidden field named '_ReloadParentOnUnload' must exist in the popup window");
         return;
      }
      

      if (form._ReloadParentOnUnload.value == "true")
         window.opener.popupParentReloadAndKeepPopups(parentFormName);

      if (form._CloseOnUnload.value == "true" || form._CloseOnUnload.value == "") {
         if (!window.closed)
            window.close();
      }
   }
}

function popupRefresh(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form.action=form.Origin.value;
   form.target="_self";
   return _popupSubmit(strFormName);
}

function popupSubmitUrl(strFormName, url, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitUrl(strFormName, url, target)

   return false; // must return false
}

function popupSubmitExecuteCommand(strFormName, command, redirect, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitExecuteCommand(strFormName, command, redirect, target)
   return false; // must return false
}

// SHOULD NOT BE USED ANYMORE
function _popupSubmit(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   form.submit();
   return false; // must return false
}

function popupClose(strFormName) {
   if (!window.closed) {
//      window.opener._popupParentDereferencePopup(strFormName, this, this.name);
      window.close();
   }
}

function popupCloseAndParentRefresh(strFormName, parentFormName) {
   if (!window.closed) {
      window.opener._popupParentDereferencePopup(strFormName, this, this.name);
      window.opener.formRefresh(parentFormName);
      window.close();
   }
}

function popupRefreshAndClose(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form.action=form.Origin.value;
   form.target="_self";
   return popupSubmitAndClose(strFormName);
}

function popupSubmitUrlAndClose(strFormName, url, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitUrl(strFormName, url, target)
   return false; // must return false
}

function popupSubmitExecuteCommandAndClose(strFormName, command, redirect, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitExecuteCommand(strFormName, command, redirect, target)
   return false; // must return false
}

// SHOULD NOT BE USED ANYMORE
function popupSubmitAndClose(strFormName) {
   alert("###The function popupSubmitAndClose() has been deprecated ###\nUse popupSubmitUrlAndClose or popupSubmitExecuteCommandAndClose instead");
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="false";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   form.submit();
   return false; // must return false
}

function popupRefreshAndCloseAndParentRefresh(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form.action=form.Origin.value;
   form.target="_self";
   return _popupSubmitAndCloseAndParentRefresh(strFormName);
}

function popupSubmitUrlAndCloseAndParentRefresh(strFormName, url, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitUrl(strFormName, url, target);
   return false; // must return false
}

function popupSubmitExecuteCommandAndCloseAndParentRefresh(strFormName, command, redirect, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitExecuteCommand(strFormName, command, redirect, target);
   return false; // must return false
}

// SHOULD NOT BE USED ANYMORE
function _popupSubmitAndCloseAndParentRefresh(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="true";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   form.submit();
   return false; // must return false
}

function popupRefreshAndParentRefresh(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form.action=form.Origin.value;
   form.target="_self";
   return _popupSubmitAndParentRefresh(strFormName);
}

function popupSubmitUrlAndParentRefresh(strFormName, url, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitUrl(strFormName, url, target);
   return false; // must return false
}

function popupSubmitExecuteCommandAndParentRefresh(strFormName, command, redirect, target) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   m_bClosePopupsOnUnload = false;
   formSubmitExecuteCommand(strFormName, command, redirect, target);
   return false; // must return false
}

// SHOULD NOT BE USED ANYMORE
function _popupSubmitAndParentRefresh(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _popupFatal("cannot find a valid form in the popup. Probably because some fields are missing");
      return;
   }

   form._CloseOnLoad.value="false";
   form._ReloadParentOnLoad.value="true";
   form._CloseOnUnload.value="false";
   form._ReloadParentOnUnload.value="false";
   form.submit();
   return false; // must return false
}

function _popupForceClose(strFormName) {
   m_bPopupForceClose = true;
   this.close();
}


// Parent methods and variables //

var m_popupParentOldAction;
var m_popupParentOldCommand;
var m_popupParentOldRedirect;
var m_popups = new Array();
var m_popupParentLoaded = false;

function popupParentExecuteOnLoad(strFormName) {
   var form = formGetForm(strFormName);
   var strPopups;
   var strPopupName;
   var nStart, nEnd, nCounter;
   var iPopup;

   if (form == null) {
      _popupFatal("cannot find a valid form in the parent. Probably because some fields are missing (popupParentExecuteOnLoad)");
      return;
   }

   if (form._Popups == null) {
      _popupFatal("A hidden field named '_Popups' must exist in the parent window");
      return;
   }
   strPopups = form._Popups.value;
   nStart=1; // a comma precede the name of the window
   nCounter = 0;

   strPopups = popupCookieRemoveClosedPopups("Closed", strPopups);

   while((nEnd = strPopups.indexOf(",", nStart)) != -1) {
      strPopupName = strPopups.substring(nStart, nEnd);
      iPopup = new _IPopup(window.open("", strPopupName, ""), strPopupName);
      m_popups[nCounter]=iPopup;
      nStart = nEnd + 2;
      nCounter++;
   }

   m_popupParentLoaded = true;
}

function popupParentExecuteOnUnload(strFormName) {
   if (m_bClosePopupsOnUnload == true)
      _popupParentCloseAllPopups(strFormName);
}

function popupParentOpenPopup(strFormName, name, command, url, width, height) {
   var form = formGetForm(strFormName);
   var newPopup;
   var i;
   var strPopupUrl;
   var temp_Popups;
   var tempParentFormName;
   var strBlankUrl;
   var bSubmitForm;

   strBlankUrl = WEBAPP_URL + "blank.htm";

   if (form == null) {
      _popupFatal("cannot find a valid form in the parent. Probably because some fields are missing (popupParentOpenPopup)");
      return;
   }

   bSubmitForm = true;
   strPopupUrl = strBlankUrl;

   if ((newPopup = _popupIsOpened(name)) != null) {
      // popup already opened
      newPopup.popup.focus();
   } else {
      _popupParentPushContext(strFormName);

      if(command==null || command=="") {
         if (url==null || url=="") {
            bSubmitForm = false;
         } else if (url.indexOf("?") != -1) {
            strPopupUrl = url;
            bSubmitForm = false;
         } else {
            form.action = url;
         }
      } else {
         form.action=INSTRASERVLET_URL;
         form.Command=command;
      }

      newPopup = window.open(strPopupUrl,name,"toolbar=0,location=0,directories=0,status=0 ,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width="+width+",height="+height);
      _popupParentReferenceNewPopup(strFormName, newPopup, name);

      if (bSubmitForm) {
         _formPushContext(strFormName, name)
         
         form.target=name;
         form.submit();
         
         _formPopContext(strFormName, name)
      }

      _popupParentPopContext(strFormName);
   }

   return false;
}

function popupParentReloadAndClosePopups(strFormName) {
   var form = formGetForm(strFormName);
   m_bClosePopupsOnUnload = true;
   formRefresh(strFormName);
}

function popupParentReloadAndKeepPopups(strFormName) {
   var form = formGetForm(strFormName);
   m_bClosePopupsOnUnload = false;
   formRefresh(strFormName);
}

function _popupParentPushContext(strFormName) {
   var form = formGetForm(strFormName);
   m_popupParentOldAction = form.action;
   m_popupParentOldCommand = form.Command.value;
   m_popupParentOldRedirect = form.Redirect.value;
}

function _popupParentPopContext(strFormName) {
   var form = formGetForm(strFormName);
   form.action = m_popupParentOldAction;
   form.target = "_self";
   form.Command.value = m_popupParentOldCommand;
   form.Redirect.value = m_popupParentOldRedirect;
}

function _popupParentReferenceNewPopup(strFormName, newPopup, name) {
   var nPopupsReferenced = m_popups.length;
   m_popups[nPopupsReferenced] = new _IPopup(newPopup, name);
}

function _popupParentDereferencePopup(strFormName, popup, popupName) {
   var popusArrayCopy;
   var i, j;

   if (m_popupParentLoaded == false)
      return null;

   popupsArrayCopy = new Array();
   j=0;
   for (i=0; i<m_popups.length; i++) {
      if (m_popups[i].name != popupName) {
         popupsArrayCopy[j] = m_popups[i];
         j++;
      }
   }
   m_popups = popupsArrayCopy;
   return popup;
}

function _popupParentCloseAllPopups(strFormName) {
   var i;
   var dereferencedPopup;
   while (m_popups != null && m_popups.length>0) {
      dereferencedPopup = _popupParentDereferencePopup(strFormName, m_popups[0].popup, m_popups[0].name);
      try {
         dereferencedPopup._popupForceClose(strFormName);
      } catch (e) {
         _popupFatal("Cannot access to the forceClose() function of the popup, verify that the file popup.js is included in the popup");
         return;
      }
   }
}

function _popupFatal(strMessage) {
   if (m_bPopupDebug)
      alert("***DEBUG ERROR***\n" + strMessage);
}

function _IPopup(windowObject, windowName) {
   this.popup=windowObject;
   this.name=windowName;
}

function _popupPrepareFormForSubmit(strFormName) {
   var form = formGetForm(strFormName);
   var strPopups;
   var i;

   if (form._Popups == null) {
      return;
   }
   if (m_popups == null) {
      return;
   }

   strPopups = '';
   for (i=0; i<m_popups.length; i++) {
      strPopups += ',' + m_popups[i].name + ',';
   }
   form._Popups.value = strPopups;
}

function _popupIsOpened(name) {
   var i;
   var popup;

   for (i=0; i<m_popups.length; i++) {
      if (m_popups[i].name == name)
         return m_popups[i];
   }
   return null;
}




// TODO: put these functions in cookie.js, change the names, etc...
function _popupAddCookie(strCookieName, strValue) {
   var strCookies = document.cookie;
   var nStart = strCookies.indexOf(strCookieName);
   var nEnd;
   var strValues;

   if (nStart == -1) {
      document.cookie = strCookieName + '=' + strValue;
      return;
   }

   nEnd = strCookies.indexOf(';', nStart);

   if (nEnd == -1)
      strValues = strCookies.substring(nStart + strCookieName.length + 1);
   else
      strValues = strCookies.substring(nStart + strCookieName.length + 1, nEnd);

   if (strValues.indexOf(strValue) >= 0)
      return;

   if (nEnd == -1) {
      document.cookie = strCookies.substring(nStart) + ',' + strValue;
   } else {
      document.cookie = strCookies.substring(nStart, nEnd) + ',' + strValue;
   }
}

function popupCookieRemoveClosedPopups(strCookieName, strPopups) {
   var strCookies = document.cookie;
   var nStart = strCookies.indexOf(strCookieName);
   var nEnd;
   var strValues;
   var names;
   var newNames;
   var popups;
   var newPopups;
   var iName;
   var iPopup;

   if ((nStart == -1) || (strPopups.length == 0)) {
      return strPopups;
   }

   nEnd = strCookies.indexOf(';', nStart);

   if (nEnd == -1)
      strValues = strCookies.substring(nStart + strCookieName.length + 1);
   else
      strValues = strCookies.substring(nStart + strCookieName.length + 1, nEnd);

   if (strValues.length == 0)
      return strPopups;

   names = strValues.split(',');
   newNames = new Array();
   popups = strPopups.split(',');
   newPopups = new Array();

   iName = 0;
   iPopup = 0;
   while (iName < names.length) {
      if (strPopups.indexOf(names[iName]) == -1) {
         newNames[newNames.length] = names[iName];
      }
      iName++;
   }

   while (iPopup < popups.length) {
      if (strValues.indexOf(popups[iPopup]) == -1) {
         newPopups[newPopups.length] = popups[iPopup];
      }
      iPopup++;
   }

   if (newNames.length == 0) {
      // Remove cookie
      document.cookie = strCookieName + "=x";
   } else {
      document.cookie = strCookieName + '=' + newNames.join(',');
   }

   if (newPopups.length == 0)
      return "";
   else
      return ',' + newPopups.join(',');
}

/**
 * View a document in a new Popup
 *
 * @param   strFormName the name of the current HTML form object
 * @param   strUrl the Renderer URL of the corresponding document
 * @param   nDocId the identifier of the document to visualize
 *
 * @return  false
 */
function viewDocumentInPopup(strFormName, strUrl, nDocId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var strModule = form.Module.value;
   window.open(strUrl+"&amp;IsPopup=true"+"&amp;Module="+strModule,"DocumentWindow"+nDocId,"toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=900,height=600");

   return false;
}

function viewPromotionsDocumentInPopup(strFormName, strUrl, nDocId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var strModule = form.Module.value;
   window.open(strUrl+"&amp;IsPopup=true"+"&amp;Tracked=true" + "&amp;Module="+strModule,"DocumentWindow"+nDocId,"toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=1018,height=600");

   return false;
}


/**
 * View a reminder in a new Popup
 *
 * @param   strFormName the name of the current HTML form object
 * @param   strUrl the Renderer URL of the corresponding document
 * @param   nDocId the identifier of the document to visualize
 *
 * @return  false
 */
function viewReminderInPopup(strFormName, strUrl, nDocId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var strParentFormName = form.ParentFormName.value;
   var strModule = form.Module.value;
   window.open(strUrl+"&amp;IsPopup=true"+"&amp;Module="+strModule+"&amp;ParentFormName="+strParentFormName,"ReminderWindow"+nDocId,"toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=640,height=480");

   return false;
}

/**
 * View a feedback in a new Popup
 *
 * @param   strFormName the name of the current HTML form object
 * @param   strUrl the Renderer URL of the corresponding document
 * @param   nDocId the identifier of the document to visualize
 *
 * @return  false
 */
function viewFeedbackInPopup(strFormName, strUrl, nDocId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var strModule = form.Module.value;
   window.open(strUrl+"&amp;IsPopup=true"+"&amp;Module="+strModule,"FeedbackWindow"+nDocId,"toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=860,height=200");

   return false;
}

/**
 * View an alert in a new Popup.
 *
 * @param   strFormName the name of the current HTML form object
 * @param   strUrl      the renderer URL of the corresponding document
 * @param   nAlertId    the identifier of the document to visualize
 *
 * @return  false
 */
function viewAlertInPopup(strFormName, strUrl, nAlertId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   window.open(strUrl, "AlertWindow"+nAlertId, "toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=560,height=450");

   return false;
}

function viewDocumentFromReminderPopup(strFormName, strParentFormName, nDocExtId, nSecMode, strUrl, nReminderExtId) {
   var parentform = window.opener.formGetForm(strParentFormName);

   if (parentform == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   parentform.ReminderExtId.value = nReminderExtId;
   parentform.DocToRead.value = "true";
   parentform.Tracked.value = "true";
   
   popupClose(strFormName);
   
   window.opener.viewDocumentInCurrentWindow(strParentFormName, nDocExtId, nSecMode, strUrl) 

   return false;
}

function viewDocumentInCurrentWindow(strFormName, nDocExtId, nSecMode, strUrl) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.DocId.value = nDocExtId;
   form.SecMode.value = nSecMode;
   formSubmitUrl(strFormName, strUrl, "_self");

   return false;
}


function viewLastDocumentInCurrentWindow(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var tempAllValues = form.lastDocsCombo.value;

   allValues = tempAllValues.toString();

   var indexOfFirstPipe = allValues.indexOf('|', 0);
   firstDocId = allValues.substring(0, indexOfFirstPipe);

   secondAllValues = allValues.substr(indexOfFirstPipe);
   var indexOfSecondPipe = secondAllValues.indexOf('|', 0);
   var finalIndexOfSecondPipe = indexOfSecondPipe + 1;

   firstURL = secondAllValues.substr(finalIndexOfSecondPipe);

   form.DocId.value = firstDocId;
   form.SecMode.value = 1;

   formSubmitUrl(strFormName, firstURL, "_self");

   return false;

}


/**
 * Adds a document to the favorites preference.
 *
 * @param   strFormName the name of the current HTML form object
 * @param nExternalDocumentId the external ID of the doc to add to favorites
 *
 * @return  false
 */
function addFavorites(strFormName, nExternalDocumentId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.AddDocId.value=nExternalDocumentId;

   formSubmitExecuteCommand(strFormName, "com.instranet.CCILCmdFavoritesAdd", form.Origin.value, "_self");

   return false;
}

/**
 * Empties the favorites documents list.
 *
 * @param   strFormName the name of the current HTML form object
 * @return  false
 */
function emptyFavorites(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (confirm(CCIL_FAVORITESDELETEALL)) {
      form.RemoveAll.value="true";
      formSubmitExecuteCommand(strFormName, 'com.instranet.CCILCmdFavoritesDel', form.Origin.value, "_self");
   }

   return false;
}

/**
 * Removes a document from the favorites documents list
 *
 * @param   strFormName the name of the current HTML form object
 * @param nExternalDocumentId the external ID of the doc to remove from favorites
 *
 * @return  false
 */
function removeFavorite(strFormName, nDocId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.RemoveDocId.value=nDocId;
   formSubmitExecuteCommand(strFormName, 'com.instranet.CCILCmdFavoritesDel', form.Origin.value, "_self");

   return false;
}

/**
 * Edits the user's informations.
 *
 * @param   strFormName the name of the current HTML form object
 * @param   strUrl      the URL used to display the editor popup
 *
 * @return  false
 */
function editUserInfo(strFormName, strUrl) {
   popupParentOpenPopup(strFormName, "EditUserInfo", null, strUrl, 430, 320);

   return false;
}

/**
 * Allows to change the selected menu tab.
 *
 * @param   strFormName    the name of the current HTML form object
 * @param   strTabSel      the ID of the tab selected
 * @param   strUrl         the URL corresponding to the selected tab
 * @param   strMenuSel     the hidden field used to set the selection
 */
function selectMenuTab(strFormName, strTabSel, strUrl, strMenuSel) {
   var menuSel;
   var form = formGetForm(strFormName);

   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   menuSel = eval("document." + form.name + "." + strMenuSel);
   menuSel.value = strTabSel;

   formSubmitUrl(strFormName, strUrl, "_self");

   return false;
}

var isNav4, isMSIE4;

// checking the type and the version of the browser
if ( parseInt(navigator.appVersion) >= 4) {
   isNav4 = (navigator.appName == "Netscape");
   isMSIE4 = (navigator.appName.indexOf("Microsoft") != -1);
}

// necessary for Netscape to be able to trap key press event
if (isNav4 && navigator.language!="ja") {
   document.captureEvents(Event.KEYPRESS);
   document.onkeypress = disableRKey;
}

function disableRKey(e) {
   if (isMSIE4) {
      if(event.keyCode == 13)
         return false;
   } else {
      if(e!=null && e.which == 13)
         return false;
   }
   return true;
}

function enableNumKeys(e) {
   if (isMSIE4) {
      if(event.keyCode < 48 || event.keyCode > 57)
         return false;
   } else {
      if(e!=null && (e.which < 48 || e.which > 57))
         return false;
   }
   return true;
}

function enableValidChar(e) {
   if (isMSIE4) {
      if( event.keyCode == 38 || event.keyCode == 60 || event.keyCode == 62 || event.keyCode == 13 )
         return false;
   } else {
      if( e!=null && (e.which == '<' || e.which == '>' || e.which == '&' || e.which == 13 || e.which == 13) )
         return false;
   }
   return true;
}

/**
 * Performs checks about user fields in any user editor.
 *
 * CAUTION:
 *
 * Checks are are performed in all the following fields:
 * _ Login :
 *    * if the field does not exist: no check
 *    * checking if field is XML compliant
 *    * checking the field max size: a hidden input named Login_MaxSize **MUST** exist and its value set to IUserBean.LOGIN_LENGTH
 *    * checking the field min size: a hidden input named Login_MinSize **MUST** exist and its value set to 1 (checks a value is provided)
 * _ Firstname
 *    * if the field does not exist: no check
 *    * checking if field is HTML compliant
 *    * checking the field max size: a hidden input named Firstname_MaxSize **MUST** exist and its value set to IUserBean.FIRSTNAME_LENGTH
 *    * checking the field min size: a hidden input named Firstname_MinSize **MUST** exist and its value set to 1 (checks a value is provided)
 * _ Lastname
 *    * if the field does not exist: no check
 *    * checking if field is HTML compliant
 *    * checking the field max size: a hidden input named Lastname_MaxSize **MUST** exist and its value set to IUserBean.LASTNAME_LENGTH
 *    * checking the field min size: a hidden input named Lastname_MinSize **MUST** exist and its value set to 1 (checks a value is provided)
 * _ Password
 *    * if the field does not exist: no check
 *    * checking the field max size: a hidden input named Password_MaxSize **MUST** exist and its value set to IUserBean.PASSWORD_LENGTH
 *    * checking the field min size: a hidden input named Password_MinSize **MUST** exist and its value set to 1 (checks a value is provided)
 * _ PasswordCheck
 *    * if the field does not exist: no check
 *    * checking the field max size: a hidden input named PasswordCheck_MaxSize **MUST** exist and its value set to IUserBean.PASSWORD_LENGTH
 *    * checking the field min size: a hidden input named PasswordCheck_MinSize **MUST** exist and its value set to 1 (checks a value is provided)
 * _ Email
 *    * if the field does not exist: no check
 *    * checking if field is HTML compliant
 *    * checking the field max size: a hidden input named Email_MaxSize **MUST** exist and its value set to IUserBean.EMAIL_LENGTH
 * _ PhoneNumber
 *    * if the field does not exist: no check
 *    * checking if field is HTML compliant
 *    * checking the field max size: a hidden input named PhoneNumber_MaxSize **MUST** exist and its value set to IUserBean.PHONENUMBER_LENGTH
 * _ Description
 *    * if the field does not exist: no check
 *    * checking the field max size: a hidden input named Description_MaxSize **MUST** exist and its value set to IUserBean.DESCRIPTION_LENGTH
 *
 * ADDITIONNAL NOTE: if Password & PasswordCheck fields exist, a check is performed to verify the 2 value set are the same.
 *
 * @param   strFormName   the name of the current form HTML object
 * @return  true/false depending on the checks results
 */
function _checkUserEditorFields(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var field;

   if (formCheckFieldExist(strFormName, 'Login')) {
      if (!formCheckFieldContent(strFormName, 'Login', VERIFYSTRING_MINSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDLOGIN + " " + CCIL_USEREDITOR_MANDATORYFIELD);
         form.Login.focus();
         form.Login.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Login', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDLOGIN + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Login.focus();
         form.Login.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Login', VERIFYSTRING_COMPATIBLEXML)) {
         alert(CCIL_USEREDITOR_INVALIDLOGIN + " " + CCIL_USEREDITOR_XMLVALIDITY);
         form.Login.focus();
         form.Login.select();
         return false;
      }
   }

   if (formCheckFieldExist(strFormName, 'Firstname')) {
      if (!formCheckFieldContent(strFormName, 'Firstname', VERIFYSTRING_MINSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDFIRSTNAME + " " + CCIL_USEREDITOR_MANDATORYFIELD);
         form.Firstname.focus();
         form.Firstname.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Firstname', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDFIRSTNAME + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Firstname.focus();
         form.Firstname.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Firstname', VERIFYSTRING_COMPATIBLEHTML)) {
         alert(CCIL_USEREDITOR_INVALIDFIRSTNAME + " " + CCIL_USEREDITOR_HTMLVALIDITY);
         form.Firstname.focus();
         form.Firstname.select();
         return false;
      }
   }

   if (formCheckFieldExist(strFormName, 'Lastname')) {
      if (!formCheckFieldContent(strFormName, 'Lastname', VERIFYSTRING_MINSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDLASTNAME + " " + CCIL_USEREDITOR_MANDATORYFIELD);
         form.Lastname.focus();
         form.Lastname.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Lastname', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDLASTNAME + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Lastname.focus();
         form.Lastname.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Lastname', VERIFYSTRING_COMPATIBLEHTML)) {
         alert(CCIL_USEREDITOR_INVALIDLASTNAME + " " + CCIL_USEREDITOR_HTMLVALIDITY);
         form.Lastname.focus();
         form.Lastname.select();
         return false;
      }
   }

   if (formCheckFieldExist(strFormName, 'Password')) {
      if (!formCheckFieldContent(strFormName, 'Password', VERIFYSTRING_MINSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDPASSWORD + " " + CCIL_USEREDITOR_MANDATORYFIELD);
         form.Password.focus();
         form.Password.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Password', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDPASSWORD + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Password.focus();
         form.Password.select();
         return false;
      }

      if (formCheckFieldExist(strFormName, 'PasswordCheck')) {
         if (!formCheckFieldContent(strFormName, 'PasswordCheck', VERIFYSTRING_MINSIZE)) {
            alert(CCIL_USEREDITOR_INVALIDPASSWORDCHECK + " " + CCIL_USEREDITOR_MANDATORYFIELD);
            form.PasswordCheck.focus();
            form.PasswordCheck.select();
            return false;
         }
         if (!formCheckFieldContent(strFormName, 'PasswordCheck', VERIFYSTRING_MAXSIZE)) {
            alert(CCIL_USEREDITOR_INVALIDPASSWORDCHECK + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
            form.PasswordCheck.focus();
            form.PasswordCheck.select();
            return false;
         }

         if (form.Password.value != form.PasswordCheck.value) {
            alert(CCIL_USEREDITOR_PASSWORDDONTMATCH);
            form.Password.value = '';
            form.PasswordCheck.value = '';
            form.Password.focus();
            return false;
         }
      }
   }

   if (formCheckFieldExist(strFormName, 'Email')) {
      if (!formCheckFieldContent(strFormName, 'Email', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDEMAIL + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Email.focus();
         form.Email.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'Email', VERIFYSTRING_COMPATIBLEHTML)) {
         alert(CCIL_USEREDITOR_INVALIDEMAIL + " " + CCIL_USEREDITOR_HTMLVALIDITY);
         form.Email.focus();
         form.Email.select();
         return false;
      }
   }

   if (formCheckFieldExist(strFormName, 'PhoneNumber')) {
      if (!formCheckFieldContent(strFormName, 'PhoneNumber', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDPHONENUMBER + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.PhoneNumber.focus();
         form.PhoneNumber.select();
         return false;
      }
      if (!formCheckFieldContent(strFormName, 'PhoneNumber', VERIFYSTRING_COMPATIBLEHTML)) {
         alert(CCIL_USEREDITOR_INVALIDPHONENUMBER + " " + CCIL_USEREDITOR_HTMLVALIDITY);
         form.PhoneNumber.focus();
         form.PhoneNumber.select();
         return false;
      }
   }

   if (formCheckFieldExist(strFormName, 'Description')) {
      if (!formCheckFieldContent(strFormName, 'Description', VERIFYSTRING_MAXSIZE)) {
         alert(CCIL_USEREDITOR_INVALIDDESCRIPTION + " " + CCIL_USEREDITOR_MAXSIZETOOBIG);
         form.Description.focus();
         form.Description.select();
         return false;
      }
   }
   return true;
}
