var txt_ids;
var IE = document.all?true:false;
var browser;
var version;
var lang;
var abrir = 0;
var aux = 0;
var titulo1;
var titulo2;
var categ_id;
var texto_mas = "";
var texto_y = "";
function detectBrowser()
{
	browser=navigator.appName;
	version=navigator.appVersion;	
}
function strrpos (haystack, needle, offset) {    
    var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1    
    return i >= 0 ? i : false;
}
function cargar_categorias(){	
	var myAjax = new Ajax('../maps/carga_categorias.php',
	{
		method: 'post',
		postBody: 'lang='+lang,
		onComplete: function(){
			load_categ(this.transport);
		}
	}).request();
}
function load_categ(req){
	var categorias = (req.responseXML).firstChild; 	
	var the_div = $("categ");  
    the_div.innerHTML = "";   
	var checkbox = new Array();
	var image = new Array();	  
    var aux_check = 0;  
    var aux_img = 0;
    var div = new Array(); 
    var label = new Array();
    var aux_label = 0;    
    for (var p=0;p<categorias.childNodes.length;p++) {  
    	 div[p] =  document.createElement('div');
    	 div[p].style.margin="5px";    	 
    	 div[p].style.width="210px"; 
    	 div[p].style.height="23px";
    	 div[p].style.fontSize="10px";
    	 div[p].style.color="#2e388b";    	  
    	 checkbox[aux_check]=document.createElement('input');    	
    	 checkbox[aux_check].type="checkbox"; 	     	 
    	 checkbox[aux_check].style.width="13px";    	   
    	 checkbox[aux_check].style.marginBottom = '5px';   	  	      
         checkbox[aux_check].value=categorias.childNodes[p].attributes[0].value;           
         if (IE){
         	checkbox[aux_check]['onclick']=new Function("get_cat_ids()");
         }else{
         	checkbox[aux_check].setAttribute("onclick", "get_cat_ids()");
         }         
         checkbox[aux_check].name='cat'; 
         checkbox[aux_check].id='cat';          
         div[p].appendChild(checkbox[aux_check]);  
         if(control == 4){       
	         if(categ_id){
	         	     if(categorias.childNodes[p].attributes[0].value == categ_id){
			         	if (browser=="Microsoft Internet Explorer" && version.match("MSIE 6.0") && !version.match("MSIE 7.0")){	         		
					    	checkbox[aux_check].defaultChecked=true;
					    }else if (browser=="Microsoft Internet Explorer" && version.match("MSIE 7.0")){			    	
					    	checkbox[aux_check].setAttribute("checked",true);			    				    	   	
					    }else{			    	
			         		checkbox[aux_check].checked = true;		         	      	
			         	}
    	                mover_centro = 1;
			         }         	
	         }else{
	         	//xxxxxxxxxxxxxxxxxxx default xxxxxxxxxxxxxxxxxxxxxxxx
		                  	      	
			         if(categorias.childNodes[p].attributes[0].value == '1000014'){
			         	if (browser=="Microsoft Internet Explorer" && version.match("MSIE 6.0") && !version.match("MSIE 7.0")){	         		
					    	checkbox[aux_check].defaultChecked=true;
					    }else if (browser=="Microsoft Internet Explorer" && version.match("MSIE 7.0")){			    	
					    	checkbox[aux_check].setAttribute("checked",true);			    				    	   	
					    }else{			    	
			         		checkbox[aux_check].checked = true;		         	      	
			         	}
			         }	  
		         
		         //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	         }
         }
         
         image[aux_img]=document.createElement('img');                  
         image[aux_img].src = "../maps/images/iconos_lista/"+categorias.childNodes[p].attributes[2].value;
         image[aux_img].alt = categorias.childNodes[p].attributes[1].value; 
         image[aux_img].width = 42;
         image[aux_img].height = 23;
         div[p].appendChild(image[aux_img]);
         label[aux_label]=document.createElement('label'); 
         label[aux_label].style.lineHeight = '23px';
         label[aux_label].style.width="123px";         
         label[aux_label].style.marginLeft="10px";  
         if(categorias.childNodes[p].attributes[1].value.length > 30){
         	categorias.childNodes[p].attributes[1].value = (categorias.childNodes[p].attributes[1].value).substr(0,30);
         }
         label[aux_label].innerHTML = categorias.childNodes[p].attributes[1].value;
         div[p].appendChild(label[aux_label]);              
         the_div.appendChild(div[p]);                  	
    }
    if(control == 3){
    	abrir = 1;
    	aux = 3;
    	mover_centro = 1;
    	control = 0;
    }
    setTimeout("get_cat_ids()",2000);
}
function get_cat_ids()
 {        	 
        var chk_ids = document.getElementsByName('cat');
        var cnt_ids = chk_ids.length;
        var ids="";               
        if (cnt_ids){
            for(i=0; i<cnt_ids; i++) {            
                if (chk_ids[i].checked) {                
                    ids += "," + (chk_ids[i].value);
                }
            }
        }
        else{
            if (chk_ids.checked) {
                ids += "," + (chk_ids.value);
            }
        }         
        txt_ids = ids;              
        recargar_puntos(txt_ids);
 }

function recargar_puntos(id){	
	document.getElementById('texto_titulo').innerHTML = titulo1;
	document.getElementById('buscar').value = "";
	control = 0;		
	setCategoria(id);	
	cargar_puntos();	
}
function seleccionar_boton(){
	document.getElementById('buscar').focus();
}
function buscar_atractivos(){
	document.getElementById('texto_titulo').innerHTML = titulo2;
	keyword = document.getElementById('buscar').value;
	if (keyword != ""){
		control = 1;
		aux = 1;
		cargar_puntos();
		var chk_ids = document.getElementsByName('cat');
        var cnt_ids = chk_ids.length;                      
        if (cnt_ids){
            for(i=0; i<cnt_ids; i++) {            
                if (chk_ids[i].checked) {                
                    chk_ids[i].checked = false;
                }
            }
        }  	
		
	}else{			
		document.getElementById('texto_titulo').innerHTML = titulo1;
		document.getElementById("side_bar").innerHTML = "";		
	}
}

