var err = new Array(9);
var ms;
function calcula(){
    
	t = document.getElementById("fllegada").value;
	t1 = document.getElementById("fsalida").value;
	var array_fecha = t.split("/")
	var array_fecha1 = t1.split("/") 
	var f1 = new Date(array_fecha[2],array_fecha[1],array_fecha[0]);
    var f2 = new Date(array_fecha1[2],array_fecha1[1],array_fecha1[0]);
    var dif = f2.getTime()-f1.getTime();
    var dias = Math.floor(dif / (1000 * 60 * 60 * 24))
	return dias;
    
   }



function total()
{
  var r1 = eval(document.getElementById("habitaciones").value);
  var dias = calcula();
  if (dias <= 0)
   var dia = 1;
   else
   dia = dias;
  var precio ;
  var i 
    for (i=0;i<document.form.tipo.length;i++){ 
      if (document.form.tipo[i].checked) 
         precio = eval(document.form.tipo[i].value) ; 
    } 
	
	rt = r1*dia*precio;
	res2 = (rt*.12)+(rt*.10)+rt;
	
t = document.getElementById("impo");
v = document.getElementById("total");
t.firstChild.nodeValue =  rt;
v.firstChild.nodeValue = res2;
 
   
}
function visible(id,flag)
{
  switch (flag)
  {
     case "mostrar":
	   v = document.getElementById(id).style.display = "block";
	   break;
	  case "ocultar":
	  v1= document.getElementById(id).style.display = "none";
	  break;
	  }
}
function comprobar()
{
  for (i=0;i<document.form.tipo.length;i++){ 
      if (document.form.tipo[i].checked) 
         total() ; 
    } 
}
function sumar(id)
{
   var o = document.getElementById(id);
   var s = eval(document.getElementById(id).value);
   o.value = s+1;
   total();
   
}
function restar(id)
{
var o = document.getElementById(id);
   var s = eval(document.getElementById(id).value);
   if(s==0)
   total()
   else{
   o.value = s-1;
   total();}
}
function cambiar(id,src)
{
	document.getElementById(id).src = src;
}
function texto(id,habitacion)
{
	
	t = document.getElementById(id);
	t.removeChild(t.lastChild);
	
	ul = document.createElement("ul");
	li1 = document.createElement("li"); 
	li2 = document.createElement("li"); 
	li3 = document.createElement("li"); 
	li4 = document.createElement("li"); 
	li5 = document.createElement("li"); 
	
	switch (habitacion)
	{
	 case "simple":
	     
	     
		 li1.appendChild(document.createTextNode("TV Cable Premium"));
	     li2.appendChild(document.createTextNode("Agua caliente 24 horas"));
	     li3.appendChild(document.createTextNode("Teléfono"));
	     li4.appendChild(document.createTextNode("Baño Privado"));
		 ul.appendChild(li1);
	     ul.appendChild(li2);
	     ul.appendChild(li3);
	     ul.appendChild(li4);
	
	     
	 
		 break;
	case "doble":
	     {
		 li1.appendChild(document.createTextNode("TV Cable Premium"));
	     li2.appendChild(document.createTextNode("Telefono"));
	     li3.appendChild(document.createTextNode("Baño Privado"));
	     li4.appendChild(document.createTextNode("Agua Caliente 24 horas"));
		 ul.appendChild(li1);
	     ul.appendChild(li2);
	     ul.appendChild(li3);
	     ul.appendChild(li4);
	
	     
		 }
		 break;
    case "triple":
	     {
		 li1.appendChild(document.createTextNode("TV Cable Premium"));
	     li2.appendChild(document.createTextNode("Armarios"));
	     li3.appendChild(document.createTextNode("Agua caliente 24 horas"));
	     li4.appendChild(document.createTextNode("Telefono"));
	     li5.appendChild(document.createTextNode("Baño privado"));
		 ul.appendChild(li1);
	     ul.appendChild(li2);
	     ul.appendChild(li3);
	     ul.appendChild(li4);
	     ul.appendChild(li5);
		 }
		 break;
	case "suite":
	     {
		 li1.appendChild(document.createTextNode("Cama King Size"));
	     li2.appendChild(document.createTextNode("TV Cable premium"));
	     li3.appendChild(document.createTextNode("Espacioso closet"));
	     li4.appendChild(document.createTextNode("Amplia Sala"));
	     li5.appendChild(document.createTextNode("Jacuzzi con agua caliente"));
		 ul.appendChild(li1);
	     ul.appendChild(li2);
	     ul.appendChild(li3);
	     ul.appendChild(li4);
	     ul.appendChild(li5);
		 }
		 break;
	}
	
	t.appendChild(ul);
	
}
function tdias(id)
{
	var dias = calcula();
      if (dias <= 0)
        var dia = 1;
         else
       dia = dias;
	d = document.getElementById(id);
	d.firstChild.nodeValue =  dia;

}
function borrar(id)
{
	var f = new Date();
var d = f.getDate();
var m= f.getMonth()+1;
var a = f.getFullYear(); 
c = document.getElementById("fllegada").value=d+"/"+m+"/"+a;
c1 = document.getElementById("fsalida").value=d+"/"+m+"/"+a;
	d = document.getElementById(id);
	d.firstChild.nodeValue =  "1";
	document.getElementById("form").reset();
	
}
function titulo(id,tit)
{
	t = document.getElementById(id);
	t.removeChild(t.lastChild);
	t.appendChild(document.createTextNode(tit));
}
function hoy()
{
	var f = new Date();
var d = f.getDate();
var m= f.getMonth()+1;
var a = f.getFullYear(); 
c = document.getElementById("fllegada").value=d+"/"+m+"/"+a;
c1 = document.getElementById("fsalida").value=d+"/"+m+"/"+a;
}

