function validarForm(form, lang){
	if(isNaN(form.publicacion.length)){
		if(form.publicacion.value.length > 0){
			if(form.publicacion.checked == false){
				translate(lang, "No puede enviar una solicitud sin publicaciones","No pot enviar una sol·licitut sense publicacions","You can't send a form without publications");
				return false;
			}
		}
	}else{
		if ((typeof form.publicacion == 'undefined') || (form.publicacion.length < 0)){
			translate(lang, "No puede enviar una solicitud sin publicaciones","No pot enviar una sol·licitut sense publicacions","You can't send a form without publications");
			return false;
		}else{
			checkeds = 0
			for(i=0;i < form.publicacion.length;i++){
				if(form.publicacion[i].checked == true){
					checkeds = checkeds + 1
				}
			}
			if(checkeds <= 0){
				translate(lang, "No puede enviar una solicitud sin publicaciones","No pot enviar una sol·licitut sense publicacions","You can't send a form without publications");
				return false;
			}
		}
	}
	if(form.nombre.value == ""){
		translate(lang,"Debe introducir su nombre","Ha d'introduir el seu nom","You must insert your name");
		form.nombre.focus;
		return false;
	}
	if(form.direccion.value == ""){
		translate(lang,"Debe introducir su dirección","Ha d'introduir la direcció","You must insert your address");
		form.direccion.focus;
		return false;
	}
	if(form.cpostal.value == ""){
		translate(lang,"Debe introducir un código postal","Ha d'introduir un codi postal","You must insert a ZIP Code");
		form.cpostal.focus;
		return false;
	}else if(validarCP(form.cpostal.value)==false){
		translate(lang,"El codigo postal no es valido","El codi postal no es valid","The ZIP Code isn't valid");
		form.mail.focus;
		return false;
	}
	if(form.ciudad.value == ""){
		translate(lang,"Debe introducir una ciudad","Ha d'introduir una ciutat","You must insert a city");
		form.ciudad.focus;
		return false;
	}
	if(form.pais.value == ""){
		translate(lang,"Debe introducir un pais","Ha d'introduir un pais","You must insert a country");
		form.pais.focus;
		return false;
	}
	if(form.mail.value == ""){
		translate(lang,"Debe introducir una direccion de correo","Ha d'introduir una direcció de correu","Ypu must insert an e-mail adress");
		form.mail.focus;
		return false;
	}else if(validarMail(form.mail.value)==false){
		translate(lang,"El e-mail no es valido","L'E-mail no es valid","The E-mail address isn't valid");
		form.mail.focus;
		return false;
	}
	if(form.aceptar.checked == false){
		translate(lang,"Debe aceptar los terminos de uso","Ha d'acceptar els termes d'us","You must accept the Terms of use");
		return false;
	}
	if(form.text.value == ""){
		translate(lang,"Debe introducir un motivo","Ha d'introduir un motiu","You must insert a motive");
		form.text.focus;
		return false;
	}
	form.submit();
}

function validarMail(mail){
	reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	return reg.test(mail);
}

function validarCP(cpostal){
	reg = /^[0-9]{5}$/
	return reg.test(cpostal);
}

function translate(idioma, es_txt, cat_txt, en_txt){
	switch(idioma){
		case "es":
			text_final = es_txt;
		break;
		case "cat":
			text_final = cat_txt;
		break;
		case "en":
			text_final = en_txt;
		break;
	}
	
	alert("Error: "+text_final);
	return false;
}

function swapBackgroundMenu(elem){
	elem.className = "upper_menuopt_over";
}

function swapBackgroundMenu_2(elem){
	elem.className = "upper_menuopt";
}

function swapColorLeft(elem, aid){
	elem.className = "optionMenuLeft_over";
	document.getElementById(aid).className = "submenulink_over";
}

function swapColorLeft_2(elem, aid){
	elem.className = "optionMenuLeft";
	document.getElementById(aid).className = "submenulink";
}
function swapColorLeft2(elem, aid){
	elem.className = "optionMenuLeft2_over";
	document.getElementById(aid).className = "submenulink_over";
}

function swapColorLeft2_2(elem, aid){
	elem.className = "optionMenuLeft2";
	document.getElementById(aid).className = "submenulink";
}

function changeClass(id,td){
	elem = document.getElementById(id);
	td.style.cursor = 'pointer';
	elem.style.color = '#FFFFFF';
	elem.style.backgroundColor = '#552413';
}

function changeClass_2(id){
	elem = document.getElementById(id);
	elem.style.color = '#333333';
	elem.style.backgroundColor = '#D9D9D9';
}

