function _download_popup (id, title) {
	$('download_form_1').show();	
	$('download_form_2').hide();
	$('downloadi_form_1').show();
	$('downloadi_form_2').hide();
	if ($('win_02')) register_win.close();
	if ($('win_03')) terms_win.close();
	if ($('win_04')) error_win.close();
	$('download_parola').value = '';
	$('download_i_form').reset();
	$('terms_yes').checked=false;
	$('terms_no').checked=false;

	if(!$('win_01')) {
		download_win = new Window({id: 'win_01', className: "main", title: "", width:180, height:90, resizable: false, minimizable: false, maximizable: false, closable: true, recenterAuto: true});	
		download_win.setContent(id);
	}
	download_win.setTitle(title);
	download_win.showCenter();
	download_win.updateWidth();
	download_win.updateHeight();

	download_win.setCloseCallback(function () {
		if($('win_04')) error_win.close();
		return true;
	});
}

function _download_popup1 (id, title) {
	if(!$('win_02')) {
		register_win = new Window({id: 'win_02', className: "main", title: "", width:180, height:90, resizable: false, minimizable: false, maximizable: false, closable: true, recenterAuto: true});	
		register_win.setContent(id);
	}
	register_win.setTitle(title);
	register_win.showCenter();
	register_win.updateWidth();
	register_win.updateHeight();
	register_win.setCloseCallback(function () {
		if($('win_03')) terms_win.close();
		if($('win_04')) error_win.close();
		return true;
	});
}

function _download_popup2 (id, title) {
	if(!$('win_03')) {
		terms_win = new Window({id: 'win_03', className: "main", title: "", width:250, height:350, resizable: false, minimizable: false, maximizable: false, closable: true, recenterAuto: false});	
		terms_win.setContent(id);
	}
	terms_win.setTitle(title);
	terms_win.showCenter();
	terms_win.updateWidth();
	terms_win.updateHeight();
}

function download_form_check (title) {
	if (is_empty($('download_parola').value)) {
		_error_popup('download_error', 4, title);
		return false;
	}
	return true;
}

function downloadi_form_check (title) {
	if (is_empty($('downloadi_firstname').value) || is_empty($('downloadi_lastname').value) || is_empty($('downloadi_email').value) || is_empty($('downloadi_company').value)) {
		_error_popup('download_error', 1, title);
		return false;
	}
	if (!is_email($('downloadi_email').value)) {
		_error_popup('download_error', 2, title);
		return false;
	}
	if (!$('downloadi_terms').checked) {
		_error_popup('download_error', 3, title);
		return false;
	}
	return true;
}

function downloadi_form_submit() {
	$('downloadi_form_1').hide();
	$('downloadi_form_2').show();
	register_win.setSize(200, 50);
	
	$('download_i_form').request({
		onSuccess: function(transport){ 
			$('downloadi_form_2').update(transport.responseText); 
			register_win.setSize(200, 90);
		}
	});
}

function _error_popup (id, p, title) {	
	if(!$('win_04')) {
		error_win = new Window({id: 'win_04', className: "error", title: "", width:200, height:60, resizable: false, minimizable: false, maximizable: false, closable: true, recenterAuto: false});	
		error_win.setContent(id);
	}

	var d = $(id).getElementsByClassName('derror');
	
	for(var k=0; k<d.length; k++) {
		d[k].hide();
	}		
	$('download_error_'+p).show();
	
	error_win.setTitle(title);
	error_win.showCenter();
	error_win.updateWidth();
	error_win.updateHeight();
}

function _announce_popup (id, title, w, h) {
	if(!$('win_05')) {
		announce_win = new Window({id: 'win_05', className: "error", title: "", width:420, height:420, resizable: false, minimizable: false, maximizable: false, closable: true, recenterAuto: false});	
		announce_win.setContent(id);
	}
	announce_win.setTitle(title);
	announce_win.setSize(w*1+20, h*1+20);
	announce_win.showCenter();
}