function precargaroll()
{
	i1=new Image;
     i1.src='extras/habitacionesroll.jpg';
	 i2=new Image;
     i2.src='extras/instalacionroll.jpg';
	 i3=new Image;
     i3.src='extras/reservacionesroll.jpg';
	 i4=new Image;
     i4.src='extras/inicioroll.jpg';
}
function precargarhab()
{
	q1=new Image;
     q1.src='extras/simple1g.jpg';
	 q2=new Image;
     q2.src='extras/simple2g.jpg';
	 q3=new Image;
     q3.src='extras/doble1g.jpg';
	 q4=new Image;
     q4.src='extras/doble2g.jpg';
	 q5=new Image;
     q5.src='extras/triple1g.jpg';
	 q6=new Image;
     q6.src='extras/triple2g.jpg';
	 q7=new Image;
     q7.src='extras/suite1g.jpg';
	 q8=new Image;
     q8.src='extras/suite2g.jpg';
}
function precargarins()
{
	a1=new Image;
     a1.src='extras/edificiogrande.jpg';
	 a2=new Image;
     a2.src='extras/recepciongrande.jpg';
	 a3=new Image;
     a3.src='extras/salagrande.jpg';
	 a4=new Image;
     a4.src='extras/comegrande.jpg';
	 
}
function precargar()
{
	  precargaroll();
	  precargarhab();
	  precargarins();
	  
}
function enviar()
{
	if(nombre()!=true&&apellido()!= true&&calle()!= true&&ciudad()!= true&&provincia()!= true&&pais()!= true&&telefono()!= true&&fax() != true&&email() != true)
	 document.getElementById("form").submit();
	 
	 else
	 { 
	 
	if(nombre()) 
	   ms = "Escriba su nombre\n"
	if(apellido())
		ms += "Escriba su apellido\n"
	if(calle())
	  ms += "Escriba su dirección\n"
	if(ciudad())
	  ms += "Escriba su ciudad\n"
	if(provincia())
	  ms += "Escriba su provincia\n"
	if(pais())
	  ms += "Escriba su pais\n"
	if(telefono())
	  ms += "Escriba su telefono correctamente\n"
	if(fax())
	  ms += "Escriba su fax correctamente\n"
	if(email())
	  ms += "Escriba su email correctamente\n"
	  alert(ms);
	  ms = "";
	 }
	  
	 
	 
}

function nombre()
{ 
     if(document.getElementById("nombre").value =="")
	  return (true);
	
}
function apellido()
{
	if(document.getElementById("apellido").value =="")
	  return (true);
}
function calle()
{
	if(document.getElementById("calle").value =="")
	  return (true);
}
function ciudad()
{
	if(document.getElementById("ciudad").value =="")
	  return (true);
}
function provincia()
{
	if(document.getElementById("provincia").value =="")
	  return (true);
}
function pais()
{
	if(document.getElementById("pais").value =="")
	  return (true);
}
function telefono()
{
	var flag
	var filter=/[0-9]$/;
	if(filter.test(document.getElementById("telefono").value))
	 flag = "bien";
	 else
	 flag = "mal";
	 if(flag == "mal"||document.getElementById("telefono").value =="")
     
	  return (true);
}
function fax()
{
	var flag
	var filter=/[0-9]$/;
	if(filter.test(document.getElementById("fax").value)||document.getElementById("fax").value =="")
	 flag = "bien";
	 else
	 flag = "mal";
	 if(flag == "mal")
     
	  return (true);
}
function email()
{
	var flag
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if(filter.test(document.getElementById("email").value))
	 flag = "bien";
	 else
	 flag = "mal";
	 if(flag == "mal"||document.getElementById("email").value =="")
      return (true);
	
}
function borrar()
{
	 document.getElementById("form").reset();
}