function muestraMensaje(destino,color) {
	if(!color) {
		colorer = '';
	} else {
		colorer = color;
	}
	if(colorer == ''){
		document.getElementById(destino).innerHTML= "<p align='center'><img src='./images/loading-light.gif' border='0'>Cargando</p>";
	} else if(colorer == 'none') {
	
	} else {
		document.getElementById(destino).innerHTML= "<p align='center'><img src='./images/loading-black.gif' border='0'>Cargando</p>";
	}
}
function ajax(destino,datos,color){
	if(!color) {
		colorer = '';
	} else {
		colorer = color;
	}
	new Ajax.Updater(destino,datos,{method:"get",evalScripts: true,onLoaded:muestraMensaje(destino,colorer)});
	document.getElementById(destino).style.display = "block";
}
function ajaxformulario(destino,datos, formid, color){
	if(!color) {
		colorer = '';
	} else {
		colorer = color;
	}
	var Formulario = document.getElementById(formid);
	var longitudFormulario = Formulario.elements.length;
	var cadenaFormulario = "";
	var sepCampos = "";
	for (var i=0; i < Formulario.elements.length;i++) {
		if(Formulario.elements[i].tagName == "SELECT") {
			for (n=0; n <= Formulario.elements[i].length-1; n++) {
				if(Formulario.elements[i].options[n].selected == true) {
					cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(Formulario.elements[i].options[n].value);
					sepCampos="&";
				}
			}
		} else {
			cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(Formulario.elements[i].value);
			sepCampos="&";
		}
	}
	new Ajax.Updater(destino,datos,{method:"post", parameters:cadenaFormulario,evalScripts: true,onLoaded:muestraMensaje(destino,colorer)});
}


  
function rgbToHex(r,g,b) {
	var numero = parseInt(r+g+b);
      
    if (isNaN(numero)) return "00";
    else if (numero <= 0 ) return "00";
    else if (numero > 255) return "FF";
  
    numero = Math.round(numero);
      
    return "0123456789ABCDEF".charAt((numero - numero % 16)/16) + "0123456789ABCDEF".charAt(numero % 16);
}  
function hexToRgb( hex , alpha) {
	hex = (hex.charAt(0)=="#") ? hex.substring(1,7) : hex;
	var r = parseInt(hex.substring(0,2), 16);
	var g = parseInt(hex.substring(2,4), 16);
	var b = parseInt(hex.substring(4,6), 16);
     
	return(alpha != undefined) ? 'rgba('+r+','+g+','+b+','+alpha+')' : 'rgb('+r+','+g+','+b+')';
}

