//Todo lo que use de Javascript
function fechahoy() {
var time = new Date()
dia1 = time.getDate()
mes1 = time.getMonth()
mes1 = mes1+1
ano1 = time.getFullYear()
document.reserva.mes.value = mes1
document.reserva.dia.value = ano1
document.reserva.dia.value = dia1
var hora = time.getHours();
 hora     = (hora>12)?hora -= 12:hora;
 if (hora == 0) hora = 12;
 var minutos    = time.getMinutes();
 minutos = (minutos<10)?minutos="0"+minutos:minutos;
 var meridiano    = time.getHours();
 meridiano = (meridiano>11)&&(meridiano<24)?"PM":"AM";
 horaentera= (hora+':'+minutos+' '+meridiano)
 document.reserva.hora.value= horaentera
}
function DiffDays(S2, S1) {
 var X = ReadISO8601date(S2) ; if (X<0) return "Date 1 bad"
 var Y = ReadISO8601date(S1) ; if (Y<0) return "Date 2 bad"
 return (Date.UTC(X[0], X[1]-1, X[2])-Date.UTC(Y[0], Y[1]-1, Y[2]))/86400000
 }
 
function validacion(carrito,action) {
 alert('paso');
 tam = document.carrito.elements.length-3
 for (n = 0;  n <= tam;  n++) {
           var m=n+1
   	       if (carrito.elements[n].value=="0" || carrito.elements[n].value==""){
		     alert("Por favor, escriba un valor para el producto No."+m)
		    return (false)
	       }
           if (carrito.elements[n].value == "" || carrito.elements[n].value.substring(0,1)==0)
	           {
			alert("Por favor, entre un valor.");
    		carrito.elements[n].value.focus();
    		return (false);
	           }
		   if (carrito.elements[n].value!="") {
	     		var cadena="0123456789"
		        var v=carrito.elements[n].value
        		if (!valida_contenido(cadena,v)){
		        	alert("Por favor, escriba una cantidad válida para el producto No."+m)
			        return (false)
				}
	       }
 }
 if (action == 1) {
	 if (document.carrito.importe.value) {
	  var dato=document.carrito.importe.value
		if (dato < 10) {
		 alert ("No es posible confirmar su pedido, el importe mínimo para considerar un pedido válido de la Tienda Mascotas debe ser de 10.00 USD o superior, ustede solo ha comprado productos por un valor de "+dato+" USD.")
		 return (false)
		} else return (true)
	 }
 }
}	   

function validar22(reserva) {
if (document.reserva.cant.value == "" || document.reserva.cant.value == 0)
	{    	alert("Por favor, entre un valor.");
    		document.reserva.cant.focus();
    		return (false);
	}
	var cadena="0123456789"
	var v=document.reserva.cant.value
	if (!valida_contenido(cadena,v)){
		alert("Escriba una cantidad válida")
		return (false)}
		

var time = new Date()
 dia1 = time.getDate()
 if (dia1 < 10) dia1='0'+dia1
 mes1 = time.getMonth()
 mes1 = mes1+1
 mesx=mes1
 if (mes1 < 10) mes1='0'+mes1
 ano1 = time.getFullYear()
 cadena = ano1+'-'+mes1+'-'+dia1
dia2 = document.reserva.dia.value
 if (dia2 < 10) dia2='0'+dia2
mes2 = document.reserva.mes.value
  if (mes2 < 10) mes2='0'+mes2
ano2 = document.reserva.ano.value
cadena2 = ano2+'-'+mes2+'-'+dia2
 resta = DiffDays(cadena2, cadena)
if (resta <= 1) {
alert ('Fecha no válida, solamente puede reservar a partir de la fecha de hoy en adelante con 1 día de antelación')
document.reserva.mes.value = mesx
document.reserva.dia.value = ano1
document.reserva.dia.value = dia1

return false
} else return true

}
function valida_contenido(checkOK,checkStr) //Lo tome de un codig. free en Internet
{
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
			allNum += ch;
	}
	if (!allValid)
		return (false)
	else
		return (true)
}

function chequeacantidad(obj)
{
	if (obj.value == "" || obj.value.substring(0,1)==0)
	{
			alert("Por favor, entre un valor.");
    		obj.focus();
    		return (false);
	}
	var cadena="0123456789"
	var v=obj.value
	if (!valida_contenido(cadena,v)){
		alert("Escriba una cantidad válida")
		return (false)}
}

