






//==============================================================================
// Global Constants Begin.
//==============================================================================

/* Current Preference. */
var CURRENT_PREFERENCE = "2";

/* Navigation mode representing LIST. */
var NAV_MODE_LIST = "L";

/* Navigation mode representing CHANGE. */
var NAV_MODE_CHANGE = "C";

/* Operation mode representing INSERT. */
var OP_MODE_LIST_DELETE = "LDEL";

/* Operation mode representing INSERT. */
var OP_MODE_INSERT = "INS";

/* Operation mode representing INSERT NEW. */
var OP_MODE_INSERT_NEW = "INSNEW";

/* Operation mode representing UPDATE. */
var OP_MODE_UPDATE = "UPD";

/* Operation mode representing UPDATE NEW. */
var OP_MODE_UPDATE_NEW = "UPDNEW";

/* Operation mode representing DELETE. */
var OP_MODE_DELETE = "DEL";

/* Operation mode representing COPY. */
var OP_MODE_COPY = "CPY";

/* Whether have mouseover effect for record listing. */
var LIST_EFFECT_ENABLE = true;

//==============================================================================
// Global Constants End.
//==============================================================================


//==============================================================================
// Global Variables Begin.
//==============================================================================

/* This array is used to remember mark status of rows in browse mode. */
var g_marked_row = new Array;

/* Global Variable indicates the current function code. */
var g_curr_function_code = "";

//==============================================================================
// Global Variables End.
//==============================================================================


//==============================================================================
// Global Swap Image Functions Begin.
//==============================================================================

function PreloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=PreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function SwapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function FindObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=FindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function SwapImage() {
  var i,j=0,x,a=SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=FindObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//==============================================================================
// Global Swap Image Functions End.
//==============================================================================


//==============================================================================
// Global Navigation Functions Begin.
//==============================================================================

function NavBackward() {
  history.go(-1);
  return(false);
}

function NavForward() {
  history.go(1);
  return(false);
}

function NavReload() {
  window.location.reload();
  return(false);
}

function NavStop() {
  window.stop();
  return(false);
}

function NavLogout() {
  if (confirm(MSG_LOGOUT)) {
    popUp = false;
    top.location="/ecss/Logout.do";
    top.focus();
  }
  return(false);
}

function NavPrint() {
  var bVersion = parseInt(navigator.appVersion);
  if (bVersion >= 4) {
    window.print();
  } else {
    alert("This browser doesn't support print function.");
  }
}

function NavHelp() {
  OpenCenteredPopup("/ecss/jsp/help/PopupHelpMain.jsp?functionCode="+g_curr_function_code, "ecsuitsHelp", 600, 500, "scrollbars=yes");
  return(false);
}

//==============================================================================
// Global Navigation Functions End.
//==============================================================================


//==============================================================================
// System Function Begin
//==============================================================================

function ToggleDefaultCheckbox(theRecordID) {
  var chkAry = FindObj("basicSelectedID");

  if (chkAry) {
    if (chkAry[0]) {
      var allCheckFlag = true;
      for (var loopCnt = 0; loopCnt < chkAry.length; loopCnt++) {
        if (chkAry[loopCnt].value == theRecordID) {
          chkAry[loopCnt].checked = !chkAry[loopCnt].checked;
        }
        if (!chkAry[loopCnt].checked) {
          allCheckFlag = false;
        }
      }
      if (chkAry[0].form.PARADM_CB_ALL_NONE) {
        chkAry[0].form.PARADM_CB_ALL_NONE.checked = allCheckFlag;
      }
    } else {
      chkAry.checked = !chkAry.checked;
      if (chkAry.form.PARADM_CB_ALL_NONE) {
        chkAry.form.PARADM_CB_ALL_NONE.checked = chkAry.checked;
      }
    }
  }
}

function SetTableRowColor(theRow, theRowNum, theAction, theRecordID, theAlterRowFlag) {
  if (!LIST_EFFECT_ENABLE) {
    return;
  }

  var theCells = null;
  var thePointerColor = "#B5D2EA";
  var theMarkColor = "#FFCC99";
  var theDefaultColor = "#EEEEEE";
  if (theRowNum % 2 == 0 || theAlterRowFlag) {
    theDefaultColor = "#FFFFFF";
  }

  // 1. Pointer and mark feature are disabled or the browser can't get the
  //  row -> exits
  if ((thePointerColor == '' && theMarkColor == '')
    || typeof(theRow.style) == 'undefined') {
    return false;
  }

  // 2. Gets the current row and exits if the browser can't get it
  if (typeof(document.getElementsByTagName) != 'undefined') {
    theCells = theRow.getElementsByTagName('td');
  }
  else if (typeof(theRow.cells) != 'undefined') {
    theCells = theRow.cells;
  }
  else {
    return false;
  }

  // 3. Gets the current color...
  var rowCellsCnt  = theCells.length;
  var domDetect  = null;
  var currentColor = null;
  var newColor   = null;
  // 3.1 ... with DOM compatible browsers except Opera that does not return
  //     valid values with "getAttribute"
  if (typeof(window.opera) == 'undefined'
    && typeof(theCells[0].getAttribute) != 'undefined') {
    currentColor = theCells[0].getAttribute('bgcolor');
    domDetect  = true;
  }
  // 3.2 ... with other browsers
  else {
    currentColor = theCells[0].style.backgroundColor;
    domDetect  = false;
  } // end 3

  // 4. Defines the new color
  // 4.1 Current color is the default one
  if (!currentColor || currentColor == ''
    || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
    if (theAction == 'over' && thePointerColor != '') {
      newColor        = thePointerColor;
    }
    else if (theAction == 'click' && theMarkColor != '') {
      newColor        = theMarkColor;
      g_marked_row[theRowNum] = true;
      ToggleDefaultCheckbox(theRecordID);
    }
  }
  // 4.1.2 Current color is the pointer one
  else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
       && (typeof(g_marked_row[theRowNum]) == 'undefined' || !g_marked_row[theRowNum])) {
    if (theAction == 'out') {
      newColor        = theDefaultColor;
    }
    else if (theAction == 'click' && theMarkColor != '') {
      newColor        = theMarkColor;
      g_marked_row[theRowNum] = true;
      ToggleDefaultCheckbox(theRecordID);
    }
  }
  // 4.1.3 Current color is the marker one
  else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
    if (theAction == 'click') {
      newColor        = (thePointerColor != '')
                  ? thePointerColor
                  : theDefaultColor;
      g_marked_row[theRowNum] = (typeof(g_marked_row[theRowNum]) == 'undefined' || !g_marked_row[theRowNum])
                  ? true
                  : null;
      ToggleDefaultCheckbox(theRecordID);
    }
  } // end 4

  // 5. Sets the new color...
  if (newColor) {
    var c = null;
    // 5.1 ... with DOM compatible browsers except Opera
    if (domDetect) {
      for (c = 0; c < rowCellsCnt; c++) {
        theCells[c].setAttribute('bgcolor', newColor, 0);
      } // end for
    }
    // 5.2 ... with other browsers
    else {
      for (c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = newColor;
      }
    }
  } // end 5

  return true;
} // end of the 'SetTableRowColor()' function

function OpList(frm, sortValue, sortOrder, navMode) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  frm.sortAttribute.value = sortValue;
  frm.sortOrder.value = sortOrder;
  frm.curStartRowNo.value = 1;

  frm.opMode.value = NAV_MODE_LIST;
  frm.navMode.value = NAV_MODE_LIST;
  if (navMode!=null) {
    frm.navMode.value = navMode;
  }

  frm.submit();
  return false;
} // end of the 'OpList()' function

