
function crearAjax()
{
    var xmlhttp=false;
     try 
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) 
    {
        try 
        {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } 
        catch (E) 
        {
               xmlhttp = false;
          }
     }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
    {
          xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}
function test(){
	alert("dentro test!!!");
}

function ldCont(capa,pagina,gif,obj){
	
	if(gif!=0){
		gif="<center><div style='padding-top:70px;'><img src='http://academia.crackstv.com/images/template/ajax-loader.gif'></div></center>";
	}
	else{
		gif="";
	}
//obj para q no se pisen al cargar los 3 a la vez
    var contenedor;
    contenedor = document.getElementById(capa);
    if(!contenedor){
	 contenedor=capa;
	}
	contenedor.innerHTML = "";
	contenedor.innerHTML = gif;
    // creamos un nuevo objeto ajax
    obj=crearAjax();
    
    //cargar el archivo html por el método GET
    obj.open("GET", pagina,true);
    
    obj.onreadystatechange=function() 
    {
        if (obj.readyState==4) // Readystate 4 significa que ya acabó de cargarlo
        {
            contenedor.innerHTML = obj.responseText;
			return true;
        }
		else{
			contenedor.innerHTML = gif
		}
    }
    obj.send(null)
}


function cambiaImg(){
			document.getElementById('avatar').src=document.getElementById('avatarFr').value
}

function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		//alert("La dirección de email " + valor + " es correcta.") 
		return (true)
	} else {
		//alert("La dirección de email es incorrecta.");
		return (false);
	}
}

function validaRegistro(){
	err='';
	if (!validarEmail(document.formcoparte.mail.value)) //email //////////////////////////////
	{
		err+='Debes de introducir el Email correcto\n\r'
		document.formcoparte.mail.style.borderColor='#ff0000';
	}
	
	if (document.formcoparte.nombre.value=="") 
	{
		err+='Debes de introducir el Nombre\n\r';
		document.formcoparte.nombre.style.borderColor='#ff0000';
	}
	
	if (document.formcoparte.nick.value=="") 
	{
		err+='Debes de introducir el Nick\n\r';
		document.formcoparte.nick.style.borderColor='#ff0000';
	}
	
	if (document.formcoparte.apellidos.value=="") 
	{
		err+='Debes de introducir los Apellidos\n\r';
		document.formcoparte.apellidos.style.borderColor='#ff0000';
	}
	
	if (document.formcoparte.clave.value!=document.formcoparte.clave2.value || document.formcoparte.clave.value=="") 
	{
		err+='Debes de introducir la Clave\n\r';
		document.formcoparte.clave.style.borderColor='#ff0000';
		document.formcoparte.clave2.style.borderColor='#ff0000';
	}
	
	/*if (document.formcoparte.movil.value=="") 
	{
		err+='Debes de introducir el Telefono movil\n\r';
		document.formcoparte.movil.style.borderColor='#ff0000';
	}*/
	
	if (!document.formcoparte.checkbox.checked) //email //////////////////////////////
	{
		err+='Debes de Aceptar los terminos legales\n\r';
		document.formcoparte.checkbox.style.borderColor='#ff0000';
	}
	
	if (err!=''){
		alert(err)
		return false
	}
	else{
		return true
	}
	
}

function soloN(e){
	tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    patron2 =/\d/;
    te = String.fromCharCode(tecla); // 5
    return patron2.test(te); // 6

}

function validaIni(){
	err='';

	if (document.formalta.titulo.value=="") 
	{
		err+='Debes de introducir el Titulo\n\r';
		document.formalta.titulo.style.borderColor='#ff0000';
	}
	
	if (document.formalta.consiste.value=="")
	{
		err+='Debes de introducir el texto de tu iniciativa\n\r';
		document.formalta.consiste.style.borderColor='#ff0000';
	}
	
		if (document.formalta.consiste.value.length>400)
	{
		err+='El texto de tu iniciativa no puede superar los 400 caracteres\n\r';
		document.formalta.consiste.style.borderColor='#ff0000';
	}
	
	if (document.formalta.mejora.value=="")
	{
		err+='Debes de introducir el texto de tu iniciativa\n\r';
		document.formalta.mejora.style.borderColor='#ff0000';
	}
	
		if (document.formalta.mejora.value.length>400)
	{
		err+='El texto de tu iniciativa no puede superar los 400 caracteres\n\r';
		document.formalta.mejora.style.borderColor='#ff0000';
	}
	
	if (document.formalta.img1.value=="" || checkear_extension(document.formalta.img1.value)) 
	{
		err+='Debes de introducir la primera Imagen valida (.jpg.gif.png)\n\r';
		document.formalta.img1.style.borderColor='#ff0000';
	}
	
	if (document.formalta.img2.value!="") 
	{
		if (checkear_extension(document.formalta.img2.value)) 
		{
			err+='Formato no valido en  la segunda Imagen (.jpg.gif.png)\n\r';
			document.formalta.img2.style.borderColor='#ff0000';
		}
	}
	
	
	
	if (document.formalta.img3.value!="") 
	{
		if (checkear_extension(document.formalta.img3.value)) 
		{
			err+='Formato no valido en la tercera Imagen (.jpg.gif.png)\n\r';
			document.formalta.img3.style.borderColor='#ff0000';
		}
	}
	
	if (document.formalta.video.value!="") 
	{
		if (checkear_extensionVideo(document.formalta.video.value)) 
		{
			err+='Formato de video no valido(.flv.mp4.avi)\n\r';
			document.formalta.video.style.borderColor='#ff0000';
		}
	}

	
	if (document.formalta.web.value=="") 
	{
		err+='Debes de introducir la web de referencia\n\r';
		document.formalta.web.style.borderColor='#ff0000';
	}
	
	if (!document.formalta.legal.checked) //email //////////////////////////////
	{
		err+='Debes de Aceptar las bases legales\n\r';
		document.formalta.legal.style.borderColor='#ff0000';
	}
	
	if (!document.formalta.condiciones.checked) //email //////////////////////////////
	{
		err+='Debes de Aceptar las condiciones legales\n\r';
		document.formalta.condiciones.style.borderColor='#ff0000';
	}
	
	if (err!=''){
		alert(err)
		return false
	}
	else{
		return true
	}
	
}

function quitaTx(obj,txt){
	if(obj.value==txt){
	obj.value='';
	}
	
	
	
}
function checkear_extension(dato)	{
	// definimos antes los métodos prever() y limpiar()
	if (/.(gif|jpg|png)$/i.test(dato)){
		return false;
	}else{
		return true;
	}
	
}

function checkear_extensionVideo(dato)	{
	// definimos antes los métodos prever() y limpiar()
	if (/.(flv|mp4|avi)$/i.test(dato)){
		return false;
	}else{
		return true;
	}
	
}

function limita(elemento,maximoCaracteres) {
  if(elemento.value.length >= maximoCaracteres ) {
    return false;
  }
  else {
    return true;
  }
}
