function continuar_1(){
 var Check = document.login;

 if(Check.usuario.value == '' || Check.pw.value == '') 
	return false;
 else
	return true;
}

function cm_dia()
{
    dia = document.registro.dia.value.length;
    if(dia>0){
     dia = document.registro.dia.value;
     if(dia<1) document.registro.dia.value = 1;
     else if(dia>31) document.registro.dia.value = 31;
    }else{
     document.registro.dia.value = 1;
    }
}

function cm_mes()
{
    mes = document.registro.mes.value.length;
    if(mes>0){
     mes = document.registro.mes.value;
     dia = document.registro.dia.value;
     if(mes<1) document.registro.mes.value = 1;
     else if(mes>12) document.registro.mes.value = 12;
     if(mes<7){
      if((mes%2==0)&&(dia>30)) document.registro.dia.value = 30;
     }else if(mes>6){
      if((mes%2!=0)&&(dia>30)) document.registro.dia.value = 30;
     }
    }else{
     document.registro.mes.value = 1;
    }
}

function cm_ano()
{
   ano = document.registro.ano.value.length;
   mes = document.registro.mes.value.length;
   dia = document.registro.dia.value.length;
   if((ano>0)&&(mes>0)&&(dia>0)){
    ano = document.registro.ano.value;
    actual = document.registro.ano2.value;
    mes = document.registro.mes.value;
    dia = document.registro.dia.value;
    if(ano<1900) document.registro.ano.value = 1900;
    else if(ano>actual) document.registro.ano.value = actual;
    if(mes==2)
    {
     if((dia>29)&&(ano%4==0)) document.registro.dia.value = 29;
     else if((dia>28)&&(ano%4!=0)) document.registro.dia.value = 28;
    }
   }
   else
   {
     document.registro.ano.value = 1900;
   }
}

function check_registro_secciones()
{
 var Compo = document.registro;
 var error = '';
 if(Compo.regtitulo.value == '')
 {
  error += '* Debes de poner un titulo a la seccion';
 }
 if(error != '')
 {
  error = 'ATENCION! No puedes continuar a causa de:\n\n'+error;
  alert(error);
  return false;
 }
 else {
  return true;
 }
}

function check_registro_usuarios(){
 var Compo = document.registro;
 var error = '';
 if(Compo.regnick.value == '')
 {
  error += '* Debes de Introducir un nick\n';
 }
 if(Compo.regnombre.value == '')
 {
  error += '* Debes de Introducir un nombre\n';
 }
 if(Compo.regapellidos.value == '')
 {
  error += '* Debes de Introducir los apellidos\n';
 }
 if(Compo.regdni.value.length < 8 && Compo.regdni.value != '')
 {
  error += '* El NIF al menos debe de contener 8 caracteres\n';
 }
 else if(Compo.regdni.value.length == 8 && isNaN(Compo.regdni.value))
 {
  error += '* Formato de NIF incorrecto [00000000A]\n';
 }
 if(Compo.regmail.value == '')
 {
  error += '* Debes de Introducir una cuenta de correo\n';
 }
 if(Compo.regmovil.value != '' && isNaN(Compo.regmovil.value))
 {
  error += '* El movil solo puede contener numeros\n';
 }
 if(Compo.regtelefono.value != '' && isNaN(Compo.regtelefono.value))
 {
  error += '* El telefono solo puede contener numeros\n';
 }
 if(error != '') {
  error = 'ATENCION! No puedes continuar a causa de:\n\n'+error;
  alert(error);
  return false;
 }
 else {
  return true;
 }
}

function active_moderador()
{
 var Compo = document.registro;
 if(Compo.nivel[Compo.nivel.selectedIndex].value == 1)
 {
  Compo.estado.selectedIndex = 0;
 }
}

function check_titulos()
{
 var Compo = document.regtitulos;
 var error = '';
 if(Compo.tnombre.value == '')
 {
  error += '* Debes de Introducir un nombre\n';
 }
 if(Compo.tmin.value == '')
 {
  error += '* El valor minimo debe ser como minimo 0\n';
 }
 if(Compo.tmax.value == '')
 {
  error += '* El valor maximo debe ser como minimo 1\n';
 }
 if(parseInt(Compo.tmin.value) >= parseInt(Compo.tmax.value))
 {
  error += '* El valor minimo no puede ser mayor o igual que el maximo\n ';
 }
 if(isNaN(Compo.tmin.value))
 {
  error += '* El valor minimo no pueden ser letras.\n';
 }
 if(isNaN(Compo.tmax.value))
 {
  error += '* El valor maximo no pueden ser letras.\n';
 }
 if(error != '')
 {
  error = 'ATENCION! No puedes continuar a causa de:\n\n'+error;
  alert(error);
  return false;
 }
 else {
  return true;
 }
}

