// random-banner.js

//  2006/10/10  Last update under Ajax boom
//  2010/06/06  Relative path

var BANNER_LIST = "http://www.kawa.net/ad/banner-linkshare.txt";

if (location.href.search(/net.xp.index-..html/)>0) {
	BANNER_LIST = BANNER_LIST.replace(/^http:..www.kawa.net/, '..');
}

function banner_update ( data, area ) {
    if ( ! data ) return;

    var lines = data.split( /\n/ );
    var items = [];

    for( var i=0; i<lines.length; ++i ) {
        if ( lines[i].match( /^#/ )) continue;
        if ( ! lines[i].match( /</ )) continue;
        items[items.length] = lines[i];
    }

    var rand = Math.floor( Math.random()*lines.length );
    if ( ! items[rand] ) rand = Math.floor( Math.random()*lines.length );
    if ( ! items[rand] ) rand = Math.floor( Math.random()*lines.length );
    if ( ! items[rand] ) rand = Math.floor( Math.random()*lines.length );
    if ( ! items[rand] ) return;
    var here = document.getElementById(area);
    here.innerHTML = items[rand];
};

function get_banner ( area ) {
    var http = new JKL.ParseXML.Text( BANNER_LIST );
    var func = function ( data ) {
        banner_update( data, area );
    };
    http.async( func );
    http.parse();
};