function OpListReset(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  //frm.sortAttribute.value = '';
  //frm.sortOrder.value = '';
  frm.basicSearchField.value = '';
	if (frm.basicSearchType) {
		frm.basicSearchType.selectedIndex=0;
  }
  frm.basicSearchKeyword.value = '';
  frm.curStartRowNo.value = 1;

  frm.navMode.value = NAV_MODE_LIST;
  frm.submit();
  return false;
} // end of the 'OpListReset()' function

function OpListDelete(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  var hasChecked = false;

  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }

  if (!hasChecked) {
    alert("No record selected. Operation aborted.");
    return(false);
  }

  if (!confirm("Confirm delete selected records?")) {
    return(false);
  }

  frm.opMode.value = OP_MODE_LIST_DELETE;
  frm.navMode.value = "";
  return OpSubmit(frm);
} // end of the 'OpListDelete()' function

function OpListUserDefAction(frm,actionURL,OpMode,isRequireValidation) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  if(isRequireValidation){
    var hasChecked = false;

    for (var i = 0; i < frm.elements.length; i++) {
      if (frm.elements[i].name == "basicSelectedID") {
        if (frm.elements[i].checked) {
          hasChecked = true;
          break;
        }
      }
    }

    if (!hasChecked) {
      alert("No record selected. Operation aborted.");
      return(false);
    }
  }

  frm.opMode.value = OpMode;
  frm.navMode.value = "";
  frm.action = actionURL;
  return OpSubmit(frm);
} // end of the 'OpListUserDefAction()' function


/*
function OpInsert(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_INSERT;
  frm.navMode.value = "";
  frm.submit();
  return(false);
} // end of the 'OpInsert()' function

function OpUpdate(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_UPDATE;
  frm.navMode.value = "";
  frm.submit();
  return(false);
} // end of the 'OpUpdate()' function
*/

function OpDelete(frm) {
  if (!confirm("Confirm delete this record?")) {
    return(false);
  }

  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_DELETE;
  frm.navMode.value = "";
  return OpSubmit(frm);
} // end of the 'OpDelete()' function

function OpCopy(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_COPY;
  frm.navMode.value = "";
  return OpSubmit(frm);
} // end of the 'OpCopy' function

function OpSaveFieldModified(field){
  field.form.isFormModified.value = true;
} // end of the 'OpSaveFieldModified()' function

function OpCheckFormModifed(frm){
  if (frm.isFormModified){
    if (frm.isFormModified.value=='false'){
      return confirm("???en_US.common.message.form_unmodified???")
    } else {
      return true;
    }
  }
} // end of the 'OpCheckFormModifed()' function

function OpToggleSelectAllNone(cb, frm) {
  if (cb.checked) {
    OpSelectAll(frm);
  } else {
    OpSelectNone(frm);
  }
}

function OpSelectAll(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      frm.elements[i].checked = true;
    }
  }
  return(false);
} // end of the 'OpSelectAll()' function

function OpSelectNone(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      frm.elements[i].checked = false;
    }
  }
  return(false);
}  // end of the 'OpSelectNone()' function

function OpChangeLanguage(frm, isWarning, localStr) {
  var msg = "Are you sure to change the language setting?";
  var urlStr = frm.action;
  var Obj = frm.LANGUAGE;
  
  if (isWarning) {
    msg = "Since the current page contains submitted data, changing language will redirect to the front-page of current function." + "\n" + msg
  }

  if (confirm(msg)) {
    if (urlStr.indexOf("LANGUAGE=") > 0) {
      urlStr = urlStr.substring(0, urlStr.indexOf("LANGUAGE=")) + urlStr.substring(urlStr.indexOf("LANGUAGE=") + 15);
    }

    if (urlStr.charAt(urlStr.length - 1) == '?' || urlStr.charAt(urlStr.length - 1) == '&') {
      urlStr = urlStr.substring(0, urlStr.length - 1);
    }

    if (urlStr.indexOf("?") > 0) {
      window.location.href = urlStr + "&LANGUAGE=" + frm.LANGUAGE.options[frm.LANGUAGE.selectedIndex].value
    } else {
      window.location.href = urlStr + "?LANGUAGE=" + frm.LANGUAGE.options[frm.LANGUAGE.selectedIndex].value
    }
  }else{
    var optionEles = Obj.options;
    for(i=0;i<optionEles.length;i++){
      if(optionEles[i].value==localStr){
        Obj.selectedIndex = i;
        break;
      }
    }
    return false;
  }
}

