function sf() { document.form1.submit() }

function write(val,ctlx) {
  ctl = eval("document.form1." + ctlx);
  ctl.value = val }

function copy(val,ctlx,x) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  ctl.value = val }

function writeback(val,ctlx) {
  ctl = eval("opener.document.form1." + ctlx);
  ctl.value = val;
  window.close(); }

function chk(ctlx,x) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  switch(ctl.type) {
    case 'checkbox': if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = false }; break; 
    case 'radio':    if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = true }; break; } }

function chkall(ctlx,x) {
  ctl = eval("document.form1." + ctlx);
  if ( x == 1) { bool = true } else { bool = false }
  if ( ctl.length > 1 ) { for (i = 0; i < ctl.length; i++) { ctl[i].checked = bool } }
  else  { ctl.checked = bool } }

function append(ctlx,ctly) {
  ctl = eval("document.form1." + ctlx);
  var incl = ''; var excl = ''; var x = 0;
  var a = '';  var b = '';  var c = ''

  if ( ctl.length > 1 ) {
	for (i = 0; i < ctl.length; i++) {
	  if (ctl[i].checked == true) { incl = incl + ctl[i].value + ", " } 
	  else { excl = excl + ctl[i].value + ", " } } }
  else {  if (ctl.checked == true) { incl = ctl.value + ", " } 
	  else { excl = ctl.value + ", " } }

  x = parseInt(incl.length) - 2;
  if ( x >= 0 ) { incl = incl.substring(0, x ) }

  ctl2 = eval("document.form1." + ctly); val2 = ctl2.value;

  if ( val2 != '' && incl != '' ) { val2 = val2 + ", " + incl } 
  else { if ( incl != '' ) { val2 = incl } }

  ary = val2.split(", ");
  for (i = 0; i < ary.length; i++) { a = ary[i] + ", ";
    if ( excl.indexOf(a) == -1 && b.indexOf(a) == -1 ) { b = b + a} }

  x = parseInt(b.length) - 2;
  if ( x >= 0 ) { b = b.substring(0, x ) }

  ctl2.value = b; }

function dedupe(val) {
  var count = 0;
  var mainlist = val
  var listvalues = new Array();
  var newlist = new Array();
  var a = '';
	
  listvalues = mainlist.split(", ");
	
  var hash = new Object();
	
  for (var i=0; i<listvalues.length; i++)	{
    if (hash[listvalues[i].toLowerCase()] != 1) {
	newlist = newlist.concat(listvalues[i]);
	hash[listvalues[i].toLowerCase()] = 1 }
    else { count++; } }

  for (i = 0; i < newlist.length; i++) { 
	if ( newlist[i] != '' ) { a = a + newlist[i] + ", " } }

  x = parseInt(a.length) - 2
  if ( x >= 0 ) { a = a.substring(0, x ) }

  return a; }



// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) { 
  var a = [], i, l = this.length;
  for( i=0; i<l; i++ ) {
    if( a.indexOf(this[i],0,b) < 0 ) { a.push( this[i] ); } } return a;}

function xreplace(checkMe,toberep,repwith){
  var temp = checkMe;
  var i = temp.indexOf(toberep);
  while(i > -1) {
    temp = temp.replace(toberep, repwith);
    i = temp.indexOf(toberep, i + repwith.length + 1); }
  return temp; }



function chkvar(ctlx,x,ctly) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  switch(ctl.type) {
    case 'checkbox': if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = false }; break; 
    case 'radio':    if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = true }; break; }
  
  ctl2 = eval("document.form1." + ctly);
  val1 = ctl.value;  val2 = ctl2.value; a = '';

  if (val2 == ''  && ctl.checked == true) { ctl2.value = val1 }
  else {
	ary = val2.split(", ");
	for (i = 0; i < ary.length; i++)
	    if ( ary[i] != val1 ) { a = a + ary[i] + ", " }

	if (ctl.checked == true)  { a = a + val1 + ", " }
	x = parseInt(a.length);
	if ( x > 0 ) { x = x - 2; a = a.substring(0,x) }
	ctl2.value = a; } }


