String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function GetBrowserType() {
 var sBrowser=navigator.appName;
 var sVersion=navigator.appVersion;
 return(sBrowser+'|'+sVersion);
}

function openCenteredWindow(url, height, width, name, parms) {

   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   if (height <= 1) { height = Math.floor(screen.height * height); }
   if (width <= 1) { width = Math.floor(screen.width * width); }
   if (navigator.appName=="Netscape") {
    var winParms = "screenY=" + top + ",screenX=" + left + ",height=" + height + ",width=" + width;
   }
   else {
    var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   }
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   return win;
}

function closeCenteredWindow() {

  win.close();

}

function GetASPSession(sURL) {

 var sRet='';
 var xmlHttp;
 if (window.XMLHttpRequest) {
  xmlHttp = new XMLHttpRequest();
 } else {
  if (window.ActiveXObject) {
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 if (xmlHttp == null) return null;
 xmlHttp.open("GET", sURL, false);
 xmlHttp.send(null);
 sRet = xmlHttp.responseText;
 return sRet;
}

function AddDaysToDate(dDate,nDays) {
 var newDate= new Date(dDate);
 newDate.setDate(newDate.getDate()+nDays);
 return newDate.toLocaleDateString();
}

function AddMonthsToDate(dDate,nMonths) {
 var newDate= new Date(dDate);
 newDate.setMonth(newDate.getMonth()+nMonths);
 return newDate.toLocaleDateString();
}

function getPos(el,sProp) {
	var iPos = 0
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos
}

function ShowIframePos(i,d,t) {
if(i.length < 1) { return; }
if(d.length < 1) { return; }
if(t.length < 1) { return; }
var p=document.getElementById(i);
var q=document.getElementById(d);
var r=document.getElementById(t);
if(!p) { return; }
if(!q) { return; }
if(!r) { return; }
p.style.left=q.style.left;
p.style.top=q.style.top;
p.width=r.offsetWidth;
if(navigator.appName=="Microsoft Internet Explorer") {p.width=r.offsetWidth+2;}
p.height=r.offsetHeight;
if(navigator.appName=="Microsoft Internet Explorer") {p.height=r.offsetHeight+2;}
p.style.visibility="visible";
p.style.display = "block";
p.style.frameBorder="0px";
p.style.display="block";
}
function ShowIframe(i) {
if(i.length < 1) { return; }
var p=document.getElementById(i);
if(!p) { return; }
p.style.display = "block";
}

function HideIframe(i) {
if(i.length < 1) { return; }
var p=document.getElementById(i);
if(!p) { return; }
p.style.display= "none";
}

function UnSelectAll(d) {
if(d.length<1) {return;}
var p=document.getElementById(d);
if(p==null) {return;}
 var i=0;
 for (i=0; i<p.options.length; i++) {
  if (p.options[i].selected) {p.options[i].selected=false;}
 }
}

function GetAllSelected(d) {
if(d.length<1) {return '';}
var p=document.getElementById(d);
if(p==null) {return '';}
 var i=0;
 var sret='';
 for (i=0; i<p.options.length; i++) {
  if (p.options[i].selected) {sret=AddToString(sret,p.options[i].value,',');}
 }
 return sret;
}

function SetCheck(d,value) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).checked=value;
}

function EnableControl(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).disabled=false;
}

function DisableControl(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).disabled=true;
}

function CheckControlDups(d,iStart,iEnd,sSuffix,sLabel,sBlankPhrases) {
 var bRet=true;
 var sTemp='';
 var sTemp1='';
 var sBP=sBlankPhrases;
 if(d.length<1) {return bRet;}
 if(iEnd<=0) {return bRet;}
 if(iStart<0) {return bRet;}
 if(iStart>iEnd) {return bRet;}
 if(sBP.length==0){sBP=';N/A;NA;BLANK;NONE;';}
 sBP=sBP.toUpperCase();
 var i=0;
 var j=0;
 for (i=iStart; i<=iEnd; i++) {
  sTemp=GetControlValue(d + i.toString() + sSuffix).toUpperCase();
  for (j=iStart; j<=iEnd; j++) {
   if (i!=j) {
    sTemp1=GetControlValue(d + j.toString() + sSuffix).toUpperCase()
    if (sTemp1.length!=0 || sTemp.length!=0) {
     if ((';' + sBP + ';').indexOf(';' + sTemp + ';')<0) {
      if ((';' + sBP + ';').indexOf(';' + sTemp1 + ';')<0) {
       if (sTemp1==sTemp) {
        alert('Duplicate ' + sLabel + ' detected for value: ' + sTemp);
        bRet = false;
        i=iEnd+1;
        j=iEnd+1;
       }
      }
     }
    }
   }
  }
 }
 return bRet;
}

function CreatePopUpBox(sID,sParentID,iZIndex,sPosition,iTop,iLeft,iWidth,iHeight,sBackgroundColor,sBorder,sPadding,sOpacity,iFormNo,sTail) {

//alert('Entering CreatePopUpBox with '+sID);
//sPosition='static';
//iZIndex=3;

 var iWidthMax = document.documentElement.clientWidth + document.documentElement.scrollLeft;
 var iHeightMax = document.documentElement.clientHeight + document.documentElement.scrollTop;
 var sHTML=''; 
 var oDiv = document.createElement('div');
 oDiv.style.zIndex = iZIndex;
 oDiv.id = sID;
 if(sPosition==''){
  oDiv.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
 } else {
  if(sPosition.toLowerCase()=='center') {
   iLeft=(iWidthMax/2) - (iWidth/2);
   iTop=(iHeightMax/2) - (iHeight/2);
   oDiv.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
  } else {
   if(sPosition.toLowerCase()=='adjacent') {
    var iPLeft=document.getElementById(sParentID).style.left;
    var iPTop=document.getElementById(sParentID).style.top;
    iTop = iTop+iPTop;
    iLeft = iLeft+iPLeft;
    oDiv.style.position=document.getElementById(sParentID).style.position;
   } else {
    oDiv.style.position = sPosition;
   }
  }
 }
 oDiv.style.top = iTop + 'px';
 oDiv.style.left = iLeft + 'px';
 oDiv.style.height = iHeight + 'px';
 oDiv.style.width = iWidth + 'px';
 if(sBackgroundColor=='') {
  oDiv.style.backgroundColor = 'white'; 
 } else {
  oDiv.style.backgroundColor = sBackgroundColor;
 }
 if(sBorder=='') {
  oDiv.style.border = '2px solid silver';
 } else {
  oDiv.style.border = sBorder;
 }
 if(sPadding=='') {
  oDiv.style.padding = '20px';
 } else {
  oDiv.style.padding = sPadding;
 }
 if(sOpacity!='') {
  oDiv.style.opacity = sOpacity;  
  oDiv.style.filter += ('progid:DXImageTransform.Microsoft.Alpha(opacity='+(sOpacity*100)+')');
 }
 if(iFormNo>0) {
  sHTML=GetFormHTML(iFormNo,sTail,sID);
//  alert('HTML: '+sHTML)
 }
 if(sHTML!='') {
  oDiv.innerHTML=sHTML;
 } 
 document.body.appendChild(oDiv);
 return
}

