<commit_before>ETHERID_CONTRACT = "0x3589d05a1ec4af9f65b0e5554e645707775ee43c"
ETHERID_ABI = 
[{"constant":true,"inputs":[],"name":"root_domain","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"domain","type":"uint256"}],"name":"getDomain","outputs":[{"name":"owner","type":"address"},{"name":"expires","type":"uint256"},{"name":"price","type":"uint256"},{"name":"transfer","type":"address"},{"name":"next_domain","type":"uint256"},{"name":"root_id","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"n_domains","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"domain","type":"uint256"},{"name":"id","type":"uint256"}],"name":"getId","outputs":[{"name":"v","type":"uint256"},{"name":"next_id","type":"uint256"},{"name":"prev_id","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"domain","type":"uint256"},{"name":"expires","type":"uint256"},{"name":"price","type":"uint256"},{"name":"transfer","type":"address"}],"name":"changeDomain","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"domain","type":"uint256"},{"name":"name","type":"uint256"},{"name":"value","type":"uint256"}],"name":"changeId","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":false,"name":"domain","type":"uint256"},{"indexed":false,"name":"id","type":"uint256"}],"name":"DomainChanged","type":"event"}]
;

domains = new Array()
ids = new Array()
current_domain = 0
current_block = 0
domain = {}
ether_contract = undefined;
batch_progress = {}
batch_domain_list = []
batch_domain_n = 0
batch_domain_wallet_to_use = ""
batch_domain_cancel = false;
batch_domain_process = ""
batch_id_value = 0
batch_id = 0
batch_is_active = false;
batch_price = 0;

all_domains_data = []
all_domains_curent_domain = 0
all_domains_n = 0;
all_domain_pattern = ""
all_domains_cancel = false;
all_domains_csv = "";
all_domain_to_csv = false;
only_mine = false
only_expired = false
only_for_sale = false

BATCH_PROCESS_TIMEOUT = 1500;
ALL_DOMAINS_TIMEOUT = 200;
ALL_DOMAINS_SEARCH_PORTION = 112;
MAX_ITEMS_IN_TABLE = 5000;

var all_domains_table
var all_domains_data = new Array();
my_accounts = [];


if(typeof web3 === 'undefined')
    web3 = require('web3');

ETH1 = new BigNumber( 1000000000000000000 );   
SECONDS_PER_BLOCK = 12;
ETH_SIGN = "\u{1D763}"

function getContract(){
    if( ether_contract ) return ether_contract;
    ether_contract = web3.eth.contract(ETHERID_ABI).at(ETHERID_CONTRACT);
    ether_contract.DomainChanged().watch( function( error, result ) {
        
        if( !batch_is_active )
        {
            try 
            {
                $("#stat_domains").text( contract.n_domains() );
                updateDomainPage()
            }
            catch( x ) {}
        }
    });
    return ether_contract;
}

