function encuesta(c,r){
	var xpos=(screen.width - 500)/2;
	var ypos=(screen.height -400)/3;
	pagina='encuesta.php?id='+c+'&voto='+r
	window.open(pagina,'Encuesta','width=500,height=400,top='+ypos+',left='+xpos+',scrollbars=yes,resizable=yes')
}
function registrar(c){
	if(document.forms.frmLogin.username.value=="" || document.forms.frmLogin.password.value==""){
		alert("Debes introducir tu usuario y password")
	}
	else{
		document.forms.frmLogin.action="galeria/login.php?referer="+c+""
		document.forms.frmLogin.submit()
	}
}

var nav4 = window.Event ? true : false;
function acceptNum(evt){
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57));
}

function enviaramigo(){
	var xpos=(screen.width - 300)/2;
	var ypos=(screen.height -340)/3;
	pagina="/enviar_amigo.php"
	window.open(pagina,'Enviar','width=300,height=290,top='+ypos+',left='+xpos+',scrollbars=no,resizable=no')
}

function imprimir(c){
	var xpos=(screen.width - 650)/2;
	var ypos=(screen.height -500)/3;
	pagina="/"+c;
	window.open(pagina,'Imprimir','width=650,height=500,top='+ypos+',left='+xpos+',scrollbars=yes,resizable=yes')
}

function rectificar(c){
	var xpos=(screen.width - 300)/2;
	var ypos=(screen.height - 290)/3;
	pagina="/rectificar.php?id="+c+"";
	window.open(pagina,'Rectificar','width=300,height=290,top='+ypos+',left='+xpos+',scrollbars=no,resizable=no')
}

function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("La dirección de e-mail es incorrecta")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
    	alert("La dirección de e-mail es incorrecta.")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	alert("La dirección de e-mail es incorrecta")
				return false
			}
		}
	return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("La dirección de e-mail es incorrecta.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
		alert("la dirección de e-mail es incorrecta.")
		return false
	}
	if (len<2) {
   		var errStr="La dirección de e-mail es incorrecta"
		alert(errStr)
		return false
	}
return true;
}

function ira_provincia(){if (document.frm1.provincia.value!=0){location = document.frm1.provincia.options[document.frm1.provincia.selectedIndex].value}}
function ira_marca(){if (document.frm1.marca.value!=0){location = document.frm1.marca.options[document.frm1.marca.selectedIndex].value}}

function compruebaAnunciarse(){
	formu=document.forms.frmAnunciarse;
	if(formu.nombre.value=="" || formu.email.value==""){
		alert("Debes introducir el nombre y el email");
		return false;
	}else if(emailCheck(formu.email.value)==false){
		return false;
	}else{
		return true;
	}
}

function validarAnuncio(){
	formu=document.forms.frmAnuncio;
	if(formu.titulo.value==""){
		alert("Debes introducir el título del anuncio");
		formu.titulo.focus();
	}else if(formu.categoria.selectedIndex==0){
		alert("Debes escoger a que categoría pertenece el producto");
		formu.categoria.focus();
	}else if(formu.texto.value==""){
		alert("Debes introducir el texto descriptivo del anuncio");
		formu.texto.focus();
	}else if(formu.contacto.value==""){
		alert("Debes introducir una forma de contacto");
		formu.contacto.focus();
	}else{
		formu.action="anuncios_publicar.php?accion=nuevo";
		formu.submit();
	}
}

function validarNoticia(){
	formu=document.forms.frmAnuncio;
	if(formu.titulo.value==""){
		alert("Debes introducir el título de la noticia");
		formu.titulo.focus();
	}else if(formu.texto.value==""){
		alert("Debes introducir el texto descriptivo del anuncio");
		formu.texto.focus();
	}else{
		formu.action="noticias_enviar.php?accion=nuevo";
		formu.submit();
	}
}

function mostrarDiv(c){
	if(document.getElementById(""+c+"").style.diplay=="none"){
		document.getElementById(""+c+"").style.diplay="block";
	}else{
		document.getElementById(""+c+"").style.diplay="block";
	}
}

function search(){
	formu=document.forms.frmBuscador;
	if(formu.seccion[0].checked==true){
		location.href='/noticias.php?txt='+formu.buscar.value+'';
	}else if(formu.seccion[1].checked==true){
		location.href='/galeria/thumbnails.php?album=search&type=full&search='+formu.buscar.value+'';
	}else if(formu.seccion[2].checked==true){
		location.href='/foro/buscador.php?tipo=texto&txt='+formu.buscar.value+'';
	}
}