function MyTrim(camp) {
	var valor = camp;
	while (''+valor.charAt(0)==' ') valor=valor.substring(1,valor.length);
	while (''+valor.charAt(valor.length)==' ') valor=valor.substring(0,valor.length-1);
	return valor;
}

function validarNews(idioma) {
	var msgError='';
	var error=0;

	switch(idioma)
	{
		case "ca":
			error1 = "No has introduït el teu e-mail. \n\r";
			error2 = "El teu e-mail es incorrecte. \n\r";
			break;
		case "es":
			error1 = "No has introducido tu e-mail. \n\r";
			error2 = "Tu e-mail es incorrecto. \n\r";
			break;
		case "en":
			error1 = "No has introducido tu e-mail. \n\r";
			error2 = "Tu e-mail es incorrecto. \n\r";
			break;
		case "fr":
			error1 = "No has introducido tu e-mail. \n\r";
			error2 = "Tu e-mail es incorrecto. \n\r";
			break;
		case "ar":
			error1 = "No has introducido tu e-mail. \n\r";
			error2 = "Tu e-mail es incorrecto. \n\r";
			break;
	}
	
	if (MyTrim(document.getElementById('NewsletterTexto').value) == '') {
		msgError += error1;
		error = 1;
	}else{
		var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if (!filter.test(document.getElementById('NewsletterTexto').value)){
			msgError += error2;
			error = 1;
		}
	}
	if (error) alert(msgError);
	return error;
}

function finestra (URL){
window.open(URL,"ventana1","width=450, height=300, scrollbars=yes, menubar=no, location=no, resizable=no")
}

function buscadorFlash(idComarca) {
	document.getElementById("comarcas").value = idComarca;
	document.getElementById('frmBuscador').action = 'xarxa';
	document.getElementById('frmBuscador').submit();
}
function buscador(ruta,tipo,idioma) {
	var url_site = '';
	if(document.getElementById("comarcas").value != "_" && document.getElementById("municipios").value == "_" && document.getElementById("museos").value == "_") {
		tipo = 1;
		ruta = SERVER+'/xarxa';
	}
	if(document.getElementById("comarcas").value == "_" && document.getElementById("municipios").value != "_" && document.getElementById("museos").value == "_") {
		tipo = 2;
		ruta = SERVER+'/tipus';
	}
	if (tipo == 3) {
		if(document.getElementById('museos').value == "_") {
			ruta = SERVER+'/xarxa/'+document.getElementById("municipios").value;
		}
		else url_site = document.getElementById('museos').value;
	}
	document.getElementById('frmBuscador').action = ruta+url_site;
	
	var error1='';
	var error2='';
	
	switch(idioma)
	{
		case "ca":
			error1 = "No hi ha cap museu amb aquestes característiques.";
			error2 = "No has seleccionat cap camp";
			break;
		case "es":
			error1 = "No hay ningun museo con estas características.";
			error2 = "No has seleccionado ningun campo";
			break;
		case "en":
			error1 = "No hay ningun museo con estas características.";
			error2 = "Please, select a field";
			break;
		case "fr":
			error1 = "No hay ningun museo con estas características.";
			error2 = "No has seleccionado ningun campo";
			break;
		case "ar":
			error1 = "No hay ningun museo con estas características.";
			error2 = "No has seleccionado ningun campo";
			break;
	}
	
	// if(document.getElementById("comarcas").value != "_" && document.getElementById("municipios").value != "_" && document.getElementById("museos").value == "_") {
		// alert(error1);
	// } else {
		// if(document.getElementById("comarcas").value == "_" && document.getElementById("municipios").value == "_" && document.getElementById("museos").value == "_") {
			// alert(error2);
		// } else {
		document.getElementById('frmBuscador').submit();
		// }
	// }
}

function abrir(url,height,width) {
	var navegador = navigator.appName ;
	if (navegador == "Microsoft Internet Explorer")  height = height+46; width = width+1;
	window.open(url,'','scrollbars=1,resizable=0,top=100,left=100,width='+width+',height='+height) ;
}

// combo museu versio prototype sino es fot d'osties amb el jquery 
function comboMuseos(valor,ruta) {
	
	if (valor == 1 ) {
		new Ajax.Updater('museosListar', ruta+'ajaxs/ajax_museos/',{});
		$('museosListar').show();		
		$('museoDiv').show();
	} else {
		$('museosListar').hide();
		$('museosListar').descendants().each(Element.remove);
		$('museoDiv').hide();
	
	}
}

function comboMuseosCercador(ruta) {
	comarca = $('comarcas').value;
	tipo = $('municipios').value;
	if(comarca == '_') comarca = 0;
	if(tipo == '_') tipo = 0;
	new Ajax.Updater('museos', ruta+'ajaxs/ajax_cercador/'+comarca+'/'+tipo,{});
}

function verificar_mis_datos() {
	var password1 = document.getElementById('UserPassword1').value;
	var password2 = document.getElementById('UserPassword2').value;
	var msgError = '';
	var valor = true;
	
	if (password1 != password2) {
		 valor = false;
		 msgError +='Error password. \n\r';
	}
	
	if (MyTrim(document.getElementById('UserUsername').value) == '') {
		msgError += 'No has introducido un e-mail. \n\r';
		valor = false;
	}else{
		var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if (!filter.test(document.getElementById('UserUsername').value)){
			msgError += 'E-mail incorrecto. \n\r';
			valor = false;
		}
	}
	if (!valor) alert(msgError);
	return valor;	
}
function meneame(){
 window.open('http://meneame.net/submit.php?url='+document.location,'','');
}


function technorati(){
 window.open('http://www.technorati.com/search/'+document.location+'?sub=postcosm','','');
}


function delicious(){
 window.open('http://del.icio.us/post?title='+escape(document.title)+'&url='+document.location,'','');
}


function facebook(){
	 window.open('http://www.facebook.com/share.php?u='+document.location,'','');
}

