function muestraDiv(id){
	obj = document.getElementById(id);
	obj.style.display = (obj.style.display=='none') ? 'block' : 'none';
}

function validateForm(frmNewusr)
{
	if (frmNewusr.txtNombre.value == "" || frmNewusr.txtApellidos.value == "" || frmNewusr.mnuDia.selectedIndex == 0 ||frmNewusr.mnuMes.selectedIndex == 0 ||frmNewusr.mnuYear.selectedIndex == 0 || frmNewusr.mnuGen.selectedIndex == 0 || frmNewusr.txtUser.value == "" || frmNewusr.pass1.value == "" || frmNewusr.pass2.value == "" || frmNewusr.mnuPais.selectedIndex == 0 || frmNewusr.txtCorreo.value == "" || frmNewusr.txtSeg.value == "")
	{
		alert(jsMsj['fillAll']);
		return;
	}

	user=document.frmNewusr.txtUser.value;
	formatUser= /\w/; 					//solo numero y letras
	if(!formatUser.test(user) || tieneEspacios(user))
	{
		alert(jsMsj['invalUsr']);
		return;
	}
	
	pass1=document.frmNewusr.pass1.value;
	pass2=document.frmNewusr.pass2.value;
	if(pass1.length<6 || tieneEspacios(pass1))	
	{	
		alert(jsMsj['invalPasslen']);
		return;	
	}
	
	mail = document.frmNewusr.txtCorreo.value;
    formatMail = /^([\w-\.])+@([\w-]+\.)+([a-z]){2,4}$/;
    if(!formatMail.test(mail))
	{
		alert(jsMsj['invalCorreo']);
		return;
    }

	if (pass1 != pass2 || tieneEspacios(pass1) || tieneEspacios(pass2))
	{
		alert(jsMsj['invalPass']);
		return;
	}
		
	if(!frmNewusr.chbTerms.checked){
		alert(jsMsj['noCfrmTerms']);
		return;
	}
	document.frmNewusr.submit();
}

function tieneEspacios(cadena)
{
	n=1;
	while(n<=cadena.length)
	{
		if(cadena.charAt(n)==" ")
			return true;
		n++;
	}
}
function validarLogin(frmLogin)
{
	if(typeof(frmLogin.txtSeg) != "undefined"){ 
		if(frmLogin.txtSeg.value==""){
			alert(jsMsj['fillAll']);
			return;
		}		
	}

	if ( frmLogin.txtUser.value == "" || frmLogin.pass1.value == "")
	{
		alert(jsMsj['noLgn']);
		return;
	}
	else{
		document.frmLogin.submit();
	}
}

function pruebaAds(frmEditusr)
{
	var cad=frmEditusr.txaAds.value;

	var posPubi=cad.indexOf("google_ad_client")+20;
	var sub1=cad.substr(posPubi,cad.length);
	var posPubf=sub1.indexOf(";")-1;
	var pub=cad.substr(posPubi,posPubf);

	var posSloti=cad.indexOf("google_ad_slot")+18;
	var sub=cad.substr(posSloti,cad.length);
	var posSlotf=sub.indexOf(";")-1;
	var slot=cad.substr(posSloti,posSlotf);
	var dir="includes/pruebaAds.php?pub=" + pub + "&slot=" + slot; 

	if(frmEditusr.txaAds.value !="")
	{
		window.open(dir,"Titulo" ,"directories=no, location=no, menubar=no, scrollbars=yes, statusbar=no, tittlebar=no, width=500, height=400");
	}
}

function validCorreo(frmCorreo){
	if(frmCorreo.txtCorreo.value=="" || frmCorreo.txtSeg.value=="")
	{
		alert(jsMsj['fillAll']);
		return;
	}
	mail = frmCorreo.txtCorreo.value;
    formatMail = /^([\w-\.])+@([\w-]+\.)+([a-z]){2,4}$/;
    if(!formatMail.test(mail))
	{
		alert(jsMsj['invalCorreo']);
		return;
    }
	else
		document.frmCorreo.submit();
}