function CreateLayerFromControl(sID,iTop,iLeft,iWidth,iHeight,sBackgroundColor,sBorder,sPadding,sOpacity,sHTMLControl) {

//alert('Entering CreatePopUpBox with '+sID);
//sPosition='static';
//iZIndex=3;

 var sHTML=GetInnerHTML(sHTMLControl); 
 var oDiv = document.createElement('div');
 oDiv.style.zIndex = 2;
 oDiv.id = sID;
 oDiv.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
 oDiv.style.top = iTop + 'px';
 oDiv.style.left = iLeft + 'px';
 oDiv.style.height = iHeight + 'px';
 oDiv.style.width = iWidth + 'px';
 if(sBackgroundColor=='') {
  oDiv.style.backgroundColor = 'white'; 
 } else {
  oDiv.style.backgroundColor = sBackgroundColor;
 }
 if(sBorder=='') {
  oDiv.style.border = '2px solid silver';
 } else {
  oDiv.style.border = sBorder;
 }
 if(sPadding=='') {
  oDiv.style.padding = '20px';
 } else {
  oDiv.style.padding = sPadding;
 }
 if(sOpacity!='') {
  oDiv.style.opacity = sOpacity;  
  oDiv.style.filter += ('progid:DXImageTransform.Microsoft.Alpha(opacity='+(sOpacity*100)+')');
 }
 oDiv.innerHTML=sHTML;
 document.body.appendChild(oDiv);
 return
}

function RemoveElement(sID) {

 if(sID.length<1) {return;}
 if(document.getElementById(sID)==null) {return;}
 if(document.getElementById(sID)==undefined) {return;}
// if(document.getElementById(sID).type==undefined) {return;}
//alert('Entering RemoveElement with '+sID+': '+document.getElementById(sID).type);
 document.body.removeChild(document.getElementById(sID));
 return;
}

function GetControlValueH(d) {
 //alert(d+'='+GetControlValue(d)+', H'+d+'='+GetControlValue('H'+d));
 
 if (GetControlValue(d)==null || GetControlValue(d)==undefined) {return GetControlValue('H'+d);}
 return GetControlValue(d);
}

function GetControlValue(d) {
 if(d.length<1) {return;}
 if(document.getElementById(d)==null) {return;}
 if(document.getElementById(d)==undefined) {return;}
 if(document.getElementById(d).type==undefined) {return;}
 if(document.getElementById(d).type.toUpperCase().indexOf('SELECT')<0) {
  return document.getElementById(d).value;
 } else {
  var sControlTest=document.getElementById(d)
  var i=0;
  var s='';
  for (i=0; i<sControlTest.options.length; i++) {
   if (sControlTest.options[i].selected) {s=AddToString(s,sControlTest.options[i].value,',');}
  }
  if (s==''){s=sControlTest.value;}
  return s;
 }
}

function GetControlValueAtSelectedIndex(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
if(document.getElementById(d)==undefined) {return;}
 if(document.getElementById(d).type==undefined) {return;}
if(document.getElementById(d).type.toUpperCase().indexOf('SELECT')<0) {return;}
return document.getElementById(d).options[document.getElementById(d).selectedIndex].text;
}

function GetControlType(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
return document.getElementById(d).type;
}

function GetControlSelectedIndex(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
return document.getElementById(d).selectedIndex;
}

function GetObject(d) {
if(d.length<1) {return;}
return document.getElementById(d)
}

function SetControlValue(d,value) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).value=value;
}

function Increment(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
var p=document.getElementById(d);
p.value++
}

function Decrement(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
var p=document.getElementById(d);
p.value--
if(p.value<0){p.value=0;}
}

function SetControlFocus(d) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).focus();
}

function SetControlIndex(d,value) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).selectedIndex=value;
}

function GetCheck(d) {
if(d.length<1) {return false;}
if(document.getElementById(d)==null) {return false;}
return document.getElementById(d).checked;
}

function SetInnerHTML(d,svalue) {
if(d.length<1) {return;}
if(document.getElementById(d)==null) {return;}
document.getElementById(d).innerHTML=svalue;
return;
}

function GetInnerHTML(d) {
if(d.length<1) {return '';}
if(document.getElementById(d)==null) {return '';}
return document.getElementById(d).innerHTML;
}

function ExtractSCControls(svalue) {
var sRet='';
if(!svalue) {return sRet;}
if(svalue.length<1) {return sRet;}
var sRest=svalue;
var sTemp='';
var sTest='';
var iAt=0;
var sAdd='s'

do {

 iAt=sRest.indexOf('_IMG');
 if(iAt>=0) {
  sTemp=sRest.substring(0,iAt);
  sRest=sRest.substring(iAt+4);
  iAt=sTemp.lastIndexOf('"');
  if(iAt>=0) {
   sTest=sTemp;
   sTemp=sTemp.substring(iAt+1);
   if((','+sRet+',').indexOf(',d'+sTemp+',')<0 && (','+sRet+',').indexOf(',s'+sTemp+',')<0) {
    sAdd='s';
    iAt=sTest.indexOf('id="' + sTemp + '"');
    if(iAt>=0) {
     sTest=sTest.substring(iAt+4+sTemp.length);
     iAt=sTest.indexOf('>');
     if(iAt>=0) {
      sTest=sTest.substring(0,iAt);
      iAt=sTest.indexOf('style="width:400px"');
      if(iAt>=0) {
       sAdd='d';
      }
     }
    }
    sRet=AddToString(sRet,sAdd+sTemp,",");
   }
  }
 } else {
  sRest='';
 }
}
while (sRest.length>0);

return sRet;
}

function ConditionallyShowContent(d) {
if(d==null) {return;}
if(d==undefined) {return;}
if(d.length < 1) { return;}
var sDiv=ReturnField(d,0,',');
var sTmp=ReturnField(d,1,',');
var sTest=ReturnField(sTmp,0,'|');
var sOp=ReturnField(sTmp,1,'|');
var sVal=ReturnField(sTmp,2,'|');

//alert('sDiv='+sDiv+', sTmp='+sTmp+', sTest='+sTest+', sOp='+sOp+', sVal='+sVal);

HideContent(sDiv);

//alert('ApplyOperator returns: '+ApplyOperator(sTest,sOp,sVal));

if(ApplyOperator(sTest,sOp,sVal)==true){ShowContent(sDiv);}
}