function valida_forma(gped){

    var importe=document.gped.importe.value;
	if (importe>2000) {
		alert("No es posible confirmar su pedido. Para considerar un pedido válido su importe no puede superar los 2000.00 USD, y usted ha comprado productos por un valor de "+importe+" USD. Si Ud. desea hacer compras con un monto superior al establecido por favor contacte a nuestro administrador.");
		return (false);
	}   
    var chflores=document.gped.florin.value;
	if ((chflores != 0) && (document.gped.provinciad.selectedIndex != 1)) {
		//document.gped.idpaisf.selectedIndex = 49
		//document.gped.provinciad.selectedIndex = 3
		//document.gped.municcf.disabled = false
		alert("Si compra flores, solo pueden ser entregadas en Ciudad de la Habana, Cuba");
		return (false);
	}
	//vflor(chflores)
	
/*	var chhotel=document.gped.hotelin.value;
	if ((chhotel != 0) && (document.gped.pasaporte.value=="")) {
		alert("Si reserva hotel, tiene que introducir el número del pasaporte");
		return (false);
	}*/
	
	
	// datos del cliente
	if (gped.nombre.value==""){
		alert("Por favor, escriba el nombre del cliente")
		return (false)
	}
	if (gped.direccion.value==""){
		alert("Por favor, escriba la dirección del cliente")
		return (false)
	}
	if (gped.codpost.value==""){
		alert("Por favor, escriba el código postal del cliente")
		return (false)
	}	
	if (gped.codpost.value!=""){
		var cadena="0123456789()- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		var v=gped.codpost.value
		if (!valida_contenido(cadena,v)){
			alert("Escriba un código postal válido para el cliente")
			return (false)}
	}	
	if (gped.ciudad.value==""){
		alert("Por favor, escriba la ciudad del cliente")
		return (false)
	}
	if (gped.provest.value==""){
		alert("Por favor, escriba el estado o provincia del cliente")
		return(false)
	}
	if (gped.email.value == 0 || gped.email.value == "") {
	   alert ("Por favor, escriba el Correo Electrónico del cliente");
	   return (false);   
	} 
	if (gped.email.value!=""){
	    var email=gped.email.value
	    if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
		  alert("Por favor, escriba una dirección E-mail válida para el cliente")
		  return(false)}
	}	
	if  (gped.telefono.value!=""){
		var cadena="0123456789()- "
		var v=gped.telefono.value
		  if (!valida_contenido(cadena,v)){
			alert("Escriba un número telef. válido para el cliente")
			return (false)}
	}	
	
    // datos del destinatario
	if (gped.nombref.value==""){
		alert("Por favor, escriba el nombre del destinatario")
		return (false)
	}
	if (gped.direccionf.value==""){
		alert("Por favor, escriba la dirección del destinatario")
		return (false)
	}
	if (gped.codpostf.value==""){
		alert("Por favor, escriba el código postal del destinatario")
		return (false)
	}	
	if (gped.codpostf.value!=""){
		var cadena="0123456789()- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		var v=gped.codpostf.value
		if (v != "") {
		if (!valida_contenido(cadena,v)){
			alert("Escriba un código postal válido para el destinatario")
			return (false)}
		}
	}
	if (gped.ciudadf.value==""){
		alert("Por favor, escriba la ciudad del destinatario")
		return (false)
	}	
	if ((gped.provestd.value=="") && (document.gped.idpaisf.selectedIndex != 49)) {
		alert("Por favor, escriba el estado o provincia del destinatario")
		return (false)
	}	
	if (gped.emailf.value!=""){
		var emailf=gped.emailf.value
		if (emailf != "") {
		if ((emailf.indexOf("@")==-1) || (emailf.indexOf(".")==-1)){ 
			alert("Por favor, escriba una dirección E-mail válida para el destinatario")
			return(false)}
		}
	}	
	if (gped.telefonof.value==""){
		alert("Por favor, escriba el número telef. del destinatario")
		return (false)
	}	
	if  (gped.telefonof.value!=""){
		var cadena="0123456789()- "
		var v=gped.telefonof.value
    	if (v != "") {
		if (!valida_contenido(cadena,v)){
			alert("Escriba un número telef. válido para el destinatario")
			return (false)}
		}
	}	
	var chhotelf=document.gped.hotelin.value;
	if ((chhotelf != 0) && (document.gped.pasaportef.value=="")) {
		alert("Si reserva hotel, tiene que introducir el número del pasaporte del destinatario");
		return (false);
	}
	if (gped.acepto.checked==false){
		alert("Tiene que aceptar los términos del contrato")
		return (false)
	}	
}			

