function ShowConfirmMessage(Mesg) {
   return (confirm(Mesg + ' Please click OK to continue.'));
}
function ShowInputLookUpMessage(Mesg) {
   var InputLU = prompt(Mesg, "");
   if (InputLU == null)
      return false;
   else
      if (InputLU == '') {
         alert('The value is invalid.');
         return false;
      }
      else {
         var LUName = event.srcElement.AddLookUpName;
         var LUDisp = event.srcElement.AddLookUpDisplay;
         document.getElementById('hdnLookUp').value = LUName + "|" + InputLU + "|" + LUDisp;
         return true;
      }
}
//CCC0003
//textBox is texbox object to modify, e is event)
//eg onkeyup='javascript:WSYWIGInput(this,event, 10,5);'
function WSYWIGInput(textBox, e, maxCharPerLine, maxLines) {
   var keynum;

   if (window.event) // IE
   {
      keynum = e.keyCode;
   }
   else if (e.which) // Netscape/Firefox/Opera
   {
      keynum = e.which;
   }

   if ((keynum == 67 || keynum == 65) && e.ctrlKey == true) return true; //copy
   if (keynum < 46 && keynum != 8 && keynum != 13 && keynum != 32) return true; //all control keys except delete and backspace 

   if (textBox == null) return;
   if (maxCharPerLine == null || maxCharPerLine < 1) maxCharPerLine = 1;
   if (maxLines == null || maxLines < 1) maxLines = 1;
   var caretpos = getCaretPosition(textBox);

   var src = textBox.value;
   var rtn = "";

   src = src.replace(/\n/g, "").replace(/\r/g, "").replace(/\f/g, "");

   if (keynum == 13) {
      //we need to add spaces to end of that line
      var remainder = (caretpos) % maxCharPerLine;
      var nLines = ((caretpos - remainder) / maxCharPerLine) + 1;
      var numspaces = ((nLines) * maxCharPerLine) - caretpos + nLines;
      var spaces = "";
      for (var i = caretpos; i < caretpos + numspaces; i++) {
         spaces += " ";
      }
      var sPre = src.substring(0, caretpos - nLines);
      var sPost = src.substring(caretpos - nLines);
      src = sPre + spaces + sPost;
      caretpos = (nLines * maxCharPerLine) + (nLines * 2) + 1;
   }

   if (src.length <= maxCharPerLine) {
      rtn = src;
   }
   else {
      for (var i = 0; i < maxLines; i++) {
         if (src.length > maxCharPerLine) {
            if (i < maxLines - 1) {
               rtn += src.substring(0, maxCharPerLine) + "\n\r";
            }
            else {
               rtn += src.substring(0, maxCharPerLine);
            }
            src = src.substring(maxCharPerLine);
         }
         else {
            rtn += src;
            break;
         }
      }

   }
   if (keynum == 86 && e.ctrlKey == true)//paste
   {
      //do nothing at this stage. Paste that causes line shift will result in offset caretpos. No way to detect at this stage.
   }
   else {

      //if we're at the beginning of a new line, unless deleting
      //NOTE: this code is triggered on keyup; if a key is pressed and held then caretpos will be off by one.

      if (caretpos % maxCharPerLine == 0 && keynum != 46) {
         switch (keynum) {
            case 8:
               caretpos--;
               break;
            default:
               caretpos++;

         }
      }


   }

   textBox.value = rtn;
   SetCaretPosition(textBox, caretpos);

   return true;
}

function SetCaretPosition(ctrl, pos) {
   if (document.selection) {
      var range = ctrl.createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
   }
   else {
      ctrl.selectionStart = pos;
      ctrl.selectionEnd = pos;
   }

}

function getCaretPosition(textarea) {
   var rtn;
   // get selection in firefox, opera, ...

   if (typeof (textarea.selectionStart) == 'number') {
      rtn = textarea.selectionStart;

   }

   // get selection in IE

   else if (document.selection) {

      var range = document.selection.createRange();

      // create a selection of the whole textarea

      var range_all = document.body.createTextRange();

      range_all.moveToElementText(textarea);

      // calculate selection start point by moving beginning of range_all to beginning of range

      for (var sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {
         range_all.moveStart('character', 1);
      }

      // get number of line breaks from textarea start to selection start and add them to sel_start
      /*
      for (var i = 0; i <= sel_start; i ++)

      {
      if (textarea.value.charAt(i) == '\n')

      sel_start= sel_start+2;
      }
      */
      rtn = sel_start;
   }

   return (rtn);
}

function pageReload(){
   window.location=window.location;
}
function updatePanelRefresh(pnlClientId, ctlClientID) {
   __doPostBack(pnlClientId, ctlClientID);
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
function pageWidth() { return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null; } function pageHeight() { return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null; } function posLeft() { return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0; } function posTop() { return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0; } function posRight() { return posLeft() + pageWidth(); } function posBottom() { return posTop() + pageHeight(); }



