// JavaScript Document<script languaje='javascript 1.2'>
function mostrarDiv(elem) { 

	var d = document.form1;
	d.guardar.value = elem.id;

	if(elem.id == 'tabla_historia'){
		elem2 = tabla_asociar;
		tb_btn1.style.backgroundColor="#F3F3F3" 
		tb_btn2.style.backgroundColor="#1C76AA" 
	}else{
		elem2 = tabla_historia;
		tb_btn1.style.backgroundColor="#1C76AA" 
		tb_btn2.style.backgroundColor="#F3F3F3" 
	}

   var style = elem.style;
   var style2 = elem2.style; 

   if(style.display=='none'){
		style.display = "";
	} else {
		style.display = "none";
		d.guardar.value = '';
		tb_btn1.style.backgroundColor="#F3F3F3" 
		tb_btn2.style.backgroundColor="#F3F3F3" 
	}
	
	style2.display = "none";

}

function paciente(){

	if(document.form1.usted_es.value == 'Paciente')
	{
		divEstado('campo_paciente', 1)
		divEstado('texto_paciente', 1)
	}
	else
	{
		divEstado('campo_paciente', 0)
		divEstado('texto_paciente', 0)
	}
}


function divEstado(elem, estado) { 
	
	if(estado === 1)
	{
		document.getElementById(elem).style.visibility="visible"; 
	}
	else if(estado === 0)
	{
		document.getElementById(elem).style.visibility="hidden"; 
	}
	else
	{
		if(document.getElementById(elem).style.visibility == "visible")
		{
			document.getElementById(elem).style.visibility="hidden"; 
		}
		else
		{
			document.getElementById(elem).style.visibility="visible"; 
		}
	}		
	
}


function validar(){
	var d = document.form1;
	var error = '';
	
	//NOMBRE
	if(d.nombre.value == '')
		error += ' - El campo NOMBRE es obligatorio\n';
	
	//CIUDAD
	if(d.ciudad.value == '')
		error += ' - El campo CIUDAD es obligatorio\n';
		
	//PROVINCIA
	if(d.provinciaID.value == '0')
		error += ' - El campo PROVINCIA es obligatorio\n';
		
	//EMAIL
	if(d.email.value=='') {
		error+= " - El campo E-MAIL es obligatorio\n";
	} else {
		if(d.email.value!=d.email2.value) {
			error+= " - Los campos E-MAIL's no coinciden\n";
		}else{
			var txt = new String(d.email.value);
			//EMAIL MAL ESCRITO
			if(txt.indexOf('@') < 1 || txt.indexOf('.') < 1)
				error+= " - El campo E-MAIL no es correcto\n";
		}
			
	}
	
	//USTED ES
	if(d.usted_es.value == '0')
		error += ' - El campo USTED ES es obligatorio\n';
	
		// SI PRESIONO EL BOTON 1
		if(d.guardar.value == 'tabla_asociar'){
			//CIUDAD
			if(d.direccion.value == '')
				error += ' - El campo DIRECCION POSTAL es obligatorio\n';
			// CODIGO POSTAL
			if(d.cp.value == '')
				error += ' - El campo CÓDIGO POSTAL es obligatorio\n';
			// TELELFONO
			if(d.telefono.value == '')
				error += ' - El campo TELEFONO es obligatorio\n';
		} else if (d.guardar.value == 'tabla_historia'){
			// HISTORIA
			if(d.historia.value == '')
				error += ' - El campo HISTORIA es obligatorio\n';
		}
	
	
	if(error != '')
		alert("ERROR:\n" + error);
	else
		d.submit();
	
	
	
	
}

