var pvpTipoPrueba=0;
var pvpEnvio=0;
var pvpUrgente=0;
var ruta='/logo.jpg';
function formularioPruebas(){
	if($('pruebaID')){
		//ocultamos los divs con clase "oculto
	 	$$('.oculto').each(function(el){
			el.setStyle('display','none');
		});
		
		//deshabilitamos input de informar doctor
		if($('pruebaUsuarioNuevoInformar')){
			if($('pruebaUsuarioNuevoInformar').getProperty('checked') != true){
				$("pruebaUsuarioNuevoDoctor").setProperty('disabled','disabled');	
			}
		}

		
		
		//comportamiento de los elementos que afectan al precio
		//si hay error y hay prueba elegida
		if($('pruebaID').getProperty('value') !='-'){
			
			if ($('pruebaID').getProperty('value') == '3'){
				$("paternidad").setStyle('display','block');
				//$('pruebaPrecio').setProperty('value',pvpPaternidad);
				pvpTipoPrueba=$("pruebaPVP3").getProperty('value').toInt()+($("pruebaParentescoPersonas").getProperty('value').toInt()*150);
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
			}
			else{
				
				pvpTipoPrueba=$("pruebaPVP"+$('pruebaID').getProperty('value')).getProperty('value').toInt();
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
			}
		}
		// Cuando cambie el valor de la prueba
		$('pruebaID').addEvent('change',function(e){
			if (this.getProperty('value') == '3'){
				$("paternidad").setStyle('display','block');
				//$('pruebaPrecio').setProperty('value',pvpPaternidad);
				pvpTipoPrueba=$("pruebaPVP3").getProperty('value').toInt()+($("pruebaParentescoPersonas").getProperty('value').toInt()*150);
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				Growl.Bezel({
					title: 'Precio Modificado',
					text: 'Total: '+$('precio').getText(),
					image: ruta,
					duration: 2
				});
			}
			else{
				$("paternidad").setStyle('display','none');
				if (this.getProperty('value') == '-'){
					pvpTipoPrueba=0;
					$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
					Growl.Bezel({
						title: 'Precio Modificado',
						text: 'Total: '+$('precio').getText(),
						image: ruta,
						duration: 2
					});
				} else{
					pvpTipoPrueba=$("pruebaPVP"+this.getProperty('value')).getProperty('value').toFloat();
					$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
					
					Growl.Bezel({
						title: 'Precio Modificado',
						text: 'Total: '+$('precio').getText(),
						image: ruta,
						duration: 2
					});
				}
			}
		});
		$('pruebaParentescoPersonas').addEvent('change',function(e){
			pvpTipoPrueba=$("pruebaPVP3").getProperty('value').toInt()+($("pruebaParentescoPersonas").getProperty('value').toInt()*150);
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				Growl.Bezel({
				title: 'Precio Modificado',
				text: 'Total: '+$('precio').getText(),
				image: ruta,
				duration: 2
			});
		});
	/*	
		$('pruebaEnvioCorreoCertificado').addEvent('click',function(e){
			if (this.getProperty('checked') == true){
				pvpEnvio=3.50;
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				Growl.Bezel({
					title: 'Precio Modificado',
					text: '',
					image: ruta,
					duration: 2
				});
			}	
			});
	
		$('pruebaEnvioCorreo').addEvent('click',function(e){
			if (this.getProperty('checked') == true){
				pvpEnvio=0;
				if($('precio').getText() != pvpEnvio+pvpTipoPrueba+pvpUrgente+' €'){
					Growl.Bezel({
					title: 'Precio Modificado',
					text: '-3.50€',
					image: ruta,
					duration: 2
					});
				}
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				
			}	
			});
		$('pruebaEnvioCorreoBlanco').addEvent('click',function(e){
			if (this.getProperty('checked') == true){
				pvpEnvio=0;
				if($('precio').getText() != pvpEnvio+pvpTipoPrueba+pvpUrgente+' €'){
					Growl.Bezel({
					title: 'Precio Modificado',
					text: '-3.50€',
					image: ruta,
					duration: 2
					});
				}
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				
			}	
			});
		$('pruebaEnvioEmail').addEvent('click',function(e){
			if (this.getProperty('checked') == true){
				pvpEnvio=0;
				if($('precio').getText() != pvpEnvio+pvpTipoPrueba+pvpUrgente+' €'){
					Growl.Bezel({
					title: 'Precio Modificado',
					text: '-3.50€',
					image: ruta,
					duration: 2
					});
				}
				$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
				
			}	
			});
			
	*/
	}
	if($('clienteSI')){
		$('clienteSI').addEvent('click',function(e){
		
			$("datosCliente").setStyle('display','block');
			$("datosClienteNuevo").setStyle('display','none');
		});
		$('clienteNO').addEvent('click',function(e){
		
			$("datosCliente").setStyle('display','none');
			$("datosClienteNuevo").setStyle('display','block');
		});
		
	}
	/*$('pruebaFactura').addEvent('click',function(e){
		
		if (this.getProperty('checked') == true){
			
			$("datosFactura").setStyle('display','block');
		}
		else{
			$("datosFactura").setStyle('display','none');
		}
	});*/
/*	$('pruebaUrgente').addEvent('click',function(e){
		
		if (this.getProperty('checked') == true){
			pvpUrgente=100;
			$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
			Growl.Bezel({
	title: 'Precio Modificado',
	text: '',
	image: ruta,
	duration: 2
});
		}
		else{
			pvpUrgente=0;
			$('precio').setText(pvpEnvio+pvpTipoPrueba+pvpUrgente+' €');
			Growl.Bezel({
	title: 'Precio Modificado',
	text: '',
	image: ruta,
	duration: 2
});
		}
	});
*/
	// input doctor
	if($('pruebaUsuarioNuevoInformar')){
		$('pruebaUsuarioNuevoInformar').addEvent('click',function(e){
			
			if (this.getProperty('checked') == true){
				$("pruebaUsuarioNuevoDoctor").setProperty('disabled','');
				$("pruebaUsuarioNuevoDoctor").focus();
			}
			else{
				$("pruebaUsuarioNuevoDoctor").setProperty('disabled','disabled');
				$("pruebaUsuarioNuevoDoctor").setProperty('value','');
			}
		});
	}
	//borrar formulario
	if($('reset')){
	$('reset').addEvent('click',function(e){
		$('precio').setText(0+' €');
		Growl.Bezel({
	title: 'Formulario borrado',
	text: '',
	image: ruta,
	duration: 2
});	
	});
	}
}