function ApplyOperator(sVar,sOp,sTest) {
if(sVar==null){return false;}
if(sVar==undefined){return false;}
var sGetVal=GetControlValueH(sVar);
if(sGetVal==null){return false;}
if(sGetVal==undefined){return false;}

//alert ('sOp='+sOp+', sGetVal='+sGetVal.toUpperCase()+', sTest='+sTest.toUpperCase()+', '+ (sGetVal.toUpperCase().trim()==sTest.toUpperCase().trim())+', '+(sGetVal==sTest));

if(sOp=='=' && sGetVal.toUpperCase().trim()==sTest.toUpperCase().trim()){return true;}
if(sOp=='<>' && sGetVal.toUpperCase().trim()!=sTest.toUpperCase().trim()){return true;}
if(sOp=='<' && sGetVal.toUpperCase().trim()<sTest.toUpperCase().trim()){return true;}
if(sOp=='>' && sGetVal.toUpperCase().trim()>sTest.toUpperCase().trim()){return true;}
if(sOp=='<=' && sGetVal.toUpperCase().trim()<=sTest.toUpperCase().trim()){return true;}
if(sOp=='>=' && sGetVal.toUpperCase().trim()>=sTest.toUpperCase().trim()){return true;}
if(sOp=='IN' && (','+sTest.toUpperCsse().trim()+',').indexOf(','+sGetVal.toUpperCase().trim()+',')>=0){return true;}
return false;
}

function ClearSelect(d) {
 var d1=ReturnField(d,0,'~');
 var iRetain=ReturnField(d,1,'~');
 if(iRetain.length==0 || isNaN(iRetain)){iRetain=0;}
 if(d1.length<1) {return;}
 if(document.getElementById(d1)==null) {alert('could not find element');return;}
 var od=document.getElementById(d1);
 if(od.type.toLowerCase().indexOf('select')<0) {return;}
 od.options.length=iRetain;
 return(true);
}

function HideContent(d) {
if(d==null){return;}
if(d==undefined){return;}
if(d.length < 1) { return; }
if(document.getElementById(d)==null) { return; }
document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
if(d==null){return;}
if(d==undefined){return;}
if(d.length < 1) { return; }
if(document.getElementById(d)==null) { return; }
document.getElementById(d).style.display = "block";
}

function SelectedCount (d) {
if(d.length < 1) { return -2; }
if(document.getElementById(d)==null) { return -1; }
 var sControlTest=document.getElementById(d)
 var i=0;
 var iCount=0;
 for (i=0; i<sControlTest.options.length; i++) {
  if (sControlTest.options[i].selected) {iCount++;}
 }
 return(iCount);
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d)==null) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

function GetDIVDisplayMode(d) {
if(d.length < 1) { return(''); }
if(document.getElementById(d)==null) { return(''); }
if(document.getElementById(d)==undefined) { return(''); }
return(document.getElementById(d).style.display);
}