function CheckTextArea(field, maxlimit) {
  if (field.value.length > maxlimit) { // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
  }
} // end of the 'CheckTextArea()' function

function enlargeTextareaSize(field,styleClass){
  field.className=styleClass;
}

function miniTextareaSize(field,styleClass){
  if(field.value==null||field.value.length<=0){
    field.className=styleClass;
  }
}

function PagerGotoPage(frm, value, navMode) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  document.forms[frm].curStartRowNo.value = value;
  document.forms[frm].navMode.value = NAV_MODE_LIST;
  document.forms[frm].opMode.value = "";
  if (navMode!=null) {
    document.forms[frm].navMode.value = navMode;
  }
  document.forms[frm].submit();
  return (false);
} // end of the 'pagerGotoPage()' function

function CustPagerGotoPage(frm, value, currListType) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  if (document.forms[frm].name == 'listPersonalHomeForm'){
    document.forms[frm].currListType.value=currListType;
  }

  document.forms[frm].curStartRowNo.value=value;
  document.forms[frm].navMode.value=NAV_MODE_LIST;
  document.forms[frm].submit();
  return (false);
} // end of the 'CustPagerGotoPage()' function

function OpSetRecordID(id, fullname, property, form, index) {
  var frm;
  if (!form || form == null) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  } else {
    frm = window.opener.document.forms[form];
  }

  if(index!= null &&index!="null"){
    frm.elements[property+"_"+index].value = id;
    frm.elements["dummy_" + property+"_"+index].value = fullname;
  }else{
    frm.elements[property].value = id;
    frm.elements["dummy_" + property].value = fullname;
  }
  window.close();
}

//==============================================================================
// System Function End
//==============================================================================

//==============================================================================
// Global Submit Functions Begin.
//==============================================================================
var submitted = false;
function OpSave(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  if (typeof ValidateForm == "function" && !ValidateForm(frm)) {
    return(false);
  }
  if (frm.elements['ID'].value == "") {
    if (frm.elements['navMode'].value == NAV_MODE_CHANGE) {
      return(OpCopy(frm));
    } else {
      return(OpInsert(frm));
    }
  } else {
    return(OpUpdate(frm));
  }
}

function OpSaveAndNew(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  if (typeof ValidateForm == "function" && !ValidateForm(frm)) {
    return(false);
  }

  if (frm.elements['ID'].value == "") {
    return(OpInsertAndNew(frm));
  } else {
    return(OpUpdateAndNew(frm));
  }
}

function OpInsert(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_INSERT;
  frm.navMode.value = "";
  return OpSubmit(frm);
}

function OpInsertAndNew(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_INSERT_NEW;
  frm.navMode.value = "";
  return OpSubmit(frm);
}

function OpUpdate(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_UPDATE;
  frm.navMode.value = "";
  return OpSubmit(frm);
}

function OpUpdateAndNew(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  frm.opMode.value = OP_MODE_UPDATE_NEW;
  frm.navMode.value = "";
  return OpSubmit(frm);
}

function OpSubmit(frm){
  if(submitted){
    alert("Concurrent updates detected.");
    return false;
  }
  submitted = true;
  frm.submit();
  return (false);
}

//==============================================================================
// Global Submit Functions End.
//==============================================================================


//==============================================================================
// Common Function Begin
//==============================================================================