function goTo(url_id){
	window.location.href = url_id;
}

function overPointer(elem){
	elem.style.cursor = 'pointer';
}

function goGestor(destiny){
	window.location.href = destiny;
}
function downGestor(destiny){
	window.location.href = destiny+"&download=1";
}

function valSubscripcion(form){
	if(isNaN(form.chk_actividad.length)){
		if(form.chk_actividad.value.length > 0){
			if(form.chk_actividad.checked == false){
				alert("No puede enviar una inscripción sin actividades");
				return false;
			}
		}
	}else{
		if ((typeof form.chk_actividad == 'undefined') || (form.chk_actividad.length < 0)){
			alert("No puede enviar una inscripción sin actividades");
			return false;
		}else{
			checkeds = 0
			for(i=0;i < form.chk_actividad.length;i++){
				if(form.chk_actividad[i].checked == true){
					checkeds = checkeds + 1
				}
			}
			if(checkeds <= 0){
				alert("No puede enviar una inscripción sin actividades");
				return false;
			}
		}
	}
	for(i=0;i<=form.length;i++){
		type = form[i].type;
		switch(type){
			case "text":
				if(form[i].value.length <= 0){
					alert("Rellene el campo " + form[i].name + " por favor");
					form[i].focus();
					return false;
				}
			break;
		}
	}
	
	email = document.getElementById("email");
	email_p = document.getElementById("email_p");
	cpostal = document.getElementById("cpostal");
	cpostal_p = document.getElementById("cpostal_p");
	telf = document.getElementById("telefono");
	telf_p = document.getElementById("telefono_p");
	
	if(validarMail(email.value)==false){
		alert("La dirección de correo electrónico no es válida");
		email.focus();
		return false;
	}
	if(validarMail(email_p.value)==false){
		alert("La dirección de correo electrónico no es válida");
		email_p.focus();
		return false;
	}
	if(validarCP(cpostal.value)==false){
		alert("El código postal no es válida");
		cpostal.focus();
		return false;
	}
	if(validarCP(cpostal_p.value)==false){
		alert("El código postal no es válida");
		cpostal_p.focus();
		return false;
	}
	
	return true;
}

function validateActivities(form){
	for(i=0;i<form.length;i++){
		if(form[i].type == "text"){
			if(form[i].value.length <= 0){
				alert("Debe rellenar el campo "+form[i].name);
				form[i].focus();
				return false;
			}else if(form[i].name == "mail"){
				if(validarMail(form[i].value)==false){
					alert("El Mail debe ser valido");
					form[i].focus();
					return false
				}
			}
		}else if(form[i].type == "file"){
			if(form[i].value.length <= 0){
				alert("Debe añadir el documento especificado");
				return false;
			}else{
				ext = form[i].value.length -3;
				max = form[i].value.length;
				extension = form[i].value.substr(ext, max);
				fichero = form[i].value.substr(form[i].value.length-15, max);
				if(extension != "doc"){
					alert("Asegurese que el fichero es el correcto");
					return false;
				}else if(fichero != "inscripcion.doc"){
					alert("Asegurese que el fichero es el correcto");
					return false;
				}
			}
		}else if(form[i].type == "checkbox"){
			if(form[i].checked == false){
				alert("Debe aceptar las condiciones de uso")
				return false;
			}
		}
	}
	form.submit();
}


function submitPaginate(index, form){
	page = document.getElementById("index");
	page.value = index;
	
	form.submit();
}

function toggle(id){
	elem = document.getElementById(id);
	if(elem.style.display == "none"){
		elem.style.display = "block";
	}else{
		elem.style.display = "none";
	}
}

function setNotice(permision, dlink){
	var notice = '';
	switch(permision){
		case "compartido":
			notice = 'La asociación o editorial detenta el copyright de este artículo.\n';
			notice+= 'Se ha reproducido en versión impresa y electrónica con su correspondiente autorización.\n';
			notice+= '-------------------------\n';
			notice+= 'The association or publisher holds the copyright of this article.\n';
			notice+= 'The electronic and printed reproduction is authorized.';
			alert(notice);
			window.location.href=dlink;
		break;
		case "nopermitido":
			notice = 'Copyright detentado por las correspondientes asociaciones o editoriales.\n';
			notice+= 'Reproducción electrónica no autorizada.\n';
			notice+= '-------------------------\n';
			notice+= 'Copyright hold by its corresponding associations or publishers.\n';
			notice+= 'Electronic reproduction is not authorized.';
			alert(notice);
		break;

	}
}