function check_perfil()
{
 var Compo = document.registro;
 var error = '';
 if(Compo.regnombre.value == '')
 {
  error += '* Debes de Introducir un nombre\n';
 }
 if(Compo.password.value != '' && Compo.password.value != Compo.password2.value)
 {
  error += '* Las contraseñas no son iguales\n';
 }
 if(Compo.regapellidos.value == '')
 {
  error += '* Debes de Introducir los apellidos\n';
 }
 if(Compo.regdni.value.length < 8 && Compo.regdni.value != '')
 {
  error += '* El NIF al menos debe de contener 8 caracteres\n';
 }
 if(Compo.regdni.value.length == 8 && isNaN(Compo.regdni.value))
 {
  error += '* Formato de NIF incorrecto [00000000A]\n';
 }
 if(Compo.regmail.value == '')
 {
  error += '* Debes de Introducir una cuenta de correo\n';
 }
 if(Compo.regmovil.value != '' && isNaN(Compo.regmovil.value))
 {
  error += '* El movil solo puede contener numeros\n';
 }
 if(Compo.regtelefono.value != '' && isNaN(Compo.regtelefono.value))
 {
  error += '* El telefono solo puede contener numeros\n';
 }
 if(error != '')
 {
  error = 'ATENCION! No puedes continuar a causa de:\n\n'+error;
  alert(error);
  return false;
 }
 else {
  return true;
 }
}

function check_newpost()
{
 var Compo = document.newpost;
 var error = '';
 if(Compo.titulo.value == '')
 {
  error += '* Debes de poner un titulo al tema\n';
 }
  if(Compo.mensaje.value == '')
 {
  error += '* Debes de poner un mensaje al tema\n';
 }
 if(error != '')
 {
  error = 'ATENCION! No puedes continuar a causa de:\n\n'+error;
  alert(error);
  return false;
 }
 else
 {
  Compo.submit();
  return true;
 }
}


function ocultar(Capa1,Show) //identificador tabla - enlace
{
         var C1 = document.getElementById(Capa1);
         if(C1.style.display == "none") {
             C1.style.display="";
             C1 = document.getElementById(Show);
             C1.innerHTML = '-';
         }
         else {
             C1.style.display="none";
             C1 = document.getElementById(Show);
             C1.innerHTML = '+';
         }
}

function validar(id)
{
      var udel = document.getElementById(id);
      var contador = document.getElementById('formulario');
      if(udel.checked) contador.value++;
      else contador.value--;
}

function continuar(tipo)
{
      var contador = document.getElementById('formulario');
      if(contador.value == 0) return false;
      else if(tipo == 'borrar' && contador.value > 0)
      {
       var continuo = confirm('¿Desea borrar '+contador.value + document.registro.mod.value+'?');
       if(continuo == false) return false;
	   else return true;
      }
	  else {
	  return true;
	  }
}

function continuarb2(tipo)
{
      var continuo = confirm('¿Desea borrar la '+tipo+ ' ?');
      if(continuo == false) return false;
	  else return true;
}

function ocultarBig()
{
    jQuery('#grande').fadeOut('fast',function(){
        jQuery(this)[0].innerHTML = '';
        jQuery(this).css('display','');
        window.onscroll='';
    });
	/*var x1 = document.getElementById('grande');
	x1.innerHTML = '';*/
}

        jQuery.clientCoords = function() {
             var dimensions = {width: 0, height: 0};

             if (typeof window.innerWidth != 'undefined')
             {
                  dimensions.width = window.innerWidth,
                  dimensions.height = window.innerHeight
             }

            // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

             else if (typeof document.documentElement != 'undefined'
                 && typeof document.documentElement.clientWidth !=
                 'undefined' && document.documentElement.clientWidth != 0)
             {
                   dimensions.width = document.documentElement.clientWidth,
                   dimensions.height = document.documentElement.clientHeight
             }

             // older versions of IE

             else
             {
                   dimensions.width = document.getElementsByTagName('body')[0].clientWidth,
                   dimensions.height = document.getElementsByTagName('body')[0].clientHeight
             }
             return dimensions;
        }

