
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

function loadFilters(){

	var printArray = function (x) {
			var paises = $("str"+x).value;
			var pais_array=paises.split(",");
			$$('#items-'+x+' input').each(function(item) {
				pais_array.each(function(item2) {
					if(item.value==item2){
                                               // alert("item.value:"+item.value+" - item2"+item2)
						$(x+item2).checked = true
						$$('#li-'+x+item2+' span').each(function(elemento){elemento.style.fontWeight = "bold"});			
						//$$('#li-pais'+item2+' img').each(function(elemento){elemento.src = "img/checkbox_act.png"});			
					}
				});
			});
			
	}

	var filtros=['pais','ano'];
	filtros.forEach(printArray);	
	
}


function filtersAct(filtro,idfiltro){
    
    $(filtro+idfiltro).checked == false ? $(filtro+idfiltro).checked = true : $(filtro+idfiltro).checked = false
    $$('#li-'+filtro+idfiltro+' span').each(function(elemento){elemento.style.fontWeight = "bold"});			
   // $$('#li-pais'+idfiltro+' img').each(function(elemento){elemento.src = "img/checkbox_act.png"});			
	
    $("str"+filtro).value = "0"
    $$('#items-'+filtro+' input').each(function(item) {
		if(item.checked == true)
			$("str"+filtro).value == "" || $("str"+filtro).value == "0" ? $("str"+filtro).value = item.value : $("str"+filtro).value = $("str"+filtro).value+","+item.value
			//console.log(item.id+":"+item.value+" "+item.checked);
    });

    /*console.log("str:"+$('str'+filtro).value);
    console.log("---------------------------------------");*/

    location.href = "/store/index.jsp?idioma="+$("idioma").value+"&sector="+$("sector").value+"&tp="+$("tipo_producto").value+"&strpais="+$("strpais").value+"&strano="+$("strano").value

}

function callProdDestacados(idioma, sector){

	var params = 'idioma='+idioma+'&sector='+sector;
	var url = 'productos_destacados_menu.jsp';
        var texto = 'Ver m&aacute;s publicaciones de '
        var texto2 = 'Publicaciones destacadas ';
        if(idioma=='I'){
            texto = 'View more reports from '
            texto2 = 'Featured reports '
        }
        var nameSector = $('pd'+sector).innerHTML;

        myAjax = new Ajax.Updater('productosCarrusel', url, {method: 'post', asynchronous:true, parameters:params,        
	onComplete:function(){
            carrusel = new Carousel($('carrusel').down('.middle'), $('carrusel').down('.inner').select('div'), $('carrusel').select('a.carousel-control'), {
                        duration: 0.5,
                        transition: 'sinoidal',
                        visibleSlides: 3,
                        circular: true,
                        effect: 'scroll'
                });
		carrusel.first2();
                $("ver_mas_publicaciones").style.display = "block"
                $("ver_mas_publicaciones_texto").innerHTML = '<a href="browse.jsp?idioma='+idioma+'&sector='+sector+'">'+texto+nameSector+'</a>'
                $("titPubliDes").innerHTML = texto2 + nameSector;

                $$('#mnuSec li a').each(function(f) {
                    f.className = "";
                    f.style.backgroundColor = '#E7EBEE'
                    f.style.fontSize = '13px'
                    f.style.fontWeight = 'normal'
                });

                $("pd"+sector).className = "mnuActivo"
                $("pd"+sector).style.backgroundColor = '#C7D2D8'
                $("pd"+sector).style.fontSize = '12px'
                $("pd"+sector).style.fontWeight = 'bold'

                
	}
	});

}

function valida_form_login(){

    var frm = document.formSingIn;

	if($("login").value != ''){ 
		if($("password").value!= ''){
			objForm = document.formSingIn;
			objForm.action = "sign_in.jsp";
			objForm.signonoper.value = "signon";
			objForm.submit();
		}else{	
			if(frm.idioma.value=='E')
				alert ( "Por favor, ingrese Clave." );
			else
				alert ( "Please, input Password." );
			$("password").focus();
		}
	}else{
		if(frm.idioma.value=='E')
			alert ( "Por favor, ingrese Email." )
		else
			alert ( "Please, input Email." )		
		$("login").focus();
	}
}

function valida_form_login_e(){
	objForm = document.formSingIn;
	objForm.action = "login_myaccount5.jsp";
	objForm.signonoper.value = "signon";
	objForm.submit();
}

