/* GALERIA DE FUNCIONES JAVASCRIPT */

/* Cambia el estado de un objeto (Activo, Inactivo) 
Parametros: objeto - Objeto a cambiar de estado
			estado - 0 -> inactivo; 1 -> activo
Salida: ninguno */
function Cambiar_estado(objeto,estado)
{
	if (estado == "0")
	{
		document.getElementById(objeto).disabled = true;
	}
	else
	{
		document.getElementById(objeto).disabled = false;
	}

}

// Funcion para el pupload del fichero del parte

function Upload()
{
	if (document.getElementById('select_docum').value == "si")
	{
		Cambiar_estado("upload","1");
	}
	if (document.getElementById('select_docum').value == "no")
	{
		Cambiar_estado("upload","0");
	}	
}


// Comprobar el formulario del acceso principal
function Acceso()
{
	if ((document.getElementById('usuario').value == "") || (document.getElementById('password').value == ""))
	{
		alert("Debe rellenar todos los campos del formulario");
		document.getElementById('usuario').focus();
	}
	else
	{
		document.form1.submit();
	}
}


/// ######### APARTADO PARTES #############

function Alta_Parte()
{
	
	if (document.getElementById('select_colegiados').value == "0")
	{
			alert("Debe rellenar el 'NOMBRE' del colegiado.");
		document.getElementById('select_colegiados').focus();
	}
	else
	{
		if (document.getElementById('fecha_con').value == "")
		{
			alert("Debe rellenar la 'FECHA DE CONSULTA' del parte.");
			document.getElementById('fecha_con').focus();
		}
		else
		{
			if (document.getElementById('select_voces').value == "0")
			{
				alert("Debe rellenar la 'VOZ' del parte.");
				document.getElementById('select_voces').focus();
			}
			else
			{
				if (document.getElementById('select_docum').value == "0")
				{
					alert("Debe rellenar la 'DOCUMENTACIÓN' del parte.");
					document.getElementById('select_docum').focus();
				}
				else
				{
					if ((document.getElementById('upload').value == "") && (document.getElementById('upload').disabled == false))
					{
						alert("Debe seleccionar un fichero de documentación del parte.");
						document.getElementById('upload').focus();
					}
					else
					{
						if (document.getElementById('select_contactos').value == "0")
						{
							alert("Debe rellenar el 'CONTACTO' del parte.");
							document.getElementById('select_contactos').focus();
						}
						else
						{
							if (document.getElementById('consulta').value == "")
							{
								alert("Debe rellenar la 'CONSULTA' del parte.");
								document.getElementById('consulta').focus();
							}
							else
								{
								if (document.getElementById('select_abogados').value == "0")
								{
									alert("Debe rellenar el 'ABOGADO' del parte.");
									document.getElementById('select_abogados').focus();
								}
								else
								{
									document.form1.submit();
								}
							}
						}
					}
				}
			}
		}
	}	
}


function Imprimir_Parte(id)
{
      Ventana=open("","","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,width=666,height=400");
	  Encoger(Ventana,666,400);
	  Ventana.location.href='parte_imprimir.php?id='+id;
	  Ventana.focus();
}


function Encoger(Ventana,ancho,alto)
{
x = screen.width;
y = screen.height;
xfin = (x/2) - (ancho/2);
yfin = (y/2) - (alto/2);
Ventana.moveTo(xfin,yfin);
}


function Nuevo_Colegiado()
{
      Ventana=open("","","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,width=500,height=400");
	  Encoger(Ventana,500,400);
	  Ventana.location.href='colegiado_alta_form.php';
	  Ventana.focus();
}

function Nueva_Voz(tipo)
{
      Ventana=open("","","scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,width=500,height=300");
	  Encoger(Ventana,500,300);
	  Ventana.location.href="voz_alta_form.php?tipo="+tipo+"";
	  Ventana.focus();	  
}


// ######### ALTA USUARIOS ##############

function Select_Cargo()
{
	if (document.getElementById('select_cargo').value == "0")
	{
		alert("Debe seleccionar un tipo de usuario");
		document.getElementById('select_cargo').focus();
	}
	else
	{
			document.form1.submit();
	}
}

