
function sfFocus(element)
{
	var val = jQuery(element).val();
	if (val=='Поиск по товарам')
	{
		jQuery(element).val('');
	}


}

function sfOrderProducts(url, type)
{
	location.href = url + type;
}

function hkObj(id) {
	return document.getElementById(id);
}


function hkPopupWindow(url,width,height,scroll) {
	var popUpWin = 0;
	
	if (scroll==null) scroll=false;
	
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}

	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var scrolling = (scroll)?'yes':'no';

	popUpWin = open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrolling+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}

function hkFilesetAddTableRow(tableId, formName, elementName) {
	var table = hkObj(tableId);
	if (!table) return;

	var lastRowIdx = table.rows.length;
	
	var row = table.insertRow(lastRowIdx);
	row.id = "idRow" + elementName + lastRowIdx;

	var cell_1 = row.insertCell(0);
	cell_1.style.padding = '0px';
	cell_1.style.margin = '0px';

	var input = document.createElement('input');
	input.type = 'file';
	input.name = formName + '[' + elementName + '][]';
	input.id = 'idFile' + row.id;
	input.style.border = 'solid 1px #727272';
	input.style.width = '230px';
	
	cell_1.appendChild(input);

	var cell_2 = row.insertCell(1);
	
	var a = document.createElement('a');
	a.href= "javascript: hkFilesetDeleteTableRow('" + tableId + "', '" + row.id +"')";
	a.name = 'remove file';
	var text = document.createTextNode('убрать');
	a.appendChild(text);

	cell_2.appendChild(a);
}

function hkFilesetDeleteTableRow(tableId, rowId) {
	var table = document.getElementById(tableId);
	if (!table) return;
	for (var i=0; i<table.rows.length; i++) {
		var row = table.rows[i];
		if (row.id==rowId) {
			table.deleteRow(i);
		}
	}
}


function hkToggleBlockDisplay(id) {
	var obj = hkObj(id);
	if (obj && obj.style) {
		if (obj.style.display=='none') obj.style.display = '';
		else obj.style.display = 'none';
	}
}

function hkShowBlock(id) {
	var obj = hkObj(id);
	if (obj) {
		obj.style.display = '';
	}
}

function hkHideBlock(id) {
	var obj = hkObj(id);
	if (obj) {
		obj.style.display = 'none';
	}
}

function showImage(what,w,h,root,title) {
	var scroll=0;
	if (w>screen.width) {
		w=screen.width;
		scroll=1;
	}
	if (h>screen.height) {
		h=screen.height;
		scroll=1;
	}

	var left = (screen.width/2) - w/2;
  	var top = (screen.height/2) - h/2;

	var opt='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scroll+',height='+h+',width='+w+',top='+top+',left='+left;
	
	var titleAdd = '';
	if (title) {
		titleAdd = '&title='+escape(title);
	}
	
	var wnd= window.open(root+'showimage.php?name='+what+titleAdd,'',opt);
	wnd.focus();
}