function valida_forma_en(gped){
	var chflores=document.gped.florin.value
	if ((chflores != 0) && (document.gped.provinciad.selectedIndex != 1)) {
	//if (document.gped.idpaisf.selectedIndex != '49') {
		document.gped.idpaisf.selectedIndex = 49
		document.gped.provinciad.selectedIndex = 3
		document.gped.municcf.disabled = false
		alert("If you by flowers, only can be delivered in Ciudad de la Habana, Cuba")
		return (false)
	}
		//vflor(chflores)
		
/*	var chhotel=document.gped.hotelin.value;
	if ((chhotel != 0) && (document.gped.pasaporte.value=="")) {
		alert("Please, write the passport");
		return (false);
	}*/
	
	if (gped.nombre.value==""){
		alert("Please, write the name of purchaser")
		return (false)
	}
	if (gped.nombref.value==""){
		alert("Please, write the name of final client")
		return (false)
	}
	if (gped.direccion.value==""){
		alert("Please, write the address of purchaser")
		return (false)
	}
		if (gped.direccionf.value==""){
		alert("Please, write the address of final client")
		return (false)
	}
	if (gped.provest.value==""){
		alert("Please, write the purchaser's province ")
		return(false)
	}
	if (gped.ciudad.value==""){
		alert("Please, write the purchaser's city")
		return (false)
	}
	if  (gped.telefono.value!="")
	{
		var cadena="0123456789()- "
		var v=gped.telefono.value
		  if (!valida_contenido(cadena,v)){
			alert("Write a valid phone number")
			return (false)}
	}	
	if  (gped.telefonof.value!="")
	{
		var cadena="0123456789()- "
		var v=gped.telefonof.value
    	if (v != "") {
		if (!valida_contenido(cadena,v)){
			alert("Write a valid phone number to the final client")
			return (false)}
		}
	}
	var chhotel=document.gped.hotelin.value;
	if ((chhotel != 0) && (document.gped.pasaportef.value=="")) {
		alert("Please, write the passport");
		return (false);
	}
	if (gped.email.value!=""){
		
	
	var email=gped.email.value
	if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
		alert("Please, write a valid E-mail address to the purchaser")
		return(false)}
	}
	if (gped.emailf.value!=""){
		var emailf=gped.emailf.value
		if (emailf != "") {
		if ((emailf.indexOf("@")==-1) || (emailf.indexOf(".")==-1)){ 
			alert("Please, write a valid E-mail address to the final client")
			return(false)}
		}
	}
	
	
	if (gped.codpost.value!="")
	{
		var cadena="0123456789()- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		var v=gped.codpost.value
		if (!valida_contenido(cadena,v)){
			alert("Write a valid postal code")
			return (false)}
	}
	if (gped.codpostf.value!="")
	{
		var cadena="0123456789()- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		var v=gped.codpostf.value
		if (v != "") {
		if (!valida_contenido(cadena,v)){
			alert("Write a valid postal code")
			return (false)}
		}
	}
	if (gped.fax.value!="")
	{
	
		var cadena="0123456789()- "
		var v=gped.fax.value
		if (v != "") {
		if (!valida_contenido(cadena,v)){
			alert("Write a valid fax number")
			return (false)}
		}
	}
}			
function valida_total(carrito) {
 var dato=document.carrito.importe.value
	if (dato < 10) {
	 alert ("No es posible confirmar su pedido, el importe mínimo para considerar un pedido válido de la Tienda Mascotas debe ser de 10.00 USD o superior, ustede solo ha comprado productos por un valor de "+dato+" USD.")
	 return (false)
	} else return (true)
}

function valida_productos(carrito) {
 var total=document.carrito.total.value
 //alert ('cantidad de productos: '+total);
 	if (total < 5) {
	 alert ("No es posible confirmar su pedido, debe comprar como mínimo 5 productos, usted ha comprado solamente "+total+ ".")
	 return (false)
	} else return (true)
}
function valida_productosen(carrito) {
 var dato=document.carrito.totprod.value
	if (dato < 5) {
	 alert ("It's not possible to confirm your order, it must buy like minimum 5 products, you you have only bought "+total+ ".")
	 return (false)
	} else return (true)
}

function valida_totalmin(carro) {
 var dato=document.carro.importe.value
	if (dato < 10) {
	 alert ("No es posible confirmar su pedido, el importe mínimo para considerar un pedido válido de la Tienda Mascotas debe ser de 10.00 USD o superior, usted solo ha comprado productos por un valor de "+dato+" USD.")
	 return (false)
	} else return (true)
}

