function ckDate(dt,nm){
  var reDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
  if(!dt.value.match(reDate)){
    if(nm.length>0){
	  alert(nm + " field must be in m/d/yyyy numeric format!\nPlease correct and resubmit.");
	  dt.focus();
	}
	return 0;
  }
  else{
    var d;
    var ttmp = dt.value.split("/");
    switch(Number(ttmp[0])){
      case 2:   if(Number(ttmp[2])%4==0) d=29;
	            else d=28;
                break;
      case 4:   
      case 6:   
      case 9:   
      case 11:  d=30;
                break;
      case  1:  
      case  3:  
      case  5:  
      case  7:  
      case  8:  
      case 10: 
      case 12: d=31;
               break;
      default: d=-1;
               break;
    }
    var ck = 0;
    if(Number(ttmp[0])<1||Number(ttmp[0])>12) ck++;
    if(Number(ttmp[1])<1||Number(ttmp[1])>d) ck++;
    if(Number(ttmp[2])<1895||Number(ttmp[2])>2099)ck++;
    if(ck){
      if(nm.length>0){
	    alert(nm + " field is not a valid date!\nPlease correct and resubmit!");
        dt.focus();
	  }
      return 0;
    }
  }
  return 1;
}			 


function ckDateTime(dt,nm){
  var dtm = dt.value.split(" ");
  var reDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
  var reTime = /^[1-9]:[0-5]\d{1}[ap]m$/i;
  var reTime2 = /^1[0-2]:[0-5]\d{1}[ap]m$/i;
  
  if(!dtm[0].match(reDate)){
    alert(nm + " field must be in mm/dd/yyyy 12:00AM datetime format!\nPlease correct and resubmit.");
	dt.focus();
	return 0;
  }
  else{
    var d;
    var ttmp = dtm[0].split("/");
    switch(Number(ttmp[0])){
      case 2:   if(Number(ttmp[2])%4==0) d=29;
	            else d=28;
                break;
      case 4:   
      case 6:   
      case 9:   
      case 11:  d=30;
                break;
      case  1:  
      case  3:  
      case  5:  
      case  7:  
      case  8:  
      case 10: 
      case 12: d=31;
               break;
      default: d=-1;
               break;
    }
    var ck = 0;
    if(Number(ttmp[0])<1||Number(ttmp[0])>12) ck++;
    if(Number(ttmp[1])<1||Number(ttmp[1])>d) ck++;
    if(Number(ttmp[2])<1895||Number(ttmp[2])>2099)ck++;
    if(ck){
      alert(nm + " field is not a valid date!\nPlease correct and resubmit!");
      dt.focus();
      return 0;
    }
  }
  if(dtm[1]!=null){
    if(!dtm[1].match(reTime)&&!dtm[1].match(reTime2)){
      alert(nm + " field must be in mm/dd/yyyy 12:00AM datetime format!\nPlease correct and resubmit.");
	  dt.focus();
	  return 0;
	}
  }
  else{
      alert(nm + " field must be in mm/dd/yyyy 12:00AM datetime format!\nPlease correct and resubmit.");
	  dt.focus();
	  return 0;  
  }
  return 1;
}			 

  //required buildDate() exists in calling page
  function grabDate(s,t){
    var win;
	var reDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if(t.value.match(reDate)){
	  var tDate = t.value.split("/");
	  win = window.open("/common/win_GetDate.cfm?type=" + s + "&month=" + tDate[0] + "&year=" + tDate[2],"datewin","width=235,height=225");	  
	}
	else{
	  win = window.open("/Common/win_GetDate.cfm?type=" + s,"datewin","width=235,height=225");
	}
	win.focus();
  }

  function ckLen(t,len){
    if(t.value.length>=len){
	  alert("Character limit of " + len + " reached!");
	  t.value = t.value.substring(0,len);
	}
  }

function DecFormat(num,dec,pre){
  num *= Math.pow(10,dec);
  num = (Math.round(num)/Math.pow(10,dec))+ "" ;
  if(num.indexOf(".") == -1 && dec>0)
    num += "." ;
  while(num.length - num.indexOf(".") - 1 < dec)
    num += "0" ;
  return pre + num;
}

function DecFormatChop(num,dec,pre){
  num *= Math.pow(10,dec);
  num = (Math.floor(num)/Math.pow(10,dec))+ "" ;
  if(num.indexOf(".") == -1 && dec>0)
    num += "." ;
  while(num.length - num.indexOf(".") - 1 < dec)
    num += "0" ;
  return pre + num;
}
  
