var start = 0;
$(function(){
	$('.sel').live('click',function(){
		$(this).removeClass('sel');
		$(this).addClass('notSel');
		$('input',$(this)).attr('checked','');
		return false;
	});
	
	$('.notSel').live('click',function(){
		$(this).removeClass('notSel');
		$(this).addClass('sel');
		$('input',$(this)).attr('checked','checked');
		return false;
	});
});

function getStatus(id){
	var str='';
	$('.uploading').each(function(){
		str += $(this).text()+',';
	});
	
	$.post('index/status',{servers: str, id: id}, function(data){
		for(var i=0;i<data.length;i++){
			$('#'+data[i].server).removeClass('uploading');
			$('#'+data[i].server).attr('href',data[i].link);
			$('img', $('#'+data[i].server)).remove();
		}
		if($('.uploading').size())setTimeout('getStatus('+id+')',6000);
	},'json');
}

function upload(){
	var str;
	$('#overlay').show();
	if(!$('input:checked').size() || !($('#overlay').html())){
		$('#overlay').hide();
		$('#error').remove();
		$('#upload_form').prepend('<p id="error">Nu ati selectat un server sau un fisier</p>');
	} else {
		$('input:checked').each(function(i){
			str += "&server[]="+$(this).val();
		});
		str += "&PHPSESSID="+sessid;
		$('#fileBrowse').fileUploadSettings('scriptData',str);	
		$('#fileBrowse').fileUploadStart();
	}
}