function processBatch()
{
    if( batch_domain_cancel )
    {
        batch_progress.setText( "Canceled");
        batch_domain_n = 0;
                
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );     
        $("#batch_title").text( "No active process")    
        batch_is_active = false;

        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    }
    
    
    if( batch_domain_n >= batch_domain_list.length )
    {
        batch_progress.setText( "Done");
        batch_progress.animate( 1 );
        batch_domain_n = 0;
        if( batch_domain_process == "claim" ) $("#batch_list").val( "" );
                
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );          
        $("#batch_title").text( "No active process")
        batch_is_active = false;
        
        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    }
    
    name = batch_domain_list[ batch_domain_n ];
    
    if( name.substring( 0, 2 ) === "0x" ) 
    {    
        a = hexToArray( name )
        hex = arrayToHex( a )    
        hex = "0x" + hex.substr( 0, 64 )
        ascii = ""
        try {
            ascii = utf8.decode( toAscii( hex ) ) 
        }
        catch( x ) {}
    }
    else
    {
        utf = utf8.encode( name ).slice(0, 32);
        hex = "0x" + asciiToHex( utf )    
        try {
            ascii = utf8.decode( toAscii( hex ) ) 
        }
        catch( x ) {}
    }    
    
    domain = new BigNumber( hex );
    
    batch_progress.setText( ascii );
    
    try 
    {
        var params  = {}
        contract = getContract();
        
        switch( batch_domain_process )
        {
            case "claim":            
                params = {
                            gas: 200000,
                            from : batch_domain_wallet_to_use,
                            value: 0
                        };
                contract.changeDomain.sendTransaction( domain, 2000000, 0, 0, params );
                break;
            case "prolong":            
                
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                contract.changeDomain.sendTransaction( domain, 2000000, d.price, d.transfer, params );
                break;
            case "price":            
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                
                contract.changeDomain.sendTransaction( domain, 2000000, batch_price, d.transfer, params );
                break;
            case "id":            
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                getContract().changeId.sendTransaction
                (
                    domain, 
                    batch_id, 
                    batch_id_value, 
                    params 
                );                
                break;
        }
    }
    catch( err )
    {
        swal( "Error", "Domain: " + hex + " (" + err + ")", "error" );
        
        batch_progress.setText( "Error");
        batch_domain_n = 0;
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );       
        $("#batch_title").text( "No active process")
        batch_is_active = false;
        
        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    } 
    
    batch_domain_n++;
    batch_progress.animate( batch_domain_n / batch_domain_list.length );
    
    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);
}


