//funcao abrir pagina em div
try{
xmlhttp = new XMLHttpRequest();
}
catch(ee){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E){
xmlhttp = false;
}
}
}
div_base = "";
function abre(arquivo,metodo,div){
div_base = div;
xmlhttp.open(metodo,arquivo);
xmlhttp.onreadystatechange=conteudo
xmlhttp.send(null)
}
function conteudo() {
nova_div = div_base;
document.getElementById(nova_div).innerHTML="cargando..."
if (xmlhttp.readyState==4){
document.getElementById(nova_div).innerHTML=xmlhttp.responseText
}
}
//fim funcao abrir pagina em div
//funcion colorear tr
function colorear(sel){
    //if(sel.checked == true)document.getElementById(sel.name).style.background = '#00FF00';
    //else
    document.getElementById(sel).style.background = '#FFFFFF';
    alert('popopo');
}
//fin colorear tr
//validar formulario
function valida_form(ele){
   var nerr=0;

        numero = ele.elements.length
        erro = "";
        for(i=0; i<numero; i++){
                if(ele.elements[i].alt == "yes"){
                        if(ele.elements[i].name == "correo" || ele.elements[i].name == "e-mail" || ele.elements[i].name == "mail"){
                                if(ele.elements[i].value.indexOf('@')==-1 || ele.elements[i].value.indexOf('.')==-1){
                                erro = erro + "Preencha o campo '"+ ele.elements[i].name.toUpperCase() +"' corretamente. \n"
                                nerr++;
                                }
                        }else{
                                if(ele.elements[i].value=="" || ele.elements[i].value==" "){
                                erro = erro + "Rellene el campo '"+ ele.elements[i].name.toUpperCase() +"'. \n"
                                nerr++;
                                }
                        }
                }
                if(ele.elements[i].title == "yes"){
                        if(ele.elements[i].value=="" || ele.elements[i].value==" "){
                        erro = erro + "Rellene el campo '"+ ele.elements[i].name.toUpperCase() +"'. \n"
                        nerr++;
                        }
                }
        }

        if(erro != ""){
                alert("Errors: "+nerr+" \n"+erro);
                return false
        }else{
                return true
        }
}
//fin validar formulario

//funcion bloquear comillas
function comillas(caracter)
{
  var tecla;
  if(window.event)
  { // Internet Explorer
  tecla = event.keyCode;
  }
  else
  { // Firefox
  tecla = caracter.which;
  }

  if(tecla == 34 || tecla == 39 || tecla == 13) //bloqua que se escriba comillas simple(39) o dobles(34)
  {
  //alert('33');

  var targ=caracter.target; //alert(targ);
     if((targ == "[object HTMLTextAreaElement]" || targ == "[object HTMLButtonElement]") && tecla == 13)
       return true;
     else
       return false;
  }
  else
  {
  //alert('otra');
  return true;
  }
}

//fin bloquear comillas

//funcion confirma cierre ejercicio (llamada en menu2)
function si_cierra_eje()
{
 if(confirm('Se creará una base de datos para el nuevo ejercicio. ¿Aceptar? ')==true)
 {
   window.location.href="index_login.php?pagina=includes/creabase.php";
   return true;
 }
 else{
   return false;
 }
}
//fin funcion confirma cierre

//verifica si hay campos seleccionados para montar impresion
function seleccionados(control) {
	marcados = 0;
	for (i = 0, total = control.options.length; i < total; i ++)
		marcados += (control.options[i].selected);// ? 1 : 0;
    //alert(marcados);
    return marcados;
}

//fin verifica
// popup centro pantalla

function popcentro(url,nome,wi,he, settings){
    var  w, h, left, top

    w=screen.width
    h=screen.height

    left=(w-wi)/2
    top=(h-he)/2

    settings+=",width="+wi+",height="+he+", left="+left+", top="+top

    window.open(url, nome, settings)
}
//fin popcentro
function validafiltro()
{
 var select = document.getElementById('campos[]');
 if(select.value != "")
 {
 popcentro('','nuevaventana','800','700','scrollbars=yes');
 }
 else
 {
 alert('Hay que elegir, minimo, un campo para imprimir');
 return false;

 }
}

//solo abrir impresion en nueva ventana, sin validar campos
function nueva_ventana()
{
popcentro('','nuevaventana','800','700','scrollbars=yes');
}

function nueva_ventana2()
{
popcentro('','nuevaventana2','500','400','scrollbars=no');
//self.setTimeout('window.close();', 1500);
}

//validar campo solo para numeros inteiros
function validar_inteiro(valor)
{
      //tento converter a inteiro.
     //se for um inteiro nao lhe afeta, se não for tenta convertelo
     valor = parseInt(valor)
         //alert(valor);
      //Comprovo se é um valor numérico
      if (isNaN(valor)) {
      //alert('popo');
            //entao (nao e numero) devuelvo el valor cadena vacia
            document.frmti.tiempo.value="";
      }else{
            //No caso contrario (Se for um número) devolvo o valor
            document.frmti.tiempo.value=valor;
      }
}
//fin numeros inteiros
//pestanas
function tab(pestana,panel)
{
   pst = document.getElementById(pestana);
   pnl = document.getElementById(panel);
   psts = document.getElementById('tabs').getElementsByTagName('li');
   pnls = document.getElementById('paneles').getElementsByTagName('div');

   // eliminamos las clases de las pestañas
   for(i=0; i< psts.length; i++)
   {
   // Para evitar meternos en temas de dom
   // hacemos que la clase sea vacío
      psts[i].className = '';
   }

   // Añadimos la clase "actual" a la pestaña activa
   pst.className = 'actual';

   // ocultamos todos los paneles
   for(i=0; i< pnls.length; i++)
   {
      //alert(pnls[i].id);
      if(pnls[i].className!='div_in')
      pnls[i].style.display = 'none';
   }

   // Y mostramos el panel que nos interesa
   pnl.style.display = 'block';
}
//fin pestanas
//Drag and Drop script
if  (document.getElementById){
(function(){
if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}
var n = 500;
var dragok = false;
var y,x,d,dy,dx;
function move(e){
if (!e) e = window.event;
 if (dragok){
  d.style.left = dx + e.clientX - x + "px";
  d.style.top  = dy + e.clientY - y + "px";
  return false;
 }
}
function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
 temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
 }
if (temp.className == "dragclass"){
 if (window.opera){
  document.getElementById("Q").focus();
 }
 dragok = true;
 temp.style.zIndex = n++;
 d = temp;
 dx = parseInt(temp.style.left+0);
 dy = parseInt(temp.style.top+0);
 x = e.clientX;
 y = e.clientY;
 document.onmousemove = move;
 return false;
 }
}
function up(){
dragok = false;
document.onmousemove = null;
}
document.onmousedown = down;
document.onmouseup = up;
})();
}

