function getYear(d) 
{ 
   return (d < 1000) ? d + 1900 : d;
}

function isDate (sFormat,Obj) 
{
	if (sFormat=='mm/dd/yy')
		reference=1
	if (sFormat=='dd/mm/yy')
		reference=2

   chuoi=Obj.split("/")
   if (reference==1) 
   {
	   month=chuoi[0]
	   day=chuoi[1]
	   year=chuoi[2]
   }
   else
   {
	   day=chuoi[0]
	   month=chuoi[1]
	   year=chuoi[2]		
   }
   if (year<100)
   {
   	year=parseInt(year)+2000
   } 
   month = month - 1;  // javascript month range : 0- 11
   var tempDate = new Date(year,month,day);
   if ( 
   		(getYear(tempDate.getYear()) == year)
   		&&(month == tempDate.getMonth())
		&&(day == tempDate.getDate())
	 )
   {    
	  return false;
	}  
   else
   {
	  return true;
	} 
}
function isBlank(str) {
	var len = str.length;
	var enter = 0;
     if(len == 0) {
     	return true;
     }
	  //Check if user only enter
	  for (i=0; i<len; i++) {
	  		if((str.charCodeAt(i) == 13)||(str.charCodeAt(i) == 10)||(str.charCodeAt(i) == 32)) {
	  			enter = 0;
	  		}
	  		else {
	  			return false;
	  		}
	  }	  
	  	return true;
}

function ConfirmDel()
{
var ok;
ok=window.confirm("Are you sure you want to delete these record?");
	if(ok)
		{
		return true;
		}
	else
	{
		return false;
		}
}
function ConfirmSaveAll()
{
var ok;
ok=window.confirm("Are you sure you want to modify these record?");
	if(ok)
		{
		return true;
		}
	else
	{
		return false;
		}
}
function ConfirmSubmit()
{
var ok;
ok=window.confirm("Are you sure you want to submit this form?");
	if(ok)
		{
		return true;
		}
	else
	{
		return false;
		}
}

function CompareDate( sStartDate, sEndDate)
{
var f, startDay, startMonth, startYear, endMonth, endDay, endYear, n1, n2,n3, n4;
n1 = sStartDate.indexOf( "/" );
n2 = sStartDate.lastIndexOf( "/" );
n3 = sEndDate.indexOf( "/" );
n4 = sEndDate.lastIndexOf( "/" );

startMonth = parseInt( sStartDate.substring( 0, n1  ),10);
startDay = parseInt( sStartDate.substring( n1 + 1, n2 ),10);
startYear = parseInt( sStartDate.substring( n2+1 ),10);

endMonth = parseInt( sEndDate.substring( 0, n3  ),10);
endDay = parseInt( sEndDate.substring( n3+1, n4 ),10);
endYear = parseInt( sEndDate.substring( n4+1 ),10);

if ( startYear > endYear ) return 1;
if ( startYear < endYear ) return -1;

if ( startMonth > endMonth ) return 1;
if ( startMonth < endMonth ) return -1;

if ( startDay > endDay ) return 1;
if ( startDay < endDay ) return -1;
return 0;} 

function isTime(timeStr) {

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0 || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using. OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
}
}
if (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

function isEmail(email) {   
	if (email == "")
		return false;
	if (email.indexOf(" ") > 0)	
		return false;
	if (email.indexOf("@") == -1)	
		return false;
	if (email.indexOf(".") == -1)	
		return false;
	if (email.indexOf("..") != -1)	
		return false;
	if (email.indexOf("@") != email.lastIndexOf("@"))		
		return false;
		
	var len = email.length;
	
	if (email.lastIndexOf(".") == len-1)
		return false;
	
	var str = "0123456789abcdefghikjlmnopqrstuvwxyz-@._";
	
	for (var index = 0; index < len; index++)
		if (str.indexOf(email.charAt(index)) == -1)
			return false;
			
	var indexDot = 	email.indexOf(".");
	var indexAcsign = email.indexOf("@");
	
	if ((indexDot == indexAcsign-1) || (indexDot-1 == indexAcsign))
		return false;
					
	return true;
}
