var ctime = new Date();

//start of cache control - dont remove
//var cnow = ctime.getTime();
//if (window==top) {  
//  var pagecache_lastcheck = cnow;
//}

var cachetime = 0;
ctime.setTime(ctime.getTime() + cachetime);
document.write("<META HTTP-EQUIV='PRAGMA' CONTENT='CACHE'><META HTTP-EQUIV='Expires' CONTENT='"+ctime+"'>");

var topMBX = 'top';
if (typeof MindBrixServer == 'undefined') {
  if (typeof top.MindBrixServer == 'undefined') {
    var cnt = 0; topMBX = 'parent';
    while (cnt < 20 && typeof eval(topMBX).MindBrixServer == 'undefined') {
      if (typeof eval(topMBX).calledMBX != 'undefined') {
        topMBX += "."+eval(topMBX).calledMBX;
      } else {
        topMBX += ".parent";
      }
      cnt++;
    }
  } else { topMBX = 'top'; }
  if (typeof OptObj == 'undefined') {
    OptObj = eval(topMBX).OptObj; SysSettings = eval(topMBX).SysSettings;
  }
} else {
  topMBX = 'self';
}

//start of cache control - dont remove
//if (cnow - eval(topMBX).pagecache_lastcheck > 10000){ // 10 seconds to check for next version
//  document.write("<script language=JavaScript src='/MBX_CACHE_CONTROL.js'></"+"script>"); 
//  //or do we want to do a websubmit call?
//  eval(topMBX).pagecache_lastcheck = cnow;
//}


WebSubmit = parent.WebSubmit; SubmitResult = parent.SubmitResult; SetWait = parent.SetWait; CancelSubmit = parent.CancelSubmit;
var gStyle = {
  'styles': {
    'INPUT':'g',
    'A':'g',
    'A:hover':'g',      
    'B':'g',
    'TR':'g',
    'TD':'g',
    'BODY':'g',
    'DIV':'g',
    'SPAN':'g',
    'TEXTAREA':'g',
    '.s_msg_dialog':'g',
    '.s_msg_hdr':'g',
    '.s_msg_link':'g',
    '.s_msg_link:hover':'g',
    '.s_msg_link_d':'g',
    '.s_msg_link_d:hover':'g',
    '.s_msg_txt':'g',
    '.s_msg_snd':'g',
    '.s_msg_sent':'g',
    '.s_msg_rcvd':'g',
    '.s_dmsg_dialog':'g',
    '.s_dmsg_title':'g',
    '.s_dmsg_box':'g',
    '.s_dmsg_txt':'g',
    'DIV.opaque_bg':'g',
    'SPAN.opaque_bg':'g',
    'DIV.opaque_70':'g',
    'DIV.opaque_80':'g',
    'DIV.busy':'g',
    'B.busy_msg':'g',
    '.s_button':'g',
    '.s_button:hover':'g',
    '.s_item_button':'g',
    '.s_item_button:hover':'g',
    '.s_item_button2':'g',
    '.s_item_button2:hover':'g',
    '.s_italref':'g',
    '.s_italref:hover':'g',
    '.s_dialog':'g',
    '.s_dialog_box':'g',
    '.s_dialog_title':'g',
    '.s_dialog_frame':'g',
    '.s_dialog_work':'g',
    '.s_cmonthday':'g',
    '.s_cmonthday:hover':'g',
    '.s_omonthday':'g',
    '.s_omonthday:hover':'g',
    '.s_weekday':'g'
  }
}
function lengthof(obj) {
  var ocnt = 0;
  for (var o in obj) {
    ocnt++;
  }
  return ocnt;  
}
function retHeight() {
  var x = document.body.scrollHeight;
  if (document.body.offsetHeight > x) { x = document.body.offsetHeight; }
  return x;
}
function retWidth() {
  var x = document.body.scrollWidth;
  if (document.body.offsetWidth > x) { x = document.body.offsetWidth; }
  return x;
}
function noright() {
  // disables right click
  event.cancelBubble = true;
  event.returnValue = false;
  return false;
}
function InHash(item,hash) {
  for (var x in hash) {
    if (x == item) { return true; }
  }
  return false;
}
function NotInHash(item,hash) {
  for (var x in hash) {
    if (x == item) { return false; }
  }
  return true;
}
function HasRole(role) {
  var grps = eval(topMBX).Groups.split(/,/);
  for (var i=0;i<grps.length;i++) {
    if (grps[i] == role) { return true; }
  }
  return false;
}
// DOM FUNCTIONS
function GetTextFromObject(objToGet) {
  // Function used for debugging.  Displays all properties of a given object.
  var msg = "";
  for(var i in objToGet) { msg += i+": "+objToGet[i]+"\n"; }
  return msg;
}
function GetTextFromObjectPutIntoNewWindow(objToGet) {
  // Function used for debugging.  Displays all properties of a given object.
  // Alternates from One Color to Another - Puts data into a new window
  var msg = "<html><body>";
  var j = 0;
  for(var i in objToGet) {
    if (j % 2) {
      msg += "<div>" + i + ": "+objToGet[i]+"</div>";
    } else {
      msg += "<div>" + i + ": "+objToGet[i]+"</div>";
    }
    j++;
   }
   msg += "</html></body>";

  gtWindow = open("", "gtWindow");
  gtWindow.document.open();
  gtWindow.document.write(msg);
  return 1;
}
// DOM FUNCTIONS
function subcolors(txt) {
  // global color replacement
  if (txt == null) { return ''; }
  var re = /%(\w+)%/;
  var tmp = txt; txt = txt.replace(re,"\#\*\*\*");
  if (RegExp.$1) { txt = txt.replace(/\*\*\*/,eval(topMBX).tStyle.colors[RegExp.$1]); }
  if (tmp!=txt) { txt = subcolors(txt); } return txt;
}
var x = eval(topMBX).document.location.host;
if (x != 'emldev.mindbrix.com' && x != 'landamdev.mindbrix.com' && !eval(topMBX).debug) { document.oncontextmenu = noright; } else {
  //enables style editor
  //document.oncontextmenu = editmenu;
}

