function toDateString(oDay, oMonth, oYear) {
	return oDay.options[oDay.selectedIndex].value + "/" + oMonth.options[oMonth.selectedIndex].value + "/" + oYear.options[oYear.selectedIndex].value;
}

function isDateSelect(oDay, oMonth, oYear) {
	return isDate(toDateString(oDay, oMonth, oYear), "/");
}

function isDate(sDate, sSep, bWithHour, bWithMin) {
	if ( arguments.length < 2 ) {
		sSep = "/";
	}
	if ( arguments.length < 3 ) {
		bWithHour = false;
	}
	if ( arguments.length < 4 ) {
		bWithMin = false;
	}
	return !BadDate(sDate, sSep, bWithHour, bWithMin);
}

function parseDate(sDate, sSep) {
	if ( arguments.length < 2 ) {
		sSep = "/";
	}
	var j, m, y, h, mn;
	if ( sSep == "" ) {
		j = sDate.substr(0,2);
		m = sDate.substr(2,2);
		y = sDate.substr(4,4);
	} else {
		j = parseInt(sDate.substring(0,sDate.indexOf("/")),10);
		m = parseInt(sDate.substring(sDate.indexOf("/")+1,sDate.lastIndexOf("/")),10);
		y = sDate.substring(sDate.lastIndexOf("/")+1,sDate.length);
		if ( y.indexOf(" ") == -1 ) {
			h = 0;
			mn = 0;
			y = parseInt(y,10);
		} else {
			h = y.substring(y.indexOf(" ")+1, y.length);
			y = parseInt(y.substring(0, y.indexOf(" ")), 10);
			if ( h.indexOf(":") == -1 ) {
				mn = 0;
				h = parseInt(h,10);
			} else {
				mn = parseInt(h.substring(h.indexOf(":")+1, h.length),10);
				h = parseInt(h.substring(0, h.indexOf(":")),10);
			}
		}
	}
	dDate = new Date(y, m-1, j, h, mn);
	return dDate;
}

function BadDate(sDate, sSep, bWithHour, bWithMin) {
	if ( arguments.length < 2 ) {
		sSep = "/";
	}
	if ( arguments.length < 3 ) {
		bWithHour = false;
	}
	if ( arguments.length < 4 ) {
		bWithMin = false;
	}
	var j, m, y, a;
	if ( sSep == "" ) {
		j = sDate.substr(0,2);
		m = sDate.substr(2,2);
		y = sDate.substr(4,4);
	} else {
		if ( String.prototype.split ) {
			a = sDate.split("/");
			if ( a.length != 3 ) {
				return true;
			}
			j = a[0];
			m = a[1];
			y = a[2];
		} else {
			j = sDate.substring(0,sDate.indexOf("/"));
			m = sDate.substring(sDate.indexOf("/")+1,sDate.lastIndexOf("/"));
			y = sDate.substring(sDate.lastIndexOf("/")+1,sDate.length);
		}
		if ( bWithHour ) {
			h = null;
			mn = null;
			if ( y.indexOf(" ") == -1 ) {
				h = "";
				mn = "";
			} else {
				var h = y.substring(y.indexOf(" ")+1, y.length);
				y = y.substring(0, y.indexOf(" "));
				if ( bWithMin ) {
					if ( h.indexOf(":") == -1 ) {
						mn = "";
					} else {
						var mn = h.substring(h.indexOf(":")+1, h.length);
						h = h.substring(0, h.indexOf(":"));
						mn = parseInt(mn,10);
					}
				}
				h = parseInt(h,10);
			}
		} else {
			y = parseInt(y,10);
		}
	}
	for ( i = 0;i<sDate.length;i++) {
		if ( isNaN(parseInt(sDate.charAt(i))) && (sDate.charAt(i) != '/') && ((bWithHour || bWithMin) && (sDate.charAt(i) != ' ') && (sDate.charAt(i) != ':')) )
			return true;
	}
	if ( isNaN(j) || isNaN(m) || isNaN(y) ) {
		return true;
	}
	j = parseInt(j,10);
	m = parseInt(m,10);
	if ( (j<1) || (j>31) )
		return true;
	if ( (m<1) || (m>12) )
		return true;
	if  ( ((m == 4) || (m == 6) || (m == 9) || (m == 11)) && (j == 31) )
		return true;
	if ( (m == 2) && (j == 29) && !( (y%400 == 0) || ( (y%4 == 0) && y%100 ) ) )
		return true;
	if ( (m == 2) && (j > 29) )
		return true;
	if ( bWithHour ) {
		if ( isNaN(h) != isNaN(mn) ) {
			return true;
		}
		if ( !isNaN(h) && ((h < 0) || (h > 23)) ) {
			return true;
		}
		if ( !isNaN(mn) && (mn < 0) || (mn > 59) ) {
			return true;
		}
	}
	return false;
}

function dateDiff (strDDeb, strDFin)
{
	if ( strDDeb.indexOf("/") != -1 ) {
		sSep = "/";
	} else {
		sSep = "";
	}
	dDeb = parseDate(strDDeb, sSep);
	dFin = parseDate(strDFin, sSep);
	return (dDeb - dFin);
}