$().ready( function(e){ 
    $( "#tabs" ).tabs(
        {
            beforeActivate: function( event, ui ) 
            {
                if( ui.newPanel[0].id == "tabs-all" ) {
                    
                    //if( all_domains_data.length == 0 ) refreshAllDomains();
                }
                if( ui.newPanel[0].id == "tabs-batch" ) {
                    
                    try
                    {
                        my_accounts = web3.eth.accounts;      

                        $("#batch_claim_my_address").empty();

                        for( var i = 0; i < my_accounts.length; i++ )
                        $("#batch_claim_my_address")
                            .append( $("<option>").val( my_accounts[i] ).text( 
                                no0x(my_accounts[i]) + 
                                " (" + formatEther( web3.eth.getBalance( my_accounts[i] ), "ETH" ) + ")"                                            
                            ) );        

                        lua = Cookies.get('etherid_last_used_address'); 
                        if( lua ) $("#batch_claim_my_address").val( lua )
                    }
                    catch( x ) 
                    {
                        swal("Web3 Error!", "Cannot connect to the Ethereum network. Please install and run an Ethereum client. \n(" + x + ")", "error" ) 
                    }                
                }
            }    
        }
    );    
    
    
    batch_progress = new ProgressBar.Circle('#batch_progress', {
        color: '#59869b',
        duration: 500,
        easing: 'easeInOut',
        strokeWidth: 2
    });

    update_list_progress = new ProgressBar.Circle('#update_list_progress', {
        color: '#59869b',
        duration: 500,
        easing: 'easeInOut',
        strokeWidth: 2
    });

    try
    {
        if( web3.currentProvider == null )
            web3.setProvider( new web3.providers.HttpProvider( ) );    
        
//        if(typeof web3 === 'undefined')
//            web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); //8545 8080         
        
        contract = getContract();        
        $("#stat_domains").text( contract.n_domains() );
//        root_domain = web3.toHex( contract.root_domain() );
//        alert( root_domain )
    }
    catch( x ) {
        x = x;
    }
    
    $("input#search_domain").keyup(function( event ) {
        if( event.keyCode == 13 ) $("#btn_search_domain").click()
    });
    

    $("#btn_all_refresh").click( function() { refreshAllDomains( false ); } );
    $("#btn_all_cancel").click( function() { all_domains_cancel = true; } );
    $("#btn_download_all").click( function() { refreshAllDomains( true ); } ); 
    
    
    $("#btn_batch_prolong").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }       

        swal({   
            title: "Are you sure?",   
            text: "You are about to prolong " + batch_domain_list.length + 
                    " domains."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, prolong!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm ) 
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "prolong";
                    $("#batch_title").text( "Prolonging in progress...")



                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });
    
    $("#btn_batch_price").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }
        
        price_in_eth = $("#batch_price").val()
        batch_price = web3.toWei( new BigNumber( price_in_eth ), "ether" );
            

        swal({   
            title: "Are you sure?",   
            text: "You are about to set price for " + batch_domain_list.length + 
                    " domains to " + formatEther( batch_price, "ETH") + "."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, set price!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm )
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "price";
                    $("#batch_title").text( "Pricing in progress...")



                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });

    $("#btn_batch_id").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }
        
        iv = $("#batch_id").val()
        batch_id = ""
        if( iv.substring( 0, 2 ) === "0x" ) 
        {    
            a = hexToArray( iv )
            batch_id = arrayToHex( a )    
            batch_id = "0x" + batch_id.substr( 0, 64 )
        }
        else
        {
            utf = utf8.encode( iv ).slice(0, 32);
            batch_id = "0x" + asciiToHex( utf )    
        }        
        
        iv = $("#batch_value").val()
        batch_id_value = ""
        if( iv.substring( 0, 2 ) === "0x" ) 
        {    
            a = hexToArray( iv )
            batch_id_value = arrayToHex( a )    
            batch_id_value = "0x" + batch_id_value.substr( 0, 64 )
        }
        else
        {
            utf = utf8.encode( iv ).slice(0, 32);
            batch_id_value = "0x" + asciiToHex( utf )    
        } 
        
        if( new BigNumber( batch_id ) == 0 || new BigNumber( batch_id_value ) == 0 )
        {
            swal("Error!", "ID and value should not be empty", "error" ) 
            return;            
        }

        swal({   
            title: "Are you sure?",   
            text: "You are about to change id " + batch_id + " for " + batch_domain_list.length +  
                    " domains to " + formatEther( batch_price, "ETH") + "."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, change ID!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm )
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "id";
                    $("#batch_title").text( "ID changing in progress...")

                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });
    
    
    $("#btn_download_ascii").click( function() { 
        var csv = "";
        
        for( var i = 0; i < all_domains_data.length; i++ )
        {
            csv += all_domains_data[i].name() + "\n";
        }
        
        var downloadLink = document.createElement("a");
        var blob = new Blob([ csv ] );
        var url = URL.createObjectURL(blob);
        downloadLink.href = url;
        downloadLink.target = "names.csv";

        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
    });
        
    $("#btn_download_hex").click( function() { 
        var csv = "";
        
        for( var i = 0; i < all_domains_data.length; i++ )
        {
            csv += all_domains_data[i].name_hex() + "\n";
        }
        
        var downloadLink = document.createElement("a");
        var blob = new Blob([ csv ] );
        var url = URL.createObjectURL(blob);
        downloadLink.href = url;
        downloadLink.target = "hex.csv";

        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);        
    });<commit_msg>makes .csv files download in mist<commit_after>ETHERID_CONTRACT = "0x3589d05a1ec4af9f65b0e5554e645707775ee43c"
ETHERID_ABI = 
[{"constant":true,"inputs":[],"name":"root_domain","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"domain","type":"uint256"}],"name":"getDomain","outputs":[{"name":"owner","type":"address"},{"name":"expires","type":"uint256"},{"name":"price","type":"uint256"},{"name":"transfer","type":"address"},{"name":"next_domain","type":"uint256"},{"name":"root_id","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"n_domains","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"domain","type":"uint256"},{"name":"id","type":"uint256"}],"name":"getId","outputs":[{"name":"v","type":"uint256"},{"name":"next_id","type":"uint256"},{"name":"prev_id","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"domain","type":"uint256"},{"name":"expires","type":"uint256"},{"name":"price","type":"uint256"},{"name":"transfer","type":"address"}],"name":"changeDomain","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"domain","type":"uint256"},{"name":"name","type":"uint256"},{"name":"value","type":"uint256"}],"name":"changeId","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":false,"name":"domain","type":"uint256"},{"indexed":false,"name":"id","type":"uint256"}],"name":"DomainChanged","type":"event"}]
;

