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;
}
function frontOnLoad(strFormName) {
   popupParentExecuteOnLoad(strFormName);
   tickerInit(strFormName);
   _frontFocusOnKeyword();
}

function _frontFocusOnKeyword(strFormName) {
   var keywordField;
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   keywordField=eval("form.docSearch_SearchKeyWord");
   if (keywordField != null && keywordField.type == "text")
      keywordField.focus();
}

// To be **TRASHED** after cleaning
function viewDocument(strFormName, nDocExtId, nSecMode, strUrl) {
   viewDocumentInCurrentWindow(strFormName, nDocExtId, nSecMode, strUrl);
}

function frontSetWorkingCtx(strFormName, strType, strId) {
   var form = formGetForm(strFormName);

   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   try {
      searchReset();
   } catch(e) {}
   frontQuitSearch(strFormName);
   form.ContextType.value=strType;

   strId = form.select_ctx.value;

   form.ContextId.value=strId;
   formSubmitExecuteCommand(strFormName, "com.instranet.CCILCmdSetWorkingContext", form.Origin.value, "_self");

   return false;
}

// Search related Functions

function frontSelectMenuTab(strFormName, nTab, strUrl) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (form.PerformSearch != null) {
      form.ResetContext.value='true';
      _frontSearchReset(strFormName);
      _frontSearchResetKeyword(strFormName);
   }
   if (form.PerformSearch != null)
      form.PerformSearch.value="false";


   selectMenuTab(strFormName, nTab, strUrl, "MenuSelectedTab");

   return false;
}

function _frontSearchReset(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.Reinitialize.value="true";
   if (form.page1 != null)
      form.page1.value=1;
   if (form.page2 != null)
      form.page2.value=1;
}

function _frontSearchResetKeyword(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.ReinitializeKeyword.value="true";
}

function frontDoSearch(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.PerformSearch.value="true";
   if (form.page1 != null)
      form.page1.value=1;
   if (form.page2 != null)
      form.page2.value=1;
   formSubmitUrl(strFormName, form.Origin.value, "_self");

   return false;
}


function frontQuitSearch(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.PerformSearch.value="false";
   if (form.page1 != null)
      form.page1.value=1;
   if (form.page2 != null)
      form.page2.value=1;
   formSubmitUrl(strFormName, form.Origin.value, "_self");

   return false;
}

function frontSearchOnReturn(strFormName, evt) {
   var nCharCode;
   if (evt.keyCode != null)
      nCharCode=evt.keyCode;
   else if (evt.which != null)
      nCharCode=evt.which;
   if (nCharCode == 13) {
      frontDoSearch(strFormName);
      return false;
   }

   return true;
}

function ChangePageKnowledgeBase(strFormName, strPage) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.page1.value=strPage;
   form.PerformSearch.value="true";
   formSubmitUrl(strFormName, form.Origin.value, "_self");

   return false;
}

function ChangePageUpsell(strFormName, strPage) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.page2.value=strPage;
   form.PerformSearch.value="true";
   formSubmitUrl(strFormName, form.Origin.value, "_self");

   return false;
}

function CustomerSelector(url) {
   var pop = window.open(url,"CtiSimulator","toolbar=0,location=0,directories=0,status=0 ,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=400,height=250");
   pop.focus();
   return true;
}

function frontDoClearSearch(strFormName){
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

//   form.PerformSearch.value="true";

   form.docSearch_SearchKeyWord.value="";
   form.docSearchCommunity6.value="0";
   form.docSearchCommunity11.value="0";
   form.docSearchCommunity12.value="0";


   form.includePromos.r1.checked=false;
   form.includePromos.r2.checked=false;

   form.searchDocId.checked=false;



//   if (form.page1 != null)
//      form.page1.value=1;
//   if (form.page2 != null)
//      form.page2.value=1;
//   formSubmitUrl(strFormName, form.Origin.value, "_self");

   return false;
}


//code commented cause the doc previsualization popup automatic close has to be coded cleanly
function genericRendererOnLoad(strFormName, strParentFormName, bIsPopup, strNewNotesUrl) {
//   if (bIsPopup)
//      popupExecuteOnLoad(strFormName, strParentFormName);
   popupParentExecuteOnLoad(strFormName);
   if (strNewNotesUrl != null && strNewNotesUrl.length > 0)
       genericRendererViewNewNotes(strFormName, strNewNotesUrl);
}
//code commented cause the doc previsualization popup automatic close has to be coded cleanly
function genericRendererOnUnload(strFormName, strParentFormName, bIsPopup) {
//   if (bIsPopup)
//      popupExecuteOnUnload(strFormName, strParentFormName)

   popupParentExecuteOnUnload(strFormName);
}

function genericRendererDisplayDocument(strFormName, nDocExtId, 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.SelectedSectionId.value = '';
   form.DocRead.value = '';
   form.DocToRead.value = '';
   form.DocRecommended.value = '';
   form.FireEvent.value = 'true';

   formSubmitUrl(strFormName, strUrl, "_self");

   return false;
}

function genericRendererBackClicked(strFormName, nDocExtId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   formSubmitUrl(strFormName, form.ComesFrom.value, "_self");

   return false;
}

function genericRendererSubmitRating(strFormName, strRedirect) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }
   formSubmitExecuteCommand(strFormName, "com.instranet.CCILCmdRatingSave", strRedirect, "_self");

   return false;
}

function genericRendererRecommendDoc(strFormName, nAction, nDocExtId) {
   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.ActionId.value = nAction;
   form.DocRecommended.value = true;

   genericRendererSubmitRating(strFormName, form.Origin.value);

   return false;
}

function genericRendererValidateDocRead(strFormName, nAction, nDocExtId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }
   form.StoredDocId.value = form.DocId.value;
   form.DocId.value = nDocExtId;
   form.DocRead.value = true;
   form.DocToRead.value = false;
   form.ActionId.value = nAction;

   genericRendererSubmitRating(strFormName, form.Origin.value);

   return false;
}

function _genericRendererAddInfo(strFormName, nAction) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }
   form.ActionId.value = nAction;

   formRefresh(strFormName);
}

function genericRendererFeedbackSend(strFormName, strFeedbackEditorUrl, nExternalDocumentId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.StoredDocId.value = form.DocId.value;
   form.DocId.value = '';
   form.LinkedDocumentExtId.value = nExternalDocumentId;
   popupParentOpenPopup(strFormName, "FeedbackEditorWindow", null, strFeedbackEditorUrl, 600, 400);

   return false;
}

function genericRendererDisplayLastDocs() {
   if (xGetElementById("ccilextnavbarlvdmnu") != null) {
      xGetElementById("ccilextnavbarlvdmnu").style.visibility='visible';
      xGetElementById("ccilextnavbarlvd").style.zIndex=5;
   }
}

function genericRendererDisplaySeeAlso(strFormName) {
   if (xGetElementById("ccilextnavbarsalmnu") != null) {
      xGetElementById("ccilextnavbarsalmnu").style.visibility='visible';
      xGetElementById("ccilextnavbarsal").style.zIndex=5;
   }
}

function genericRendererHideLastDocs() {
   if (xGetElementById("ccilextnavbarlvdmnu") != null) {
      xGetElementById("ccilextnavbarlvdmnu").style.visibility='hidden';
      xGetElementById("ccilextnavbarlvd").style.zIndex=0;
   }
}

function genericRendererHideSeeAlso() {
   if (xGetElementById("ccilextnavbarsalmnu") != null) {
      xGetElementById("ccilextnavbarsalmnu").style.visibility='hidden';
      xGetElementById("ccilextnavbarsal").style.zIndex=0;
   }
}

function genericRendererHideSubMenu(strFormName) {
   if (xGetElementById("ccilextnavbarlvdmnu") != null && xGetElementById("ccilextnavbarlvdmnu").style.visibility == 'visible')
         genericRendererHideLastDocs();

   if (xGetElementById("ccilextnavbarsalmnu") != null && xGetElementById("ccilextnavbarsalmnu").style.visibility == 'visible')
      genericRendererHideSeeAlso();
}

function genericRendererPreviousSectionsClicked(strFormName, nLine) {
   var lineId = xGetElementById("line"+(nLine-1));
   lineId.style.visibility='visible';

   var previousLineId = xGetElementById("line"+nLine);
   previousLineId.style.visibility='hidden';

   return false;
}

function genericRendererNextSectionsClicked(strFormName, nLine) {
   var lineId = xGetElementById("line"+(nLine+1));
   lineId.style.visibility='visible';

   var previousLineId = xGetElementById("line"+nLine);
   previousLineId.style.visibility='hidden';

   return false;
}