// -----------------------------------------------------------------------------
// Get the extension of a filename.
//  RETURN   : The extension of a filename.
// -----------------------------------------------------------------------------
function GetFileExtension(filename) {
  var ext = "";
  var idx = filename.lastIndexOf(".");
  if (idx >= 0) {
    ext = filename.substring(idx + 1);
  }
  return(ext);
}

// -----------------------------------------------------------------------------
// Find the inner height within the browser window.
//  RETURN   : The inner height within the browser window.
// -----------------------------------------------------------------------------
function GetInnerHeight() {
  if (window.innerHeight) {
    return(window.innerHeight);
  } else if (document.body && document.body.clientHeight) {
    return(document.body.clientHeight);
  } else {
    return(700);
  }
}

// -----------------------------------------------------------------------------
// Find the inner width within the browser window.
//  RETURN   : The inner width within the browser window.
// -----------------------------------------------------------------------------
function GetInnerWidth() {
  if (window.innerWidth) {
    return(window.innerWidth);
  } else if (document.body && document.body.clientWidth) {
    return(document.body.clientWidth);
  } else {
    return(1000);
  }
}

// -----------------------------------------------------------------------------
// Remove all options from a select list.
//  from     : The select object which going to remove all options.
// -----------------------------------------------------------------------------
function RemoveAllOptions(from) {
  for (var i=(from.options.length-1); i>=0; i--) {
    from.options[i] = null;
  }
  from.selectedIndex = -1;
}

// -----------------------------------------------------------------------------
// Add an option to a select list.
//  obj      : The select object which going to add an option.
//  text     : The text label of that option.
//  value    : The value of that option.
//  selected : Whether it is pre-selected or not.
// -----------------------------------------------------------------------------
function AddOption(obj, text, value, selected) {
  if (obj!=null && obj.options!=null) {
    obj.options[obj.options.length] = new Option(text, value, false, selected);
  }
}

// -----------------------------------------------------------------------------
// Remove an array element at a given index
//  ary     : The array.
//  idx     : The index of element in array going to be removed.
// -----------------------------------------------------------------------------
function RemoveArrayElement(ary, idx) {
  var length = ary.length;
  if (idx>=length || idx<0) {
    return;
  }
  for (var i=idx; i<length-1; i++) {
    ary[i] = ary[i+1];
  }
  ary.length--;
}

// -----------------------------------------------------------------------------
// Join several arrays into one up to 4.
//  ary1    : The array 1.
//  ary2    : The array 2.
//  ary3    : The array 3.
//  ary4    : The array 4.
//  RETURN  : The result array after joining.
// -----------------------------------------------------------------------------
function JoinArray(ary1, ary2, ary3, ary4) {
  var result = new Array();

  if (ary1) {
    for (var i=0; i<ary1.length; i++) {
      result[result.length] = ary1[i];
    }
  }

  if (ary2) {
    for (var i=0; i<ary2.length; i++) {
      result[result.length] = ary2[i];
    }
  }

  if (ary3) {
    for (var i=0; i<ary3.length; i++) {
      result[result.length] = ary3[i];
    }
  }

  if (ary4) {
    for (var i=0; i<ary4.length; i++) {
      result[result.length] = ary4[i];
    }
  }

  return(result);
}

// -----------------------------------------------------------------------------
// Dynamic change the content of a layer.
//  divName : The name of layer.
//  content : The content.
// -----------------------------------------------------------------------------
function ChangeDivContent(divName, content) {
  if (document.getElementById) {
    if(document.getElementById(divName)) {
      document.getElementById(divName).innerHTML = content;
    }
  } else if (document.all) {
    var divLayer = eval("document.all." + divName);
    divLayer.innerHTML = content;
  } else if (document.layers) {
    var divLayer = eval("document.layers." + divName + ".document");
    divLayer.open();
    divLayer.write(content);
    divLayer.close();
  }
  return(false);
}