function valida_stpedido () {
   var idpedido=document.pedido.idpedido.value
   var clave=document.pedido.clave.value
   if (idpedido == 0 || idpedido == "") {
   alert ("Escriba un valor para el identificador de pedido.");
   } 
   if (clave == 0 || clave == "") {
   alert ("Escriba un valor para la clave del pedido.");
   } 
   if (idpedido!="") {
	var cadena="0123456789"
    var v=idpedido
    if (!valida_contenido(cadena,v)){
		alert("Por favor, escriba identificador de pedido válido.")
	return (false)
    }
   }
   if (clave.length < 12) {
   		alert("Por favor, escriba una clave válida para el pedido "+idpedido+", la misma debe tener 12 caracteres, la tecleada tiene "+clave.length+" caracteres.")
		return(false)
   }
}

function valida_correo (correo) {
  var  nombre=document.correo.nombre.value
  var  email=document.correo.email.value
  var texto=document.correo.texto.value
  if (nombre == 0 || nombre == "") {
   alert ("Escriba un valor para el nombre.");
   return (false);
  } 
  if (email == 0 || email == "") {
   alert ("Escriba un valor para el E-mail.");
   return (false);   
  } 
  if (texto == 0 || texto == "") {
   alert ("Escriba un valor para el texto, no se permite el envío de mensajes vacíos.");
   return (false);   
  } 
  if (email != ""){
	if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
		alert("Por favor, escriba una dirección E-mail válida")
		return(false)
	}
  }
}

function valida_opinion (idioma, opinion) {
	var nombre=document.opinion.nombre.value
	var email=document.opinion.email.value
	var direccion=document.opinion.direccion.value
	var conocio=document.opinion.conocio.value
	var conocioalt=document.opinion.conocioalt.value
	var noencontro=document.opinion.noencontro.value
	var mensaje=document.opinion.mensaje.value
	if (idioma="en") {
		var tnombre="Enter a value Name";
		var temail="Enter a value for e-mail";
		var tvemail="Please enter a valid e-mail";
		var tconocio="Select a value for the option How do you hear about us?";
		var tconocioalt="Enter a value for the option of specifying otherwise, because you have selected the one which we knew that is not on the list we show you";
		var tnoencontro="Enter a value for the option Specify product or service not found, as you have selected that did not find what they wanted in the previous option, please specify";
		var tmensaje="Please write your comments about him site, we will appreciate much";
	} else {
		var tnombre="Escriba un valor para el Nombre";
		var temail="Escriba un valor para el Correo Electrónico";
		var tvemail="Por favor, escriba una dirección de Correo Electrónico válida";
		var tconocio="Seleccione un valor para la opción ¿Cómo nos conoció?";
		var tconocioalt="Escriba un valor para la opción de especificación de otra vía, pues usted ha seleccionado que nos conoció por una que no se encuentra en la lista que le mostramos";
		var tnoencontro="Escriba un valor para la opción Especificar producto o servicio no encontrado, pues usted ha seleccionado que no encontró lo que deseaba en la opción anterior, por favor especifique";
		var tmensaje="Por favor escriba sus comentarios sobre le sitio, se lo agradeceremos mucho";
	}
	
	if (nombre == 0 || nombre == "") {
	   alert (tnombre);
	   return (false);
	} 
	if (email == 0 || email == "") {
	   alert (temail);
	   return (false);   
	} 
    if (email != ""){
		if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
			alert(tvemail)
			return(false)
		}
    }
    if (conocio == "") {
	   alert (tconocio);
	   return (false);
	} 
	if (conocio == 0) {
	   if (conocioalt == 0 || conocioalt == "") {
		   alert (tconocioalt);
		   return (false);
	   }
	} 
   	if ((document.opinion.encontro[1].value == 0) && (document.opinion.encontro[1].checked)) {
	   if (noencontro == 0 || noencontro == "") {
		   alert (tnoencontro);
		   return (false);
	   }
	} 
	if (mensaje == 0 || mensaje == "") {
	   alert (tmensaje);
	   return (false);
	} 

}

function valida_paging (paging) {
	var nombre=document.paging.nombre.value
	var email=document.paging.email.value
	if (nombre == 0 || nombre == "") {
	   alert ("Escriba un valor para el nombre.");
	   return (false);
	} 
	if (email == 0 || email == "") {
	   alert ("Escriba un valor para el E-mail.");
	   return (false);   
	} 
    if (email != ""){
		if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
			alert("Por favor, escriba una dirección E-mail válida")
			return(false)
		}
    }
}