function GetSession() {

// this function must be called from the /pages directory - either MIE or accx

  var base = "GetSession.asp"
  var prtcl = "http:";
  if (document.URL.substr(0,6).toLowerCase() == "https:") prtcl = "https:"
  
  var adjust = '';
  if (document.URL.toLowerCase().indexOf('.aspx')>-1) {adjust='../../acc/pages/';}
  
  var url = prtcl + adjust + base; 
  var xmlHttp;
  if (window.XMLHttpRequest)
  {
    xmlHttp = new XMLHttpRequest();
  }
  else
  {
    if (window.ActiveXObject)
    {
      var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

  xmlHttp.open("POST", url, false);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.send();

  var rt=xmlHttp.responseText;
  var iAt=rt.indexOf('id="Contact"');
  var bRet=false;
  if(iAt>-1) {
   rt=rt.substring(iAt+12);
   iAt=rt.indexOf('value="');
   if(iAt>-1) {
    rt=rt.substring(iAt+7);
    if(rt.substring(0,2)=='-1'){bRet=true;}
   }
  }
 return(bRet);
}

function GetFormHTML(iFormNo,sTail,sElement) {

// this function must be called from the /pages directory - either MIE or accx

  var sRet='';
  var base = "GetFormHTML.aspx?S="+sTail+"&ME="+sElement
  
//  alert('base='+base);
  
  var prtcl = "http:";
  if (document.URL.substr(0,6).toLowerCase() == "https:") prtcl = "https:"
  
  var adjust = '';
  if (document.URL.toLowerCase().indexOf('.aspx')==-1) {adjust='../../accx/pages/';}
  
  var url = prtcl + adjust + base; 
  var xmlHttp;
  if (window.XMLHttpRequest)
  {
    xmlHttp = new XMLHttpRequest();
  }
  else
  {
    if (window.ActiveXObject)
    {
      var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

//alert('URL: '+url);

  xmlHttp.open("POST", url, false);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.send();

  var rt=xmlHttp.responseText;
  var rtSave=rt;
  var iAt=rt.indexOf('id="Contact"');
  if(iAt>-1) {
   rt=rt.substring(iAt+12);
   iAt=rt.indexOf('value="');
   if(iAt>-1) {
    rt=rt.substring(iAt+7);
    if(rt.substring(0,2)=='-1'){
// we have made contact, now pick off the returned HTML    
     rt=rtSave;
     iAt=rt.indexOf('id="Results"');
     if(iAt>-1) {
      rt=rt.substring(iAt+12);
      iAt=rt.indexOf('value="');
      if(iAt>-1) {
       rt=rt.substring(iAt+7);
       iAt=rt.indexOf('~||~');
       if(iAt>-1) {
        sRet=rt.substring(0,iAt);
       }
      }
     }
    }
   }
  }
 return(sRet);
}

function isValidDate(dateStr, format) {
if (dateStr == null) {return true;}
if (dateStr.length == 0) {return true;}
if (format == null) { format = "MDY"; }
format = format.toUpperCase();
if (format.length != 3) { format = "MDY"; }
if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
if (format.substring(0, 1) == "Y") { // If the year is first
var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
} else if (format.substring(1, 2) == "Y") { // If the year is second
var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
} else { // The year must be third
var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
}
// If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
// Check to see if the 3 parts end up making a valid date
if (format.substring(0, 1) == "M") { var mm = parts[0]; } 
else if (format.substring(1, 2) == "M") { var mm = parts[1]; } 
else { var mm = parts[2]; }
if (format.substring(0, 1) == "D") { var dd = parts[0]; } 
else if (format.substring(1, 2) == "D") { var dd = parts[1]; } 
else { var dd = parts[2]; }
if (format.substring(0, 1) == "Y") { var yy = parts[0]; } 
else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } 
else { var yy = parts[2]; }
if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
if (parseFloat(dd) != dt.getDate()) { return false; }
if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
return true;
}

function isValidTime (timeStr) {
 if (timeStr == null) {return true;}
 if (timeStr.length == 0) {return true;}
 var min = 0;
 var hr = 0;
 var sec = 0;
 var ampm = '';
 var iAt = -1;
 var sep = ':'
 iAt = timeStr.indexOf(sep);
 if (iAt==-1) {sep='.';}
 iAt = timeStr.indexOf(sep);
 if (iAt==-1) {return false;}
 hr = timeStr.substring(0,iAt);
 min = timeStr.substring(iAt+1);
 iAt = min.indexOf(sep);
 if (iAt<0) {
  iAt = min.indexOf(' ');
  if (iAt>=0) {
   ampm = min.substring(iAt+1).toUpperCase();
   min = min.substring(0,iAt);
  }
 } 
 else {
  sec = min.substring(iAt+1);
  min = min.substring(0,iAt);
  iAt = sec.indexOf(' ');
  if (iAt>=0) {
   ampm = sec.substring(iAt+1).toUpperCase();
   sec = sec.substring(0,iAt);
  }
 }

 if (hr.NaN) {return false;}
 if (min.NaN) {return false;}
 if (sec.NaN) {return false;}
 if ((hr < 0 || hr > 23) && ampm=='') {return false;}
 if ((hr < 0 || hr > 11) && ampm!='') {return false;}
 if (min < 0 || min > 59) {return false;}
 if (sec < 0 || sec > 59) {return false;}
 if ((ampm != '') && (ampm != 'AM') && (ampm != 'PM')) {return false;}
 return true;
}

function MOD137 (sTest) {
 if (sTest == null) {return true;}
 if (sTest.length == 0) {return true;}
 var T = 0;
 var v = new Array();
  v[0] = 1;
  v[1] = 3;
  v[2] = 7;
 var cv = 0;
 var t1;
 var t2;
 var i;
 var iMOD = false;
 for (i=sTest.length-2;i>=0;i--) {
  T = T + (parseInt(sTest.substr(i,1)) * v[cv]);
  cv++
  if (cv>2) cv=0;
 }
 t1 = sTest.substr(sTest.length-1,1)
 t2 = T.toString()
 t2 = t2.substr(t2.length-1,1)
 if (t1==t2) iMOD=true;
return iMOD;
}

function MOD43 (sTest) {
 if (sTest == null) {return true;}
 if (sTest.length == 0) {return true;}
 var TestD = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
 var TestSum = 0;
 var iPos = 0;
 var TestDiv = 0;
 var CD = 0;
 var CkD = 0;
 var iMOD = false;
 for (i=0; i <= sTest.length-2; i++) {
  iPos = TestD.indexOf(sTest.substr(i,1))
  TestSum = TestSum + iPos
 }
 TestDiv = TestSum / 43
 CD = (TestDiv - parseInt(TestDiv)) * 43
 CkD = TestD.substr(CD,1)
 if (CkD == sTest.substr(sTest.length-1,1)) iMOD=true;
 return iMOD;
}

var g_obj=null;

function TestActiveXObject() {
  var nErr=-1;
  if(ReturnField(GetBrowserType(),0,"|").toUpperCase().indexOf('INTERNET EXPLORER')>=0) {
   if(g_obj==null || typeof(g_obj)==undefined){g_obj = new ActiveXObject("ESIControls.ESControl");}
   if(typeof(g_obj)!=undefined){nErr=0;}
  }
  return(nErr);
}

function cmdSaveSetting(strRootKeyName,strKeyName,strSubKeyName,strValue) {
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  var strErrMsg='';
  g_obj.SaveSetting(nErrCode,strErrMsg,strRootKeyName,strKeyName,strSubKeyName,strValue);
 }
 return (nErrCode);
}

function cmdGetSetting(strRootKeyName,strKeyName,strSubKeyName) {
 var strValue='';
 if(TestActiveXObject()==0) {
  var strErrMsg='';
  var nErrCode=0;
  strValue=g_obj.GetSetting (nErrCode,strErrMsg,strRootKeyName,strKeyName,strSubKeyName);
 }
 return (strValue);
}

function SaveAssetNumber (strValue) {
 var strKey1='';
 var strKey2='';
 var strKey3='';
 var nRet=0;
 var nRet1=0;
 strKey1 = '7E839AA3BC'
 strKey2 = '7E94B7B841D453F172828B9BB0'
 strKey3 = '7EFA3AE8 23ACD17C16881B6'
 nRet = cmdSaveSetting(strKey1,strKey2,strKey3,strValue);
 strKey1 = "7E839A98A1"
 strKey2 = "7E868D93"
 strKey3 = "7EFA3AE8 23ACD17C16881B6"
 nRet1=cmdSaveSetting(strKey1,strKey2,strKey3,strValue);
 if(nRet!=0){return(nRet);}
 return(nRet1);
}

function SaveDynamic (strValue,strWhich) {
 var strKey1='';
 var strKey2='';
 var strKey3='';
 var strEmail='';
 var strLastName='';
 var strFirstName='';
 var strOrganization='';
 var strCostCenter='';
 var strLocation='';
 var strEmpID='';
 var strDept='';
 var strTech='';
 var strTicket='';
 var strOrgRemove='';
 var strDeptRemove='';
 var strLocRemove='';
 var strClaimChk='';
 var strClaimChkExpire='';
 var strAssetType='';
 var strSN='';
 var strMfr='';
 var strProdDesc='';
 var strModel='';
 var strState='';
 var strStateRemove='';
 strKey1 = "7E839A98A1"
 strKey2 = "7E868D93"
 strEmail = "7E86A74CF92A2EC66EAC5E945C"
 strLastName = "7E8FA45D9DA74CED16"
 strFirstName = "7E81BE74AB6CFF35E7 1"
 strOrganization = "7E88AE53F82BD1183CFC2ADC1F"
 strCostCenter = "7E84A75E9EAD569040E910"
 strLocation = "7E8FAA4BE019C76394"
 strEmpID = "7E86A75DEA63"
 strDept = "7E87B86C81BF718AAA5585"
 strTech = "7E97A849FD20CC6488A558"
 strTicket = "7E9755FD25C67E"
 strOrgRemove = "7E88AE53F82BD1183CFC2ADC1F34D5 F3BE5 E"
 strDeptRemove = "7E87B86C81BF718AAA558592A3548F4AEA"
 strLocRemove = "7E8FAA4BE019C76394AA5C8CAF6384"
 strClaimChk = "7E84A443E0 2 03CE4 423"
 strClaimChkExpire = "7E84A443E0 2 03CE4 4232DF127DC 32DF4"
 strAssetType = "7EFA3AE8 23ACB11C466"
 strSN = "7E94AD6582AF59F32CD5749C5B"
 strMfr = "7E8EBB6FA843E111C07AA043E1"
 strProdDesc = "7E8BA95C8C4EF43DC46695BD6488B4658BAE58"
 strModel = "7E8EA94BFC25"
 strState = "7E945DFB3CED"
 strStateRemove = "7E945DFB3CED 53EEE12C46F"
 if(strWhich.toUpperCase()=='EMAIL ADDRESS' || strWhich.toUpperCase()=='EMAIL'){strKey3=strEmail;}
 if(strWhich.toUpperCase()=='LASTNAME'){strKey3=strLastName;}
 if(strWhich.toUpperCase()=='FIRSTNAME'){strKey3=strFirstName;}
 if(strWhich.toUpperCase()=='ORGANIZATION'){strKey3=strOrganization;}
 if(strWhich.toUpperCase()=='COSTCENTER'){strKey3=strCostCenter;}
 if(strWhich.toUpperCase()=='LOCATION'){strKey3=strLocation;}
 if(strWhich.toUpperCase()=='EMPID'){strKey3=strEmpID;}
 if(strWhich.toUpperCase()=='DEPARTMENT'){strKey3=strDept;}
 if(strWhich.toUpperCase()=='TECHNICIAN'){strKey3=strTech;}
 if(strWhich.toUpperCase()=='TICKET'){strKey3=strTicket;}
 if(strWhich.toUpperCase()=='ORGANIZATIONREMOVE'){strKey3=strOrgRemove;}
 if(strWhich.toUpperCase()=='STATE'){strKey3=strState;}
 if(strWhich.toUpperCase()=='STATEREMOVE'){strKey3=strStateRemove;}
 if(strWhich.toUpperCase()=='DEPARTMENTREMOVE'){strKey3=strDeptRemove;}
 if(strWhich.toUpperCase()=='LOCATIONREMOVE'){strKey3=strLocRemove;}
 if(strWhich.toUpperCase()=='CLAIMCHECK'){strKey3=strClaimChk;}
 if(strWhich.toUpperCase()=='CLAIMCHECKEXPIRES'){strKey3=strClaimChkExpire;}
 if(strWhich.toUpperCase()=='ASSETTYPE'){strKey3=strAssetType;}
 if(strWhich.toUpperCase()=='SERIALNUMBER' || strWhich.toUpperCase()=='SN' || strWhich.toUpperCase()=='S/N'){strKey3=strSN;}
 if(strWhich.toUpperCase()=='MFR' || strWhich.toUpperCase()=='MANUFACTURER'){strKey3=strMfr;}
 if(strWhich.toUpperCase()=='PRODDESC' || strWhich.toUpperCase()=='PRODUCTDESCRIPTION'){strKey3=strProdDesc;}
 if(strWhich.toUpperCase()=='MODEL'){strKey3=strModel;}
 return(cmdSaveSetting(strKey1,strKey2,strKey3,strValue));
}

function GetAssetNumber() {
 var strKey1='HKLM';
 var strKey2='SOFTWARE\ESI'
 var strKey3='AssetNumber'
 var strValue='';
 strValue=cmdGetSetting(strKey1,strKey2,strKey3)
 if(strValue=='') {
  strKey1='HKCU'
  strKey2='ESI'
  strKey3='AssetNumber'
  strValue=cmdGetSetting(strKey1,strKey2,strKey3);
 }
 return(strValue);
}

function GetAltirisGUID() {
 var strValue='';
 var strKey1='HKLM';
 var strKey2='SOFTWARE\Altiris\Altiris Agent'
 var strKey3='MachineGUID'
 strValue=cmdGetSetting(strKey1,strKey2,strKey3);
 return(strValue);
}

var TestNothing=',NA,N/A,NOT AVAILABLE,ERROR,';

function GetManufacturer() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.HWManufacturer;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetVersion() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.Version;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetSerialNumber() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.HWSerialNumber;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetModel() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.hwmodel;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetModelNumber() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.HWModelNumber;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetMemory() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.TotalMemory.toString();
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetDriveSpace() {
 var strValue='';
 if(TestActiveXObject()==0) {
  if(typeof(g_obj.TotalDiskSpace)!='unknown') {
   strValue = g_obj.TotalDiskSpace.toString();
   if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
    strValue = '';
   }
  }
 }
 return(strValue);
}

function GetDriveRemaining() {
 var strValue='';
 if(TestActiveXObject()==0) {
  if(typeof(g_obj.TotalDiskRemaining)!='unknown') {
   strValue = g_obj.TotalDiskRemaining.toString();
   if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
    strValue = '';
   }
  }
 }
 return(strValue);
}