function validPasslost(frmPasslost)
{
	if(frmPasslost.txtCorreo.value=="" || frmPasslost.txtCodigo.value=="" || frmPasslost.passNew1.value=="" || frmPasslost.passNew2.value=="")
	{
		alert(jsMsj['fillAll']);
		return;
	}

	pass1=frmPasslost.passNew1.value;
	if(pass1.length<6 || tieneEspacios(pass1))	
	{	
		alert(jsMsj['invalPasslen']);
		return;	
	}

	if(frmPasslost.passNew1.value == frmPasslost.passNew2.value)
		document.frmPasslost.submit();
	else
	{
		alert(jsMsj['invalPass']);
		return;
	}

}

function validPost(frmNewpost)
{
	syncTextarea();
	if(frmNewpost.txtTitulo.value=="" || frmNewpost.txtEtiqs.value=="" || frmNewpost.txaPost.value=="" || frmNewpost.mnuCat.value=="" || frmNewpost.mnuCat.selectedIndex==0)
	{
		alert(jsMsj['fillAll']);
		return;		
	}
	else
		document.frmNewpost.submit();	
}

function validComent(coment){
	if(coment.txaComen.value==""){
		alert(jsMsj['noComent']);
		return;
	}
		
	else
		document.coment.submit();
}

function validMotor(frmBuscar){
	var str=frmBuscar.q.value;
	str=str.replace(/\s/gi, "+"); 
	if(frmBuscar.rdoDonde[1].checked)
	{
		var action='http://'+document.domain+'/modulos.php?m=sitio&f=busqueda&opc=buscar&cx=partner-pub-6664861454620052:m616guyu60b&cof=FORID%3A11&ie=ISO-8859-1&q='+str+'&rdoDonde='+frmBuscar.rdoDonde[1].value;
	}
	if(frmBuscar.rdoDonde[0].checked){
		var action='modulos.php?m=sitio&f=busqueda&opc=buscar&q='+str+'&rdoDonde='+frmBuscar.rdoDonde[0].value;
	}
	//alert(str+' '+action);
	document.frmBuscar.action=action;
	document.frmBuscar.submit();
}

function validContacto(frmContacto,idUsr){
	if(frmContacto.txtAsunto.value=="" || frmContacto.txaContacto.value=="" || frmContacto.txtSeg.value=="")
	{
		alert(jsMsj['fillAll']);
		return;
	}
	if(idUsr=="" && frmContacto.txtCorreo.value=="")
	{
		alert(jsMsj['noCorreo']);
		return;
	}

	formatMail = /^([\w-\.])+@([\w-]+\.)+([a-z]){2,4}$/;
    if(!formatMail.test(frmContacto.txtCorreo.value))
	{
		alert(jsMsj['invalCorreo']);
		return;
    }

	document.frmContacto.submit();
}

function cfrmElmp(idpost){
	var confirmar=confirm(jsMsj['elmPost']);
	var dir="modulos.php?m=cuenta&f=mispost&opc=elmpost&idpost="+idpost;	
	
	if(confirmar)
		{
			window.location=dir;
		}
	else
		return;		
}

function inclAdults(frm,donde,order){
	var dir="";
	switch(donde) {
		case 'all':
			dir="modulos.php?m=post&f=all&";
		break;
	}
	
	if(order!='')
		dir+='&short='+order;

	if(frm.mnuCat.value==22)
		dir+='&inad=s';

	var cfrmEdad=confirm(jsMsj['+18']);
	if(cfrmEdad)
		window.location=dir;
	else
		return;	
}

function validKey(evento,frm){
	tecla=(document.all) ? evento.keyCode : evento.which;
	if(tecla == 13){
		switch(frm){
			case'login':
				validarLogin(document.frmLogin);
			break;
			case'busqueda':
				validMotor(document.frmBuscar);
			break;
		}
	}		
}

