
/*
	  This function is used to validate dates 
	  param: array of ids of the controls that contain the dates in the order you which to validate 
	         in descending order (from older date to later date)
	  These controls must have attribute strname that contain the message of this control that will be
	  displayed in the alert
	  return true if all dates are valid
	  return false if some of the dates are invalid
	*/

	function validateDates(arr,str,enableEqual){
	
	   for(i=0;i<arr.length-1;i++)
	   {
		  
	      if(enableEqual==1)
	      {
	         if(convertDate(arr[i])>convertDate(arr[i+1]))
	         {
	        	 
	            
	             alert(document.getElementById(arr[i][0]).getAttribute("strname")+" "+str+" "+document.getElementById(arr[i+1][0]).getAttribute("strname"));
	             return false;
	         }
	       }
	       else
	       {
	          if(convertDate(arr[i])>=convertDate(arr[i+1]))
	         {
	        	 
	             alert(document.getElementById(arr[i][0]).getAttribute("strname")+" "+ str+" "+document.getElementById(arr[i+1][0]).getAttribute("strname"));
	             return false;
	         }
	       
	       }
	   } 
	   return true;
	}	
	
	/*
	 This function is used to split the string that contain the date and convert it into a date
	*/
	function convertDateEmam(MyDate)
	{
		MD_Y=MyDate.substring(6,10);
		MD_D=MyDate.substring(0,2); 
		MD_M=MyDate.substring(3,5);
		
		MD_H=0   
		MD_N=0;  
		MD_S=0;
	    MD_M=MD_M-1; 
		newDate=new Date(MD_Y, MD_M, MD_D, MD_H, MD_N, MD_S);
		return newDate;
	}
	/*
	 This function is used to split the string that contain the date and convert it into a date
	*/
	function convertDate(MyDate)
	{
	
	 var hour=0;
	 var min=0;
	 var amPm=0;
	 
	 var date = document.getElementById(MyDate[0]).value;
	 
	 if(MyDate[1]!=0){
	  	hour = document.getElementById(MyDate[1]).value;
	  }
	  if(MyDate[2]!=0){
	  	min = document.getElementById(MyDate[2]).value;
	  }
	  if(MyDate[3]!=0){
	  	amPm = document.getElementById(MyDate[3]).value;
	  }
	
	 if(amPm==1){
		 if(hour !=12)
	 	hour=eval(hour)+12;
	 }
	 
	 var arr=date.split("/"); 
	 
	 
	 MD_Y=arr[2];
	 MD_D=arr[0];
	 MD_M=arr[1];
	 MD_H=hour;  
	 MD_N=min;  
	 MD_S=0;
     MD_M=MD_M-1; 
	 newDate=new Date(MD_Y, MD_M, MD_D, MD_H, MD_N, MD_S);
	 return newDate;
	}
	//---------------------------------------------------------------------------------------------------------------------------------
	
	/*
	 This function is used to split the string that contain the date and convert it into a date
	*/
	function convertDateWithNoTime(MyDate)
	{
	 var arr=MyDate.split("/");
	 MD_Y=arr[2];
	 MD_D=arr[0];
	 MD_M=arr[1];
		MD_H=0   
		MD_N=0;  
		MD_S=0;
	    MD_M=MD_M-1; 
		newDate=new Date(MD_Y, MD_M, MD_D, MD_H, MD_N, MD_S);
		return newDate;
	}