function genericRendererSectionSelected(strFormName, nSectionId) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var previousSelectedSectionIdTab;
   var previousSelectedSectionIdTabSel;
   var sectionIdTab;
   var sectionIdTabSel;
   var previousSelectedSectionId;
   var sectionId;

   previousSelectedSectionIdTab = xGetElementById("section"+form.SelectedSectionId.value);
   previousSelectedSectionIdTab.style.visibility='inherit';

   previousSelectedSectionIdTabSel = xGetElementById("sectionsel"+form.SelectedSectionId.value);
   previousSelectedSectionIdTabSel.style.visibility='hidden';

   sectionIdTab = xGetElementById("section"+nSectionId);
   sectionIdTab.style.visibility='hidden';

   sectionIdTabSel = xGetElementById("sectionsel"+nSectionId);
   sectionIdTabSel.style.visibility='inherit';

   previousSelectedSectionId = xGetElementById("sectiondisplay"+form.SelectedSectionId.value);
   previousSelectedSectionId.style.visibility='hidden';

   form.SelectedSectionId.value=nSectionId;

   sectionId = xGetElementById("sectiondisplay"+nSectionId);
   sectionId.style.visibility='visible';

   return false;
}

function genericRendererReloadSectionSelected(strFormName, nSectionId, nLine, bPopup) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.SelectedSectionId.value=nSectionId;
   form.SelectedLine.value=nLine;

   if (bPopup)
      popupRefresh(strFormName);
   else
      formRefresh(strFormName);

   return false;
}

function genericRendererSurveyReply(strFormName, nSurveyId, strQuestionPrefix) {
   var form = formGetForm(strFormName);

   form.QuestionPrefix.value = strQuestionPrefix;
   form.SurveyId.value = nSurveyId;

   formSubmitExecuteCommand(strFormName, "com.instranet.CCILCmdFeedbackSave", form.Origin.value, "_self");

   return false;
}

function genericRendererPrint(strFormName, strParentFormName, strUrl, nDocId, nSecMode) {

   window.open(strUrl+"?DocId="+nDocId+"&SecMode="+nSecMode,"PrintableRenderer","toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=800,height=600");
   return false;
}

function genericRendererViewIFrameContent(strUrl) {
   window.open(strUrl,"IFrameContent","toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=1,width=640,height=480");
   return false;
}

function genericRendererViewNewNotes(strFormName, strUrl) {
   window.open(strUrl,"NewNotes","toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=640,height=480");
   return false;
}
// x.js
// X v3.14.1, Cross-Browser DHTML Library from Cross-Browser.com
// Copyright (c) 2002,2003 Michael Foster (mike@cross-browser.com)
// This library is distributed under the terms of the LGPL (gnu.org)

