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 muestra(eldiv) {
	div = document.getElementById(eldiv);
	div.style.display = 'block';
}
function oculta(eldiv) {
	div = document.getElementById(eldiv);
	div.style.display = 'none';
}

function muestraFad(eldiv,segundos) { //segundos en aparecer
	div = document.getElementById(eldiv);
	div.style.MozOpacity = '0';
	div.style.filter = 'alpha(opacity: 0)';
	div.style.display = 'block';
	setTimeout("mues1(div)",segundos * 1000);
}
function ocultaFad(eldiv,segundos) { //segundos en desaparecer
	div = document.getElementById(eldiv);
	div.style.MozOpacity = '1';
	div.style.filter = 'alpha(opacity: 100)';
	setTimeout("ocult1(div)",segundos * 1000);
}
function ocult1(div) {
	div.style.MozOpacity = '0.9';
	div.style.filter = 'alpha(opacity: 90)';
	setTimeout("ocult2(div)",50);
}
function ocult2(div) {
	div.style.MozOpacity = '0.8';
	div.style.filter = 'alpha(opacity: 80)';
	setTimeout("ocult3(div)",50);
}
function ocult3(div) {
	div.style.MozOpacity = '0.7';
	div.style.filter = 'alpha(opacity: 70)';
	setTimeout("ocult4(div)",50);
}
function ocult4(div) {
	div.style.MozOpacity = '0.6';
	div.style.filter = 'alpha(opacity: 60)';
	setTimeout("ocult5(div)",50);
}
function ocult5(div) {
	div.style.MozOpacity = '0.5';
	div.style.filter = 'alpha(opacity: 50)';
	setTimeout("ocult6(div)",50);
}
function ocult6(div) {
	div.style.MozOpacity = '0.4';
	div.style.filter = 'alpha(opacity: 40)';
	setTimeout("ocult7(div)",50);
}
function ocult7(div) {
	div.style.MozOpacity = '0.3';
	div.style.filter = 'alpha(opacity: 30)';
	setTimeout("ocult8(div)",50);
}
function ocult8(div) {
	div.style.MozOpacity = '0.2';
	div.style.filter = 'alpha(opacity: 20)';
	setTimeout("ocult9(div)",50);
}
function ocult9(div) {
	div.style.MozOpacity = '0.1';
	div.style.filter = 'alpha(opacity: 10)';
	setTimeout("ocult10(div)",50);
}
function ocult10(div) {
	div.style.display = 'none';
	div.style.MozOpacity = '1';
	div.style.filter = 'alpha(opacity: 100)';
	
}
function mues1(div) {
	div.style.MozOpacity = '0.1';
	div.style.filter = 'alpha(opacity: 10)';
	setTimeout("mues2(div)",50);
}
function mues2(div) {
	div.style.MozOpacity = '0.2';
	div.style.filter = 'alpha(opacity: 20)';
	setTimeout("mues3(div)",50);
}
function mues3(div) {
	div.style.MozOpacity = '0.3';
	div.style.filter = 'alpha(opacity: 30)';
	setTimeout("mues4(div)",50);
}
function mues4(div) {
	div.style.MozOpacity = '0.4';
	div.style.filter = 'alpha(opacity: 40)';
	setTimeout("mues5(div)",50);
}
function mues5(div) {
	div.style.MozOpacity = '0.5';
	div.style.filter = 'alpha(opacity: 50)';
	setTimeout("mues6(div)",50);
}
function mues6(div) {
	div.style.MozOpacity = '0.6';
	div.style.filter = 'alpha(opacity: 60)';
	setTimeout("mues7(div)",50);
}
function mues7(div) {
	div.style.MozOpacity = '0.7';
	div.style.filter = 'alpha(opacity: 70)';
	setTimeout("mues8(div)",50);
}
function mues8(div) {
	div.style.MozOpacity = '0.8';
	div.style.filter = 'alpha(opacity: 80)';
	setTimeout("mues9(div)",50);
}
function mues9(div) {
	div.style.MozOpacity = '0.9';
	div.style.filter = 'alpha(opacity: 90)';
	setTimeout("mues10(div)",50);
}
function mues10(div) {
	div.style.MozOpacity = '1';
	div.style.filter = 'alpha(opacity: 100)';
}




// 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);
};








