/* The format is in dd/mm/yyyy
 *
 */
var DATE_COMPARE_BAD_DATE = "00000000";
function validEventDate(dateStart)
{
	var valueStart;	
	valueStart = valueDate(dateStart);
	if (valueStart == DATE_COMPARE_BAD_DATE)
	{
		errorDateFormat();
		return false;
	}
	
	return true;
}
function valueDate(strDate)
{
	var dd, mm;
	var result = 0;
    
	if (strDate.length != 4)
		return DATE_COMPARE_BAD_DATE;

	dd = parseInt(strDate.substring(0,2), 10);
	mm = parseInt(strDate.substring(2,4), 10);
	
	if (isValidDateCombo(dd, mm) == false)
		return DATE_COMPARE_BAD_DATE;
	
	result += mm * 100;
	result += dd;
	return result;
}

function isValidDateCombo(dd, mm)
{
	if (isValidMonthYear(mm) == false)
		return false;
		
	var totalDays;
	totalDays = maxDay(mm);
	return isValidMinMax(dd, 1, totalDays);
	return false;
}

function isValidMonthYear(mm)
{	
	if (isValidMinMax(mm, 1, 12) == true)
		return true;
	return false;
}

function isValidMinMax(number, low, high)
{
	if (number < low)
		return false;
	if (number > high)
		return false;
	if ((number >= low) && (number <= high)) 
		return true;
	return false;
}

function maxDay(mm)
{
	switch(mm)
	{
		case 1:		case 3:		case 5: case 7:
		case 8:		case 10:	case 12:
			return 31;
		case 4:		case 6:		case 9:	case 11:
			return 30;
		case 2:
			return 29;
		default:
			return -1;
	}
}

function errorDateFormat()
{
	var message;
	message = "Please enter a valid event date.\n[ddmm]";
	alert(message);
}