//*
//* Charalambos
//* Copyright 1996-2000
//*
//*************************************************************************
//*************************************************************************
var GoSubmit=true
var FirstClick=true
var wNewWindow=null

//*************************************************************************
function isFirstClick()
{var ok=false

if (GoSubmit)
{
  if (!FirstClick)
  {
    //*** alert("Processing request. Please wait...")
    //ok=ok

    alert("Processing request. Please wait...")
  } 
  else
    ok=true;  

  FirstClick=false
}  

return ok
}
//*************************************************************************
function selectDefaultIndex(sel)
{var ok=-1, i=0

 for (i=0; i<sel.length; i++)
   if (sel.options[i].defaultSelected)
   {
     ok=i
     break;
   }  

return ok
}
//*************************************************************************
//
//
//
function selectIndex(sel)
{var ok=-1, i=0

 for (i=0; i<sel.length; i++)
   if (sel.options[i].selected)
   {
     ok=i
     break;
   }  

return ok
}
//*************************************************************************
//
// returns: -1 if no buttons are checked or the index 0..btn
//

function radioIndex(btn)
{var ok=-1, i=0

//* btn.length 
//*     -1  if no buttons 
//*   null  if 1 button
//*      n  if >1 buttons

if (btn.length==null)
{
  //ok=-1    let's assume there is only one button and that is checked
  ok=0
}    
else
{
 for (i=0; i<btn.length; i++)
 {
   if (btn[i].checked)
   {
     ok=i
     break;
   }
 }  
}

return ok
}
//*************************************************************************
//
// 
//
function radioDefaultIndex(btn)
{var ok=-1, i=0

//* btn.length 
//*     -1  if no buttons
//*   null  if 1 button
//*      n  if >1 buttons

if (btn.length==null)
{
  ok=-1
}    
else
{
 for (i=0; i<btn.length; i++)
   if (btn[i].defaultChecked)
   {
     ok=i
     break;
   }  
}

return ok
}
//*************************************************************************
function promptLink(lnk,msg,URL)
{
if (confirm(msg))
  lnk.href=URL
else
  return false;
}
//*************************************************************************
function changeTarget(x, destination)
{
// with (parent.MainW.document)
  x.forms[0].target=destination
 return true
}
//*************************************************************************
function doNothing(){}
//*************************************************************************
//*************************************************************************
function setFocus()  
{
var i=0

if ((document.forms.length>0) && (document.forms[0].elements.length>0))
with (document.forms[0])
{
  while ((elements[i].type.toUpperCase()!="TEXT") && (elements[i].type.toUpperCase()!="TEXTAREA") && (elements[i].type.toUpperCase()!="PASSWORD"))
  {
    i++
    if (i>=elements.length)
      return false;
  }
  elements[i].focus()
  selectText(elements[i])
}
else
{
  SetFrameFocus()
}

return true
}
//*************************************************************************
function NewSetFrameFocus(oWindow)
{
   if (oWindow==null)
   {
     if (parent.frames.length>0) 
       parent.frames[1].focus()
   }
   else
   {
     oWindow.focus()
   }

return true
}
//*************************************************************************
function SetFrameFocus()
{   
if (parent.frames.length>0) 
   parent.frames[1].focus();

return true
}
//*************************************************************************
function isDate(ds)
{var ok=true
 var slashPos1=ds.indexOf("/")
 var slashPos2=ds.indexOf("/",slashPos1+1)
  
  ds=alltrim(ds)
  
  if (ds.length==0 || slashPos1<0 || slashPos2<0 ||
     ds.substring(slashPos1+1).length==0 || ds.substring(slashPos2+1).length==0)
    ok=false
  else
  {
    var m=alltrim(ds.substring(0,           slashPos1))
    var d=alltrim(ds.substring(slashPos1+1, slashPos2))
    var y=alltrim(ds.substring(slashPos2+1, ds.length))
    var s=m+d+y

    for (var i=0; i<s.length; i++)
      if (!((s.charAt(i)>="0" &&  s.charAt(i)<="9")  || s.charAt(i)=="/" ) )             
      {
        ok=false
        break
      }  

    if (ok)
    {
      var mInt=parseInt(m,10)
      var dInt=parseInt(d,10)
      var yInt=parseInt(y,10)

      if (yInt>3000 || (y.length!=2 && y.length!=4) || mInt<1 || mInt>12)
        ok=false
      else      
      if (mInt==1 || mInt==3 || mInt==5 || mInt==7 || mInt==8 || mInt==10 || mInt==12)
        ok=(dInt<=31)
      else 
      if (mInt!=2)  
        ok=(dInt<=30)
      else
      if (yInt%4==0)
        ok=(dInt<=29)
      else
        ok=(dInt<=28);       
    }    
  }
   
return ok
}
//*********************************************************************************
function selectText(x) 
// Selects the text in a text field if less than 12 chars.  Should only be
//called from text boxes
{
  if ((x.value.length<12) && (x.value.length>0))
    x.select();
}
//*************************************************************************
function isPhone(elm) {

    if (elm.value.length != 12) {

        return false;

    }

    for (var i = 0; i < elm.value.length; i++) {

        if ((i > -1 && i < 3) || (i > 3 && i < 7) || (i > 7 && i < 12)) {

            if (elm.value.charAt(i) < "0" || elm.value.charAt(i) > "9") {

                return false;

            }

        }

        else if (elm.value.charAt(i) != "-") {

            return false;

       }

    }

    return true;

}
//*************************************************************************
function isEmpty(s)
{
return (s==null) || (alltrim(s)=="")
}
//*************************************************************************
function isNumber(s, lNegative, lDecimal)
{
if (lNegative==null)
  lNegative=false;
if (lDecimal==null)
  lDecimal=true;

var ok=true

if (!isEmpty(s))
{
  s=alltrim(s)
  if (lNegative)
  {
    if (s.charAt(0)=="-")
      s=s.substring(1,s.length)
  }  
  
//  if (false)
//    ok=validCharSet(s, "0123456789")   // slow
//  else
  {
    for(var i=0; i<s.length; i++)
      if ((s.charAt(i)<"0") ||  (s.charAt(i)>"9"))
      {
        if ((!lDecimal) || (s.charAt(i)!="."))
        {
          ok=false          
          break
        }  
      }
  }    
}
else
  ok=false;   
  
return ok
}
//*************************************************************************
function isTime(s)
{
var ok=true
var colonPos=s.indexOf(":")

s=alltrim(s.toUpperCase())

var hour=parsestr(s, 1, ":")
var endofs=parsestr(s, 2, ":")
var minute="";
var ampm="";
if (endofs.length==4)
	{
  	  var minute=endofs.substring(0,2);
	  var ampm=endofs.substring(2,4);
	}
	if (endofs.length==5 && endofs.charAt(2," "))
	{
	  var minute=parsestr(parsestr(s, 2, ":"),1," ");
	  var ampm=parsestr(s, 2, " ");
	}

if ((!isEmpty(s)) && (colonPos>=0) && (hour.length>0) && (hour.length<3) && (minute.length=2) && (ampm.length>=1))
{

	if ((hour.length==2) && (hour.charAt(0)!="0"))
      if ((hour.charAt(0)>"1") || (hour.charAt(0)<"0") || (hour.charAt(1)<"0") || (hour.charAt(1)>"2") )
      {
        ok=false          
      }

	if ((hour.length==2) && (hour.charAt(0)=="0"))
      if ((hour.charAt(1)<"0") || (hour.charAt(1)>"9"))
      {
        ok=false          
      }

	if (hour.length==1)
      if ( (hour.charAt(0)<"1") ||  (hour.charAt(0)>"9"))
      {
        ok=false          
      }  

    if ((minute.charAt(0)<"0") || (minute.charAt(0)>"5") || (minute.charAt(1)<"0") || (minute.charAt(1)>"9"))
    {
      ok=false          
    }  

  if (((ampm.charAt(0)!="A") && (ampm.charAt(0)!="P")) || (ampm.charAt(1)!="M"))
    {
      ok=false          
    }  
}
else
  ok=false;   
 
return ok
}
//*************************************************************************
function validCharSet(s, set, allowEmpty)
{
var i, ok=true

if (allowEmpty==null)
  allowEmpty=false;

if (!isEmpty(s))
{
  for(var i=0; i<s.length; i++)
    if (set.indexOf(s.charAt(i))==-1)
    {
      ok=false
      break
    }  
}
else
  ok=allowEmpty;
  
return ok
}
//*************************************************************************
function isBetween(n, low, high)
{  var ok=false
   if (isNumber(n))
   {
     n=parseInt(n,10)
     ok=((n>=low) && (n<=high))
   }
return ok
}
//*************************************************************************
//*************************************************************************
function UpperCase(x)
{
x.value=x.value.toUpperCase()
return true
}
//*************************************************************************
function checkValidCharSet(x, set)
{
var ok=true

if (!validCharSet(x.value, set, false))
{
   x.focus()
   alert("Invalid character -- must be in ("+set+")")
   ok=false
}
  
return ok
}
//*************************************************************************
function checkEmpty(x, silent)
{
if (silent==null)
  silent=false;
  
var ok=false

 if (isEmpty(x.value))
 {
   x.focus()
   if (!silent)
     alert("Field cannot be blank ("+x.name+")");
        
   ok=true
 }
return ok
}
//*************************************************************************
function checkDate(x)
{var ok=true

 if (!isDate(x.value))
 {
   x.focus()
   alert("Invalid Date (MM/DD/YY)")
   x.value=""
   ok=false
 }
return ok
}
//*********************************************************************************
function checkTime(x)
{var ok=true

 if (!isTime(x.value))
 {
   x.focus()
   alert("Invalid Time (HH:MM am/pm)")
   x.value=""
   ok=false
 }
 else
 { 
   var hour=parsestr(x.value,1,":");
   if (((alltrim(x.value.length)==7) && (hour.length==2)) || ((alltrim(x.value.length)==6) && (hour.length==1)))
   {
     var s=parsestr(x.value,2,":");
     x.value=parsestr(x.value,1,":")+":"+s.substring(0,2)+" "+s.substring(2,4); 
   }	 
 }
return ok
}
//*********************************************************************************
function EcheckDate(x)
{return ( (isEmpty(x.value)) || (checkDate(x)) )}
//*********************************************************************************
function EcheckTime(x)
{return ( (isEmpty(x.value)) || (checkTime(x)) )}
//*********************************************************************************
function checkInt(x, lNegative, lDecimal)
{
if (lNegative==null)
  lNegative=false;

if (lDecimal==null)
  lDecimal=true;

var ok=true

 if (!isNumber(x.value, lNegative, lDecimal))
 {
   x.focus()
   //x.select()
   alert("A numeric value should be entered")
   x.value=""
   ok=false
 }
return ok 
}
//*********************************************************************************
// allows int to be empty
function EcheckInt(x, lNegative, lDecimal)
{return ( (isEmpty(x.value)) || (checkInt(x, lNegative, lDecimal)) )}
//*********************************************************************************
function checkRange(x,low,high)
{ var ok=true

  if (!isBetween(x.value,low,high))
  {
    x.focus()  
    alert('Value must be between '+low+' and '+high)
    x.select()
    ok=false
  }
return ok 
}

