function eliminar(ide,tabla){
	if(confirm(" Eliminar ?")){
		document.getElementById('id').value=ide;
		document.getElementById('tabla').value=tabla;
		document.eliminar.submit();	
	}
}
function mostrarPuntos(ptos) {
		document.getElementById('valoracionPuntos').innerHTML=(ptos/2)+' / 5';
}
function compRegistro(){
	if(document.registro.nick.value.length==0){
		alert('Introduce un nick');
		document.registro.nick.focus();
		return false;
	}
	if(document.getElementById('disponible')=="no"){
		alert('El nick no esta disponible');
		document.registro.nick.focus();
		return false;
	}
	if(document.registro.passw.value.length==0){
		alert('Introduce un password');
		document.registro.passw.focus();
		return false;
	}
	if(document.registro.passw2.value.length==0){
		alert('Repite el password');
		document.registro.passw2.focus();
		return false;
	}
	if(document.registro.passw.value!=document.registro.passw2.value){
		alert('Los passwords no coinciden');
		document.registro.passw.focus();
		return false;
	}
	if(document.registro.email.value.length==0){
		alert('Introduzca un email');
		document.registro.email.focus();
		return false;
	}
	apos=document.registro.email.value.indexOf("@")
	dotpos=document.registro.email.value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2){
	alert("Dirección email no valida");
	document.registro.email.focus();
	return false;
	}
	document.registro.submit();
}
	

function comprobarNick(){
		var nick=document.getElementById('nick').value;
		if(nick.length==0){
			alert('Escribe algun nick');
		}else{
		var ajax=nuevoAjax();
		var aleatorio=Math.random();
		var Contenido=document.getElementById('contenido');
		var cad="addclick.php?nick="+nick+"&aleatorio="+aleatorio;
		ajax.open("GET", cad, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
			// Al recibir la respuesta coloco directamente el HTML en la capa contenedora
			Contenido.innerHTML=ajax.responseText;
			}
		}
		}
}

function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objeto AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}
function addClick(ide){
		window.open('addclick.php?ide='+ide,'','height=1,width=1');
}
function smilies(smile) {
	var inserta=document.agregar.elements["Comentario"];
	inserta.value=inserta.value+smile+' ';
	document.agregar.Comentario.focus();
}
function comprobarModificar(){
	if(document.formModificar.nick.value.length==0){
		alert('Escribe un nick');
		document.formModificar.nick.focus();
		return 0;
	}
	if(document.formModificar.passw.value!=0){
			if(document.formModificar.passw.value!=document.formModificar.passw2.value){
				alert("Los passwords no coinciden");
				document.formModificar.passw.focus();
				return 0;
			}
	}
	
	apos=document.formModificar.email.value.indexOf("@")
	dotpos=document.formModificar.email.value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2){
		alert("Dirección email no valida");
		document.formModificar.email.focus();
		return 0;
	}
	document.formModificar.submit();
}

function comprobarRegistro(){
	if(document.formRegistro.nick.value.length==0){
		alert('Escribe un nick');
		document.formRegistro.nick.focus();
		return 0;
	}
	if(document.formRegistro.passw.value==0){
		alert('Escribe un password');
		document.formRegistro.passw.focus();
		return 0;
	}
	if(document.formRegistro.passw2.value==0){
		alert('Repite el password');
		document.formRegistro.passw2.focus();
		return 0;
	}
	
	if(document.formRegistro.passw.value!=document.formRegistro.passw2.value){
	alert("Los passwords no coinciden");
	document.formRegistro.passw.focus();
	return 0;
	}
	
	apos=document.formRegistro.email.value.indexOf("@")
	dotpos=document.formRegistro.email.value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2){
		alert("Dirección email no valida");
		document.formRegistro.email.focus();
		return 0;
	}
	document.formRegistro.submit();
}


function comprobarMod(){
	if(document.formModifica.titulo.value.length==0){
		alert('Escribe un titulo');
		document.formModifica.titulo.focus();
		return 0;
	}
	if(document.formModifica.formato.value==0){
		alert('Selecciona un formato');
		document.formModifica.formato.focus();
		return 0;
	}
	if(document.formModifica.categoria.value==0){
		alert('Selecciona una categoria');
		document.formModifica.categoria.focus();
		return 0;
	}
	if(document.formModifica.descripcion.value==0){
		alert('Escribe una breve descripcion sobre el archivo');
		document.formModifica.descripcion.focus();
		return 0;
	}
	
	document.formModifica.submit();
}

function comprobarEnvio(){
	if(document.formEnvio.titulo.value.length==0){
		alert('Escribe un titulo');
		document.formEnvio.titulo.focus();
		return 0;
	}
	if(document.formEnvio.formato.value==0){
		alert('Selecciona un formato');
		document.formEnvio.formato.focus();
		return 0;
	}
	if(document.formEnvio.categoria.value==0){
		alert('Selecciona una categoria');
		document.formEnvio.categoria.focus();
		return 0;
	}
	if(document.formEnvio.descripcion.value==0){
		alert('Escribe una breve descripcion sobre el archivo');
		document.formEnvio.descripcion.focus();
		return 0;
	}
	if(document.formEnvio.archivo.value==0){
		alert('Sube algun archivo!');
		document.formEnvio.archivo.focus();
		return 0;
	}	
	document.formEnvio.submit();
}

function objetus(file) {
    xmlhttp=false;
    this.AjaxFailedAlert = "Su navegador no soporta las funciónalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada. Por favor habilite javascript en su navegador para verlo normalmente.\n";
    this.requestFile = file;
    this.encodeURIString = true;
    this.execute = false;
    if (window.XMLHttpRequest) { 
        this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType) {
            this.xmlhttp.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            this.xmlhttp = new XMLHttpRequest();
            if (!this.xmlhttp){
                this.failed = true; 
            }
        } 
    }
    return this.xmlhttp ;
}
function mover(nombre,accion,posicion){
	recibeid("mover_bloques.php","nombre="+nombre+"&accion="+accion+"&posicion="+posicion,"","bloques");
}

function recibeid(_pagina,valorget,valorpost,capa){ 
    ajax=objetus(_pagina);
    if(valorpost!=""){
        ajax.open("POST", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    } else {
        ajax.open("GET", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    }
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1){
            document.getElementById(capa).innerHTML = 
				"<img src='img/loadingcircle.gif' align='center' />";
        }
        if (ajax.readyState==4) {
            if(ajax.status==200)
            {document.getElementById(capa).innerHTML = ajax.responseText;}
            else if(ajax.status==404)
            {
                capa.innerHTML = "La direccion no existe";
            }
            else
            {
                capa.innerHTML = "Error: ".ajax.status;
            }
        }
    }
    if(valorpost!=""){
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajax.send(valorpost);
    } else {
        ajax.send(null);
    }
} 