// XHR
XHR = function() {
	var req;
	if (window.XMLHttpRequest) {      // code for IE7+, Firefox, Chrome, Opera, Safari
	      req = new XMLHttpRequest();
	} else {      // code for IE6, IE5
	      req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return req;
};
evalMyScripts = function(DIVID, req) {
	var scriptsTexts = [];
	scriptsTexts = req.responseText.match(/<script[^>]*>[\w|\t|\r|\W]*?<\/script>/gi);
	if(scriptsTexts != null) {
		for(var n = 0; n < scriptsTexts.length; n++) {
			var isSRC = scriptsTexts[n].match(/<script src="\S+"/gi);
			if(isSRC != null) {
				var reqJS = new XHR();
				reqJS.DIVID = DIVID;
				reqJS.onreadystatechange = function() {
					if(reqJS.readyState == 4) {
						evalThisScript(reqJS.DIVID, reqJS.responseText);
					}
				};
				var theSourceURL = isSRC[0].match(/"\S+"$/gi);
				reqJS.open('GET', theSourceURL[0].replace(/"/gi, ''), true);
				reqJS.send(null);
			} else {
				evalThisScript(DIVID, scriptsTexts[n].replace(/<script>|<\/script>/gim));
			}
		}
	}
};
evalThisScript = function(DIVID, texto) {
	var elementScript = document.createElement('script');
	elementScript.text = texto;
	
	document.getElementById(DIVID).innerHTML.replace(/<script[^>]*>[\w|\t|\r|\W]*?<\/script>/gi, '');
	document.getElementsByTagName('head')[0].appendChild(elementScript);
};
getFormParams = function(FORMID) {
	var Formulario = document.getElementById(FORMID);
	var longitudFormulario = Formulario.elements.length;
	var cadenaFormulario = "";
	var sepCampos = "";
	for (var i=0; i < Formulario.elements.length;i++) {
		if(Formulario.elements[i].tagName == "SELECT") {
			for (n=0; n <= Formulario.elements[i].length-1; n++) {
				if(Formulario.elements[i].options[n].selected == true) {
					cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(Formulario.elements[i].options[n].value);
					sepCampos="&";
				}
			}
		} else {
			cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(Formulario.elements[i].value);
			sepCampos="&";
		}
	}
	
	return cadenaFormulario;
};





// ARCHIVOSFLASHV3
var fileUploadsNames = [];
addFileUploadNames = function(fileName) {
	fileUploadsNames.push(fileName);
};

/**
 * Mostrar barra de progreso
 */
showProgressBar = function(DIVIDdestino, current, total) {	
	var barraProgreso = document.createElement('div');
	barraProgreso.setAttribute('style', 'width:'+(current/total)*100+'px; height:100%; background:#006600; color:#EEE; text-align:center; text-shadow:2px 2px #000; font-size:11px; z-index:1');
	
	var fondoBarraProgreso = document.createElement('div');
	fondoBarraProgreso.setAttribute('style', 'margin:0 auto;width:100px; height:18px;background:#333; border:1px solid #EEE;');
	fondoBarraProgreso.appendChild(barraProgreso);
	
	document.getElementById(DIVIDdestino).innerHTML = '';
	document.getElementById(DIVIDdestino).appendChild(fondoBarraProgreso); 
	
	barraProgreso.innerHTML = (current/1024)+'Kb';
};





/**
 * abreviatura document.createElement
 * @param element
 */
DCE = function(element) {
	document.createElement(element);
};
var $DCE = new DCE;








// GOOGLE MAPS
var arrayNamesGoogleObjects = [];
var objectGE;
var objectGM;
StormGoogle = function(nameGoogleObject,mode) {
	this.object;
	this.nameGoogleObject = nameGoogleObject;
	arrayNamesGoogleObjects.push(this.nameGoogleObject);
	this.DIVID;
	this.centrarEn = '(40.396764305572056, -3.9111328125)';
	this.zoom = 5;
	this.mode = mode;
	
	
	
};
StormGoogle.prototype.go = function(keyGoogle, DIVID, centrarEn, zoom, mode) {
	this.DIVID = DIVID;
	if(centrarEn != undefined) {
		this.centrarEn = centrarEn;
	}
	if(zoom != undefined) {
		this.zoom = zoom;
	}
	if(mode != undefined) {
		this.mode = mode;
	}
		
	this.loadScript_google(keyGoogle);
};
StormGoogle.prototype.loadScript_google = function(keyGoogle) {
	

	var script = document.createElement("script");
	
	script.src = "https://www.google.com/jsapi?key="+keyGoogle+"&callback="+this.nameGoogleObject+".loadMapsGoogle";
	
	script.type = "text/javascript";

	document.getElementsByTagName("head")[0].appendChild(script);
	
};
StormGoogle.prototype.loadMapsGoogle = function() {
	if(this.mode == "map") {
		google.load("maps", "2", {"callback" : this.nameGoogleObject+".start()"});
	} else {
		google.load("earth", "1", {"callback" : this.nameGoogleObject+".start()"});
	}
};
StormGoogle.prototype.start = function() {
	if(this.mode == "earth") {
		google.earth.createInstance(this.DIVID, this.initEarth, this.failureEarth);
	} else if(this.mode == "map") {
		this.initMap();
	}
};
StormGoogle.prototype.initEarth = function(instance) {
	this.object = instance;
	this.object.getWindow().setVisibility(true);

	this.object.getNavigationControl().setVisibility(this.object. VISIBILITY_AUTO);

	this.object.getLayerRoot().enableLayerById(this.object.LAYER_ROADS, true);
	this.object.getLayerRoot().enableLayerById(this.object.LAYER_BUILDINGS, true);
	objectGE = this.object;
};
StormGoogle.prototype.failureEarth = function(errorCode) {
	if(errorCode == "ERR_CREATE_PLUGIN") {
		this.mode = "map";
		this.initMap();
    }
    
};
StormGoogle.prototype.initMap = function() {
	this.object = new GMap2(document.getElementById(this.DIVID));
	this.object.setCenter(eval('new GLatLng'+this.centrarEn));
	this.object.setZoom(this.zoom);
	//this.object.setMapType(G_SATELLITE_MAP);
	this.object.addMapType(G_SATELLITE_3D_MAP);
	this.object.addControl(new GMapTypeControl());
	this.object.enableScrollWheelZoom();
	GEvent.addListener( this.object, "zoomend", this.hayzoom);
	

};
StormGoogle.prototype.hayzoom = function(x,y){
	if(y<5) this.object.setZoom(this.zoom);
};








