﻿function check_fields(object)
{
	if (object.name.value == '')
	{
		alert("Please fill your name");
		return false;
	}
	if (object.phone.value == '')
	{
		alert("Please fill your phone number");
		return false;
	}
	var mail = /^[\w\-]+(\.[\w\-]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/;
	if (!mail.test(object.email.value))
	{
		alert("E-mail Address wrong (ex: nom@provider.com)");
		return false;
	}
	if (!check_date(object.day.value, object.month.value, object.year.value))
	{
		alert("The date is not a valid day");
		return false;
	}
	if (!isNumeric(object.number.value))
	{
		alert("Please fill your phone number");
		return false;
	}
	return true;
}

var current_day = new Date();
var cday = current_day.getDate();
var cmonth = current_day.getMonth();
var cyear = current_day.getFullYear();

function event_day ()
{
	cday;
	for(var i = 1; i < 31 + 1; i++)
	{
		if (i == cday)
		{
			if (i < 10)
				document.write("<option value=0"+i+" selected=selected>0"+i+"</option>");
			else
				document.write("<option value="+i+" selected=selected>"+i+"</option>");
		}
		else
		{
			if (i < 10)
				document.write("<option value=0"+i+">0"+i+"</option>");
			else
				document.write("<option value="+i+">"+i+"</option>");
		}
	}
}

function event_month ()
{
	cmonth = cmonth + 1;
	for(var i = 1; i < 13; i++)
	{
		if (i == cmonth)
		{
			if (i < 10)
				document.write("<option value=0"+i+" selected=selected>0"+i+"</option>");
			else
				document.write("<option value="+i+" selected=selected>"+i+"</option>");
		}
		else
		{
			if (i < 10)
				document.write("<option value=0"+i+">0"+i+"</option>");
			else
				document.write("<option value="+i+">"+i+"</option>");
		}
	}
}

function event_year ()
{
	for(var i = cyear; i < (cyear + 10); i++)
	{
		if (i == cyear)
		{
			document.write("<option value="+i+" selected=selected>"+i+"</option>");
		}
		else
		{
			document.write("<option value="+i+">"+i+"</option>");
		}
	}
}

function event_hour ()
{
	for(var i = 9; i < 23; i++)
	{
		document.write("<option value="+i+">"+i+"</option>");
	}
}

function event_minute ()
{
	for(var i = 0; i < 60; i += 10)
	{
		document.write("<option value="+i+">"+i+"</option>");
	}
}

function check_date(d, m, y)
{
	var feb = 28;
	if (y % 4 == 0 || y % 400 == 0)
		feb = 29;
	var days = new Array(31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (d > 0 && d <= days[m - 1])
	{
		if ((d >= cday && m >= cmonth) || m > cmonth)
			return true;
	}
	return false;
}