//setCityState(city,state,type) will need to be defined in calling window
function getCityState(t,z){
  var win = window.open("/Common/ZipFinder.cfm?zip=" + t + "&type=" + z,"zipwin","scrollbars,width=20,height=20");
  win.blur();
}
  
  
//setZip(value,type) will need to be defined in calling window
function getZip(t,c,z){
  if(t!=""&&c!=""){
    var win = window.open("/Common/CityFinder.cfm?city=" + escape(c) + "&State=" + t + "&type=" + z,"zipwin","scrollbars,resizable,width=120,height=30");
    win.moveTo(100,100)
	win.focus();
  }
}
  
function maskData(txt,type){
  var key = event.keyCode;
  //Allow all backspaces
  if (key == 8) return;
  if(key < 48 || key > 57){
	event.returnValue = false;
	return;
  }
  switch(type){	
	//phone
	case "phone":
	  if(txt.value.length >= 12){
        if(document.selection.type == "text"){
		  document.selection.clear();
		  return;
	    }
	    else{
		  event.returnValue = false;
		  return;
	    }
	  }
	  if(txt.value.length == 2 || txt.value.length == 6){
		var str2 = String.fromCharCode(key);
		txt.value = txt.value  + str2+ "-";
		event.returnValue = false;
		return;
	  }
	  if(txt.value.length == 3 || txt.value.length == 7){
		var str2 = String.fromCharCode(key);
		txt.value = txt.value + "-" + str2;
		event.returnValue = false;
		return;
	  }
	  break;
	//zip codes
	case "zip":
	  /*
	  if(txt.value.length >= 10){
	    if(document.selection.type == "text"){
		  document.selection.clear();
		  return;
		}
		else{
		  event.returnValue = false;
		  return;
		}
      }
	  
	  if(txt.value.length == 4){	
	    var str2 = String.fromCharCode(key);
		txt.value = txt.value  + str2+ "-";
		event.returnValue = false;
		return;
	  }
	  if(txt.value.length == 5){
		var str2 = String.fromCharCode(key);
		txt.value = txt.value + "-" + str2;
		event.returnValue = false;
		return;
	  }
	  */
	  break;
	case "ssn":
	  if(txt.value.length >= 11){
	    if(document.selection.type == "text"){
		  document.selection.clear();
		  return;
		}
		else{
		  event.returnValue = false;
		  return;
		}
	  }
	  if(txt.value.length == 2 || txt.value.length == 5){	
		var str2 = String.fromCharCode(key);
		txt.value = txt.value  + str2+ "-";
		event.returnValue = false;
		return;
	  }
	  if(txt.value.length == 3 || txt.value.length == 6){
		var str2 = String.fromCharCode(key);
		txt.value = txt.value + "-" + str2;
		event.returnValue = false;
		return;
	  }
      break;	
	default: break;
  }
}

	
  function setBGcolor(t,c){
    t.style.backgroundColor=c;
  }	
	

  function hx(s,pfx){
    var str = "";
	var tmp;
	for(var i=0;i<s.length;i++){
	  tmp = s.substring(i,i+1);
	  str += pfx + parseInt(tmp.charCodeAt(0)).toString(16);
	}
    return str;
  }
  
  function isNum(n){
    if(isNaN(Number(n))) return 0;
	else return Number(n);
  }

  function daysInMonth(dt){
    var reDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
    if(!dt.match(reDate)){
	  return 0;
    }
    else{
      var d;
      var ttmp = dt.split("/");
      switch(Number(ttmp[0])){
        case 2:   
		  if(Number(ttmp[2])%4==0) d=29;
	      else d=28;
          break;
        case 4:   
        case 6:   
        case 9:   
        case 11:  
		  d=30;
          break;
        case  1:  
        case  3:  
        case  5:  
        case  7:  
        case  8:  
        case 10: 
        case 12: 
		  d=31;
          break;
        default: 
		  d=-1;
          break;
      }
    }
    return d;
  }	

  function isTime(timeStr) {
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var matchArray = timeStr.match(timePat);
	if (timeStr <= "") { return false; }
	if (matchArray == null) return false;

	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }

	if (hour < 1  || hour > 12) return false;
	if (hour <= 12 && ampm == null) return false;
	if  (hour > 12 && ampm != null) return false;
	if (minute < 0 || minute > 59) return false;
	if (second != null && (second < 0 || second > 59)) return false;
	return true;
	}
  
  function getValue(n) {
	var s = unFormatNumber(getItem(n).innerHTML);
	return s;
	}
	
  function copyTo(src,des) {
	var d = getItem(des);
	d.innerHTML = getValue(src);
  }
	
  function copyValue(v,d,dp) {
	getItem(d).innerHTML = Number(v).toFixed(dp);	
  }	

  function getItem(id) {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)
            itm = document.layers[id];

        return itm;
    	}

  function unFormatNumber(num) {
    var m = num.indexOf("(");
  	num = +num.replace(/[^\d\.-]/g,'');
	if (m >= 0) num = Number(num) * -1;
	return num;
  }

  function copyNum(val,id,dec,pre,com){
    var tmpNum = DecFormat(isNum(val),dec,"");
    if(com){
      // remove precision for computation
	  psplit = tmpNum.split(".");
 
	  var cnum = psplit[0],
		parr = [],
		j = cnum.length,
		m = Math.floor(j / 3),
		n = cnum.length % 3 || 3; // n cannot be ZERO or causes infinite loop
 
	  // break the number into chunks of 3 digits; first chunk may be less than 3
	  for(var i=0;i<j;i+=n) {
	    if(i != 0){n=3;}
	    parr[parr.length] = cnum.substr(i, n);
	    m -= 1;
	  }
 
	  // put chunks back together, separated by comma
	  tmpNum = parr.join(",");
 
	  // add the precision back in
	  if (psplit[1]) {tmpNum += "." + psplit[1];}
    }
    getItem(id).innerHTML = pre + tmpNum;
  }

  function isNull(t){
    if(t==null) return "";
	else return t;
  }
  
  function show_hide_column(tb,col_no, do_show) {

    var stl;
    if (do_show) stl = 'block'
    else         stl = 'none';

    var tbl  = document.getElementById(tb);
    var rows = tbl.getElementsByTagName('tr');

    for (var row=0; row<rows.length;row++) {
      var cels = rows[row].getElementsByTagName('td')
      cels[col_no].style.display=stl;
    }
  }
 
  function placeFocus(){
    var reSel = /select/i;
    var reText = /^text/i;
    if(document.forms.length>0){
      var field = document.forms[0];
	  for(i=0;i<field.elements.length; i++){
	    if((field.elements[i].type.match(reText)&&(field.elements[i].disabled==false)) || (field.elements[i].type.match(reSel))){
		  field.elements[i].focus();
	       break;
        }
      }
    }
  }

  function newWindow(url){
    var win = window.open(url,"newwin","toolbar,location,status,menubar,scrollbars,resizable,width=" + (screen.width-10) + ",height=350");
	win.focus();
	win.moveTo(0,0);
  }

 function playsound(dest,fm){
   var plugw = navigator.mimeTypes["audio/wav"];
   var plugw2= navigator.mimeTypes["audio/rmf"];
   var plugm = navigator.mimeTypes["audio/midi"];
   var browser_check=" ";
   if(navigator.appName=="Netscape" && ((parseInt(navigator.appVersion)>=3) && (parseInt(navigator.appVersion)<4)))
     browser_check="n3_up";
   if(navigator.appName.indexOf("Microsoft")>-1)
     browser_check="msie";
   if((navigator.appName=="Netscape")&&((parseInt(navigator.appVersion)==4)&&((plugw)||(plugw2))))
     browser_check="n4";
   if((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>4))
     browser_check="n4";
   if(browser_check!="n3_up" && browser_check!="msie" && browser_check!="n4") return;
   var file=dest;
   var doc=parent.frames[fm].document;
   doc.open("text/html");
   doc.write("<html><head>");
   doc.write("<title></title>");
   doc.write("</head><body bgcolor=\"#000000\">");
   if(browser_check=="n3_up" || browser_check=="n4")
     doc.write("<embed src=\""+file+"\" hidden=true mastersound>");
   if(browser_check=="msie")
     doc.write("<bgsound src=\""+file+"\" loop=1 volume=10>");
   doc.write("</body></html>");
   doc.close();
 } 
 
 function forgotPW(f){
   var lg = f.Login.value + "";
   var pmt = prompt("Enter login or email address on file:",lg);
   if(isNull(pmt)!=""){
     parent.frames["ifmHid"].location = "act_GetPW.cfm?LG=" + escape(pmt);
   }
   else forgotPW(f);
 }
 
  function helpFile(){
    var hwin = window.open("/help/contentmanual.htm","helpwin","menubar,scrollbars,resizable,width="+(screen.width-10)+",height=450,left=0,top=0");
  }
 