var isIE		= (navigator.appName.indexOf('Internet Explorer') != -1);
var isOpera		= (navigator.userAgent.indexOf("Opera")>-1);
var isBlocked 	= false;

function replbyscript(id, src, width, height)
{
	document.getElementById(id).src = '/com/scr/preview.php?image=store/'+src+'&h='+height+'&w='+width;
	document.getElementById(id).parentNode.href = '/proj/food/upload/store/'+src;

	window.location = '#';
}

function mypost(url,query,imgname,id)
{
	url = url.replace('.html', '.xml');

	if (url)
	{

		var ajaxload = '<img style="margin-left:95px; margin-right:4px; float:left;" src="'+imgname+'" /> Загрузка...';
		document.getElementById(id).innerHTML = ajaxload;


		JsRequest.openPOST(url, query);

		return false;
	}
	else
	{
		return true;
	}
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

function printPage() {
if (window.print)
    window.print()
	else
	alert( "Извините, но Ваш браузер не поддерживает печать страниц. Попробуйте воспользоваться опцией ПЕЧАТЬ в другом брайзере");
}

function formToUrl(obj)
{
	var elem = obj.elements;
	var url = '';

	for (var i=0; i<elem.length; i++)
	{
		if (elem[i] && elem[i].name && elem[i].name != '_dont_save_')
		{
			if (elem[i].type == 'radio' || elem[i].type == 'checkbox')
			{
				if (elem[i].checked) url = url + elem[i].name + '=' + encodeURIComponent(elem[i].value) + '&';
			}
			else url = url + elem[i].name + '=' + encodeURIComponent(elem[i].value) + '&';
		}
	}

	return url;
}

function set_StoreValue(number, id, title)
{
	document.getElementById('store_good_id').value = id;
	document.getElementById('store_number').value = number;
	document.getElementById('store_title').value = title;
	//document.getElementById('store_form').action='http://food/index/basket/form/index.html?form=1&amp;menu_id=0';
	return true;
}

function getClientWidth()
{
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function hide_show(name)
{
	var inf = document.getElementById(name);
	if (inf.style.display == 'none')
	{
		inf.style.display = 'block';
	}
	else
	{
		inf.style.display = 'none';
	}
}

function block()
{
	try {

		var blocking = document.getElementById('blocking');
		if (isIE) blocking.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(opacity=0.4)";
			else blocking.style.opacity = 0.4;

		blocking.style.width = getDocumentWidth() + 'px';
		blocking.style.height = document.getElementById('allPage').offsetHeight + 'px';

	} catch (e) { }

	try {
		var blocking = document.getElementById('loading');
		var x = getClientWidth() / 2 - 23;
		var y = getClientHeight() / 2 - 23;
		blocking.style.left = x + "px";
		blocking.style.top = y + "px";
	} catch (e) { }

	try
	{
		document.getElementById('blocking').style.display = 'block';
		isBlocked = true;
	} catch (e) {}
}

function unblock(scrollUp, offOnLoad)
{
	try
	{
		document.getElementById('blocking').style.display = 'none';
		document.getElementById('loading').style.display = 'none';
		isBlocked = false;

		if (scrollUp == 'yes') document.body.scrollTop = 0;
	} catch (e) {}
}

function searchsel(num)
{
	if (document.getElementById('search_stype') && document.getElementById('search_a') && document.getElementById('search_a1') && document.getElementById('search_a2') && document.getElementById('search_a3'))
	{
		var s = document.getElementById('search_stype');
		var a = document.getElementById('search_a');
		var a1 = document.getElementById('search_a1');
		var a2 = document.getElementById('search_a2');
		var a3 = document.getElementById('search_a3');
		a1.className = '';
		a2.className = '';
		a3.className = '';
		s.value = '1';
		if (num == '1')
		{
			a.innerHTML = 'Поиск по: сайту';
			a1.className = 'active';
		}

		if (num == '2')
		{
			a.innerHTML = 'Поиск по: магазину';
			a2.className = 'active';
			s.value = '2';
		}

		if (num == '3')
		{
			a.innerHTML = 'Поиск по: каталогу';
			a3.className = 'active';
			s.value = '3';
		}

		hide_show('search_chk');
	}
}

function v()
{
	return true;
}

function getSecMenu()
{
	try{
	document.getElementById("secmenuplace").innerHTML =  document.getElementById("secmenu").innerHTML;
	
	document.getElementById("secmenu").innerHTML = "<!-- -->";
	}
	catch(e)
	{
	}
}


function setlinkPdf(obj)
{

	try{
		if (obj.options[obj.selectedIndex].value!="0")
		{
			document.getElementById("pdflink").href =  "/proj/food/upload/sheme/"+obj.options[obj.selectedIndex].value;
		}
		else
		{
			document.getElementById("pdflink").href  = "#";
		}
	}
	catch(e)
	{
	}
}