
function is_address(addr, city, state, zip)
{
	
  if (addr.value == "")
  {
    alert("Please enter the address.");
	addr.focus();
    return (false);
  }
  
  if (city.value == "")
  {
    alert("Please enter the address including city.");
	city.focus();
    return (false);
  }

  if (state.value.length < 2)
	  {
	  	alert("Please enter at least 2 characters in the \"State\" field.");
		state.focus();
    	return (false);
	  }
  
  if (zip.value.length < 5)
  {
    alert("Please enter at least 5 digits in the \"Zip\" field.");
	zip.focus();
    return (false);
  }
////////////////////////////////////////////////////////////
//makes sure input to state and zip fields were in proper format 
////////////////////////////////////////////////////////////
  var allValid = true;
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 
  var chkOK = "1234567890";
  var checkStr = state.value;
    
  var chkStr = zip.value;

  for (i = 0;  i < checkStr.length;  i++)
  {   ch = checkStr.charAt(i);
	     for (j = 0;  j < checkOK.length;  j++)
		       if (ch == checkOK.charAt(j))
			           break;
			   if (j == checkOK.length)
				{      allValid = false;
				       break;
				}
  }
  if (!allValid)
  {
      alert("Please enter only letters in the \"State\" field.");
	  state.focus();
	  return (false);
  }

for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digits in the \"Zip\" field.");
    zip.focus();
    return (false);
  }
}

function is_phone(phone_code, phone)
{
////////////////////////////////////////////////////////////
//checks on the phone number
////////////////////////////////////////////////////////////
  var chkOK = "1234567890";
  var allValid = true;
  var chkStr = phone_code.value;
  for (i = 0;  i < chkStr.length;  i++)  
  {    
	ch = chkStr.charAt(i);
	for (j = 0;  j < chkOK.length;  j++)  
	if (ch == chkOK.charAt(j)) break; 
	if (j == chkOK.length)    
	{     
		allValid = false;      
		break;    
	} 
  }

  var chkStr = phone.value;

  if (8 == chkStr.length && '-' != chkStr.charAt(3))
  allValid = false;

  for (i = 0;  i < chkStr.length;  i++)  
  {    
  if (i == 3 && '-' == chkStr.charAt(3))
  ;
  else
  {
  ch = chkStr.charAt(i);
	for (j = 0;  j < chkOK.length;  j++)  
	if (ch == chkOK.charAt(j)) break; 
	
	if (j == chkOK.length)    
	{     
		allValid = false;      
		break;    
	} 
  }
  }

  if (phone_code.value.length < 3 || phone.value.length < 7 || !allValid) 
  {
    alert("Please enter the number in the form ### ###-####.");
    phone_code.focus();
    return (false);
  }

}

function is_1_phone(phone){
	var bad="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,.<>/?'[{]}\|+=_-)(*&^%$#@!`~" + '"';
	strip(phone, bad);
	//alert(phone.value.length);
	if(phone.value.length != 10){
		alert("Too few characters\n\nPlease enter the area code");
		return false
	}
	
	//force in the dashes
	var area,phone3, phone4;
	area = phone.value.substring(0,3) + '-';
	phone3 = phone.value.substring(3,6) + '-';
	phone4 = phone.value.substring(6, phone.value.length);
	phone.value = area+phone3+phone4;
	
	
}

function is_money(amount)
{
////////////////////////////////////////////////////////
//check amount characters
///////////////////////////////////////////////////  
  if (amount.value == "")
  {
    alert("Please enter a payment amount.");
    amount.focus();
    return (false);
  }
  
  
	var chkOK = "1234567890.$,";
	var chkStr = amount.value;
	var allValid = true; 
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
	if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
    alert("Illegal character in \"Amount\" field.");
    amount.focus();
    return (false);
  }
  
  //check for proper syntax of "$"
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
	if ( ch =='$' && i != 0) 
	{
		allValid = false;
		break;
	}
	
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
  	alert("Invalid format\n\n \"$\" must be first character only");
    amount.focus();
	allValid = false;
    return (allValid);
  }
  
  //check for proper sytnax of "."
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
	if ( ch =='.' && i != chkStr.length-3) 
	{
		allValid = false;
		break;
	}
	
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
  	alert("Invalid format of \".\"");
    amount.focus();
	allValid = false;
    return (allValid);
  }
  
  
  //make sure amount is greater than 0
   
  for (i = 0;  i < chkStr.length;  i++)
  {
    
	if (chkStr.charAt(i) != NaN)
		ch = chkStr.charAt(i);
	else
		continue;
		
	if(ch > 0)
	{	allValid = true;
		break;
	}
	
	else allValid = false;
  }
  
  if (!allValid)
  {
  	alert("Please enter an amount greater than 0");
    amount.focus();
	allValid = false;
    return (allValid);
  }
  
  //end of amount check

}