function GetClass() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.HWChassisType;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetOS() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.OSTitle;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function GetOSType() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.OSProductType;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function cmdWinDir() {
 var strValue='';
 if(TestActiveXObject()==0) {
  strValue = g_obj.WinDir;
  if(TestNothing.indexOf(','+strValue.toUpperCase()+',')>=0) {
   strValue = '';
  }
 }
 return(strValue);
}

function cmdPingHost(strHostName,nTimeOut) {
 var strValue='';
 var strErrMsg='';
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  strValue = g_obj.PingHost (nErrCode,strErrMsg,strHostName,nTimeOut);
 }
 return(strValue);
}

function cmdReadFile(strFileName) {
 var strValue='';
 var strErrMsg='';
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  strValue = g_obj.ReadFile(nErrCode,strErrMsg,strFileName);
 }
 return(strValue);
}

function cmdWriteFile(strFileName,strText,fAppend,fReadOnly,fHidden) {
 var strErrMsg='';
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  g_obj.WriteFile(nErrCode,strErrMsg,fAppend,fReadOnly,fHidden,strFileName,strText);
 }
 return(nErrCode);
}

function cmdGetAddRemoveProgramsList() {
 var strValue='';
 var strErrMsg='';
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  strValue = g_obj.GetAddRemoveProgramsList (nErrCode,strErrMsg);
 }
 return(escape(strValue));
}

function cmdGetComponentsList() {
 var strValue='';
 var strErrMsg='';
 var nErrCode=0;
 if(TestActiveXObject()==0) {
  strValue = g_obj.GetComponentsList(nErrCode,strErrMsg);
 }
 return(escape(strValue));
}

function CheckAgentInstall(strAI) {

 var nErr=0;
 var strErrMsg='';
 if(TestActiveXObject()==0) {
  var strAN=GetAssetNumber();
  if(strAN=='') {strAN='0';}
  var arF = strAI.split(',');
  
  if(arF.length<6) {return(-1);}

  var strBaseURLQS = arF[0];
  var strInstallerPath = arF[1];
  var strInstallerMD5 = arF[2];
  var strSchedulerPath = arF[3];
  var strSchedPackageID = arF[4];
  var strBaseURL = arF[5];
  var strAgentProxy = arF[6];
  var nLocalErr=0;
  try
  {
   g_obj.CheckAgentInstallation(nErr,strErrMsg,strBaseURL,strAN,strInstallerPath,strInstallerMD5,strSchedulerPath,strSchedPackageID,strAgentProxy);
  }
  catch(err)
  {
   nLocalErr=-1;
  }
  if(nLocalErr==-1) {
   try
   {
    g_obj.CheckAgentInstallation(nErr,strErrMsg,strBaseURL,strAN,strInstallerPath,strInstallerMD5,strSchedulerPath,strSchedPackageID);
   }
   catch(err)
   {
    nErr=err.number;
   }
  }
 }
 return(nErr);
}