// Variables:
var xVersion='3.14.1',xOp7=false,xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) {xNN4=true;}
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}
// Object:
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}
function xParent(e,bNode){
  if (!(e=xGetElementById(e))) return null;
  var p=null;
  if (!bNode && xDef(e.offsetParent)) p=e.offsetParent;
  else if (xDef(e.parentNode)) p=e.parentNode;
  else if (xDef(e.parentElement)) p=e.parentElement;
  else if (xDef(e.parentLayer)){if (e.parentLayer!=window) p=e.parentLayer;}
  return p;
}
function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xStr(s) {
  return typeof(s)=='string';
}
function xNum(n) {
  return typeof(n)=='number';
}
// Appearance:
function xShow(e) {
  if(!(e=xGetElementById(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='visible';
  else if(xDef(e.visibility)) e.visibility='show';
}
function xHide(e) {
  if(!(e=xGetElementById(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='hidden';
  else if(xDef(e.visibility)) e.visibility='hide';
}
function xZIndex(e,uZ) {
  if(!(e=xGetElementById(e))) return 0;
  if(e.style && xDef(e.style.zIndex)) {
    if(xNum(uZ)) e.style.zIndex=uZ;
    uZ=parseInt(e.style.zIndex);
  }
  else if(xDef(e.zIndex)) {
    if(xNum(uZ)) e.zIndex=uZ;
    uZ=e.zIndex;
  }
  return uZ;
}
function xColor(e,sColor) {
  if(!(e=xGetElementById(e))) return '';
  var c='';
  if(e.style && xDef(e.style.color)) {
    if(xStr(sColor)) e.style.color=sColor;
    c=e.style.color;
  }
  return c;
}
function xBackground(e,sColor,sImage) {
  if(!(e=xGetElementById(e))) return '';
  var bg='';
  if(e.style) {
    if(xStr(sColor)) {
      if(!xOp5or6) e.style.backgroundColor=sColor;
      else e.style.background=sColor;
    }
    if(xStr(sImage)) e.style.backgroundImage=(sImage!='')? 'url('+sImage+')' : null;
    if(!xOp5or6) bg=e.style.backgroundColor;
    else bg=e.style.background;
  }
  else if(xDef(e.bgColor)) {
    if(xStr(sColor)) e.bgColor=sColor;
    bg=e.bgColor;
    if(xStr(sImage)) e.background.src=sImage;
  }
  return bg;
}
// Position:
function xMoveTo(e,iX,iY) {
  xLeft(e,iX);
  xTop(e,iY);
}
function xLeft(e,iX) {
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if (css && xStr(e.style.left)) {
    if(xNum(iX)) e.style.left=iX+'px';
    else {
      iX=parseInt(e.style.left);
      if(isNaN(iX)) iX=0;
    }
  }
  else if(css && xDef(e.style.pixelLeft)) {
    if(xNum(iX)) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }
  else if(xDef(e.left)) {
    if(xNum(iX)) e.left=iX;
    else iX=e.left;
  }
  return iX;
}
function xTop(e,iY) {
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  else if(xDef(e.top)) {
    if(xNum(iY)) e.top=iY;
    else iY=e.top;
  }
  return iY;
}
function xPageX(e) {
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.pageX)) return e.pageX;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xPageY(e) {
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.pageY)) return e.pageY;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
//  if (xOp7) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324
  return y;
}
function xOffsetLeft(e) { // v3.14, see x_nn4.js
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.offsetLeft)) return e.offsetLeft;
  else return 0;
}
function xOffsetTop(e) {
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.offsetTop)) return e.offsetTop;
  else return 0;
}
function xScrollLeft(e) {
  var offset=0;
  if (!(e=xGetElementById(e))) {
    if(xDef(window.pageXOffset)) offset=window.pageXOffset;
    else if(document.documentElement && document.documentElement.scrollLeft) offset=document.documentElement.scrollLeft;
    else if(document.body && xDef(document.body.scrollLeft)) offset=document.body.scrollLeft;
  }
  else { if (xNum(e.scrollLeft)) offset = e.scrollLeft; }
  return offset;
}
function xScrollTop(e) {
  var offset=0;
  if (!(e=xGetElementById(e))) {
    if(xDef(window.pageYOffset)) offset=window.pageYOffset;
    else if(document.documentElement && document.documentElement.scrollTop) offset=document.documentElement.scrollTop;
    else if(document.body && xDef(document.body.scrollTop)) offset=document.body.scrollTop;
  }
  else { if (xNum(e.scrollTop)) offset = e.scrollTop; }
  return offset;
}
// Size:
function xResizeTo(e,uW,uH) {
  xWidth(e,uW);
  xHeight(e,uH);
}
function xWidth(e,uW) {
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(uW)) { // v3.13.1
    if (uW<0) uW = 0;
    else uW=Math.round(uW);
  }
  else uW=0;
  var css=xDef(e.style);
  if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(uW) xSetCW(e, uW);
    uW=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(uW) e.style.pixelWidth=uW;
    uW=e.style.pixelWidth;
  }
  else if(xDef(e.clip) && xDef(e.clip.right)) {
    if(uW) e.clip.right=uW;
    uW=e.clip.right;
  }
  return uW;
}
function xHeight(e,uH) {
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(uH)) { // v3.13.1
    if (uH<0) uH = 0;
    else uH=Math.round(uH);
  }
  else uH=0;
  var css=xDef(e.style);
  if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(uH) xSetCH(e, uH);
    uH=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(uH) e.style.pixelHeight=uH;
    uH=e.style.pixelHeight;
  }
  else if(xDef(e.clip) && xDef(e.clip.bottom)) {
    if(uH) e.clip.bottom=uH;
    uH=e.clip.bottom;
  }
  return uH;
}
function xGetCS(ele,sP){return parseInt(document.defaultView.getComputedStyle(ele,'').getPropertyValue(sP));}
function xSetCW(ele,uW){
  var pl=0,pr=0,bl=0,br=0;
  if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
    pl=xGetCS(ele,'padding-left');
    pr=xGetCS(ele,'padding-right');
    bl=xGetCS(ele,'border-left-width');
    br=xGetCS(ele,'border-right-width');
  }
  else if(xDef(ele.currentStyle,document.compatMode)){
    if(document.compatMode=='CSS1Compat'){
      pl=parseInt(ele.currentStyle.paddingLeft);
      pr=parseInt(ele.currentStyle.paddingRight);
      bl=parseInt(ele.currentStyle.borderLeftWidth);
      br=parseInt(ele.currentStyle.borderRightWidth);
    }
  }
  else if(xDef(ele.offsetWidth,ele.style.width)){ // ?
    ele.style.width=uW+'px';
    pl=ele.offsetWidth-uW;
  }
  if(isNaN(pl)) pl=0; if(isNaN(pr)) pr=0; if(isNaN(bl)) bl=0; if(isNaN(br)) br=0;
  var cssW=uW-(pl+pr+bl+br);
  if(isNaN(cssW)||cssW<0) return;
  else ele.style.width=cssW+'px';
}
function xSetCH(ele,uH){
  var pt=0,pb=0,bt=0,bb=0;
  if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
    pt=xGetCS(ele,'padding-top');
    pb=xGetCS(ele,'padding-bottom');
    bt=xGetCS(ele,'border-top-width');
    bb=xGetCS(ele,'border-bottom-width');
  }
  else if(xDef(ele.currentStyle,document.compatMode)){
    if(document.compatMode=='CSS1Compat'){
      pt=parseInt(ele.currentStyle.paddingTop);
      pb=parseInt(ele.currentStyle.paddingBottom);
      bt=parseInt(ele.currentStyle.borderTopWidth);
      bb=parseInt(ele.currentStyle.borderBottomWidth);
    }
  }
  else if(xDef(ele.offsetHeight,ele.style.height)){ // ?
    ele.style.height=uH+'px';
    pt=ele.offsetHeight-uH;
  }
  if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
  var cssH=uH-(pt+pb+bt+bb);
  if(isNaN(cssH)||cssH<0) return;
  else ele.style.height=cssH+'px';
}
function xClip(e,iTop,iRight,iBottom,iLeft) {
  if(!(e=xGetElementById(e))) return;
  if(e.style) {
    if (xNum(iLeft)) e.style.clip='rect('+iTop+'px '+iRight+'px '+iBottom+'px '+iLeft+'px)';
    else e.style.clip='rect(0 '+parseInt(e.style.width)+'px '+parseInt(e.style.height)+'px 0)';
  }
  else if(e.clip) {
    if (xNum(iLeft)) { e.clip.top=iTop; e.clip.right=iRight; e.clip.bottom=iBottom; e.clip.left=iLeft; }
    else { e.clip.top=0; e.clip.right=xWidth(e); e.clip.bottom=xHeight(e); e.clip.left=0; }
  }
}
// Window:
function xClientWidth() {
  var w=0;
  if(xOp5or6) w=window.innerWidth;
  else if(!window.opera && document.documentElement && document.documentElement.clientWidth) // v3.12
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}
function xClientHeight() {
  var h=0;
  if(xOp5or6) h=window.innerHeight;
  else if(!window.opera && document.documentElement && document.documentElement.clientHeight) // v3.12
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}
// Animation:
function xSlideTo(e,x,y,uTime) {
  if (!(e=xGetElementById(e))) return;
  if (!e.timeout) e.timeout = 25;
  e.xTarget = x; e.yTarget = y; e.slideTime = uTime; e.stop = false;
  e.yA = e.yTarget - xTop(e); e.xA = e.xTarget - xLeft(e); // A = distance
  e.B = Math.PI / (2 * e.slideTime); // B = period
  e.yD = xTop(e); e.xD = xLeft(e); // D = initial position
  var d = new Date(); e.C = d.getTime();
  if (!e.moving) xSlide(e);
}
function xSlide(e) {
  if (!(e=xGetElementById(e))) return;
  var now, s, t, newY, newX;
  now = new Date();
  t = now.getTime() - e.C;
  if (e.stop) { e.moving = false; }
  else if (t < e.slideTime) {
    setTimeout("xSlide('"+e.id+"')", e.timeout);
    s = Math.sin(e.B * t);
    newX = Math.round(e.xA * s + e.xD);
    newY = Math.round(e.yA * s + e.yD);
    xMoveTo(e, newX, newY);
    e.moving = true;
  }  
  else {
    xMoveTo(e, e.xTarget, e.yTarget);
    e.moving = false;
  }  
}
// Event:
function xAddEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  if((!xIE4Up && !xOp7) && e==window) {
    if(eventType=='resize') { window.xPCW=xClientWidth(); window.xPCH=xClientHeight(); window.xREL=eventListener; xResizeEvent(); return; }
    if(eventType=='scroll') { window.xPSL=xScrollLeft(); window.xPST=xScrollTop(); window.xSEL=eventListener; xScrollEvent(); return; }
  }
  var eh='e.on'+eventType+'=eventListener';
  if(e.addEventListener) e.addEventListener(eventType,eventListener,useCapture);
  else if(e.attachEvent) e.attachEvent('on'+eventType,eventListener);
  else if(e.captureEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.captureEvents(eval('Event.'+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}
function xRemoveEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  if((!xIE4Up && !xOp7) && e==window) {
    if(eventType=='resize') { window.xREL=null; return; }
    if(eventType=='scroll') { window.xSEL=null; return; }
  }
  var eh='e.on'+eventType+'=null';
  if(e.removeEventListener) e.removeEventListener(eventType,eventListener,useCapture);
  else if(e.detachEvent) e.detachEvent('on'+eventType,eventListener);
  else if(e.releaseEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.releaseEvents(eval('Event.'+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}
function xEvent(evt) { // cross-browser event object prototype
  this.type = '';
  this.target = null;
  this.pageX = 0;
  this.pageY = 0;
  this.offsetX = 0;
  this.offsetY = 0;
  this.keyCode = 0;
  var e = evt ? evt : window.event;
  if(!e) return;
  if(e.type) this.type = e.type;
  if(e.target) this.target = e.target;
  else if(e.srcElement) this.target = e.srcElement;
  else if(xNN4) this.target = xLayerFromPoint(e.pageX, e.pageY);
  if(xOp5or6) { this.pageX = e.clientX; this.pageY = e.clientY; }
  else if(xDef(e.pageX,e.pageY)) { this.pageX = e.pageX; this.pageY = e.pageY; } // v3.14
  else if(xDef(e.clientX,e.clientY)) { this.pageX = e.clientX + xScrollLeft(); this.pageY = e.clientY + xScrollTop(); }
  if(xDef(e.offsetX,e.offsetY)) { this.offsetX = e.offsetX; this.offsetY = e.offsetY; }
  else if(xDef(e.layerX,e.layerY)) { this.offsetX = e.layerX; this.offsetY = e.layerY; }
  else { this.offsetX = this.pageX - xPageX(this.target); this.offsetY = this.pageY - xPageY(this.target); }
  if (e.keyCode) { this.keyCode = e.keyCode; } // for moz/fb, if keyCode==0 use which
  else if (xDef(e.which)) { this.keyCode = e.which; }
}
function xResizeEvent() { // window resize event simulation
  if (window.xREL) setTimeout('xResizeEvent()', 250);
  var cw = xClientWidth(), ch = xClientHeight();
  if (window.xPCW != cw || window.xPCH != ch) { window.xPCW = cw; window.xPCH = ch; if (window.xREL) window.xREL(); }
}
function xScrollEvent() { // window scroll event simulation
  if (window.xSEL) setTimeout('xScrollEvent()', 250);
  var sl = xScrollLeft(), st = xScrollTop();
  if (window.xPSL != sl || window.xPST != st) { window.xPSL = sl; window.xPST = st; if (window.xSEL) window.xSEL(); }
}
// end x.js

var fitterTimer;
var fitterSpeed = 500;
var count = 0;
var maxFit = 10;

function iframeFitterInit() {
   if (document.getElementsByTagName('iframe').length>0) {
      fitterTimer = window.setTimeout("iframeFitter()", 0);
   }
}

function iframeFitter() {
   var iframes = document.getElementsByTagName('iframe');

   for (var i = 0; i < iframes.length; i++) {
      try {
         if (iframes[i].contentDocument && iframes[i].contentDocument.body.offsetHeight) { //ns6 syntax
            iframes[i].height = (iframes[i].contentDocument.body.offsetHeight+30)+"px";
         } else if (iframes[i].Document && iframes[i].Document.body.scrollHeight) { //ie5+ syntax
            iframes[i].height = (iframes[i].Document.body.scrollHeight+30)+"px";
         }
      } catch(e) {
         // if the content is not html...
      }
   }

   count++;
   if (count<maxFit)
      fitterTimer = window.setTimeout("iframeFitter()", fitterSpeed);
}


/**
 * Check if we have a valid front office module search to perform
 *
 * @param   strFormName the name of the current form
 *
 * @return  false/false depending on the result
 */
function validateFrontSearch(strFormName) {
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }
       
	if ((parseInt(form.docSearch_SearchKeyWord.value) != form.docSearch_SearchKeyWord.value) && (form.searchDocId.checked)) {
		alert('Please enter a valid document id to search');
		form.docSearch_SearchKeyWord.focus();
		form.docSearch_SearchKeyWord.select();
		return false;
                
	}else if (((parseInt(form.docSearch_SearchKeyWord.value) == form.docSearch_SearchKeyWord.value) && (form.searchDocId.checked)) || !(form.searchDocId.checked)){
                frontDoSearch(strFormName);
                return true;
        }
	
}

function validateSSILSearch(strFormName) {
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }


	if (form.docSearch_SearchKeyWord.value == "")
	{
		alert("Please enter Keyword(s)");
	  	return false;
	}
	{
		form.fromSearch.value="true";
                form.PerformSearch.value="true";

		formSubmitUrl(strFormName, form.Redirect.value, "_self");
        	return true;
	}


	
}

function ssilSearchOnReturn(strFormName, evt) {
   var nCharCode;
   if (evt.keyCode != null)
      nCharCode=evt.keyCode;
   else if (evt.which != null)
      nCharCode=evt.which;
   if (nCharCode == 13) {
      validateSSILSearch(strFormName);
      return false;
   }

   return true;
}

function validateProdSSILSearch(strFormName) {
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }

		if (form.docSearchCommunity6.value == "0")
		{
			return false;
		}

	
		if (form.tempCustomerZip.value == "000000" && form.docSearchCommunity6.value != 252 && form.docSearchCommunity6.value != 254)
	        {
		    var tempCommunity = form.docSearchCommunity6.value;

		    var product = "";

		    if (tempCommunity == "250")
		    {
			product = "DigitalTV";
	            }
		    else if (tempCommunity == "251")
		    {
			product = "Internet";
		    }
		    else if (tempCommunity == "248")
		    {
			product = "Telephone";
		    }

		    form.action = form.zipCodeCheckURL.value + "?Product=" + product;
		
		    form.submit();
		    return true;
		}
		else
	        {
     			form.fromSearch.value="true";
                	form.PerformSearch.value="true";
			form.addImportantDocs.value="false";

			formSubmitUrl(strFormName, form.Redirect.value, "_self");
        		return true;
		}

}


function ssilProdSearchOnReturn(strFormName, evt) {
   var nCharCode;
   if (evt.keyCode != null)
      nCharCode=evt.keyCode;
   else if (evt.which != null)
      nCharCode=evt.which;
   if (nCharCode == 13) {
      validateProdSSILSearch(strFormName);
      return false;
   }

   return true;
}

/**
 * Check if we have a valid publisher desk module search to perform
 *
 * @param   strFormName the name of the current form
 *
 * @return  false/false depending on the result
 */
function validatePublisherSearch(strFormName) {
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        } 
	if ((parseInt(form.DocSearch_SearchKeyWord.value) != form.DocSearch_SearchKeyWord.value) && (form.searchDocId.checked)) {
		alert('Please enter a valid document id to search');
		form.DocSearch_SearchKeyWord.focus();
		form.DocSearch_SearchKeyWord.select();
		return false;
                
	}else if (((parseInt(form.DocSearch_SearchKeyWord.value) == form.DocSearch_SearchKeyWord.value) && (form.searchDocId.checked)) || !(form.searchDocId.checked)){
                return docSearchFiltersSearch(strFormName);
        }
	
}
/**
 * prepare and direct to view all favorites documents
 *
 * @param   strFormName the name of the current form
 * @param   strURL of redirect page
 *
 */
