// load htmlarea
_editor_url = "/dzapps/docs/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

var boxtip = initTip('Box',1,700,100);
var h = initTip('Help',2,180,100);
h.dzHideDelay = 100;
var t = initTip('ToolMenu',0);
var lookupTip = initTip('Lookup',1,50,50);


function showHelp(event,helpGroup, helpField,nsLeft,nsTop,ieLeft,ieTop){
  var displayHelp = getCookie(webUserID + "_Help_" + helpGroup);
  if (displayHelp == 'no') return;
  var helpVar = helpGroup + "_" + helpField;
  var notOk = eval("typeof " + helpVar + "_Title == 'undefined'");
  if (notOk) return;
  helpTitle = eval(helpVar + "_Title");
  helpText = eval(helpVar + "_Text");
  helpBookmark = helpVar + "_BM";
  if (nsLeft == null) nsLeft = -190;
  if (nsTop == null) nsTop = 0;
  if (ieLeft == null) ieLeft = -190;
  if (ieTop == null) ieTop = 0;
  setTip(event,'Help',helpTitle,helpText,helpBookmark,nsLeft,nsTop,ieLeft,ieTop); 
}

function hideHelp(){
  hideTip('Help');
}

function helpOptions(event,helpGroup){
  var displayHelp = getCookie(webUserID + "_Help_" + helpGroup);
  var helpText = (displayHelp == 'no') ? "Show Help Tips" : "Hide Help Tips";
  var t_opt = makeTextMenuItem('ToolMenuTitle','Help Option');
  t_opt = t_opt + makeTextMenuItem('ToolMenu','<a href="javascript:toggleHelp({a}' + helpGroup + '{a})">&nbsp;•&nbsp;' + helpText + '</a>');
  setTip(event,'ToolMenu','',t_opt);
}

function toggleHelp(helpGroup){
  var d = new Date("December 31, 2999");
  var displayHelpField = webUserID + "_Help_" + helpGroup;
  var displayHelp = getCookie(displayHelpField);
  if (displayHelp == 'no') {
    deleteCookie(displayHelpField);
    alert('The pop-up help feature for this section has been turned ON.');
  } else
  {
    setCookie(displayHelpField,'no',d);
    alert('The pop-up help feature for this section has been turned OFF.');
  }
}

function showImage(img,ref) {
 document.images[img].src = ref; 
}

function hideHelp(){
  hideTip('Help');
}

function setTimeOption(fldName,timeValue){
  f[fldName].value = timeValue;
}

function showTimeOptions(event,fldName,bmName,nsLeft,nsTop,ieLeft,ieTop){
  var t_opt = "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
  t_opt = t_opt + "<tr>";
  for (i=1;i<12;i++) {
    var t = i + 'am';
    var t_value = i + ':00 am';
    t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  }

  var t = '12pm';
  var t_value = '12:00 pm';
  t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  t_opt = t_opt + "</tr>";
  t_opt = t_opt + "<tr>";
  for (i=1;i<12;i++) {
    var t = i + 'pm';
    var t_value = i + ':00 pm';
    t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  }
  var t = '12am';
  var t_value = '12:00 am';
  t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  t_opt = t_opt + "</tr>";
  var t_opt = t_opt + "</table>";

  setTip(event,'Box','',t_opt,bmName,nsLeft,nsTop,ieLeft,ieTop); 
}

function showHourOptions(event,fldName,bmName,nsLeft,nsTop,ieLeft,ieTop){
  var t_opt = "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
  t_opt = t_opt + "<tr>";
  for (i=0;i<12;i++) {
    var t = i;
    var t_value = i;
    t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  }
  t_opt = t_opt + "</tr>";
  var t_opt = t_opt + "</table>";
  setTip(event,'Box','',t_opt,bmName,nsLeft,nsTop,ieLeft,ieTop); 
}