function FindInOption (sControlTest,sControlVal,sDelim) {

 var iLen=sControlTest.options.length;
 var i=0;
 var iFnd=false;
 var sTest;
 var iAt;
 for (i=0; i<iLen; i++) {
  sTest = sControlVal.value.toUpperCase()
  if (sDelim.length > 0) {
   iAt = sControlVal.value.indexOf(sDelim)
   if (iAt>=0) {
    sTest = sControlVal.value.toUpperCase().substr(0,iAt)
   }
  }
  if (sControlTest.options[i].value.toUpperCase() == sTest) {
   iFnd=true;
   sControlTest.options[i].selected=true;
   break;
  }
 }
 return(iFnd);
}

function CountChars(elname,sChar) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   for (i=0 ; i<elname.value.length ; i++) {
    if (elname.value.substr(i,1).toUpperCase() == sChar.toUpperCase()) {
     icnt++;
    }
   }
  }
 }
 return(icnt);
}

function CountSelected (sControlTest,iStart) {
 var iCount=0;
 var i=0;
 for (i=iStart; i<sControlTest.options.length; i++) {
  if (sControlTest.options[i].selected) {iCount++;}
 }
 return(iCount);
}

function numinc (tcontrol,ramount) {
 tcontrol.value = formatnumber((removechars(tcontrol.value,",")*(1+(ramount/100))).toString(),0);
 return null;
}

function numdec (tcontrol,ramount) {
 tcontrol.value = formatnumber((removechars(tcontrol.value,",")/(1+(ramount/100))).toString(),0);
 return null;
}

function removechars (tstring,tremove) {
 var s = "";
 for (i=0 ; i<tstring.length ; i++) {
  if (tremove.indexOf(tstring.substr(i,1)) == -1) {
   s = s + tstring.substr(i,1);
  }
 }
 return s;
}

function formatnumber (tstring,ndecimals) {
 var sbeforedecimal = "";
 var safterdecimal = "";
 var idecimal = tstring.indexOf(".");
 var nret = 0;
 var ntest = 0;
 var i=0;
 if (idecimal > -1) {
  sbeforedecimal = tstring.substr(0,idecimal);
  safterdecimal = tstring.substr(idecimal+1);
 }
 else {
  sbeforedecimal = tstring;
 }
 if (ndecimals > 0) {
  if (safterdecimal.length > ndecimals) {
   nret = parseFloat(safterdecimal.substr(ndecimals-1,1));
   ntest = parseFloat(safterdecimal.substr(ndecimals,1));
   if (ntest > 4) nret ++;
   safterdecimal = safterdecimal.substr(0,ndecimals-1)+nret.toString()
  }
  else {
   if (safterdecimal.length < ndecimals) {
    for (i=safterdecimal.length ; i <= ndecimals ; i++) {
     safterdecimal = safterdecimal + '0'
    }
   }
  }
  if (isNaN(parseFloat(sbeforedecimal+'.'+safterdecimal))==true) {
   return ''
  }
  else {
   return numbercommas(sbeforedecimal) + "." + safterdecimal.substr(0,ndecimals);
  }
 }
 else {
  if (parseFloat("0."+safterdecimal) > 0.5) {
   nret = parseFloat(sbeforedecimal);
   nret = nret + 1;
   return numbercommas(nret.toString());
  }
  else {
   return numbercommas(sbeforedecimal);
  }
 }
}

function numbercommas (tstring) {
 var nq = parseInt(tstring.length / 3);
 var nr = (parseFloat(tstring.length / 3) - parseInt(tstring.length / 3)) * 3;
 var s = "";
 var i = 0;
 if (nq > 0) {
  if (nr == 0) {
   i = 3;
  }
  else {
   i = parseInt(nr);
  }
 }
 else {
  i = 3;
 }
 for (j=0 ; j<tstring.length ; j++) {
  s = s + tstring.substr(j,1);
  i--;
  if (i==0) {
   if (j < tstring.length-1) {
    s = s + ",";
   }
   i = 3;
  }
 }
 return s;
}


function testforMax(elname,imax,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.value!=null && elname.value!='') {
     if (elname.value.length > imax)  {
      alert('Please enter at most '+imax.toString()+' character(s) for \"' + slabel + '\".');
      elname.focus();
      return(false);
     }
    }
   }
  }
 }
return(true);
}

function testforMaxDIV(divname,elname,imax,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if (document.getElementByID(elname)==null) {return(true);}
 if (!document.getElementByID(elname).disabled)  {
  if (document.getElementByID(elname).type != 'hidden') {
   if (document.getElementByID(elname).value.length > imax)  {
    alert('Please enter at most '+imax.toString()+' character(s) for \"' + slabel + '\".');
    document.getElementByID(elname).focus();
    return(false);
   }
  }
 }
return(true);
}

function testforMinDIV(divname,elname,imin,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementByID(elname).disabled)  {
  if (document.getElementByID(elname.type) != 'hidden') {
   if (document.getElementByID(elname).value.length > 0)  {
    if (document.getElementByID(elname).value.length < imin)  {
     alert('Please enter at least '+imin.toString()+' character(s) for \"' + slabel + '\".');
     document.getElementByID(elname).focus();
     return(false);
    }
   }
  }
 }
return(true);
}

function testforMin(elname,imin,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.value.length > 0)  {
     if (elname.value.length < imin)  {
      alert('Please enter at least '+imin.toString()+' character(s) for \"' + slabel + '\".');
      elname.focus();
      return(false);
     }
    }
   }
  }
 }
return(true);
}

function testOption(elname,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.selectedIndex < 0)  {
     alert('Please select one of the \"' + slabel + '\" options.');
     elname.focus();
     return (false);
    }

    if (elname.selectedIndex == 0)  {
     if (elname.value.charAt(0)=='-') {
      alert('The first \"' + slabel + '\" option is not a valid selection.  Please choose one of the other options.');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
return(true);
}

function testOptionDIV(divname,elname,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementById(elname).disabled)  {
  if (document.getElementById(elname).type != 'hidden') {
   if (document.getElementById(elname).selectedIndex < 0)  {
    alert('Please select one of the \"' + slabel + '\" options.');
    document.getElementById(elname).focus();
    return (false);
   }

   if (document.getElementById(elname).selectedIndex == 0)  {
    if (document.getElementById(elname).value.charAt(0)=='-') {
     alert('The first \"' + slabel + '\" option is not a valid selection.  Please choose one of the other options.');
     document.getElementById(elname).focus();
     return (false);
    }
   }
  }
 }
return(true);
}