function Alta_Abogado()
{
	if (document.getElementById('nombre').value == "")
	{
		alert("Debe rellenar el 'NOMBRE' del abogado.");
		document.getElementById('nombre').focus();
	}
	else
	{
		
		if (document.getElementById('apellidos').value == "")
		{
			alert("Debe rellenar los 'APELLIDOS' del abogado.");
			document.getElementById('apellidos').focus();
		}
		else
		{
		document.form2.submit();
		}
	}
}


function Alta_Colegiado()
{
	if (document.getElementById('nombre').value == "")
	{
		alert("Debe rellenar el 'NOMBRE' del colegiado.");
		document.getElementById('nombre').focus();
	}
	else
	{
		if (document.getElementById('apellidos').value == "")
		{
			alert("Debe rellenar el 'APELLIDOS' del colegiado.");
			document.getElementById('apellidos').focus();
		}
		else
		{
			if (document.getElementById('n_colegiado').value == "")
			{
				alert("Debe rellenar el 'NUMERO' del abogado.");
				document.getElementById('n_colegiado').focus();
			}
			else
			{
				document.form2.submit();
			}
		}
	}	
}


function Eliminar_Colegiado()
{
	if (document.getElementById('select_colegiados').value == "0")
	{
		alert("Debe seleccionar un colegiado");
		document.getElementById('select_colegiados').focus();
	}
	else
	{
			document.form.submit();
	}
}



//// ########## APARTADO VOCES ##################

function Alta_Voz()
{
	
	if (document.getElementById('tipo').value == "0")
	{
			alert("Debe rellenar el campo 'TIPO' del formulario");
			document.getElementById('tipo').focus();		
	}
	else
	{
		if (document.getElementById('voz').value == "") 
		{
			alert("Debe rellenar el campo 'VOZ' del formulario");
			document.getElementById('voz').focus();
		}
		else
		{
			document.form1.submit();
		}
	}
}

function Modificar_Voz()
{
	if (document.getElementById('select_voces').value=="0")
	{
		alert("Debe seleccionar una VOZ");
		document.getElementById('select_voces').focus();
	}
	else
	{
		if (document.getElementById('voz').value == "") 
		{
			alert("Debe rellenar la nueva descripción de la 'VOZ' del formulario");
			document.getElementById('voz').focus();
		}
		else
		{
			document.form1.submit();
		}
	}
}

function Eliminar_Voz()
{
	if (document.getElementById('select_voces').value=="0")
	{
		alert("Debe seleccionar una VOZ");
		document.getElementById('select_voces').focus();
	}
	else
	{
		document.form1.submit();
	}
}


/// ####### APARTADO PETICIONARIOS ####################

function Alta_Peticionario()
{
	if (document.getElementById('peticionario').value == "") 
	{
		alert("Debe rellenar el campo 'DESCRIPCIÓN' del formulario");
		document.getElementById('peticionario').focus();
	}
	else
	{
		document.form1.submit();
	}
}

function Modificar_Peticionario()
{
	if (document.getElementById('select_peticionarios').value=="0")
	{
		alert("Debe seleccionar un PETICIONARIO");
		document.getElementById('select_peticionarios').focus();
	}
	else
	{
		if (document.getElementById('peticionario').value == "") 
		{
			alert("Debe rellenar la nueva descripción del 'PETICIONARIO' del formulario");
			document.getElementById('peticionario').focus();
		}
		else
		{
			document.form1.submit();
		}
	}
}

// ############ APARTADO DICTAMENES #######################3

