function verify(theForm)
{	for (i = 0; i < theForm.length; i++)
		{	
		//alert(theForm.elements[i].value)
			if (theForm.elements[i].attributes.getNamedItem('notnull') != null)
			{	{	
					if (theForm.elements[i].value == "")
					{	
						
						if (theForm.elements[i].attributes.getNamedItem('alt') != null)
							alert("Vui lòng nhập giá trị cho trường '"+theForm.elements[i].alt+"'.")
						else
							alert("Vui lòng nhập giá trị cho trường '"+theForm.elements[i].title+"'.")					
						theForm.elements[i].focus()
						return false
					}
				}
			}
			
			if (theForm.elements[i].attributes.getNamedItem('checkexistfile') != null)
			{
				if (theForm.elements[i].value !='' && theForm.elements[i].value !='ok')
					{	alert("File '"+theForm.elements[i].alt+"' không tồn tại. Vui lòng chọn file khác.")
							return false
					}
			}
			
			if (theForm.elements[i].attributes.getNamedItem('strvalid') != null)
			{	if (!StringValid(theForm.elements[i].value))            /* Date : 27/04/2007            */
				{	alert("Vui lòng nhập lại dữ liệu không có các ký tự đặc biệt.")                            /* Comment : test invalid of string */
					theForm.elements[i].focus()
					return false
				}
			}
					
			if (theForm.elements[i].attributes.getNamedItem('email') != null && theForm.elements[i].value != "")
			{	if (!EmailValid(theForm.elements[i].value))
				{	alert("Địa chỉ Email không hợp lệ.")
					theForm.elements[i].focus()
					return false
				}
			}
		
			if (theForm.elements[i].attributes.getNamedItem('upload_zip_file') != null)
			{	//alert(theForm.elements[i].value);
				if (theForm.elements[i].value != "")
				{	
					var arr = new Array('.zip');
					var src;
					src=theForm.elements[i].value;
					for(i=0;i<arr.length;i++)
					{	if(src.lastIndexOf(arr[i]) == -1) //tim thay
						{
							alert('Vui lòng upload file có đuôi mở rộng là .zip');
							theForm.elements[i].focus()
							return false;			
						}
						
					}
						
				}
			}		
			
			if (theForm.elements[i].attributes.getNamedItem('upload_template_file') != null)
			{	//alert(theForm.elements[i].value);
				if (theForm.elements[i].value != "")
				{	
					var arr = new Array('.tpl');
					var src;
					src=theForm.elements[i].value;
					for(i=0;i<arr.length;i++)
					{	if(src.lastIndexOf(arr[i]) == -1) //tim thay
						{
							alert('Vui lòng upload file có đuôi mở rộng là .tpl');
							theForm.elements[i].focus()
							return false;			
						}
						
					}
						
				}
			}	
			
			if (theForm.elements[i].attributes.getNamedItem('number') != null)
			{	if (isNull(Trim(theForm.elements[i].value)))
					theForm.elements[i].value = 0
				else
				if (!NumberValid(theForm.elements[i]))
				{	alert("Giá trị không hợp lệ.")
					theForm.elements[i].focus()
					if (typeof(theForm.elements[i].defaultvalue) != "undefined")
						theForm.elements[i].value = theForm.elements[i].defaultvalue
					else
						theForm.elements[i].value = "0"
					return false
				} 
				else theForm.elements[i].value = parseInt(theForm.elements[i].value)
			}			

			if (theForm.elements[i].attributes.getNamedItem('float') != null)			
			{	if (!FloatValid(theForm.elements[i]))
				{	alert("Số thực không hợp lệ.")
					theForm.elements[i].focus()
					return false
				} 
				else theForm.elements[i].value = parseFloat(theForm.elements[i].value)
			}
			
			if (theForm.elements[i].attributes.getNamedItem('date') != null)			
			{	if (!dateValid(theForm.elements[i]))
				{	alert("Gia tri ngay khong hop le.")
					theForm.elements[i].focus()
					return false
				} 
			}
			/*
				Modifile: Nguyen Thi Tu Trinh
				Date: 27/04/2007
				Comment: check length of Password
			*/
			if (theForm.elements[i].attributes.getNamedItem('password') != null)			
			{	
				if (theForm.elements[i].value.length <4 )
				{	alert("Mật khẩu quá ngắn.")
					theForm.elements[i].focus()
					return false
				}
			}
			
			if (theForm.elements[i].attributes.getNamedItem('password') != null)			
			{	
				if (theForm.elements[i].value.length > 32 )
				{	alert("Mật khẩu quá dài.")
					theForm.elements[i].focus()
					return false
				}
			}

			if (theForm.elements[i].attributes.getNamedItem('pwdconfirm') != null)			
			{	if (theForm.elements[i].value != theForm.password.value)
				{	alert("Mật khẩu xác nhận lại không trùng khớp với mật khẩu chỉ định.\r\n Vui lòng xác nhận lại mật khẩu.")
					//alert("sise");
					theForm.elements[i].focus()
					return false
				}
			}			
		}
		return true
	}

