function ver_nuevas(){
	document.getElementById('leidas').style.display = "none"; 
	document.getElementById('nuevas').style.display = "";	
}

function aviso_legal(id){
	alert('GuíaVerde necesita comprobar que Usted es una persona autorizada por la empresa para gestionar sus datos en la plataforma. En breve nos pondremos en contacto con la empresa para validar su solicitud. Si la gestión es positiva, vincularemos su cuenta de usuario a la ficha de su empresa y le enviaremos un email de notificación. A partir de entonces podrá acceder a los datos de la empresa desde su zona privada de usuario.');
	document.getElementById("encontrada").value=id;
	document.new_company.submit();

}

function ver_leidas(){
	document.getElementById('nuevas').style.display = "none"; 
	document.getElementById('leidas').style.display = "";	
}

function ver_empresas_nuevas(){
	document.getElementById('empresas_nuevas').style.display = ""; 
	document.getElementById('empresas_vistas').style.display = "none";	
}

function ver_empresas_vistas(){
	document.getElementById('empresas_nuevas').style.display = "none"; 
	document.getElementById('empresas_vistas').style.display = "";	
}

function busqueda_empresas(form){
 	var url;
 	var error = 0;
 	var activity;
 	url = form.path.value;
 	
 	
 	//if (form.lang.value == 1){
		url = url + "empresas/busqueda/";

	//}
	//if (form.lang.value == 1){
		url = url + "texto/";
	//}
 	if (form.text.value != 0){
		url = url + form.text.value;
	}else{
		url = url + "null";
	}
	url = url + "/";
	
	//if (form.lang.value == 1){
		url = url + "ciudad/";
	//}
 	if (form.city.value != 0){
		url = url + form.city.value;
	}else{
		url = url + "null";
	}
	url = url + "/";
	//if (form.lang.value == 1){
		url = url + "provincia/";
	//}
 	if (form.state.value != 0){
		url = url + form.state.value;
	}else{
		url = url + "0";
	}
	url = url + "/";
	//if (form.lang.value == 1){
		url = url + "actividad/";
	//}
	
	if (form.sub_act.value != 0){
		activity = form.sub_act.value;
	}else{
		if (form.act.value != 0){
			activity = form.act.value;
		}else{
			if (form.sect.value != 0){
			 	//if (form.lang.value == 1){
					alert("Debes seleccionar una actividad");
				//}
				error = 1;
			}
		}
	}
	if (activity != 0){
		url = url + activity;
	}else{
		url = url + "0";
	}
	url = url + "/";
	//if (form.lang.value == 1){
		url = url + "pais/";
	//}
 	if (form.country.value != 0){
		url = url + form.country.value;
	}else{
		url = url + "0";
	}
	
	url = url + "/";
	if (error != 1){
	 	
		return form.action=url;
	}else{
		return 0;
	}
}

function busqueda_noticias(form){
 	var url;
 	url = form.path.value;
 	//if (form.lang.value == 1){
		url = url + "noticias/busqueda/";
	//}
	//if (form.lang.value == 1){
		url = url + "tipo/";
	//}
 	if (form.type_noticia.value != 0){
		url = url + form.type_noticia.value;
	}else{
		url = url + "0";
	}
	url = url + "/";
	
	
	//if (form.lang.value == 1){
		url = url + "texto/";
	//}
 	if (form.text.value != 0){
		url = url + form.text.value;
	}else{
		url = url + "null";
	}
	url = url + "/";
	
	//if (form.lang.value == 1){
		url = url + "fechas/";
	//}
	
	valuefechas = getRadioButtonSelectedValue(form.fechas);
	if (valuefechas != ""){
	 	if (valuefechas == 4){
	 	 	desde = form.desde.value;
	 	 	desde = desde.replace("/", "")
	 	 	desde = desde.replace("/", "")
	 	 	hasta = form.hasta.value;
	 	 	hasta = hasta.replace("/", "");
	 	 	hasta = hasta.replace("/", "");
			url = url + valuefechas + "_" + desde + "-" + hasta;
		}else{
			url = url + valuefechas;
		}
	}else{
		url = url + "0";
	}
	
	url = url + "/";
	
	return form.action=url;
}

