function format(expr, decplaces){
	var str=""+Math.round(eval(expr)*Math.pow(10,decplaces));
	while ( str.length <= decplaces){
		str = "0"+str;
	}
	var decpoint=str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function isEmpty(inp){ if (inp==null || inp == "") { return true; } return false; }
function isFilled(inp){ if (inp==null || inp == "") { return false; } return true; }

function verNum(form,input,min,max){
  var theObj=eval("document."+form+"."+input);
  var theVal=parseFloat(theObj.value);
  if (isNaN(theVal)){
    alert("Only Numbers Allowed in "+input+" field")
	theObj.value = min;
	return;
  }
  if (min != max && (theVal < min || theVal > max)){
    alert("Only Numbers Between "+min+" and "+max+" allowed")
	theObj.value = min;
	return;
  }
  return;
}

function CreateArray(length)
{
   this.size=(length+3);
   for(var i = 1; i <= length+3; i++)
      this[i] = "Unacceptable character\nOnly alpha-numerics, underscores, hyphens and periods are allowed.";
}

function valMail(address)
{
	
   if(address.length == 0) return 0; 
	
   invalidchars = new Array(' ', ',', '[', ']', '/', '=', ';', '`', '+', '!', '#', '$', '%', '^', '&', '*', '(', ')', '~', ':', '\"', '\'', '\b', '<', '>', '?', '|', '{', '}');
   var numchars = invalidchars.length;
   error_messages = new CreateArray(numchars);  
   error_messages[0] = "Valid";
   error_messages[1] = "Address must have an @ then a '.'\nand cannot begin with @";
   error_messages[2] = "Address cannot have '.' next to @ or as final character";
   error_messages[3] = "Spaces are invalid";
   error_messages[4] = "Commas are invalid";
   error_messages[5] = "Brackets are invalid";
   error_messages[6] = "Brackets are invalid";
   error_messages[7] = "Slashes are invalid";
   error_messages[8] = "Equals are invalid";
   error_messages[9] = "Semi-Colons are invalid";
   error_messages[10] = "Accents are invalid";

   var atloc=address.indexOf('@');
   var dotloc=address.lastIndexOf('.');
         
   // Tests For one '.' and one '@' in correct order
   // And makes sure first substring isn't null
   if(atloc<1||dotloc==-1||dotloc<atloc)
   {
      alert("\nInvalid E-Mail Address\n" + error_messages[1] + "\nExample: bob@foo.com" );           
      return 1;
   }
                
   // Tests second and third substrings for nullness
   else if(dotloc < atloc+2 || address.length < dotloc+2)
   {
      alert("\nInvalid E-Mail Address\n"+error_messages[2] + "\nExample: bob@foo.com");     
      return 2;
   }             
        
   // Tests for individual syntax errors
   // Only common keystroke errors included!        
   for(var ct=0;ct<numchars;ct++)
   {
      status=invalidchars[ct];
      if(address.indexOf(invalidchars[ct])!=-1)
      {
         alert("\nInvalid E-mail Address\n" + error_messages[ct+3] + "\nExample: bob@foo.com");
         return (ct+3);
      }
   }
   return 0;
}

function checkMail(form){
	var box=eval("document."+form+".email");
	var address=box.value;
	var ret = valMail(address);
	if (ret != 0){
		box.value = "";
	}
}


var tncWind=null;

function openTNC(file){
	if (tncWind==null || tncWind.closed){
		tncWind=window.open(file,'Terms','toolbar=no,location=no,scrolling=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
		if (tncWind.opener==null){
			tncWind.opener=self;
		}
	}
	tncWind.focus();
} 