// -----------------------------------------------------------------------------
// Get the content of a layer.
//  divName : The name of layer.
//  RETURN  : The content.
// -----------------------------------------------------------------------------
function GetDivContent(divName) {
  if (document.getElementById) {
    return document.getElementById(divName).innerHTML;
  } else if (document.all) {
    var divLayer = eval("document.all." + divName);
    return divLayer.innerHTML;
  } else if (document.layers) {
    var divLayer = eval("document.layers." + divName + ".document");
    return("");
  }
}

// -----------------------------------------------------------------------------
// Show a layer.
//  divName : The name of layer.
// -----------------------------------------------------------------------------
function ShowDiv(divName) {
  var divObj = FindObj(divName);

  if (document.getElementById) {
    divObj.style.visibility = "visible";
  } else if (document.all) {
    divObj.style.visibility = "visible";
  } else if (document.layers) {
    divObj.visibility = "show";
  }
}

// -----------------------------------------------------------------------------
// Hide a layer.
//  divName : The name of layer.
// -----------------------------------------------------------------------------
function HideDiv(divName) {
  var divObj = FindObj(divName);

  if (document.getElementById) {
    divObj.style.visibility = "hidden";
  } else if (document.all) {
    divObj.style.visibility = "hidden";
  } else if (document.layers) {
    divObj.visibility = "hide";
  }
}

// -----------------------------------------------------------------------------
// Get the visibility of a layer
//  layerName : The name of layer.
//  RETURN    : The visibility of the layer in "visible" or "hidden".
// -----------------------------------------------------------------------------
function GetDivVisibility(layerName) {
  var layer = FindObj(layerName);
  var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                  parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  var isMinIE4 = (document.all) ? 1 : 0;

  if (isMinNS4) {
    if (layer.visibility == "show")
      return "visible";
    if (layer.visibility == "hide")
      return "hidden";
    if (layer.style) {
      return layer.style.visibility;
    }
    return layer.visibility;
  }
  if (isMinIE4)
    return layer.style.visibility;
  return "";
}