function busqueda_productos(form){
 	var url;
 	url = form.path.value;
 	//if (form.lang.value == 1){
		url = url + "productos/busqueda/";
	//}
	//if (form.lang.value == 1){
		url = url + "texto/";
	//}
 	if (form.text.value != 0){
		url = url + form.text.value;
	}else{
		url = url + "null";
	}
	url = url + "/";
	
	//if (form.lang.value == 1){
		url = url + "provincia/";
	//}
 	if (form.select_state.value != 0){
		url = url + form.select_state.value;
	}else{
		url = url + "0";
	}
	url = url + "/";
	
	//if (form.lang.value == 1){
		url = url + "pais/";
	//}
 	if (form.country.value != 0){
		url = url + form.country.value;
	}else{
		url = url + "0";
	}
	url = url + "/";
	return form.action=url;
}

function busqueda_actualidad(form){
 	var opt;
 	opt = getRadioButtonSelectedValue(form.tipobusq);
 	if (opt == 1){
		var url;
	 	url = form.path.value;
		url = url + "noticias/busqueda/";
		url = url + "tipo/";
		url = url + "0";
		url = url + "/";
		url = url + "texto/";
	 	if (form.text.value != 0){
			url = url + form.text.value;
		}else{
			url = url + "null";
		}
		url = url + "/";
		url = url + "fechas/";
		valuefechas = getRadioButtonSelectedValue(form.fechas);
		if (valuefechas != ""){
		 	if (valuefechas == 4){
		 	 	desde = form.from.value;
		 	 	desde = desde.replace("/", "")
		 	 	desde = desde.replace("/", "")
		 	 	hasta = form.to.value;
		 	 	hasta = hasta.replace("/", "");
		 	 	hasta = hasta.replace("/", "");
				url = url + valuefechas + "_" + desde + "-" + hasta;
			}else{
				url = url + valuefechas;
			}
		}else{
			url = url + "0";
		}
		
		url = url + "/";
		
		return form.action=url;
	}else{
	 	var $event_type = 0;
	 	
	 	var $event_state = 0;
	 	
	 	var $event_country = 0;
	 
		$event_text = document.getElementById("text").value;
		
		$event_from = document.getElementById("from").value;
		
		$event_to = document.getElementById("to").value;
	 	$url = '/eventos/busqueda/';
		if($event_text != ''){
				$url = $url + "texto-" + $event_text + "/" ;
		}
		if($event_type != 0){
				$url = $url + "tipo-" + $event_type + "/" ;	
		}
		if($event_state != 0){
				$url = $url + "provincia-" + $event_state + "/" ;	
		}
		if($event_country != 0){
				$url = $url + "pais-" + $event_country + "/" ;
		}
		fecha_ok=true;
		valuefechas = getRadioButtonSelectedValue(form.fechas);
		if (valuefechas == 4){
			if( ($event_from != "") || ($event_to != "") ){
				
				if( ($event_from != "") && ($event_to != "") ){
					$compare_from=$event_from.split("/"); 
					$compare_to=$event_to.split("/"); 
					if($compare_to[2]+$compare_to[1]+$compare_to[0] < $compare_from[2]+$compare_from[1]+$compare_from[0]){
						fecha_ok=false;	
					}
				}
				$event_from=replace($event_from,"/","_");
				$event_to=replace($event_to,"/","_");
				$url = $url + "fechas-" + $event_from + "-" + $event_to + "/" ;
			}
		}
		if (valuefechas == 1){
			$url = $url + "fechas-" + form.hoy.value + "-" + form.hoy.value + "/" ;
		}
		if (valuefechas == 2){
			$url = $url + "fechas-" + form.principiosemana.value + "-" + form.hoy.value + "/" ;
		}
		if (valuefechas == 3){
			$url = $url + "fechas-" + form.principiomes.value + "-" + form.finmes.value + "/" ;
		}
		if(fecha_ok==true){
			return form.action=$url;
		}else{
			alert("La fecha de fin debe ser mayor o igual a la fecha de inicio");
		}
		
	}
}


