function homeShowAuctionsTable(what){
	var cb = new Array('homeController','DisplayAuctions_table');
	var params = what ;
	var rpc = new Array(cb, params);
	setCookie('homepage_what',what,10);
	new Ajax.Request ('/rpc/', {
		method: 'post',
		onSuccess: doResponse_homeShowAuctionsTable,
		onFailure: null,
		parameters: 'rpc='+rpc.toJSON()});

}
function doResponse_homeShowAuctionsTable(resp){
	$('auctions_table').innerHTML = resp.responseText;
	if(typeof(ExpCountDown)=='function'){
		ExpCountDown();
	};
}


function setCookie(c_name,value,expiredays)
{
	//console.log('cookie '+c_name+'  '+value+'  '+expiredays);
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function timeFormat(ttl){
	if (ttl < 0) return 'Expirat';
	var sec = ttl%60;
	var min = Math.floor(ttl/60);
	var hour = Math.floor(min/60);
	var min = min%60;

	return   min + ' m ' + sec + ' s';
}
var ExpCountDownRunning = 0;
function ExpCountDown(selfCall){
	//console.log(selfCall);

	//console.log(ExpCountDownRunning);
	if (ExpCountDownRunning == 1 && selfCall == 'undefined') return false;

	ExpCountDownRunning = 1;
	$j('.counter_data').each(function(i){
		//var ExpCountDownRunning;



				//if (i == 0) console.log(i+' '+this.value);
				var ttl = this.value;
				$j('#'+this.name).html(timeFormat(ttl));
				if (ttl == 0){
					$j('#'+this.name).parent('td').fadeTo('slow',0.33);
					this.value = -1;
				} else if(this.value < 0){

				} else {

					//console.log($j('#'+this.name).html());
					if (ttl >= 1)
	  					this.value = ttl - 1;
					else
						this.value = 0;
				}
 	});

 	setTimeout("ExpCountDown(1)", 1000);
}
