/*
 *  Funciones Bnamericas.com  (c) 2009
  */

var isIE;
var req;
var names;
var target;
var bloqueResul;
var myAjax;

if(document.getElementById("logo_head"))
	setTimeout("$('logo_head').onclick = function(){location.href='http://www.bnamericas.com'};$('logo_head').style.cursor = 'pointer'",2500);	

function getElementY(element){
      var targetTop = 0;
      if (element.offsetParent) {
      while (element.offsetParent) {
      targetTop += element.offsetTop;
      element = element.offsetParent;
		}
      } else if (element.y) {
      targetTop += element.y;
    }
	return targetTop;
}

function init() {
    target = document.getElementById("complete-field");
}

function initRequest(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function setTab(id){
/*
  if(id == 'emailed'){      
    $('emailed').style.backgroundImage = 'url(images/boton_azul2.gif)';
    $('viewed').style.backgroundImage = 'url(images/boton_celeste2.gif)';    
  }else{
    $('emailed').style.backgroundImage = 'url(images/boton_celeste2.gif)';
    $(id).style.backgroundImage = 'url(images/boton_azul2.gif)';    
  }    
*/
}

function aleatorio(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.round(aleat)
    return parseInt(inferior) + aleat
}

// ----------- COMUNICACION ASINCRONA ----------- 

function callContent(destino,org,param,param2,contenedor,idioma,canalNT,param3) {

	var par = aleatorio(100,10000);

	//news tracker vars
	tmpLstSubTemas = new Array()
	strEdit = false
	tmpLstCompanias = new Array()
	tmpLstCompaniasRel = new Array()

	//alert(destino+org+param+param2+contenedor+idioma);
	sec = 'ajax-'+destino+'-'+contenedor+'_'+idioma;
	var tracking = false; // habilita el trackeo google analytics de la peticion ajax
	//console.log("callContent() is called");
	 
	if(org=="most"){var url = "most_content.jsp?most=" + escape(destino) +"&idioma="+idioma; setTab(destino);}
	if(org=="values"){var url = "/historical_data_content.jsp?tipo=" + escape(destino) + "&indicador=" + escape(param) + "&nombre_periodo=" + escape(param2)+"&idioma="+idioma+"&par="+par}
	if(org=="valuesNew"){var url = "/historical_data_content.jsp?tipo=" + escape(destino) + "&indicador=" + escape(param) + "&periodo=" + escape(param2)+"&idioma="+idioma+"&estado="+param3}
	if(org=="member"){
		var url = "/member_preferences_content.jsp?accion=" + escape(destino)+"&idioma="+idioma+"&par="+par+"&addPais="+param3;
		mpTabs = $$('#memberPreHead a');
		for(i=1;i<=mpTabs.length;i++){$('op'+i).style.backgroundImage = 'url(images/tabPreferencesOff.gif)';}
		$('op'+destino).style.backgroundImage = 'url(images/tabPreferencesOn.gif)';
		if(destino==1)sec='/MP-CambieContraseña_'+idioma;
		if(destino==2)sec='/MP-ActualizePerfil_'+idioma;
		if(destino==3)sec='/MP-IdiomaPreferencia_'+idioma;
		if(destino==4)sec='/MP-FormatoEmail_'+idioma;
		if(destino==5)sec='/MP-Boletines_'+idioma;
		if(destino==6)sec='/MP-NewsTrackers_'+idioma;
	}
	if(org=="is"){var url = "/intelligence_series_seleccion.jsp?accion=" + escape(destino)+"&idioma="+idioma+"&id_documento="+param+"&sector="+param2}

	//alert(url);

    initRequest(url);
    //req.onreadystatechange = processRequest;
    req.onreadystatechange = function(){
                                        DivVar = document.getElementById(contenedor);
                                        if (req.readyState == 4) {
                                            if (req.status == 200) {
												DivVar.innerHTML = req.responseText;
												if(tracking) urchinTracker(sec);
												//if(canalNT!="0"){nt_next(1,idioma,canalNT)};
                                            }
                                        }
                             }
    req.open("GET", url, true);
    req.send(null);
}

function processRequest(contenedor) {
    DivVar = document.getElementById('centro2_c');
    if (req.readyState == 4) {
        if (req.status == 200) {
          DivVar.innerHTML = req.responseText;
        } 
    }
}

 //enviar formulario 
function enviarFormulario(url, formid){
    var Formulario = document.getElementById(formid);
    var longitudFormulario = Formulario.elements.length;
    var cadenaFormulario = ""
    var sepCampos
    sepCampos = ""
    for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
    }
    peticion.open("POST", url, true);
    peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
    peticion.onreadystatechange = function () {
                                    if (peticion.readyState == 4) {
                                       document.getElementById('Ficha').innerHTML = "Los datos han sido enviados correctamente";
                                    }
                                  }
    peticion.send(cadenaFormulario);
}