function Alta_Dictamen()
{
	if (document.getElementById('select_voces').value == "0")
	{
			alert("Debe rellenar la 'VOZ' del Dictámen.");
		document.getElementById('select_voces').focus();
	}
	else
	{
		if (document.getElementById('select_peticionarios').value == "0")
		{
			alert("Debe rellenar el 'PETICIONARIO' del Dictámen.");
			document.getElementById('select_peticionarios').focus();
		}
		else
		{
			if (document.getElementById('fecha_peticion').value == "")
			{
				alert("Debe rellenar la 'FECHA DE PETICION' del Dictámen.");
				document.getElementById('fecha_peticion').focus();
			}
			else
			{
				if (document.getElementById('fecha_emision').value == "")
				{
					alert("Debe rellenar la 'FECHA DE EMISION' del Dictámen.");
					document.getElementById('fecha_emision').focus();
				}
				else
				{
					if (document.getElementById('objeto').value == "")
					{
						alert("Debe rellenar el 'OBJETO' del Dictámen.");
						document.getElementById('objeto').focus();
					}
					else
					{	
						if (document.getElementById('texto').value == "")
						{
							alert("Debe rellenar el 'DICTAMEN' del Dictámen.");
							document.getElementById('texto').focus();
						}
						else
						{
							document.form1.submit();							
						}
					}
				}
			}
		}
	}
}

function Imprimir_Dictamen(id)
{
      Ventana=open("","","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,width=666,height=400");
	  Encoger(Ventana,666,400);
	  Ventana.location.href='dictamen_imprimir.php?id='+id;
	  Ventana.focus();
}


//////// INFORMES ////////////////////

function Alta_Informe()
{
	if (document.getElementById('select_anos').value == "0")
	{
		alert("Debe rellenar un 'AÑO' del Informe.");
		document.getElementById('select_anos').focus();
	}
	else
	{
		document.form1.submit();
	}
}

function Informe_Periodo()
{
if (document.getElementById('fecha_inicio').value == "")
	{
		alert("Debe rellenar el campo 'FECHA INICIO'.");
		document.getElementById('fecha_inicio').focus();
	}
	else
	{
		if (document.getElementById('fecha_fin').value == "")
		{
			alert("Debe rellenar el campo 'FECHA FIN'.");
			document.getElementById('fecha_fin').focus();
		}
		else
		{
		document.form1.submit();
		}
	}	
}



//////////// CUDIGO PARA EL TOOLTIP
//Begin dHTML Toolltip Timer
var tipTimer;
//End dHTML Toolltip Timer

function locateObject(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=locateObject(n,d.layers[i].document); return x;
}

function hideTooltip(object)
{
if (document.all)
{
	locateObject(object).style.visibility="hidden"
	locateObject(object).style.left = 1;
	locateObject(object).style.top = 1;
return false
}
else if (document.layers)
{
	locateObject(object).visibility="hide"
	locateObject(object).left = 1;
	locateObject(object).top = 1;
	return false
}
else
	return true
}

function showTooltip(object,e, tipContent, backcolor, bordercolor, textcolor, displaytime)
{
	window.clearTimeout(tipTimer)
	
	if (document.all)
		{
			locateObject(object).style.top=document.body.scrollTop+event.clientY+20
			
			locateObject(object).innerHTML='<table style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+'" width="150" border="0" cellspacing="1" cellpadding="1"><tr><td><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table> '

			if ((e.x + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
				{	
					locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth-10;
				}
			else
			{
			locateObject(object).style.left=document.body.scrollLeft+event.clientX
			}
		locateObject(object).style.visibility="visible"
		tipTimer=window.setTimeout("hideTooltip('"+object+"')", displaytime);
		return true;
		}
	else if (document.layers)
		{
		locateObject(object).document.write('<table width="10" border="0" cellspacing="1" cellpadding="1"><tr bgcolor="'+bordercolor+'"><td><table width="10" border="0" cellspacing="0" cellpadding="2"><tr bgcolor="'+backcolor+'"><td><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table></td></tr></table>')
		locateObject(object).document.close()
		locateObject(object).top=e.y+20

		if ((e.x + locateObject(object).clip.width) > (window.pageXOffset + window.innerWidth))
			{
				locateObject(object).left = window.innerWidth - locateObject(object).clip.width-10;
			}
		else
			{
			locateObject(object).left=e.x;
			}
		locateObject(object).visibility="show"
		tipTimer=window.setTimeout("hideTooltip('"+object+"')", displaytime);
		return true;
	}
	else
	{
		return true;
	}
}