domains = new Array()
ids = new Array()
current_domain = 0
current_block = 0
domain = {}
ether_contract = undefined;
batch_progress = {}
batch_domain_list = []
batch_domain_n = 0
batch_domain_wallet_to_use = ""
batch_domain_cancel = false;
batch_domain_process = ""
batch_id_value = 0
batch_id = 0
batch_is_active = false;
batch_price = 0;

all_domains_data = []
all_domains_curent_domain = 0
all_domains_n = 0;
all_domain_pattern = ""
all_domains_cancel = false;
all_domains_csv = "";
all_domain_to_csv = false;
only_mine = false
only_expired = false
only_for_sale = false

BATCH_PROCESS_TIMEOUT = 1500;
ALL_DOMAINS_TIMEOUT = 200;
ALL_DOMAINS_SEARCH_PORTION = 112;
MAX_ITEMS_IN_TABLE = 5000;

var all_domains_table
var all_domains_data = new Array();
my_accounts = [];


if(typeof web3 === 'undefined')
    web3 = require('web3');

ETH1 = new BigNumber( 1000000000000000000 );   
SECONDS_PER_BLOCK = 12;
ETH_SIGN = "\u{1D763}"

function getContract(){
    if( ether_contract ) return ether_contract;
    ether_contract = web3.eth.contract(ETHERID_ABI).at(ETHERID_CONTRACT);
    ether_contract.DomainChanged().watch( function( error, result ) {
        
        if( !batch_is_active )
        {
            try 
            {
                $("#stat_domains").text( contract.n_domains() );
                updateDomainPage()
            }
            catch( x ) {}
        }
    });
    return ether_contract;
}

function processBatch()
{
    if( batch_domain_cancel )
    {
        batch_progress.setText( "Canceled");
        batch_domain_n = 0;
                
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );     
        $("#batch_title").text( "No active process")    
        batch_is_active = false;

        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    }
    
    
    if( batch_domain_n >= batch_domain_list.length )
    {
        batch_progress.setText( "Done");
        batch_progress.animate( 1 );
        batch_domain_n = 0;
        if( batch_domain_process == "claim" ) $("#batch_list").val( "" );
                
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );          
        $("#batch_title").text( "No active process")
        batch_is_active = false;
        
        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    }
    
    name = batch_domain_list[ batch_domain_n ];
    
    if( name.substring( 0, 2 ) === "0x" ) 
    {    
        a = hexToArray( name )
        hex = arrayToHex( a )    
        hex = "0x" + hex.substr( 0, 64 )
        ascii = ""
        try {
            ascii = utf8.decode( toAscii( hex ) ) 
        }
        catch( x ) {}
    }
    else
    {
        utf = utf8.encode( name ).slice(0, 32);
        hex = "0x" + asciiToHex( utf )    
        try {
            ascii = utf8.decode( toAscii( hex ) ) 
        }
        catch( x ) {}
    }    
    
    domain = new BigNumber( hex );
    
    batch_progress.setText( ascii );
    
    try 
    {
        var params  = {}
        contract = getContract();
        
        switch( batch_domain_process )
        {
            case "claim":            
                params = {
                            gas: 200000,
                            from : batch_domain_wallet_to_use,
                            value: 0
                        };
                contract.changeDomain.sendTransaction( domain, 2000000, 0, 0, params );
                break;
            case "prolong":            
                
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                contract.changeDomain.sendTransaction( domain, 2000000, d.price, d.transfer, params );
                break;
            case "price":            
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                
                contract.changeDomain.sendTransaction( domain, 2000000, batch_price, d.transfer, params );
                break;
            case "id":            
                res = contract.getDomain( domain );

                d = new DomainRecord( domain, res[0], res[1], res[2], res[3] );
                
                params = {
                            gas: 200000,
                            from : d.owner,
                            value: 0
                        };
                getContract().changeId.sendTransaction
                (
                    domain, 
                    batch_id, 
                    batch_id_value, 
                    params 
                );                
                break;
        }
    }
    catch( err )
    {
        swal( "Error", "Domain: " + hex + " (" + err + ")", "error" );
        
        batch_progress.setText( "Error");
        batch_domain_n = 0;
        $('#btn_batch_claim').prop('disabled', false );                
        $('#btn_batch_price').prop('disabled', false );                
        $('#btn_batch_prolong').prop('disabled', false );                
        $('#btn_batch_domain_cancel').prop('disabled', true );       
        $("#batch_title").text( "No active process")
        batch_is_active = false;
        
        try 
        {
            $("#stat_domains").text( contract.n_domains() );
            updateDomainPage()
        }
        catch( x ) {}
        
        return;
    } 
    
    batch_domain_n++;
    batch_progress.animate( batch_domain_n / batch_domain_list.length );
    
    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);
}