function viewAllFavorites(strFormName,strURL)
{
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }

        form.ViewAllFavorites.value='true';
        form.MenuSelectedTab.value='0';
        formSubmitUrl(strFormName, strURL, "_self");
        
}

/**
 * remove a favorite, from the 'all favorites' page
 *
 * @param   strFormName the name of the current form
 * @param   nDocExtId doc id of the doc we want to remove from favorites
 *
 */
function removeFromAllFavorites(strFormName,nDocExtId)
{
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }
        form.ViewAllFavorites.value='true';
        form.RemoveDocId.value=nDocExtId;
        formSubmitExecuteCommand(strFormName, 'com.instranet.CCILCmdFavoritesDel', form.Origin.value, "_self");

        return false;
}

/**
 * remove all favorites, from the 'all favorites' page
 *
 * @param   strFormName the name of the current form
 *
 */
function emptyFromAllFavorites(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";
      form.ViewAllFavorites.value='true';
      formSubmitExecuteCommand(strFormName, 'com.instranet.CCILCmdFavoritesDel', form.Origin.value, "_self");
   }

   return false;
}

/**
 * display 'Promotions documents'
 *
 * @param   strFormName the name of the current form
 * @param   strURL of redirect page
 *
 */  
function viewAllPromotions(strFormName,strURL)
{
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }
        form.ViewAllPromotions.value='true';
        formSubmitUrl(strFormName, strURL, "_self");
}

/**
 * display 'Alerts documents'
 *
 * @param   strFormName the name of the current form
 * @param   strURL of redirect page
 *
 */  
function viewAllAlerts(strFormName,strURL)
{
        var form = formGetForm(strFormName);
        if (form == null) {
        _formFatal("cannot find a valid form. Probably because some fields are missing");
        return false;
        }
        form.ViewAllAlerts.value='true';
        form.MenuSelectedTab.value='0';
        formSubmitUrl(strFormName, strURL, "_self");
}


function ChangePageFavorites(nNewPage) {
   document.HomePageForm.page.value=nNewPage;
   document.HomePageForm.ViewAllFavorites.value='true';
   document.HomePageForm.MenuSelectedTab.value='0';
   document.HomePageForm.submit();

   return false;
}

function ChangePageAlerts(nNewPage) {
   document.HomePageForm.page.value=nNewPage;
   document.HomePageForm.ViewAllAlerts.value='true';
   document.HomePageForm.MenuSelectedTab.value='0';
   document.HomePageForm.submit();

   return false;
}

function ChangePagePromotions(nNewPage) {
   document.promotionForm.page.value=nNewPage;
   document.promotionForm.submit();

   return false;
}

