//variables que determinan la fecha y hora final de la cuenta atras
toYear=2009;
toMonth=5;
toDay=11;
toHour=23;
toMinute=59;
toSecond=59;

function countDown()
{
	new_year=0;
	new_month=0;
	new_day=0;
	new_hour=0;
	new_minute=0;
	new_second=0;
	actual_date=new Date();

	if(actual_date.getFullYear()>toYear)
	{
		//si ya nos hemos pasado del año, mostramos los valores a 0
		//form.second.value=0;
		document.getElementById('day').value = 0;
		document.getElementById('hour').value = 0;
		document.getElementById('minute').value = 0;
		
	}else{
		new_second=new_second+toSecond-actual_date.getSeconds();
		if(new_second<0)
		{
			new_second=60+new_second;
			new_minute=-1;
		}
		//document.getElementById('second').innerHTML=new_second;

		new_minute=new_minute+toMinute-actual_date.getMinutes();
		if(new_minute<0)
		{
			new_minute=60+new_minute;
			new_hour=-1;
		}
		document.getElementById('minute').innerHTML=new_minute;

		new_hour=new_hour+toHour-actual_date.getHours();
		if(new_hour<0)
		{
			new_hour=24+new_hour;
			new_day=-1;
		}
		document.getElementById('hour').innerHTML=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;
				}
			}
		}
		document.getElementById('day').innerHTML=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;
		}
		//form.month.value=new_month;

		new_year=new_year+toYear-actual_date.getFullYear();
		if(new_year<0)
		{
			//form.year.value=0;
		}else{
			//form.year.value=new_year;
			//vuelve a ejecutar la funcion dentro de 1000 milisegundos = 1 segundo
			setTimeout("countDown()",1000);
		}
	}
}

function borraform(){
	document.getElementById('empresa').value = "";
	document.getElementById('sector').value = "";
	document.getElementById('responsable').value = "";
	document.getElementById('direccion').value = "";
	document.getElementById('cp').value = "";
	document.getElementById('poblacion').value = "";
	document.getElementById('telefono').value = "";
	document.getElementById('fax').value = "";
	document.getElementById('web').value = "";
	document.getElementById('mail').value = "";
	document.getElementById('solicita').value = "";
}

function form(){
	if(confirm("¿Es usted cliente final?")) { 
          return false;
	}
	else {
	      document.location.href="form2.php";
          return false;

    }   

    
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n) ; return x;
}

function NewWindow(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=0'
win = window.open(theURL, "", winprops)
}

function NewWindowScroll(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=1'
win = window.open(theURL, "", winprops)
}

function NewWindowScrollResize(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=1,resizable=1'
win = window.open(theURL, "", winprops)
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="")

//Email
{
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<6 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección de correo electrónico.\n';
}

//validar números requeridos
else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' debe contener un número.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es necesario.\n'; }
}
// Errores
if (errors) alert('Error(s) occurrido/s:\n'+errors);
document.MM_returnValue = (errors == '');
}