function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
}


/* Productos */

function productos_nuevos(){
	document.getElementById('productos_leidos').style.display = "none"; 
	document.getElementById('productos_nuevos').style.display = "";	
}

function productos_leidos(){
	document.getElementById('productos_nuevos').style.display = "none"; 
	document.getElementById('productos_leidos').style.display = "";	
}
/* Empresas */

function ver_general(){
	
	document.getElementById('localizacion').style.display = "none"; 
	
	document.getElementById('productos').style.display = "none";
	
	document.getElementById('general').style.display = "";
			
}

function ver_localizacion(lat,lon,type){
	document.getElementById('general').style.display = "none"; 
	document.getElementById('productos').style.display = "none";
	document.getElementById('localizacion').style.display = "";	
	if(type == 'create'){
		create_map(lat,lon);
	}
	if(type == 'show'){
		showAddress(lat);
	}
}
function ver_productos(){
	document.getElementById('general').style.display = "none"; 
	document.getElementById('localizacion').style.display = "none";
	document.getElementById('productos').style.display = "";
}

/* Calendario de Eventos */

function handleHttpResponse() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			if(document.getElementById("contenedor_calendario") != null){
			 	
			 	calendario_agenda = document.getElementById('contenedor_calendario');
				calendario_agenda.innerHTML="";
				calendario_agenda.innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
			}
            isWorking = false;
		}
    }
}


var isWorking = false;
function calendario_agenda(fech)
{
    var ieVer =0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}

    if (!isWorking && http)
    {
        if (!fech)
        {
            alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");   
        }
        else
        {
            var url = "/inc/calendario.php?date="+fech;
            http.open("GET", url, true);
            http.onreadystatechange = handleHttpResponse;
            isWorking = true;
            http.send(null);
        }
   }
   
}

function calendario2(fech){
    var ieVer =0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}

    if (!isWorking && http)
    {
        if (!fech)
        {
            alert("Poner error publico");   
        }
        else
        {
         
        
            var url = "/inc/calendario.php?date="+fech;
          
            http.open("GET", url, true);
            http.onreadystatechange = handleHttpResponse;
           
            isWorking = true;
            http.send(null);
            
        }
   }
   
}

function calendario3(fech){
    var ieVer =0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}

    if (!isWorking && http)
    {
        if (!fech)
        {
            alert("Poner error publico");   
        }
        else
        {
         
        
            var url = "/inc/calendario2.php?date="+fech;
          
            http.open("GET", url, true);
            http.onreadystatechange = handleHttpResponse;
           
            isWorking = true;
            http.send(null);
            
        }
   }
   
}

/* Busqueda de eventos */

function search_event($lang) {
	for (i = 0; i < document.getElementById("input_type").length; i++) {
      if (document.getElementById("input_type")[i].selected) {
         $event_type = document.getElementById("input_type")[i].value;
      }   
    }
	$event_text = document.getElementById("input_text").value;

	//$event_type = document.getElementById("input_type").selectedIndex;

	$event_state = document.getElementById("select_state").value;

	$event_country = document.getElementById("input_country").value;
	
	$event_from = document.getElementById("from").value;
	
	$event_to = document.getElementById("to").value;
 	$url = '/eventos/busqueda/';
	if($event_text != ''){
			$url = $url + "texto-" + $event_text + "/" ;
	}
	if($event_type != 0){
			$url = $url + "tipo-" + $event_type + "/" ;	
	}
	if($event_state != 0){
			$url = $url + "provincia-" + $event_state + "/" ;	
	}
	if($event_country != 0){
			$url = $url + "pais-" + $event_country + "/" ;
	}
	fecha_ok=true;
	if( ($event_from != "") || ($event_to != "") ){
		
		if( ($event_from != "") && ($event_to != "") ){
			$compare_from=$event_from.split("/"); 
			$compare_to=$event_to.split("/"); 
			if($compare_to[2]+$compare_to[1]+$compare_to[0] < $compare_from[2]+$compare_from[1]+$compare_from[0]){
				fecha_ok=false;	
			}
		}
		$event_from=replace($event_from,"/","_");
		$event_to=replace($event_to,"/","_");
		$url = $url + "fechas-" + $event_from + "-" + $event_to + "/" ;
	}
	if(fecha_ok==true){
		document.location = $url;
	}else{
		alert("La fecha de fin debe ser mayor o igual a la fecha de inicio");
	}
	
}