//enviar formulario con prototype   -------------
function protoSend(){
    var params = Form.serialize($('formulario'));
    var save = $('save').value;
    var url;
    var destino;

    if(save=='S3'){
       url = "servlets/ajaxpreferredlanguage";
       destino = "memberPreBody";//"resultadoMemberPre";
       bloqueResul = 'resultadoTransaccion';
    }
    if(save=='FP'){
       url = "/servlets/ajaxforgotpassword";
       destino = 'MensajeForgotPassword';
       bloqueResul = 'MensajeForgotPassword';
    }
    if(save=='MP'){
       url = "servlets/ajaxmediapartner";
       destino = "contenido_editor";
       bloqueResul = 'resultadoTransaccion';
    }
    if(save != 'S3' && save != 'FP' && save != 'MP'){
       url = "member_preferences_save.jsp";
       destino = "memberPreBody";
    }
    
    myAjax = new Ajax.Updater(destino, url, {method: 'post', asynchronous:true, parameters:params,
    onComplete:function(resul){accionResul(bloqueResul,resul);}
    });

    /*
    new Ajax.Request(url, {method: 'post', asynchronous:true, parameters:params,
    onSuccess: function(resp) {
           var message = resp.responseXML.getElementsByTagName("resultado")[0].childNodes[0].nodeValue;
           console.log("mensaje="+message);                  
         }    
    });    */
    
     if(save=='S3'){
      //var message = resp.responseXML.getElementsByTagName("resultado")[0].childNodes[0].nodeValue;
      //console.log("mensaje="+message);
    }
}

function accionResul(bloqueResul,resul){

  var resultStr = resul.responseText;
  resultStr = resultStr.replace(/^\s*|\s*$/g,"");
  
  response = resul.responseText.evalJSON();
  strEstado = response.resultado
  StrLogin = response.login
  StrEmail = response.email
  var strCriterio
  if(document.getElementById("idioma").value=='I')
	if(StrLogin=="") strCriterio = 'e-mail address'; else strCriterio = 'username';
  else
	if(StrLogin=="") strCriterio = 'e-mail'; else strCriterio = 'usuario';
  
  if ( bloqueResul == 'MensajeForgotPassword') {
	  var mensaje="";
	  
	  if(strEstado == '4'){
			if((document.getElementById("idioma").value)=='I'){
				paramPath = "/images/english/";
				mensaje="\
						<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>close X</span>\
						<h1>Forgot your Password</h1>\
						<p>You will receive an email with your correct Username and Password. If you have any questions, please call Customer Service on 56-2 9410300 or email us at:<a href='mailto:info@BNamericas.com'> info@BNamericas.com</a></p>";
			}else{ 
				paramPath = "/images/spanish/";
				mensaje="\
						<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>cerrar X</span>\
						<h1>Solicitud de Clave</h1>\
						<p>Recibirá un correo electrónico con su clave y nombre de usuario correctos. Si tiene alguna inquietud, s&iacute;rvase llamar al Servicio al Cliente al número 56-2 9410300 o bien env&iacute;enos un correo electrónico a: <a href='mailto:info@BNamericas.com'> info@BNamericas.com.</a></p>";
			}
		}

		if(strEstado == '0' || strEstado == '2'){

			if((document.getElementById("idioma").value)=='I'){
				paramPath = "/images/english/";
				mensaje="<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>close X</span>\
					     <h2 style='color:#fff;margin-top:30px'>This "+strCriterio+" is not registered.</h2>\
					     <p style='text-align:center;text-decoration:underline'><a href='/freetrial_1.jsp?idioma=I&sector=0'>Register to begin your free trial</a></p>";
			}else{
				paramPath = "/images/spanish/";
				mensaje="<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>cerrar X</span>\
					     <h2 style='color:#fff;margin-top:25%'>Este "+strCriterio+" no se encuentra registrado.</h2>\
					     <p style='text-align:center;text-decoration:underline'><a href='/freetrial_1.jsp?idioma=E&sector=0'>Reg&iacute;strese para tomar una prueba gratis</a></p>";
			}
		}
		
		if(strEstado == '1'){
			if((document.getElementById("idioma").value)=='I'){
				paramPath = "/images/english/";
				mensaje="<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>close X</span>\
					     <h2 style='color:#fff'>Your account is inactive</h2>\
					     <p style='margin-bottom:20px'>Your must confirm your e-mail adress first. Check your e-mail to find the validation message.</p>\
						 <h2 style='color:#fff'>Resend Validation e-mail</h2>\
						 <p>If you have not received an email from BNamericas with the link to validate your email address, you may resend clicking the button below.</p>\
						 <span onclick='javascript:fp_resend_p(\""+StrLogin+"\",\""+StrEmail+"\")' style='margin:30px 80px 10px;display:block;background-color:#AEB404;padding:3px 0;cursor:pointer;padding:3px 0'>Resend Validation E-mail</span>";
			}else{
				paramPath = "/images/spanish/";
				mensaje="<span class='cerrar_solicitudClave' onclick='javascript:Dialog.cancelCallback()'>cerrar X</span>\
					     <h2 style='color:#fff'>Su cuenta está inactiva</h2>\
					     <p style='margin-bottom:20px'>Ud. debe confirmar su dirección de e-mail primero. Revise su correo y encuentre el mensaje de validación</p>\
						 <h2 style='color:#fff'>Reenv&iacute;o de e-mail de validación</h2>\
						 <p>Si Ud. no ha recibido un e-mail de BNamericas con el enlace para validar su dirección de e-mail, puede solicitar reenv&iacute;o haciendo clic en el siguiente botón:</p>\
						 <span onclick='javascript:fp_resend_p(\""+StrLogin+"\",\""+StrEmail+"\")' style='margin:30px 80px 10px;display:block;background-color:#AEB404;padding:3px 0;cursor:pointer;padding:3px 0'>Reenviar E-mail de Validación</span>";
			}
		}
		
        var eleNew=document.getElementById('cont_solClave');
        eleNew.innerHTML = mensaje;
  }
   
  //$(bloqueResul).style.display='block;';
  document.getElementById('cont_solClave').style.display='block;';
  $('formulario').reset();
  
}