//Implement Global Styles
if (!self.tStyle) { tStyle = { colors:{}, styles:{} }; }
var temp = "<style>";
//if (topMBX != 'self') {
  for (var g in gStyle.styles) { temp = temp+g+" {"+subcolors(eval(topMBX).tStyle.styles[g])+"}\n"; }
  for (var d in self.tStyle.styles) {
    var tmp = "";
    if (self.tStyle.styles[d]=='g') {
      tmp = eval(topMBX).tStyle.styles[d];
    } else {
      tmp = self.tStyle.styles[d];
    }
    temp = temp+d+" {"+subcolors(tmp)+"}\n";
  }
  temp += "<\/style>";
  try {
    //alert(temp);
    document.write(temp);
  } catch (e) { alert("Style Write Error:"+e.description+"\n"+temp); }
//}
/****************************************************************************
Display & Hide divs, Modals, navPanes
****************************************************************************/
function Display(tdiv,hide,resize) {
  // Centers a standard dialog on the screen and shows it
  // tdiv - the dialog object
  // hide - null - show, 1 - hide
  if (typeof tdiv == 'string') {
    try {
      tdiv = eval(tdiv);
    } catch(e) {
      window.status = "Display "+tdiv+" Failed.";
      return 0;
    }
  }
  if (hide == 1) { tdiv.style.display='none'; return; } else { tdiv.style.display='inline'; }
  var done=0;
  if (typeof tdiv.children != 'undefined' && typeof tdiv.children(0) != 'undefined' && resize) {
    done=1;
    tdiv.children(0).style.pixelTop = 0;
    tdiv.children(0).style.pixelLeft = 0;
    tdiv.children(0).style.pixelWidth = document.body.scrollWidth;
    tdiv.children(0).style.pixelHeight = document.body.scrollHeight;
  }
  if (typeof tdiv.children(1) != 'undefined' && done==0) {
    tdiv.children(1).style.pixelLeft = document.body.scrollLeft + document.body.offsetWidth/2 - tdiv.children(1).offsetWidth/2;
    tdiv.children(1).style.pixelTop = document.body.scrollTop + document.body.offsetHeight/2 - tdiv.children(1).offsetHeight/2;
   }
}
var ShowingModal = 0;
function HideModal() {
  // Hides Modal Dialog opened with ShowModal.
  if (ShowingModal == 1) {
    window.setTimeout("HideModal()",50);
    return;
  }
  dmsg.style.display='none';
  dbox.style.pixelTop=1;      dbox.style.pixelLeft=1;
  dmsg_hdr.innerHTML = "";
  //not sure why this used to remove the TD and then insert a new one.  The insertRow was causing the modal to grow and grow and grow throughout the day  -Tonya 10/31/06  
  //dmsg_txt.removeNode(true);
  //var trow = dmsg_replace.insertRow();  trow.id = 'dmsg_txt_row';
  //var tcell = trow.insertCell();
  //tcell.className = 's_dmsg_txt'; tcell.id = 'dmsg_txt'; tcell.TABINDEX=1;
  dmsg_txt.innerHTML = "";
  dbox.style.pixelWidth=50;  dbox.style.pixelHeight=50;
  if (document.all.BPOForm) {
    for (var i=0; i < BPOForm.length; i++) { BPOForm[i].tabIndex = null; }
    b_sv.tabIndex = null; b_qc.tabIndex = null; b_ap.tabIndex = null; b_sb.tabIndex = null;
  }
  if (dbox.gTo) {
    window.status = "Goto Object from HideModal";
    if (dbox.gTo.type == 'hidden') {
      setFoci(dbox.gTo,0);
    } else {
      if (dbox.gTo.type == 'checkbox' ) {
        dbox.gTo.style.border = '1px solid #FF4444';
        setFoci(dbox.gTo,0);
      } else {
        //window.status = "Bring Focus to:"+dbox.gTo.name;
        setFoci(dbox.gTo,1);
      }
    }
  }
  if (event) { event.returnValue = false; event.cancelBubble = true; }
  return false;
}

