/* 
	Funciones de JavaScript
	
	Para incluir el archivo:
		<script src="funciones.js" type="text/javascript"></script> 
*/

//FUNCIONES


//Control para guardar una posicion  

function MDControl2() { }
 
 MDControl2.prototype = new GControl();
 
 MDControl2.prototype.initialize = function(map) {
 var container = document.createElement("div");
 var savepos= document.createElement("div");
 savepos.className= "MDbuttons";
 savepos.title= "Save position and Zoom level";
 container.appendChild(savepos);
 savepos.appendChild(document.createTextNode("Save.."));
 GEvent.addDomListener(savepos, "click", function() {
 var center = map.getCenter(); var zoom = map.getZoom();
 saved.splice(0,2,center,zoom);
 alert("Saved position: "+center.toUrlValue()+"\nZoom level: "+zoom);
 });

 var tosaved=document.createElement("div");
 tosaved.className= "MDbuttons";
 tosaved.title= "Back to Saved";
 container.appendChild(tosaved);
 tosaved.appendChild(document.createTextNode("Back.."));
 
 GEvent.addDomListener(tosaved, "click", function() {
 if(saved.length > 0) { map.setZoom(saved[1]); map.panTo(saved[0]); }
 });
 map.getContainer().appendChild(container);
 return container;
 }

MDControl2.prototype.getDefaultPosition = function() {
 return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7,40));
}

//........FIN


//funciones del div con los checkboxes

function hideAll() {
  var boxes = document.getElementsByName("mark");
  for(var i = 0; i < boxes.length; i++) {
	if(boxes[i].checked) {
	boxes[i].checked = false;
	switchLayer(false, layers[i].obj);
	chosen.push(i);
    }
  }
}

function checkChecked() {
var boxes = document.getElementsByName("mark");
	for(var i = 0; i < boxes.length; i++) {
		if(boxes[i].checked) return true;
	}
	return false;
}

function switchLayer(checked, layer) {
var boxlink = document.getElementById("boxlink");
var box = document.getElementById("box");

if(checked){
	map.addOverlay(layer);
	// Reset chosen array
	chosen.length = 0;
	/* Highlight the link and
	* make the button font bold.*/
	box.className="highlight";
	boxlink.className="highlight";
}
else {
	map.removeOverlay(layer);
	/* Reset the link and the button
	* if all checkboxes were unchecked.*/
	if(!checkChecked()) {
	boxlink.blur();
	boxlink.className="";
    box.className="";
	}
}
}

function toggleLayers() {

	if(chosen.length > 0 ) {
	var copy = chosen.slice();
	for(var i = 0; i < copy.length; i++) {
	var index = parseInt(copy[i]);
	switchLayer(true, layers[index].obj);
	document.getElementsByName("mark")[index].checked = true;
	}
	}
	else {
	hideAll();
	}
}

//........FIN


//para el alto dinamico del mapa

function cargaAlto(){
	
	height_res=screen.height-250;
	alto=height_res+"px";
/* 
	hay que hacer esta forma porque IE tiene problemas para usar el comando
	setAttribute ¬ ¬
*/
	divMapa=document.getElementById("map");
	cssStyle="border: 3px solid #0066CC; width:94%; height:"+alto+"; margin:0 0 0 0; padding:10px;";
	
	if (navigator.appName == "Microsoft Internet Explorer"){
		var styleData = cssStyle;
		divMapa.style.setAttribute('cssText', styleData);
	}else{
		divMapa.setAttribute("style",cssStyle);
	}
		
}	

//........FIN

