function checkNumber(fieldName)
{
	var stopped = 'no';
	var val = fieldName.value;
	var len = val.length;

	// First make sure that the characters are integers
	if (stopped == 'no') {
		for (var i=0; i < len; i++) {
			if (stopped == 'no') {
				var c = val.charAt(i);
				if(c!="," && c!="."){
					var n = parseInt(c);
					if (isNaN(n)) {
						stopped = 'yes';
						alert('Please use numbers only');
						fieldName.focus();
						fieldName.value = "";				
					}
				}
			}
		}
	}
}

function checkNumberLength(fieldName,size)
{
	var stopped = 'no';
	var val = fieldName.value;
	var len = val.length;

	// First make sure that the characters are integers
	if (stopped == 'no') {
		for (var i=0; i < len; i++) {
			if (stopped == 'no') {
				var c = val.charAt(i);
				var n = parseInt(c);
				if (isNaN(n)) {
					stopped = 'yes';
					alert('Please use numbers only');
					fieldName.focus();
					fieldName.value = "";
				}
				// Now check to see that there are enough digits in each field
				else if (len != size) {
					stopped = 'yes';
					alert('This part of the number must be ' + size + ' digits long');
					fieldName.focus();
				}
			}
		}
	}
}

function checkEmail(fieldName)
{
	var email = fieldName.value;

	if (email.length > 0)
	{
		if ( (email.indexOf('@') < 0) ||
			((email.charAt(email.length-4) != '.') && (email.charAt(email.length-3) != '.')) )
		{
  			alert('Email Address is not correct');
  			fieldName.focus();
  		}
  	}
  	
  	checkUpper(fieldName);
}

function checkUpper(fieldName)
{
	fieldName.value = fieldName.value.toUpperCase();
}

function insertCommas(fieldName) {
   var num = fieldName.value;

   num = num.replace(/[^\d|.]+/g, "");

   if(isNaN(num)) {
      alert("Invalid number: " + num + ". Pease enter a number.");
      fieldName.focus();
      return "";
   }

   if(num != "")
   {
   	var regEx = /(-?\d+)(\d{3})/;
   	var is_neg= (num<0)? true:false;
   	var num = parseFloat(num);num=num.toString();
   	var end=(num.indexOf(".") <0)?"":num.substring(num.indexOf("."));
   	num= (end)?num.substring(0,num.length-end.length):num;
 
	   while (regEx.test(num)) {
      	num = num.replace(regEx, "$1,$2")
   	}

   	var result= (is_neg)?"-"+num.substring(1)+end:num+end;

   	return result;
   }

	return "";
}

function checkDate(fieldName)
{
	key = event.keyCode;
	
	if(key < 47 || key > 57)
	{
		alert("Please only input numbers or a '/'");
		event.returnValue = false;
		return false;
	}

	return true;
}

function checkValidDate(fieldName)
{
	key = event.keyCode;
	
	if(((key > 46 && key < 58) || key == 0) && fieldName.value != "")
	{
		len = fieldName.value;
		len = len.toString();
		
		if(len.length != 5)
		{
			alert('Please enter a valid date in the format (mm/yy)');
			fieldName.focus();
			fieldName.value = "";
			return;
		}
		
		if(fieldName.value.match(/.*\//) != "")
		{
			var head = fieldName.value.match(/.*\//);
			
			if(head != "" && head != null)
			{
				head = head.toString();
   			head = head.replace(/\//g, "");
   		}
   	}
		
		if(fieldName.value.match(/\/.*/) != "")
		{
			var tail = fieldName.value.match(/\/.*/);
			
			if(tail != "" && tail != null)
			{
				tail = tail.toString();
   			tail = tail.replace(/\//g, "");
   		}
   	}
	
		if(head.length != 2 || tail.length != 2 || head < 1 || head > 12 || tail < 0 || tail > 99)
		{
			alert('Please enter a valid date in the format (mm/yy)');
			fieldName.focus();
			fieldName.value = "";	
		}
	}
}

function checkPhoto(fieldName)
{
	var str = new String(fieldName.value);
	filetype = str.substring(str.length-3, str.length);
	filetype = filetype.toLowerCase();
 
  	if(fieldName.value != "" && filetype != "jpg" && filetype != "gif")
	{
		return false;
	}
	
	return true;
}