function btnSetupAnAccount_onclick(){
	objForm = document.formSingIn;
	objForm.accion.value = "account_create";
	objForm.action = "account_login.jsp";
	objForm.submit();
}

function espacios(str){
	var lon = str.length;
	var tem = "";
	var con = 0;

	for( i = 0 ; i < lon ; i++ ){
		if( str.charAt(i) == " " ){
			con = con + 1;
		}
	}
	if( con == str.length )return(""); else	return(str);
}

function trim(s){
	sNew = "";
	if (s.length > 0){
	  for (i = 0; i < s.length; i++){
	    if (s.substring(i, i + 1) != " "){
	      for (j = s.length; j >= i; j--){
	       if (s.substring(j - 1, j) != " "){
	         sNew = s.substring(i, j);
	         break;
	       }
	      }
	      break;
	    }
	  }
	}  
	return sNew;
}

function getValueSelect(obj_select){
	i = obj_select.selectedIndex;

	if( i == (-1) )
		str = "-1"; //No existe �ndice seleccionado
	else
		str = obj_select.options[i].value;

	return(str);
}
function setObjSelect(obj_sel,x){
  var lon = obj_sel.length;

  if( lon > 0 ){
    if( x.length == 0){
      obj_sel.selectedIndex = 0;
      return(true);    
    }
  }

  for( var i = 0; i < lon ; i++ )
  {
    if( obj_sel.options[i].value == x )
    {
      obj_sel.selectedIndex = i;
      return(true);
    }
  }
  return(false);
}

function checkMail( p_objTxtEmail ){ 
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	var x = p_objTxtEmail.value;

	if ( filter.test(x) ) 
		return(true);
	else 
		return(false);
}

function validar_txt(obj_txt,mensaje){
	var valor = "";

	if( obj_txt.disabled == false )
	{
		valor = espacios(obj_txt.value);
		if(  valor == "" ){
			obj_txt.value = "";		alert(mensaje);		obj_txt.focus();		return(false);
		}else{
			obj_txt.value = trim(obj_txt.value);
			return(true);
		}
	}
	return( true );
}

function seleccione( ObjSelect , valueSelect , mensaje ){	
	cod = getValueSelect( ObjSelect ) ;
	if( cod == valueSelect ){
		alert( mensaje );
		ObjSelect.focus();
		return(false);
	}
	return(true);
}

function muestra_reporte(doc,sis,log){
    equ = 'AQSWEDRFTGYHUJDE';
    if (log == '' ){
            log = 'is_free';
    }
    strUrl = "http://member.bnamericas.com/cgi-bin/getreports?document="+doc+"&system="+sis+"&equiv="+equ+"&login="+log ;
    window.open(strUrl ,'newWin','toolbar=no,location=no,directories=no,menubar=no,width=650,height=600,status=yes,resizable=yes,top=100,left=50,scrollbars=yes');
}


function baja_reporte(ord,sku,log){
    strUrl = "http://member.bnamericas.com/cgi-bin/getreports_store?sku="+sku+"&orden="+ord+"&login="+log ;
    window.open(strUrl ,'newWin','toolbar=no,location=no,directories=no,menubar=no,width=650,height=600,status=yes,resizable=yes,top=100,left=50,scrollbars=yes');
}

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 btnEliminar_onclick( p_IdNroDoc, pIdioma,sku){
        var objForm = document.formShoppingCart;
        objForm.pNroDocumento.value = p_IdNroDoc;
        objForm.idioma.value = pIdioma;
        objForm.lastSku.value = sku;
		
		objForm.action = "shopping_cart.jsp"; 

        objForm.pAccion.value = "2";
        objForm.submit();
}


function btnActualizar_onchange( p_IdNroDoc,pIdioma ){

        var objForm = document.formShoppingCart;
        objForm.pNroDocumento.value = p_IdNroDoc;

        var objTxtCantidad = document.getElementById("txt_" + p_IdNroDoc );
        var objTxtCantidadOriginal = document.getElementById("txt_cantidad_" + p_IdNroDoc );

        // Validación
        objTxtCantidad.value = mc_trim(objTxtCantidad.value);
        if( objTxtCantidad.value == "" ){
                alert("Ingrese una cantidad mayor o igual a 1");
                objTxtCantidad.value = objTxtCantidadOriginal.value;
                return(false);
        }

        // Validación
        var cantidad = parseInt(objTxtCantidad.value,10);
        if( cantidad < 0 ){
                alert("Ingrese una cantidad mayor o igual a 1");
                objTxtCantidad.value = objTxtCantidadOriginal.value;
                return(false);
        }
        if(cantidad==0)
            btnEliminar_onclick(p_IdNroDoc,pIdioma)

        objForm.pCantidad.value = cantidad;
        objForm.idioma.value = pIdioma;
        objForm.pAccion.value = "3";		
        objForm.submit();
        return true;
}

