
//Inician funciones de scroll text
function regenerate(){
	window.location.reload()
}

function regenerate2(){
	if (document.layers){
		setTimeout("window.onresize=regenerate",450)
		intializemarquee()
	}
}

function intializemarquee(){
	document.cmarquee01.document.cmarquee02.document.write('<nobr>'+marqueecontents+'</nobr>')
	document.cmarquee01.document.cmarquee02.document.close()
	thelength=document.cmarquee01.document.cmarquee02.document.width
	scrollit()
}

function scrollit(){
	if (document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){
		document.cmarquee01.document.cmarquee02.left-=speed
		setTimeout("scrollit()",100)
	}
	else{
		document.cmarquee01.document.cmarquee02.left=marqueewidth
		scrollit()
	}
}
//Terminan funciones de scroll text

//Inician funciones de HTTPREQUEST
function http_request() {
    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
}
//Terminan funciones de HTTPREQUEST

function VerLogin()
{
	_target=document.getElementById('login') //id resultado
   _target.style.display = '';
	return
}


//Validador para la forma del registro
function valida_registro(){
	var why = "";
	why += checkName(document.fregistro.nombre.value);
	why += checkApp(document.fregistro.app.value);
	why += checkCorreo(document.fregistro.correo.value,document.fregistro.ccorreo.value);
	why += checkUsername(document.fregistro.usuario.value);
   why += checkPassword(document.fregistro.password.value,document.fregistro.usuario.value);
   why += checkConfirmacion(document.fregistro.confirmacion.value,document.fregistro.password.value);
   why += checkPregSec(document.fregistro.pregsec.value);
   why += checkRespSec(document.fregistro.respsec.value);
   why += checkFNac(document.fregistro.dia.value,document.fregistro.mes.value,document.fregistro.anio.value);
   why += checkPais(document.fregistro.paisres.value);
   why += checkTermino(document.fregistro.contrato.checked);
   why += checkacercademi(document.fregistro.acercademi.value);
   if (why != "") {
   	alert(why);
   }
   else
   	document.fregistro.submit();
}

function checkacercademi (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere escribir algo acerca de ti.\n";
	}

    return error;
}

function checkName (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere completar el nombre.\n";
	}

    return error;
}

function checkApp (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere completar el Apellido paterno.\n";
	}

    return error;
}

function checkCorreo (strng, strng2) {
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= "/[\(\)\<\>\,\;\:\\\/\"\[\]]/";
	if (!(emailFilter.test(strng))) {
   	error = "Se requiere un correo valido.\n";
	}
	else if (strng.match(illegalChars)) {
   	error = "El correo contiene caracteres invalidos.\n";
   }
   else if(strng != strng2) {
		error = "Se debe confirmar el correo electronico. \n";
   }

    return error;
}

function checkUsername (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere un nombre de usuario.\n";
	}
	else
 		if ((strng.length < 4) || (strng.length > 20)) {
    		error = "El Usuario debe tener una longitud entre 4 y 20 caracteres.\n";
		}
 	var illegalChars = /\W/;
  	// Permitir solo letras, numeros y guion bajo
   if (illegalChars.test(strng)) {
       error = "El Usuario contiene caracteres invalidos.\n";
    }
    return error;
}

function checkPassword (strng, strng2) {
	var error = "";
	var illegalChars = /[\W_]/; // Permitir solo letras y numeros

	if (strng == "") {
   	error = "Es necesario que asignes un Password.\n";
 	}
 	else if (strng==strng2) {
   	error = "El Password no puede ser igual al nombre de Usuario.\n";
   }
	else if ((strng.length < 6) || (strng.length > 15)) {
   	error = "El Password debe tener una longitud entre 6 y 15 caracteres.\n";
   }
   else if (illegalChars.test(strng)) {
   	error = "El Password solo puede contener letras y numeros.\n";
   }

 /*  if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/))&& (strng.search(/(0-9)+/)))) {
		error = "El Password debe contener al menos un letra en mayusculas, una letra en minusculas y un numero.\n";
  	}*/
  	return error;
}