function grande(este){
 var direc = este;
 var ruta = '';
 
 direc = direc.split('/');
 direc.splice(direc.length - 2,1);
 direc = direc.join('/');

 ruta = '.';
 var x = 0;
 var y = 0;
 var x1 = document.getElementById('grande');
 x1.innerHTML = '<div id="fotoGrande"></div>'+
 '<div id="cuerpoFotoGrande">'+
 '<img src="'+String(ruta)+'/images/flecha-izq.png" id="flecha-izq" width="105" height="48" alt="Foto Anterior" title="Foto Anterior" class="flechaIzq" onclick="javascript:dameFoto(\'resta\');" />'+
 '<img src="'+String(direc)+'" id="marcoFoto"  style="display:none"  width="'+String(x)+'" height="'+String(y)+'" alt="" title="" class="img"/>'+
 '<img src="'+String(ruta)+'/images/flecha-der.png" id="flecha-der" width="105" height="48" alt="Foto Siguiente" title="Foto Siguiente" class="flechaDer" onclick="javascript:dameFoto(\'suma\');" />'+
 '<img src="'+String(ruta)+'/images/salir.png" width="48" height="48" alt="Salir" title="Salir" class="salir" onclick="javascript:ocultarBig()" style="cursor:pointer" />'+
 '<div id="posicionFotos" title="Posicion de la Foto / Cantidad de Fotos"> 0/0</div>'+
 '</div>';

         var width = 800;
         var height = 600;
         var x2 = jQuery.clientCoords();
         var newW = x2.width-60;
         var newH = x2.height-40;
         if(width > newW ){
             height = (height * newW) / width;
             width = newW;
         }

         if(height > newH ){
             width = (width * newH) / height;
             height = newH;
         }

         jQuery('#cuerpoFotoGrande').css('width',width);
         jQuery('#cuerpoFotoGrande').css('height',height);
         jQuery('#cuerpoFotoGrande').css('margin-left',(width/2)*-1);
         jQuery('#cuerpoFotoGrande').css('margin-top',(height/2)*-1);         

 dameFoto('nada');
}

function dameFoto(sumaResta){
    /*if(imagen != undefined)
    else*/
     var sel = document.getElementById('marcoFoto');
     var ruta = sel.src;
     ruta = ruta.split('/');
     ruta.splice(0,4);
     ruta = ruta.join('/');
    jQuery('#marcoFoto').fadeOut('slow',function(){
        $.ajax({type: "POST",url: "damefotos.php",data: "foto="+ruta+"&metodo="+sumaResta,
            beforeSend: function(){
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                alert(textStatus);
            },
            success: function(html){
                       var vari = html;
                       var cantidad = vari.getElementsByTagName("valor").item(0).firstChild.data;
                       var max = vari.getElementsByTagName("valor").item(1).firstChild.data;
                       var min = vari.getElementsByTagName("valor").item(2).firstChild.data;
                       var width = vari.getElementsByTagName("valor").item(5).firstChild.data;
                       var height = vari.getElementsByTagName("valor").item(6).firstChild.data;

                        sel.src = cantidad;

             /* obtenemos el tamaño de la ventana del navegador */
             var x = jQuery.clientCoords();
             var newW = x.width-60;
             var newH = x.height-40;
             if(width > newW ){
                 height = (height * newW) / width;
                 width = newW;
             }

             if(height > newH ){
                 width = (width * newH) / height;
                 height = newH;
             }

    //         jQuery('#mypopup').show('slow');

                        sel.width = width;
                        sel.height = height;
                        sel.style.marginTop =-parseInt(height / 2)+"px";
                        sel.style.marginLeft = -parseInt(width / 2)+"px";
                        sel.style.top = "50%";
                        sel.style.left = "50%";

                            if(max == 1) {
                             sel = document.getElementById('flecha-der');
                             ruta = sel.src;
                             ruta = ruta.split('/');
                             ruta[ruta.length-1] = 'flecha-der-desmarcado.png';
                             ruta = ruta.join('/');
                             if(sel.src != ruta) {
                              sel.src = ruta;
                              sel.style.cursor = '';
                              sel.onclick = '';
                             }
                            } else {
                             sel = document.getElementById('flecha-der');
                             ruta = sel.src;
                             ruta = ruta.split('/');
                             ruta[ruta.length-1] = 'flecha-der.png';
                             ruta = ruta.join('/');
                             if(sel.src != ruta) {
                              sel.src = ruta;
                              sel.style.cursor = 'pointer';
                              sel.onclick = function onclick(event){javascript:dameFoto("suma");};
                             }
                            }

                            if(min == 1) {
                             sel = document.getElementById('flecha-izq');
                             ruta = sel.src;
                             ruta = ruta.split('/');
                             ruta[ruta.length-1] = 'flecha-izq-desmarcado.png';
                             ruta = ruta.join('/');
                             if(sel.src != ruta) {
                              sel.src = ruta;
                              sel.style.cursor = '';
                              sel.onclick = '';
                             }
                            } else {
                             sel = document.getElementById('flecha-izq');
                             ruta = sel.src;
                             ruta = ruta.split('/');
                             ruta[ruta.length-1] = 'flecha-izq.png';
                             ruta = ruta.join('/');
                             if(sel.src != ruta) {
                              sel.src = ruta;
                              sel.style.cursor = 'pointer';
                              sel.onclick = function onclick(event){javascript:dameFoto("resta");};
                             }
                            }

                       var posicion = vari.getElementsByTagName("valor").item(3).firstChild.data;
                       var posicionMax = vari.getElementsByTagName("valor").item(4).firstChild.data;
                       sel = document.getElementById('posicionFotos');
                       sel.innerHTML = posicion + ' / ' + posicionMax;
                       jQuery('#marcoFoto').load(function(){
                           //alert('voy a mostrar la imagen');
                          jQuery('#marcoFoto').fadeIn('slow');
                       });
            }
        });
    });
}