var W3CDOM = (document.createElement && document.getElementsByTagName);

document.getElementsByClassName = function(className, container){
   var data = tags = [];
   var obj = document.getElementById("wrapper");
   var node = aux = null;
	var strClassName = className.replace(/\-/g, "\\-");
    var pattern = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	if(container) node = (typeof(container) == "object") ? container : document.getElementById(container);
	else node = (obj) ? obj : document;
	aux = node.getElementsByTagName("*");
	tags = (document.all) ? node.all : aux;
   for(var i=0;i<tags.length;i++) { if(pattern.test(tags[i].className)) data.push(tags[i]);}
   return data;
}

String.prototype.trim = function() { return this.replace(/^[\s]+|[\s]+$/g,'') }
String.prototype.numOfCharacters = function(character){
	var rep = 0;
	for(var i=0; i<=this.length-1;i++) if(this.charAt(i) == character) rep++;
	return rep;
}

var e = {
	addEvent : function(obj, evType, fn, useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evType, fn, useCapture);
			return true;
		}else if (obj.attachEvent){
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		}else {
			return false;
		}
	}
}

var fixes={
	setLinkPrint:function(){	
		var obj = document.getElementById("pageOptions");
		var firstChild = obj.getElementsByTagName("li")[0];
		var liElement = document.createElement("li");
		var aElement = document.createElement("a");
		aElement.href = "javascript:window.print()";
		aElement.appendChild(document.createTextNode("Imprimir"))
		liElement.appendChild(aElement);
		liElement.className = "print";
		obj.insertBefore(liElement,firstChild);
		
	},
	setBubble:function(){
		var obj = document.getElementById("bubble");
		var imgElement = document.createElement("img");
		imgElement.src = "/img/bck_arrow-bullet.gif";
		obj.appendChild(imgElement);		
	},
	setBckHome:function(){
		var obj = document.getElementById("content").getElementsByTagName("div")[1];
		var img = document.createElement("img");
		img.src = "/img/bck_hand3.gif";
		img.alt = "";
		obj.appendChild(img);
	},
	setBackRecommend:function(){
		var obj = document.getElementById("recommendPage");
		var forms = obj.getElementsByTagName("form");
		var parent = obj.parentNode;
		var spanElement = document.createElement("span");
		var spanElement2 = document.createElement("span");
		var aElement = document.createElement("a");
		spanElement.className = "btn";
		aElement.appendChild(document.createTextNode("Volver"));
		aElement.href = (forms.length != 0) ? "javascript:history.back()" : "javascript:history.go(-2)";
		spanElement2.appendChild(aElement);
		spanElement.appendChild(spanElement2);		
		parent.appendChild(spanElement);
	},
	setContactPressForm:function(){
		var obj = document.getElementById("contactPressForm").getElementsByTagName("div")[0];
		var divElement = document.createElement("div");
		divElement.className = "arrow sp";
		divElement.appendChild(document.createTextNode(""));
		obj.appendChild(divElement);
	},
	setMsgError:function(){
		var obj = document.getElementById("error").getElementsByTagName("div")[0];
		var divElement = document.createElement("div");
		divElement.className = "fix sp";
		divElement.appendChild(document.createTextNode(""));
		obj.appendChild(divElement);
	},
	setTabSel:function(){
		if($("#tabsPress").hasClass("type2")){
			var obj = $("#tabsPress .current");
			var divElement = $("<div class='sp fix'>&nbsp;</div>")
			obj.append(divElement);	
		}
	},
	setTitlesMedia:function(){
		var obj = $("#mediaGallery");
		var titles = obj.find("h4");
		var h = 0;
		var _this = null;
		titles.each(function(){
			_this = $(this);
			if(_this.height() > h) h = _this.height();
		})
		titles.each(function(){$(this).css("height", h);})
	},
	setBackContact:function(){
		var obj = $("#formContact");
		var parentt = bck = null;
		if(obj.hasClass("selectForm")){
			parentt = obj.parent();
			bck = $("<span class='btn'><span><a href='javascript:history.back()'>Volver</a></span></span>");
			parentt.append(bck);			
		}
	}
}