function checkConfirmacion(strng,strng2){
	var error = "";

	if (strng == "") {
   	error = "Debes de confirmar el Password.\n";
 	}
	if (strng != strng2) {
   	error = "Debes de confirmar correctamente el Password.\n";
 	}

 	return error;
}

function checkPregSec(strng){
	var error = "";

	if (strng == "") {
   	error = "Debes asignar una Pregunta secreta.\n";
 	}
 	else if(strng.lenght < 6){
		error = "Por seguridad tu Pregunta secreta debe ser mayor a 6 caracteres";
 	}

 	return error;
}

function checkRespSec(strng){
	var error = "";

	if (strng == "") {
   	error = "Debes asignar una Respuesta secreta.\n";
 	}
 	else if(strng.lenght < 4){
		error = "Por seguridad tu Respuesta secreta debe ser mayor a 4 caracteres";
 	}

 	return error;
}

function checkFNac(strng,strng2,strng3){
	var error = "";

	if ((strng == 0) || (strng2 == 0) || (strng3 == 0)) {
   	error = "Debes completar tu Fecha de nacimiento.\n";
 	}

 	return error;
}

function checkPais(strng){
	var error = "";

	if (strng == "0") {
   	error = "Debes seleccionar el Pais en donde resides.\n";
 	}
 	return error;
}

function checkTermino(strng){
	var error = "";

	if (strng == false) {
   	error = "Debes leer y aceptar los terminos de uso y legales.\n";
 	}
 	return error;
}


function valida_login(Nforma){
	var error = "";

	if(Nforma.usuario.value=="")
		error += "Favor de escribir el Nombre de usuario.\n";
	if (Nforma.contrasena.value=="")
		error += "Favor de escribir la Contrasena.\n";

	if (error != "")
   	alert(error);
   else
		window.open('valida.php?login=Login&usuario='+Nforma.usuario.value+'&contrasena='+Nforma.contrasena.value+'','valida','width=260,height=10,menubar=no,resizable=no,scrollbars=no,toolbar=no,screenX=0px,screenY=0px,left=0px,top=0px');

}

function CheckFieldLength(fn,wn,rn,mc) {
  var len = fn.value.length;
  if (len > mc) {
    fn.value = fn.value.substring(0,mc);
    len = mc;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}

//Valida el editor de noticias
function valida_editorNyP(){
	var why = "";
	why += checkTitulo(document.formEd.TituloN.value);
	why += checkNoticia(document.formEd.Noticia.value);
	why += checkReferencia(document.formEd.ReferenciaN.value);
	why += checktags(document.formEd.tags.value);
   if (why != "") {
   	alert(why);
   }
   else
  	document.formEd.submit();
}

function vistaprevia_editorNyP(){
	var why = "";
	why += checkTitulo(document.formEd.TituloN.value);
	why += checkNoticia(document.formEd.Noticia.value);
	why += checkReferencia(document.formEd.ReferenciaN.value);
	why += checktags(document.formEd.tags.value);
   if (why != "") {
   	alert(why);
   }
   else
   {
	parametros='Titulo='+document.formEd.TituloN.value+'&Noticia='+document.formEd.Noticia.value+'&Referencia='+document.formEd.ReferenciaN.value+'&Rubro='+document.formEd.RubroN.value+'&idMiembro='+document.formEd.idMiembro.value;
  	window.open('index.php?PAGE=vp&'+parametros+'','vistaprevia','width=800,height=600,scrollbars');
	}
}

function checkTitulo (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere un Titulo.\n";
	}

    return error;
}

function checkNoticia (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere redactar la noticia.\n";
	}
	else if(strng.length < 450){
		error = "La noticia debe contener al menos 450 caracteres";
	}

    return error;
}

