// JavaScript Document
//QUITAR VALUES
	function quitarValues(campo) {
		if( campo.value == campo.defaultValue ) campo.value = '';
		if( campo.style.backgroundColor != "#FFFFFF")validacionValido( campo.name );
	}
//VALIDACIONES
	//Validar Email
	function validarEmail( email) {
		//re = var emailPattern = /^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b/;
		return email.match(/^[-_\.a-zA-Z0-9]+@[-_\.a-zA-Z0-9]+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.name)|(\.info)|(\.biz)|(\.int)|(\.museum)|(\.aero)|(\.coop)|(\.ws)|(\..{2,2}))$/gi)
	}
	//Validar Nombre
	function validarObligatorio( q ) {
		for ( var i = 0; i < q.length; i++ ) {
			if ( q.charAt(i) != " " ) {
				return true
			}
		}
		return null
	}
	
	function spam(q) {
	var spamPal = new Array(5);
	
	spamPal[0] = "Content-Type:";
	spamPal[1] = "MIME-Version:";
	spamPal[2] = "Content-Transfer-Encoding:";
	spamPal[3] = "Return-path:";
	spamPal[4] = "Subject:";
	spamPal[5] = "From:";
	spamPal[6] = "Envelope-to:";
	spamPal[7] = "To:";
	spamPal[8] = "bcc:";
	spamPal[9] = "cc:";

	var i;
	for (i=0; i < 10; i++) {
		if (spamPal[i] === q) {
			return true;
		}
	}
	return false;
};
	
	//ESTILOS
		//Error
		function validacionError( campo , contenedor,textoError ){

			//Variables con los textos
			var textos=new Array("es","eu");
			textos["es"]=new Array('<h2>Error</h2><p>Se han detectado errores en los siguientes campos:</p><ul id="listado_errores"><li></ul>'),
			textos["eu"]=new Array('<h2>Errore</h2><p>Erroreak aurkitu dira hurrengo arloetan:</p><ul id="listado_errores"><li></ul>')

			document.getElementById(campo).style.backgroundColor = "#FFFFCC";
			document.getElementById(campo).value = document.getElementById(campo).defaultValue;
			//mensaje de error
			if(contenedor!=""){
				if(document.getElementById("listado_errores")==null){
					document.getElementById(contenedor).innerHTML=textos[idioma][0];
				}
				if(textoError!="")document.getElementById("listado_errores").innerHTML=document.getElementById("listado_errores").innerHTML+textoError;	
			}
		}
		//Quitar Error
		function validacionValido( campo ){
			document.getElementById(campo).style.backgroundColor = "#FFFFFF";
		}
//GETEMELENTSBYCLASSNAME		
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}
//CODIFICACION A UTF8 PARA GOOGLE COOP
	 var Utf8 = {  
	   
		 // public method for url encoding  
		 encode : function (string) {  
			 string = string.replace(/\r\n/g,"\n");  
			 var utftext = "";  
	   
			 for (var n = 0; n < string.length; n++) {  
	   
				 var c = string.charCodeAt(n);  
	   
				 if (c < 128) {  
					 utftext += String.fromCharCode(c);  
				 }  
				 else if((c > 127) && (c < 2048)) {  
					 utftext += String.fromCharCode((c >> 6) | 192);  
					 utftext += String.fromCharCode((c & 63) | 128);  
				 }  
				 else {  
					 utftext += String.fromCharCode((c >> 12) | 224);  
					 utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
					 utftext += String.fromCharCode((c & 63) | 128);  
				 }  
	   
			 }  
	   
			 return utftext;  
		 },  
	   
		 // public method for url decoding  
		 decode : function (utftext) {  
			 var string = "";  
			 var i = 0;  
			 var c = c1 = c2 = 0;  
	   
			 while ( i < utftext.length ) {  
	   
				 c = utftext.charCodeAt(i);  
	   
				 if (c < 128) {  
					 string += String.fromCharCode(c);  
					 i++;  
				 }  
				 else if((c > 191) && (c < 224)) {  
					 c2 = utftext.charCodeAt(i+1);  
					 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));  
					 i += 2;  
				 }  
				 else {  
					 c2 = utftext.charCodeAt(i+1);  
					 c3 = utftext.charCodeAt(i+2);  
					 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
					 i += 3;  
				 }  
	   
			 }  
	   
			 return string;  
		 }  
	   
	}
//INICIO DE LOS EVENTOS COMUNES	
	var ini = function() {
		var textos=new Array("es","eu");
		textos["es"]=new Array("Buscar","T&eacute;rmino b&uacute;squeda");
		textos["eu"]=new Array("Bilaketa","Bilaketa hitzak");
		//menu desplegable
			//funcion poner enventos
			if (document.all&&document.getElementById&&typeof document.body.style.maxHeight == "undefined") {
				var submenus=getElementsByClassName("submenu_li");
				//alert(submenus);
				for(var i=0;submenus.length>i;i++){
					submenus[i].onmouseover=function() {						
						this.className+=" over";
					}
					submenus[i].onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}

		//En caso de tener javascript activo metemos el formulario de google	
			if(document.getElementById("google_coop")!=null){
				var divGoogleCoop=document.getElementById("google_coop");
				divGoogleCoop.innerHTML="<!-- Google CSE Search Box Begins --><form id=\"searchbox_013199633623313773974:org9huuacke\" action=\"/secciones/buscador.php\"><p><label for=\"busqueda\" class=\"ayudaAcces\">"+textos[idioma][0]+"</label><input type=\"hidden\" name=\"cx\" value=\"013199633623313773974:org9huuacke\" /><input type=\"hidden\" name=\"cof\" value=\"FORID:9\" /><input name=\"q\" id=\"q\" class=\"busqueda\" type=\"text\" value=\""+textos[idioma][1]+"\" /><input name=\"q_t\" type=\"hidden\" /><input class=\"boton\" type=\"submit\" name=\"sa\" value=\""+textos[idioma][0]+"\" />	</p></form><!-- Google CSE Search Box Ends -->";
				document.forms[0].q.onfocus = function(){
						quitarValues(document.forms[0].q)
				}
				document.forms[0].onsubmit = function(){ 
					if(validarObligatorio( document.forms[0].q.value )==null ||  document.forms[0].q.value == document.forms[0].q.defaultValue ){
						validacionError( "q","","");
						document.forms[0].q.onfocus = function(){quitarValues(document.forms[0].q)};
						return false;
					}else return true;
					
				}	
			}
	}