function is_date(expdate)
{
////////////////////////////////////////////////////////
//check for date
///////////////////////////////////////////////////
  if (expdate.value == "")
  {
    alert("Please enter the date.");
    expdate.focus();
    return (false);
  }
  
  if (expdate.value.length < 6)
  {
    alert("Improper format in \"Date\" field.\n\n Please use the format \n\n mm/dd/yyyy ");
    expdate.focus();
    return (false);
  }
  
	var chkOK = "1234567890/";
	var chkStr = expdate.value;
	var allValid = true; 
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
    alert("Illegal character in \"Date\" field.\n\n Please use the format \n\n mm/dd/yyyy ");
    expdate.focus();
    return (false);
  }
  
  dateArr = chkStr.split('/')
  //alert(dateArr[0].length +"\n\n"+ dateArr[1].length +"\n\n"+ dateArr[2].length)
  
  if(dateArr[0].length > 2){
  	alert("Improper Format in \"Date\" field.\n\n Please use the format \n\n mm/dd/yyyy")
	expdate.focus()
	return false
  }
  
  if(dateArr[1].length > 2){
  	alert("Improper Format in \"Date\" field.\n\n Please use the format \n\n mm/dd/yyyy")
	expdate.focus()
	return false
  }
 
  if(dateArr[2].length != 4 && dateArr[2].length != 2){
  	alert("Improper Format in \"Date\" field.\n\n Please use either a 2 or 4 digit year")
	expdate.focus()
	return false
  }
  
  	
  return true
// end of date check

}

function is_number(num)
{
	var chkOK = "1234567890";
	var chkStr = num.value;
	var allValid = true; 
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
	
  }
  
  if (!allValid)
  {
    alert("Improper format in please use only numbers");
    num.focus();
    return (allValid);
  }
  
}

function is_float(num)
{
	var chkOK = "1234567890.";
	var chkStr = num.value;
	var allValid = true; 
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
	
  }
  
  if (!allValid)
  {
    alert("Improper format in please use only numbers");
    num.focus();
    return (allValid);
  }
  
  return true
  
}


function is_letter(alpha)
{
	var chkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var chkStr = alpha.value;
	var allValid = true; 
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
	
  }
  
  if (!allValid)
  {
    alert("Improper format in please use only letters");
    alpha.focus();
    return (allValid);
  }
  
}

function is_email(email)
{
	email.value = strip(email, " ")
	
  if (email.value == "")
  {
    alert("Please enter the email address.");
    email.focus();
    return (false);
  }

  var amp=false;
  for (j = 1;  j < email.value.length-1;  j++)  
  {
  if (email.value.charAt(j) == "@")
  amp=true;
  }

  if (email.value.length == 0)
  amp=true;

  if (email.value.charAt(0) == "@" || email.value.charAt(email.value.length-1) == "@")
  {
    alert("Your e-mail address can't start or end with an @.");
    email.focus();
    return (false);
  }


  if (!amp)
  {
    alert("Your e-mail address has to have an @.");
    email.focus();
    return (false);
  }

}

function is_there(it)
{	/* there is no alert box so you can customize 
	your alert box message in the Validation function*/
  if (it.value == "")
  	return (false);
  else 
  	return (true);
}

function is_checked(it)
{	/* there is no alert box so you can customize 
	your alert box message in the Validation function*/
  if (it.checked)
  	return (true);
  else 
  	return (false);
}

function is_time(time)
{
	var chkOK = "1234567890:";
	var chkStr = time.value;
	var allValid = true; 
	var ch;
	var size = time.value.length, colon=size-3;
	
  if(time.value == "")
	{
		alert("Please enter the time\n\nPlease use the format ##:##");
	    time.focus();
	    return (false);
	}
	
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
    for (j = 0;  j < chkOK.length;  j++)
      if (ch == chkOK.charAt(j))
        break;
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
	
  }
  
  if (!allValid)
  {
    alert("Illegal character	'"+ ch +"'\n\nplease re-enter information");
    time.focus();
    return (allValid);
  }
  
  for (i = 0;  i < chkStr.length;  i++)
  {
    ch = chkStr.charAt(i);
	if ( ch ==':' && i != chkStr.length-3) 
	{
		allValid = false;
		break;
	}
	
    if (j == chkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
  	alert("Improper format of time\n\nPlease use the format ##:##");
    time.focus();
	allValid = false;
    return (allValid);
  }
	
	if(chkStr.charAt(size-3) != ':')
	{
		alert("Improper format of time\n\nPlease use the format ##:##");
	    time.focus();
	    return (false);
	}
	
	if(time.value.length<4)
	{
		alert("Please enter at least 4 characters for the time\n\n example:	#:##	or	##:##");
	    time.focus();
	    return (false);
	}
  
	
}

function strip(naked, illegal){
	//naked is the form element to be stripped of characters specified in the string "illegal"
	//var naked_str = naked.value;
	var naked_str = ""
	for(x=0; x<= naked.value.length; x++)
	{	
		var bad = false;
		chr = naked.value.charAt(x);
		for(i=0; i <= illegal.length; i++)
		{
			if(chr == illegal.charAt(i) )
			{	bad = true;
				break;}
				
		}
		
		if(!bad)
			naked_str += chr;
	}
	
	naked.value = naked_str;
  
  return naked.value

}

function keep(naked, legal){
	//strip the form element of everything but the characters passed to it
	
	var naked_str = ""
	for(x=0; x<= naked.value.length; x++)
	{	
		var good = false;
		chr = naked.value.charAt(x);
		for(i=0; i <= legal.length; i++)
		{
			if(chr == legal.charAt(i) )
			{	good = true;
				break;}
		}
		
		if(good)
			naked_str += chr;
	}
	
	naked.value = naked_str;

  return naked.value

}
function isTextAreaLessThanLength(textArea, length)
{
	if (textArea.value.length >= length){
		//
		return false;
	}
	return true;

}
function trimText(textbox,maxSize)
{	if(textbox.value.length>maxSize){
		alert("The maximum number of characters is "+maxSize);
		var extraText=textbox.value.substring(0,maxSize)
		textbox.value=extraText;
	}
}