function feedbackeditionSaveFeedback(strFormName, strUrl, bFeedbackYetAnswered) {
   var strTitle ="";
   var nNumberOfWords = 10;
   var form;

   form=formGetForm(strFormName);

   if (form.pb_solved[0].checked == false && form.pb_solved[1].checked == false) {
      alert('Please, choose a resolution state about this document before submitting your feedback');
      return false;
   }

   strInput = _feedbackeditionTrim(form.Field_FeedbackSection_Question.value);
   if (form.pb_solved[0].checked == true) {
      if (!_feedbackeditionChangeAudience(strFormName, form.pb_solved[0].value, bFeedbackYetAnswered, strInput))
         return false;
   } else {
      if (!_feedbackeditionChangeAudience(strFormName, form.pb_solved[1].value, bFeedbackYetAnswered, strInput))
         return false;
   }

   arr = strInput.split(" ");
   if (nNumberOfWords > arr.length)
      nNumberOfWords = arr.length;
   for(i=0;i<nNumberOfWords;i++) {
      strTitle += arr[i];
      if (i != nNumberOfWords - 1)
         strTitle += ' ';
   }

   strTitle = strTitle.replace(/\"/g,'');
   // " emacs display
   strTitle = strTitle.replace(/</g,'');
   strTitle = strTitle.replace(/>/g,'');

   form.Title.value=strTitle;
   if (!formCheckFieldContent(form.name, "Title", VERIFYSTRING_MAXSIZE) || (nNumberOfWords != arr.length)) {
      // find the max size for title field.
      var nMaxSize;
      var maxSizeField = eval("form.Title"+ MAXLENGTH_SUFFIX);
      if (!_formCheckFieldExist(maxSizeField)) {
         _formFatal("Cannot find the hidden field Title" + MAXLENGTH_SUFFIX + ": it is a mandatory field to check max size");
         return false;
      }
      nMaxSize = parseInt(maxSizeField.value);
      if (!formCheckFieldContent(form.name, "Title", VERIFYSTRING_MAXSIZE)) {
         strTitle = strTitle.substring(0,nMaxSize-3);
         strTitle += "...";
      } else if (nNumberOfWords != arr.length) {
         if (!formCheckFieldContent(form.name, "Title", VERIFYSTRING_MAXSIZE)) {
            strTitle = strTitle.substring(0,nMaxSize-3);
            strTitle += "...";
         } else {
            strTitle += " ...";
         }
      }
   }
   if (strTitle.length == 0) {
      strTitle = form.DefaultTitle.value;
   }
   form.Title.value=strTitle;
   form.FeedbackAnswered.value='true';
   editorSaveQuit(strFormName, strUrl, 'none');
}

function _feedbackeditionTrim(inputString) {
   cpt=0;

   var retValue = inputString;

   var ch = retValue.substring(0, 1);
   while (ch.charCodeAt(0) == 10 || ch.charCodeAt(0) == 32) {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch.charCodeAt(0) == 10 || ch.charCodeAt(0) == 32) {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue;
}

function _feedbackeditionChangeAudience(strFormName, nItemId, bFeedbackYetAnswered, strAnswer) {
   var strIdsList, strIdsLineList, strIdsRemainingList, strNewIdsList;
   var nIndex;
   var nRootHelpFullItemId;
   var form=formGetForm(strFormName);

   if (nItemId == form.helpfull_no.value && !bFeedbackYetAnswered) {
      if (strAnswer.length == 0 && form.helpfull_no_alertMessageDisplayed.value == "false") {
         alert(form.helpfull_no_alertMessage.value);
         form.helpfull_no_alertMessageDisplayed.value = "true";
         return false
      }
      form.UselessDocId.value = form.DocId.value;
   }

   strIdsList = form.Audiences_FeedbackSection.value;
   nRootHelpFullItemId = form.HelpFull_rootitem.value;

   var nIndex = strIdsList.indexOf(",");

   strIdsLineList = strIdsList.substr(0, nIndex);
   strIdsRemainingList = strIdsList.substr(nIndex+1, strIdsLineList.length+1);
   strNewIdsList = _feedbackeditionChangeAudienceLine(strIdsLineList, nRootHelpFullItemId, nItemId);
   while (strIdsRemainingList.indexOf(",") != -1) {
      nIndex = strIdsRemainingList.indexOf(",");
      strIdsLineList = strIdsRemainingList.substr(0, nIndex);
      strIdsRemainingList = strIdsRemainingList.substr(nIndex+1, strIdsRemainingList.length+1);
      strNewIdsList += _feedbackeditionChangeAudienceLine(strIdsLineList, nRootHelpFullItemId, nItemId);
   }

   form.Audiences_FeedbackSection.value = strNewIdsList;

   return true;
}

function _feedbackeditionChangeAudienceLine(strIdsLine, nRootHelpFullItemId, nItemId) {
   var strNewIdsListStart, strNewIdsListEnd, strNewLine;
   var strIdToReplace = ";"+nRootHelpFullItemId+";";
   var nIndex = strIdsLine.indexOf(strIdToReplace);

   
   strNewIdsListStart = strIdsLine.substr(0, nIndex);
   strNewIdsListEnd = strIdsLine.substr(nIndex+strIdToReplace.length, strIdsLine.length);
   
   return strNewIdsListStart+";"+nItemId+";"+strNewIdsListEnd+",";
}

var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

// DPS Variable
var DPSLaunchURL = '';

// Presentation variable
var BlobChooserHeight = 465;
var BlobChooserWidth = 505;
var BlobChooserScrolling = 0;
var DocChooserHeight = 500;
var DocChooserWidth = 400;
var BlobImporterHeight = 120;
var BlobImporterWidth = 400;
var BlobImporterScrolling = 0;
var MPChooserHeight = 350;

var strPreviewUrl;

// Control window status
var winMyTasksAction = null;

function editorOnLoad(strFormName) {
   popupParentExecuteOnLoad(strFormName);
}

function editorOnUnload(strFormName) {
   popupParentExecuteOnUnload(strFormName);
}

function _editorRefreshOpener(strOpenerUrl) {
   if (window.opener != null) {
      window.opener.document.launchForm.target="_self";
      window.opener.ReloadWin("_self", "launchForm", strOpenerUrl, "", "");

      return false;
   }
}

function editorChangeSection(strFormName, nSection, strUrl) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   _editorCheck(strFormName);

   if  (form.DocumentChanged.value=='1') {
      if (!confirm(CCILP_DOCEDITOR_CHANGESECTIONCONFIRM)) {
         return false;
      }
   }

   form.SelectedSection.value=nSection;
   DPSLaunchURL = '';
   formSubmitUrl(strFormName, strUrl, form.target);

   return false;
}

function editorSaveCCILDoc(strFormName) {
/*
   Perform the checks of save() because it returns always false.
   We have no way to know whether the save was actually performed or not.
   We do not need to refresh the opener since nothing was changed.
*/
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (_editorCheck(strFormName)==false) {
      return false;
   }
   if (_editorFillMultipleFields(strFormName) == false) {
      return false;
   }

   form.QuitCCILEditor.value='0';
   editorSave(strFormName, 'none');

   return false;
}

function editorSaveAndPreviewCCILDoc(strFormName) {
   // Sumbit
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (form.DocumentChanged.value=='1') {
      if (!confirm(CCILP_DOCEDITOR_CONFIRMCHANGEBEFOREPREVIEW)) {
         return false;
      }
   }

   form.PreviewCCILEditor.value='1';
   DPSLaunchURL = '';
   editorSaveCCILDoc(strFormName);

   return false;
}

function _editorGetDays(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 _editorFillSimpleFields(strFormName) {

   var loopEl, elem;
   var objElement;
   var id;
   var form = eval("document."+strFormName);
   var simple = false;

   for (loopEl=0; loopEl<form.length; loopEl++) {
      objElement = form.elements[loopEl];
      if (objElement.name.indexOf("IdDocPos")==0) {
         var strPosition="";
         if (form.Positions.value=="") {
            for (i=1;i<=16;i++) {
               if (eval("form.IdDocPos"+i)!=null) {
                  strPosition += eval("form.IdDocPos"+i).value;
                  strPosition += ";";
               }
            }
            strPosition+= form.PositionDimItemAdded.value;
            form.Positions.value = strPosition;
         }
      }

      if (objElement.name.indexOf("IdAud_")==0) {
         var strAudience="";
         var objName = objElement.name;
         var sectionName = objName.substring(6);
         var cpt = 0;
         var audienceElem;

         cpt = sectionName.length;
         while (cpt>0 && (sectionName.charAt(cpt)!='_')) {
            cpt--;
         }
         sectionName = sectionName.substring(0,cpt);
         audienceElem = eval("form.Audiences_"+sectionName);

         if (audienceElem.value=="") {
            for (i=1;i<=16;i++) {
               if (eval("form.IdAud_"+sectionName+"_"+i)!=null) {
                  strAudience += eval("form.IdAud_"+sectionName+"_"+i).value;
                  strAudience += ";";
               }
            }
            strAudience+= form.AudiencesDimItemAdded.value;
            audienceElem.value = strAudience;
         }
      }
   }

   return true;
}

function _editorFillMultipleFields(strFormName) {
   return _editorCheckMultipleFields(strFormName, true);
}

function _editorCheckMultipleFields(strFormName, bCheckMultiples) {

   // Fill the multi rows position and audiences
   var loopEl;
   var objElement;
   var sectionName;
   var form = eval("document."+strFormName);

   for (loopEl=0; loopEl<form.length; loopEl++) {
      objElement = form.elements[loopEl];

      if (objElement.name == "DocPositions") {
         // Fill the mutli position
         var elem = form.DocPositions;
         var strPositions = "";
         var nCurOpt = 0;
         while (nCurOpt<elem.length) {
            strPositions+=elem[nCurOpt].value;
            if (form.PositionDimItemAdded.value!="") {
               strPositions+= ";"+ form.PositionDimItemAdded.value;
            }
            if (nCurOpt<elem.length-1) {
               strPositions+=",";
            }
            nCurOpt++;
         }
         if (bCheckMultiples && form.PositionMandatory.value=="true") {
            if (strPositions=="") {
               alert(EDITORPOSITIONMANDATORY);
               return false;
            }
         }
         form.Positions.value = strPositions;
      }
      if (objElement.name.indexOf("SectAudiences_")!=-1 || objElement.name == "DocAudiences") {
         if (objElement.name.indexOf("SectAudiences_")!=-1) {
            sectionName = objElement.name.substring(14);
            elem = eval("form.Audiences_"+sectionName);
         } else
            elem = form.Audiences;

         strPositions = "";
         nCurOpt = 0;
         while (nCurOpt<objElement.length) {
            strPositions+=objElement[nCurOpt].value;
            if (form.AudiencesDimItemAdded.value!="") {
               strPositions+= ";"+form.AudiencesDimItemAdded.value;
            }
            if (nCurOpt<objElement.length-1) {
               strPositions+=",";
            }
            nCurOpt++;
         }
         if (form.AudienceMandatory.value=="true") {
            if (bCheckMultiples && strPositions=="") {
               alert(EDITORAUDIENCEMANDATORY);
               return false;
            }
         }
         elem.value = strPositions;
      }
   }
   return true;
}


function editorActionFromSelect(strFormName, Select) {
   var strDocAction  = Select.options[Select.selectedIndex].value;
   var strActionName = Select.options[Select.selectedIndex].text;
   var strExecCommand;
   var strActionId;
   var strPopup;

   strExecCommand = strDocAction.substring(strDocAction.lastIndexOf(";")+1);
   strDocAction = strDocAction.substring(0, strDocAction.length - strExecCommand.length -1);

   strPopup = strDocAction.substring(strDocAction.lastIndexOf(";")+1);

   strActionId = strDocAction.substring(0, strDocAction.length - strPopup.length -1);

   return editorAction(strFormName, strActionId, strPopup, true, "", strExecCommand);
}


function editorAction(strFormName, strActionId, strPopup, checkChanges, forwardUrl, strExecCommand) {
   var strType;
   var win = null;
   var bAdmin;
   var strCommand;

   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (strActionId == "" || strPopup == "")
      return false;

   // some checks
   if (_editorCheck(strFormName)==false) {
      return false;
   }

   if (_editorFillMultipleFields(strFormName)==false) {
      return false;
   }
   _editorFillSimpleFields(strFormName);

   if  (form.DocumentChanged.value=="1" && checkChanges==true) {
      if (!confirm(EDITORCONFIRMWORKFLOW)) {
         return false;
      }
   }

   bAdmin      = 0;
   // 9 = delete action
   if (strActionId == 9)
      if (!confirm(MYTASKSDELCONFIRM))
         return false;

   form.ActionName.value = "";
   form.ActionId.value   = strActionId;
   if (forwardUrl == "") {
      form.Redirect.value=form.ComesFrom.value;
   } else {
      form.Redirect.value=forwardUrl;
   }

   form.DocumentChanged.value="0";
   form.Save.value="1";
   form.Release.value="1";
   form.WorkflowAction.value="1";

   if (strPopup == "false") {
      if (strExecCommand == "none")
         strExecCommand = "com.instranet.CmdEditorSaveDoc";

      formSubmitExecuteCommand(strFormName, strExecCommand, form.Redirect.value, "_self");

      return false;
   } else {
      if (strExecCommand == "none")
         strExecCommand = "";

      popupParentOpenPopup(strFormName, "ExecuteActionPopUp", strExecCommand, form.MyTasksActionsJsp.value, 545, 540);

      return false;
   }
}


function _editorExtractFieldName(str) {
   // The str begins with Field_

   if (str.substring(0,6)!="Field_") {
      return str;
   }
   str = str.substring(6);
   strMod = str.substring(str.indexOf('_')+1);
   strNumber = strMod.substring(0,strMod.indexOf('_'));
   if (!isNaN(parseInt(strNumber))) {
      strMod = strMod.substring(strMod.indexOf('_') + 1);
   }
   return  strMod;
}

function _editorltrim(inputString) {
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
       retValue = retValue.substring(1, retValue.length);
       ch = retValue.substring(0, 1);
    }
    return retValue;
}

function _editorCheck(strFormName) {
   return _editorAdvancedCheck(strFormName, '');
}

function _editorAdvancedCheck(strFormName, strNotCheckedField) {
   var objElement;
   var strRoot;
   var nDay, nMonth, nYear, strVal, nVal, nMax, nMin;
   var loopEl;
   var tmpElem;
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   for (loopEl=0; loopEl<form.length; loopEl++) {
      objElement = form.elements[loopEl];

      if (objElement.name.length>10 && objElement.name.lastIndexOf("_MaxLength")==objElement.name.length-10) {
         nMax = parseInt(objElement.value);
         strRoot = objElement.name.substr(0, objElement.name.length-10);
         strVal = new String(eval("document."+strFormName+"."+strRoot).value);
         if (strVal.length>nMax) {
            alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORMAXSIZE+" "+nMax);
            eval("document."+strFormName+"."+strRoot).focus();
            return false;
         }
      }

      if (objElement.name.length>10 && objElement.name.lastIndexOf("_Mandatory")==objElement.name.length-10) {
         strRoot = objElement.name.substr(0, objElement.name.length-10);
         strVal = eval("document."+strFormName+"."+strRoot).value;
         if (strRoot == strNotCheckedField)
            return true;
         if (_editorltrim(strVal)=="") {
            alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORMANDATORYFIELD);
            return false;
         }
      }

      if (objElement.name.length>10 && objElement.name.lastIndexOf("_IsANumber")==objElement.name.length-10) {
         strRoot = objElement.name.substr(0, objElement.name.length-10);
         strVal = eval("document."+strFormName+"."+strRoot).value;
         if (isNaN(strVal) || strVal=='') {
            alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORSHOUDBEANUMBER +"");
            eval("document."+strFormName+"."+strRoot).focus();
            return false;
         }
         var decimals = eval("document."+strFormName+"."+strRoot+"_NumOfDec").value;
         if (strVal.substring(strVal.indexOf('.'))!=-1) {
            if (strVal.indexOf('.')!=-1) {
               var decs = strVal.substring(strVal.indexOf('.'));
               if ((decs.length-1)>decimals) {
                  alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORTOOMANYDECIMALS+" "+decimals);
                  return false;
               }
            }
         }
      }

      if (objElement.name.length>12 && objElement.name.lastIndexOf("_IsAnInteger")==objElement.name.length-12) {
         strRoot = objElement.name.substr(0, objElement.name.length-12);
         strVal = eval("document."+strFormName+"."+strRoot).value;
         if (isNaN(strVal) || strVal=='' || (strVal.indexOf(".")!=-1)) {
            alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORSHOUDBEANINTEGER +"");
            eval("document."+strFormName+"."+strRoot).focus();
            return false;
         }
      }

      if (objElement.name.length>9 && objElement.name.lastIndexOf("_MaxValue")==objElement.name.length-9) {
         strRoot = objElement.name.substr(0, objElement.name.length-9);
         strVal = eval("document."+strFormName+"."+strRoot).value;
         if (strVal!="") {
            nVal = parseFloat(strVal);
            nMax = parseFloat(objElement.value);
            if (nVal>nMax) {
               alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORMAXVALUE +" "+nMax);
               eval("document."+strFormName+"."+strRoot).focus();
               return false;
            }
         }
      }

      if (objElement.name.length>9 && objElement.name.lastIndexOf("_MinValue")==objElement.name.length-9) {
         strRoot = objElement.name.substr(0, objElement.name.length-9);
         strVal = eval("document."+strFormName+"."+strRoot).value;
         if (strVal!="") {
            nVal = parseFloat(strVal);
            nMin = parseFloat(objElement.value);
            if (nVal<nMin) {
               alert("'"+_editorExtractFieldName(strRoot)+"' "+EDITORMINVALUE +" "+nMin);
               eval("document."+strFormName+"."+strRoot).focus();
               return false;
            }
         }
      }

      if (objElement.name.length>11 && objElement.name.lastIndexOf("_CheckChars")==objElement.name.length-11) {
         var idx;
         strRoot = objElement.name.substr(0, objElement.name.length-11);
         strVal = eval("document."+strFormName+"."+strRoot).value;

         if (strVal != null) {
            for (idx = 0; idx< strVal.length; idx++) {
               if (strVal.charAt(idx) == '"') {
                  alert("'"+_editorExtractFieldName(strRoot)+"': "+EDITORINVALIDCHAR+" : "+strVal.charAt(idx));
                  eval("document."+strFormName+"."+strRoot).focus();
                  return false;
               }
            }
         }
      }

      if (objElement.name.lastIndexOf("_D")==objElement.name.length-2) {
         strRoot = objElement.name.substr(0, objElement.name.length-2);
         strRootd = _editorExtractFieldName(strRoot);
         nDay = eval("document."+strFormName+"."+strRoot+"_D").value;
         nMonth = eval("document."+strFormName+"."+strRoot+"_M").value;
         nMonth = nMonth - 1;
         nYear = eval("document."+strFormName+"."+strRoot+"_Y").value;

         if (isNaN(nYear)) {
            alert("'"+strRootd+"' "+EDITORWRONGDATE +"");
            eval("document."+strFormName+"."+strRoot+"_Y").focus();
            return false;
         }


         if ((isNaN(nMonth)) || nMonth<0 || nMonth>11) {
            alert("'"+strRootd+"' "+EDITORWRONGDATE +"");
            eval("document."+strFormName+"."+strRoot+"_M").focus();
            return false;
         }
         if ((isNaN(nDay)) || nDay<1 || nDay>_editorGetDays(nMonth, nYear)) {
            alert("'"+strRootd+"' "+EDITORWRONGDATE +"");
            eval("document."+strFormName+"."+strRoot+"_D").focus();
            return false;
         }
      }
      if (objElement.name.lastIndexOf("_Ho")==objElement.name.length-3) {
         strRootd = _editorExtractFieldName(objElement.name.substr(0, objElement.name.length-3));
         nHour = objElement.value;
         if (isNaN(nHour) || nHour<0 || nHour>23) {
            alert("'"+strRootd+"' "+EDITORWRONGTIME +"");
            objElement.focus();
            return false;
         }
      }
      if (objElement.name.lastIndexOf("_Mi")==objElement.name.length-3) {
         strRootd = _editorExtractFieldName(objElement.name.substr(0, objElement.name.length-3));
         nMinute = objElement.value;
         if (isNaN(nMinute) || nMinute<0 || nMinute>59) {
            alert("'"+strRootd+"' "+EDITORWRONGTIME +"");
            objElement.focus();
            return false;
         }
      }
      if (objElement.name.lastIndexOf("_Se")==objElement.name.length-3) {
         strRootd = _editorExtractFieldName(objElement.name.substr(0, objElement.name.length-3));
         nSecond = objElement.value;
         if (isNaN(nSecond) || nSecond<0 || nSecond>59) {
            alert("'"+strRootd+"' "+EDITORWRONGTIME +"");
            objElement.focus();
            return false;
         }
      }
   }

   var  bIsRootEditable = true;
   if (form.IsRootEditable.value!="true") {
      bIsRootEditable = false;
   }

   if (bIsRootEditable && form.Title!=null) {
      strVal = form.Title.value;
      strRoot = "Title";
      for (idx = 0; idx< strVal.length; idx++) {
         if (strVal.charAt(idx) == '<' || strVal.charAt(idx) == '>') {
            alert("'Title' "+EDITORINVALIDCHAR+ " : "+strVal.charAt(idx));
            eval("document."+strFormName+"."+strRoot).focus();
            return false;
         }
       }
   }


   if (bIsRootEditable && form.StartDate_Y!=null && form.EndDate_Y!=null) {
      var startDate = new Date(form.StartDate_Y.value , form.StartDate_M.value, form.StartDate_D.value , form.StartDate_Ho.value , form.StartDate_Mi.value , form.StartDate_Se.value ,0);
      var endDate = new Date(form.EndDate_Y.value , form.EndDate_M.value, form.EndDate_D.value , form.EndDate_Ho.value , form.EndDate_Mi.value , form.EndDate_Se.value  ,0);

      if (endDate.getTime()<startDate.getTime()) {
         alert(""+EDITORSTARTDATEAFTERENDDATE +"");
         return false;
      }
   }

   return true;
}