function fp_resend_p(login, email){
	url = "/servlets/ajaxresendemailactivation";
	params = "login="+login+"&email="+email;
	myAjax = new Ajax.Updater('cont_solClave', url, {method: 'post', asynchronous:true, parameters:params,onComplete:function(resul){
		//console.log(resul.responseText);
		if(parseInt(resul.responseText) == 0){		
		    if((document.getElementById("idioma").value)=='I'){
				//console.log('I');
				$('cont_solClave').innerHTML = '<span class="cerrar_solicitudClave" onclick="javascript:Dialog.cancelCallback()">close X</span><h3 style="text-align:center;margin:20px 0;color:#FFF">The email was sent.</h3>';
			}
			else{
				$('cont_solClave').innerHTML = '<span class="cerrar_solicitudClave" onclick="javascript:Dialog.cancelCallback()">cerrar X</span><h3 style="text-align:center;margin:20px 0;color:#FFF">El email fue enviado.</h3>';
			}
		}
		else{
			$('cont_solClave').innerHTML = '<h3 style="text-align:center;margin:20px 0">Error.</h3>';
		}
	
	}});
	//console.log('login:'+login+' - email:'+email)
    
}


function Muestra(){



}
// ---------------------- 
  
  
// ----------------------

function alternaImg(destino){

    document.getElementById("most_emailed_home").style.BackgroundImage="url(/imagenes/boton_celeste.jpg)";
    document.getElementById("most_searched_home").style.BackgroundImage="url(/imagenes/boton_celeste.jpg)";
    document.getElementById("most_viewed_home").style.BackgroundImage="url(/imagenes/boton_celeste.jpg)";

    if(destino=='emailed'){document.getElementById("most_emailed_home").style.backgroundImage="url(/imagenes/boton_azul.jpg)";}     
    if(destino=='searched'){document.getElementById("most_searched_home").style.backgroundImage="url(/imagenes/boton_azul.jpg)";}     
    if(destino=='viewed'){document.getElementById("most_viewed_home").style.backgroundImage="url(/imagenes/boton_azul.jpg)";}    

}