function showMinuteOptions(event,fldName,bmName,nsLeft,nsTop,ieLeft,ieTop){
  var t_opt = "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
  t_opt = t_opt + "<tr>";
  for (i=0;i<4;i++) {
    var t = i*15;
    var t_value = i*15;
    t_opt = t_opt + "<td style='font-family:arial;font-size:8pt'><a href=\"javascript:setTimeOption('" + fldName + "','" + t_value + "');\">" + t + "</a></td>";
  }
  t_opt = t_opt + "</tr>";
  var t_opt = t_opt + "</table>";
  setTip(event,'Box','',t_opt,bmName,nsLeft,nsTop,ieLeft,ieTop); 
}

function popAssessments(event,ItemID,ItemName){
  var notOk = eval("typeof asm_nums_" + ItemID + " == 'undefined'");
  if (notOk){
    setTip(event,'Box',ItemName,'No Existing Assessments!');
    return;
  }
  var asm_nums = eval('asm_nums_' + ItemID);
  var asm_nums_array = asm_nums.split("|");
  var asm_registered = eval('asm_registered_' + ItemID);
  var asm_registered_array = asm_registered.split("|");
  var asm_assessedBy = eval('asm_assessedBy_' + ItemID);
  var asm_assessedBy_array = asm_assessedBy.split("|");
  var asm_assessedOn = eval('asm_assessedOn_' + ItemID);
  var asm_assessedOn_array = asm_assessedOn.split("|");
  var asm_createdOn = eval('asm_createdOn_' + ItemID);
  var asm_createdOn_array = asm_createdOn.split("|");
  var asm_updatedOn = eval('asm_updatedOn_' + ItemID);
  var asm_updatedOn_array = asm_updatedOn.split("|");
  var asm_seqNum = eval('asm_seqNum_' + ItemID);
  var asm_seqNum_array = asm_seqNum.split("|");
  var asm_status = eval('asm_status_' + ItemID);
  var asm_status_array = asm_status.split("|");
  var asm_level = eval('asm_level_' + ItemID);
  var asm_level_array = asm_level.split("|");
  var asm_category1 = eval('asm_category1_' + ItemID);
  var asm_category1_array = asm_category1.split("|");
  var asm_category2 = eval('asm_category2_' + ItemID);
  var asm_category2_array = asm_category2.split("|");

  var t = "<table cellpadding=0 cellspacing=0 border=0>";
  t = t + "<tr><td bgcolor=#99cccc width=100%>";
  t = t + "<table cellpadding=2 cellspacing=2 border=0>";
  t = t + "<tr>"
  t = t + "<td nowrap class=ColumnHeader align=center>Assessment ID</td>"
  t = t + "<td nowrap class=ColumnHeader align=center>Updated</td>"
  t = t + "<td nowrap class=ColumnHeader align=center>Assessor</td>"
  t = t + "<td nowrap class=ColumnHeader align=center>Assessed</td>"
//  t = t + "<td nowrap class=ColumnHeader align=center>Created</td>"
  t = t + "<td nowrap class=ColumnHeader align=center>Seq#</td>"
  t = t + "<td nowrap class=ColumnHeader align=center>Status</td>"
 // t = t + "<td nowrap class=ColumnHeader align=center>Level</td>"
 // t = t + "<td nowrap class=ColumnHeader align=center>Category1</td>"
 //t = t + "<td nowrap class=ColumnHeader align=center>Category2</td>"
  t = t + "</tr>";
  for (i=0;i<asm_nums_array.length;i++){
    var useClass = 'Class=RowData';
    if (asm_status_array[i] != 'Completed') useClass='Class=RegisteredAssessment';
    t = t + "<tr>";
    t = t + "<td nowrap " + useClass + "><a href=get?Action=CreateRecord&SubAction=EditAssessment" + "&pAssessmentID=" + asm_nums_array[i] +  "&pSection=Review>" + asm_nums_array[i] + "</a></td>";
    t = t + "<td nowrap align=center " + useClass + ">" + asm_updatedOn_array[i] + "</td>";
    t = t + "<td nowrap align=center " + useClass + ">" + asm_assessedBy_array[i] + "</td>";
    t = t + "<td nowrap align=center " + useClass + ">" + asm_assessedOn_array[i] + "</td>";
//    t = t + "<td nowrap align=center " + useClass + ">" + asm_createdOn_array[i] + "</td>";
    t = t + "<td nowrap align=center " + useClass + ">" + asm_seqNum_array[i] + "</td>";
    t = t + "<td nowrap align=center " + useClass + ">" + asm_status_array[i] + "</td>";
 //   t = t + "<td nowrap align=center " + useClass + ">" + asm_level_array[i] + "</td>";
 //   t = t + "<td nowrap align=center " + useClass + ">" + asm_category1_array[i] + "</td>";
 //   t = t + "<td nowrap align=center " + useClass + ">" + asm_category2_array[i] + "</td>";
    t = t + "</tr>";
  }
  t = t + "</table>";
  t = t + "</td></tr>";
  t = t + "</table>";  

  setTip(event,'Box',ItemName,t,null,0,10);
}
function showDetails(event,ItemID,ItemName){
  var arrayCaptions = details_fields_captions.split("|");
  var data = eval('details_' + ItemID).replace(/{lt}/g,'<');
  var arrayFieldData = data.split("|");
  var arrayAligns = details_fields_aligns.split("|");
  var editLink = "get?Action=CreateRecord&SubAction=EditItem&pItemID=" + ItemID;
  var previewLink = "get?Action=CreateRecord&SubAction=PreviewItem&pItemID=" + ItemID;

  var t = "<table cellpadding=0 cellspacing=0 border=0 align=center>";
  t = t + "<tr><td bgcolor=#99cccc width=100%>";
  t = t + "<table cellpadding=2 cellspacing=2 border=0>";
  t = t + "<tr>";
  for (i=0;i<arrayCaptions.length;i++){
   t = t + "<td nowrap class=ColumnHeader align=" + arrayAligns[i] + ">" + arrayCaptions[i] + "</td>";
  }
   t = t + "<td nowrap class=RowData rowspan=2 nowrap>• <a href=" + editLink + ">Edit</a><br>• <a href=" + previewLink + ">Preview</a></td>";
  t = t + "</tr>";
  t = t + "<tr>";
  for (i=0;i<arrayFieldData.length;i++){
   var d = arrayFieldData[i];
   if (d.substring(0,7) == '<script') {
    d = eval(d.match(/write.*script/i)[0].slice(6,-10).replace(/{a}/g,"'"));    
   }

   t = t + "<td nowrap class=RowData align=" + arrayAligns[i] + ">" + d + "</td>";
  }
  t = t + "</tr>";
  t = t + "</table>";
  t = t + "</td></tr>";
  t = t + "</table>";  
  setTip(event,'Box',ItemName,t,null,0,10);
}

