function js_datetime(id)
{
        var strDateTime = document.getElementById(id).value;
        var result = true;
        var intIndex =-1;
        var regExpInfo=" ";
        var trimDateTime =null;
        if (strDateTime=="")
        {
             result = true;
        }
        else{
             intIndex=strDateTime.search(regExpInfo);
             if (intIndex == -1)
             {
                 result=false;
             }
            else{
                     trimDateTime =  new Array(strDateTime);
                     trimDateTime =  strDateTime.split(" "); 
                     if (trimDateTime.length !=2)
                     {
                          
                            result=false;
                     }
                     else {
                            
                            if (js_dateDDMMYY(trimDateTime[0], false) && js_time(trimDateTime[1],false)){
                                result = true;
                                 
                            } 
                            else{
                                result = false;
                            }
                     }
            }
       }
       if (result==false)
       {
                document.getElementById(id).style.backgroundColor = "#FFCCFF";
                alert("Error datetime: The field must only contain DateTime with the format of DD/MM/YY HH:MM");
//                document.getElementById(id).focus();
       }
       else
       {
                document.getElementById(id).style.backgroundColor = "white";
       }
        return result;
}






function js_time(id,showerr)
{
         var strCheckTime =null;
         var result = true;
         var intIndex =-1;
         var regExpInfo=":";
         var trimTime ="";
         if (document.getElementById(id)==null){
             strCheckTime = id;
         }
         else{
			 
             strCheckTime = document.getElementById(id).value;
         }
         if (strCheckTime=="")
         {

             result = true;
         }
         else if (strCheckTime.length!=5)
         {
             result = false;
         }
         else
	 {	
                intIndex=strCheckTime.search(regExpInfo);
                if (intIndex == -1)
                {
                        result=false;
                }
                else
                {
                        trimTime =  new Array(strCheckTime);
                        trimTime =  strCheckTime.split(":"); 
                       
                        if (trimTime.length >3)
                        {
                                result=false;
                              
                        }
                     
                        else{
                          
                                
                           if (parseInt(trimTime[0], 10) < 0  || parseInt(trimTime[0], 10) > 23) {
                               result = false;
                               
                            }   
                          
                          else if (parseInt(trimTime[1], 10)<0 || parseInt(trimTime[1], 10) > 59) {
                                result = false;
                           }
                          
                          else if ((isNaN(trimTime[0]))||(isNaN(trimTime[1]))){
                                 
                                 result = false;
                              
                           }
                          else{
                                 result = true;
                           }
                       }
                }
	}

        if (result==false && showerr!=false)
        {
                alert("Error: The field must only contain time with the format of HH:MM");
                if (document.getElementById(id)!=null){
                   document.getElementById(id).style.backgroundColor = "#FFCCFF";
                   document.getElementById(id).focus();
                }
        }
        else
        {
               if (document.getElementById(id)!=null){
                  document.getElementById(id).style.backgroundColor = "white";
               }
        }
        return result;
}




function js_dateDDMMYY(id,showerr)
{
		var strCheckDate =null;
		var result=true;
		var intIndex=-1;
		var arrDate;
		var regExpInfo="/";
		if (document.getElementById(id)==null){
             strCheckDate = id;
         }
         else{
             strCheckDate = document.getElementById(id).value;
         }
        if (strCheckDate=="")
        {
             result = true;
        }
		//blank field
		if (strCheckDate == "")
		{
			result=true;
		}
		//longer than 8
		else if (strCheckDate.length !=8)
		{
			result=false;
		}
		else
		{	
			intIndex=strCheckDate.search(regExpInfo);
			if (intIndex == -1)
			{
				result=false;
			}
			else
			{
				arrDate =  new Array(strCheckDate);
				arrDate = strCheckDate.split("/"); 
				if (arrDate.length != 3)
				{
					result=false;
				}
				else
				{
					//check year
					if ( fnIsIntNum(arrDate[2]))
					{
						if (parseInt(arrDate[2], 10) < 1 || parseInt(arrDate[2], 10) > 99) 
						{
							result = false;
						} 
					}
					else
					{
						result=false;
					}
					//check month
					if ( fnIsIntNum(arrDate[1]))
					{
						if (parseInt(arrDate[1],10) < 1 || parseInt(arrDate[1],10) > 12)
						{
							result = false;
						} 
					}
					else
					{
						result=false;
					}
					//check day
					if ( fnIsIntNum(arrDate))
					{
						var intDayCount = fnComputerDay(parseInt(arrDate[2], 10),parseInt(arrDate[1], 10));
						if(intDayCount < parseInt(arrDate[0], 10))
						{
							result = false;
						} 
					}
					else
					{
						result=false;
					}
				}
			}
		}
		if (result==false && showerr!=false)
		{
		    alert("Error: The field must only contain date with the format of DD/MM/YY");
		    if (document.getElementById(id)!=null){
			    document.getElementById(id).style.backgroundColor = "#FFCCFF";
//                            document.getElementById(id).focus();
			}
		}
		else
		{
		   if (document.getElementById(id)!=null){
			   document.getElementById(id).style.backgroundColor = "white";
			}
		}
		return result;
		
}

function fnIsIntNum(strNum)
{
	var strCheckNum = strNum + "";
	//if(strCheckNum.length < 1) //blank field
	//	return false;
	//else if(isNaN(strCheckNum)) //not number
	//	return false;
	//else if(parseInt(strCheckNum, 10) < 1) //not positive
	//	return false; 
	//else if(parseFloat(strCheckNum) > parseInt(strCheckNum, 10)) //not int
	//	return false;

	return true;
}

function fnComputerDay(intYear,intMonth)
{
	var dtmDate = new Date(intYear,intMonth,-1);
	var intDay = dtmDate.getDate() + 1;
	return intDay; 
}