var ShowModal_goTo;
var ShowModal_zIndex=9999;
function ShowModal(hdr,msg,gTo,sc,dH,dW,dT,dL,noOpaque) {
  // Shows a custom modal dialog defined by the following
  // hdr - Dialog Title
  // msg - Dialog Contents
  // gTo - Goto this Object when closed
  // sc - 0 = dont show X to close, 1 = show close and set focus to X, object as text = set focus to this object when opened
  // dH - Height, dW - Width, dT - Top, dL - Left
  // noOpaque - Do Not Show Opaque BG
  ShowingModal = 1;
  var dTo = "dbox.gTo=ShowModal_goTo;dmsg.style.display='inline';ShowingModal=0;";
  if (!dT || !dL) {
    dTo += "dbox.style.top=(document.body.offsetHeight-dbox.clientHeight)/2+document.body.scrollTop;dbox.style.left=(document.body.offsetWidth-dbox.clientWidth)/2+document.body.scrollLeft;";
  }
  var dCls = "display:inline;";
  if (sc!=null) {
    if (sc==0) { dCls = "display:none;"; } else if (typeof(sc)!='number') { dTo += sc+".focus();"; dCls = "display:none;"; } else { dTo += "document.all.dmsg_close_btn.focus();"; }
  }
  if (gTo) { ShowModal_goTo = gTo; } else { ShowModal_goTo = false; }
  if (!document.all.dmsg) {
    //also change in Select.js initControls if you change div here.
    var overflow = '';
    var dwid = 240; if (dW) { dwid = dW; overflow += "width:"+dW+"px;overflow-x:auto;"; }
    var dhgt = 100; if (dH) { dhgt = dH; overflow += "height:"+dH+"px;overflow-y:auto;";}
    if (dT && dL) { dtop = dT; dleft = dL; }
    ShowModal_zIndex++;
    var sCommonInit = "<div id=dmsg style='display:none;'><div id=dmsg_opbg class='opaque_bg' style='z-index:9998;'></div><div id=dbox class='s_dmsg_dialog' style='z-index:"+ShowModal_zIndex+";position:absolute;height:"+dhgt+"px;width:"+dwid+"px;'><div class='s_dmsg_title' id=dmsg_hdr mobile=2 msize=0 mmove=1>"+hdr+"</div><div id=dmsg_box class='s_dmsg_box' style='padding-bottom:10px;margin:2px;margin-top:0;padding:2px;'><table cellpadding=0 cellspacing=0 width=100% height=100%><tr><td align=center valign=middle><table cellpadding=0 cellspacing=0 id=dmsg_replace><tr><td class='s_dmsg_txt' id=dmsg_txt TABINDEX=1>"+msg+"</td></tr></table></td></tr></table></div><a TABINDEX=99 class=s_button id=dmsg_close_btn href=# style='"+dCls+"position:absolute;top:2;left:"+(dwid-21)+";' onclick='HideModal();'>X</a></div></div>"
    document.body.insertAdjacentHTML("beforeEnd",sCommonInit);
  } else {
    dTo = "dmsg_close_btn.style.pixelLeft=dbox.offsetWidth-21;"+dTo;
    if(noOpaque == 1) { document.all.dmsg_opbg.style.display = 'none'; } else { document.all.dmsg_opbg.style.display='inline'; } 
    if (dCls == "display:none;") { document.all.dmsg_close_btn.style.display='none'; } else { document.all.dmsg_close_btn.style.display='inline'; }
    if (dH) { dmsg_box.style.pixelHeight=dH; dmsg_box.style.overflowY = 'auto'; } else { dmsg_box.style.pixelHeight=100; dmsg_box.style.overflowY = 'visible'; }
    if (dW) { dmsg_box.style.overflowX = 'auto'; dmsg_close_btn.style.pixelLeft=(dW-21); dbox.style.pixelWidth=dW; } else { dbox.style.pixelWidth=240;dmsg_close_btn.style.pixelLeft=219;}
    if (dT && dL) { dbox.style.pixelTop = dT; dbox.style.pixelLeft = dL; dTo = "dmsg.style.display='inline';" + dTo } else { dTo = "Display(dmsg);" + dTo; }
    dmsg_hdr.innerHTML = "<nobr>"+hdr+"</nobr>";
    dmsg_txt.innerHTML = msg;
    dTo += ";if (dmsg_box.scrollWidth - dmsg_box.offsetWidth > 0) { dmsg_box.style.pixelWidth = parseInt(dmsg_box.offsetWidth)+6; dmsg_close_btn.style.pixelLeft=dbox.offsetWidth-21;}";
  }
  if (document.all.BPOForm) {
    for (var i=0; i<BPOForm.length;i++) { BPOForm[i].tabIndex=-1;}
    b_sv.tabIndex = -1; b_qc.tabIndex = -1; b_ap.tabIndex = -1; b_sb.tabIndex = -1;
  }
  window.setTimeout(dTo,20);
  if (event) { event.returnValue = false; event.cancelBubble = true; }
  return false;
}

var cEle;
function setFoci(dEle,dFoc) {
  // sets focus to an element that may need scrolling to get to
  // dEle -
  // dFoc -
  try {
    cEle = dEle;
    var sBy = 0;
    var done = 0;
    //window.status = "Find ScrollTo Height: ";
    while (!done && sBy<10000) {
      if (cEle.nodeName != 'TR' && cEle.nodeName != 'TD' && cEle.nodeName != 'TBODY' && cEle.nodeName != 'FORM' && cEle.nodeName != 'CENTER') {
        //window.status += cEle.nodeName+"["+cEle.offsetHeight+"|"+cEle.offsetTop+"] ";
        sBy += cEle.offsetTop;
      }
      cEle = cEle.parentNode;
      if (cEle.nodeName == 'BODY') { done=1; }
    }
    cEle = dEle;
    sBy = sBy - document.body.offsetHeight/2;
    //window.status += " Set:"+sBy;
    if (dFoc) { if(!(sBy < document.body.scrollTop+document.body.scrollHeight && sBy > document.body.scrollTop)){ window.setTimeout("window.scrollTo(0,"+sBy+");cEle.setActive();",20); } else{cEle.setActive();} }
  } catch (e) { window.status = "Warning [Focus]"; }
  if (event) { event.returnValue = false; event.cancelBubble = true; }
  return false;
}

function disable(o,dir){
  try{
    if(dir){
      o.style.backgroundColor = "";
      o.className = 'qcdisabled';
      o.old = o.value;
      if(typeof o.sname != 'undefined'){ SetOptionBox(o,'',0); }
      else{ if(o.type == 'checkbox'){o.checked=false} o.value = ""; sboxchng(o); }
      o.oldreq = o.req;
      o.req = 0;              
      o.readOnly = true;
      o.ROF = true;
      o.disabled = true;
    }else{           
      o.disabled = false;
      o.readOnly = false;
      o.ROF = false; 
      if(typeof o.sname != 'undefined'){ SetOptionBox(o,o.old,0); }
      else{ o.value = o.old; sboxchng(o); }
      o.req = o.oldreq;
      o.style.backgroundColor = "";
      o.className = 'qcOK';
    }
  }catch(e){ alert(o.name+":"+e.description) }
}

