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;
}
var tickerTimer;
var tickerCurrItem = 1;
var tickerSpeed = 4000;

function tickerInit(strFormName) {
   tickerTimer = window.setTimeout("tickerScroll('"+strFormName+"')", 0);
}

function tickerOnMouseOut(strFormName) {
   tickerTimer = window.setTimeout("tickerScroll('"+strFormName+"')", tickerSpeed);
}

function tickerOnMouseOver() {
   if (tickerTimer != null)
      window.clearTimeout(tickerTimer);
}

function tickerScroll(strFormName) {
   var curAlert;
   var curStyle;
   var nextAlert;
   var nextStyle;
   
   var form = formGetForm(strFormName);
   if (form == null) {
      _formFatal("Cannot find a valid form. Probably because some fields are missing");
      return false;
   }

   curAlert = xGetElementById("alert"+tickerCurrItem);
   if (curAlert == null)
      return;

   curStyle = curAlert.style;
   tickerCurrItem = tickerCurrItem + 1;
   if (tickerCurrItem > form.AlertMaxNumber.value)
      tickerCurrItem = 1;
   nextAlert = xGetElementById("alert"+tickerCurrItem);

   if (nextAlert == null) {
      nextAlert = getNextAlert(form.AlertMaxNumber.value);
   }
   
   if (nextAlert.id == curAlert.id) {
      curStyle.visibility = 'visible';
      return;
   }
      
   nextStyle = nextAlert.style;
   curStyle.visibility = 'hidden';
   nextStyle.visibility = 'visible';

   tickerTimer = window.setTimeout("tickerScroll('"+strFormName+"')", tickerSpeed);
}

function getNextAlert(nMaxAlertNumber) {
   var nextAlert = null;
   var nAlertIndex = tickerCurrItem + 1;
   
   while (nextAlert == null && nAlertIndex != tickerCurrItem) {
      if (nAlertIndex > nMaxAlertNumber)
         nAlertIndex = 1;
      else
         nAlertIndex++;

      nextAlert = xGetElementById("alert"+nAlertIndex);
   }
   tickerCurrItem = nAlertIndex;
   return nextAlert;
}

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;
}


// 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;
}

