function getKeyCode(e)
{
	var e= (window.event)? event : e;
	var intKey = (e.keyCode)? e.keyCode: e.charCode;
	return intKey;
}

function cambio(origen, valor, campo, longitud, event)
{
	var codigo = getKeyCode(event);
	var caracter = String.fromCharCode(codigo);	

	if((codigo >=96 && codigo <=105) || (codigo>=48 && codigo <=57))
	{
		if( document.getElementById(campo).getAttribute("autocomplete") )	
			document.getElementById(campo).setAttribute('autocomplete','off');
		
		if (codigo !=9 && codigo !=0 && codigo != 40)
		{
			if(valor.length == longitud)
			{
				document.getElementById(campo).focus();
				document.getElementById(campo).select();			
				return false;
			}
		}
	}
	else
	{	
		origen.value = origen.value.replace(caracter, '');
		origen.value = origen.value.replace(caracter.toLowerCase(), '');  
		return false;
	}
}
function muestraAsegurados(valor)
{	
	for (var i = 1; i <= valor;i++)
	{
		document.getElementById("asegurado"+(i)).style.display='block';
		document.getElementById("linea"+(i)).style.display='block';
	}
	
	for (; i <= 8; i++)
	{				
		document.getElementById("asegurado"+(i)).style.display='none';
		document.getElementById("linea"+(i)).style.display='none';
		borrarAsegurado(i);
	}
}


function borrarAsegurado(numero)
{
	document.getElementById("diaN"+(numero)).value = '';
	document.getElementById("mesN"+(numero)).value = '';
	document.getElementById("anyoN"+(numero)).value = '';
	document.getElementById("sexo"+(numero)).selectedIndex = 0;
}


function calcular_total()
{
	primaria = document.getElementById('primaria').value;
	especialistas = document.getElementById('especialistas').value;
	hospitalizacion = document.getElementById('hospitalizacion').value;
	
	if(primaria == 'true' && especialistas == 'false' && hospitalizacion == 'false')
		total = document.getElementById('primariaprecio').value;
	if(primaria == 'false' && especialistas == 'true' && hospitalizacion == 'false')
		total = document.getElementById('especialistasprecio').value;
	if(primaria == 'false' && especialistas == 'false' && hospitalizacion == 'true')
		total = document.getElementById('hospitalizacionprecio').value;
	if(primaria == 'true' && especialistas == 'true' && hospitalizacion == 'false')
		total = document.getElementById('prima_espe_precio').value;
	if(primaria == 'true' && especialistas == 'false' && hospitalizacion == 'true')
		total = document.getElementById('prima_hospi_precio').value;
	if(primaria == 'false' && especialistas == 'true' && hospitalizacion == 'true')
		total = document.getElementById('espe_hospi_precio').value;
	if(primaria == 'true' && especialistas == 'true' && hospitalizacion == 'true')
		total = document.getElementById('total_precio').value;
	if(primaria == 'false' && especialistas == 'false' && hospitalizacion == 'false')
		total = 0;
	
	formapago = document.getElementById('formaPago').value;
	var redondeado = Math.round(total * Math.pow(10,2)) / Math.pow(10,2);	
	document.getElementById('preciototal').innerHTML = redondeado + ' &#8364;';	
}

function si_no_parrillasalud(campo, rutaimg)
{
	valor = document.getElementById(campo).value;
	if(valor =='true')
	{
		document.getElementById('img' + campo).src = rutaimg + 'check-no.jpg';
		document.getElementById(campo).value = false;
		document.getElementById(campo + 'mail').value = false;
	}
	else
	{
		document.getElementById('img' + campo).src = rutaimg + 'check-si.jpg';
		document.getElementById(campo).value = true;
		document.getElementById(campo + 'mail').value = true;
	}
}


function AbrirCentrado(Url,NombreVentana,width,height,extras) 
{
	var largo = width;
	var altura = height;
	var adicionales= extras;
	var top = (screen.height-altura)/2;
	var izquierda = ((screen.width-largo)/2) - 10; 
	nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',' + adicionales + '');
	nuevaVentana.focus();
	}

function AbrirCobertura(url)
{
	AbrirCentrado(url, 'coberturas', '900', '400', 'Scrollbars=YES,resizable=YES');
}

function iniciarprecios(rutaimg)
{
	if(document.getElementById('primaria').value == 'true')
		document.getElementById('img' + 'primaria').src = rutaimg + 'check-si.jpg';
	else
		document.getElementById('img' + 'primaria').src = rutaimg + 'check-no.jpg';
	
	if(document.getElementById('especialistas').value == 'true')
		document.getElementById('img' + 'especialistas').src = rutaimg + 'check-si.jpg';
	else
		document.getElementById('img' + 'especialistas').src = rutaimg + 'check-no.jpg';
	
	if(document.getElementById('hospitalizacion').value == 'true')
		document.getElementById('img' + 'hospitalizacion').src = rutaimg + 'check-si.jpg';
	else
		document.getElementById('img' + 'hospitalizacion').src = rutaimg + 'check-no.jpg';
	
	calcular_total();
}

function mostrarayuda(campo)
{		
	if(campo == 'ayudatitular')	
		document.getElementById('textoayuda').innerHTML ='ayuda ayuda ad adyuda adya da adya ad asayuda ayuda ad adyuda adya da adya ad asayuda ayuda ad adyuda adya da adya ad asayuda ayuda ad adyuda adya da adya ad as';
	
	if(campo == 'ayudatomador')	
		document.getElementById('textoayuda').innerHTML ='ayuda tomador ad adyuda adya da tomador ad asayuda tomador ad tomador adya da adya ad tomador ayuda ad tomador adya da adya ad tomador ayuda ad adyuda adya da adya ad as';
		
	
	var p = fGetXY(document.getElementById(campo));
	divDesc = document.getElementById('ayuda');
	divDesc.style.top=(p[1] - 157 )+"px"
	divDesc.style.left=( p[0] + 27) +"px"
	divDesc.style.zIndex=1001;
	divDesc.style.display="block";
	document.getElementById('ayuda').style.display = '';
}

function fGetXY(aTag)
{
	var p=[0,0];
	while(aTag!=null)
	{
		p[0]+=aTag.offsetLeft;
		p[1]+=aTag.offsetTop;
		aTag=aTag.offsetParent;
	}
	return p;
} 

function ContratarOnlineSalud(rutaimg)
{
	primaria = document.getElementById('primaria').value;
	especialistas = document.getElementById('especialistas').value;
	hospitalizacion = document.getElementById('hospitalizacion').value;
	if(primaria =='false' && especialistas == 'false' && hospitalizacion =='false')
	{
		document.getElementById('imgprimaria').src = rutaimg + 'check-error.jpg';
		document.getElementById('imgespecialistas').src = rutaimg + 'check-error.jpg';	
		document.getElementById('imghospitalizacion').src = rutaimg + 'check-error.jpg';
	}
	else
	{
		document.forms['form_seguros_salud'].submit();		
	}
}

	
	