var p_lastnav;
function p_navto(pid,eid) {
  if (p_lastnav) {
    eval(p_lastnav.navto).style.display='none';
    p_lastnav.className = 'p_nav_button_off';
  }
  if(eid) {
    p_lastnav = eid;
    eid.className = 'p_nav_button_on';
    eval(eid.navto).style.display='inline';
    try { if (eid.navrun) { eval(eid.navrun); } } catch(e) { alert("NavRun:"+eid.navrun+" on "+eid.navto+" failed.");}
  }
  if (event) { event.returnValue=false; }
}
/****************************************************************************
Creating OptObj for UTypes??
****************************************************************************/
var CDataTypes_LastUType = {};
function CreateCDataTypePage(cdname,UType,lid,slf) {
  if (UType != CDataTypes_LastUType[cdname]) {
    CDataTypes_LastUType[cdname] = UType;
    OptObj.UType_CDataTypes = {};
    var thtml = "";
    for (var r in eval(topMBX).AppSetup.UType_CDataType_Perms[UType]) {
      if (r.substr(0,1) == eval(topMBX).UType) {
        if (OptObj.EmpRoles[r.substr(1,1)]) {
          for (var s in eval(topMBX).AppSetup.UType_CDataType_Perms[UType][r]) {
            if (s != 'M') {
              OptObj.UType_CDataTypes[s] = eval(topMBX).AppSetup.UType_CDataTypes[s];
    } } } } }
    for (var s in OptObj.UType_CDataTypes) {
      thtml += "<table cellspacing=0 cellpadding=2 BORDER=1 align=left id='d_"+cdname+"_Data_"+s+"' style='display:none;'>";
      var rof=""; if(GetMax_CDataTypes_Perms(UType,s)==1) { rof = " readOnly ROF=1"; }
      for (var i in eval(topMBX).AppSetup.UType_CDataType[s]) {
        var tmp = eval(topMBX).AppSetup.UType_CDataType[s][i];
        var sdat = "";
        if (tmp.Type=='input') { sdat = "<input name='"+i+"' "+tmp.Data+rof+">"; }
        if (tmp.Type=='sbox') { sdat = "<input name='"+i+"' type=hidden><input name='s"+i+"' tname='"+i+"' sname='"+tmp.Data+"' size=16 class=sbox"+rof+"><a href=# class=sbutt tabindex=-1>V</a>"; }
        if (tmp.Check != '') { jschk[i] = { funct:tmp.Check, opt1:tmp.COPT1, opt2:tmp.COPT2, opt3:tmp.COPT3, help:tmp.CHelp }; }
        thtml += "  <tr><td width=190>"+tmp.Desc+"</td><td width=225>"+sdat+"</td></tr>";
      } thtml += "</table>";
    }
    //var d=window.open();d.document.open('text/plain').write(thtml);
    eval("d_"+cdname+"_Data").innerHTML = thtml;
  } else {
    if (ShowContactData_Last) { ShowContactData_Last.style.display='none'; }
  }
}
var ShowContactData_Last;
function ShowContactData(cdname) {
  var sExists = 0; try { if (document.all.item('d_'+cdname+'_Data_'+eval(cdname).ContactDataType.value)) { sExists = 1; } } catch(e) { }
  if (ShowContactData_Last) { ShowContactData_Last.style.display='none'; }
  if (sExists == 1) {
    ShowContactData_Last = document.all.item('d_'+cdname+'_Data_'+eval(cdname).ContactDataType.value);
    document.all.item('d_'+cdname+'_Data_'+eval(cdname).ContactDataType.value).style.display = 'inline';
  } else { alert("Error:"+sExists); }
}
function InitCDataTypePage(cdname,UType,createFlag) {
  var init=1; for (var s in OptObj.UType_CDataTypes) {
    if (init==1) { SetOptionBox(eval(cdname).sContactDataType,s); init=0; }
    if (createFlag) {
      for (var i in eval(topMBX).AppSetup.UType_CDataType[s]) {
        var tmp = eval(topMBX).AppSetup.UType_CDataType[s][i];
        if (tmp.Default) {
          var tst = eval('function f(){'+tmp.Default+'};f();');
          if (tmp.Type=='sbox') { SetOptionBox(cdname+'.s'+i,tst); }
          if (tmp.Type=='input') { eval(cdname)[i].value = tst; }
} } } } }
function GetMax_CDataTypes_Perms(UType,CDataType) {
  var ret = 1; for (var r in OptObj.EmpRoles) {
    var tc = eval(topMBX).UType + r;
    try { if (eval(eval(topMBX).AppSetup.UType_CDataType_Perms[UType][tc][CDataType]) == 0) { ret = 0; } } catch(e) {}
  } return ret;
}
/****************************************************************************
    Data formatting functions for lists, etc.
****************************************************************************/
function ShowCancel() { try {dmsg_close.style.display='inline';}catch(e){window.status='e.description';} }

function DT_show(idate) { var idKeys = idate.split(/ /); var mos = { Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12}; if (idKeys.length == 4) { return ""+mos[idKeys[0]]+"/"+idKeys[1]+"/"+idKeys[2].substr(2,2)+" "+idKeys[3]; } else { return "-err-"; } }

function BView (nada, id) {
  return "<a href='#' onclick='SelectDoNotUse(\""+id+"\");'>"+lObj[id]['FName']+" "+lObj[id]['LName']+"</a>";
}
/****************************************************************************
    Brokers
****************************************************************************/
var tWchBrkr;
function SearchBrokers(ToWhich) {
  if (isEmpty(eval(ToWhich.form.name+".PropState").value)) { alert("Please Select the Property State first");return; }
  tWchBrkr = ToWhich;
  var tmp = "<table><form name=Search><tr><td><input type=hidden name=State readonly value='"+eval(ToWhich.form.name+".PropState").value+"'>First Name:<input name=FName><br>Last Name:<input name=LName>";
  tmp += "<a href='#' onclick='SearchForBroker();' style='padding-left:4px;'>Search</a></td></tr></form></table><div id='SearchList' style='width:272;height:90;'></div>";
  ShowModal("Search For Brokers Not to Use",tmp);
}
function SelectDoNotUse(ID) {
  eval(tWchBrkr.vc).value = lObj[ID]['ContactID'];
  eval(tWchBrkr.vc).mod = 1;
  eval(tWchBrkr).mod = 1;
  tWchBrkr.value = lObj[ID]['FName'] + ' ' + lObj[ID]['LName'];
  HideModal();
}
function SearchForBroker() {
  if (eval(topMBX).UType != "V") { if (Search.FName.value.indexOf("%") != -1 || Search.LName.value.indexOf("%") != -1) { alert("please remove the special characters and try again"); return; } }
  if (Search.FName.value.length < 1 && Search.LName.value.length < 1) { alert("Please be more selective"); return; }
  var thtml = CompileForm(Search);
  parent.WebSubmit(eval(topMBX).UType,"SearchForBroker",thtml,"main","FoundBrokerList","n");
}
function FoundBrokerList() {
  SubmitResult(1);
  SetWait(0);
  SearchList.innerHTML = ShowNewList("blist","","SearchList",1);
}
/****************************************************************************
    MindBrix Style Editor
****************************************************************************/
//New code copied from the Common.js(Prod)