function testOption1(elname,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.selectedIndex < 0)  {
     alert('Please select one of the \"' + slabel + '\" options.');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function setallCaps(elname) {
 if (elname) {
  if (!elname.disabled)  {
   elname.value=elname.value.toUpperCase();  }
 }
return(true);
}

function testforDate(elname,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (!isValidDate(elname.value))  {
     alert('Please enter a valid date for \"' + slabel + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforTime(elname,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (!isValidTime(elname.value))  {
     alert('Please enter a valid time for \"' + slabel + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforMinValue(elname,imin,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.value.length > 0)  {
     if (!elname.NaN) {
      if (elname.value < imin)  {
       alert('Please enter a number no smaller than '+imin.toString()+' for \"' + slabel + '\".');
       elname.focus();
       return (false);
      }
     }
    }
   }
  }
 }
return(true);
}

function testforMinValueDIV(divname,elname,imin,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementById(elname).disabled)  {
  if (document.getElementById(elname).type != 'hidden') {
   if (document.getElementById(elname).value.length > 0)  {
    if (!document.getElementById(elname).NaN) {
     if (document.getElementById(elname).value < imin)  {
      alert('Please enter a number no smaller than '+imin.toString()+' for \"' + slabel + '\".');
      document.getElementById(elname).focus();
      return (false);
     }
    }
   }
  }
 }
return(true);
}

function testforMaxValueDIV(divname,elname,imax,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementById(elname).disabled)  {
  if (document.getElementById(elname).type != 'hidden') {
   if (document.getElementById(elname).value.length > 0)  {
    if (!document.getElementById(elname).NaN) {
     if (document.getElementById(elname).value > imax)  {
      alert('Please enter a number no greater than '+imax.toString()+' for \"' + slabel + '\".');
      document.getElementById(elname).focus();
      return (false);
     }
    }
   }
  }
 }
return(true);
}

function testforMaxValue(elname,imax,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.value.length > 0)  {
     if (!elname.NaN) {
      if (elname.value > imax)  {
       alert('Please enter a number no greater than '+imax.toString()+' for \"' + slabel + '\".');
       elname.focus();
       return (false);
      }
     }
    }
   }
  }
 }
return(true);
}