$().ready( function(e){ 
    $( "#tabs" ).tabs(
        {
            beforeActivate: function( event, ui ) 
            {
                if( ui.newPanel[0].id == "tabs-all" ) {
                    
                    //if( all_domains_data.length == 0 ) refreshAllDomains();
                }
                if( ui.newPanel[0].id == "tabs-batch" ) {
                    
                    try
                    {
                        my_accounts = web3.eth.accounts;      

                        $("#batch_claim_my_address").empty();

                        for( var i = 0; i < my_accounts.length; i++ )
                        $("#batch_claim_my_address")
                            .append( $("<option>").val( my_accounts[i] ).text( 
                                no0x(my_accounts[i]) + 
                                " (" + formatEther( web3.eth.getBalance( my_accounts[i] ), "ETH" ) + ")"                                            
                            ) );        

                        lua = Cookies.get('etherid_last_used_address'); 
                        if( lua ) $("#batch_claim_my_address").val( lua )
                    }
                    catch( x ) 
                    {
                        swal("Web3 Error!", "Cannot connect to the Ethereum network. Please install and run an Ethereum client. \n(" + x + ")", "error" ) 
                    }                
                }
            }    
        }
    );    
    
    
    batch_progress = new ProgressBar.Circle('#batch_progress', {
        color: '#59869b',
        duration: 500,
        easing: 'easeInOut',
        strokeWidth: 2
    });

    update_list_progress = new ProgressBar.Circle('#update_list_progress', {
        color: '#59869b',
        duration: 500,
        easing: 'easeInOut',
        strokeWidth: 2
    });

    try
    {
        if( web3.currentProvider == null )
            web3.setProvider( new web3.providers.HttpProvider( ) );    
        
//        if(typeof web3 === 'undefined')
//            web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); //8545 8080         
        
        contract = getContract();        
        $("#stat_domains").text( contract.n_domains() );
//        root_domain = web3.toHex( contract.root_domain() );
//        alert( root_domain )
    }
    catch( x ) {
        x = x;
    }
    
    $("input#search_domain").keyup(function( event ) {
        if( event.keyCode == 13 ) $("#btn_search_domain").click()
    });
    

    $("#btn_all_refresh").click( function() { refreshAllDomains( false ); } );
    $("#btn_all_cancel").click( function() { all_domains_cancel = true; } );
    $("#btn_download_all").click( function() { refreshAllDomains( true ); } ); 
    
    
    $("#btn_batch_prolong").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }       

        swal({   
            title: "Are you sure?",   
            text: "You are about to prolong " + batch_domain_list.length + 
                    " domains."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, prolong!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm ) 
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "prolong";
                    $("#batch_title").text( "Prolonging in progress...")



                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });
    
    $("#btn_batch_price").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }
        
        price_in_eth = $("#batch_price").val()
        batch_price = web3.toWei( new BigNumber( price_in_eth ), "ether" );
            

        swal({   
            title: "Are you sure?",   
            text: "You are about to set price for " + batch_domain_list.length + 
                    " domains to " + formatEther( batch_price, "ETH") + "."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, set price!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm )
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "price";
                    $("#batch_title").text( "Pricing in progress...")



                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });

    $("#btn_batch_id").click( function() { 
        batch_domain_list = []
        
        list = $("#batch_list").val();
        res = list.split(/[\s\,;\t\"\']+/);
        
        for( var i = 0; i < res.length; i++ )
        {
            n = res[i].trim();
            if( n == "" ) continue;
            
            batch_domain_list.push( n );
            
        }
        
        if( batch_domain_list.length == 0 ) {
            swal("List Error!", "Cannot recognize any valid names in the list", "error" ) 
            return;
        }
        
        iv = $("#batch_id").val()
        batch_id = ""
        if( iv.substring( 0, 2 ) === "0x" ) 
        {    
            a = hexToArray( iv )
            batch_id = arrayToHex( a )    
            batch_id = "0x" + batch_id.substr( 0, 64 )
        }
        else
        {
            utf = utf8.encode( iv ).slice(0, 32);
            batch_id = "0x" + asciiToHex( utf )    
        }        
        
        iv = $("#batch_value").val()
        batch_id_value = ""
        if( iv.substring( 0, 2 ) === "0x" ) 
        {    
            a = hexToArray( iv )
            batch_id_value = arrayToHex( a )    
            batch_id_value = "0x" + batch_id_value.substr( 0, 64 )
        }
        else
        {
            utf = utf8.encode( iv ).slice(0, 32);
            batch_id_value = "0x" + asciiToHex( utf )    
        } 
        
        if( new BigNumber( batch_id ) == 0 || new BigNumber( batch_id_value ) == 0 )
        {
            swal("Error!", "ID and value should not be empty", "error" ) 
            return;            
        }

        swal({   
            title: "Are you sure?",   
            text: "You are about to change id " + batch_id + " for " + batch_domain_list.length +  
                    " domains to " + formatEther( batch_price, "ETH") + "."  ,   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonText: "Yes, change ID!",
            closeOnConfirm: true,    
            },
            function(isConfirm){   
                if( isConfirm )
                {
                    batch_progress.setText( "");
                    batch_progress.animate( 0 );
                    batch_domain_n = 0;
                    batch_domain_process = "id";
                    $("#batch_title").text( "ID changing in progress...")

                    $('#btn_batch_claim').prop('disabled',true );                
                    $('#btn_batch_price').prop('disabled',true );                
                    $('#btn_batch_prolong').prop('disabled',true );                
                    $('#btn_batch_domain_cancel').prop('disabled',false );                
                    batch_domain_cancel = false;
                    batch_is_active = true;

                    setTimeout( processBatch, BATCH_PROCESS_TIMEOUT);          
                }
            }
        );        
        
    });
    
    
    $("#btn_download_ascii").click( function() { 
        var csv = "";
        
        for( var i = 0; i < all_domains_data.length; i++ )
        {
            csv += all_domains_data[i].name() + "\n";
        }
        
        var downloadLink = document.createElement("a");
        var blob = new Blob([ csv ] );
        var url = URL.createObjectURL(blob);
        downloadLink.href = url;
        downloadLink.target = "names.csv";
        downloadLink.download = "names.csv";        

        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
    });
        
    $("#btn_download_hex").click( function() { 
        var csv = "";
        
        for( var i = 0; i < all_domains_data.length; i++ )
        {
            csv += all_domains_data[i].name_hex() + "\n";
        }
        
        var downloadLink = document.createElement("a");
        var blob = new Blob([ csv ] );
        var url = URL.createObjectURL(blob);
        downloadLink.href = url;
        downloadLink.target = "hex.csv";
        downloadLink.download = "hex.csv";        

        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);        
    });
{'fraction_non_alphanumeric': 0.1445589859569768, 'fraction_numerical': 0.01630463367169831, 'mean_word_length': 1.4453089833451225, 'pattern_counts': {'":': 182, '<': 17, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 45, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7083290', 'n_tokens_mistral': 11156, 'n_tokens_neox': 10374, 'n_words': 1825}