function confirma(tipo){

  nombre = "";//document.getElementById("txtCompaniaNombre").value;
  fecha_ant ="";
  fecha = "";
  
  if(document.getElementById("der"))
     document.getElementById("der").style.visibility="hidden";

  if(document.getElementById("publi1"))
     document.getElementById("publi1").style.visibility="hidden";
     
  if(document.getElementById("frameResearch"))
     document.getElementById("frameResearch").style.visibility="hidden";     
	 
  if(document.getElementById("trial_center"))	 
     document.getElementById("trial_center").style.visibility="hidden";

  $$('.colder div').each(function(f) {f.style.visibility = 'hidden' });
  
  if(tipo=='directline'){
  var ancho=350;
  
  if((document.getElementById("idioma").value)=='I'){
    paramPath = "/images/english/";
    texto0 = "Thank you. You message was sent and we will be in touch immediately.";
    texto1 = "Direct Line";
    texto2 = "Editorial content";
    texto3 = "Technical Support";
    texto4 = "Customer Service";
    texto5 = "Advertising Opportunities";
    texto6 = "Please type your message here. If required, a BNamericas' representative will contact you shortly.";
    texto7 = "Please Select Topic";
    texto8 = "close";
  }
  else{ 
    paramPath = "/images/spanish/";
    texto0 = "Gracias. Su mensaje ha sido enviado y nos pondremos en contacto a la brevedad";
    texto1 = "Linea Directa";
    texto2 = "Contenidos editoriales";
    texto3 = "Soporte técnico";
    texto4 = "Servicio al cliente";
    texto5 = "Publicidad en BNamericas";
    texto6 = "Por favor escriba aqu&iacute; su mensaje. De ser necesario, un representante de BNamericas se comunicará con usted a la brevedad.";
    texto7 = "Por favor seleccione";
    texto8 = "cerrar";
  }  
  
  var mensaje="\
  <form id='direct' name='direct' method='post' action='linea_directa.jsp'>\
     <input type='hidden' name='idioma' value='I'>\
     <input type='hidden' name='id_area' value=''>\
     <input type='hidden' name='login' value=''>\
     <input type='hidden' name='Action'>\
     <input type='hidden' name='resp' value='"+texto0+"'>\
     <div id='direct_line'>\
        <div id='direct_h'>\
           <h3 class='titulo_popUp1'>"+texto1+"</h3><span><a class='close_windows' href='#a' onclick='javascript:Dialog.cancelCallback()'>"+texto8+" X</a></span>\
        <\/div>\
        <div id='direct_c'>\
           <ul class='list_direct'>\
              <li><p>"+texto7+"<\/p><\/li>\
              <li><input type='radio' name='radArea' id='radSubs1' value='0'\/><label class='radio_direct' for='radSubs1'>"+texto2+"<\/label><\/li>\
              <li><input type='radio' name='radArea' id='radSubs2' value='0'\/><label class='radio_direct' for='radSubs2'>"+texto3+"<\/label><\/li>\
              <li><input type='radio' name='radArea' id='radSubs3' value='0'\/><label class='radio_direct' for='radSubs3'>"+texto4+"<\/label><\/li>\
              <li><input type='radio' name='radArea' id='radSubs4' value='0'\/><label class='radio_direct' for='radSubs4'>"+texto5+"<\/label><\/li>\
           <\/ul>\
           <textarea id='mensaje_texto' name='mensaje_texto' cols='25' rows='2' class='text_area_direct' onFocus='javascript:SetTexto(1,\""+texto6+"\");' onBlur='javascript:SetTexto(0,\""+texto6+"\");'>"+texto6+"<\/textarea>\
           <p><a href='javascript:valida_linea_directa()'><img class='bot_buscar3' src='"+paramPath+"submit.gif' border='0'\/><\/a><\/p>\
        <\/div>\
     <\/div>\
  <\/form>\
";  
}
if(tipo=='logintrial'){
  var ancho=831;
  
  if((document.getElementById("idioma").value)=='I'){
    paramPath = "/images/english/";
    estilo='I';
    texto0 = "Receive original daily news via BNamericas's customer e-mail service.";
    texto1 = "Access to 4,000 continuously updated Company Profiles." ;
    texto2 = "Search 11-year content library and Research Center.";
    texto3 = "Stay informed with our Regional Event Calendar by industry sector.";
    texto4 = "Remember my ID on this computer";
    texto5 = "Forgot your password?";
    texto6 = "Free Trial ended?";
    texto7 = "<a href='#'>Ask for your subscription<\/a>";
    texto8 = "Contact Us";
    texto9 = "If you have any question or need aditional information, <a href='#'>please write to us</a>";
    texto10 = "Login subscribers";
  }
  else{ 
    paramPath = "/images/spanish/";
    estilo='E';
    texto0 = "Reciba diariamente nuestras noticias por e-mail para clientes de BNamericas.";
    texto1 = "Acceda a 4.000 Perfiles de Empresas actualizados continuamente.";
    texto2 = "Busque en nuestro Archivo y Centro de Informes, con más de 11 años de contenidos.";
    texto3 = "Mántengase al d&iacute;a con la Agenda de Eventos regionales, categorizada por industrias.";
    texto4 = "Recuerde mi ID en mi computador";
    texto5 = "¿Olvidó su clave?";
    texto6 = "¿Ya finalizó su periodo de prueba gratis?";
    texto7 = "Entonces, <a href='#'>solicite su suscripción aqu&iacute;<\/a>";
    texto8 = "Contáctenos";
    texto9 = "Si tiene cualquier pregunta o quiere recibir información adicional sobre nuestros servicios, por <a href='#'>favor escr&iacute;banos<\/a> o llámenos.";
    texto10 = "Ingreso de suscriptores";    
  }    
  
  var mensaje="\
  <div id='cont_suscrip_"+estilo+"'>\
     <div id='suscrip_lateral_izq'>\
        <a href='http://www.bnamericas.com/freetrial.jsp?idioma="+document.getElementById("idioma").value+"'><img class='bot_buscar2'src='"+paramPath+"comiense_prueba.gif' border='0'\/><\/a>\
	<ul class='list_suscrip'>\
	   <li>"+texto0+"<\/li>\
	   <li>"+texto1+"<\/li>\
	   <li>"+texto2+"<\/li>\
	   <li>"+texto3+"<\/li>\
	<\/ul>\
        <a class='close_windows2' href='#a'><img src='"+paramPath+"cerrar.gif' border='0' onclick='javascript:Dialog.cancelCallback()'></a>\
     <\/div>\
     <div id='suscrip_lateral_der'>\
          <h3>"+texto10+"<\/h3>\
 	  <div id='line_log_suscrip'>\
             <span class='txt_linaLogin_solClave'>Username: <\/span>\
             <input class='b_suscrip' name='login2' id='login2' type='text'\/>\
          <\/div>\
          <div id='line_log_suscrip'>\
             <span class='txt_linaLogin_solClave'>Password: <\/span>\
             <input class='b_suscrip' name='password2' id='password2' type='password'\/>\
          <\/div>\
          <img onclick='javascript:sendLogin_pop();' class='log_sus' src='/images/english/bot_login.gif' border='0' style='cursor:pointer'>\
          <div id='chk_sus'>\
	     <label class='head_texto1' for='chk_news2'>\
	     <input id='chk_news2' name='ca' value='' class='texto_checkbox' border='0' type='checkbox'\/>"+texto4+"<\/label>\
          <\/div>\
	  <p><a class='link_sus' href='/forgot_password.jsp?idioma="+document.getElementById("idioma").value+"'>"+texto5+"<\/a><\/p>\
	  <ul class='list_lat_izq_sus'>\
	     <li class='sus1'><span class='tit_list_sus'>"+texto6+"<\/span><br \/> "+texto7+"<\/li>\
	     <li class='sus2'><span class='tit_list_sus'>"+texto8+"<\/span><br \/>"+texto9+"<\/li>\
	     <li class='sus3'>USA Fono/Fax: (800) 535-2137 Santiago, Chile: +56 (2) 941-0300 info@BNAmericas.com<\/li>\
	  <\/ul>\
     <\/div>\
   <\/div>\
";
}

if(tipo=='forgotPass'){
  var ancho=353;
  var texto0, texto1, texto2, texto3, texto4, texto5;
  
  if((document.getElementById("idioma").value)=='I'){
    paramPath = "/images/english/";
    texto0 = "Forgot your Password";
    texto1 = "Please enter the username or e-mail address you registered with. Your account information will be e-mailed to you shortly." ;
    texto2 = "Enter Username";
    texto3 = "or Enter E-mail address";
    texto4 = "Click to contact <a href='mailto:info@bnamericas.com' class='linknoticia'>BNamericas Customer Service Center</a>";
    texto5 = "You will receive an email with your correct Username and Password. If you have any questions, please call Customer Service on 56-2 9410300 or email us at:<a href='mailto:info@BNamericas.com'> info@BNamericas.com</a>"; 
    texto6 = "close"; 
  }
  else{ 
    paramPath = "/images/spanish/";
    texto0 = "Solicitud de Clave";
    texto1 = "Por favor ingrese el nombre de usuario o la dirección de correo electrónico con la que se registró. La información de su cuenta le será enviada via email a la brevedad";
    texto2 = "Usuario login";
    texto3 = "o ingrese dirección E-mail";
    texto4 = "Haga clic para contactar a <a href='mailto:info@bnamericas.com' class='linknoticia'>Servicio al cliente</a>";
    texto5 = "Recibirá un correo electrónico con su clave y nombre de usuario correctos. Si tiene alguna inquietud, s&iacute;rvase llamar al Servicio al Cliente al número 56-2 9410300 o bien env&iacute;enos un correo electrónico a: <a href='mailto:info@BNamericas.com'> info@BNamericas.com.</a>";
    texto6 = "cerrar"; 
  }
  
  var mensaje="\
  <div id='MensajeForgotPassword' style='display:none'>\
  </div>\
  <div id='cont_solClave'>\
    <span class='cerrar_solicitudClave'><a class='cerrarLink' href='#a' onclick='javascript:Dialog.cancelCallback()'>"+texto6+" X</a></span>\
    <form id='formulario' name='formulario' method='POST'>\
      <input type='hidden' name='idioma' value='"+document.getElementById("idioma").value+"'/>\
      <input type='hidden' name='accion' value='{/page/XSLparameters/accion}'/>\
      <input type='hidden' name='save' id='save' value=''/>\
      <h1>"+texto0+"</h1>\
      <p>"+texto1+"</p>\
      <div id='line_log_solClave'>\
        <span class='txt_linaLogin_solClave'>"+texto2+"</span>\
	<input class='b_solClave' name='txt_user' type='text'/>\
      </div>\
      <div id='line_log_solClave'>\
        <span class='txt_linaLogin_solClave'>"+texto3+"</span>\
	<input class='b_solClave' name='txt_email' type='text'/>\
      </div>\
      <div id='line_log_solClave'>\
        <a href='javascript:checkform_forgot_password()'><img class='bot_buscar' src='"+paramPath+"enviar_fondoAzul.gif' border='0'/></a>\
      </div>\
      <p>"+texto4+"</p>\
    </form>\
  </div>\
  ";
}


  Dialog.confirm(mensaje, 
                  {width:ancho, okLabel: "Enviar", cancelLabel: "Close",
                   buttonClass: "myButtonClass",
                   id: "myDialogId",
                   cancel:function(win){cancelar();return false;},
                   ok:function(win){valida_msg_directline(); return true;}
                  });
}