function showAssessmentSummary(event,tool,summaryType,assessID){
  var asm_Summary = eval('asm_Summary_' + summaryType + "_" + assessID); 
  var t = asm_Summary; 
  setTip(event,'Box',tool,t,null,0,10);

}

function showTools(event,toolNum,ItemID,assessmentCaption){
  if (assessmentCaption == null) assessmentCaption = "Activity";
  var t_opt = '';
  var t_basehref = '<a href=get?Action=CreateRecord&pItemID='+ ItemID;
  t_opt = t_opt + "<span class=LabelSmall>";
  t_opt = t_opt + "· " + t_basehref + "&SubAction=EditItem>Edit</a>";
  t_opt = t_opt + "<br>"
  t_opt = t_opt + "· " + t_basehref + "&SubAction=PreviewItem>Preview</a>";
  if (toolNum > 1) {
    t_opt = t_opt + "<br>"
    t_opt = t_opt + "· " + t_basehref + "&SubAction=ListAssessments>List " + assessmentCaption + "</a>";
    t_opt = t_opt + "<hr noshade size=1>";
    t_opt = t_opt + "Create New...<br>";
    for (var i=1;i<=toolNum;i++){
      tool = eval('tool_' + i);
      t_opt = t_opt + " &nbsp;&nbsp;";
      t_opt = t_opt + "·&nbsp;";
      t_opt = t_opt + "<a href=get?Action=CreateRecord&SubAction=CreateAssessment&pItemID="+ ItemID + "&fTool=" + tool + ">" + tool + "</a>";
    }
  }
  t_opt = t_opt + "</span>";
  setTip(event,'Box','',t_opt);
}