var curves={
	
	createMainCurves:function(){
		var obj = document.getElementById("wrapperContent");
		var obj2 = document.getElementById("wrapperFooter");
		var cTopLeft = cTopRight = cBottomLeft = cBottomRight = null;		
		cTopLeft = curves.createElementsCurves("cLeftTop");
		cTopRight = curves.createElementsCurves("cRightTop");
		cBottomLeft = curves.createElementsCurves("cLeftBottom");
		cBottomRight = curves.createElementsCurves("cRightBottom");
		obj.appendChild(cTopLeft);
		obj.appendChild(cTopRight);
		obj2.appendChild(cBottomLeft);
		obj2.appendChild(cBottomRight);
		obj2.appendChild(cTopLeft.cloneNode(true));
		obj2.appendChild(cTopRight.cloneNode(true));		
	},
	createGalleryCurves:function(){
		var obj = document.getElementById("createGalleryCurves");		
		var blocks = document.getElementsByClassName("title", obj)
		var cLeft = cRight = null;		
		for(var i = 0; i < blocks.length; i++){
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			blocks[i].appendChild(cLeft);
			blocks[i].appendChild(cRight);
			cLeft = cRight = null;
		}		
	},
	createFormGallery:function(){
		var obj = document.getElementById("galleryDetail");		
		var element = obj.getElementsByTagName("form")[0];
		var cLeft = cRight = null;			
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		element.appendChild(cLeft);
		element.appendChild(cRight);
	},
	createReportsCurves:function(){
		var obj = document.getElementById("annualReport");		
		var blocks = document.getElementsByClassName("report", obj);
		var titles = document.getElementsByClassName("title", obj);
		var cLeft = cRight = null;			
		for(var i = 0; i < titles.length; i++){
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			titles[i].appendChild(cLeft);
			titles[i].appendChild(cRight);
			cLeft = cRight = null;
		}
	},
	createGroupsCurves:function(){
		var obj = document.getElementById("interestGroup");		
		var elements = obj.getElementsByTagName("h5")
		var cLeft = cRight = null;		
		for(var i = 0; i < elements.length; i++){
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			elements[i].appendChild(cLeft);
			elements[i].appendChild(cRight);
			cLeft = cRight = null;
		}		
	},
	createMillestonesCurves:function(){
		var obj = document.getElementById("millestones");		
		var thElements = obj.getElementsByTagName("thead");
		var tbodyElements = obj.getElementsByTagName("tbody");
		var cLeft = cRight = null;		
		var elements = [];
		for(var j = 0; j < thElements.length; j++){
			elements = thElements[j].getElementsByTagName("th");		
			for(var i = 0; i < elements.length; i++){
				cLeft = curves.createElementsCurves("cLeft");
				cRight = curves.createElementsCurves("cRight");
				elements[i].appendChild(cLeft);
				elements[i].appendChild(cRight);
				cLeft = cRight = null;
			}
		}
		for(var j = 0; j < tbodyElements.length; j++){
			elements = tbodyElements[j].getElementsByTagName("th");		
			for(var i = 0; i < elements.length; i++){
				cLeft = curves.createElementsCurves("cLeft");
				cRight = curves.createElementsCurves("cRight");
				elements[i].appendChild(cLeft);
				elements[i].appendChild(cRight);
				cLeft = cRight = null;
			}
		}
	},
	/*createIntProject:function(){
		var obj = document.getElementById("detailProjectInt");		
		var element = obj.getElementsByTagName("h4")[0].parentNode;
		var cLeft = cRight = null;			
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		element.appendChild(cLeft);
		element.appendChild(cRight);
	},
	createJobs:function(){
		var obj = document.getElementById("galleryLogo");		
		var element = obj.getElementsByTagName("h4")[0].parentNode;
		var cLeft = cRight = null;			
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		element.appendChild(cLeft);
		element.appendChild(cRight);
	},*/
	createCommonTitleCurves:function(obj){
		var element = obj.getElementsByTagName("h4")[0].parentNode;
		var cLeft = cRight = null;			
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		element.appendChild(cLeft);
		element.appendChild(cRight);
	},
	createFormDirectory:function(){
		var obj = document.getElementById("mapDirectory").getElementsByTagName("form")[0];			
		var cLeft = cRight = null;			
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		obj.appendChild(cLeft);
		obj.appendChild(cRight);
	},
	createAddressesDirectory:function(){
		var obj = document.getElementById("directory");			
		var uls = obj.getElementsByTagName("ul");
		var title = hType1 = hType2 = cLeft = cRight = null;			
		title = document.getElementsByClassName("title", obj);
		if(uls.length != 0){			
			hType1 = uls[0].getElementsByTagName("h4");
			//hType2 = uls[1].getElementsByTagName("h5");
			for(var i = 0; i < hType1.length; i++){			
				cLeft = curves.createElementsCurves("cLeft");
				cRight = curves.createElementsCurves("cRight");
				hType1[i].appendChild(cLeft);
				hType1[i].appendChild(cRight);
				cLeft = cRight = null;
			}
			/*for(var i = 0; i < hType2.length; i++){			
				cLeft = curves.createElementsCurves("cLeft");
				cRight = curves.createElementsCurves("cRight");
				hType2[i].appendChild(cLeft);
				hType2[i].appendChild(cRight);
				cLeft = cRight = null;
			}*/
		}
			for(var i = 0; i < title.length; i++){			
				cLeft = curves.createElementsCurves("cLeft");
				cRight = curves.createElementsCurves("cRight");								
				title[i].appendChild(cLeft);
				title[i].appendChild(cRight);
				cLeft = cRight = null;
			}
		

	},
	createNationalDirectory:function(){
		var obj = document.getElementById("directory").getElementsByTagName("h5");
		var cLeft = cRight = null;	
		for(var i = 0; i < obj.length; i++){			
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			obj[i].appendChild(cLeft);
			obj[i].appendChild(cRight);
			cLeft = cRight = null;
		}
	},
	createDetailCountryInt:function(){
		var obj = document.getElementById("detailCountryInt");		
		var cLeft = element = cRight = null;
		var titles = obj.getElementsByTagName("h5");
		if(titles.length != 0){
			element = titles[0].parentNode;			
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			element.appendChild(cLeft);
			element.appendChild(cRight);
		}
	},
	createDetailCountryIntType2:function(){
		var obj = document.getElementById("detailCountryIntType2");		
		var titles = document.getElementsByClassName("title", obj);
		var cLeft = cRight = null;			
		for(var i = 0; i < titles.length; i++){			
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			titles[i].appendChild(cLeft);
			titles[i].appendChild(cRight);
			cLeft = cRight = null;			
		}
	},
	createAddressesInter:function(){
		var obj = document.getElementById("detailCountryIntType2");
		var uls = obj.getElementsByTagName("ul");
		var ul = (uls.length == 3 ) ? uls[2] : uls[1];		
		var cLeft = cRight = null;			
		var titles = ul.getElementsByTagName("h5");
		for(var i = 0; i < titles.length; i++){		
			cLeft = curves.createElementsCurves("cLeft");
			cRight = curves.createElementsCurves("cRight");
			titles[i].appendChild(cLeft);
			titles[i].appendChild(cRight);
			cLeft = cRight = null;
		}
	},
	createClimate:function(){
		var obj = document.getElementById("climateChange");
		var cLeft = null;
		cLeft = curves.createElementsCurves("cLeft");
		obj.appendChild(cLeft);
	},
	createFilterMap:function(){
		var obj = document.getElementById("formFilter");						
		cLeft = curves.createElementsCurves("cLeft");
		cRight = curves.createElementsCurves("cRight");
		obj.appendChild(cLeft);
		obj.appendChild(cRight);						
	},
	createGeneralCurves:function(obj){
		var cTLeft = cTRight = cBLeft = cBRight = null;
		cTLeft = curves.createElementsCurves("cTLeft");
		cTRight = curves.createElementsCurves("cTRight");
		cBLeft = curves.createElementsCurves("cBLeft");
		cBRight = curves.createElementsCurves("cBRight");
		obj.appendChild(cTLeft);
		obj.appendChild(cTRight);
		obj.appendChild(cBLeft);
		obj.appendChild(cBRight);
	},
	createElementsCurves:function(style){
		var element = document.createElement("div");
		element.className = style + " sp";
		element.appendChild(document.createTextNode(" "));
		return element;
	}
}