/* Busqueda de empresas */

function search_company() {
	$company = document.getElementById("company_name").value;
	if($company != ''){
	 	// Se manda la url
		/*$location = String(document.location);
		$location = replace($location,"http://","");
		$location=$location.split('/');*/
		
		$url = '/empresas/busqueda/' ;
		$url = $url + $company + "/" ;
		document.location = $url;
	}
}

/* Busqueda de productos */

function search_product() {
	$product = document.getElementById("product_title").value;
	if($product != ''){
	 	// Se manda la url
		/*$location = String(document.location);
		$location = replace($location,"http://","");
		$location=$location.split('/');*/
		
		$url = '/productos/busqueda/' ;
		$url = $url + $product + "/" ;
		document.location = $url;
	}
}

/* Busqueda de reportajes */

function search_reportage() {
	$reportage = document.getElementById("reportage_title").value;
	if($reportage != ''){
	 	// Se manda la url
		/*$location = String(document.location);
		$location = replace($location,"http://","");
		$location=$location.split('/');*/
		
		$url = '/reportajes/busqueda/' ;
		$url = $url + $reportage + "/" ;
		document.location = $url;
	}
}

/* Busqueda de plantas */

function search_plant($lang) {
	var $type = "";
	var $plant = "";
	$plant = document.getElementById("plant_name").value;
	if (document.getElementById("cmbtypeplant")){
		$type = document.getElementById("cmbtypeplant").options[document.getElementById("cmbtypeplant").selectedIndex].id;
	}
	if($plant != ''){
	 	// Se manda la url
		/*$location = String(document.location);
		$location = replace($location,"http://","");
		$location=$location.split('/');*/
		//if($lang == 1){
			$url = '/guia_de_plantas/nombre/' ;
		//}
		
		$url = $url + $plant + "/" ;
		if($type != ''){
			$url = $url + "tipo/"+$type
		}
		document.location = $url;
	}
}

function search_noticia() {
	$noticia = document.getElementById("noticia_title").value;
	if($noticia != ''){
	 	// Se manda la url
		/*$location = String(document.location);
		$location = replace($location,"http://","");
		$location=$location.split('/');*/
		
		$url = '/noticias/busqueda/' ;
		$url = $url + $noticia + "/" ;
		document.location = $url;
	}
}

function replace(texto, s1, s2) {
	return texto.split(s1).join(s2);
}

function handleHttpResponse_state() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			document.getElementById('seleccion_prov').innerHTML="";
			document.getElementById('seleccion_prov').innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
		}
        isWorking = false;
	}
}


var isWorking = false;
function select_state(id){
 	if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/select_state.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_state;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}

function ver_comunidad(id){
 	for (i=0; capa = document.getElementsByTagName('div')[i]; i++){
  		id_capa = capa.id;
  		partes = id_capa.split("_");
  		if (partes[0] == "comunity"){
			capa.style.display = "none";
		}
  	}
	nombre = "comunity_" + id;
	document.getElementById(nombre).style.display = ""; 
}

function ver_pais(id){
 	for (i=0; capa = document.getElementsByTagName('div')[i]; i++){
  		id_capa = capa.id;
  		partes = id_capa.split("_");
  		if (partes[0] == "country"){
			capa.style.display = "none";
		}
  	}
	nombre = "country_" + id;
	document.getElementById(nombre).style.display = ""; 
}

function expandir_tipo(id){
	nombrecapa = "type_" + id;
	nombreimagen = "imgtype_" + id;
	if (document.getElementById(nombrecapa).style.display == "none"){
		document.getElementById(nombrecapa).style.display = "";
		document.getElementById(nombreimagen).src = "/templates/default/imgs/ico_menos.gif";
	}else{
		document.getElementById(nombrecapa).style.display = "none";
		document.getElementById(nombreimagen).src = "/templates/default/imgs/ico_cruz.gif";
	}
}