function incr(ctlx,x,y) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  a = ctl.value
  if ( a == '') { z = parseInt(y) } else { z = parseInt(a) + parseInt(y) } 
  ctl.value = z.toString() }


function mv(src,dest) {
  ctl = eval("document.form1." + dest)
  ctl.value = eval("document.form1." + src + ".value") }

function sel(src) {
  ctl=eval("document.form1." + src);
  switch(ctl.type) {
    case 'checkbox':
	if (ctl.checked == false) { ctl.checked = true}
		else { ctl.checked = false }; break; 
    case 'radio':
	if (ctl.checked == false) { ctl.checked = true}
		else { ctl.checked = true }; break; } }

function pop(pop,nam,w,h,l,t) {
  hwnd = window.open ('go.asp?pop=' + pop,nam,
  'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=yes,status=no,resizable=1'); 
  void('') }

function convnbr(src,fmt) {
  src = eval("document.form1." + src)
  src.value = fmtnbr(src.value,fmt) }

function fmtnbr(num,fmt) {
  num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = '0'
  switch(fmt) {
    case '0': cents = ''
	      num = Math.floor((num*1+0.5)).toString(); break
    case '1': cents = '.' + Math.floor((num*10+0.5)%10)
	      num = Math.floor((num*10+0.5)/10).toString(); break
    case '2': cents = Math.floor((num*100+0.5)%100)
	      if(cents < 10) {cents = ".0" + cents} else {cents = "." + cents}
	      num = Math.floor((num*100+0.5)/100).toString(); break }
  num = num+cents; return num.toString() }

function fmtdate(src,fmt) {
  ctl = eval("document.form1." + src);
  num = ctl.value;
  var d = num;
  d = new Date(d);
  d = new Date(num);
//  if (!isNaN(d)) return;
  newnum = '';
  now = new Date();
  dy = now.getDate();
  mo = now.getMonth() + 1;
  yr = now.getYear();
  for (var i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
      if (num.substring(i) < ':') {newnum = newnum + num.substring(i,i + 1) } }

    x = parseInt(newnum.length);

    switch(x) {
	case 0: ctl.value = ''; return true;
	case 1: dy = parseInt(newnum); break; 
	case 2: dy = parseInt(newnum.substring(1,2),10);
		mo = parseInt(newnum.substring(0,1),10); break;
	case 3: dy = parseInt(newnum.substring(1,3),10);
		mo = parseInt(newnum.substring(0,1),10);
		if (dy > 31) {dy = parseInt(newnum.substring(2,3),10);
			mo = parseInt(newnum.substring(0,2),10);
			if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
				mo = parseInt(newnum.substring(0,1),10);
				yr = parseInt(newnum.substring(2,3),10); } }; break;
	case 4: dy = parseInt(newnum.substring(2,4),10);
		mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
				mo = parseInt(newnum.substring(0,1),10);
				yr = parseInt(newnum.substring(2,4),10); }; break;
	case 5: dy = parseInt(newnum.substring(2,3),10);
		mo = parseInt(newnum.substring(0,2),10);
		yr = parseInt(newnum.substring(3,5),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,3),10);
			mo = parseInt(newnum.substring(0,1),10) }; break;
	case 6: mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
			mo = parseInt(newnum.substring(0,1),10);
			yr = parseInt(newnum.substring(2,6),10); }
		else {dy = parseInt(newnum.substring(2,4),10);
			yr = parseInt(newnum.substring(4,6),10); }; break;
	case 7: dy = parseInt(newnum.substring(1,3),10);
		mo = parseInt(newnum.substring(0,1),10);
		yr = parseInt(newnum.substring(3,7),10);
		if (dy > 31) {mo = parseInt(newnum.substring(0,2),10);
			if (mo > 12) {dy = parseInt(newnum.substring(1,3),10);
				mo = parseInt(newnum.substring(0,1),10); }
			else  {dy = parseInt(newnum.substring(2,3),10);
				mo = parseInt(newnum.substring(0,2),10); } }; break;
	default: mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {mo = parseInt(newnum.substring(0,1),10);
			dy = parseInt(newnum.substring(1,3),10);
			if (dy > 31) {dy = parseInt(newnum.substring(1,2),10);
				yr = parseInt(newnum.substring(2,6),10); }
			else {	yr = parseInt(newnum.substring(3,7),10); } }
		else {dy = parseInt(newnum.substring(2,4),10);
			if (dy > 31) {dy = parseInt(newnum.substring(2,3),10);
				yr = parseInt(newnum.substring(3,7),10); }
			else {yr = parseInt(newnum.substring(4,8),10);} }; break; }

  if (yr < 50) { yr = yr + 2000 }; else if (yr < 100) { yr = yr + 1900 };
  while ( mo > 12) { mo = parseInt(mo); mo = mo - 12; yr = yr + 1 }
  for (var i = 0; i < 3; i++) { 
	var days = daysinmonth(mo,yr)
	if (dy > days) {dy = dy - days; mo = mo + 1} 
	if (mo > 12) {mo = 1; yr = yr + 1} }

  if (mo<0) { mo=1 }
  if (mo==2) { var isleap = (yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0));
	if (dy>29 || (dy==29 && !isleap)) { dy = dy - 28; mo = mo + 1 } }

  if ((mo==1 || mo==3 || mo==5 || mo==7 || mo==8 || mo==10 || mo==12) && dy>31) {
	while (dy>31) { dy = dy - 31; mo = mo + 1 } }
  if ((mo==4 || mo==6 || mo==9 || mo==11) && dy>30) {
	while (dy>30) { dy = dy - 30; mo = mo + 1 } }


  m1 = mo.toString(); d1 = dy.toString(); y1 = yr.toString()

  switch(fmt) {
	case '2': if (m1.length == 1) {m1 = '0' + m1 };
		  if (d1.length == 1) {d1 = '0' + d1 };
		  ctl.value = m1 + '/' + d1 + '/' + right(y1,2); break;
	case '3': ctl.value = m1 + '/' + d1 + '/' + y1; break;
	case '4': if (m1.length == 1) {m1 = '0' + m1 };
		  if (d1.length == 1) {d1 = '0' + d1 };
		  ctl.value = m1 + '/' + d1 + '/' + y1; break;
	default:  ctl.value = m1 + '/' + d1 + '/' + right(y1,2); break; } }