function editorSaveQuit(strFormName, forwardUrl, strExecCommand) {
   var strRedirect;
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   // some checks
   if (_editorCheck(strFormName)==false) {
      return false;
   }
   if (_editorFillMultipleFields(strFormName) == false) {
      return false;
   }
   _editorFillSimpleFields(strFormName);

   if (strExecCommand == "none")
      strExecCommand = "com.instranet.CmdEditorSaveDoc";

   // Sumbit
   form.Release.value="1";
   form.WorkflowAction.value="0";
   form.LaunchDPSEdit.value="";
   DPSLaunchURL = '';
   form.DocumentChanged.value="0";
   form.Save.value="1";

   if (forwardUrl == "") {
      strRedirect=form.ComesFrom.value;
   } else {
      strRedirect=forwardUrl;
   }

   formSubmitExecuteCommand(strFormName, strExecCommand, strRedirect, "");

   return false
}

function editorDeleteSection(strFormName, nRank) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (!confirm(EDITORSECTIONDELETECONFIRM)) {
      return false;
   }
   if (form.DocumentChanged.value=="1") {
      if (!confirm(EDITORSECTIONACTIONCONFIRM)) {
         return false;
      }
   }
   form.RemoveMultipleSection.value= nRank;
   return editorSave(strFormName, 'none');
}