function mc_trim(s){
    sNew = "";
    if (s.length > 0){
        for (i = 0; i < s.length; i++){
            if (s.substring(i, i + 1) != " "){
                for (j = s.length; j >= i; j--){
                    if (s.substring(j - 1, j) != " "){
                        sNew = s.substring(i, j);
                        break;
                    }
                }
                break;
            }
        }
    }
    return sNew;
}

function val_car(e,Lista){
    var tecla, buscar = Lista;
    if (navigator.appName == "Netscape")tecla = e.which; else tecla = e.keyCode;

    c = String.fromCharCode(tecla);
    if( buscar.indexOf(c) == -1 )return(false);else return(true);
}

function validarTelefono(campo){
    valor = validarNumerico(campo)
    if (valor==false){
        $('msjTel').style.display = 'block';
        $(campo).style.backgroundColor = "#FBEFEF";
        $(campo).focus();
    }else{
        $('msjTel').style.display = 'none';
        $(campo).style.backgroundColor = "#FFF";
    }
    
    if(campo=='REQUIRED_phone1'){ $("idioma").value=="E" ? sCampo = "país" : sCampo = "country" }
    if(campo=='REQUIRED_phone2'){ $("idioma").value=="E" ? sCampo = "area" : sCampo = "area" }
    if(campo=='REQUIRED_phone3'){ $("idioma").value=="E" ? sCampo = "teléfono" : sCampo = "phone" }
    if($(campo).value==''){$(campo).value=sCampo;$(campo).style.color='#a7a7a7';}
    
}

function validarNumerico(campo){
    if (!/^([0-9])*$/.test($(campo).value))
        return false
    else
        return true
}

function setVal(){
	
	if($("txtIdioma").value=='E'){
		if ($("REQUIRED_phone1").value=='' || $("REQUIRED_phone1").value == "país"){
			$("REQUIRED_phone1").value = "país";
                        $("REQUIRED_phone1").style.color="#a7a7a7"
                }
                if ($("REQUIRED_phone2").value=='' || $("REQUIRED_phone2").value == "area"){
                        $("REQUIRED_phone2").value = "area";
                        $("REQUIRED_phone2").style.color="#a7a7a7"
                }
                if ($("REQUIRED_phone3").value=='' || $("REQUIRED_phone3").value == "teléfono"){
                        $("REQUIRED_phone3").value = "teléfono";
                        $("REQUIRED_phone3").style.color="#a7a7a7"
                }
	}else{
		if ($("REQUIRED_phone1").value=='' || $("REQUIRED_phone1").value == "country"){
			$("REQUIRED_phone1").value = "country";
                        $("REQUIRED_phone1").style.color="#a7a7a7"
                }
                if ($("REQUIRED_phone2").value=='' || $("REQUIRED_phone2").value == "area"){
                        $("REQUIRED_phone2").value = "area";
                        $("REQUIRED_phone2").style.color="#a7a7a7"
                }
                if ($("REQUIRED_phone3").value=='' || $("REQUIRED_phone3").value == "phone"){
                        $("REQUIRED_phone3").value = "phone";
                        $("REQUIRED_phone3").style.color="#a7a7a7"
                }
	}


        if($('email')) $('email').focus()

        if(idPais!=""){
            for (i=0; i<=$("REQUIRED_country").length-1; i++) {
                if($("REQUIRED_country").options[i].value==idPais){
                    $("REQUIRED_country").options[i].selected=true
                }
            }
        }
        
        if(codPais!="") $("REQUIRED_phone1").value=codPais
        if(codCiudad!="") $("REQUIRED_phone2").value=codCiudad
        if(telefono!="") $("REQUIRED_phone3").value=telefono


}

