function validaEmail(valor) {

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))

	{

		return true;

	} else {

		return false;

	}

}



function olvido()

{

		if(document.getElementById('olvido').style.display == 'none')

			{

					document.getElementById('olvido').style.display = 'block';

			}else{

					document.getElementById('olvido').style.display = 'none';

			}

}



function validarEXP (expresion, valor)

{

  var expreg = new RegExp (expresion);

  var cadena=valor;

 

  if (expreg.test(cadena)) {

    	return true;



  }

  else

  {

  	return false;

  }

}



function agregarFav()

{

	var url="http://www.messengercool.com";

	var titulo="Messengercool.com - Avatares, emoticonos, meegos";



	if (document.all) window.external.AddFavorite(url,titulo);



	if(navigator.appName == "Netscape") alert ("Presione Crtl+D para agregar este sitio en sus Favoritos");

		

}





function compUser(idForm)

{

	var divs = document.getElementsByTagName('input');

	var selects = document.getElementsByTagName('select');

	var strClass = "req";

	var ClassEmail = "email";

	var ClassPWD = "passw";

	var ClassURL = "url";
	
	var ClassFIL = "file";

	var alerta = "";



        for (ti=0;ti<divs.length;ti++)

            {

               thisDiv = divs[ti];



               if ((' '+thisDiv.className+' ').indexOf(strClass) != -1)

               {

				var valor = document.getElementById(thisDiv.id).value;



				if(valor == "" || valor == "undefined")

				{

					alerta+=" El campo "+thisDiv.id+" es obligatorio\n";

					document.getElementById(thisDiv.id).style.borderColor = "#FF0000";

				}else{ document.getElementById(thisDiv.id).style.borderColor = ""; }



               }


				if ((' '+thisDiv.className+' ').indexOf(ClassURL) != -1 && document.getElementById(thisDiv.id).disabled == false){
					var valor = document.getElementById(thisDiv.id).value;
					if(valor == "http://" || valor == "undefined" || valor == ""){
						alerta+=" Introduce una URL\n";
						document.getElementById(thisDiv.id).style.borderColor = "#FF0000";
					}else{ 
						document.getElementById(thisDiv.id).style.borderColor = ""; 
					}
               }

               if ((' '+thisDiv.className+' ').indexOf(ClassFIL) != -1  && document.getElementById(thisDiv.id).disabled == false){
					var valor = document.getElementById(thisDiv.id).value;
					if(valor == "undefined" || valor == ""){
						alerta+=" Seleccione un archivo a Subir\n";
						document.getElementById(thisDiv.id).style.borderColor = "#FF0000";
					}else{ 
						document.getElementById(thisDiv.id).style.borderColor = ""; 
					}
               }

		

		 if ((' '+thisDiv.className+' ').indexOf(ClassEmail) != -1)

               {

				var valor = document.getElementById(thisDiv.id).value;

				if(!validaEmail(valor))

				{

					alerta+=" El email es incorrecto\n";

					document.getElementById(thisDiv.id).style.borderColor = "#FF0000";

				}else{ document.getElementById(thisDiv.id).style.borderColor = ""; }



               }

		

		if ((' '+thisDiv.className+' ').indexOf(ClassPWD) != -1)

               {

				var valor = document.getElementById(thisDiv.id).value;

				var valor2 = document.getElementById(thisDiv.id+"2").value;

				if(valor != valor2 && valor != "")

				{

					alerta+=" Las contrase\u00f1as no coinciden\n";

					document.getElementById(thisDiv.id).style.borderColor = "#FF0000";

					document.getElementById(thisDiv.id+"2").style.borderColor = "#FF0000";

				}else if(!validarEXP("([a-zA-Z0-9]{4,10})$", document.getElementById(thisDiv.id).value))

				{

					alerta+=" La contrase\u00f1a tiene que tener entre 4 y 10 caracteres alfanumericos\n";

					document.getElementById(thisDiv.id).style.borderColor = "#FF0000";

				}else{ document.getElementById(thisDiv.id).style.borderColor = ""; document.getElementById(thisDiv.id+"2").style.borderColor = ""; }



               }

            }



		if(idForm == "contenido")

		{



			if(document.getElementById('urlC').value == "http://" && document.getElementById('urlC').disabled == false)

			{

				alerta+=" Escribe una URL\n";

				document.getElementById("urlC").style.borderColor = "#FF0000";



			}else if(document.getElementById('fileC').value.length == 0 && document.getElementById('fileC').disabled == false)

			{

				document.getElementById("fileC").style.borderColor = "#FF0000";

				alerta+=" Sube un archivo\n";

			}else{

				

				if(!comprueba_extension(document.getElementById('fileC').value) && document.getElementById('fileC').disabled == false)

				{

					alerta+="Comprueba la extension del archivo";

				}else if(!comprueba_extension(document.getElementById('urlC').value) && document.getElementById('urlC').disabled == false)

				{

					alerta+="Comprueba la extension del archivo";

				}



			}



		}



	if(alerta != "")

	{

		alert(alerta); 

	}else{ 

		document.getElementById(idForm).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 recuperaPWD(email)

{

	recibeid('ajax/procesoSearch.php','','email='+email,'olvidoDIV','Un momento por favor...');

}





function recibeid(_pagina,valorget,valorpost,capa,carga){ 

    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 = carga;

        }

        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);

    }

} 





function cambiaTipo(seccion,selected)

{



	recibeid('ajax/procesoSearch.php','clase=selecte&nameSelect=categoria&selected='+selected+'&seccion='+seccion,'','capaCategoria','<select class="selecte"><option>Cargando...</option></select>');



}



function addClick(idAfi)

{



	recibeid('ajax/procesoSearch.php','contaAfi='+idAfi,'','afil','');



}



function compruebaLogin(form)

{



	formulario = document.getElementById(form);



	var alerta="";



	if(formulario.emailL.value.length == 0 || !validaEmail(formulario.emailL.value))

	{

		alerta+="Introduce un email valido\n";

		document.login.emailL.focus();



	}

	if(formulario.pwdL.value.length == 0 || !validarEXP("([a-zA-Z0-9]{4,10})$", formulario.pwdL.value))

	{

		alerta+="Introduce una contrase\u00f1a valida\n";

		formulario.pwdL.focus();

	}



	if(alerta == "") formulario.submit(); else alert(alerta);



}
