function _(name) {return document.getElementById(name);}
Util={}
Util.formatTime=function(/*long*/time) {
	return parseInt(time)/60/60 +":"+ parseInt(time)/60%60+":"+ parseInt(time)%60+"."+ parseInt(time)%1000;
}
Util.lpad=function(/*long*/ num) {if (num<10){return "0"+num;} else {return ""+num;}}
Util.formatHHMMSS=function(/*long*/ time) {
	time=parseInt(time);
	return Util.lpad(Math.floor(time/60/60/1000))+":"+Util.lpad(Math.floor(time/60/1000)%60)+":"+Util.lpad(Math.floor(time/1000)%60);
}
Util.init=function () {
	$(window).scroll(function()	{
		$('#errorDisplay').animate({top:($(window).scrollTop())+"px" },{queue: false, duration: 350});
	});
	$(window).scroll(function()	{
		$('#messageDisplay').animate({top:($(window).scrollTop())+"px" },{queue: false, duration: 350});
	});
	$(window).scroll(function()	{
		$('#loadingDisplay').animate({top:($(window).scrollTop())+"px" },{queue: false, duration: 350});
	});
	var infowidth = 280;
	$(window).bind('resize', function() {
		$('#errorDisplay').css("left",($(window).width()-infowidth)+"px");
		$('#messageDisplay').css("left",($(window).width()-infowidth)+"px");
		$('#loadingDisplay').css("left",($(window).width()-infowidth)+"px");
	});
	$('#errorDisplay').css("left",($(window).width()-infowidth)+"px");
	$('#messageDisplay').css("left",($(window).width()-infowidth)+"px");
	$('#loadingDisplay').css("left",($(window).width()-infowidth)+"px");
	$('#errorDisplay').css("top","0px");
	$('#messageDisplay').css("top","0px");
	$('#loadingDisplay').css("top","0px");
	// ie warning
	$('#ie_warning_dialog').dialog({
		autoOpen: false,
		width: 400,
		height: 490,
		resizable: false,
		buttons: {"Ok": function() { $(this).dialog("close"); }  }
	});
	if ($.browser.msie) {
		$('#ie_warning_dialog').dialog('open');
	}
}
Util.contains=function( /*Array*/ list ,field, /*Any*/ obj) {
	for (var i=0;i<list.length;i++) {
		if (field) {
			if (list[i][field] == obj) {return true;}
		}
		else if (list[i] == obj) {return true;}
	}
	return false;
}
Util.showError=function(errors) {
	var html = errors.join("<br/>");
	$("#errorMessage").empty().append(html);
	$("#errorDisplay").css("display","block");
	setTimeout(function() {
		$("#errorDisplay").css("display","none");
	},3000)
}
Util.showMessage=function(text,noClear) {
	$("#message").empty().append(text);
	$("#messageDisplay").css("display","block");
	if (!noClear) {
		setTimeout(function() {
			$("#messageDisplay").css("display","none");
		},3000)
	}
}
Util.clearMessage=function(text) {
	$("#messageDisplay").css("display","none");
}
Util.showLoading=function(text) {
	$("#loadingDisplay").css("display","block");
}
Util.hideLoading=function(text) {
	$("#loadingDisplay").css("display","none");
}
/*
// doesn't work !!
Util.cloneEmpty=function (obj) {
	var newObj={};
	for (var attr in obj) {
		if (obj.length!=undefined && typeof(obj.length)!='function') {// array
			newObj[attr]=new Array();
		} else if (typeof(newObj)=='object') {// object
			newObj[attr]=Util.cloneEmpty(obj[attr]);
		} else {
			newObj[attr]="";
		}
	}
	return newObj;
}
*/
Util.getAds=function() {
	// get the ads
	$("#titleAds").append($("#loadAds"));
}
Util.showHelp=function() {
	window.open("http://mypodhelp.blogspot.com","_blank");
}
Util.showFourms=function() {
	window.open("http://my-pod.org/forums","_blank");
}
Util.scrollToView=function(selector) {
	$('html,body').animate({scrollTop: $(selector).offset().top-0},500);
}
///// Downloads stuff ///////////////////////////////////////////
Util.dlUpdateTimer=0;
Util.initDownload=function(){
	$('span#dl_progress').progressbar({ value: 0 });
	$('span#dl_currFile').empty().append("The title");
	$('span#dl_status').empty().append("status");
	$('span#dl_nqueued').empty().append("0");
	$('span#dl_nfinished').empty().append("0");
	$('span#dl_nsuccess').empty().append("0");
	Util.dlUpdateTimer=setInterval("Util.updateDownloads()",10000);
}
Util.updateDownloads=function() {
	$.getJSON("?command=db&action=dlstat", 
		function (data) {
			if (data && data.dlstat) {
				if (data.dlstat.current) {
					$('span#dl_progress').progressbar('option', 'value', data.dlstat.current.progress);
					$('span#dl_currFile').empty().append(data.dlstat.current.title);
					$('span#dl_status').empty().append(data.dlstat.current.status);
				} else {
					$('span#dl_progress').progressbar('option', 'value', 0);
					$('span#dl_currFile').empty().append("Nothing Downloading ... ");
					$('span#dl_status').empty().append("Ready");
				}
				$('span#dl_pause_lbl').empty().append(data.dlstat.paused?"Resume:":"Pause");
				$('img#dl_pause_but').attr("src",data.dlstat.paused?"/drawable/butt_dl_play_off_32.png":"/drawable/butt_dl_pause_off_32.png");
				$('span#dl_nqueued').empty().append(data.dlstat.queue);
				$('span#dl_nfinished').empty().append(data.dlstat.finished);
				$('span#dl_nsuccess').empty().append(data.dlstat.success);
				if (data.dlstat.update) {
					File.getAllFiles();
				}
			}
		}
	);
}
Util.dlPauseOrResume=function(){
	$.getJSON("?command=db&action=dlpauseresume", 
		function (data) {
			if (data && data.result && data.result=='OK') {
				$('span#dl_pause_lbl').empty().append(data.paused?"Resume:":"Pause");
				$('img#dl_pause_but').attr("src",data.paused?"/drawable/butt_dl_play_off_32.png":"/drawable/butt_dl_pause_off_32.png");
			}
	});
}
