//FUNCIONES NO MODIFICABLES
var variables=Array();
var reservado=Array("hsbToRgb","rgbToHsb","rgbToHex","test","each","getLast","getRandom","include","merge","extend","associate","contains","remove","copy","hexToRgb","indexOf","some","every","map","filter","forEach"); //Varores existentes por defecto en un array

function buscar(){
	window.document.getElementById("buscarKey").submit();
	
	
}
function filtro(keyword){
	var unidad=window.document.getElementById("unidad").value;
	var tipo=window.document.getElementById("tipo").value;
	window.location.href="./buscar.html?unit_tmp="+unidad+"&tipo="+tipo+"&keyword="+keyword;
	
}

function CargaComponente(contenedor,archivo,onComplete){

	var tmp=1;
	var ajax = new sack();
	ajax.resetData();
	for(key in this.variables ){
			if(!reservado[key]){
				//alert(variables[key]);
				ajax.setVar(key,variables[key]);
				
				
			}
			
		}
	
	
	ajax.setVar("print","1"); 

	if(onComplete){
		
			funcion="ajax.onCompletion = "+onComplete+";";
			
			eval(funcion);
		
		}
	ajax.requestFile ="./ajax/"+archivo;
	ajax.method = 'POST';
	ajax.element = contenedor;
	ajax.runAJAX();	
}


function setVariable(nom,val){
			this.variables[nom]=val;
		} 
function resetVariable(){
			this.variables=Array();			
		}

function muestraRegion(id,busqueda,contenedor){
		
			
				resetVariable();
				setVariable("objeto_id",id);
				setVariable("busqueda",busqueda);
				CargaComponente(contenedor,"busqueda.php");		
			
	}
	
  function cargar(y_p,x_p,zoom,html,id,icono) {    
  	    if (GBrowserIsCompatible()) {	
			
        map = new GMap2(window.document.getElementById("ID_"+id));
		
 		y_pico="-33.54744";
		x_pico="-70.67179";
			if(y_p && x_p){
				y_pico=y_p;
				x_pico=x_p;
			}			

			map.setCenter(new GLatLng(y_pico,x_pico), zoom);
        map.addControl(new GSmallMapControl());
	   	map.addControl(new GMapTypeControl());
 		map.setMapType(G_HYBRID_MAP);
        geocoder = new GClientGeocoder();
 
        //---------------------------------//
        //   MARCADOR AL HACER CLICK
		//---------------------------------//
	
        //---------------------------------//
        //   FIN MARCADOR AL HACER CLICK
		//---------------------------------//
 
      } // Cierra LLAVE 1.
	  
	  if(y_p && x_p){
	  showAddress(y_p+","+x_p,zoom,html,icono);
		  
		 }
    }   // Cierra LLAVE 2.
 		
		
    //---------------------------------//
    //           GEOCODER
	   
    //]]>
function meter(obj){
		if(obj.innerHTML==""){
				obj.innerHTML="Ingrese su comentario";
			}
	
	}	
function limpiar(texto,obj){
			if(texto==obj.innerHTML){
					obj.innerHTML="";
				}
	}


	
function validar(id_form){

	var formulario=window.document.getElementById(id_form);
	var error="";
	for (var i = 0; i < formulario.length; i++) {
	
	
		var val=formulario.elements[i].accessKey;
		if(val){
			if(formulario.elements[i].type=="textarea"){
				var a = formulario.elements[i].innerHTML;
				if(formulario.elements[i].value=="" || formulario.elements[i].value=="Ingrese su comentario"){
					error=error+""+val+" es obligatorio \n";
				}
			}else{ 
				if(formulario.elements[i].value==""){
					error=error+""+val+" es obligatorio \n";
				}
			}
		}					
						
	
	}
	if(error){
		alert(error);
	}else{
		formulario.submit();	
	}
}

	
    function showAddress(address, zoom,html,icono) {
		if(html)
			html=myBase64Decode(html);
			
    	if (geocoder) {
        	geocoder.getLatLng(address,
          		function(point) {
            		if (!point) {
            			alert(address + " ");
            		} else {
            			map.setCenter(point, zoom);
						var iconoMarca1 = new GIcon(G_DEFAULT_ICON);	
						if(icono==1){
							iconoMarca1.image = "http://conaf.wpchile.cl/cms/editorweb/iconos_mapa/forest.png";
						}else if(icono==2){
							iconoMarca1.image = "http://conaf.wpchile.cl/cms/editorweb/iconos_mapa/forest.png";
						}else if(icono==3){
							iconoMarca1.image = "http://conaf.wpchile.cl/cms/editorweb/iconos_mapa/forest.png";
						}else{
							iconoMarca1.image = "http://conaf.wpchile.cl/cms/editorweb/iconos_mapa/forest.png";
						}
						var tamanoIcono1 = new GSize(37,32);
						iconoMarca1.iconSize = tamanoIcono1;
            			var marker = new GMarker(point,iconoMarca1);

            			map.addOverlay(marker);
						 if(html){ 
							
							GEvent.addListener(marker, 'mouseover', function() {
								marker.openInfoWindowHtml(html);
							  });
						 }
            			//marker.openInfoWindowHtml("<b>"+address+"</b><br>Coordenadas:<br>Latitud : "+point.y+"<br>Longitud : "+point.x+"<a href=http://www.mundivideo.com/fotos_pano.htm?lat="+point.y+"&lon="+point.x+"&mapa=3 TARGET=fijo><br><br>Fotografias</a>");
       			     // marker.openInfoWindowHtml("<b>Coordenadas:</b> "+point.y+","+point.x);
       			      
               		}
               	}
        	);
      	}}
		
function myBase64Decode(str, is_binary) {
	var result = "";
	var i = 0;
	var x;
	var shiftreg = 0;
	var count = -1;
 
	
	for (i=0; i < str.length; i++) {
		c = str.charAt(i);
		if ('A' <= c && c <= 'Z')
			x = str.charCodeAt(i) - 65;
		else if ('a' <= c && c <= 'z')
			x = str.charCodeAt(i) - 97 + 26;
		else if ('0' <= c && c <= '9')
			x = str.charCodeAt(i) - 48 + 52;
		else if (c == '+')
			x = 62;
		else if (c == '/')
			x = 63;
		else
			continue;
 
		count++;
 
		switch (count % 4)
		{
		case 0:
			shiftreg = x;
			continue;
		case 1:
			v = (shiftreg<<2) | (x >> 4);
			shiftreg = x & 0x0F;
			break;
		case 2:
			v = (shiftreg<<4) | (x >> 2);
			shiftreg = x & 0x03;
			break;
		case 3:
			v = (shiftreg<<6) | (x >> 0);
			shiftreg = x & 0x00;
			break;
		}
 
		if (!is_binary && (v < 32 || v > 126) && (v != 0x0d) && (v != 0x0a)) 
		{
			result = result + "<";
			result = result + "0123456789ABCDEF".charAt((v/16)&0x0F);
			result = result + "0123456789ABCDEF".charAt((v/1)&0x0F);
			result = result + ">";
		}
		else
			result = result + String.fromCharCode(v);
 
	}
	return result.toString();
}			