function cancelar(){

   if(document.getElementById("der"))
      document.getElementById("der").style.visibility="visible"

   if(document.getElementById("publi1"))
      document.getElementById("publi1").style.visibility="visible"
      
   if(document.getElementById("frameResearch"))
      document.getElementById("frameResearch").style.visibility="visible";    

   if(document.getElementById("trial_center"))	 
     document.getElementById("trial_center").style.visibility="visible";

   $$('.colder div').each(function(f) {f.style.visibility = 'visible' });

}

/*
if (navigator.appName == 'Netscape'){ 
     document.captureEvents(Event.KEYPRESS); 
} 
document.onkeypress = KeyPress;
		
function KeyPress(e){ 
  if (navigator.appName == 'Netscape'){ 
    if(e.which == 13){
        sendLogin();
    }
  } 
  if (navigator.appName == 'Microsoft Internet Explorer'){ 
    if(window.event.keyCode == 13){
        sendLogin();
    }
  }
} 
*/

function sendLogin_pop(){

   if(document.getElementById('login')){
   
        
        document.getElementById('login').value    =  document.getElementById('login2').value;
        document.getElementById('password').value =  document.getElementById('password2').value;
	sendLogin();	
   }
}

function factfileMenu(tab){
/*
 for(var i=1;i<=9;i++){
  if(document.getElementById('CompanyCont'+i)){
   if(tab==i)
      document.getElementById('CompanyCont'+i).style.display="block";
    else
      document.getElementById('CompanyCont'+i).style.display="none";
  }
 }
*/

 for(var i=1;i<=9;i++){
  if(document.getElementById('Factfile'+i)){
   if(tab==i)
      document.getElementById('Factfile'+i).style.display="block";
    else
      document.getElementById('Factfile'+i).style.display="none";
  }
 }
}