function valida_registro (registrarse) {
	var nombre=document.registrarse.nombre.value;
	var email=document.registrarse.email.value
	var direccion=document.registrarse.direccion.value
	var telefono=document.registrarse.telef.value
	var pais=document.registrarse.idpais.value
	var prov=document.registrarse.prov.value
	var ciudad=document.registrarse.ciudad.value
	var codp=document.registrarse.codp.value
	var pass1=document.registrarse.pass1.value
	var pass2=document.registrarse.pass2.value
	if (nombre == 0 || nombre == "") {
	   alert ("Escriba un valor para el nombre y los apellidos.");
	   return (false);
	} 
	if (email == 0 || email == "") {
	   alert ("Escriba un valor para el Correo Electrónico.");
	   return (false);   
	} 
    if (email != ""){
		if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
			alert("Por favor, escriba una dirección de Correo Electrónico válida")
			return(false)
		}
    }
	if (direccion == 0 || direccion == "") {
	   alert ("Escriba un valor para la dirección.");
	   return (false);
	} 
	if (telefono == 0 || telefono == "") {
	   alert ("Escriba un valor para el teléfono.");
	   return (false);
	} 
	if (pais == 0 || pais == "") {
	   alert ("Escriba un valor para el país.");
	   return (false);
	}
	if (prov == 0 || prov == "") {
	   alert ("Escriba un valor para el estado/provincia.");
	   return (false);
	}	
	if (ciudad == 0 || ciudad == "") {
	   alert ("Escriba un valor para la ciudad.");
	   return (false);
	}	
	if (codp == 0 || codp == "") {
	   alert ("Escriba un valor para el código postal.");
	   return (false);
	}		
	if (pass1 == 0 || pass1 == "") {
	   alert ("Escriba un valor para la contraseña.");
	   return (false);
	}
	if (pass1.length <6) {
	   alert ("La contrañena tiene que tener como mínimo 6 caracteres.");
	   return (false);
	}	
	if (pass2 == 0 || pass2 == "") {
	   alert ("La contraseña no coincide con la confirmación.");
	   return (false);
	}
	if (pass2.length <6) {
	   alert ("La contraseña no coincide con la confirmación.");
	   return (false);
	}	
	if (pass1 != pass2) {
	   alert ("La contraseña no coincide con la confirmación.");
	   return (false);
	}	
}

function valida_boletin (boletin) {
	var nombre=document.boletin.nombre.value
	var email=document.boletin.email.value
	if (nombre == 0 || nombre == "") {
	   alert ("Escriba un valor para el nombre.");
	   return (false);
	} 
	if (email == 0 || email == "") {
	   alert ("Escriba un valor para el E-mail.");
	   return (false);   
	} 
    if (email != ""){
		if ((email.indexOf("@")==-1) || (email.indexOf(".")==-1)){ 
			alert("Por favor, escriba una dirección E-mail válida")
			return(false)
		}
    }
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function valida_destinatario(obj) {
	var n=document.gped.elements.length
	var paisp=document.gped.idpais.value
	paisp= trim(paisp)
	var paisf=document.gped.idpaisf.value
	paisf= trim(paisf)
	var servicio=document.gped.servicio.value
	if (servicio == 1) {
		for (i=0;i<n;i++) {
			 if ((document.gped.elements[i].type=="radio")&&(document.gped.elements[i].value=="cpv")&&(document.gped.elements[i].checked)&&(paisp != 'CU')) {
				 alert ('Lamentamos el inconveniente pero para el servicio solicitado de la Tienda Palmares el cliente que va a recibir el servicio debe vivir en Cuba, Ciudad Habana y en los municipios permitidos, ...')
				 document.gped.elements[i].checked= false;
			 }
			 if ((document.gped.elements[i].type=="radio")&&(document.gped.elements[i].value=="cfv")&&(document.gped.elements[i].checked)&&(paisf != 'CU')) {
				  alert ('Lamentamos el inconveniente pero para el servicio solicitado de la Tienda Palmares el cliente que va a recibir el servicio debe vivir en Cuba, Ciudad Habana y en los municipios permitidos, ...')
				  document.gped.elements[i].checked= false;
			 }
	
		}  
	}
}
function counter1(form,maxchars) {
var count = form.dedicatoria.value.length + 1;
  if (escape(event.keyCode) != 8 ) 
  { if (count > maxchars) 
	{ alert('Ya llegó a los 120 caracteres');
	  event.returnValue = false;
	  return false;
	}
	else 
	{ form.cantidadp.value = count;
	}
  }
  else 
  { count--;
	if (count > 0) 
	{ form.cantidadp.value = --count;
	}
  }
}