var refreshTime=5000;			//5000ms=5 secs
var numAds=0;
var current_ad=0;
var ads=new Array();
var myCode='';
		
function getTheAd(){
	jsrsExecute('select_rs.php', displayAds, 'getAdInfo', '');
}
function displayAds(stuff){
	stuff=stuff.substring(0, (stuff.length-1));
	var adArray=stuff.split('|');
	numAds=adArray.length;
	for (var i=1; i<=numAds; i++){
		ads[i]=new makeAd();
	}	
	i=1;
	for (var a=0; a<adArray.length; a++){
		var adInfo=adArray[a].split('~');	
		ads[i].width="177";		
		ads[i].height="128";
		ads[i].src="image.php?id="+adInfo[0];
		ads[i].href="directory.php?action=advertise&id="+adInfo[0];
		ads[i].alt=adInfo[1];
		i++;		
	}
	do{
		var n=Math.floor(Math.random()*(numAds+1)+1);
	} while (n>numAds);
	current_ad=n;
	myCode=getCode(n);
	document.getElementById('bannerAd').innerHTML=myCode;
}
function makeAd(){
	this.width='';
	this.height='';
	this.src='';
	this.href='';
	this.alt='';
}
function getCode(adNumber){
	var tempCode='';
	tempCode+=('<a href="'+ads[adNumber].href+'">\n');
	tempCode+=('<img src="'+ads[adNumber].src+'" border=0 width='+ads[adNumber].width+' height='+ads[adNumber].height);
	tempCode+=(' onLoad="setTimeout(\'newAd();\','+refreshTime+');"');
	tempCode+=(' alt="'+ads[adNumber].alt+'" title="'+ads[adNumber].alt+'">\n');
	tempCode+=('</a>');
	return tempCode;
}
function newAd(){	
	current_ad++;
	if (current_ad>numAds) 
		current_ad=1;
	
	myCode=getCode(current_ad);
	document.getElementById('bannerAd').innerHTML=myCode;
}