// -----------------------------------------------------------------------------
// Open a popup window which position is at the central.
//  url     : The URL of that window going to load.
//  name    : The window name.
//  popW    : The width of window.
//  popH    : The height of window.
//  feature : The additional features of that window.
// -----------------------------------------------------------------------------
function OpenCenteredPopup(url, name, popW, popH, feature) {
  var w = 1024;
  var h = 768;

  if (document.all || document.layers) {
    w = screen.availWidth;
    h = screen.availHeight;
  }

  var leftPos = (w-popW)/2;
  var topPos = (h-popH)/2;
  //---tc.add for dim
  try{
   if(typeof window.opener.showDim()=="function"){
       window.self.showDim();//show the dim
     }
  }catch(e){
  //do nothing
  }
//---tc.add end
  var popupWin = window.open(url,name,(feature ? (feature + ',') : '') + 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

//---tc.add for hidden DIM
  onPopupWinClose = function(){
    if(!popupWin.closed){
      setTimeout(onPopupWinClose,1000);
    }else{
      //popupWin close,then hidden the DIM
      try{
        if(typeof window.self.hideDim()=="function")
          window.self.hideDim();
      }catch(e){
      }
    }
  }
  onPopupWinClose();
//---tc.add end  
  popupWin.focus();
  return(false);
}

// -----------------------------------------------------------------------------
// Create a cookie entry.
//  Name    : The cookie name.
//  Value   : The cookie value.
//  Expiry  : The specified expiry date.
//  Path    : The specified path.
//  Domain  : The specified domain.
//  Secure  : Whether is secure or not.
// -----------------------------------------------------------------------------
function MakeCookie(Name, Value, Expiry, Path, Domain, Secure) {
  if (Expiry != null && !isNaN(Expiry)) {
    var datenow = new Date();
    datenow.setTime(datenow.getTime() + Math.round(86400000 * Expiry));
    Expiry = datenow.toGMTString();
  }

  Expiry = (Expiry) ? '; expires='+Expiry : '';
  Path = (Path)?'; path='+Path:'';
  Domain = (Domain) ? '; domain='+Domain : '';
  Secure = (Secure) ? '; secure' : '';
  document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;
}

// -----------------------------------------------------------------------------
// Read a cookie entry.
//  name    : The cookie name.
//  RETURN  : The cookie value.
// -----------------------------------------------------------------------------
function ReadCookie(name) {
  var cookies = ' ' + document.cookie;

  if (cookies.indexOf(' ' + name + '=') == -1) return null;
  var start = cookies.indexOf(' ' + name + '=') + (name.length + 2);
  var finish = cookies.substring(start,cookies.length);
  finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
  return unescape(cookies.substring(start, finish));
}

// -----------------------------------------------------------------------------
// Read a image position in pixel which counted from left of the page.
//  name    : The image name.
//  RETURN  : The image position in pixel which counted from left of the page.
// -----------------------------------------------------------------------------
function GetImagePageLeft(imgName) {
  var img = FindObj(imgName);
  var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                  parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  var isMinIE4 = (document.all) ? 1 : 0;
  var x, obj;

  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  if (isMinIE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}

// -----------------------------------------------------------------------------
// Read a image position in pixel which counted from top of the page.
//  name    : The image name.
//  RETURN  : The image position in pixel which counted from top of the page.
// -----------------------------------------------------------------------------
function GetImagePageTop(imgName) {
  var img = FindObj(imgName);
  var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                  parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  var isMinIE4 = (document.all) ? 1 : 0;
  var y, obj;

  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (isMinIE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}

// -----------------------------------------------------------------------------
// Move the layer to a specified position.
//  layerName : The layer name.
//  x         : The x-coordinate.
//  y         : The y-coordinate.
// -----------------------------------------------------------------------------
function MoveLayerTo(layerName, x, y) {
  var lyr = FindObj(layerName);
  var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                  parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  var isMinIE4 = (document.all) ? 1 : 0;

  if (isMinNS4) {
    if (lyr.style) {
      if (lyr.style.left) {
        lyr.style.left = x;
        lyr.style.top  = y;
      } else {
        lyr.moveTo(x, y);
      }
    } else {
      lyr.moveTo(x, y);
    }
  } else if (isMinIE4) {
    lyr.style.left = x;
    lyr.style.top  = y;
  }
}

// -----------------------------------------------------------------------------
// Compare between two date. If the first date is earlier than the second one, return -1.
// If the second date is earlier, return 1. Return 0 if they are the same day
//  dateObj1  : The first date object to compare.
//  dateObj2  : The second date object to compare.
//  ignoreTime: set to true, if only need to compare the calendar date value.
// -----------------------------------------------------------------------------
function compareDate(dateObj1, dateObj2, ignoreTime) {
  dateFormat = 'yyyy-MM-dd HH:mm:ss';
  yearStart = dateFormat.indexOf("y");
  yearEnd = dateFormat.lastIndexOf("y");
  monthStart = dateFormat.indexOf("M");
  monthEnd = dateFormat.lastIndexOf("M");
  dayStart = dateFormat.indexOf("d");
  dayEnd = dateFormat.lastIndexOf("d");
  hourStart = dateFormat.indexOf("H");
  hourEnd = dateFormat.lastIndexOf("H");
  minStart = dateFormat.indexOf("m");
  minEnd = dateFormat.lastIndexOf("m");
  secStart = dateFormat.indexOf("s");
  secEnd = dateFormat.lastIndexOf("s");

  if (yearStart==-1 || yearEnd==-1 || monthStart==-1 || monthEnd==-1 || dayStart==-1 || dayEnd==-1
      || hourStart==-1 || hourEnd==-1 || minStart==-1 || minEnd==-1 || secStart==-1 || secEnd==-1) {
    alert("Invalid date format, please consult your system admin");
  }

  jsDate1 = null;
  if (dateObj1.value!=null && dateObj1.value!='') {
    year1 = dateObj1.value.substring(yearStart, yearEnd+1);
    month1 = dateObj1.value.substring(monthStart, monthEnd+1);
    day1 = dateObj1.value.substring(dayStart, dayEnd+1);
    hour1 = dateObj1.value.substring(hourStart, hourEnd+1);
    min1 = dateObj1.value.substring(minStart, minEnd+1);
    sec1 = dateObj1.value.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate1 = new Date(year1, month1-1, day1);
    } else {
      jsDate1 = new Date(year1, month1-1, day1, hour1, min1, sec1);
    }
  }

  jsDate2 = null;
  if (dateObj2.value!=null && dateObj2.value!='') {
    year2 = dateObj2.value.substring(yearStart, yearEnd+1);
    month2 = dateObj2.value.substring(monthStart, monthEnd+1);
    day2 = dateObj2.value.substring(dayStart, dayEnd+1);
    hour2 = dateObj2.value.substring(hourStart, hourEnd+1);
    min2 = dateObj2.value.substring(minStart, minEnd+1);
    sec2 = dateObj2.value.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate2 = new Date(year2, month2-1, day2);
    } else {
      jsDate2 = new Date(year2, month2-1, day2, hour2, min2, sec2);
    }
  }

  if (jsDate1==null && jsDate2==null) {
    return 0; //treat as the same
  } else if (jsDate1==null) {
    return 1; //date 2 is later
  } else if (jsDate2==null) {
    return -1; //date 1 is earlier
  } else {
    if (jsDate1-jsDate2>0) {
      return 1; //date1 is later than date2
    } else if (jsDate1-jsDate2<0) {
      return -1; //date1 is earlier than date2
    } else {
      return 0; //they are equals
    }
  }

}

// Default onload function.
function InitializeAction() {
  window.focus();
  if (FindObj('iframeLoading')) {
    FindObj('iframeLoading').style.visibility='hidden';
  }
  //new Calendar(new Date());
  if (self.INIT) {
    self.INIT();
  }
  if (parent.adjustIFrameSize){
    parent.adjustIFrameSize(window);
//  if (FindObj('formSubmission')){
//    hideBlock("formSubmission");
//  }
  }
}

// Check whether got window.opener; then perform the action
function checkWindowForAction(url) {
  var frm;
  var parent = window.opener;

  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }

  if (window.name == "ecsuitsAppWindow" || window.name == "" || (window.name != "" && window.name.indexOf("ecsuits") < 0)) {
    self.location.href = url;
  } else {
    if (parent && window.name.indexOf("ecsuits") >= 0) {
      parent.document.location.href = url;
      window.close();
    }
  }
  return (false);
}

// Replace the special char.
function replaceSpecialChar(str) {
  str=String(str);
  str = str.replace(/\&nbsp\;/ig, " ");
  str = str.replace(/\&amp\;/ig, "&");
  str = str.replace(/\&lt\;/ig, "<");
  str = str.replace(/\&gt\;/ig, ">");
  str = str.replace(/\&quot\;/ig, "'");

  return str;
}

// Get user's Contact
function getUser(inputerControl){
    var mailStr = '';
  if(inputerControl){
    mailStr = inputerControl.value;
  }else{
    mailStr = '';
  }
  var  sReturn=window.showModalDialog("../contact/GetContactPerson.do?mailStr="+mailStr,"asd",'dialogHeight:550px;dialogWidth:470px;status:no;help:no;resizable:no');
  if(sReturn==';'){
  }else if(sReturn!=""){
    inputerControl.value=sReturn;
  }
  inputerControl.focus();
}

//==============================================================================
// Common Function End
//==============================================================================