function right(str, n) {
	if (n <= 0) { return ""; }
	else if (n > String(str).length) { return str; }
	else { var iLen = String(str).length;
	return String(str).substring(iLen, iLen - n); } }

function daysinmonth(mo,yr)  {
  var days;
  if (mo==1 || mo==3 || mo==5 || mo==7 || mo==8 || mo==10 || mo==12)  days=31;
  else if (mo==4 || mo==6 || mo==9 || mo==11) days=30;
  else if (mo==2)  {if (isleapyr(yr)) {days=29;} else {days=28;} }
  return (days); }

function isleapyr (yr) {
  if (((yr % 4)==0) && ((yr % 100)!=0) || ((yr % 400)==0)) { return (true); } 
  else { return (false); } }

function fmtime(src) {
  ctl = eval("document.form1." + src)
  num = ctl.value; newnum = ''; hr = 0; min = 0
  for (i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
	if (num.substring(i) < ':') {newnum = newnum + num.substring( i , i + 1) } }
  if (newnum.length < 3) {
	for (var i = 0; i < 3-num.length; i++) { newnum = '0' + newnum } }
  if (newnum.length > 3) { hr = newnum.substring(0,2); min = newnum.substring(2,4) }
	else  { hr = newnum.substring(0,1); min = newnum.substring(1,3); }
  if (min > 59) { hr = parseInt(hr); hr = hr + 1; min = parseInt(min); min = min - 60 }
  while ( hr > 23) { hr = parseInt(hr); hr = hr - 24; }
  min = min.toString();
  if (min.length < 2) { min = '0' + min }
  hr = hr.toString();
  if (hr.length > 1 & hr.substring(0,1) == '0') { hr = hr.substring(1,2) }
  ctl.value = hr + ':' + min }