function expandir_sector(id){
	nombrecapa = "sons_" + id;
	nombreimagen = "imgsons_" + id;
	if (document.getElementById(nombrecapa).style.display == "none"){
		document.getElementById(nombrecapa).style.display = "";
		document.getElementById(nombreimagen).src = "/templates/default/imgs/ico_menos.gif";
	}else{
		document.getElementById(nombrecapa).style.display = "none";
		document.getElementById(nombreimagen).src = "/templates/default/imgs/ico_cruz.gif";
	}
}

function ver_redes_sociales(){
 	if (document.getElementById('redes_sociales').style.display == "none"){
		document.getElementById('redes_sociales').style.display = ""; 
	}else{
		document.getElementById('redes_sociales').style.display = "none";
	}
}

function ver_recomendar(){
 	if (document.getElementById('email_amigo').style.display == "none"){
		document.getElementById('email_amigo').style.display = ""; 
	}else{
		document.getElementById('email_amigo').style.display = "none";
	}
}

// Funciona para cargar las actividades segun los tipos

function handleHttpResponse_activity() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			document.getElementById('div_activity').innerHTML="";
			if (document.getElementById('lang')){
				lang = document.getElementById('lang').value;
			}else{
				lang = "";
			}
			if (lang == "1"){
				document.getElementById('div_subactivity').innerHTML="<select id='sub_act' name='sub_act' class='busqueda_directa_interior'><option value='0'> -- Sub Actividad --</option></select>";
			}
			if(lang == "2"){
				document.getElementById('div_subactivity').innerHTML="<select id='sub_act' name='sub_act' class='busqueda_directa_interior'><option value='0'> -- Detail of activities --</option></select>";
			}
			if(lang == "3"){
				document.getElementById('div_subactivity').innerHTML="<select id='sub_act' name='sub_act' class='busqueda_directa_interior'><option value='0'> -- Sub-actividade --</option></select>";
			}
			if (lang == ""){
				document.getElementById('div_subactivity').innerHTML="<select id='sub_act' name='sub_act' class='busqueda_directa_interior'><option value='0'> -- Sub Actividad --</option></select>";
			}
			document.getElementById('div_activity').innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
			color=response.getElementsByTagName('color').item(0).firstChild.data;
			if(color==1){
				document.getElementById('act').style.background="#FFFFC1";
			}
		}
        isWorking = false;
	}
}


var isWorking = false;

function search_activities(id,color){
 	if (id){
		if (document.getElementById('lang')){
			lang = document.getElementById('lang').value;
		}
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/select_activity.php?id="+id+"&color="+color+"&lang="+lang;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_activity;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}
// Fin funcion 

// Funciona para cargar las sub-actividades 

function handleHttpResponse_subactivity() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			document.getElementById('div_subactivity').innerHTML="";
			document.getElementById('div_subactivity').innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
		}
        isWorking = false;
	}
}


var isWorking = false;

function search_sub_activities(id){
 	if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
				if (document.getElementById('lang')){
					lang = document.getElementById('lang').value;
				}
	            var url = "/ajax/select_sub_activity.php?id="+id+"&lang="+lang;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_subactivity;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}
// Fin funcion 

// INTRANET //

//Eliminar empresas favoritas

function eliminar_empresa_favorita(lang,id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar esta empresa de su lista de favoritas?")) {
			$url='/zona_usuario/empresas_favoritas/eliminar/'+id;
			document.location = $url;
		}
	}
}

//Eliminar plantas favoritas

function eliminar_planta_favorita(lang,id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar esta planta de su lista de favoritas?")) {
			$url='/zona_usuario/plantas_favoritas/eliminar/'+id;
			document.location = $url;
		}
	}
}

//Eliminar plantas favoritas

function eliminar_evento_favorito(lang,id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar este evento de su lista de favoritos?")) {
			$url='/zona_usuario/recordatorio_eventos/eliminar/'+id;
			document.location = $url;
		}
	}
}