//*************************************************************************
function noFormChanges(w)
{var ok=true, i=0
  
//  with (parent.frames[1].document.forms[0])
//  with (parent.MainW.document.forms[0])

  with (w)
  {
    for (i=0; i<=elements.length-1;i++) 
    {                
      if ((elements[i].type=="hidden") || (elements[i].type=="submit"))
      {      
      }
      else
      if ((elements[i].type=="text") 
          || (elements[i].type=="textarea") 
          || (elements[i].type=="password"))
      {
        ok=(alltrim(elements[i].value).toUpperCase()==alltrim(elements[i].defaultValue.toUpperCase()))
      }
      else
      if (elements[i].type=="radio")
      {
        ok=(elements[i].checked==elements[i].defaultChecked)
      }
      else
      if (elements[i].type=="checkbox")
      {
        ok=(elements[i].checked==elements[i].defaultChecked)
      }
      else
      if (elements[i].type=="select-one")
      {        
        ok=(selectIndex(elements[i])==selectDefaultIndex(elements[i]))
      }
     
      if (!ok)
        break;
    }    
  }
  
  if (!ok)
    ok=confirm("Some data was modified but was not saved. Do you wish to abandon changes?");
  
return ok
}
//*************************************************************************
function clearFields()
{var i=0

  with (document.forms[0])
  for (i=0; i<=elements.length-1;i++)   
    if ((elements[i].type=="text") || (elements[i].type=="textarea"))
    {
      elements[i].value=""
      i++
    }
    
  setFocus()
  
return false
}
//*************************************************************************
//
// returns the index of an object in form.elements
//
function Obj2Index(x)
{var i=0

//x.name=x.name.toUpperCase()

  with (document.forms[0])
  for (i=0; i<=elements.length-1;i++) 
  {
    // .toUpperCase()
    if (elements[i].name==x.name)
    {
      return i
    }  
  }
  
return i
}
//*************************************************************************
//
// returns the index of a field in form.elements based on field name
//
function Name2Index(s)
{var i=0, j=0

//s=s.toUpperCase()
//s=s.toLowerCase()

j=document.forms[0].elements.length-1
//alert(document.forms[0].elements.length-1);


for (i=0; i<=j;i++) 
{
  if (document.forms[0].elements[i].name==s)
  {
  //alert(document.forms[0].elements[i].name);
    return i
  } 
 // else
 // {
 // alert(document.forms[0].elements[i].name);
 // } 
}

i=-1
  
return i
}
//*************************************************************************
function nonEmptyFields(frm, silent)
{
if (silent==null)
  silent=false;

  var ok=true
  
  for (var i=0; i<=frm.elements.length-1;i++) 
  {
                  
    //alert(frm.elements[i].type.toUpperCase())
    
    if ((frm.elements[i].type=="text") || (frm.elements[i].type=="textarea"))
    if (checkEmpty(frm.elements[i],true))
    {
      if (!silent)
        alert("Please fill out all fields");
      ok=false
      break
    }
  }
return ok  
}
//*************************************************************************
// text, textarea, passsword
function isDefValue(x)
{return (alltrim(x.value.toUpperCase())==alltrim(x.defaultValue.toUpperCase()))}
//*************************************************************************
//** Returns today's date as a string MM/DD/YY (system dependent)
function todayStr()
{   
  var ok="", today=new Date()
  
  ok=parsestr(today.toLocaleString(),1," ")
  
 return ok 
}
//*************************************************************************
//*************************************************************************
function words(s, delim)
{var ok=0, i=0

if (!isEmpty(s))
{
while (at(delim, s, ++i)!=-1)
  ok++;

if (s.substring(s.length-1,s.length)!=delim)
  ok++
}

return ok
}
//*************************************************************************
function parsestr(s, i, delim)
{var ok='', e=0

if (!isEmpty(s))
{
e=at(delim, s, i)

if (i>1)
{
 b=at(delim, s, i-1)
 
 if (b!=-1)
   if (e==-1)
   {
     if (b<s.length)
       ok=s.substring(b+1,255);
   }    
   else
     ok=s.substring(b+1,e);
}   
else
{
  if (i==1)
    if (e==-1)
      ok=s.substring(0,s.length)
    else
      ok=s.substring(0,e);
}
}

return ok
}
//*************************************************************************
function at(c, s, n)
{var ok=-1, k=0

if (!isEmpty(s))
  for(var i=0; i<s.length; i++)
    if (s.charAt(i)==c)
    {
      k++
      if (k==n)
        ok=i;
    }

return ok    
}
//*************************************************************************
function ltrim(s)
{var ok=s, i=0

//**if (!isEmpty(s))
if ((s!=null) && (s.length>0))
{
while ((i<s.length) && s.charAt(i)==' ')   // count blanks
  i++;

ok=s.substring(i,s.length-i+2)
}

return ok    
}
//*************************************************************************
function rtrim(s)
{var ok=s, i=s.length-1

if ((s!=null) && (s.length>0))
{
  while ((i>=0) && s.charAt(i)==' ')   // count blanks from right
    i--;
  ok=s.substring(0,i+1)
}  
return ok    
}
//*************************************************************************
function alltrim(s)
{return rtrim(ltrim(s))}
//*************************************************************************
//*************************************************************************
//*************************************************************************
//
function CheckCriteria(fields)
{var ok=true, i, j, n, fld

 n=words(fields, ";")

 j=0
 for (i=1;i<=n;i++) 
 {
   fld=parsestr(fields, i, ";")

   if (isEmpty(document.forms[0].elements[Name2Index(fld)].value))
     j++;
 } 

if (j==0)
  ok=(confirm("You did not specify any search criteria.  The report may be very long. Ok to continue?")); 

return ok
}
//*************************************************************************
//*************************************************************************
//
// specific to gen_ppicklist and gen_listscreen
//
function SwapCheckBoxValues()
{var ok=false, i=0

  with (document.forms[0])
  {      
   for (var i=1; i<=elements[Name2Index("ItemsCount")].value; i++)
    {
      ok=Name2Index("checked"+i)
      elements[ok].checked=!elements[ok].checked
    }        
  }
  
  ok=false
return ok
}
//*************************************************************************
//
function RequiredFields(fields)
{var ok=true, i=0, j=0, n=0, fld=""

 n=words(fields, ";")

 for (i=1;i<=n;i++) 
 with (document.forms[0])
 {
   fld=parsestr(fields, i, ";")
  //alert(fld);
   j=Name2Index(fld)

//alert(j);
//alert(elements[j].value);
   if (elements[j].type=="select-one")
     ok=(!isEmpty(elements[j].options[selectIndex(elements[j])].value))
   else
     ok=(!isEmpty(elements[j].value));
//alert(ok);
   if (!ok)
   {
     alert("Field cannot be blank ("+fld+")")
     elements[j].focus() 
     break
   }
  } 

return ok
}
//*************************************************************************
function OpenWindow(url, title, t, l, w, h)
{
 if (t==null)
   t=20;
 if (l==null)
   l=20;
 if (w==null)
   w=400;
 if (h==null)
   h=300;

 if ((wNewWindow!=null) && (!wNewWindow.closed))
   wNewWindow.close();
   
 wNewWindow=window.open(url, title, "top="+t+",left="+l+",width="+w+",height="+h+",toolbar=yes,directories=no,menubar=no,scrollbars=yes,status=yes,resizable=yes");

return false
}
//*************************************************************************
function ValidateForm(o)
{
    if (o.value.length>1)
      return true 
    else
    {
      alert("Type a longer name please");
	  o.focus();
      return false  
    }
}
//*************************************************************************
function disableForm(n, isdisable) 
{
if (vBrowser()>=4)
{
with (document.forms[n])
for (i=0; i<length; i++) 
{
  var e=elements[i];
  if (e.type.toLowerCase()=="submit" || e.type.toLowerCase()=="reset")
    e.disabled=isdisable;
}
}
}
//*************************************************************************
function isExplorer()
{
return (navigator.appName=="Microsoft Internet Explorer")
}
//*************************************************************************
function isNetscape()
{
return (navigator.appName=="Netscape")
}
//*************************************************************************
function vBrowser()
{
return parseInt(navigator.appVersion)
}
//*************************************************************************
//*************************************************************************
var ie = document.all?1:0
var ns4 = document.layers?1:0
var c = 1