var edit_menu_div = "<div id=d_edit_menu_div style='background-color:#777777;color:#FFFFFF;border:1px solid #000000;visibility:hidden;position:absolute;top:0;left:0;'>";
edit_menu_div += "<b style='font-size: 9px; color:#FFFFFF; background-color:#555555; border-bottom:1px solid #000000;cursor:hand;line-height:11px;height:14px;padding-left:3px;width:100px;padding-top:2px;'>MindBrix Editor</b><br>";
edit_menu_div += "<span id=d_edit_menu_div_load><a href=# style='font-size: 9px; color:#FFFFFF; text-decoration:none; font-weight:bold; border:0px; padding:1px; width:100; padding-left:3px;' onclick='document.scripts[document.scripts.length-1].src=\"/StyleEditor/StyleEditor.js\";d_edit_menu_div_load.style.display=\"none\";id=d_edit_menu_div_edit.style.display=\"inline\";'>Load Manager</a><br></span>";
edit_menu_div += "<span id=d_edit_menu_div_edit style='display:none'><a href=# style=';font-size: 9px; color:#FFFFFF; text-decoration:none; font-weight:bold; border:0px; padding:1px; width:100; padding-left:3px;' onclick='d_edit_menu_div.style.visibility=\"hidden\";ShowStyleEditor(0);'>Manage Styles</a><br></span>";
edit_menu_div += "<a href=# style='font-size: 9px; color:#FFFFFF; background-color:#000000; border-top:1px solid #690009; text-decoration:none; font-weight:bold; padding:1px; width:100; padding-left:3px;' onclick='d_edit_menu_div.style.visibility=\"hidden\"'>Close</a></div>";

function editmenu() {
  if(!document.all.d_edit_menu_div) { document.body.insertAdjacentHTML("beforeEnd",edit_menu_div); }
  d_edit_menu_div.style.pixelTop=event.offsetY;
  d_edit_menu_div.style.pixelLeft=event.offsetX;
  d_edit_menu_div.style.visibility='visible';
  event.cancelBubble = true;
  event.returnValue = false;
  return false;
}
/****************************************************************************
    Documents
****************************************************************************/
function RemoveRequiredDoc(fname,rdoc,fnhook,show) {
  var erecs = eval(fname).RequiredDocs.value.split("");
  eval(fname).RequiredDocs.value = "";
  var Removed = 0;var len = erecs.length-1;
  for (var i=len;i>=0;i--) {
    if (erecs[i]==rdoc) {
      if (Removed==0) { Removed=1; } else { eval(fname).RequiredDocs.value = erecs[i] + eval(fname).RequiredDocs.value; }
    } else {
      eval(fname).RequiredDocs.value = erecs[i] + eval(fname).RequiredDocs.value;
    }
  }
  if (eval(fname).RequiredDocs.value == "") { eval(fname).RequiredDocs.value = " "; }
  EditRequiredDocs(fname,fnhook,show);
  if (event) { event.returnValue=false; }
}