function testforRequired(elname,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (elname.value.length == 0)  {
     alert('You must enter something for \"' + slabel + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforRequiredDIV(divname,elname,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementById(elname).disabled)  {
  if (document.getElementById(elname).type != 'hidden') {
   if (document.getElementById(elname).value.length == 0)  {
    alert('You must enter something for \"' + slabel + '\".');
    document.getElementById(elname).focus();
    return (false);
   }
  }
 }
return(true);
}


function testforMustHave(elname,stest,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    var ibad=0;
    for (i=0 ; i<stest.length ; i++) {
     if (elname.value.toUpperCase().indexOf(stest.substr(i,1).toUpperCase()) == -1) {
      ibad=-1;
     }
    }
    if (ibad==-1) {
     alert('The answer for \"' + slabel + '\" must contain at least one of each of the following character(s): \"' + stest + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforMustHaveDIV(divname,elname,stest,slabel) {
 if(divname==undefined){return(true);}
 if(divname==null){return(true);}
 if(divname!='none') {
  if(document.getElementById(divname)==null) {return(true);}
  if(document.getElementById(divname).style.display == "none") {return(true);}
 }
 if(document.getElementById(elname)==null) {return(true);}
 if (!document.getElementById(elname).disabled)  {
  if (document.getElementById(elname).type != 'hidden') {
   var ibad=0;
   for (i=0 ; i<stest.length ; i++) {
    if (document.getElementById(elname).value.toUpperCase().indexOf(stest.substr(i,1).toUpperCase()) == -1) {
     ibad=-1;
    }
   }
   if (ibad==-1) {
    alert('The answer for \"' + slabel + '\" must contain at least one of each of the following character(s): \"' + stest + '\".');
    document.getElementById(elname).focus();
    return (false);
   }
  }
 }
return(true);
}


function testCountAlphas(elname,imin,slabel) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (imin > 0) {
     for (i=0 ; i<elname.value.length ; i++) {
      if (elname.value.substr(i,1).toUpperCase() >= 'A' && elname.value.substr(i,1).toUpperCase() <= 'Z') {
       icnt++;
      }
     }
     if (icnt < imin) {
      alert('The answer for \"' + slabel + '\" must contain at least ' + imin.toString() + ' alpha character(s).');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
 return(true);
}

function testCountUpper(elname,imin,slabel) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (imin > 0) {
     for (i=0 ; i<elname.value.length ; i++) {
      if (elname.value.substr(i,1) >= 'A' && elname.value.substr(i,1) <= 'Z') {
       icnt++;
      }
     }
     if (icnt < imin) {
      alert('The answer for \"' + slabel + '\" must contain at least ' + imin.toString() + ' upper case character(s).');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
 return(true);
}

function testCountLower(elname,imin,slabel) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (imin > 0) {
     for (i=0 ; i<elname.value.length ; i++) {
      if (elname.value.substr(i,1) >= 'a' && elname.value.substr(i,1) <= 'z') {
       icnt++;
      }
     }
     if (icnt < imin) {
      alert('The answer for \"' + slabel + '\" must contain at least ' + imin.toString() + ' lower case character(s).');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
 return(true);
}

function testCountSpecials(elname,imin,slabel) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (imin > 0) {
     for (i=0 ; i<elname.value.length ; i++) {
      if ((elname.value.substr(i,1) >= '!' && elname.value.substr(i,1) <= '/') || (elname.value.substr(i,1) >= ':' && elname.value.substr(i,1) <= '@')) {
       icnt++;
      }
     }
     if (icnt < imin) {
      alert('The answer for \"' + slabel + '\" must contain at least ' + imin.toString() + ' special character(s). Ex: @$%*');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
 return(true);
}

function testCannotEqual(elname,elname1,slabel,slabel1) {
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (elname1) {
     if (!elname1.disabled) {
      if (elname.value.toUpperCase()==elname1.value.toUpperCase()) {
       alert('The answer for \"' + slabel + '\" cannot be the same as the answer for \"' + slabel1 + '\".');
       elname.focus();
       return (false);
      }
     }
    }
   }
  }
 }
 return(true);
}

function testMustEqual(elname,elname1,slabel,slabel1) {
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (elname1) {
     if (!elname1.disabled) {
      if (elname.value.toUpperCase()!=elname1.value.toUpperCase()) {
       alert('The answer for \"' + slabel + '\" must be the same as the answer for \"' + slabel1 + '\".');
       elname.focus();
       return (false);
      }
     }
    }
   }
  }
 }
 return(true);
}

function testCannotEqual2(elname,svalue,slabel,slabel1) {
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (elname.value.toUpperCase()==svalue.toUpperCase()) {
     alert('The answer for \"' + slabel + '\" cannot be the same as the answer for \"' + slabel1 + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
 return(true);
}

function testMustEqual2(elname,svalue,slabel,slabel1) {
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (elname.value.toUpperCase()!=svalue.toUpperCase()) {
     alert('The answer for \"' + slabel + '\" must be the same as the answer for \"' + slabel1 + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
 return(true);
}


function testCountNumerics(elname,imin,slabel) {
 var icnt = 0;
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    if (imin > 0) {
     for (i=0 ; i<elname.value.length ; i++) {
      if (!isNaN(elname.value.substr(i,1))) {
       icnt++;
      }
     }
     if (icnt < imin) {
      alert('The answer for \"' + slabel + '\" must contain at least ' + imin.toString() + ' numeric character(s).');
      elname.focus();
      return (false);
     }
    }
   }
  }
 }
 return(true);
}

function ReturnField(svalue,iwhich,sdelim) {
 if(svalue==null) {return;}
 if(svalue==undefined) {return;}
 var sret = "";
 if (svalue.length>0) {
  s = svalue.split(sdelim);
  if (iwhich <= s.length) sret=s[iwhich];
 }
 return(sret);
}

function ExtractFromString(sString,sMatch,sDelim) {
 var s = "";
 var iAt=-1;
 iAt=(sDelim+sString.toUpperCase()).indexOf(sDelim+sMatch.toUpperCase()+'=');
 if(iAt>-1) {
  s=sString.substr(iAt+1);
  s=ReturnField(s,0,sDelim);
  s=ReturnField(s,1,"=");
 }
 return(s);
}


function AddToString(sStr,sValue,sDelim) {
 var sret = "";
 if (sStr.length == 0) {
  sret = sValue;
 } else {
  sret = sStr + sDelim + sValue;
 }
 return(sret);
}

function AddToStringCheck(sStr,sValue,sDelim) {
 var sret = "";
 if (sStr.length==0) {
  sret = sValue;
 } else {
  if (sStr.toUpperCase().indexOf(sValue.toUpperCase())==-1) {
   sret = sStr + sDelim + sValue;
  } else {
   sret = sStr;
  }
 }
 return(sret);
}

function RemoveFromString(sStr,sValue,sDelim) {
 var sret = "";
 if (sStr.length==0) {return(sret);}
 if (sStr.toUpperCase().indexOf(sValue.toUpperCase())==-1) {return(sret);}
 var iAt=-1;
 iAt=sStr.toUpperCase().indexOf(sValue.toUpperCase()+sDelim);
 if (iAt>-1) {sret=sStr.substr(0,iAt)+sStr.substr(iAt+sValue.length+1);return(sret);}
 iAt=sStr.toUpperCase().indexOf(sValue.toUpperCase());
 if (iAt>-1) {if(sStr.length==sValue.length){sret="";return(sret);}else{sret=sStr.substr(0,iAt-1);return(sret);}}
 return(sret);
}

function testforCannotHave(elname,stest,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    var ibad=0;
    for (i=0 ; i<stest.length ; i++) {
     if (elname.value.toUpperCase().indexOf(stest.substr(i,1).toUpperCase()) != -1) {
      ibad=-1;
     }
    }
    if (ibad==-1) {
     alert('The answer for \"' + slabel + '\" cannot contain any of the following character(s): \"' + stest + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforOnlyHave(elname,stest,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    var ibad=0;
    for (i=0 ; i<elname.value.length ; i++) {
     if (stest.toUpperCase().indexOf(elname.value.toUpperCase().substr(i,1)) == -1) {
      ibad=-1;
     }
    }
    if (ibad==-1) {
     alert('The answer for \"' + slabel + '\" is restricted to the following character(s): \"' + stest + '\".');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testforRegExp(elname,stest,slabel) {
 if (elname) {
  if (!elname.disabled)  {
   if (elname.type != 'hidden') {
    if (!stest.test(elname.value)) {
     alert('The answer for \"' + slabel + '\" is not in the proper format.');
     elname.focus();
     return (false);
    }
   }
  }
 }
return(true);
}

function testRecordBox(elname,slabel,iminlen,imaxlen,iminval,imaxval,scharsmust,scharscannot,scharsonly) {
 if (elname) {
  if (!elname.disabled) {
   if (elname.type != 'hidden') {
    var iat=0;
    var snext=' ';
    var srem=elname.value;
    var ibad=0;
    do {
     iat=srem.indexOf('\n');
     if(iat>=0) {
      snext=srem.substr(0,iat).replace(/\x0a/g,'');
      srem=srem.substr(iat+1);
     } else {
      snext=srem.replace(/\x0a/g,'');
      srem='';
     }
     snext=snext.replace(/\x0d/g,'');
     if(snext.length>0) {
      if(iminlen>0) {
       if (snext.length < iminlen)  {
        alert('All entries must have at least '+iminlen.toString()+' character(s) for \"' + slabel + '\".');
        elname.focus();
        return(false);
       }
      }
      if(imaxlen>0) {
       if (snext.length > imaxlen)  {
        alert('All entries must have at most '+imaxlen.toString()+' character(s) for \"' + slabel + '\". Current longest: '+snext.length.toString());
        elname.focus();
        return(false);
       }
      }
      if(iminval<imaxval) {
       if (!snext.NaN) {
        if (parseFloat(snext) < iminval)  {
         alert('All enties must be a number no smaller than '+iminval.toString()+' for \"' + slabel + '\".');
         elname.focus();
         return (false);
        }
        if (parseFloat(snext) > imaxval)  {
         alert('All enties must be a number no greater than '+imaxval.toString()+' for \"' + slabel + '\".');
         elname.focus();
         return (false);
        }
       } else {
        alert('All enties must be a number for \"' + slabel + '\".');
        elname.focus();
        return (false);
       }
      }
      if (scharsmust.length>0) {
       ibad=0;
       for (i=0 ; i<scharsmust.length ; i++) {
        if (snext.toUpperCase().indexOf(scharsmust.substr(i,1).toUpperCase()) == -1) {
         ibad=-1;
        }
       }
       if (ibad==-1) {
        alert('All entries for \"' + slabel + '\" must contain at least one of each of the following character(s): \"' + scharsmust + '\".');
        elname.focus();
        return (false);
       }
      }
      if (scharsonly.length>0) {
       ibad=0;
       for (i=0 ; i<snext.length ; i++) {
        if (scharsonly.toUpperCase().indexOf(snext.toUpperCase().substr(i,1)) == -1) {
         ibad=-1;
        }
       }
       if (ibad==-1) {
        alert('All entries for \"' + slabel + '\" are restricted to the following character(s): \"' + scharsonly + '\".');
        elname.focus();
        return (false);
       }
      }
      if (scharscannot.length>0) {
       ibad=0;
       for (i=0 ; i<scharscannot.length ; i++) {
        if (snext.toUpperCase().indexOf(scharscannot.substr(i,1).toUpperCase()) != -1) {
         ibad=-1;
        }
       }
       if (ibad==-1) {
        alert('No entries for \"' + slabel + '\" may contain any of the following character(s): \"' + scharscannot + '\".');
        elname.focus();
        return (false);
       }
      }
     }
    } while (snext.length > 0);
   }
  }
 }
}