function eliminar_producto(lang, id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar esta producto?")) {
			$url='/zona_usuario/catalogo_de_productos/eliminar/'+id;
			document.location = $url;
		}
	}
}

function eliminar_noticia(lang, id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar esta noticia?")) {
			$url='/zona_usuario/publicar_nota_de_prensa/eliminar/'+id;
			document.location = $url;
		}
	}
}

function eliminar_evento(lang, id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar este evento?")) {
			$url='/zona_usuario/publicar_evento/eliminar/'+id;
			document.location = $url;
		}
	}
}

function eliminar_promocion(lang, id){
	if(lang == 1){
		if(confirm("¿Está seguro de eliminar esta promocion?")) {
			$url='/zona_usuario/publicar_promocion/eliminar/'+id;
			document.location = $url;
		}
	}
}

function ver_capa_language(prefijo, capa){
 	partes = capa.split("_");
 	idc = partes[1];
	for (i=0; capas = document.getElementsByTagName('div')[i]; i++){
  		id_capa = capas.id;
  		partes = id_capa.split("_");
  		if (partes[0] == prefijo){
			capas.style.display = "none";
		}
  	}
  	document.getElementById(capa).style.display = "";
  	if (idc == "1"){
		document.getElementById("solapa_idioma-1").style.backgroundColor = "#40686D";
		document.getElementById("solapa_idioma-2").style.backgroundColor = "#62993E";
		document.getElementById("solapa_idioma-3").style.backgroundColor = "#62993E";
	}
	if (idc == "2"){
		document.getElementById("solapa_idioma-1").style.backgroundColor = "#62993E";
		document.getElementById("solapa_idioma-2").style.backgroundColor = "#40686D";
		document.getElementById("solapa_idioma-3").style.backgroundColor = "#62993E";
	}
	if (idc == "3"){
		document.getElementById("solapa_idioma-1").style.backgroundColor = "#62993E";
		document.getElementById("solapa_idioma-2").style.backgroundColor = "#62993E";
		document.getElementById("solapa_idioma-3").style.backgroundColor = "#40686D";
	}
}

//Fin eliminar empresas favoritas

/*Funcion que generará una nueva imagen para el Captcha */
function new_captcha(){
	if(document.getElementById){
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;

		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"&"+Math.round(Math.random()*100000);
	}//fin if
}//fin function

function mostrar_envio(cuantos){
 	capa_emails = document.getElementById('emails');
	capa_nombres = document.getElementById('nombres');
	capa_emails.innerHTML = "";
	capa_nombres.innerHTML = "";
	for(i=0;i!=cuantos;i++){
		capa_emails.innerHTML = capa_emails.innerHTML + '<p style="padding-bottom:15px; padding-top:5px;"> <input name="mail['+ i +']" type="text"  class="registro_recomendar" size="46"/></p>';
		capa_nombres.innerHTML = capa_nombres.innerHTML + '<p style="padding-bottom:15px; padding-top:5px;"> <input name="nombre['+ i +']" type="text"  class="registro_recomendar" size="46"/></p>';
	}  
}

function mostrar_categorias_en_promociones(id){
	if (id == 1){
		document.getElementById('bloque_ficha_empresa').style.display = "none";
	}else{
		document.getElementById('bloque_ficha_empresa').style.display = ""; 	
	}
}

function noticias_mas_leidas(){
	document.getElementById('mas_leidas').style.display = "";
	document.getElementById('mas_comentadas').style.display = "none";
	document.getElementById('ultimas_noticias').style.display = "none";
}

function noticias_mas_comentadas(){
	document.getElementById('mas_comentadas').style.display = "";
	document.getElementById('mas_leidas').style.display = "none";
	document.getElementById('ultimas_noticias').style.display = "none";
}

function ultimas_noticias(){
	document.getElementById('ultimas_noticias').style.display = "";
	document.getElementById('mas_leidas').style.display = "none";
	document.getElementById('mas_comentadas').style.display = "none";
}

function quitar_foto_noticias(){
	document.getElementById('foto_cargada').style.display = "none";
	document.getElementById('quitarfoto').value = 1;
}