function editorMoveSectionUp(strFormName, nRank) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (form.DocumentChanged.value=="1") {
      if (!confirm(EDITORSECTIONACTIONCONFIRM)) {
         return false;
      }
   }
   form.MoveSectionUp.value= nRank;
   return editorSave(strFormName, 'none');
}

function editorMoveSectionDown(strFormName, nRank) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (form.DocumentChanged.value=="1") {
      if (!confirm(EDITORSECTIONACTIONCONFIRM)) {
         return false;
      }
   }
   form.MoveSectionDown.value= nRank;
   return editorSave(strFormName, 'none');
}

function editorAddNewSection(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   strNewSection = form.SelectAddMultipleSection[form.SelectAddMultipleSection.selectedIndex].value;
   if (strNewSection == "") {
     alert(EDITORSELECTASECTIONFIRST);
     return false;
   }

   if (form.DocumentChanged.value=="1") {
      if (!confirm(EDITORSECTIONACTIONCONFIRM)) {
         return false;
      }
   }
   form.AddMultipleSection.value= strNewSection;
   return editorSave(strFormName, 'none');
}

function editorSave(strFormName, strExecCommand) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   // some checks
   if (_editorCheck(strFormName)==false) {
      return false;
   }
   if (_editorFillMultipleFields(strFormName) == false) {
      return false;
   }
   _editorFillSimpleFields(strFormName);

   if (strExecCommand == "none")
      strExecCommand = "com.instranet.CmdEditorSaveDoc";;

   // Sumbit
   form.Release.value="0";
   form.WorkflowAction.value="0";
   form.DocumentChanged.value="0";
   DPSLaunchURL = '';
   form.Save.value="1";

   formSubmitExecuteCommand(strFormName, strExecCommand, form.Redirect.value, "");

   return false;
}

function editorQuit(strFormName, forwardUrl, strExecCommand) {
   var strRedirect;
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (strExecCommand == "none")
      strExecCommand = "com.instranet.CmdEditorSaveDoc";

   if  (form.DocumentChanged.value=="1") {
      if (!confirm(EDITORCONFIRMQUIT)) {
         return false;
      }
   }

   form.Release.value="1";
   form.Save.value="0";
   form.LaunchDPSEdit.value="";
   DPSLaunchURL = '';
   form.WorkflowAction.value="0";

   if (forwardUrl == "") {
      strRedirect=form.ComesFrom.value;
   } else {
      strRedirect=forwardUrl;
   }

   formSubmitExecuteCommand(strFormName, strExecCommand, strRedirect, "");

   return false;
}

function editorOpenMPChooser(strFormName, strElemString, strType, strTopPPS, coordType, strExludedIds) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   editorChanged(strFormName);

   document.MultiPosChooser.ExcludedIds.value = strExludedIds;
   document.MultiPosChooser.Type.value = strType;
   document.MultiPosChooser.CoordType.value = coordType;
   document.MultiPosChooser.TopPPS.value = strTopPPS;
   document.MultiPosChooser.FieldName.value = new String("document."+strFormName+"."+strElemString);
   document.MultiPosChooser.OpenerForm.value = strFormName;

   popupParentOpenPopup("MultiPosChooser", "MultiPosChooser", null, form.MPChooserJSP.value, 540, MPChooserHeight);

   return false;
}