function cargaAutocomplete(){

    new Autocomplete('REQUIRED_company', { serviceUrl: '/freetrial_companias.jsp' , width: 450, onSelect: onAutocompleteSelect, container: 'ac_container' });
    new Autocomplete('REQUIRED_position', { serviceUrl: '/freetrial_cargos.jsp' , width: 450, onSelect: onAutocompleteSelect, container: 'ac_container2' });

}

function queryBlur(nodePri){
    
    nodePri.value != "" ? nodePri.style.backgroundColor = "#fff" : nodePri.style.backgroundColor = "#FBEFEF"

    $$('form#frmRegistro input').each(function(node){

        if(node.id=='email'){checkEmail(node)}

        if(node.value!=""){
            if(node.id=='password'){
                if(node.value.length<6){
                    node.style.backgroundColor='#FBEFEF'
                    $('msjPassword').style.display='block'
                    $('txtIdioma').value=='E' ? $('msjPassword').innerHTML='La contrase&ntilde;a debe tener un m&iacute;nimo de 6 caracteres.' : $('msjPassword').innerHTML = 'Password'
                }else{
                    node.style.backgroundColor='#FFF'
                    $('msjPassword').style.display='none'
                }
            }
            if(node.id=='confirm_password' && $('password').value.length>=6){

                if($("password").value != $("confirm_password").value){
                     node.focus()
                     node.value=""
                     node.style.backgroundColor='#FBEFEF'
                     $('msjConfPassword').style.display='block'
                     $('txtIdioma').value=='E' ? $('msjConfPassword').innerHTML='Las contrase&ntilde;as no coinciden' : $('msjConfPassword').innerHTML = 'Passwords'
                }else{
                     $('msjConfPassword').style.display='none'
                     node.style.backgroundColor='#FFF'
                }
            }
        }
    });

}

function updatecodearea(idpais){

    url='/freetrial_codarea.xsql';

    idpais.value!=0 ? idpais.style.backgroundColor = "#FFF" : idpais.style.backgroundColor = "#FBEFEF"

    new Ajax.Request(url, {
        parameters:'pais='+idpais.value,
            method: 'get',
            onSuccess: function(code) {
                 $('REQUIRED_phone1').value = code.responseText;
                 $('REQUIRED_phone1').style.color='#000000'
                 validarTelefono('REQUIRED_phone1');
            }
    });

}

function onAutocompleteSelect(value, data){

}

function checkForm(id){

    var error = false;



    $$('form#'+id+' .required').each(function(node){

        if (node.value == "") {
            error = true;
            node.style.background = "#FBEFEF";
        }
    });

    $$('form#'+id+' .email').each(function(node){
        if ((node.value.indexOf(".") > 2) && (node.value.indexOf("@") > 0)) {
            error = true;
            node.style.background = "#FBEFEF";
        }
    });

    $$('form#'+id+' .numeric').each(function(node){

        var strChars = "0123456789.-";
        for (i = 0; i < node.value.length; i++) {
            strChar = node.value.charAt(i);
            if (strChars.indexOf(strChar) == -1) {
                error = true;
                node.style.background = "#FBEFEF";
            }
        }
    });

    if (error == true) {
        alert('Asegurate de rellenar todos los campos requeridos');
    } else {

        $(id).submit();
    }

}


function checkEmail(node){
    node.value = mc_trim(node.value)
    if(node.value.length>0){
        var valido = checkMail(node)
        if(valido==true){
            node.style.backgroundColor='#FFF'
            $('msjEmail').style.display='none'

            new Ajax.Request('valida_login.xsql',{parameters:'email='+node.value+'&idioma='+$('txtIdioma').value,method: 'post',
                onSuccess: function(resp){
                    if(resp.responseText.length>0){

                        $('msjEmail').style.display='block'
                        $('msjEmail').innerHTML = resp.responseText
                        //node.value = ""
                        /*
                        $$('#frmRegistro input,#frmRegistro select').each(function(node){
                            node.disabled="disabled"
                            $("email").disabled = ""
                        });
                        */
                    }else{
                        //console.log("no existe "+resp.responseText)
                        /*
                        $$('#frmRegistro input,#frmRegistro select').each(function(node){
                            node.disabled = ""
                        });
                        */
                    }
                }
            });

        }
        else{
            node.focus()
            node.style.backgroundColor='#FBEFEF'
            $('msjEmail').style.display='block'
            $('txtIdioma').value=='E' ? $('msjEmail').innerHTML='Email Invalido' : $('msjEmail').innerHTML = 'Invalid Email'
        }
    }
    else{
        node.style.backgroundColor='#FBEFEF'
        $('msjEmail').style.display='none'
    }
}