function hideLayer(id) {
if (ie) {
document.all[id].style.zIndex = c--;	
document.all[id].style.visibility = "hidden";
}	
else if (ns4) {
document.layers[cat].layers[id].zIndex = c--;
document.layers[cat].layers[id].visibility = "hide";
}	
}
//*************************************************************************
function showLayer(id) {
if (ie) {
document.all[id].style.zIndex = c++;	
document.all[id].style.visibility = "visible";
}	
else if (ns4) {
document.layers[cat].layers[id].zIndex = c++;
document.layers[cat].layers[id].visibility = "show";
}
else {
document.getElementById(id).style.zIndex = c++;	
document.getElementById(id).style.visibility = "visible";	
}	
}
//*************************************************************************
//*************************************************************************
// Clock
var timer = null
function stop()
{
	clearTimeout(timer)
}

function start()
{

	var time = new Date()
	var hours = time.getHours()
	var minutes = time.getMinutes()
	minutes=((minutes < 10) ? "0" : "") + minutes
	var seconds = time.getSeconds()
	seconds=((seconds < 10) ? "0" : "") + seconds
	var clock = hours + ":" + minutes + ":" + seconds
	document.forms[0].display.value = clock
	timer = setTimeout("start()",1000)
}
//*************************************************************************
//*************************************************************************
function IsNumber(para)
 {
	para=para.toString()
	
	 para = para.toUpperCase()
     if (para.length >0) 
       {   
      
		var x= para;
		var l=para.length;
		var z=""
		for (i=0;i<l;i++)
		 {
			z=x.charAt(i)
			if ((z<"0")||(z>"9"))
			{
           
			 return false;
			}
         
			}
		return true;  
       }
       return true;
  } 

function checkdate(string) {
//alert("String: " + string);
var err = 0
//string = document.frm.dat.value
var valid = "0123456789/"
var ok = "yes";
var temp;
for (var i=0; i< string.length; i++) {
temp = "" + string.substring(i, i+1);
if (valid.indexOf(temp) == "-1") err = 1;
}
aDate = string.split("/")
//alert("Month: " + aDate[0]);
//alert("length: " + aDate.length);

if (aDate.length != 3) err=1
b = aDate[0] // month

d = aDate[1] // day

f = aDate[2] // year
if (b<1 || b>12) err = 1

if (d<1 || d>31) err = 1

if (f<0 || f>99 || f==0 || f.length != 2) err = 1



if (b==4 || b==6 || b==9 || b==11){
if (d==31) err=1
}
if (b==2){
var g=parseInt(f/4)
if (isNaN(g)) {
err=1
}
if (d>29) err=1
if (d==29 && ((f/4)!=parseInt(f/4))) err=1
}

//alert("ERR: " + err);
if (err==1) {
//alert("False");
return false;
}
return true;
}