function editorChanged(strFormName) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   form.DocumentChanged.value="1";

   return true;
}

// No formName in AddElement because we receive the whole path on elemString...
// Check FieldName value in OpenMPChooser.
function editorAddElement(elemString, strText, strIds) {
   var elem = eval(elemString);
   var exist = false;
   var i = 0;

   while (i<elem.length) {
//      if (elem.options[i].text == strText) {
//alert( elem.options[i].value + " --- " + elem.options[i].text + " // " + strIds + " --- " + strText);
      if (elem.options[i].value == strIds) {
         exist = true;
      }
      i++;
   }

   if (strText != "" && exist==false) {
      elem.options[elem.length] = new Option(strText,  strIds);
   }
   return false;
}

function editorRemovePosition(strFormName, elemString) {
   var elem = eval("document."+strFormName+"."+elemString);
   var nCurOpt = 0;
   while (nCurOpt<elem.length) {
      if (elem[nCurOpt].selected == true) {
         elem[nCurOpt]=null;
      } else {
         nCurOpt++;
      }
   }
   editorChanged(strFormName);
   return false;
}

function editorOpenBlobChooser(strFormName, name) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   document.BlobChooser.FieldName.value = name+"_NAME";
   document.BlobChooser.FieldInfo.value = name;
   document.BlobChooser.OpenerForm.value = strFormName;
   document.BlobChooser.RefreshFunction.value = "editorRefresh";
   document.BlobChooser.RefreshFunctionParams.value = strFormName;

   popupParentOpenPopup("BlobChooser", "BlobChooser", null, form.BlobChooserJSP.value, BlobChooserWidth, BlobChooserHeight);

   return false;
}

function editorOpenBlobImporter(strFormName, strName, nSectionId, strExecCommand) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var field = eval("document."+strFormName+"."+strName);
   var fieldCaption = eval("document."+strFormName+"."+strName+"_NAME");

   if (_editorPrepareToSave(strFormName, strName, strExecCommand)) {
      form.AttachedBlobFieldName.value = strName+"_NAME";
      form.AttachedBlobFieldInfo.value = strName;
      form.AttachedBlobSectionId.value = new String(nSectionId);
      form.OpenerForm.value = strFormName;

      popupParentOpenPopup(strFormName, "BlobImporter", null, form.BlobImporterJSP.value, BlobImporterWidth, BlobImporterHeight);
   }
   return false;
}

function editorOpenDocURLChooser(strFormName, name) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   document.DocChooser.TextFieldName.value   = strFormName+"." + name + "_NAME";
   document.DocChooser.IdFieldName.value     = strFormName+"." + name;

   popupParentOpenPopup("DocChooser", "DocChooser", null, form.DocChooserJSP.value, DocChooserWidth, DocChooserHeight);

   return false;
}

function editorRefresh(strFormName) {
   var form;

   if (strFormName == null || strFormName=='')
      strFormName = "editorForm";

   form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   DPSLaunchURL = '';

   _editorCheckMultipleFields(strFormName, false);

   form.CommandError.value=1;

   formSubmitUrl(strFormName, form.Redirect.value, "_self");
}

function editorCreateEmptyBlob(strFormName, strFieldName, nSectionId, strBlobName, strExtension, bEditOnCreate, strSavingMessage, strExecCommand) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   var fieldBlobName = eval("document."+strFormName+"."+strFieldName+"_CREATEBLOBNAME");
   var fieldBlobExtension = eval("document."+strFormName+"."+strFieldName+"_CREATEBLOBTYPE");

   if (strExtension == null || strExtension == '') {
      return false;
   }

   if (confirm(strSavingMessage)) {
      if (strBlobName != null && strBlobName != '')
         fieldBlobName.value=strBlobName;

      fieldBlobExtension.value=strExtension;
      form.AttachedBlobSectionId.value = new String(nSectionId);
      form.AttachedBlobFieldName.value = strFieldName+"_NAME";
      form.AttachedBlobFieldInfo.value = strFieldName;
      form.SubmitCreateAttachedBlob.value = "1";

      if (_editorPrepareToSave(strFormName, strFieldName, strExecCommand)) {
         if (bEditOnCreate) {
            form.LaunchDPSEdit.value=strFieldName;
         }

         formSubmitExecuteCommand(strFormName, form.Command.value, form.Redirect.value, "");
      }
   }
   return false;
}

function _editorPrepareToSave(strFormName, FieldNotChecked, strExecCommand) {
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   if (_editorAdvancedCheck(strFormName, FieldNotChecked)==false) {
      return false;
   }
   if (_editorFillMultipleFields(strFormName) == false) {
      return false;
   }

   if (strExecCommand != "none")
      form.Command.value = strExecCommand;
   else
      form.Command.value = "com.instranet.CmdEditorSaveDoc";

   // reproduce the comportement of submit
   form.Release.value="0";
   form.WorkflowAction.value="0";
   form.DocumentChanged.value="0";
   form.Save.value="1";
   form.action=INSTRASERVLET_URL;
   form.LaunchDPSEdit.value="";
   DPSLaunchURL = '';

   return true;
}

function editorLaunchDPS(strFormName, strLaunchEdit) {

   if (strFormName=='') {
      return false;
   }

   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   DPSLaunchURL = form.DPSLaunchURL.value;

   if (strLaunchEdit != null && strLaunchEdit !='' &&  DPSLaunchURL != null && DPSLaunchURL != '') {
      window.location = DPSLaunchURL;
   }
   DPSLaunchURL = "";
   return false;
}


function customTypeOpenCustomTypeSelector(strCustomTypeName, strFormName, selector, sectionName, fieldName, width, height) {
   var fldInnerFieldsList;
   var startIndex;
   var endIndex;
   var token;
   var fieldTo;
   var strCustomFormName;
   var customForm;
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   fldInnerFieldsList = eval("document." + form.name + ".CustomType_" + strCustomTypeName + "_InnerFields");
   startIndex = 0;
   strCustomFormName = "CustomType" + strCustomTypeName + "Selector";
   customForm = eval("document." + strCustomFormName);

   do {
      endIndex = fldInnerFieldsList.value.indexOf(',', startIndex);
      if (endIndex < 0)
         endIndex = fldInnerFieldsList.value.length;

      if (endIndex > startIndex) {
         token = fldInnerFieldsList.value.substring(startIndex, endIndex);
         fieldTo = eval("document." + customForm.name + ".Field_" + token);
         fieldTo.value = eval("document." + form.name + ".Field_" + sectionName + "_" + fieldName + "_" + token + ".value");

         startIndex = endIndex + 1;
         endIndex = startIndex + 1;
      }
   } while (startIndex < endIndex);

   customForm.formName.value = form.name;
   customForm.sectionName.value = sectionName;
   customForm.fieldName.value = fieldName;

   popupParentOpenPopup(customForm.name, "CustomFieldSelector", null, selector, width, height);

   return false;
}

function customTypeClear(strCustomTypeName, strFormName, sectionName, fieldName) {
   var fldInnerFieldsList;
   var startIndex;
   var endIndex;
   var token;
   var fieldToClear;
   var customField;
   var fieldDisplay;
   var fieldDisplayValue = "";
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   fldInnerFieldsList = eval("document." + form.name + ".CustomType_" + strCustomTypeName + "_InnerFields");
   startIndex = 0;

   do {
      endIndex = fldInnerFieldsList.value.indexOf(',', startIndex);
      if (endIndex < 0)
         endIndex = fldInnerFieldsList.value.length;

      if (endIndex > startIndex) {
         token = fldInnerFieldsList.value.substring(startIndex, endIndex);
         fieldToClear = eval("document." + form.name + ".Field_" + sectionName + "_" + fieldName + "_" + token);
         fieldToClear.value = "";

         fieldDisplayValue = fieldDisplayValue + "()";

         startIndex = endIndex + 1;
         endIndex = startIndex + 1;
      }
   } while (startIndex < endIndex);

   customField = eval("document." + form.name + ".Field_" + sectionName + '_' + fieldName);
   if (customField) {
      if (customField.value != "") {
         form.DocumentChanged.value = "1";
      }
      customField.value = "";
   }

   fieldDisplay = eval("document." + form.name + ".FieldDisplay_" + sectionName + '_' + fieldName);
   fieldDisplay.value = fieldDisplayValue;

   return false;
}