function selTipoSuscrip(node){
    var bloque = ""
    var opAct = node.value;
    if(node.value=='sector') bloque = 'porSector';
    if(node.value=='region') bloque = 'porRegion';

    $$('.flecha_contenido ul li').each(function(item) {
		if(item.firstChild.nodeValue != null)
			item.update(item.firstChild.nodeValue)
		else
			item.update(item.lastChild.nodeValue)		
    });

    if(node.checked==true){

        $$('.flecha_contenido').each(function(item) {
            item.style.backgroundImage = "url(img/flecha_contenido.gif)"
        });

        $$('#'+bloque+' ul li').each(function(item) {
            texto = item.textContent
            item.insert({top:'<input type="checkbox" name="chk'+item.title+'" id="chk'+item.title+'" title="'+opAct+'" value="'+item.title+'" style="margin-right:5px"/>'})
        });

        $(bloque).style.backgroundImage = "url(img/flecha_contenido2.gif)"
    }
}

function continuarRegistro(frmid){

    var error = false

    $$('#'+frmid+' .required').each(function(node){
        if (node.value == "" || (node.type == "select-one" && node.value == 0) || (node.style.color == "rgb(167, 167, 167)")) {
            error = true;
            node.style.background = "#FBEFEF";
        }
    });

    if (error == true) {
        alert('Asegurate de rellenar todos los campos requeridos');
    } else {
        $("REQUIRED_phone").value = $("REQUIRED_phone1").value + "-" + $("REQUIRED_phone2").value + "-" + $("REQUIRED_phone3").value
        //$(frmid).action = 'register_preferences.jsp';
        $(frmid).action = 'account_save.jsp';
        if($("chkterminos").checked)
            $(frmid).submit();
        else
            $("linkTerminos").style.color = "red"
    }

}

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 pesos_onclick(tipo){
    var objForm = document.formShoppingCart;
    objForm.pesos.value = tipo;
    objForm.submit();
}

function gotoTransbank_onclick(){
    var objForm = document.formShoppingCart;
    if(objForm.pesos.value=="ch"){
        objForm.action = "/cgi-bin/kccpesos/tbk_bp_pago.cgi";
    }else{
        objForm.action = "/cgi-bin/tbk_bp_pago.cgi";
    }
    objForm.submit();
}

function gotoDownload_onclick(){
    var objForm = document.formShoppingCart;
    objForm.action = "download_suscriptor.jsp";
    objForm.submit();
}

function obtenerDescto(){

    var url =  'valida_ticket.xsql'
    new Ajax.Request(url,{parameters:'ticket='+$("txtCodTicket").value+'&login='+$("login").value,method: 'post',
        onSuccess: function(resp){
            if(resp.responseText>0){$('formShoppingCart').submit()}
            else{
                $("txtCodTicket").value=""
                $("idioma").value == 'E' ? $('mensajeTicket').update('Ticket invalido'): $('mensajeTicket').update('Invalid code')
            }
        }
    });
}

function checkEnter(event){

    if(event.which) mykey = event.which;
    else mykey = event.keyCode;

    if(mykey == 13){
        // show me that it's trying to stop it
        //document.getElementById("idBoton").click();
        // stop event propagation, keep the KEYPRESS from continuing?
        if(event.stopPropagation)
            event.stopPropagation();

        // prevent default action, is this SUBMIT?
        if(event.preventDefault)
            event.preventDefault();

        // for IE: cancel event bubble and clear return value
        event.cancelBubble = true;
        event.returnValue = false;
    }
}