var links={
	openExternalLinks:function(){		
	},
	annualReports:function(){
		var obj = document.getElementById("annualReport");			
		var titles = document.getElementsByClassName("title", obj);
		var imgElement = aElement = firstElement = null;
		for(var i = 0; i < titles.length; i++){
			aElement = document.createElement("a");
			firstElement = titles[i].firstChild;
			aElement.href = "javascript:void(null)";
			aElement.onclick = function() { behaviours.collapseAnnualReport(this); return false }
			aElement.onkeypress = function() { behaviours.collapseAnnualReport(this); return false }
			imgElement = document.createElement("img");
			if(titles[i].parentNode.className.indexOf("main") != -1) imgElement.src = "/img/ico_minus.gif";
			else{
				imgElement.src = "/img/ico_plus.gif";
				titles[i].parentNode.className += " collapsed";
			}			
			aElement.appendChild(imgElement);			
			titles[i].insertBefore(aElement, firstElement);
			imgElement = aElement = firstElement = null;
		}
	},
	setShowFormShareholders:function(){
		var obj = document.getElementById("address");
		var spanElement = document.createElement("span");
		var spanElement2 = spanElement.cloneNode(true);
		var aElement = document.createElement("a");		
		aElement.href = "javascript:void(null)";
		aElement.onclick = behaviours.collapseFormShareholders;
		aElement.onkeypress = behaviours.collapseFormShareholders;
		aElement.appendChild(document.createTextNode("Realizar una consulta"))
		spanElement2.appendChild(aElement);
		spanElement.className = "link top";
		spanElement.appendChild(spanElement2);
		obj.appendChild(spanElement);
		document.getElementById("shareholderOfficeForm").className= "hide";
	}
}

var behaviours = {
	collapseAnnualReport:function(obj){
		var objClassname = obj.parentNode.parentNode.className;
		if(objClassname.indexOf("collapsed") != -1){
			obj.parentNode.parentNode.className = objClassname.replace("collapsed","");
			obj.firstChild.src = "/img/ico_minus2.gif";
		}else{
			obj.parentNode.parentNode.className += " collapsed"; 
			obj.firstChild.src = "/img/ico_plus.gif";
		}
		obj.parentNode.parentNode.tabIndex = -1;
		obj.parentNode.parentNode.focus();		
	},
	collapseFormShareholders:function(){
		var obj =document.getElementById("shareholderOfficeForm");
		obj.className = (obj.className == "hide") ? "" : "hide";
	},
	setEventCmb:function(){
		var obj = document.getElementById("continente");
		var obj2 = document.getElementById("pais");
		var esBusqueda = (window.location.search != "") ? true : false;
		if(!esBusqueda) document.getElementById("ccaa").disabled = "disabled";
		obj.onchange = behaviours.setCmbValues;
		obj2.onchange = behaviours.checkCountry;
	},
	setCmbValues:function(){
		var f = this.parentNode.parentNode.parentNode;	
		var pais = document.getElementById("pais");
		var ccaa = document.getElementById("ccaa");
		var sel = this.selectedIndex;
		var optionElement = null;		
		if(sel != 0){
			while(pais.firstChild) pais.removeChild(pais.firstChild);
			for(var i = 1; i < cmb[sel-1].length; i++){
				optionElement = document.createElement("option");
				optionElement.appendChild(document.createTextNode(cmb[sel-1][i].split("|")[0]));
				optionElement.value = cmb[sel-1][i].split("|")[1];
				pais.appendChild(optionElement);
				optionElement = null;
			}
			ccaa.disabled = "disabled";
		}else while(pais.firstChild) pais.removeChild(pais.firstChild);
		pais.tabIndex = "-1";
		pais.focus();
	},
	checkCountry:function(){
		var value = this[this.selectedIndex].firstChild.nodeValue;
		var obj2 = document.getElementById("ccaa");
		if(value == "España" || value == "Spain"){
			obj2.disabled = "";
			obj2.focus();
		}else obj2.disabled = "disabled";
	},
	resetTerm:function(){
		var obj = document.getElementById("termino");
		obj.onfocus = function(){
			obj.value = "";
		}
	}
}

