// Helping function for CompareDates
function ReplaceMonth(strDate)
{
	var arrAlphaMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var arrMonths = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
	for (var i = 0; i < arrAlphaMonths.length; i++)
		strDate = strDate.replace(arrAlphaMonths[i], arrMonths[i]);				
	return strDate;
}

// Function to check dates begins supported format "13-Jul-2008"
function CompareDates(strDateFrom, strDateTo)
{	
    var d1_str = ReplaceMonth(strDateFrom);
    var d2_str = ReplaceMonth(strDateTo);
    
    var d1 = new Date(d1_str.split('-')[2],d1_str.split('-')[1],d1_str.split('-')[0]);
    var d2 = new Date(d2_str.split('-')[2],d2_str.split('-')[1],d2_str.split('-')[0]);

    if (d1.getTime() >= d2.getTime())
	    return false;
    else
	    return true;
}

function CompareDatesFromOld(strDateFrom, strDateTo)
{	
    var d1_str = (strDateFrom);
    var d2_str = (strDateTo);
    
    var d1 = new Date(d1_str.split('-')[0],d1_str.split('-')[1],d1_str.split('-')[2]);
    var d2 = new Date(d2_str.split('-')[0],d2_str.split('-')[1],d2_str.split('-')[2]);

	
    if (d1.getTime() < d2.getTime())
	{
		return false;
	}
    else
	{
		return true;
	}
}
// Function to check dates ends

// Function to check date formats starts
function CheckDateFormat(src)
{
	var dateReg = new RegExp("((31(?!-(Feb|Apr|Jun|(Sep|Nov))))|((30|29)(?!-Feb))|(29(?=-Feb-(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])-(Jan|Feb|Ma(r|y)|Apr|Jul|Jun|Aug|Oct|Sep|Nov|Dec)-((1[6-9]|[2-9]\\d)\\d{2})");
	var regex = new RegExp(dateReg);
	if (regex.test(src))
	{
	    var date_array = src.split('-');
      var day = date_array[0];
      
      // Attention! Javascript consider months in the range 0 - 11
      var month = ReplaceMonth(date_array[1]) - 1;
      var year = date_array[2];

      // This instruction will create a date object
      source_date = new Date(year, month, day);
      
      if(year != source_date.getFullYear())
         return false;

      if(month != source_date.getMonth())
         return false;

      if(day != source_date.getDate())
         return false;
         
      return true;   
	}  
  else 
    return false;
}