function show_edit_dict(id)
{
	$('#dict_' + id).css('display','none');
	$('#dict_edit_' + id).css('display','block');
}

function submitsearch()
{
	showhidesearchbutton(1);
	var sGet = 'articul=';
	if ($('#articul').val() != '[ Артикул ]') sGet += $('#articul').val();
	sGet += '&name=';
	if ($('#name').val() != '[ Название ]') sGet += $('#name').val();
	sGet += '&country=' + $('#country').val();
	sGet += '&color=' + $('#color').val();
	sGet += '&manuf=' + $('#manuf').val();
	sGet += '&cid=' + $('#cid').val();
	sGet += '&perp=' + $('#perp').val();
	sGet += '&view=' + $('#view').val();
	$('#results').load('_ajSearch.php?' + sGet, {}, showhidesearchbutton);
	window.location.hash = sGet;
}

function setsearchparams(cid,manuf_id,country_id,color_id)
{
	$('#cid').val(cid);
	$('#manuf').val(manuf_id);
	$('#country').val(country_id);
	$('#color').val(color_id);
}

function showhidesearchbutton(type)
{
	if (type == 1) {
		$('#sbutton').css('display','none');
		$('#searching').css('display','inline');
	} else {
		$('#sbutton').css('display','inline');
		$('#searching').css('display','none');
	}
}

function reloadsearchresults()
{
	var sGet = document.location.hash;
	sGet = sGet.replace('#','');
	var aGet = sGet.split('&');
	for (c=0;c<aGet.length;c++) {
		var aParts = aGet[c].split('=');
		if (aParts[1]) $('#' + aParts[0]).val(aParts[1]);
	}
	$('#results').load('_ajSearch.php?' + sGet);
}

function chpage(page)
{
	sGet = document.location.hash;
	sGet = sGet.replace('#','');
	if (sGet.match(/page=\d/i)) {
		sGet = sGet.replace(/page=\d+/i,'page=' + page);
	} else {
		if (sGet) sGet = sGet + '&';
		sGet = sGet + 'page=' + page;
	}
	$('#results').load('_ajSearch.php?' + sGet);
	window.location.hash = sGet;
}

function loadcalc(params)
{
	$('#results').load('_ajCalc.php?' + params);
}

function submitcalc(sGet,butObj)
{
	if (butObj)
	{
		butObj.value = 'Подождите...';
		butObj.disabled = true;
	}
	sGet += '&width=' + $('#width').val();
	sGet += '&height=' + $('#height').val();
	sGet += '&q=' + $('#q').val();
	if ($('#vo').attr("checked")) {
		sGet += '&vo=1';
		sGet += '&vo_w=' + $('#vo_w').val();
		sGet += '&vo_h=' + $('#vo_h').val();
	}
	if ($('#po').attr("checked")) {
		sGet += '&po=1';
		sGet += '&po_w=' + $('#po_w').val();
		sGet += '&po_h=' + $('#po_h').val();
	}
	if ($('#mob').attr("checked")) sGet += '&mob=1';
	if ($('#mo').attr("checked")) sGet += '&mo=1';
	if ($('#dost').attr("checked")) sGet += '&dost=1';
	loadcalc(sGet);
}


function submitbask(sGet,butObj)
{
	if (butObj)
	{
		butObj.value = 'Подождите...';
		butObj.disabled = true;
	}
	sGet += '&name1=' + encodeURIComponent($('#name1').val());
	sGet += '&name2=' + encodeURIComponent($('#name2').val());
	sGet += '&phone1=' + encodeURIComponent($('#phone1').val());
	sGet += '&phone2=' + encodeURIComponent($('#phone2').val());
	sGet += '&email=' + encodeURIComponent($('#email').val());
	sGet += '&obj=' + $('#obj').val();
	loadcalc(sGet);
}

function vopo(checked,obj)
{
	if (checked)
	{
		$('#'+obj+'_d').css('visibility','visible');
	} else {
		$('#'+obj+'_d').css('visibility','hidden');
	}
}

function showeditgps(field,id)
{
	position = $('#field_' + field + '_' + id).position();
	$('#edit_container').show();
	$('#edit_container').css('left',position.left+5);
	$('#edit_container').css('top',position.top+5);
	$('#edit_container').load('gps.php?action=edit&field=' + field + '&id=' + id);
}

function savegps(field,id)
{
	$('#field_' + field + '_' + id).load('gps.php?action=save&field=' + field + '&id=' + id + '&value=' + encodeURIComponent($('#edit_field').val()));
	$('#edit_container').hide();
	$('#edit_container').html('');
	$('#edit_container').css('left',0);
	$('#edit_container').css('top',0);
}

function canceleditgps(field,id)
{
	$('#edit_container').hide();
	$('#edit_container').html('');
	$('#edit_container').css('left',0);
	$('#edit_container').css('top',0);
}

function showeditbutton(field,id)
{
	$('#editbutton_' + field + '_' + id).show();
	$('#field_' + field + '_' + id).css('backgroundColor','#fff775');
}

function hideeditbutton(field,id)
{
	$('#editbutton_' + field + '_' + id).hide();
	$('#field_' + field + '_' + id).css('backgroundColor','#FFFFFF');
}

function showapproveurl(text,url)
{
	if (window.confirm(text)) document.location.href = url;
}

function loadbasket(iItemID)
{
	$('#basket').load('/price/_ajBasket.php?add=' + iItemID);
}