/* validaciones de formularios */
var formsValidations = {
	setMsgError:function(txt, form){
		//var main = document.getElementById("main");
		var parentForm = form.parentNode;
		var msgError = document.getElementsByClassName("msgError", parentForm);
		var divElement = (msgError.length != 0) ? msgError[0] : document.createElement("div");		
		var ulElement = document.createElement("ul");
		var liElement = null;		
		var errors = txt.split("|");				
		divElement.className = "msgError"
		if(divElement.getElementsByTagName("ul").length != 0) divElement.removeChild(divElement.getElementsByTagName("ul")[0])
		for(var i = 0; i < errors.length - 1; i++){
			liElement = document.createElement("li");
			liElement.appendChild(document.createTextNode(errors[i]));
			ulElement.appendChild(liElement);
		}
		divElement.appendChild(ulElement);		
		divElement.tabIndex = -1;
		if(msgError.length == 0) parentForm.insertBefore(divElement,form);
		divElement.focus();
	},
	validaFormShareholder:function() { 
		var f = document.forms.formShareHolder;		
		var errorTxt = "";
		if(f.denominacion.value == "") errorTxt += "(!) El campo 'Denominación Social / Nombre' es obligatorio|";
		if(f.cif.value == "") errorTxt += "(!) El campo 'CIF' es obligatorio|";
		if(f.representante.value == "") errorTxt += "(!) El campo 'Representante de la sociedad' es obligatorio|";
		if(f.cargo.value == "") errorTxt += "(!) El campo 'Cargo en la sociedad' es obligatorio|";
		if(f.numero.value == "") errorTxt += "(!) El campo 'Número de acciones' es obligatorio|";
		if(f.entidad.value == "") errorTxt += "(!) El campo 'Entidad Financiera Depositaria' es obligatorio|";
		if(f.pais.selectedIndex == 0) errorTxt += "(!) El campo 'País' es obligatorio|";
		if(f.cp.value == "") errorTxt += "(!) El campo 'Código Postal' es obligatorio|";		
		if(f.provincia.value == "") errorTxt += "(!) El campo 'Provincia' es obligatorio|";
		if(f.localidad.value == "") errorTxt += "(!) El campo 'Localidad' es obligatorio|";
		if(f.domicilio.value == "") errorTxt += "(!) El campo 'Domicilio' es obligatorio|";
		if(f.mail.value == "") errorTxt += "(!) El campo 'Email' es obligatorio|";
		//if(f.telefono.value == "") errorTxt += "(!) El campo 'Teléfono' es obligatorio|";
		if(f.motivo.value == "") errorTxt += "(!) El campo 'Motivo de la consulta' es obligatorio|";
		if(f.cif.value != "" && !regularExpressions.esCif(f.cif.value)) errorTxt += "(!) Debe introducir un CIF válido|";	
		if(f.cp.value != "" && !regularExpressions.esNumero(f.cp.value)) errorTxt += "(!) Debe introducir valores numéricos en el campo 'Código postal'|";	
		if(f.mail.value != "" && !regularExpressions.isValidEmail(f.mail.value)) errorTxt += "(!) El formato del campo 'Email' no es correcto|";			
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formShareHolder"));
			return false;
		}
	},
	validaContactForm:function(){
		var f = document.forms.formContact;		
		var errorTxt = "";
		if(f.nombre.value == "") errorTxt += "(!) El campo 'Nombre' es obligatorio|";
		if(f.apellidos.value == "") errorTxt += "(!) El campo 'Apellidos' es obligatorio|";
		//if(f.telefono.value == "") errorTxt += "(!) El campo 'Telefono' es obligatorio|";
		if(f.mail.value == "") errorTxt += "(!) El campo 'E-mail' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'E-mail' no es correcto|";
		}
		if(document.getElementById("medio")){
			if(f.medio.value == "") errorTxt += "(!) El campo 'Medio al que representa' es obligatorio|";
		}
		if(document.getElementById("asunto")){
			if(f.asunto.value == "") errorTxt += "(!) El campo 'Asunto' es obligatorio|";
		}			
		if(f.motivo.value == "") errorTxt += "(!) El campo 'Motivo de la consulta' es obligatorio|";
		else{
			if(f.motivo.value.length > 250)  errorTxt += "El campo 'Motivo de la consulta' no puede exceder de 250 caracteres|";
		}	
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formContact"));
			return false;
		}
	},
	validaFormRecommend:function(){
		var f = document.forms.formRecommend;		
		var errorTxt = aux = "";
		var okMailsAmigo = true;
		if(f.nombre.value == "") errorTxt += "(!) El campo 'Tu nombre' es obligatorio|";
		if(f.mail.value == "") errorTxt += "(!) El campo 'Tu email' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value)) errorTxt += "(!) El formato del campo 'Tu email' no es correcto|";	
		}
		if(f.destino.value == "") errorTxt += "(!) El campo 'Email destinatario' es obligatorio|";						
		if (f.destino.value.numOfCharacters("@") == 0 && f.destino.value != "") errorTxt += "El formato del campo 'Email destinatario' no es correcto|";
		else {
			aux = f.destino.value.replace(/,/g, " ");
			mailsAmigo = aux.split(" ");
			for (i = 0; i < mailsAmigo.length && okMailsAmigo; i++) {
				if (mailsAmigo[i].trim() == "") {
					okMailsAmigo = true;
					continue;
				}
				okMailsAmigo = regularExpressions.isValidEmail(mailsAmigo[i]);
			}
			if (!okMailsAmigo) errorTxt += "(!) El formato del campo 'Email destinatario' no es correcto|";
			else {
				if (aux.numOfCharacters("@") > 1 && f.destino.value.numOfCharacters(",") != f.destino.value.numOfCharacters("@") - 1) errorTxt += "(!) Debes separar los Emails de los destinatarios con comas|";
			}
		}
		if(f.comentarios.value == "") errorTxt += "(!) El campo 'Tus comentarios' es obligatorio|";		
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formRecommend"));
			return false;
		}
	},
	validaRegisterNewsletterForm:function(){
		var f = document.forms.formRegisterNews;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico' no es correcto|";
		}		
		if(f.perfil.selectedIndex==0)  errorTxt += "(!) El campo 'Perfil' es obligatorio|"; 
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formRegisterNews"));
			return false;
		}
	},
	validaModRegisterNewsletterForm:function(){
		var f = document.forms.formModRegisterNews;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico actual' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico actual' no es correcto|";
		}		
		if(f.mailN.value != ""){
			if(!regularExpressions.isValidEmail(f.mailN.value))  errorTxt += "(!) El formato del campo 'Correo electrónico nuevo' no es correcto|";
		}
		if(f.perfil.selectedIndex==0)  errorTxt += "(!) El campo 'Perfil' es obligatorio|"; 
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formModRegisterNews"));
			return false;
		}
	},
	validaBajRegisterNewsletterForm:function(){
		var f = document.forms.formBajaRegisterNews;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico actual' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico actual' no es correcto|";
		}				
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formBajaRegisterNews"));
			return false;
		}
	},
	validaRegisterAlertsForm:function(){
		var f = document.forms.formRegisterAlerts;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico' no es correcto|";
		}		
		if(!f.corp.checked && !f.inf.checked && !f.energ.checked && !f.agu.checked && !f.todas.checked) errorTxt += "(!) El campo 'Categorías' es obligatorio|";

		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formRegisterAlerts"));
			return false;
		}
	},
	validaModRegisterAlertsForm:function(){
		var f = document.forms.formModRegisterAlerts;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico actual' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico actual' no es correcto|";
		}		
		if(f.mailN.value != ""){
			if(!regularExpressions.isValidEmail(f.mailN.value))  errorTxt += "(!) El formato del campo 'Correo electrónico nuevo' no es correcto|";
		}
		if(!f.corp.checked && !f.inf.checked && !f.energ.checked && !f.agu.checked && !f.todas.checked) errorTxt += "(!) El campo 'Categorías' es obligatorio|";
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formModRegisterAlerts"));
			return false;
		}
	},
	validaBajRegisterAlertsForm:function(){
		var f = document.forms.formBajaRegisterAlerts;		
		var errorTxt = "";		
		if(f.mail.value == "") errorTxt += "(!) El campo 'Correo electrónico actual' es obligatorio|";
		else{
			if(!regularExpressions.isValidEmail(f.mail.value))  errorTxt += "(!) El formato del campo 'Correo electrónico actual' no es correcto|";
		}				
		if(errorTxt != ""){	
			formsValidations.setMsgError(errorTxt, document.getElementById("formBajaRegisterAlerts"));
			return false;
		}
	}
}

