
function get_today_date()
{
	var all_date = new Array();;
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth() + 1;
	var day=now.getDate();
	var hours=now.getHours();
	var minutes=now.getMinutes();
	var seconds=now.getSeconds();
	
	all_date["now"]=now;    
	all_date["year"]=year;     
	all_date["month"]=month;     
	all_date["day"]=day;     
	all_date["hours"]=hours;     
	all_date["minutes"]=minutes;     
	all_date["seconds"]=seconds;         
	
	return all_date;
}

function get_date_different(from, to)
{
	var from_date = new Array()
	var to_date = new Array()
	
	for ( var i in from )
	{
		from_date[i] = from[i]
	} 
	for ( var i in to )
	{
		to_date[i] = to[i]
	} 
	
	var date_diff = new Array()

	if(from_date["seconds"] != undefined && to_date["seconds"] != undefined)
	{
		date_diff["seconds"] = substract(from_date["seconds"], to_date["seconds"], 60)
		if(date_diff["seconds"] < 0)
		{
			date_diff["seconds"] = date_diff["seconds"] * -1
			if(to_date["minutes"] > 0)
			{
				to_date["minutes"]--
			}
			else if(to_date["hours"] > 0)
			{
				to_date["hours"]--
			}
			else if(to_date["day"] > 0)
			{
				to_date["day"]--
			}
			else if(to_date["month"] > 0)
			{
				to_date["month"]--
			}
			else if(to_date["year"] > 0)
			{
				to_date["year"]--
			}
		}
	}
	if(from_date["minutes"] != undefined && to_date["minutes"] != undefined)
	{
		date_diff["minutes"] = substract(from_date["minutes"], to_date["minutes"], 60)
		if(date_diff["minutes"] < 0)
		{
			date_diff["minutes"] = date_diff["minutes"] * -1
			if(to_date["hours"] > 0)
			{
				to_date["hours"]--
			}
			else if(to_date["day"] > 0)
			{
				to_date["day"]--
			}
			else if(to_date["month"] > 0)
			{
				to_date["month"]--
			}
			else if(to_date["year"] > 0)
			{
				to_date["year"]--
			}
		}
	}
	if(from_date["hours"] != undefined && to_date["hours"] != undefined)
	{
		date_diff["hours"] = substract(from_date["hours"], to_date["hours"], 24)
		if(date_diff["hours"] < 0)
		{
			date_diff["hours"] = date_diff["hours"] * -1
			if(to_date["day"] > 0)
			{
				to_date["day"]--
			}
			else if(to_date["month"] > 0)
			{
				to_date["month"]--
			}
			else if(to_date["year"] > 0)
			{
				to_date["year"]--
			}
		}
	}
	if(from_date["day"] != undefined && to_date["day"] != undefined)
	{
		if(to_date["month"] == 1 || to_date["month"] == 2 || to_date["month"] == 4 || to_date["month"] == 6 || to_date["month"] == 8 || to_date["month"] == 9 || to_date["month"] == 11)
		{
			date_diff["day"] = substract(from_date["day"], to_date["day"], 31)
		}
		else
		{
			date_diff["day"] = substract(from_date["day"], to_date["day"], 30)
		}
		if(date_diff["day"] < 0)
		{
			date_diff["day"] = date_diff["day"] * -1
			if(to_date["month"] > 0)
			{
				to_date["month"]--
			}
			else if(to_date["year"] > 0)
			{
				to_date["year"]--
			}
		}
	}
	if(from_date["month"] != undefined && to_date["month"] != undefined)
	{
		date_diff["month"] = substract(from_date["month"], to_date["month"], 12)
		
		if(date_diff["month"] < 0)
		{
			date_diff["month"] = date_diff["month"] * -1
			if(to_date["year"] > 0)
			{
				to_date["year"]--
			}
		}
	}
	if(from_date["year"] != undefined && to_date["year"] != undefined)
	{
		date_diff["year"] = substract(from_date["year"], to_date["year"], 0)
	}
	
	return date_diff
}

function substract(from, to, length)
{
	if(to >= from)
	{
		return  to - from
	}
	else
	{
		return (to + length - from) * -1
	}
}

function check_if_all_date_set(date)
{
	if(!date["year"])
	{
		date["year"] = 0
	}
	if(!date["month"])
	{
		date["month"] = 0
	}
	if(!date["day"])
	{
		date["day"] = 0
	}
	if(!date["hours"])
	{
		date["hours"] = 0
	}
	if(!date["minutes"])
	{
		date["minutes"] = 0
	}
	if(!date["seconds"])
	{
		date["seconds"] = 0
	}
}