var totalsec = 1800;
var basesec = 1800;

function TimeLeft() 
{
  if (!document.layers && !document.all) return;
  
  seconds = totalsec % 60;
  seconds = (seconds<10)?'0'+seconds:seconds;

  dispTime = Math.floor(totalsec/60) +':'+seconds;
  totalsec--;

  if (document.layers) 
  {
    document.layers.timeleft.document.write(dispTime);
    document.layers.timeleft.document.close();
  }
  else if (document.all)
    timeleft.innerHTML = dispTime;

  newtime = window.setTimeout("TimeLeft();", 1000);
}


function resettime()
{
  window.clearTimeout(myTimer);
  totalsec = basesec;
  myTimer=setTimeout("GoHome()",totalsec*1000);
}

function init()
{
  myTimer=setTimeout("GoHome()",totalsec*1000)
  newtime = window.setTimeout("TimeLeft();", 1000);
  refreshTime = window.setTimeout("refreshVars()",1200000);
  if (document.forms[0]) 
    if (document.forms[0].name=='keyForm')
      document.forms[0].KeyN.focus();
}  


function checkNum (field, txt)
{
	if (isNaN(field.value))
	{
		alert('Invalid '+txt);
		field.select();
		field.focus();
		return (false);
	}
	return(true);
}

function pdfreportwindow( parmform ) 
{
	window.open( '', 'pdfwindow', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes')
	   parmform.target = "pdfwindow"
	   parmform.submit()
}

function icap1(theElement)
{
   theElement.value = theElement.value.substr(0,1).toUpperCase() + theElement.value.substr(1,(theElement.value.length - 1)).toLowerCase();
}

function icap2(theElement)
{
 var tmpstring;
 var newstring;
 var element_array = theElement.value.split(" ");
 for (var loop=0; loop < element_array.length; loop++)
 {
    tmpstring = element_array[loop];
    if (loop == 0)
    {
        newstring = tmpstring.substr(0,1).toUpperCase() + tmpstring.substr(1,(tmpstring.length - 1)).toLowerCase();
    }
    else
    {
        newstring = newstring + ' ' + tmpstring.substr(0,1).toUpperCase() + tmpstring.substr(1,(tmpstring.length - 1)).toLowerCase();
    }
 }
   theElement.value = newstring;
}

function uCase( theElement )
{
   theElement.value = theElement.value.toUpperCase();
}

function ValidateBlank( theElement )	
{
  if ( theElement.value == "" )
    return true;
  else
    return false;
}

function phoneNum(theElement)
{
  phNum = '';
  for (i=0; i<theElement.value.length; i++)
  {
    if ((!(isNaN(theElement.value.substr(i,1))))&&(theElement.value.substr(i,1)!=' '))
      phNum += theElement.value.substr(i,1);
  }
  if (phNum.length==0) // empty field
  {
    return true;
  }
  else if (phNum.length<7)
  {
    alert('Invalid Phone Number, Less than 7 digits (< 7)');
    theElement.focus();
    theElement.select();
    return false;
  }
  else if (phNum.length==7)
  {
    phNum = '(000) ' + phNum.substr(0,3)+'-'+phNum.substr(3,4);
  }
  else if (phNum.length==10)
  {
    phNum = '('+phNum.substr(0,3)+') '+phNum.substr(3,3)+'-'+phNum.substr(6,4);
  }
  else if (phNum.length>10)
  {
    phNum = '('+phNum.substr(0,3)+') '+phNum.substr(3,3)+'-'+phNum.substr(6,4)+' #'+phNum.substr(10,phNum.length-10);
  }
  else
  {
    alert('Invalid Phone Number, Unrecognized Format');
    theElement.focus();
    theElement.select();
    return false;
  }
  theElement.value=phNum;
  return;
}

function checkYear (theElement)
{
  theYear = '';
  for (i=0; i<theElement.value.length; i++)
  {
    if ((!(isNaN(theElement.value.substr(i,1))))&&(theElement.value.substr(i,1)!=' '))
      theYear += theElement.value.substr(i,1);
  }
  
  if (theYear.length==2)
    theYear = (theYear>50)?'19'+theYear:'20'+theYear;

  theElement.value = theYear;
}

function makeNum (theElement)
{
  theInt = '';
  for (i=0; i<theElement.value.length; i++)
  {
    if ( (!(isNaN(theElement.value.substr(i,1))) && (theElement.value.substr(i,1)!=' ')) ||(theElement.value.substr(i,1)=='.') )
      theInt += theElement.value.substr(i,1);
  }
  theElement.value = theInt;
  // if (theInt=='') theElement.focus();
}

function precision (x,y)
{
  val = Math.floor(x*Math.pow(10,y)+.5)/ Math.pow(10,y) +'';
  if (val.indexOf('.') == -1) // no decimal places
    val = val + '.00';
  else if (val.indexOf('.') == val.length-2) // 1 decimal places
    val = val + '0';
  return val;	
}

function checkFormFields(form,fields)
{
	str = '';
	fieldList = fields.split(',');
	for (i=0; i<fieldList.length; i++)
	{
		field = eval('form.'+fieldList[i]);
		if (field.type == 'select-one')
			fieldVal = field.options[field.selectedIndex].value;
		else
			fieldVal = field.value;
		if (fieldVal.length==0)
			str += fieldList[i] + ' cannot be blank.\n';
	}
	if (str.length > 0)
	{
		alert(str);
		return false;
	}
	return oneClick();
}

function checkPaymentForm(form)
{

	if(form.payOpt1.selectedIndex==0 && form.Amt1.value.length)
	{
		alert('Please Select a Payment Type');
		form.payOpt1.focus();
		return false;
	}
	if(form.payOpt2.selectedIndex==0 && form.Amt2.value.length)
	{
		alert('Please Select a Payment Type');
		form.payOpt2.focus();
		return false;
	}
	if(form.payOpt3.selectedIndex==0 && form.Amt3.value.length)
	{
		alert('Please Select a Payment Type');
		form.payOpt3.focus();
		return false;
	}
	if(form.payOpt4.selectedIndex==0 && form.Amt4.value.length)
	{
		alert('Please Select a Payment Type');
		form.payOpt4.focus();
		return false;
	}
	return true;
}

var clicked=false;
function oneClick()
{
	if (!clicked)
	{
		clicked=true;
		return true;
	}
	alert ('Please don\'t click the button twice.');
	return false;
}