function timediff(index,int) {
  frdt = eval("document.form1.fr_dt" + index);
  frtm = eval("document.form1.fr_tm" + index);
  todt = eval("document.form1.to_dt" + index);
  totm = eval("document.form1.to_tm" + index);
  ctl = eval("document.form1.hours" + index);
  date1 = new Date(); date2 = new Date(); diff = new Date();

  if (frdt.value > '' && frtm.value > '' && todt.value > '' && totm.value > '') {
    a = new Date(frdt.value + " " + frtm.value);  date1.setTime(a.getTime());
    b = new Date(todt.value + " " + totm.value);  date2.setTime(b.getTime());
    x = 0;
    diff.setTime(Math.floor(date2.getTime() - date1.getTime()));
    x = Math.floor(diff.getTime() / (1000 * 60)); 
    x = parseFloat(x / 60);
    a = x.toString(); ary = a.split(".")
    if (ary.length > 1) { a = ary[1] } else { a = '0' }
    while ( a.length < 2) { a = a + '0' }
    ctl.value = ary[0] + '.' + a.substring(0,2) } }

function calchrs(fr,to,dest) {
  fr = eval("document.form1." + fr)
  to = eval("document.form1." + to)
  dest = eval("document.form1." + dest)
  y = timeinhrs(fr.value);
  z = timeinhrs(to.value);
  y = z - y
  if ( y < 0 ) { y = 0 }
  dest.value = fmtnbr(y,'2') }

function timeinhrs(num) {
  newnum = ''; hr = 0; min = 0;
  for (i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
      if (num.substring(i) < ':') {newnum = newnum + num.substring(i,i + 1) } }
  if (newnum.length < 3) {
    for (var i = 0; i < 3-num.length; i++) { newnum = '0' + newnum } }
  if (newnum.length > 3) { hr = newnum.substring(0,2); min = newnum.substring(2,4) }
    else  { hr = newnum.substring(0,1); min = newnum.substring(1,3) }
  if (min > 59) { hr = parseInt(hr); hr = hr + 1; min = parseInt(min); min = min - 60 }
  while ( hr > 23) { hr = parseInt(hr); hr = hr - 24 }
  min = min / 60
  hr = parseInt(hr); hr = hr + min
  return hr.toString() }

function chkhrs(fr,hrs,to) {
  fr = eval("document.form1." + fr)
  val = eval("document.form1." + hrs + ".value")
  to = eval("document.form1." + to)
  if (fr.value == '') { return }
  if (document.form1.fr.value > '') { addtime('fr',document.form1.hr.value,'to') }
  document.form1.hr.value = fmtnbr(document.form1.hr.value,'2') }

function addtime(fr,dest,hr) {
  fr = eval("document.form1." + fr)
  to = eval("document.form1." + dest)
  x = eval("document.form1." + hr + ".value")
  x = parseFloat(x)
  y = timeinhrs(ctl.value)
  z = parseFloat(x) + parseFloat(y)
  a = z.toString(); ary = a.split(".")
  if (ary.length > 1) { a = "." + ary[1]; a = parseInt(parseFloat(a) * 60 + 0.5 ) } else { a=''}
  a = a.toString()
  while ( a.length < 2) { a = '0' + a }
  to.value = ary[0] + a
  fmtime(dest) }


function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeval = "" + ((hours >24) ? hours -24 :hours)
if (timeval == "0") timeval = 12;
timeval += ((minutes < 10) ? ":0" : ":") + minutes
timeval += ((seconds < 10) ? ":0" : ":") + seconds
document.form1.timer.value = timeval;
timerID = setTimeout("showtime()",1000);
timerRunning = true; }

function timenow(src) {
  src = eval("document.form1." + src)
  now = new Date();
  hours = now.getHours();
  minutes = now.getMinutes();
  timeval = "" + ((hours >24) ? hours -24 :hours)
  if (timeval == "0") timeval = 12;
  timeval += ((minutes < 10) ? ":0" : ":") + minutes
  src.value = timeval }

function chktab(el) { if ((document.all) && (9==event.keyCode) && (event.ctrlKey)) {
    el.selection=document.selection.createRange(); 
    setTimeout("proctab('" + el.id + "')",0) } }
