function tam(){
if (document.getElementById('cont').clientHeight > document.getElementById('lef').clientHeight)
	{
	var x=document.getElementById('cont').clientHeight*1;
	var d= document.getElementById('lef')
	x=x+50
	d.style.height = x+"px"
	}
}

function Trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function Validar_fecha(dia,mes,anho)
{	result = true
	if (!(Trim(dia)=='' && Trim(mes)=='' && Trim(anho)=='')) 
	{
		if  ((dia > 31) || (mes >12) || (!(IsNumeric_date(anho))) || (!IsNumeric_date(mes )) || (!(IsNumeric_date(dia))) || ( (mes==4 || mes==6 || mes==9 || mes==11) && (dia > 30) ) || (mes==2 && dia>29) || (anho<1900 || anho>2006 ) || (dia>28 && mes==2 && ((anho - Math.floor(anho / 4) * 4)>0) ) )
  			{
			result = false
			}	
	}
	
	return result
}



function validar_alta(e){
message=''
resultado=true

if (document.datos.value == '' || document.datos.apellido1.value == '' || document.datos.apellido2.value == '' || document.datos.email.value == '' || document.datos.telefono.value == '' || document.datos.tipo.value == '' || document.datos.nombrevia.value == '' || document.datos.poblacion.value == '' || document.datos.cp.value == '' || document.datos.provincia.value == '' || document.datos.pass.value == '' )
	{message = message + "Por favor, rellene los campos requeridos (marcados con *)"
	resultado = false
	}
	
if (!document.datos.condiciones.checked)
	{message = message + "\nPor favor, lea las condiciones de contratación y marque la casilla corrspondiente"
	resultado = false
	}
	

if(!(document.datos.pass.value == document.datos.confirm_pass.value) )
  {
    message = message + "\nLas nuevas contraseñas no coinciden. Por favor introdúcelas de nuevo."
    resultado = false
  }	 
  
 
if (!(Validar_fecha(document.datos.dia.value,document.datos.mes.value,document.datos.ano.value)))
	{
	message = message + "\nPor favor compruebe la fecha de nacimiento."
    resultado = false
	}
	
if (message != '')
	{alert (message)}

	return resultado
}


function IsNumeric_date(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
   
function recalculate(){

if (document.entrega.entr.value==0 || document.entrega.ok.value == 0 )
{document.entrega.genvio.value=0;
 document.entrega.total.value=document.entrega.articulos.value*1
 return}

if (document.entrega.ok.value==0 && !document.entrega.recoger.checked)
{alert ("Lo siento el pedido minimo para entrega a domicilio son 6 botellas")
 document.entrega.genvio.value=0;
 document.entrega.total.value=document.entrega.articulos.value*1
 document.entrega.recoger.checked=true
return
}

if (!document.entrega.recoger.checked){
if (document.entrega.provincia.value=='' || document.entrega.nombre_via.value==''|| document.entrega.cp.value=='' || document.entrega.poblacion ==''){
alert ("Por favor rellene la direccion de entrega para calcular los costes de envío")
return
}
}


if (document.entrega.provincia.value =='Palma de Mallorca' || document.entrega.provincia.value=='Palmas de G.C.,Las'){
alert ("Para pedidos a entregar fuera de la península \n por favor contacte con el departamento de atención al cliente")
return
}
if (document.entrega.cajas.value==0 || document.entrega.recoger.checked)
{document.entrega.genvio.value=0
document.entrega.total.value=(document.entrega.genvio.value*1)+(document.entrega.articulos.value*1)
return
}
if (document.entrega.provincia.value =='Madrid'){
	if (document.entrega.cajas.value==1)
	{document.entrega.genvio.value=8}
	else
	{document.entrega.genvio.value=6+(3*document.entrega.cajas.value)}

}
else
{
	if (document.entrega.cajas.value==1)
	{document.entrega.genvio.value=12}
	else
	{document.entrega.genvio.value=10+(3*document.entrega.cajas.value)}

}
document.entrega.total.value=(document.entrega.genvio.value*1)+(document.entrega.articulos.value*1)

}


function form_pago (forma)
{
	
	var i
	var valor
    for (i=0;i<forma.length;i++){
    if (forma[i].checked)
          {valor=forma[i].value
		  break
		  }
    } 
	
	if (valor=="aplazado")
	{document.location.href='pago_frame_per.htm'}
	else
	{document.location.href='pago_frame_pun.htm'}
}



function condiciones_leidas() 
{
	if (document.form_cond.condiciones.checked) 
		{
			document.location.href='compra.php'
		}
	else
		{
			alert ("Por favor, confirme que está de acuerdo con las condiciones generales de contratación")
		}
	
	
	
}