// Remove leading & trailing spaces from string
function trim(str) {
        var i = 0, j = str.length - 1;

        while(i < str.length && str.charAt(i) == ' ') i++;
        while(j > i && str.charAt(j) == ' ') j--;

        return str.substring(i, j + 1);
}

function is_HHMM_time(strtime) {
	 str = trim(strtime);

        if (str.length == 0)
                return true;

        r = new RegExp("([0-9]{1,2}):([0-9]{1,2})", "g");
	a = r.exec(str);

	if (a == null)
		return false;

	hour = a[1];
	minute = a[2];

	if ((hour > 24) || (minute > 59))
		return false;

	return true;
}

function is_DDMMYYYY_date(strdate) {
        str = trim(strdate);

        if (str.length == 0)
                return true;

        r = new RegExp("([0-9]{1,2})[-/]([0-9]{1,2})[-/]([0-9]{4})", "g");
        a = r.exec(str)
        
        if (a == null)
                return false;

        date = a[1];
        month = a[2] - 1;
        year = a[3];

        d = new Date(year, month, date);

        if ((d.getMonth() != month) || (d.getFullYear() != year) || (d.getDate() != date))
                return false;
        return true;
}

function is_empty_string(str) {
        return (trim(str).length == 0);
}