function handleHttpResponse_state2() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			document.getElementById('div_state2').innerHTML ="";
			document.getElementById('div_state2').innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
		}
        isWorking = false;
	}
}

var isWorking = false;
function ajax_state2(id){
 	if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/ajax_state.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_state2;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}// Funcion

function handleHttpResponse_state() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            var response = http.responseXML;
			document.getElementById('div_state').innerHTML ="";
			document.getElementById('div_state').innerHTML = response.getElementsByTagName('data').item(0).firstChild.data;
		}
        isWorking = false;
	}
}

function formatear_garden(form, ventana){
 	var form;
 	var error = 0;
 	if (form.paisjardin.value == 0){
		alert("ERROR: Debes seleccionar un país");
		error = 1;
	}
	if (form.select_state.value == 0){
		alert("ERROR: Debes seleccionar una provincia");
		error = 1;
	}
	if (error != 1){
	 	url = "/empresas/busqueda/texto/null/ciudad/null/provincia/"+form.select_state.value+"/actividad/centros_de_jardineria/pais/"+form.paisjardin.value;
	 	
		if (ventana == 1){
			window.open(url);
		}else{
			location.href=url;
		}
	}else{
		return 0;
	}
}


var isWorking = false;
function ajax_state(id){
 	if (id){
		if (document.getElementById('lang')){
			lang = document.getElementById('lang').value;
		} 
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/ajax_state.php?id="+id+"&lang="+lang;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_state;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}// Funcion
var isWorking = false;
function event_state(id){
 	if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/event_state.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_state;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}// Funcion

function handleHttpResponse_mail() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}


var isWorking = false;
function reponder_mail(id){
 	if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/mail.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_mail;
	            isWorking = true;
	            http.send(null);
	   }
	}else{
		alert("El parametro recibido no es el correcto, si el problema persiste, pongase en contacto con el administrador del sistema");  
	}
}

function mostrar_info(id){
	nombrecapa = "info-"+id;
	if (document.getElementById(nombrecapa)){
	 	if (document.getElementById(nombrecapa).style.display == "none"){
			document.getElementById(nombrecapa).style.display = "";
		}else{
			document.getElementById(nombrecapa).style.display = "none";
		}
	}
}

function sacar_info_empresa(texto, lang){
	if (document.getElementById('detail').value == ""){
		if (lang == 1){
			alert("No podrá guardar los cambios hasta que haya rellenado el campo descripcion en idioma español (obligatorio). Si no dispone de la traducción, puede rellenarlo con cualquier otro idioma");
		}
		if (lang == 2){
			alert("You can not save the changes until you complete the field 'description' in Spanish (required). If you have no translation, you can fill it with any other language");
		}
		if (lang == 3){
			alert("Não poderá guardar as correcções até ter preenchido o campo 'descriçao' no idioma espanhol (obrigatório). Se não dispõe da tradução, pode preencher em qualquer outro idioma");
		}
		return false;
	}
	if (confirm(texto)){
		return true;
	}else{
		return false;
	}
}

function sacar_info_productos(texto, lang){
	if (document.getElementById('tituloa').value == ""){
		if (lang == 1){
			alert("No podrá guardar los cambios hasta que haya rellenado el campo titulo en idioma español (obligatorio). Si no dispone de la traducción, puede rellenarlo con cualquier otro idioma");
		}
		if (lang == 2){
			alert("You can not save the changes until you complete the field 'title' in Spanish (required). If you have no translation, you can fill it with any other language");
		}
		if (lang == 3){
			alert("Não poderá guardar as correcções até ter preenchido o campo 'titulo' em idioma espanhol (obrigatório). Se não dispõe da tradução, pode preencher em qualquer outro idioma.");
		}
		return false;
	}
	if (document.getElementById('entradillaa').value == ""){
		if (lang == 1){
			alert("No podrá guardar los cambios hasta que haya rellenado el campo entradilla en idioma español (obligatorio). Si no dispone de la traducción, puede rellenarlo con cualquier otro idioma");
		}
		if (lang == 2){
			alert("You can not save the changes until you complete the field 'short intro text' in Spanish (required). If you have no translation, you can fill it with any other language");
		}
		if (lang == 3){
			alert("Não poderá guardar as correcções até ter preenchido o campo 'entrada' em idioma espanhol (obrigatório). Se não dispõe da tradução, pode preencher em qualquer outro idioma.");
		}
		return false;
	}
	if (document.getElementById('sinopsis').value == ""){
		if (lang == 1){
			alert("No podrá guardar los cambios hasta que haya rellenado el campo descripcion en idioma español (obligatorio). Si no dispone de la traducción, puede rellenarlo con cualquier otro idioma");
		}
		if (lang == 2){
			alert("You can not save the changes until you complete the field 'description' in Spanish (required). If you have no translation, you can fill it with any other language");
		}
		if (lang == 3){
			alert("Não poderá guardar as correcções até ter preenchido o campo 'descriçao' no idioma espanhol (obrigatório). Se não dispõe da tradução, pode preencher em qualquer outro idioma");
		}
		return false;
	}
	if (confirm(texto)){
		return true;
	}else{
		return false;
	}
}