function checkReferencia (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere una referencia de la noticia.\n";
	}
	else {
		var urlFilter=/^[A-Za-z]+:\/\/[A-Za-z0-9-_]+\..[A-Za-z0-9-_%&\?\/.=]+/;
		if (!(urlFilter.test(strng))) {
   			error = "Se requiere un URL valido. (Ejem. http://www.noticiasypunto.com/index.php?PAGE=ay)\n";
		}
	}

    return error;
}

function checktags (strng) {
	var error = "";
	if (strng == "") {
		error = "Se requiere de al menos una palabra clave.\n";
	}
    return error;
}

//Termina valida el editor de noticias


//Inicia valida comentarios

function valida_comentario(){
   if (document.FormaC.ComentarioC.value == "") {
   	alert("El comentario no puede estar vacio.");
   }
   else
  	document.FormaC.submit();
}

//Termina valida comentarios

//Valida la actualizacion del perfil

function valida_actualiza_perfil(){
	var why = "";
	why += checkName(document.factualizaperfil.nombre.value);
	why += checkApp(document.factualizaperfil.app.value);
	why += checkCorreo(document.factualizaperfil.correo.value,document.factualizaperfil.ccorreo.value);
   why += checkPregSec(document.factualizaperfil.pregsec.value);
   why += checkRespSec(document.factualizaperfil.respsec.value);
   why += checkFNac(document.factualizaperfil.dia.value,document.factualizaperfil.mes.value,document.factualizaperfil.anio.value);
   why += checkPais(document.factualizaperfil.paisres.value);
  // why += checkAP(document.factualizaperfil.actualiza_contra.checked,document.factualizaperfil.password.value,document.factualizaperfil.confirmacion.value,document.factualizaperfil.usuario.value);
   if (why != "") {
   	alert(why);
   }
   else
   	document.factualizaperfil.submit();
}

function valida_actualiza_contra() {
	var strng2 = document.factualizacontra.password.value;
	var strng3 = document.factualizacontra.confirmacion.value;
	var strng4 = document.factualizacontra.usuario.value;
	var error = "";
	var illegalChars = /[\W_]/; // Permitir solo letras y numeros
		if (strng2 == "") {
   			error = "Es necesario que asignes un Password.\n";
 		}
 		else if (strng2==strng4) {
		   	error = "El Password no puede ser igual al nombre de Usuario.\n";
		}
		else if ((strng2.length < 6) || (strng2.length > 15)) {
   			error = "El Password debe tener una longitud entre 6 y 15 caracteres.\n";
   		}
   		else if (illegalChars.test(strng2)) {
   			error = "El Password solo puede contener letras y numeros.\n";
		}
		else if(strng2 != strng3)
			error = "Debes de confirmar correctamente el Password.\n";	
			
		error += checkPregSec(document.factualizacontra.pregsec.value);
   		error += checkRespSec(document.factualizacontra.respsec.value);

  	if (error != "") {
   		alert(error);
   	}
   	else
   		document.factualizacontra.submit();
}

//Termina validacion de la actualizacion del perfil

//Inicia parte de ayuda

function reglas(target){
	if(document.getElementById(target).style.display=='')
		document.getElementById(target).style.display  = 'block';
	else if(document.getElementById(target).style.display=='block')
		document.getElementById(target).style.display  = '';
}

//Termina parte de ayuda

function cambia_fondo_noticia(target,estilo,target2){
	if(estilo=="ResumenNoticiaAzul")
		document.getElementById(target).className  = 'ResumenNoticiaAzulA';
	else
		document.getElementById(target).className  = 'ResumenNoticiaAzulB';
		
		document.getElementById(target2).className  = 'EstiloLiga_Blanca';
}

function cambia_fondo_noticia_orig(target,estilo,target2){
	document.getElementById(target).className  = estilo;
	document.getElementById(target2).className  = 'EstiloLiga';
}

function cambia_LigaRubro(target){
	document.getElementById(target).className  = 'LigasRubro2';
}

function regresa_LigaRubro(target){
	document.getElementById(target).className  = 'LigasRubro';
}