function trim(str)
	{	var i, j
		for (i = 0; i < str.length; i++)
			if (str.charAt(i) != ' ') break;
		for (j = str.length - 1; j >= 0; j--)
			if (str.charAt(j) != ' ') break;
		return str.substr(i, j - i + 1)
	}

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 isFloat(str)
{	var f = str.indexOf('.')
	var l = str.lastIndexOf('.')
	if (f != l)
		return false
	var iLen;
	iLen=str.length;
	var c ;
	for(var i = 0; i<iLen; i++)
	{	c = str.charAt(i);
		if (((c < '0') || (c > '9')) && (c != '.'))
			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;
}

function NumberValid(thefield)
{	var NumStr = Trim(thefield.value)
	if (isNull(NumStr))
	{
		return true
	}
	if (isNaN(parseInt(NumStr)))
		return false
	return true
}

function FloatValid(thefield)
{	var NumStr = Trim(thefield.value)
	if (isNull(NumStr))
		return false
	if (isNaN(parseFloat(NumStr)))
		return false
	return true
}

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 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);
	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 = ((day<10)?"0"+day:day)+"-"+((month < 10)?"0"+month:month)+"-"+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(a)	
{	myexp = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if (a.toString().match(myexp)) return true;
	return false;
}

/*
function EmailValid(str)
{	if(isNull(str))
		return true;
	var chrs = "~`!#$%^&*()+=|\{}[]':;<>\",/?";
	for(var i = 0; i < chrs.length; i++)
		if(str.indexOf(chrs.charAt(i)) < 0)
			continue;
		else
			return false;	
	var i = str.indexOf("@"), j = str.indexOf("."), k = str.indexOf("@", i + 1)
	if ((i == -1) || (j == -1) || (str.charAt(str.length-1) == '.') || (k >= 0))
		return false;	
	return true;
}
*/


/* Creat by : TRan Thi Thu Hien */
 /* Date : 27/04/2007            */
 /* Comment : test invalid of string */
function StringValid(str)
{	if(isNull(str))
		return true;
	var chrs = "<\>@~`!#$%^&*()+=|\{}[]':;<>\",/?";
	for(var i = 0; i < chrs.length; i++)
		if(str.indexOf(chrs.charAt(i)) < 0)
			continue;
		else
			return false;	
  return true;
}
function my_alert(mess)
{	if (mess != '')
		alert(mess);
}

function setchildOff(rows, i, parent_id)
{	
/*Trinh Update: 19/06/2007*/
	for (var j = i;  j < rows.length; j++)
	{	var getAttributes = document.getElementById(rows[j].id).attributes
		if (getAttributes.getNamedItem("parent_id").value== parent_id) // old source: if (rows[j].parent_id == parent_id)
		{	
			rows[j].curStat = rows[j].style.display
			rows[j].style.display = 'none'
			setchildOff(rows, j + 1, rows[j].id)
		}
	}
}

function setchildOn(rows, i, parent_id)
{	/*Trinh Update: 19/06/2007*/
	for (var j = i;  j < rows.length; j++)
	{	var getAttributes = document.getElementById(rows[j].id).attributes
		if (getAttributes.getNamedItem("parent_id").value== parent_id) // old source: if (rows[j].parent_id == parent_id)
		{	if (typeof(rows[j].curStat) == 'undefined')
				rows[j].style.display = ''
			else
				rows[j].style.display = rows[j].curStat
			rows[j].curStat = ''
			setchildOn(rows, j + 1, rows[j].id)
		}
	}
}

function ShowHide(what, parent_id, id_listTable)
{	src = what.src;
	//Old source: theTable = document.getElementById('listTable');
	theTable = document.all ? document.all[id_listTable] : document.getElementById ?document.getElementById(id_listTable) : null; // no access
	if (theTable) 
	{
		theRows = theTable.rows;
		if (src.indexOf('m.gif') >= 0)
		{	what.src = imgDir + 'p.gif';
			setchildOff(theRows, 1, parent_id)
		}
		else
		{	what.src = imgDir + 'm.gif';
			setchildOn(theRows, 1, parent_id)
		}
	}
}

function checkValidDate(start_date, end_date)
{
	if(document.getElementById(start_date).value > document.getElementById(end_date).value )
	{
		alert("Vui lòng nhập giá trị cho trường '"+document.getElementById(start_date).alt+"' nhỏ hơn hoặc bằng giá trị của '"+document.getElementById(end_date).alt+"'")
		return false;	
	}
	return true;
}
	
function inputMask(input, mask)
{	
	var index = 0;
	var len = input.value.length;
		
	while ((index < len) && (len != 0))
		if (mask.indexOf(input.value.charAt(index)) == -1)
		{
			if (index == len-1)
				input.value = input.value.substring(0, len-1);
			else if (index == 0)
				 	input.value = input.value.substring(1, len);
				 else input.value = input.value.substring(0, index)+input.value.substring(index+1, len);
			index = 0;
			len = input.value.length;
		}
		else index++;
}