function ver_descripcion_empresa(idioma){
	if (idioma == "es"){
		document.getElementById('bandera_en').src = '/files/language/lang_00002_ingles-bn.gif';
		document.getElementById('bandera_pt').src = '/files/language/13092010131458_portugal-bn.gif'; 
		document.getElementById('bandera_es').src = '/files/language/lang_00001_espanol.gif';
		document.getElementById('detail_en').style.display = 'none';
		document.getElementById('detail_pt').style.display = 'none';
		document.getElementById('detail_es').style.display = '';
	}
	if (idioma == "en"){
		document.getElementById('bandera_pt').src = '/files/language/13092010131458_portugal-bn.gif'; 
		document.getElementById('bandera_es').src = '/files/language/lang_00001_espanol-bn.gif';
		document.getElementById('bandera_en').src = '/files/language/lang_00002_ingles.gif';
		document.getElementById('detail_pt').style.display = 'none';
		document.getElementById('detail_es').style.display = 'none';
		document.getElementById('detail_en').style.display = '';
	}
	if (idioma == "pt"){
		document.getElementById('bandera_es').src = '/files/language/lang_00001_espanol-bn.gif';
		document.getElementById('bandera_en').src = '/files/language/lang_00002_ingles-bn.gif';
		document.getElementById('bandera_pt').src = '/files/language/13092010131458_portugal.gif'; 
		document.getElementById('detail_es').style.display = 'none';
		document.getElementById('detail_en').style.display = 'none';
		document.getElementById('detail_pt').style.display = '';
	}
}

function abrir_enviar_amigo(capa){
 	document.getElementById(capa).style.display = "";
}

//Estadisticas

function handleHttpResponse_clickcorreo() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_correo(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_correo.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickcorreo;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickweb() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_web(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_web.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickweb;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickcompartir() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_compartir(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_compartir.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickcompartir;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickcatalogo() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_catalogo(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_catalogo.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickcatalogo;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clicktwitter() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_twitter(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_twitter.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clicktwitter;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickfacebook() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_facebook(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_facebook.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickfacebook;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickyoutube() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_youtube(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_youtube.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickyoutube;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clicklinkedin() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_linkedin(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_linkedin.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clicklinkedin;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickxing() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_xing(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_xing.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickxing;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function handleHttpResponse_clickflickr() {
    if (http.readyState == 4) {
        isWorking = false;
	}
}

var isWorking = false;
function click_en_flickr(id){
		if (id){
		http = new XMLHttpRequest();
	    if (!isWorking && http){
	            var url = "/ajax/stats_flickr.php?id="+id;
	            http.open("GET", url, true);
	            http.onreadystatechange = handleHttpResponse_clickflickr;
	            isWorking = true;
	            http.send(null);
	   }
	}
}// Funcion

function cerrar_enviar_amigo(capa){
	document.getElementById(capa).style.display = "none";
}

function cambiar_ano(action, id, year){
	if (id == ""){
		id = "0";
	}
	location.href = "/zona_usuario/estadisticas/"+action+"/"+id+"/"+year;
	
}
