function OpenWindow(url, nombre, opciones){
  window.open(url, nombre, opciones);}

function envia_form(form, pagina){
  form.action = pagina;
  form.submit();}

function previo(id){
  previo = window.open('vista_previa.php?id_recurso='+id, 'previo', 'width=640,height=480,scrollbars=yes');}

function selecciona(id){
  if (window.opener.document.forms[0].id_recurso.value.length == 0){
    window.opener.document.all['recurso'].innerHTML = "<a href=javascript:previo(document.forms[0].id_recurso.value) class=texmenu>Ver recurso asociado</a> - " + window.opener.document.all['recurso'].innerHTML + " - <a href=javascript:borra_recurso(document.forms[0].id_recurso,'recurso') class=texmenu>Eliminar recurso</a>";}
  window.opener.document.forms[0].id_recurso.value=id;
  window.close();}

function selecciona_imagen(id){
  if (window.opener.document.forms[0].id_imagen.value.length == 0){
    window.opener.document.all['imagen'].innerHTML = "<a href=javascript:previo(document.forms[0].id_imagen.value) class=texmenu>Ver imagen asociada</a> - " + window.opener.document.all['imagen'].innerHTML + " - <a href=javascript:borra_recurso(document.forms[0].id_imagen,'imagen') class=texmenu>Eliminar imagen</a>";}
  window.opener.document.forms[0].id_imagen.value=id;
  window.close();}
  
function borra_recurso(elem, divName){
  if (elem.value != null && elem.value.length > 0){
  elem.value="";
  pos = document.all[divName].innerHTML.indexOf("-")+2;
  ult = document.all[divName].innerHTML.lastIndexOf("-");
  document.all[divName].innerHTML = document.all[divName].innerHTML.substr(pos,ult-pos);}}

function borra_option(elem){
  elem.options[elem.selectedIndex] = null;}

function eliminar(url) {
 var inputedData =  ("");
 if (confirm("Se procederá a ELIMINAR.")) {
  alert ("Se eliminará al aceptar.");
  location.href= url
 } else {
  alert ("Eliminar CANCELADO.");
 }
}
function desvincular(url) {
 var inputedData =  ("");
 if (confirm("Se procederá a DESVINCULAR.")) {
  alert ("Se eliminará al aceptar.");
  location.href= url
 } else {
  alert ("Desvincular CANCELADO.");
 }
}
function papelera(url) {
 var inputedData =  ("");
 if (confirm("Se procederá a enviar a la PAPELERA.")) {
  alert ("Se enviará a la PAPELERA.");
  location.href= url
 } else {
  alert ("Enviar a la PAPELERA CANCELADO.");
 }
}
function restaurar(url) {
 var inputedData =  ("");
 if (confirm("Se procederá a RESTAURAR el documento.")) {
  alert ("Se RESTAURARÁ el documento.");
  location.href= url
 } else {
  alert ("RESTAURACIÓN CANCELADA.");
 }
}
function eliminar_angel(url) {
 var inputedData =  ("");
 if (confirm("ÁNGEL, ¿Seguro que quieres borrar ésto?")) {
  alert ("Mejor AVISA A CRISTINA. Gracias Salao.");
  location.href= url
 } else {
  alert ("Mejor AVISA A CRISTINA. Gracias Salao.");
 }
}
function imprimir(que) {
var ventana = window.open("", "", "");
var contenido = "<html><head><link href='archivos/estructura.css' rel='stylesheet' type='text/css'/><link href='archivos/comunes1.css' rel='stylesheet' type='text/css'/></head><body onload='window.print();window.close();'>" + document.getElementById(que).innerHTML + "</body></html>";
ventana.document.open();
ventana.document.write(contenido);
ventana.document.close();
}
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
   function habilita(){ 
    document.enmienda.pardes.disabled = false;
    document.enmienda.parhas.disabled = false; 
    document.enmienda.lindes.disabled = false;
    document.enmienda.linhas.disabled = false; 	
	document.enmienda.parhas.className = 'hab';
	document.enmienda.pardes.className = 'hab';	
	document.enmienda.linhas.className = 'hab';
	document.enmienda.lindes.className = 'hab';	
	
   } 

   function deshabilita(){ 
    document.enmienda.pardes.disabled = true; 
    document.enmienda.parhas.disabled = true;
    document.enmienda.lindes.disabled = true; 
    document.enmienda.linhas.disabled = true;	
	document.enmienda.parhas.className = 'des';
	document.enmienda.pardes.className = 'des';	
	document.enmienda.linhas.className = 'des';
	document.enmienda.lindes.className = 'des';		
   } 
   function habilita_tex(){ 
    document.enmienda.texsus.disabled = false;
	document.enmienda.texsus.className = 'hab';

   } 

   function deshabilita_tex(){ 
    document.enmienda.texsus.disabled = true; 
	document.enmienda.texsus.className = 'des';

   }    

function validar(formulario) {
  if (formulario.nomdel.value.length < 4) {
    alert("Escriba por lo menos 4 caracteres en el campo \"Nombre\".");
    formulario.nomdel.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
  var checkStr = formulario.nomdel.value;
  var allValid = true; 
  for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    }
  }
  if (!allValid) { 
    alert("Escriba sólo letras en el campo \"Nombre\"."); 
    formulario.nomdel.focus(); 
    return (false); 
  } 
  
  if (formulario.ape1del.value.length < 4) {
    alert("Escriba por lo menos 4 caracteres en el campo \"1 Apellido\".");
    formulario.ape1del.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
  var checkStr = formulario.ape1del.value;
  var allValid = true; 
  for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    }
  }
  if (!allValid) { 
    alert("Escriba sólo letras en el campo \"1º Apellido\"."); 
    formulario.ape1del.focus(); 
    return (false); 
  } 

  if ((formulario.emadel.value.indexOf ('@', 0) == -1)||(formulario.emadel.value.length < 5)) { 
    alert("Escriba una dirección de correo válida en el campo \"Dirección de correo\"."); 
    return (false); 
  }
  return (true); 
}
function cambiaCapa(valor){
	if (valor=="0"){
		capa.className = "oculto";
	} else{
		capa.className = "visible";
	}
}

function ShowDiv(id, valor){
    if(document.getElementById(id).style.display=='none'){
    	document.getElementById(id).style.display='';
    }else{
    	document.getElementById(id).style.display='none';
    }
}