function showLookupForm(event,agencyItemIDCaption){
  if (agencyItemIDCaption == null) agencyItemIDCaption = "ID";
  var t = "";
  t = t + "<form action='get'>";
  t = t + "<input type=hidden name=action value=CreateRecord>";
  t = t + "<input type=hidden name=subaction value=ListSelectItem>";
  t = t + "<table cellpadding=0 cellspacing=0 border=0 align=center>";
  t = t + "<tr>"
  t = t + "<td class=LabelSmall>" + agencyItemIDCaption + ":&nbsp;</td>";
  t = t + "<td><input type=text name=pAgencyItemID size=25 maxlength=25 onfocus='enterKey_enable=true;' onblur='enterKey_enable=false;'></td>";
  t = t + "</tr>";
  t = t + "<tr>"
  t = t + "<td class=LabelSmall>Last Name:&nbsp;</td>";
  t = t + "<td><input type=text name=pLastName size=25 maxlength=25 onfocus='enterKey_enable=true;' onblur='enterKey_enable=false;'></td>";
  t = t + "</tr>";
  t = t + "<tr>"
  t = t + "<td class=LabelSmall>&nbsp;</td>";
  t = t + "<td align=right class=LabelSmall><a href=get?action=CreateRecord&subaction=LookupItem>Advanced</a> &nbsp;&nbsp; <input type=Submit value=Submit></td></form>";
  t = t + "</tr>";
  t = t + "</table>";
  setTip(event,'Box','',t);  
}

function validate(f){return true;}
function isValidAgencyItemID(){return true;}

function extractAgencyItemID(s){
  return s;
}

function extractDigits(s){
  return s.replace(/[^0-9]/g,'');
}

function extractPhone(s){
  return s.replace(/[^0-9x]/g,'');
}

function extractNumber(s){
  var minus = "";
  if (s.charAt(0) == "-") minus = "-";
  return minus + s.replace(/[^0-9.]/g,'');
}

function extractCurrency(s){
  if (s.length == 0) return s;
  var minus = "";
  if (s.charAt(0) == "-") minus = "-";
  var v = s.replace(/[^0-9.]/g,'');
  var v_array = v.split('.');
  if (v_array.length > 2) {
    alert('Invalid Currency Format: ' + v);
  }
  var decimal = "00";
  if (v_array.length >= 2) {
    var decimal = v_array[1];
    if (v_array[1].length > 2) {
      decimal = decimal.substring(0,2);
    }
    if (decimal.length == 0) decimal = '00';
  }
  if (decimal.length == 1) decimal = decimal + "0";
  var integer = v_array[0];
  if (integer.length == 0) integer = '0';
  v = minus + integer + '.' + decimal;
  return v;
}

function roundCurrency(value){
    if (value == null) return null;
    var roundfactor = 0.005;
    var v = value;
    if (v < 0) roundfactor = -0.005;    
    v = v + roundfactor;
    v = parseInt(v * 100)/100;
    return v;
}

function makeUpperCase(fld){
  fld.value = fld.value.toUpperCase();
}

function isValidSSN(fld, fldname){
  var p = extractDigits(fld.value);
  if (p.length == 0 || p.length == 9) return true;
  alert("Please enter a valid 9 digit number in the \"" + fldname + "\" field.");
  fld.focus();
  return false;
}

function isValidAgencyItemID(fld, fldname){
  return true;
  // Sample Code
  var p = extractDigits(fld.value);
  if (p.length == 0 || p.length == 9) return true;
  alert("Please enter a valid 9 digit number in the \"" + fldname + "\" field.");
  fld.focus();
  return false;

}

function formatAgencyItemID(s){
  return(s);
}

function formatPhone(s){
  var phone = unformatPhone(s);
  var parray = phone.split('x');
  var x = '';
  var p = phone;
  if (parray.length > 1) {
   p = parray[0];
   x = 'x' + parray[1];
  }
  if (p.length <= 4) return(p+x);
  if (p.length <= 7) return(p.substring(0,p.length-4) + "-" + p.substring(p.length-4)+x); 
  if (p.length > 10) p = p.substring(p.length-10);
  if (p.length <= 10) return(p.substring(0,p.length-7) + "-" + p.substring(p.length-7,p.length-4) + "-" + p.substring(p.length-4)+x); 
}