function registerSave(){
    var lstSeleccion = '';
    if($('radSector').checked==true){
        $$('#contenido_tabla_registro input').each(function(item) {
            if(item.title==$('radSector').value){                
                if(item.checked==true){                    
                    lstSeleccion =='' ? lstSeleccion = item.value : lstSeleccion = lstSeleccion +','+item.value
                }
            }
        });
    }
    if($('radRegion').checked==true){
        $$('#contenido_tabla_registro input').each(function(item) {
            texto = item.textContent
            if(item.title==$('radRegion').value){
                if(item.checked==true){
                    lstSeleccion=='' ? lstSeleccion = item.value : lstSeleccion = lstSeleccion +','+item.value
                }
            }
        });
    }
    $("lstSeleccion").value = lstSeleccion
    $("accion").value="save"
    $("frmRegistro").submit()

}

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 = 'S'
	frm.action = "forgot_password_modal.jsp"
	frm.submit()
	*/
		Modalbox.show('/store/forgot_password_modal.jsp?save=S&txt_email='+frm.txt_email.value+'&txt_user='+frm.txt_user.value,{width: 500, title: 'Sending status'});
		return false;	
	
    }
}

function gotoCheckout(tipo){

    
        var objForm = document.formShoppingCart;
        if(tipo==1)
                objForm.action = "checkout.jsp";
        else
                objForm.action = "expresscheckout.jsp";

        if($("precio_final").innerHTML!='US$ ,00'){
            if(validFields()){
                if(document.getElementById("chkterminos")){
                    if($("chkterminos").checked)
                        objForm.submit();
                    else
                        $("tblTerminos").style.border = "1px solid #F19A9A"
                }else{
                    objForm.submit();
                }
            }
        }
 
        if($("precio_final").innerHTML=='US$ ,00'){
            if(document.getElementById("chkterminos")){
                if($("chkterminos").checked)
                    objForm.submit();
                else
                    $("tblTerminos").style.border = "1px solid #F19A9A"
            }else{
                objForm.submit();
            }
        }

}

function modProfile(formNum){

    if(formNum==1){
        var param = $('frmRegistro1').serialize()
        var url =  'valida_password.xsql'
        new Ajax.Request(url,{parameters:param,
            onSuccess: function(resp){
                if(resp.responseText=='1'){
                    $("idioma").value == 'E' ? $('frm1msjPass1').update('Contraseña incorrecta'): $('frm1msjPass1').update('Invalid password')
                    $('frm1msjPass1').style.display="block"
                    $('frm1msjPass2').style.display="none"
                }
                if(resp.responseText=='2'){
                    $("idioma").value == 'E' ? $('frm1msjPass2').update('La nueva contraseña y la confirmacion no coinciden.'): $('frm1msjPass2').update('The new password and confirmation password do not match. Please retype.')
                    $('frm1msjPass2').style.display="block"
                    $('frm1msjPass1').style.display="none"
                }
                if(resp.responseText=='0'){
                    $("frmRegistro"+formNum).submit()
                    //$("idioma").value == 'E' ? $('mensajeTicket').update('Ticket invalido'): $('mensajeTicket').update('Invalid code')
                }
            }
        });

    }

    if(formNum==2){
        if($("REQUIRED_phone1").value=='country' || $("REQUIRED_phone1").value=='país') $("REQUIRED_phone1").value = ""
        if($("REQUIRED_phone2").value=='area') $("REQUIRED_phone2").value = ""
        $("REQUIRED_phone").value = $("REQUIRED_phone1").value + "-" + $("REQUIRED_phone2").value + "-" + $("REQUIRED_phone3").value
        checkForm("frmRegistro"+formNum)
    }
}

function compartir(sku, idioma){

    /*
        var url = "send_email_to_friend.jsp"
        myAjax = new Ajax.Updater('blockCompartir', url, {method: 'post', asynchronous:true, parameters:"idioma="+sku+"&sku="+idioma,
	onComplete:function(){
            $("blockCompartir").style.display="block"
        }
	});
*/

}


function checkChrRut(e){
	if(window.event) // IE
	{
		if (((event.keyCode>47)&&(event.keyCode<58))||(event.keyCode==75)||(event.keyCode==107)){
			event.returnValue=true;
		}else{
			event.returnValue=false;
		}
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum= e.which;
		if (((keynum>47)&&(keynum<58))||(keynum==75)||(keynum==107)||(keynum==8)){
			return true;
		}else{
			return false;
		}
	}
} 


function formatear4_menu(forma){        
	$("rut_1").value = $("rut_2").value;
}


function formatear3_menu(forma){
        valor = $("rut_1").value;
        //valor = valor.replace(/.-/g,'');
        valor = valor.replace('.','');
        valor = valor.replace('.','');
        valor = valor.replace('-','');
        $("rut_2").value = valor;
	if ($("rut_1").value != "" && $("cboPais").value=="11"){
            if (valor.length > 1){
                $("rut_1").value = insertapuntos_menu(valor.substring(0,valor.length - 1)) + '-' + valor.substring(valor.length - 1,valor.length);
            }
	}else{
            $("rut_1").value = valor
	}
        return true
}