function AddRequiredDoc(fname,rdoc,fnhook,show) {
  var ok=0;
  if (eval(topMBX).UType == 'X') {
    var tst = confirm("Do you wish to require this additional document?\nA handling fee of "+AddtlDocFee.innerText+" will be added.");
    if (tst) { ok=1; }
  } else { ok=1; }
  if (ok==1) {
    if (OnAdminPage==0) {
      var utst = eval(fname).RequiredDocs.value.split(" ");
      if (utst.length<2) { rdoc = " "+rdoc; }
    }
    eval(fname).RequiredDocs.value += rdoc;
  }
  EditRequiredDocs(fname,fnhook,show);
  if (event) { event.returnValue=false; }
}
function CheckDocCost() {
  //alert(top.SysSettings['OType_'+ReqMod.OrderType.value+'_MapEnabledForms']);
  if(ReqMod.AddReq.value == 'm' && typeof eval(topMBX).SysSettings['OType_'+ReqMod.OrderType.value+'_MapEnabledForms'] != 'undefined'){
    var allow = 0;
    var forms = eval(topMBX).SysSettings['OType_'+ReqMod.OrderType.value+'_MapEnabledForms'].split(',');
    for(var i = 0; i < forms.length; i++){ if(forms[i] == ReqMod.OrderForm.value){allow=1;} }
    if(allow == 0){
       alert("Maps are not enabled for form "+ReqMod.OrderForm.value+" yet!");
       add_doc_but.style.display = 'none';
    }else{
      add_doc_but.style.display = 'inline';
    }
  }else{
    add_doc_but.style.display = 'inline';
  }
  if (OptObj.AttachTypeClientFees != null && !OnAdminPage) {
    AddtlDocFee.innerHTML = "$ "+OptObj.AttachTypeClientFees[NewOrder.OrderedFor.value][OrderType][NewOrder.OrderSType.value][ReqMod.AddReq.value]+".00";
    AddtlDocFee.Fee = OptObj.AttachTypeClientFees[NewOrder.OrderedFor.value][OrderType][NewOrder.OrderSType.value][ReqMod.AddReq.value];
  }
  if (event) { event.returnValue=false; }
}
function CheckCostAdj(fname,fnhook) {
  if (eval(topMBX).UType == 'C' && TotalDocFee.innerText != "$ 0.00") {
    var tst = confirm("The extra documents will increase the cost of this order by "+TotalDocFee.innerText+", and will require us to take extra time to complete this order.\nWould you still like to proceed?");
    if (!tst) { eval(fname).RequiredDocs.value = eval(fname).RequiredDocs.old; }
  }
  //alert("Your changes have been saved.");
  if (fnhook) { eval(fnhook); }
  if (event) { event.returnValue=false; }
}
var OnAdminPage = 0;
function EditRequiredDocs(fname,fnhook,show) {
  var tform;
  if (typeof(fname) != 'object') { tform = eval(fname); } else { tform = fname; }
  if (!fnhook) { fnhook="HideModal();"; }
  var reqdoc = "<center><form name=ReqMod><input type=hidden name=OrderType value='"+tform.OrderType.value+"'><input type=hidden name=OrderForm value='"+tform.OrderForm.value+"'><input type=hidden name=AddReq><div class=s_dialog_box style='border:1px solid #000000;width:240;height:100;background-color:#999999;'><table cellpadding=2 cellspacing=1>";
  var erecs = eval(fname).RequiredDocs.value.split("");
  var total = 0; var tfirst = 0;
  var OrderType = tform.OrderType.value;
  for (var i=0;i<erecs.length;i++) {
    if (erecs[i] != ' ') {
      if (tfirst) { total += parseInt(OptObj.AttachTypeClientFees[tform.OrderedFor.value][OrderType][tform.OrderSType.value][erecs[i]]); }
      reqdoc += "<tr><td align=right><b style='color:#FFFFFF;padding:1px;margin:1px;'>"+eval(topMBX).OptObj['OType_'+tform.OrderType.value+'_AT'][erecs[i]]+"</b></td><td><a href=# class=s_button onclick=\"RemoveRequiredDoc('"+fname+"','"+erecs[i]+"','"+fnhook+"','"+show+"')\">Remove</a></td></tr>";
    } else {
      if (OnAdminPage==0) { tfirst = 1; }
    }
  }
  var adminview = "display:none;"; var orderview = "display:inline;"; var donotshow=0;
  var tst = document.location.href.split("/");
  var tst2 = tst[tst.length-1].split("?");
  if ( tst[tst.length-1] == 'client_admin.html#' || tst[tst.length-1] == 'client_admin.html' || tst2[0] == 'order_details.html' || tst2[0] == 'PVAL_order_details.html') { OnAdminPage=1; adminview = "display:inline;"; orderview = "display:none;";  ATType = ""; }
  var ATType="";
  try {
    var ttt = OptObj.AttachFeeType[tform.OrderedFor.value][OrderType][tform.OrderSType.value];
    //var ttt=OptObj.AttachFeeType[eval(fname).OrderedFor.value][OrderType][eval(fname).OrderSType.value];
    ATType = "ename='OptObj.AttachFeeType["+tform.name+".OrderedFor.value]["+tform.name+".OrderType.value]["+tform.name+".OrderSType.value]'";
  } catch (e) {
    if (OnAdminPage==0) { alert("Not Setup for any Added Benefit Cost Adjustments, please contact us to find out more."); donotshow=1; }// alert(e.description+"\n"+OrderedFor+"\n"+tform.OrderType.value+"\n"+tform.OrderSType.value); }
  }
  if(show){
    reqdoc += "</table></div><table cellpadding=0 cellspacing=1 width=242><tr><td align=right>Document:</td><td><input size=18 readonly class=sbox name=sAddReq tname='AddReq' sname='OType_"+tform.OrderType.value+"_AT'  onchange='CheckDocCost()'><a href=# class=sbutt tabindex=-1>V</a><a id='add_doc_but' href=# class=s_button onclick=\"AddRequiredDoc('"+fname+"',ReqMod.AddReq.value,'"+fnhook+"','"+show+"')\" style='margin-left:1px;'>Add</a></td><td align=right style='"+adminview+"'><a href=# class=s_button onclick=\"CheckCostAdj('"+fname+"','"+fnhook+"')\">Save</a></td></tr>";
  } else {
    reqdoc += "</table></div><table cellpadding=0 cellspacing=1 width=242><tr><td align=right>Document:</td><td><input size=18 readonly class=sbox name=sAddReq tname='AddReq' sname='OType_"+tform.OrderType.value+"_AT' "+ATType+" onchange='CheckDocCost()'><a href=# class=sbutt tabindex=-1>V</a><a id='add_doc_but' href=# class=s_button onclick=\"AddRequiredDoc('"+fname+"',ReqMod.AddReq.value,'"+fnhook+"','"+show+"')\" style='margin-left:1px;'>Add</a></td><td align=right style='"+adminview+"'><a href=# class=s_button onclick=\"CheckCostAdj('"+fname+"','"+fnhook+"')\">Save</a></td></tr>";
  }
  reqdoc += "<tr style='"+orderview+"'><td align=right>Fee to add this:</td><td id=AddtlDocFee>$ 0.00</td><td></td></tr>";
  reqdoc += "<tr style='"+orderview+"'><td align=right><hr>Total Additional:</td><td><hr style='width:60;text-align:left;'><b id=TotalDocFee Fee=0>$ "+total+".00</b></td><td></td></tr><tr style='"+orderview+"'><td colspan=3 align=right><a href=# class=s_button onclick=\"RevertReqDocs('"+fname+"','"+fnhook+"')\">Reload Included</a><a href=# class=s_button onclick=\"CheckCostAdj('"+fname+"','"+fnhook+"')\">Save</a></td></tr></form></table>";
  reqdoc += "</center>";
  if (!donotshow) {
    ShowModal("Requested Documents",reqdoc,null,1);
    initControls(ReqMod);
  }
  if (event) { event.returnValue=false; }
}