function factfilePrinter(){

 for(var i=1;i<=9;i++){
  if(document.getElementById('CompanyCont'+i)){
      document.getElementById('CompanyCont'+i).style.display="block";
  }
 }
}

function SetTexto(param,texto){

     if(param==1){
        if(document.getElementById("mensaje_texto").value==texto){
           document.getElementById("mensaje_texto").value="";
        }
     }
     if(param==0){
        if(document.getElementById("mensaje_texto").value==""){
           document.getElementById("mensaje_texto").value=texto;
           
        }
     }     

}

function valida_linea_directa()	{

	if ((document.direct.radArea[0].checked) || (document.direct.radArea[1].checked)  ||  (document.direct.radArea[2].checked)  || (document.direct.radArea[3].checked)) {
		if (document.direct.radArea[0].checked) 
			document.direct.id_area.value = 1;
		if (document.direct.radArea[1].checked)  
			document.direct.id_area.value = 2;
		if (document.direct.radArea[2].checked) 
			document.direct.id_area.value = 3;
		if (document.direct.radArea[3].checked) 
			document.direct.id_area.value = 4;

		if (document.direct.mensaje_texto.value != "" &&
                    document.direct.mensaje_texto.value!="Please type your message here. If required, a BNamericas' representative will contact you shortly." &&
                    document.direct.mensaje_texto.value!="Please type your message here. If required, a BNamericas' representative will contact you shortly."){
			document.direct.Action.value = 'save';
                        document.direct.login.value = strLogin;                        
                        //alert("mensaje:"+document.direct.mensaje_texto.value+" - login:"+document.direct.login.value);
                        protoSend2();
			//document.direct.submit()
		}
		else{	
			alert("Enter message");
			document.direct.mensaje_texto.focus();
		}
	}
	else
	{
		alert("Please, select topic");
	}
}