function insertapuntos_menu(strval){
	var A = new Array();
	var strtemp = strval;
	strtemp = new Number(strtemp);
	strtemp = new String(strtemp);
	if (strtemp.length > 3){
		for(var i = 0; strtemp.length > 3; i++){
			A[i] = Right_menu(strtemp,3);
			strtemp /= 1000;
			strtemp=new String(strtemp);
			if (strtemp.indexOf('.') != -1){
				strtemp = strtemp.substr(0,strtemp.indexOf('.'));
			}
		}
		for(i-- ;i >= 0 ;i--){
			strtemp = strtemp + "." + A[i];
		}
	}
	return(strtemp);
} 

function Right_menu(strvar,intcant){
	strtemp = "";
	intlargo = strvar.length -1;
	for(i = 1;i <= intcant; i++){
		strtemp = strtemp + strvar.charAt(intlargo);
		intlargo--;
	}
	strtmp2=""
	for(intlargo = strtemp.length -1; intlargo >=0; intlargo--){
		strtmp2 = strtmp2 + strtemp.charAt(intlargo);
	}
	return(strtmp2);
}

function validRut(){
        if($("cboPais").value=="11")
            $("sRut").innerHTML = "* Rut"
        else
            $("sRut").innerHTML = "Tax ID"

	if (document.formShoppingCart.rut_1.value != "" && $("cboPais").value=="11"){
		formatear3_menu	(document.formShoppingCart)
		var LargoRut = document.formShoppingCart.rut_2.value.length;
		Rut = document.formShoppingCart.rut_2.value.substring(0,LargoRut-1);
		Dig = document.formShoppingCart.rut_2.value.substring(LargoRut-1,LargoRut);
		if (!(rut_menu2(Rut, Dig))){
			alert('Rut inv\xe1lido \npor favor ingr\xe9selo nuevamente');
			document.formShoppingCart.rut_2.value = '';
			document.formShoppingCart.rut_1.value = '';
			document.formShoppingCart.rut_1.focus();
		}	
	}
}


function validFields(){
	var Rut = '';
	var Dig	= '';
	var LargoRut = document.formShoppingCart.rut_2.value.length;


	if($("cboPais").value=="0"){
		alert("Seleccione un pa\xeds")
		$("cboPais").focus()
		return false
	}
	
	document.formShoppingCart.rut_2.value = document.formShoppingCart.rut_2.value.toUpperCase( );
	valor = document.formShoppingCart.rut_1.value
	document.formShoppingCart.rut_1.value = valor.replace(/ /g,'');
	if (document.formShoppingCart.rut_1.value == '' && $("cboPais").value=="11"){
		alert('Ingrese Rut');
		document.formShoppingCart.rut_1.focus();
		return false;
	}	
	
	if($("cboPais").value=="11"){
		Rut = document.formShoppingCart.rut_2.value.substring(0,LargoRut-1);
		Dig = document.formShoppingCart.rut_2.value.substring(LargoRut-1,LargoRut);
		//if (!(rut_menu(Rut, Dig))){
		if (!(rut_menu(document.formShoppingCart.rut_2.value))){		
			alert('Rut inv\xe1lido \npor favor ingr\xe9selo nuevamente');
			document.formShoppingCart.rut_2.value = '';
			document.formShoppingCart.rut_1.value = '';
			document.formShoppingCart.rut_1.focus();
			return false;
		}
	}
	valor = $("txtRazonSocial").value
	valor = valor.replace(/ /g,'')
	if(valor==""){
		alert("Ingrese el nombre de la empresa")
		$("txtRazonSocial").focus()
		return false
	}

	valor = $("txtDireccion1").value
	valor = valor.replace(/ /g,'')
	if(valor==""){
		alert("Ingrese la direcci\xf3n")
		$("txtDireccion1").focus()
		return false
	}	

	valor = $("txtTel").value
	valor = valor.replace(/ /g,'')
	if(valor==""){
		alert("Ingrese n\xfamero de tel\xe9fono")
		$("txtTel").focus()
		return false
	}	
	
	return true
}