/****************************************************************************
    Notes
****************************************************************************/
function ShowAddNote() {
  var thtml = "<form name=ModalForm><input type=hidden name=OrderNoteCode><input type=hidden name=OrderID always=1><input type=hidden name=ObjectID always=1>Note Type:<br>";
      thtml += "<input req=1 style='width:184;' readonly class=sbox type=text name=sOrderNoteCode tname='OrderNoteCode' sname='ODetailsNoteCode' vname='Type of Note'><a href=# class=sbutt tabindex=-1>V</a><br>";
      thtml += "Note Text:<br><textarea req=0 rows=4 name=OrderNoteMsg class='white' style='width:200;overflow:hidden;margin-bottom:3px;' maxlength=255 onkeydown='FixLength()'></textarea><br>";

      thtml += "<a class=s_button href=# onclick='AddOrderNote();'>+Note</a></form>";
  ShowModal("Order Notes [Add Note]",thtml,null,1);
  initControls(ModalForm);
  InitFormChanges(ModalForm);
  ModalForm.OrderID.value = OrderDetailsForm.OrderID.value;
  ModalForm.ObjectID.value = OrderDetailsForm.ObjectID.value;
}
function AddOrderNote() {
  var thtml = CompileFormChanges(ModalForm);
  WebSubmit(top.UType,"AddOrderNote",thtml,"main","iODet.GotOrderNotes","d");
  if (event) { event.returnValue = false; }
}
/****************************************************************************
    List Editor - creates a delimited list of values for an input box
    default delimiter is ',' but can be overriden with sep parameter
    allows free text values, or if lup is provided uses lookup in a select box
****************************************************************************/
var _EditListLUP; var _EditListOLUP; var _EditListSrc; var _EditListHK;
function EditList(sep,lup,hk,olup,inp,rname){
  //separator - default is comma ","
  //lup-LookUp
  //hk
  //olup-oname
  if(typeof inp == 'undefined' || inp == ''){ 
      if(typeof inp != 'object'){ inp = event.srcElement.previousSibling; }
  }
  var luptype = 's';
  _EditListLUPType = 's';
  if(rname == 1) { luptype = 'r'; _EditListLUPType = 'r' };
  _EditListSrc = inp; _EditListHK = hk; if(lup){ _EditListLUP = lup } else { _EditListLUP = '' }  if(olup){ _EditListOLUP = olup }else{ _EditListOLUP = '' }
  var max = inp.maxlength;  if(max == ''){ max = 255; }
  if(sep == null){ sep = ',' }
  var htm = "<table cellspacing=0 cellpadding=0><form name=EditListForm sep='"+sep+"' val=''>";
  htm += "<input type=hidden name=EVal>";
  htm += "<tr><td>List:</td></tr>";
  htm += "<tr><td><div id=EValRow style='height:80px;overflow-y:auto;overflow-x:hidden;border:1px solid #444444;padding:4px;'></div></td></tr>";
//  htm += "<tr><td><textarea name=EVal readonly rows=4 style='width:250px;' maxlength="+max+">"+inp.value+"</textarea></td></tr>";
  htm += "<tr><td>Enter value to add to List:</td></tr>";
  var on = "";  if(olup){ on = "oname=EdLOVal" }
  if(lup && olup){ htm += "<tr><td><input type=hidden name=EdLOVal><input class=sbox type=text name=sEdLOVal tname=EdLOVal sname='"+olup+"' size=40><a href=\"#\" class=sbutt tabindex=-1>V</a>"; }
  if(lup){ htm += "<tr><td><input type=hidden name=EdLVal><input class=sbox type=text name=sEdLVal tname=EdLVal "+luptype+"name='"+lup+"' "+on+" size=40><a href=\"#\" class=sbutt tabindex=-1>V</a>&nbsp;<a href=# class=sbutt onclick='EditList_Add()'>Add</a>&nbsp;<a href=# class=sbutt onclick='EditList_Remove()'>Rem</a></td></tr>"; }
  else{ htm += "<tr><td><input type=text size=44 name=EdLVal maxlength="+max+"><a href=# class=sbutt onclick='EditList_Add()'>Add</a>&nbsp;<a href=# class=sbutt onclick='EditList_Remove()'>Rem</a></td></tr>"; }
  htm += "<tr style='padding-top:8px;'><td style='text-align:right;'><a href=# class='s_button' onclick='EditList_Close()'>Done</a></td></tr>";
  htm += "</form></table><br>";
  ShowModal("Edit List",htm,null,null,null,300);
  initControls(EditListForm);
  var v = inp.value.split(sep);
  if(v != ''){
    for(var i in v){
      if(olup){
        var to = v[i].split(':');
        EditList_Add(to[1],to[0]);
      }else{
        EditList_Add(v[i]);
      }
    }
  }
}
function EditList_Add(val,oval){
  var v; var ov; var display;
  if(typeof val != 'undefined' && val != ''){
    v = val;
    if(typeof oval != 'undefined' && oval != ''){ ov = oval }
  } else {
    v = EditListForm.EdLVal.value;
    if(_EditListOLUP != ''){ ov = EditListForm.EdLOVal.value;  }
  }
  if(typeof _elv == 'object' && _elv.length){
    for (var i = 0; i<_elv.length;i++) {
      if(_elv[i].innerHTML == EditListForm.EdLVal.value){
        alert("Value is already in List!");
        return;
      }
    }
  }else if(typeof _elv == 'object'){
    if(_elv.innerHTML == EditListForm.EdLVal.value){
        alert("Value is already in List!");
        return;
    }
  }
  if(_EditListLUP != ''){
    var o;  
    if(_EditListLUPType == 'r'){
      if(_EditListOLUP != ''){ o = eval(_EditListLUP+"['"+ov+"']") }else{ o = eval(_EditListLUP) }
    } else {
      if(_EditListOLUP != ''){ o = eval("OptObj['"+_EditListLUP+"']['"+ov+"']") }else{ o = eval('OptObj.'+_EditListLUP) }
    }
    display = o[v];
    if(_EditListOLUP != ''){ v = ov + ":" + v; }
  } else { display = v; }

  if(typeof v != 'undefined' && v != ''){ EValRow.innerHTML += "<div style='margin-bottom:5px;'><span id=_elv style='width:180px;overflow-x:hidden;' val='"+v+"'>"+display+"</span><a class=sbutt href=# onclick='EditList_Remove()'>Remove</a></div>"; }
  EditListForm.EdLVal.value = '';
  try {
  event.cancelBubble = true;
  event.returnValue = false;
  } catch (e) {}
}
function EditList_Remove(){
  event.srcElement.previousSibling.innerHTML = "";
  event.srcElement.parentElement.style.display = 'none';
  event.srcElement.style.display = 'none';
  event.cancelBubble = true;
  event.returnValue = false;
}
function EditList_Close(){
  var v = "";
  if(typeof _elv == 'object' && _elv.length){
    for (var i = 0; i<_elv.length;i++) {
      if(_elv[i].innerHTML != ''){
        if(v != ''){ v += EditListForm.sep  }
        v += _elv[i].val;
      }
    }
  }else if(typeof _elv == 'object'){
    if(_elv.innerHTML != ''){ v = _elv.val; }
  }else{
    alert('Error in EditList!');
  }
  _EditListSrc.value = v;
  if(typeof _EditListHK != 'undefined' && _EditListHK != ''){ eval(_EditListHK); }
  HideModal();
}



var win; var winfld; var RO = 0; var val;
function PopupText(str,form,field){
  var ht = window.screen.height - 120;
  var wd = (window.screen.width - 700)/2;
  var parm = 'location=no,status=no,toolbar=no,menubar=no,resizable=yes,height='+ht+',width=700,scrollbars=yes,left='+wd+',top=30';
  win=window.open('./MBX_TextEditor.html',null,parm);
  if (top.debug) {debugger;}
  if(str != ''){ 
    val = str;
    RO = 1;
  }else{
    winfld = eval(form+"."+field);
    val = winfld.value;
    RO = winfld.readOnly;
  }  
  //win.document.all.donebutt.onclick=this.SaveValue;  
  if (event) { event.returnValue = false; }
}