function protoSend2(){
    var params = Form.serialize($('direct'));
    new Ajax.Updater('direct_c', 'direct_line_save.jsp', {method: 'post', asynchronous:true, parameters:params});
}

//Story tool -----------------------------------

function openwinemailtofriend(filename){
        window.open(filename, "", "menunbar=no,toolbar=no,left=50,top=100,width=500,height=420,resizable=no,scrollbars=yes");
}

function openwinprintfriendly(filename){
        window.open(filename, "", "menunbar=no,toolbar=yes,scrollbars=yes,left=10,top=1,width=700,height=600,resizable=yes,scrollbars=yes");
}

function agendaroutlook(id){
    //alert(id+' '+document.buscar.stringParam.value);
    document.getElementById("stringParam").value = eval('document.getElementById("SPC_Par_"+id).value');
    var action = document.getElementById('formulario').action;
    document.getElementById('formulario').action = "http://www.bnamericas.com/cgi-bin/agenda";
    document.getElementById('formulario').submit();
    document.getElementById('formulario').action = action;
}   

function isEmail (s){
    if (isEmpty(s)) 
     if (isEmail.arguments.length == 1) return defaultEmptyOK;
     else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    {
		i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    {
		i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

//Forgot Password

function checkform_forgot_password(){
var frm = document.formulario;
id_valida = true;

	if (frm.txt_user.value =="" && frm.txt_email.value ==""){
		if(frm.idioma.value=='E'){
			alert ( "Por favor, ingrese Nombre de usuario o E-mail." );
		}
		else{
			alert ( "Please, input Username or E-mail address." );
		}	
		frm.txt_user.focus ();
		id_valida = false;
	}

	if (id_valida){
		//frm.save.value = 'FP'
                document.getElementById("save").value = "FP";
                protoSend();
		//frm.action = "forgot_password.jsp"
		//frm.submit()
	}
}

function goPosgradoSector(){
  location.href = 'postgrados_sector_home.jsp?sector='+$('sectores').value+'&idioma='+$('idioma').value;
}

function goConfsector(){
    location.href = 'conferences_home.jsp?sector='+$('sectores').value+'&idioma='+$('idioma').value;
}    

function load(){

       document.getElementById("loading").style.display="none";

}

function btnActivoMost(id){

    document.getElementById(id).style.backgroundImage = 'url(images/boton_azul2.gif)';
    
    if(id!='viewed')
        document.getElementById('viewed').style.backgroundImage = 'url(images/boton_celeste2.gif)'
    
    if(id!='emailed')
        document.getElementById('emailed').style.backgroundImage = 'url(images/boton_celeste2.gif)'    
}

function tabActivo(tab){

    for(i=1;i<=3;i++){
       i==tab ? $("tab"+tab).style.backgroundImage = "url(/images/boton_azul.gif)" : $("tab"+i).style.backgroundImage = "url(/images/boton_celeste.gif)";
    }

}

function urljump(doc, idioma, sector){

  document.getElementById("loginUrlJump").value= "/story.jsp$SEP$idioma$EQ$"+idioma+"$AMP$sector$EQ$"+sector+"$AMP$noticia$EQ$"+doc;

}

function loadTab(){      
      
      callContent('oil','valuesNew','P_IPE','5DIAS','centro1_c',document.getElementById('strIdioma').value,'','1');      
      tabActivo(2);
/*  
      
      myitem = document.getElementById("contenedor");
      alto = myitem.offsetHeight;
      
      document.getElementById("sombra_left").style.height=(alto-90)+"px";
      document.getElementById("sombra_right").style.height=(alto-90)+"px";

      if (screen.width == 1280)
      {
         document.getElementById("sombra_left").style.left = "108px";
         document.getElementById("sombra_right").style.left = "1132px";
      }

*/
   
}

function openIndicators(filename){
	window.open(filename, "", "menunbar=no,toolbar=no,left=50,top=100,width=400,height=450,resizable=no");
}

function openIndicators2(filename){
	window.open(filename, "", "menunbar=no,toolbar=no,left=50,top=100,width=400,height=550,resizable=yes,scrollbars=yes");
}

function Formato( strValue, stridioma ) {
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');
    while(objRegExp.test(strValue)) {
       if (stridioma == 'I'){ 
          strValue = strValue.replace(objRegExp, '$1,$2');
       } else {
          strValue = strValue.replace(objRegExp, '$1.$2');
       }
    }
	  return strValue;
}

function moreCompany(bloque,bloqueImg,num){

   if(num==0)num=''

   if($(bloque).style.display=='none'){
      $(bloque).style.display='block';
      $(bloqueImg).style.backgroundImage='url(images/close'+num+'.gif)';            
   }
   else{
      $(bloque).style.display='none';
      $(bloqueImg).style.backgroundImage='url(images/open'+num+'.gif)';
   }

}

function colapsa(bloque){

   if($(bloque).style.display=='none'){
    $(bloque).style.display='block';
    if($("img_"+bloque)) $("img_"+bloque).src='/images/expandir.gif';
    if(bloque=="blok_compartir") $("block_compartir_padre").className='comp_story2';
    if(bloque=="caja_verMas"){$("btnVerMas").style.background='transparent url(/images/ver_mas_icon02.gif) no-repeat scroll left center';}

   }else{
    $(bloque).style.display='none';
    if($("img_"+bloque)) $("img_"+bloque).src='/images/colapso.gif';
    if(bloque=="blok_compartir") $("block_compartir_padre").className='comp_story';
    if(bloque=="caja_verMas") $("btnVerMas").style.background='transparent url(/images/ver_mas_icon.gif) no-repeat scroll left center';	

   }

}

function closeInfo(imagen,bloque){

   if($(bloque).style.display=='block'){
    $(imagen).style.background='transparent url(/images/colapso.gif) no-repeat scroll left center';
    $(bloque).style.display='none';

   }else{
    $(imagen).style.background='transparent url(/images/expandir.gif) no-repeat scroll left center';
    $(bloque).style.display='block';

   }

}

function NotRel(destino,compania,idioma,not_actual){

    if($(destino).style.display=='block'){
        url='/compania_not_rel.jsp';
        params='documento='+compania+'&idioma='+idioma+'&not_actual='+not_actual;

        myAjax = new Ajax.Updater(destino, url, {method: 'post', asynchronous:true, parameters:params,
        onComplete:function(){/*accionResul(bloqueResul);*/}
        });
    }
    
}   

function colapsa_login(bloque_display, bloque_hidden){

	if($(bloque_display).style.display=='none'){
		$(bloque_display).style.display='block';
		if("bloque_hidden"!='')
			$(bloque_hidden).style.display='none';
	}else{
		$(bloque_display).style.display='none';
		if("bloque_hidden"!='')
			$(bloque_hidden).style.display='display';
	}
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1){
				end = document.cookie.length;
			}
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function popunder(page){
	if (get_cookie('bnapopunder')==''){
		loadpopunder(page)
		document.cookie="bnapopunder=1"
	}else{
		if(get_cookie('bnapopunder') < 3){
			loadpopunder(page)
			document.cookie="bnapopunder="+(parseInt(get_cookie('bnapopunder'))+1)
		}
	}
}

function loadpopunder(page){
	var ancho = screen.width
	var alto = screen.height
	var windowprops = "width="+ancho+",height="+alto+",location=1,menubar=1,toolbar=1,scrollbars=1,resizable=1,directories=1"
	var win_pop = window.open(page,"BnamericasStat",windowprops)
	win_pop.blur()
	window.focus()
}

function bnaMsge(page){
	if (get_cookie('bnamsgein')==''){
		loadmsge(page)
		document.cookie="bnamsgein=1"
	}else{
		if(get_cookie('bnamsgein') < 1){
			loadmsge(page)
			document.cookie="bnamsgein="+(parseInt(get_cookie('bnamsgein'))+1)
		}
	}
}

function loadmsge(page){
	setTimeout('ocultaPubli(0)',1600);
	$('strIdioma').value=="E" ? imgpop = "pop_bna_esp.gif" : imgpop = "pop_bna_ing.gif";
	mensaje="<img height=\"689\" border=\"0\" width=\"609\" style=\"cursor:pointer\" src=\"images/"+imgpop+"\" onclick='javascript:Dialog.cancelCallback()'/>";
	Dialog.confirm(mensaje,
                  {width:'609', okLabel: "Enviar", cancelLabel: "Close",
                   buttonClass: "myButtonClass",
                   id: "myDialogId",
                   cancel:function(win){ocultaPubli(1);return false;},
                   ok:function(win){return true;}
                  });
}

function ocultaPubli(op){
	if (op==1){
		if (document.getElementById('publi1')) $('publi1').style.visibility="visible";
		if (document.getElementById('publi2')) $('publi2').style.visibility="visible";
		if (document.getElementById('publi3')) $('publi3').style.visibility="visible"
	}else{
		if (document.getElementById('publi1')) $('publi1').style.visibility="hidden";
		if (document.getElementById('publi2')) $('publi2').style.visibility="hidden";
		if (document.getElementById('publi3')) $('publi3').style.visibility="hidden";
	}
}

/* Link sitio stats */
window.onload=function(){
	var stats_links = document.getElementsByTagName("a");
	for (var a = 0; a < stats_links.length; a++) {
		if (stats_links[a].name=="telecomstats") stats_links[a].onclick = function() {
			document.formStats.submit();
			return false;
		}
	}
}