function emptyfield(dataField) 
{
	if (Trim(dataField.value).length < 1)
		return true;
	else
		return false;
}

function isNumeric(dataField)
{
	if(isNaN(parseFloat(dataField.value)))
		return false;
	else
		return true;
}		

function filenameOK(filename)
{
	filename = filename.toUpperCase();
	if(Trim(filename) != "NONE") 
	{
		filetyp = filename.substring(filename.lastIndexOf("."), filename.length);
		if(filetyp.length!=0)
		{
			if ((filetyp != ".GIF") && (filetyp != ".JPG")) 
			{
				alert("Only GIF or JPG images may be used!");		
				return false;
			}
		}
	}
	return true;
}

function filenameZipOK(filename)
{
	if(filename.toUpperCase() != "NONE") {
		filetyp = filename.substring(filename.lastIndexOf("."), filename.length);
		if(filetyp.length!=0){
			if ((filetyp != ".zip") && (filetyp != ".ZIP")) {
				alert("Only ZIP files may be uploaded!");		
				return false;
			}
		}
	}
	return true;
}

function filenamePdfOK(filename)
{
	if(filename.toUpperCase() != "NONE") {
		filetyp = filename.substring(filename.lastIndexOf("."), filename.length);
		if(filetyp.length!=0){
			if ((filetyp != ".pdf") && (filetyp != ".PDF")) {
				alert("Only PDF files may be uploaded!");		
				return false;
			}
		}
	}
	return true;
}

function filenameBisOK(filename)
{
	if(filename.toUpperCase() != "NONE") {
		filetyp = filename.substring(filename.lastIndexOf("."), filename.length);
		if(filetyp.length!=0){
			if ((filetyp != ".bis") && (filetyp != ".BIS") && (filetyp != ".zip") && (filetyp != ".ZIP")) {
				alert("Only BIS or ZIP files may be uploaded!");		
				return false;
			}
		}
	}
	return true;
}

function emailOK(email)
{
	parts=email.split("@");
	if (parts.length>0)
	{
		if (parts[0].length>0)
		{
			domain=parts[1].split(".");
			if (domain.length>0)
			{
				if(domain[0].length>0  && domain[domain.length-1].length>0) {
					return true;
				}
			}
		}
	}
	return false;
}

function isValidDate(strD)
{
	var strDate = Trim(strD);
	var isOk = true;
	var pos1 = strDate.indexOf('/');
	var pos2 = strDate.indexOf('/', pos1+1);
	
	var dd, mm, yyyy;
	
	if(isOk && ((pos1 == -1) || (pos2 == -1))) { isOk = false; }
	
	if(isOk)
	{
		// get and pre-check day (dd)
		dd = Trim(strDate.substring(0,pos1));
		if(dd.charAt(0) == '0')
		{
			dd = dd.charAt(1);
		}

		if((dd == '') || isNaN(parseInt(dd))) { isOk = false; }
		else
		{
			dd = parseInt(dd);
			if(dd > 31 || dd < 1) isOk = false;
		}
	
		// get and pre-check month (mm)
		mm = Trim(strDate.substring(pos1+1,pos2));
		
		if(mm.charAt(0) == '0')
		{
			mm = mm.charAt(1);
		}

		if(isOk && ((mm == '') || isNaN(parseInt(mm)))) { isOk = false; }
		else
		{
			mm = parseInt(mm);
			if(mm < 1 || mm > 12) isOk = false;
		}

		// get and pre-check year (yyyy)
		yyyy = Trim(strDate.substr(pos2+1,strDate.length));
		if(isOk && ((yyyy == '') || isNaN(parseInt(yyyy))))	{ isOk = false; }
		else
		{
			yyyy = parseInt(yyyy);
			if(yyyy < 2003 || yyyy > 2099) { isOk = false; }
		}
	}

	// check for valid dd as per mm
	if(isOk && mm == 2) //Febraury
	{
		tmpYYYY = yyyy/4;
		if((((yyyy/4) - Math.floor(yyyy/4)) > 0) && (dd > 28)) { isOk = false; }
	}
	// 30 Days has September, April, June and November
	else if(isOk && ((mm == 9) || (mm == 4) || (mm == 6) || (mm == 11)) && (dd > 30)) { isOk = false; }
	else {/* all the rest have 31 - checked */ }
	
	//alert('isValidDate = ' + isOk);		 
	return isOk;
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