function unformatPhone(s){
 return s.replace(/[^0-9x]/g,'');
}

function formatAge(s){
  return s.replace(/[^0-9x]/g,'');
}

function formatSSN(s){
  var p = extractDigits(s);
  if (p.length <= 4) return(p);
  if (p.length <= 6) return(p.substring(0,p.length-4) + "-" + p.substring(p.length-4)); 
  if (p.length > 9) p = p.substring(p.length-9);
  if (p.length <= 9) return(p.substring(0,p.length-6) + "-" + p.substring(p.length-6,p.length-4) + "-" + p.substring(p.length-4)); 

}

function formatZip(s){
  var p = s.replace(/[^0-9a-zA-Z]/g,'').toUpperCase();
  if (p.length <= 6) return(p);
  if (p.length > 9) p = p.substring(p.length-9);
  if (p.length <= 9) return(p.substring(0,5) + "-" + p.substring(5,p.length)); 
}

function unformatZip(s){
  var p = s.replace(/[^0-9a-zA-Z]/g,'').toUpperCase();
  return p;
}

function getDate(fldName){
  window.fldDate=document.forms['shell'][fldName];
  openCal(event,window);
  return(false);
}

function initForm(){}

function resetForm(){
   f.reset();
   initForm();
}

var multiselectCaption = null;
var multiselectOptionField = null;
var multiselectValueField = null;

function openMultiSelect(e,selectFieldName,valueFieldName,caption){
  multiselectCaption  = caption;
  multiselectOptionField = document.forms.shell[selectFieldName];
  multiselectValueField = document.forms.shell[valueFieldName];
  winMultiSelect=openWinTip(e,'/dzapps/docs/popup/multiselect.htm','_blank','resizable=no',450,310);
}

var enterKey = false;
var enterKey_enable = false;
function noSubmitOnEnterKey(e){
  if (!document.all) return;
  if (enterKey_enable) return;
  enterKey = (event.keyCode == 13);
  if (enterKey) {
    alert('The ENTER key is disabled for this page. Try pressing TAB or use your mouse.');
    return false;
  }
}

function formatDate(s){
  if (s.length == 0) return "";
  if (s.indexOf("/") >= 0) return s;
  if (s.substring(0,1) == "+" || s.substring(0,1) == "-") return s;
  var today = new Date();
  var thisDay   = today.getDate();
  var thisMonth = today.getMonth();
  if ((thisMonth + "").length == 1) thisMonth = "0" + thisMonth;

  var thisYear  = today.getYear() < 1000 ? today.getYear() + 1900 : today.getYear();
  var thisCentury  = parseInt(thisYear/100) * 100;
  var p = extractDigits(s);
  if (p.length <= 2) return p + "/" + thisMonth + "/" + thisYear;
  if (p.length == 3) return p.substring(0,1) + "/" + p.substring(1,3)  + "/" + thisYear;
  if (p.length == 4) return p.substring(0,2) + "/" + p.substring(2,4)  + "/" + thisYear;
  if (p.length == 5) return p.substring(0,1) + "/" + p.substring(1,3)  + "/" + p.substring(3,5);
  if (p.length == 6) return p.substring(0,2) + "/" + p.substring(2,4)  + "/" + p.substring(4,6);
  if (p.length == 7) return p.substring(0,1) + "/" + p.substring(1,3)  + "/" + p.substring(3,7);
  if (p.length == 8) return p.substring(0,2) + "/" + p.substring(2,4)  + "/" + p.substring(4,8);
  if (p.length > 8) return formatDate(p.substring(0,8));
  return ""; 
}


function openModifierImage(winurl,winname,winattr,winwidth,winheight,winleft,wintop) {

  wintop = (screen.height-winheight)/2;
  winleft = (screen.width-winwidth)/2;

  hwnd=open(winurl,winname,winattr+',width='+winwidth+',height='+winheight+',left=' + winleft + ',top=' + wintop);
  if (!hwnd.opener) hwnd.opener=self;
  if (hwnd.focus) hwnd.focus();
}


//-->