// JavaScript Document
function validar(x){
  if(x == 'contactos'){
	var email = document.form1.email.value;
	if(document.form1.nombres.value == ''){
	  alert('Nombres es un campo requerido.');
	}else if(document.form1.apellidos.value == ''){
	  alert('Apellidos es un campo requerido.');
	}else if(document.form1.telefono.value == ''){
	  alert('Tel\éfono es un campo requerido.');
	}else if(email == "" || email.indexOf ('@') == -1 || email.indexOf ('.') == -1 || (email.indexOf('.') < email.indexOf('@')+3)){
	  alert('Email es un campo requerido.');
	}else if(document.form1.fuente.value == ''){
	  alert('C\ómo se enter\ó de nosotros? es un campo requerido.');
	}else if(document.form1.comentarios.value == ''){
	  alert('Preguntas o sugerencias es un campo requerido.');
	}else{
	  document.form1.submit();
	}
  }
}
function getAction(x){
  if(x == 'seleccionar'){
	document.form1.accion.value = 'seleccionar';
	document.form1.submit();
  }else if(x == 'eliminar'){
	if(document.form1.codigo.value == 0){
	  alert('Seleccione una opci\ón para eliminarla.');
	}else{
	  document.form1.accion.value = 'eliminar';
	  document.form1.submit();
	}
  }else if(x == 'horarios_borrar'){
    document.form1.accion.value = 'ingresar';
	document.form1.codigo.options[0].selected = true;
	document.form1.dia.options[0].selected = true;
	document.form1.hora.options[0].selected = true;
	document.form1.clase.value = '';
	document.form1.profesor.value = '';
  }else if(x == 'horarios_guardar'){
	if(document.form1.dia.value == 0){
	  alert('Seleccione un d\ía del listado.');  
	}else if(document.form1.hora.value == 0){
	  alert('Seleccione una hora del listado.');
	}else if(document.form1.clase.value == ''){
	  alert('Clase es un campo requerido.');
	}else{
	  document.form1.submit();  
	}
  }else if(x == 'noticias_borrar'){
	document.form1.accion.value = 'ingresar';
	document.form1.codigo.options[0].selected = true;
	document.form1.titulo.value = '';
	document.form1.texto.value = '';
	document.form1.fecha.value = '';
	document.form1.archivo.value = '';
  }else if(x == 'noticias_guardar'){
	if(document.form1.titulo.value == ''){
	  alert('T\ítulo es un campo requerido.');
	}else if(document.form1.texto.value == ''){
	  alert('Texto es un campo requerido.');
	}else if(document.form1.fecha.value == ''){
	  alert('Fecha es un campo requerido.');
	}else{
	  document.form1.submit();
	}
  }
}
function abreVentana(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function redimensionar(ancho,alto){
  this.resizeTo(ancho+30,alto+100)
  this.moveTo((screen.width-ancho)/2,(screen.height-alto)/2) //centra la ventana. Eliminar si no se quiere centrar el popup
}
function capa_horarios(x){
  if(x == 1){
	showDivPos('horarios')  
  }else{
	hideDiv('horarios')
  }
}
function getRefToDiv(divID,oDoc) {
    if( !oDoc ) { oDoc = document; }
    if( document.layers ) {
        if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
            //repeatedly run through all child layers
            for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
                //on success, return that layer, else return nothing
                y = getRefToDiv(divID,oDoc.layers[x].document); }
            return y; } }
    if( document.getElementById ) {
        return document.getElementById(divID); }
    if( document.all ) {
        return document.all[divID]; }
    return false;
}

function showDiv(divID_as_a_string) {
    //get a reference as above ...
    myReference = getRefToDiv(divID_as_a_string);
    if( !myReference ) {
        window.alert('Nothing works in this browser');
        return false; //don't go any further
        //return anything would work,
        //but I am using false to show failure
    }
    //now we have a reference to it
    if( myReference.style ) { //DOM & proprietary DOM
        myReference.style.visibility = 'visible';
		myReference.style.top = 430;
    } else {
        if( myReference.visibility ) { //Netscape
            myReference.visibility = 'show';
			myReference.top = 430;
        } else {
            window.alert('Nothing works in this browser');
            return false; //don't go any further
        }
    }
    return true;
}
function showDivPos(divID_as_a_string) {
    //get a reference as above ...
    myReference = getRefToDiv(divID_as_a_string);
    if( !myReference ) {
        window.alert('Nothing works in this browser');
        return false; //don't go any further
        //return anything would work,
        //but I am using false to show failure
    }
    //now we have a reference to it
    if( myReference.style ) { //DOM & proprietary DOM
        myReference.style.visibility = 'visible';
		myReference.style.left = (screen.width/2)-405;
		myReference.style.top = 120;
    } else {
        if( myReference.visibility ) { //Netscape
            myReference.visibility = 'show';
			myReference.left = (screen.width/2)-405;
			myReference.top = 120;
        } else {
            window.alert('Nothing works in this browser');
            return false; //don't go any further
        }
    }
    return true;
}
function hideDiv(divID_as_a_string) {
    //get a reference as above ...
    myReference = getRefToDiv(divID_as_a_string);
    if( !myReference ) {
        window.alert('Nothing works in this browser');
        return false; //don't go any further
        //return anything would work,
        //but I am using false to show failure
    }
    //now we have a reference to it
    if( myReference.style ) { //DOM & proprietary DOM
        myReference.style.visibility = 'hidden';
    } else {
        if( myReference.visibility ) { //Netscape
            myReference.visibility = 'hide';
        } else {
            window.alert('Nothing works in this browser');
            return false; //don't go any further
        }
    }
    return true;
}
function showLayer(x){
  for(i=1;i<=15;i++){
	if (x==i) {
	  showDiv('l_'+i);
	}else{
	  hideDiv('l_'+i);
	}
  }
}
function resizeCell(id,value) {
		var cell=document.getElementById(id);
		//alert(cell.offsetHeight);
		cell.setAttribute('height',value); 
		}