function verify(theForm)
	{
	for (i = 0; i < theForm.length; i++)
		{	if (theForm.elements[i].getAttribute("notnull") == 1)
			{	if (!NotEmptyValid(theForm.elements[i].value))
				{	alert("Please enter value for '"+theForm.elements[i].getAttribute("alt")+"' field.")
					theForm.elements[i].focus()
					return false
				}
			}
	
			if (theForm.elements[i].getAttribute("email") == 1)
			{	if (!EmailValid(theForm.elements[i].value))
				{	alert("Invalid email address.")
					theForm.elements[i].focus()
					return false
				}
			}
			
			if (theForm.elements[i].getAttribute("int") == 1)//check for integer characters
			{	if (!IntValid(theForm.elements[i].value))
				{	alert("Invalid integer number.")
					theForm.elements[i].focus();
					return false;
				}
			}
	
			if (theForm.elements[i].getAttribute("float") == 1)
			{	if (!FloatValid(theForm.elements[i].value))
				{	alert("Invalid float number.")
					theForm.elements[i].focus();
					return false;
				}
			}
	
			if (theForm.elements[i].getAttribute("date") == 1)
			{	if (!dateValid(theForm.elements[i].value))
				{	alert("Invalid date format.")
					theForm.elements[i].focus();
					return false;
				} 
			}
	
			if (theForm.elements[i].getAttribute("time") == 1)
			{	if (!timeValid(theForm.elements[i].value))
				{	alert("Invalid time format.")
					theForm.elements[i].focus();
					return false;
				}
			}
		}
		return true
	}

function NotEmptyValid(str)
{	return (Trim(str)!='');
}
//End check form

function Trim(str)
{	return str.replace(/^\s*|\s*$/g, '');
}

function replaceAll(content, s1, s2)
{	return content.split(s1).join(s2); //content.replace((new RegExp(s1, 'g')), s2);
}

function isNumeric(str)
{	var iLen;
	iLen=str.length;
	var c ;
	for(var i=0; i<iLen; i++)
	{	c = str.charAt(i);
		if ((c<'0') || (c>'9'))
			return false;
	}
	return true;
}

function isNull(str)
{	
	if(str==null)
		return true;
	var iLen = str.length;
	for (var i = 0; i < iLen; i++)
		if (str.charAt(i)!= ' ')
			return false;
	return true;
}

function Trim(str)
{
	while((str.length > 0) && (str.charAt(0) == ' '))
			str = str.substring(1,str.length);
	while((str.length > 0) && (str.charAt(str.length-1) == ' '))
			str = str.substring(0,str.length-1);
	return str;
}

/************************************************
DESCRIPTION: 
	Validates that a string contains only valid integer number.
PARAMETERS:
	str - String to be tested for validity.
RETURNS:
   True if valid, otherwise false.
******************************************************************************/
function IntValid(str)
{	if (str=='') return true;

	var objRegExp  = /(^-?\d\d*$)/; 
	//check for integer characters
	return objRegExp.test(str);
}

/******************************************************************************
DESCRIPTION:
	Validates that a string contains only valid numbers.
PARAMETERS:
	str - String to be tested for validity.
RETURNS:
	True if valid, otherwise false.
******************************************************************************/
function FloatValid(str)
{	if (str=='') return true;

	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	//check for numeric characters
	return objRegExp.test(str);
}

function dateValid(thefield)
{	
	var dateStr = Trim(thefield.value);
	if (isNull(dateStr))
		return true;
	var i1 = dateStr.indexOf("/");
	var j1 = dateStr.indexOf("/", i1 + 1);
	if ((i1 == -1) || (j1 == -1))
		return false;
	var month = parseInt(dateStr.substr(0, i1), 10);
	var day = parseInt(dateStr.substr(i1 + 1, j1 - i1 - 1), 10);
	var year = parseInt(dateStr.substr(j1 + 1), 10);
	if ((month < 1) || (month > 12))
		return false;
	if (isNaN(day) || isNaN(month) || isNaN(year) || (year < 0)) 		
		return false;
	if (year < 30)
		year += 2000;
	else if (year < 100)
		year += 1900;
	var DOM = 31;
	switch(month)
	{
		case 2:
			DOM = ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) ? 29 : 28;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			DOM = 30;break;
		default:
			DOM = 31;
	}
	if ((day < 1) || (day > DOM))
		return false;
	thefield.value = ((month < 10)?"0"+month:month) + "/" + ((day<10)?"0"+day:day)+"/"+year;
	return true;
}

function timeValid(thefield)
{	var timeStr = Trim(thefield.value);
	var i1 = timeStr.indexOf(":");
	var j1 = timeStr.indexOf(":", i1 + 1);
	if ((i1 == -1) || (j1 == -1))
		return false;
	var day = parseInt(dateStr.substr(0, i1), 10);
	var month = parseInt(dateStr.substr(i1 + 1, j1 - i1 - 1), 10);
	var year = parseInt(dateStr.substr(j1 + 1), 10);

	var hour = parseInt(timeStr.substr(0, i1), 10)
	var minute = parseInt(timeStr.substr(i1+1, j1 - i1 - 1), 10)
	var second = parseInt(timeStr.substr(j1+1), 10)

	if (isNaN(hour) || isNaN(minute) || isNaN(second)) 		
		return false;
	if(hour < 0 || hour >12)
		return false;
	if(minute < 0 || hour >59)
		return false;
	if(second < 0 || second >59)
		return false;
	return true
}

function EmailValid(str)
{	if (str=='') return true;
	
	var objRegExp = /^([a-z_][a-z_0-9\-]*)(([\.][a-z_0-9]+)*)@([a-z_][a-z_0-9\-]*)(([\.][a-z_0-9]+)*)([\.][a-z]{2,3})$/i;
  	//check for valid email
  	return objRegExp.test(str);
}