function EnllacaIdioma(intOrigen,bIdioma1,bIdioma2){

//catala=1,castellà=2,angles=3
var Idiomes = new Array()
Idiomes[0] = "cat"   	//directori
Idiomes[1] = "cas"
Idiomes[2] = "eng"


	if(document.getElementById){
	
		var strURL = new String(window.location)
		
		var idioma1 = document.getElementById("idioma1_link")
		var idioma2 = document.getElementById("idioma2_link")
		
		
		idioma1.href = strURL.replace("/"+Idiomes[intOrigen-1]+"/","/"+Idiomes[bIdioma1-1]+"/")
		idioma2.href = strURL.replace("/"+Idiomes[intOrigen-1]+"/","/"+Idiomes[bIdioma2-1]+"/")

	}
	
}

function addEvent(obj, evType, fn){ 

	if(obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}else if (obj.attachEvent){ 
		return obj.attachEvent("on" + evType, fn); 
	}else{ 
		return false; 
	} 
 
}

function SelectIdioma(){
var testIdioma = ""

	try{testIdioma=idioma}
	catch(e){}

	if(testIdioma!=""){
		switch(testIdioma){
			case "cat":
				EnllacaIdioma(1,2,3) 
				break
			case "cas":
				EnllacaIdioma(2,1,3) 
				break
			case "eng":
				EnllacaIdioma(3,1,2) 
				break
		}
	}
}


function TreureTextInput(){

	if(document.getElementById){
		//cercador
		if(document.getElementById("cerca")){
			document.getElementById("cerca").blur()
			addEvent(document.getElementById("cerca"), 'focus', function(){
																		 if(document.getElementById("cerca").value=="cercar" || 
																			document.getElementById("cerca").value=="buscar" ||
																			document.getElementById("cerca").value=="search" 
																			) 
																		 document.getElementById("cerca").value=""
																}
			);
		}

		//qui és qui
		if(document.getElementById("query")){
			document.getElementById("query").blur()
			addEvent(document.getElementById("query"), 'focus', function(){
																		 if(document.getElementById("query").value=="Cerca de persones i organismes" ) 
																		 document.getElementById("query").value=""
																}
			);
		}
	}
	
}


function ValidaParaulaCerca(){
	
		if(!document.getElementById) return;
		if(!document.getElementById("cercador")) return;
		
		var objFORM = document.getElementById("cercador");

		if(objFORM.nodeName.toLowerCase()!="form"){
			objFORM = objFORM.getElementsByTagName("form");
			
			if(objFORM.length>0){
				objFORM = objFORM[0];
			}else{
				return;
			}
		
		}
		
		objFORM.onsubmit = function(){

			var ca = "Si us plau, introduïu les paraules a cercar.";
			var es = "Por favor, introduzca las palabras a buscar.";
			var en = "Type your search please.";
			var continuar = true;
			var idioma = "";
			
			if(document.documentElement.getAttribute && (document.documentElement.getAttribute("lang")!="" || document.documentElement.getAttribute("xml:lang")!="" )){
				idioma = (document.documentElement.getAttribute("lang")?document.documentElement.getAttribute("lang"):(document.documentElement.getAttribute("xml:lang")?document.documentElement.getAttribute("xml:lang"):""));
			}

			switch(document.getElementById("cerca").value){
				
				case "":
					alert(eval(idioma));
					continuar = false;
					break;
				case "cercar":
					alert(idioma!=""?eval(idioma):ca);
					continuar = false;
					break;
				case "buscar":
					alert(idioma!=""?eval(idioma):es);
					continuar = false;
					break;
				case "search":
					alert(idioma!=""?eval(idioma):en);
					continuar = false;
					break;
			}
		
			if(continuar)
				return true;
			else{
				document.getElementById("cerca").focus();
				return false;
			}
			
		}
		
}

function ObjectsIE(){

	if(navigator.userAgent.toLowerCase().indexOf("msie")>-1 && document.getElementsByTagName && document.createElement){
		script = document.createElement("script");
		script.setAttribute("type","text/javascript");
		script.setAttribute("src","http://www.gencat.net/js/objects_ie.js");
		document.getElementsByTagName('head')[0].appendChild(script);		
	}
	
}


if(navigator.userAgent.toLowerCase().indexOf("minimo")>-1){
	var blocEstil = document.createElement("style");
	blocEstil.innerHTML = "body{width:100%!important;}"
	blocEstil.innerHTML += "div{width:100%!important;float:none!important;clear:both!important;	margin:0!important;	padding:0!important;}"
	blocEstil.innerHTML += ".border_left,.contingut_pastilla_bg,.contingut_pastilla_bg_nofloat{background-image:none!important;}"
	blocEstil.innerHTML += "div#marc div.menu_superior, div#marc div.menu_superior ul, div#capcalera div#menu_cap ul{float:left !important;}"
	blocEstil.innerHTML += "div#capcalera div#menu_cap ul li{display:inline; float:left; margin-left:0; background-color:#818181; color: #fff;}"
	blocEstil.innerHTML += "div.titulomenu{background-image:none!important;}"
	blocEstil.innerHTML += "div#impacte, div#marc div.imatge_impacte, div#marc div.imatge_impacte_petita,h1, div#bloc_dades_img{display:none;}"
	blocEstil.innerHTML += "div.ocult{position: inherit; height:auto; width:auto; overflow: visible ; margin: .2em auto 0 auto !important; font-size:.7em;}"
	document.getElementsByTagName('head')[0].appendChild(blocEstil);		
}


addEvent(window, 'load', SelectIdioma);
addEvent(window, 'load', TreureTextInput);
addEvent(window, 'load', ValidaParaulaCerca);