function rut_menu2(variable,digit){
    
	Sum = 0;
	digito = 0;
	factor = 2;
	largo = variable.length;
	while (largo !== 0){
		Sum = Sum + (variable.substring(largo, largo-1) * factor);
		if (factor == 7){
				factor = 2;
		}else{
			factor = factor + 1;
		}
		largo = largo - 1;
	}
	d = 11 - Sum % 11;
	if (d == "10"){
		digito = "K";
  }else {
		if (d == "11"){
			digito = 0;
		}else{
			digito = d;
		}
	}
	if (digito == digit){
		return true;
	}else{
		return false;
	}
}



function rut_menu(rut) {
        
	var tmpstr = "";
	var intlargo = rut;
 
	if (intlargo.length> 0) {
		crut = rut;
		largo = crut.length;
		if ( largo <2 ) {
			return false;
		}
 
		for ( i=0; i <crut.length ; i++ ) {
			if ( crut.charAt(i) != ' ' && crut.charAt(i) != '.' && crut.charAt(i) != '-' ) {
				tmpstr = tmpstr + crut.charAt(i);
			}
		}
		rut = tmpstr;
		crut=tmpstr;
		largo = crut.length;
		if ( largo> 2 ){
			rut = crut.substring(0, largo - 1);
		}else rut = crut.charAt(0);
 
		dv = crut.charAt(largo-1);
		if ( rut == null || dv == null ) return 0;
		var dvr = '0';
		suma = 0;
		mul = 2;

		for (i= rut.length-1 ; i>= 0; i--) {
			suma = suma + rut.charAt(i) * mul;
			if (mul == 7) mul = 2;
			else mul++;
		}

		res = suma % 11;
		if (res==1) dvr = 'k';
		else if (res==0) dvr = '0';
		else { dvi = 11-res; dvr = dvi + ""; }
 
		if ( dvr != dv.toLowerCase() ) {
			//alert('El Rut Ingreso es Invalido');
			return false;
		}
		//alert('El Rut Ingresado es Correcto!');
		return true;
	}
}

var tooltipObj = false;
var tooltipOver1 = new Array(false,false,false,false,false,false);
var tooltipOver = new Array(false,false,false,false,false,false);
var contador = 0
var time = 250;
var hideDelay = 200;
var timer = new Array();

function showTooltip(item,pos,sku,idioma){

    var posLeft = 0
    if(pos==1) posLeft = 40
    if(pos==2) posLeft = 220
    if(pos==3) posLeft = 400
    if(pos==4) posLeft = 580

    if ($('tt_'+item) == undefined){
        tooltipObj = document.createElement('div');
        tooltipObj.style.position = 'absolute';
        tooltipObj.style.zIndex = '10';
        tooltipObj.style.left = posLeft+'px';
        tooltipObj.id = 'tt_'+item;
        tooltipObj.className = 'tooltip';

        //$(item).appendChild(tooltipObj);
        $("series").appendChild(tooltipObj);

        var url =  '/store/tooltip_destacado.jsp'
        myAjax = new Ajax.Updater('tt_'+item, url, {method: 'post', asynchronous:true, parameters:"sku="+sku+"&idioma="+idioma,
	onComplete:function(){}
	});
        
        $('tt_'+item).onmouseover = function(){
            tooltipOver[pos] = true
        }
        $('tt_'+item).onmouseout = function(){
            tooltipOver[pos] = false
            timer[pos] = setTimeout ('hideTooltipAction(\''+item+'\',\''+pos+'\')', hideDelay );
        }
        clearTimeout(timer[pos]);
    }else{
         tooltipOver1[pos] = true
    }

}

function hideTooltip(item,pos){
     tooltipOver1[pos] = false
     timer[pos] = setTimeout ('hideTooltipAction(\''+item+'\',\''+pos+'\')', hideDelay );
}

function hideTooltipAction(item,pos){

     if(!tooltipOver[pos] && !tooltipOver1[pos]){
          if ($('tt_'+item) != undefined){
            //var d = $(item)
            var d = $("series")
            var olddiv = $('tt_'+item)
            d.removeChild(olddiv)
            //$('tt_'+item).style.display='none';
          }
    }

}

function tabactive(tab,act){

    $$('.tab li').each(function(node){
            node.className = "";
    });

	tab.className = "active"
	
    $$('.tabContent ul').each(function(node){
            node.style.display = "none";
    });
	
	$(act).style.display="block"

}

