/* end date */
/*8-11-2011 17:00*/
/*30-11-2011 19:00*/
toYear=2011;
toMonth=11;
toDay=30;
toHour=18;
toMinute=59;
toSecond=59;

function countDown(){
	new_year=0;
	new_month=0;
	new_day=0;
	new_hour=0;
	new_minute=0;
	new_second=0;
	var actual_date=new Date();
	/*point_date = new Date();
	point_date.setFullYear(2011, 9, 27, 21, 59, 59);*/ 
	
	var point_date = new Date(2011, 10, 30, 18, 59, 59);
	if(dateComapreTo(point_date, actual_date) <= 0){
		$("#second").html("00");
		$("#minute").html("00");
		$("#hour").html("00");
		$("#day").html("00");
		
	}else{
		

		if(actual_date.getFullYear()>toYear){
			//si ya nos hemos pasado del aņo, mostramos los valores a 0
			document.forms.form.second.value=0;
			document.forms.form.minute.value=0;
			document.forms.form.hour.value=0;
			document.forms.form.day.value=0;
			document.forms.form.month.value=0;
			document.forms.form.year.value=0;
		}else{
			new_second=new_second+toSecond-actual_date.getSeconds();
			if(new_second<0)
			{
				new_second=60+new_second;
				new_minute=-1;
			}
			
			if(new_second < 10){
				$("#second").html("0"+new_second);
			}else{
				$("#second").html(new_second);
			}
	
			new_minute=new_minute+toMinute-actual_date.getMinutes();
			if(new_minute<0)
			{
				new_minute=60+new_minute;
				new_hour=-1;
			}
			
			if(new_minute < 10){
				$("#minute").html("0"+new_minute);
			}else{
				$("#minute").html(new_minute);
			}
	
			new_hour=new_hour+toHour-actual_date.getHours();
			if(new_hour<0)
			{
				new_hour=24+new_hour;
				new_day=-1;
			}
			if(new_hour < 10){
				$("#hour").html("0"+new_hour);
			}else{
				$("#hour").html(new_hour);
			}
	
			new_day=new_day+toDay-actual_date.getDate();
			if(new_day<0)
			{
				x=actual_date.getMonth();
				if(x==0||x==2||x==4||x==6||x==7||x==9||x==11){new_day=31+new_day;}
				if(x==3||x==5||x==8||x==10){new_day=30+new_day;}
				if(x==1)
				{
					//comprobamos si es un aņo bisiesto...
					if(actual_date.getYear()/4-Math.floor(actual_date.getYear()/4)==0)
					{
						actual_date=29+actual_date;
					}else{
						actual_date=28+actual_date;
					}
				}
			}
			
		    if(new_day < 10){
		    	$("#day").html("0"+new_day);
		    }else{
		    	$("#day").html(new_day);
		    }
	
			new_month=-1;
			new_month=new_month+toMonth-actual_date.getMonth();
			if(new_month<0)
			{
				new_month=11+new_month;
				new_year=-1;
			}
			  if(new_month < 10){
			    	$("#month").html("0"+new_month);
			    }else{
			    	$("#month").html(new_month);
			    }
	
			new_year=new_year+toYear-actual_date.getFullYear();
			if(new_year<0)
			{
				//document.forms.form.year.value=0;
			}else{
				//document.forms.form.year.value=new_year;
				//vuelve a ejecutar la funcion dentro de 1000 milisegundos = 1 segundo
				setTimeout("countDown()",1000);
			}
		}
	}
}

function dateComapreTo(fecha1, fecha2) {
	return fecha1.getTime() - fecha2.getTime();
}