function TextEditDone(){
  if(RO == 1){
    win.SetReadOnly(1);
  }else{
    win.SetReadOnly(0);
  }
  win.SetValue(val);
  win.document.all.donebutt.onclick=this.SaveValue;
  if (event) { event.returnValue = false; }
}
function SaveValue(){
  win.SetSavedFlag(1);
  win.close();
  if(win.IsReadOnly() == 0){  
    winfld.value = win.WinForm.Text.value;
    winfld.mod = 1;
  }
}





function clearModal(obj){
  if (typeof(obj)!= 'undefined'){ ShowModal("","", null, 1); HideModal(); }
}
function derefit(txt) {
  if (txt == null) { return ''; }
  var sa = txt.toString();
  var re;
  re = /\\/g; sa = sa.replace(re, "\\\\");
  re = /\//g; sa = sa.replace(re, "\\\/");
  re = /\"/g; sa = sa.replace(re, '\\""');      //"//replace " with \"" for SQL
  re = /�/gi; sa = sa.replace(re, "'");
  re = /�/gi; sa = sa.replace(re, "-");
  re = /\'/g; sa = sa.replace(re, "\'");
  re = /\n/g; sa = sa.replace(re, "\\n");
  re = /\t/g; sa = sa.replace(re, "");
  re = /\r/g; sa = sa.replace(re, "");
  re = /�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|ፉ|�|�|�|�|�|�/gi; sa = sa.replace(re, "");
  re = /�/gi; sa = sa.replace(re, "1/4");
  re = /�/gi; sa = sa.replace(re, "1/2");
  re = /�/gi; sa = sa.replace(re, "3/4");
  re = /\\+$/g; sa = sa.replace(re, '');
  return sa;
}
//function CheckMe(theField) {
//  if (typeof(theField) != 'object') { theField = eval(theField); }
//
//  txt = theField.value;
//
//  if (txt == null) { return ''; }
//
//  var DataField = txt.toString();
//  var DataCapture = " ";
//
////  replace all characters that the user shouldn't concern themselves with
////  re = /[^\x20-\x7E]/g;
////  DataField = DataField.replace(re, "");
//
////  re = /\//g;
////  DataField = DataField.replace(re, "\\\/");
//
////  re = /\"/g;
////  DataField = DataField.replace(re, '\\""');      // replace " with \"" for SQL
//
//  re = /�/gi;
//  DataField = DataField.replace(re, "'");
//
//  re = /�/gi;
//  DataField = DataField.replace(re, "-");
//
////  re = /\'/g;
////  DataField = DataField.replace(re, "\'");
//
////  re = /\n/g;
////  DataField = DataField.replace(re, "\\n");
//
//  re = /\t/g;
//  DataField = DataField.replace(re, "");
//
//  re = /\r/g;
//  DataField = DataField.replace(re, "");
//
//  re = /�/gi;
//  DataField = DataField.replace(re, "1/4");
//
//  re = /�/gi;
//  DataField = DataField.replace(re, "1/2");
//
//  re = /�/gi;
//  DataField = DataField.replace(re, "3/4");
//
//  re = /\\+$/g;
//  DataField = DataField.replace(re, '');
//
//  var BadChar = DataField;
//
////  re = /�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|�|ፉ|�|�|�|�/; // affects entire function
//
//  re = /[^\x20-\x7E]/; // affects entire function
//
//  var BadDataFound = 0; // no bad data found yet...
//
//  while (re.exec(DataField) != null) {
//
//    BadDataFound += 1;  // found some bad data, mark to open ShowModal
//
//    BadChar = DataField.match(re);  // put all bad chars in BadChar array
//
//    PosOfBad = DataField.indexOf(BadChar, 0); // position of BadChar in string DataField
//
//    // capture data from -14 to +16 and add to variable with <br> at end
//
//    if (PosOfBad >= 14) {
//      var DataMin = PosOfBad -14; // go back to this point in the data
//    } else {
//      var DataMin = 0;
//    }
//
//    if (DataField.length <= 16 ) {
//      var DataMax = DataField.length;
//    } else {
//      var DataMax = PosOfBad + 16; // go forward to this point in the data
//    }
//
//    DataCapture = DataCapture + DataField.slice(DataMin, PosOfBad);
//    DataCapture = DataCapture + "<font color=\"#dd0000\">" + DataField.slice(PosOfBad, PosOfBad+1) + "</font>";
//    DataCapture = DataCapture + DataField.slice(PosOfBad+1 , DataMax);
//    DataCapture = DataCapture + "<br>"; // break to next line
//
//    // change bad data to OK data and loop through this again until no more data to look through
//    DataField = DataField.replace(re, "");
//  }
//
//  // change caption of ShowModal to reflect proper grammar ;)
//  if (BadDataFound < 10 ) { // normal ammount of bad data found
//    if ((BadDataFound > 0 ) && (BadDataFound >= 2)) {
//      ShowModal(BadDataFound + " Out of Range Characters Found", DataCapture);
//    } else if ((BadDataFound > 0 ) && (BadDataFound < 2)) {
//      ShowModal(BadDataFound + " Out of Range Character Found", DataCapture);
//    }
//
//  } else { // large sum of bad data found - prevents browser from failing
//    DataCapture = DataCapture.slice(0, 300);
//    DataCapture = DataCapture + "<br><br><font color=\"#dd0000\"><u>Too Many Changes to List<u></font><br><br>";
//    ShowModal(BadDataFound + " Out of Range Characters Found", DataCapture);
//  }
//
//theField.value = DataField;
//
//return true;
//}



// Override the built in Number.toFixed method. 
// This was lifted directly from the comp.lang.javascript FAQ http://www.jibbering.com/faq/

function Stretch(Q, L, c) { var S = Q
 if (c.length>0) while (S.length<L) { S = c+S }
 return S
}
function StrU(X, M, N) { // X>=0.0
 var T, S=new String(Math.round(X*Number("1e"+N)))
 if (S.search && S.search(/\D/)!=-1) { return ''+X }
 with (new String(Stretch(S, M+N, '0')))
 return substring(0, T=(length-N)) + '.' + substring(T)
}
function Sign(X) { return X<0 ? '-' : ''; }
function StrS(X, M, N) { return Sign(X)+StrU(Math.abs(X), M, N) }
Number.prototype.toFixed= new Function('n','return StrS(this,1,n)')

