function popup(theURL, winName, winWidth, winHeight, features)
{
	if (winWidth > (screen.width-100))
	{
		winWidth = screen.width-100;
	}

	if (winHeight > (screen.height-100))
	{
		winHeight = screen.height-100;
	}

	var w = (screen.width - winWidth)/2;
	var h = (screen.height - winHeight)/2 - 100;
	var features = features+',width='+winWidth+',height='+winHeight+',top='+h+',left='+w;

	_popup = window.open(theURL, winName, features);
	try {
		if(_popup == null) {
			return true;
		}
		if (window.opera) {
			if (!_popup.opera) {
				return true;
			}
		}
	} catch(e) {
		return true;
	}
	
	return false;
}

function auto_details_popup(auto_id)
{
	var theURL = '/content/office/auto_details.php?id='+auto_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 50);
	var winHeight = 620;//screen.height - 290;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function load_details_popup(load_id)
{
	var theURL = '/content/office/load_details.php?id='+load_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 620;//screen.height - 290;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function load_preview_popup(no)
{
	var theURL = '/content/office/load_preview.php?no='+no;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 620;//screen.height - 290;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function owner_details_auto_popup(uid)
{
	var theURL = '/content/office/owner_details_auto_popup.php?id='+uid;
	var winName = '';
	var winWidth = parseInt(screen.width - 300);
	var winHeight = 400;//screen.height - 290;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}
function owner_details_load_popup(uid)
{
	var theURL = '/content/office/owner_details_load_popup.php?id='+uid;
	var winName = '';
	var winWidth = parseInt(screen.width - 300);
	var winHeight = 400;//screen.height - 290;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function blocked_owner_auto_popup(owner_id)
{
	var theURL = '/content/office/auto_by_owner_popup.php?blocked=1&oid='+owner_id;
	var winName = '';
	var winWidth = parseInt(screen.width - 100);
	var winHeight = screen.height - 150;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myauto_auto_edit_popup(action, auto_id, sheet)
{
	if(!sheet) {
		sheet = '0';
	}
	var theURL = '/content/office/myauto_auto_edit.php?action='+action+'&aid='+auto_id+'&sheet='+sheet;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 50);
	var winHeight = 620;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myaoffs_aoff_edit_popup(action, aoff_id, auto_id)
{
	var theURL = '/content/office/myaoffs_aoff_edit.php?action='+action+'&ao_id='+aoff_id+'&aid='+auto_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myloads_load_edit_popup(action, load_id, sheet)
{
	if(!sheet) {
		sheet = 0;
	}
	var theURL = '/content/office/myloads_load_edit.php?action='+action+'&oid='+load_id+'&sheet='+sheet;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myloffs_loff_edit_popup(action, loff_id, load_id)
{
	var theURL = '/content/office/myloffs_loff_edit.php?action='+action+'&lo_id='+loff_id+'&lid='+load_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function add_master_popup(what)
{
	var theURL = '/add_master.php?what='+what;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 57);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myroutes_route_edit_popup(action, route_id, in_city)
{
	var theURL = '/content/office/myroutes_route_edit.php?action='+action+'&rid='+route_id;
	if(in_city) {
		theURL = theURL + '&in_city=1';
	}
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 50);
	var winHeight = 400;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function myauto_cont_edit_popup(action, cont_id)
{
	var theURL = '/content/office/myauto_cont_edit.php?action='+action+'&cid='+cont_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 - 50);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function contact_details_popup(cont_id)
{
	var theURL = '/content/office/contact_details.php?cid='+cont_id;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 - 50);
	var winHeight = 600;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function act_mob_popup(msg)
{
	var theURL = '/content/office/popup_act_mob.php?msg='+msg;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 - 50);
	var winHeight = 230;
	var features = '';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function balance_details_popup(href) {
	var theURL = href;
	var winName = '';
	var winWidth = parseInt(screen.width / 2 + 150);
	var winHeight = screen.height - 150;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}

function help_details_popup(topic, w, h) {
	if(!w) {
		w = 450;
	}
	if(!h) {
		h = 300;
	}
	var theURL = '/content/help.php?topic='+topic;
	var winName = 'Справка';
	var winWidth = w;
	var winHeight = h;
	var features = 'resizable,scrollbars';
	return popup(theURL, winName, winWidth, winHeight, features);
}