/* expresiones regulares para validar formularios */
var regularExpressions = {	
	isValidEmail:function (str){
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		return (filter.test(str));
	},
	//esCadena:function(c){ return /^[0-9A-Z/\\t\n\r\s]+$/.test(c); },
	esCadena:function(c) { return /^[0-9A-Za-z-\/Ññ?É?ÓÚáéíóúÜüÄäËë?ïÖö´,'/\\t\n\r\s]+$/.test(c); },
	esAlfabetico:function(c){return /^([a-zA-Z])+$/.test(c);},
	esNumero:function(c){return /^[0-9]+$/.test(c);},
	esTelefono:function(c){return /^[0-9\s\+\-)(]+$/.test(c)},
	esCif:function(c){
		if (!/^[A-Za-z0-9]{9}$/.test(c) || !/^[ABCDEFGHKLMNPQS]/.test(c)) return false;
		var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
		var digCrtl=c.charAt(c.length-1);
		var temp = 0;
		for(i=2;i<=6;i+=2 ) {
		      temp = temp + v1[ parseInt(c.substr(i-1,1)) ];
		      temp = temp + parseInt(c.substr(i,1));
		};
		temp = temp + v1[ parseInt(c.substr(7,1)) ];                   
		temp = (10 - ( temp % 10));
		if( temp == 10 ){if(!(digCrtl=="J" || digCrtl=="0")) return false;
		}else{if(digCrtl!=temp) return false; }
		return true;
	}
}

/*AÑADO*/


var gmaps = {
	ubicaciones:{
		init:function(){			
			if (GBrowserIsCompatible()) gmaps.load(document.getElementById("ubicacion"))			
		}
	},
	buscador:{
		init:function(){
			if (GBrowserIsCompatible()) gmaps.load(document.getElementById("gmapsWrap"))
		},
		mundo:function(){			
			var PuntoCero = new GLatLng(40.416632788688474, -3.7040340900421143);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "0";
			map.setCenter(PuntoCero, 1);
		},
		espania:function(){			
			var PuntoCero = new GLatLng(40.416632788688474, -3.7040340900421143);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "1";
			map.setCenter(PuntoCero, 4);
		},		
		madrid:function(){			
			var PuntoCero = new GLatLng(40.38839687388361, -3.72161865234375);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "2";
			map.setCenter(PuntoCero, 9);
		},
		africa:function(){			
			var PuntoCero = new GLatLng(3.6888551431470478, 21.09375);		
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "3";
			map.setCenter(PuntoCero, 2);
		},
		america:function(){			
			var PuntoCero = new GLatLng(41.50857729743935, -102.65625);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "4";
			map.setCenter(PuntoCero, 3);
		},
		americaC:function(){			
			var PuntoCero = new GLatLng(16.63619187839765, -84.814453125);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "5";
			map.setCenter(PuntoCero, 4);
		},
		americaS:function(){			
			var PuntoCero = new GLatLng(-24.206889622398023, -60.29296875);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "6";
			map.setCenter(PuntoCero, 3);
		},
		asia:function(){			
			var PuntoCero = new GLatLng(53.74871079689897, 91.40625);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "7";
			map.setCenter(PuntoCero, 2);
		},
		europa:function(){			
			var PuntoCero = new GLatLng(50.12057809796007, 16.171875);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "8";
			map.setCenter(PuntoCero, 4);
		},
		oceania:function(){			
			var PuntoCero = new GLatLng(-3.1624555302378474, 129.375);
			if(document.getElementById("actividad")) document.forms.formFilter.tipomapa.value = "9";
			map.setCenter(PuntoCero, 2);
		},
		events:function(){
			var obj = document.getElementById("mapa");
			var title = document.createElement("h4");
			var ul = document.createElement("ul");
			var li = document.createElement("li");
			var li2 = li.cloneNode(true);
			var li3 = li.cloneNode(true);
			var li4 = li.cloneNode(true);
			var li5 = li.cloneNode(true);
			var li6 = li.cloneNode(true);
			var li7 = li.cloneNode(true);
			var li8 = li.cloneNode(true);
			var li9 = li.cloneNode(true);
			var a = document.createElement("a");
			var a2 = a.cloneNode(true);
			var a3 = a.cloneNode(true);
			var a4 = a.cloneNode(true);
			var a5 = a.cloneNode(true);
			var a6 = a.cloneNode(true);
			var a7 = a.cloneNode(true);
			var a8 = a.cloneNode(true);
			var a9 = a.cloneNode(true);
			title.appendChild(document.createTextNode("Accesos directos"));
			li.id = "nacional";
			ul.className = "clearFix";
			a.appendChild(document.createTextNode("España"));
			a.href = "javascript:void(null)";
			a.onclick = function(){
				gmaps.buscador.espania();
				return false;
			}
			a.onkeypress = function(){
				gmaps.buscador.espania();
				return false;
			}
			li2.id = "madrid";
			li.appendChild(a);			
			a2.href = "javascript:void(null)";
			a2.appendChild(document.createTextNode("Madrid"));
			a2.onclick = function(){
				gmaps.buscador.madrid();
				return false;
			}
			a2.onkeypress = function(){
				gmaps.buscador.madrid();
				return false;
			}
			li3.id = "africa";
			a3.href = "javascript:void(null)";
			a3.appendChild(document.createTextNode("África"));
			a3.onclick = function(){
				gmaps.buscador.africa();
				return false;
			}
			a3.onkeypress = function(){
				gmaps.buscador.africa();
				return false;
			}
			li4.id = "america";
			a4.href = "javascript:void(null)";
			a4.appendChild(document.createTextNode("América del Norte"));
			a4.onclick = function(){
				gmaps.buscador.america();
				return false;
			}
			a4.onkeypress = function(){
				gmaps.buscador.america();
				return false;
			}
			li5.id = "asia";
			a5.href = "javascript:void(null)";
			a5.appendChild(document.createTextNode("Asia"));
			a5.onclick = function(){
				gmaps.buscador.asia();
				return false;
			}
			a5.onkeypress = function(){
				gmaps.buscador.asia();
				return false;
			}
			li6.id = "europa";
			a6.href = "javascript:void(null)";
			a6.appendChild(document.createTextNode("Europa"));
			a6.onclick = function(){
				gmaps.buscador.europa();
				return false;
			}
			a6.onkeypress = function(){
				gmaps.buscador.europa();
				return false;
			}
			li7.id = "oceania";
			a7.href = "javascript:void(null)";
			a7.appendChild(document.createTextNode("Oceanía"));
			a7.onclick = function(){
				gmaps.buscador.oceania();
				return false;
			}
			a7.onkeypress = function(){
				gmaps.buscador.oceania();
				return false;
			}
			li8.id = "americaC";
			a8.href = "javascript:void(null)";
			a8.appendChild(document.createTextNode("América Central"));
			a8.onclick = function(){
				gmaps.buscador.americaC();
				return false;
			}
			a8.onkeypress = function(){
				gmaps.buscador.americaC();
				return false;
			}
			li9.id = "americaS";
			a9.href = "javascript:void(null)";
			a9.appendChild(document.createTextNode("América del Sur"));
			a9.onclick = function(){
				gmaps.buscador.americaS();
				return false;
			}
			a9.onkeypress = function(){
				gmaps.buscador.americaS();
				return false;
			}
			li2.appendChild(a2);
			li3.appendChild(a3);
			li4.appendChild(a4);
			li5.appendChild(a5);
			li6.appendChild(a6);
			li7.appendChild(a7);
			li8.appendChild(a8);
			li9.appendChild(a9);
			ul.appendChild(li2);
			ul.appendChild(li3);
			ul.appendChild(li4);			
			ul.appendChild(li5);
			ul.appendChild(li7);
			ul.appendChild(li);
			ul.appendChild(li8);
			ul.appendChild(li9);
			ul.appendChild(li6);
			obj.appendChild(title);
			obj.appendChild(ul);						
		}
	},
	
	load:function(obj){
		var map = new GMap2(obj);		
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl(1));
		map.enableDoubleClickZoom();					
		var PuntoCero = new GLatLng(latitud, longitud);
		map.setCenter(PuntoCero, zoom);					
		var markerD2 = new GMarker(PuntoCero, {icon:G_DEFAULT_ICON, draggable: false});
		map.addOverlay(markerD2);
	}
}






var carruseles = {	
	mycarousel_initCallback:function(carousel) {	
		var clicks = 1;
	    var pages = parseInt(carousel.size()) - 1;  	
		if($("#prev")) $("#prev").css("visibility", "hidden");
	    jQuery('#next').bind('click', function() {
	        carousel.next();
			clicks++;
			carruseles.updatePaging(clicks,pages);
	        return false;
	    });
				
	    jQuery('#prev').bind('click', function() {
	        carousel.prev();
			clicks--;
			carruseles.updatePaging(clicks,pages);
	        return false;
	    });
	},
	updatePaging:function(clicks, pages){
		var prev = $("#prev");		
		var next = $("#next");
		if(clicks == 1) {
			$(prev).css("visibility", "hidden");
			$(next).css("visibility", "visible");
		}
		else if(clicks != pages) {		
			$(prev).css("visibility", "visible");
			$(next).css("visibility", "visible");
		}
		else if(clicks == pages) {		
			$(prev).css("visibility", "visible");
			$(next).css("visibility", "hidden");
		}		
	},		
	galleries:{
		clicks:1,
		items:0,
		pages:0,
		mycarousel_initCallback:function(carousel) {
			carruseles.galleries.items = carousel.size()
			carruseles.galleries.pages = parseInt(carruseles.galleries.items) - 2; 						
		    jQuery('#next').bind('click', function() {
		        carousel.next();														
				carruseles.galleries.clicks++;
				carruseles.updatePaging(carruseles.galleries.clicks,carruseles.galleries.pages);				
		        return false;
		    });						
		    jQuery('#prev').bind('click', function() {
		        carousel.prev();
				carruseles.galleries.clicks--;					
				carruseles.updatePaging(carruseles.galleries.clicks,carruseles.galleries.pages);				
		        return false;
		    });
		},			
		init:function(){			
			var txt = ($("#press").hasClass("fotos")) ? "Foto" : "Video";			
			var number = $("#thumb").parent().find(".number").eq(0);
			$("#thumb").toggleClass("noJv");
			number.toggleClass("noJv");	
			$("#prev").css("visibility","hidden");
			var obj = $(".jcarousel-scroll.clearFix");
			if($("#thumb").find("li").length > 3){	
				number.toggleClass("alone");	
				var pag = $("<ul><li id='mycarousel-prev'><a id='prev' href='#'>" + txt + " anterior</a></li><li id='mycarousel-next'><a id='next' href='#'>" + txt + " siguiente</a></li></ul>");			
				obj.append(pag);
			}
			carruseles.updatePaging(carruseles.galleries.clicks,carruseles.galleries.pages);			
		   jQuery("#thumb").jcarousel({
	    	    scroll: 1,
	        	initCallback: carruseles.galleries.mycarousel_initCallback,		        								
				buttonNextHTML: null,
		        buttonPrevHTML: null				
	    	});
		}
	}
}

var gallery = {
	media:null,
	history:null,
	urlLocation:"",
	social:null,
	init:function(){
		var obj = $("#thumb");
		var aElements = $(obj).find("a");
		gallery.media = $("#detailItem").find(".innerDetail");
		gallery.urlLocation = document.location.href;
		gallery.social = $("#detailItem").find(".social.related");
		for(var i = 0; i < aElements.length; i++) {
			aElements[i].onclick = function(i){
				return function(e){
					if(gallery.history) $(gallery.history).toggleClass("current");
					$(this).toggleClass("current");					
					gallery.showMedia(this, i);
					gallery.setSocialsLinks(i);
					gallery.history = this;
					return false;
				};
			}(i);
		}
	},
	showMedia:function(obj,idx){
		var item = galleryItems[idx].src;
		//var downloadMedia = $("#detailItem .downloadMedia a");
		$(gallery.media).empty();		
		if(item.indexOf("http") == -1 && item.indexOf(".flv") == -1 && item.indexOf(".swf") == -1){
			$(gallery.media).append(gallery.createImg(galleryItems[idx]));
			gallery.downloadMedia(galleryItems[idx]);
		}else{
			gallery.createSwf(galleryItems[idx]);	
		}
		$("#text").empty();
		$("#text").html("<p>" + galleryItems[idx].txt + "</p>");
		//downloadMedia.attr("href",galleryItems[idx].src);
		//downloadMedia.html("("+galleryItems[idx].ext+" - "+galleryItems[idx].size+" kb)")				
	},
	setSocialsLinks:function(idx){
		var aElements = gallery.social.find("a");
		var aux = gallery.urlLocation + "&amp;nodo=" + galleryItems[idx].nodo;
		aElements.eq(0).attr("href","http://www.technorati.com/faves?add="+aux);
		aElements.eq(1).attr("href","http://twitter.com/home?status="+aux);
		aElements.eq(2).attr("href","http://del.icio.us/post?url="+aux);
		aElements.eq(3).attr("href","http://www.meneame.net/submit.php?url="+aux);
		aElements.eq(4).attr("href","http://www.facebook.com/sharer.php?u="+aux);
		aElements.eq(5).attr("href","http://bookmarks.yahoo.com/toolbar/savebm?u="+aux);
	},
	addMedia:function(data){
		var detailItem = $("#detailItem");
		var i = $("#detailItem .addMedia input");
		var d = $("#detailItem .downloadMedia");
		var aux = "";
		if(i.length != 0){
			i.attr("value",data.src);
		}else{
			aux = "<div class='addMedia'>\n";
				aux += "<form action='' method='post'>\n";
				aux += "<label for='embed_code'>Añade este video a tu web:</label>\n";
				aux += "<input type='text' id='embed_code' name='embed_code' value='<object width=\"425\" height=\"344\"><param name=\"movie\" value=\""+data.src+"\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\""+data.src+"\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>' readonly='readonly' />\n";			
			aux += "</form>";
			aux += "</div>";
			
			
			detailItem.append($(aux));
		}
		d.remove();
	},
	downloadMedia:function(data){
		var detailItem = $("#detailItem");
		var d = $("#detailItem .downloadMedia a");		
		var i = $("#detailItem .addMedia");
		var aux = "";
		if(d.length != 0){
			d.attr("href",data.src);
			d.html("("+data.ext+" - "+data.size+" kb)")				
		}else{
			aux = '<div class="downloadMedia"><span>Descargar este video:</span> <a href="'+data.src+'">('+data.ext+' - '+data.size+' kb)</a></div>';
			detailItem.append($(aux));
		}
		i.remove();
	},
	createImg:function(data){
		return $("<img src='"+data.src+"' width='413' height='251' alt='"+data.alt+"' />");
	},

	createSwf:function(data){
		var s1 = null;

		var flashvars = {url:'', file: data.src, image: data.image, width: "415", height: "344", wmode: "transparent", bgcolor: "#ffffff", allowfullscreen: "true", movie: data.src};
		var attributes = {id: 'videoNoticia'};

		if(data.src.indexOf(".swf") == -1 && data.src.indexOf("http://") == -1){
			swfobject.embedSWF("/swf/mediaplayer.swf", "contentVideo", "415", "344", "9.0.0","", flashvars, attributes);
		}else{
			swfobject.embedSWF(data.src, "contentVideo", "415", "344", "9.0.0","", flashvars, attributes);		
		}
		if(data.src.indexOf("http://") == -1){
			gallery.downloadMedia(data);
		}else{
			gallery.addMedia(data);
		}
	}
}


var load={
	existeId:function(cid){	
		if(document.getElementById(cid)) return true;		
		return false;
	},
	setEvents:function(){		
						
	}
}




jQuery(document).ready(function() {			
		curves.createMainCurves();	
		if(load.existeId("termino")) behaviours.resetTerm();
		if(load.existeId("pageOptions")) fixes.setLinkPrint();		
		if(load.existeId("home")) fixes.setBckHome(); 
		if(load.existeId("galleryIntro")) curves.createGalleryCurves(); 
		if(load.existeId("galleryDetail")) curves.createFormGallery(); 
		if(load.existeId("annualReport")){
			curves.createReportsCurves(); 
			links.annualReports();
		}
		//if(load.existeId("interestGroup")) curves.createGroupsCurves();
		if(load.existeId("millestones")) curves.createMillestonesCurves();
		if(load.existeId("detailProjectInt")) curves.createCommonTitleCurves(document.getElementById("detailProjectInt"));
		if(document.getElementsByClassName("jobs",document.getElementById("main")).length != 0) curves.createCommonTitleCurves(document.getElementById("galleryLogo"));	
		//if(load.existeId("mapDirectory")) curves.createFormDirectory();		
		if(load.existeId("mapDirectoryNational")) curves.createNationalDirectory();		
		if(load.existeId("directory")) curves.createAddressesDirectory();
		if(load.existeId("detailCountryInt")) curves.createDetailCountryInt();
		if(load.existeId("detailCountryIntType2")){
			curves.createDetailCountryIntType2();
			curves.createAddressesInter();			
		}
		if(load.existeId("recommendPage")) fixes.setBackRecommend();
		//if(load.existeId("address")) links.setShowFormShareholders();
		if(load.existeId("bubble")) fixes.setBubble();
		if(load.existeId("awards")) curves.createGeneralCurves(document.getElementById("awards").getElementsByTagName("h4")[0].parentNode);
		if(load.existeId("climateChange")) curves.createClimate();
		/*if(load.existeId("contactPressForm")){
			fixes.setContactPressForm();
			curves.createGeneralCurves(document.getElementById("contactPressForm").getElementsByTagName("div")[0]);			
		}*/
		if(load.existeId("error")){
			curves.createGeneralCurves(document.getElementById("error").getElementsByTagName("div")[0]);
			fixes.setMsgError();
		}
		if(load.existeId("continente")) behaviours.setEventCmb();
		if(load.existeId("formFilter")) curves.createFilterMap();
		if(load.existeId("interestGroup")) curves.createCommonTitleCurves(document.getElementById("interestGroup"));
		if(load.existeId("formContact")) document.getElementById("formContact").onsubmit = formsValidations.validaContactForm;			
		if(load.existeId("formShareHolder")) document.getElementById("formShareHolder").onsubmit = formsValidations.validaFormShareholder;
		if(load.existeId("formRecommend")) document.getElementById("formRecommend").onsubmit = formsValidations.validaFormRecommend;
		if(load.existeId("formRegisterNews")) document.getElementById("formRegisterNews").onsubmit = formsValidations.validaRegisterNewsletterForm;
		if(load.existeId("formModRegisterNews")) document.getElementById("formModRegisterNews").onsubmit = formsValidations.validaModRegisterNewsletterForm;
		if(load.existeId("formBajaRegisterNews")) document.getElementById("formBajaRegisterNews").onsubmit = formsValidations.validaBajRegisterNewsletterForm;
		if(load.existeId("formRegisterAlerts")) document.getElementById("formRegisterAlerts").onsubmit = formsValidations.validaRegisterAlertsForm;
		if(load.existeId("formModRegisterAlerts")) document.getElementById("formModRegisterAlerts").onsubmit = formsValidations.validaModRegisterAlertsForm;
		if(load.existeId("formBajaRegisterAlerts")) document.getElementById("formBajaRegisterAlerts").onsubmit = formsValidations.validaBajRegisterAlertsForm;

		if(load.existeId("mapa")) {
			gmaps.buscador.mundo();
			gmaps.buscador.events();
		}		
		if (load.existeId("press") && load.existeId("thumb")){
		  gallery.init(); 
		  carruseles.galleries.init();	
		}
		if (load.existeId("tabsPress")) fixes.setTabSel();
		if (load.existeId("mediaGallery")) fixes.setTitlesMedia();			
		if (load.existeId("formContact")) fixes.setBackContact();	
});		
//if(W3CDOM) e.addEvent(window, "load", load.setEvents, false);