var ajaxcounter = 0;
var doc = window.document;

function SfindObj(n, d) 
{	//v4.01
	var p, i, x;
	if (!d) 
		d = document; 
	if ((p = n.indexOf("?") ) > 0 && parent.frames.length) 
	{
		d = parent.frames [n.substring(p + 1)].document; 
		n = n.substring(0, p);
	}
	if (!(x = d [n]) && d.all) 
		x = d.all [n]; 
	for (i = 0; !x && i < d.forms.length; i ++) 
		x = d.forms [i] [n];
	for (i = 0; !x && d.layers && i < d.layers.length; i ++)
		x = SfindObj(n, d.layers [i].document);
	if(!x && d.getElementById) 
		x = d.getElementById(n);
	return x;
}

function ajax()
{
    //---------------------
    // Private Declarations
    //---------------------
    var _request = null;
    var _this = null;
    
    //--------------------
    // Public Declarations
    //--------------------
    var nAjaxWidth = 250;
    var nAjaxHeight = 200;
    var nAjaxXOffset = 0;
    var nAjaxYOffset = 0;
    
    this.GetResponseXML = function()
    {
        return (_request) ? _request.responseXML : null;
    };
    
    this.GetResponseText = function()
    {
        return (_request) ? _request.responseText : null;
    };
    
    this.GetRequestObject = function()
    {
        return _request;
    };
    
    this.InitializeRequest = function(Method, Uri)
    {
        _InitializeRequest();
        _this = this;
        
        switch (arguments.length)
        {
            case 2:
                _request.open(Method, Uri);
                break;
                
            case 3:
                _request.open(Method, Uri, arguments[2]);
                break;
        }
        
        if (arguments.length >= 4) 
            _request.open(Method, Uri, arguments[2], arguments[3]);
        this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    };
    
    this.SetRequestHeader = function(Field, Value)
    {
        if (_request) 
            _request.setRequestHeader(Field, Value);
    };
    
    this.Commit = function(Data)
    {
        if (_request) 
            _request.send(Data);
    };
    
    this.Close = function()
    {
        if (_request) 
            _request.abort();
    };
    
    //---------------------------
    // Public Event Declarations.
    //---------------------------
    this.OnUninitialize = function()
    {
    };
    this.OnLoading = function()
    {
    };
    this.OnLoaded = function()
    {
    };
    this.OnInteractive = function()
    {
    };
    this.OnSuccess = function()
    {
    };
    this.OnFailure = function()
    {
        alert('AJAX Error. Sorry');
    };
    
    //---------------------------
    // Private Event Declarations
    //---------------------------
    function _OnUninitialize()
    {
        _this.OnUninitialize();
    };
    function _OnLoading()
    {
        _this.OnLoading();
    };
    function _OnLoaded()
    {
        _this.OnLoaded();
    };
    function _OnInteractive()
    {
        _this.OnInteractive();
    };
    function _OnSuccess()
    {
        _this.OnSuccess();
    };
    function _OnFailure()
    {
        _this.OnFailure();
    };
    
    //------------------
    // Private Functions
    //------------------
    function _InitializeRequest()
    {
        _request = _GetRequest();
        _request.onreadystatechange = _StateHandler;
    };
    
    function _StateHandler()
    {
        switch (_request.readyState)
        {
            case 0:
                window.setTimeout("void(0)", 100);
                _OnUninitialize();
                break;
                
            case 1:
                window.setTimeout("void(0)", 100);
                _OnLoading();
                break;
                
            case 2:
                window.setTimeout("void(0)", 100);
                _OnLoaded();
                break;
                
            case 3:
                window.setTimeout("void(0)", 100);
                _OnInteractive();
                break;
                
            case 4:
                if ((_request.status == 200) || !_request.status) 
                {
                    ajaxcounter--;
                    _OnSuccess();
                    
                }
                else 
                {
                    ajaxcounter--;
                    _OnFailure();
                }
                
                return; break;
        }
    };
    
    function _GetRequest()
    {
        var obj;

        try 
        {
            obj = new XMLHttpRequest();
        } 
        catch (error) 
        {
            try 
            {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (error) 
            {
                try 
                {
                    obj = new ActiveXObject('Msxml2.XMLHTTP');
                } 
                catch (error) 
                {
                    return null;
                }
            }
        }
        
        return obj;
    };
}

function apply_responce(xmldoc, nAjaxWidth, nAjaxHeight, nV, nAjaxXOffset, nAjaxYOffset)
{
    var root = xmldoc.getElementsByTagName('root')[0];
    if (!root) return; 
       
	var count = root.childNodes.length;
    for (var iNode = 0; iNode < count; iNode++) 
    {
    	var child = root.childNodes[iNode];
        if (child.nodeType != 1) continue; 
        
        try 
        {
            var innerH = child.firstChild.nodeValue;
        } 
        catch (error) 
        {
            innerH = '';
        }
        
		if (child.tagName == 'goto') 
			window.location.href = innerH;
		else
		if (child.tagName == 'error') 
			alert(innerH);
		else
		if (child.tagName == 'code') 
			eval(innerH);
		else 
		{
			var tag = '';
			var wnd = 0;
			
			if (child.tagName.indexOf('wnd_') == 0) 
			{
				tag = child.tagName.substr(4);
				wnd = 1;
			}
			else 
				tag = child.tagName;
			
			var obj = doc.getElementById(tag);
			
			if (!obj && wnd==1) 
			{
				try 
				{
					obj = doc.createElement("<div class=wnd id=\"" + tag + "\""+ "></div>");
				} 
				catch (e) 
				{
					obj = doc.createElement("div");
					obj.setAttribute("id", tag);
					obj.setAttribute("class", "wnd");
				}
				if(obj) doc.body.appendChild(obj);
			}
			
			if (!obj) continue; 
			
			if(child.tagName == 'cart_count')
			{
				var values = innerH.toString().split(':');
				if(values[0]<=0 && values[2] == 'del') window.location.href=window.location.href;
				else
				{
					obj.innerHTML = values[0];
					if(values[2] == 'del')
					{
						var objl = doc.getElementById('good_'+values[1]);
						objl.style.display='none';
				
				
						var cook = '';
						sum = 0;
						for(var i in prices)
						{
							if(!prices[i][1]) continue;
							cook += i+':'+prices[i][1]+';';
							
							sum += prices[i][0] * prices[i][1];
						}
						SetCookie('order',cook);
						
						var objl = doc.getElementById('sum');
						objl.innerHTML = make_nbsp(sum)+' p';
				
						alert('Товар удален!');
					}
					else if(values[2] == 'add') alert('Товар добавлен!');
				}
			}
			else
				obj.innerHTML = wnd?'<div id=inner_'+tag+' style="position:relative;">'+innerH+'</div>':innerH; 
		
			if(wnd)	CenterLayer(tag, obj.offsetWidth, obj.offsetHeight, doc);
			obj.style.visibility = (innerH == '' ? 'hidden' : 'visible');

			if(wnd && document.all && typeof(SelectFix)!='undefined')
			{
				if (obj.className.indexOf("select-free")!=-1) obj.className = "wnd";
				SelectFix.repairFloatingElement(obj);
			}
		}
	}
}

AjaxObject = function()
{
    this.OnSuccess = function()
    {
        var xmldoc = this.GetResponseXML();
       // alert(this.GetResponseText());
        if (!xmldoc) return;
        apply_responce(xmldoc, this.nAjaxWidth, this.nAjaxHeight, 0, this.nAjaxXOffset, this.nAjaxYOffset);
        
    };
    
    this.GetData = function(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset)
    {
        this.InitializeRequest('POST', action, true);
        this.Commit(vars);
        this.nAjaxWidth = newWidth;
        this.nAjaxHeight = newHeight;
        this.nAjaxXOffset = newXOffset;
        this.nAjaxYOffset = newYOffset;
        ajaxcounter++;
    };
};

function AjaxSendRequest(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset)
{
    if (vars) 
        vars = vars + '&object=' + sObject;
    else 
        vars = 'object=' + sObject;
    vars = vars + '&frompage=' + encodeURIComponent(window.location.href);
    
    if (!newWidth) 
        newWidth = 347;
    if (!newHeight) 
        newHeight = 210;
    if (!newXOffset) 
        newXOffset = 0;
    if (!newYOffset) 
        newYOffset = 0;
    
    AjaxObject.prototype = new ajax();
    myObject = new AjaxObject();
    myObject.GetData(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset);
}

function AjaxSendPOST(action, form, sObject, newWidth, newHeight, newXOffset, newYOffset)
{
    var vars = '';
    var elems = doc.forms[form].elements;
    for (var i = 0; i < elems.length; i++) 
    {
        elem = elems[i];
        if (((elem.type == 'checkbox') || (elem.type == 'radio')) && elem.checked != true) 
            continue;
        if(elem.name == '' || elem.value=='') continue;
        
        vars = vars + '&' + elem.name + '=' + encodeURIComponent(elem.value);
    }
    if (vars) 
        vars = vars + '&object=' + sObject;
    else 
        vars = 'object=' + sObject;
    vars = vars + '&frompage=' + encodeURIComponent(window.location.href);
    if (!newWidth) 
        newWidth = 347;
    if (!newHeight) 
        newHeight = 210;
    if (!newXOffset) 
        newXOffset = 0;
    if (!newYOffset) 
        newYOffset = 0;
    
    AjaxObject.prototype = new ajax();
    myObject = new AjaxObject();
    myObject.GetData(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset);
  //  ShowAjaxIndicator();
}


function ShowProd (wwidth,wheight,isrc,modelid) {
	if(isrc=='/') return;
	
	var obj1=doc.getElementById('preview');
	var obj2=doc.getElementById('previewimg');
	var obj3=doc.getElementById('previewtbl');
	var obj4=doc.getElementById('loading');
	
	if (modelid >=0 ) {
		var objLoad=doc.getElementById("loaddata");
		objLoad.innerHTML='';
		objLoad.style.display='none';
	}
	
	obj2.src='/i/dot.gif';
	wheight = wheight*1+20;
	wwidth = wwidth*1+20;
	obj1.style.width=wwidth+'px';
	obj1.style.height=wheight+'px';
	
	obj3.style.width=wwidth+'px';
	obj3.style.height=wheight+'px';
	
	obj4.style.width=wwidth+'px';
	obj4.style.height=wheight+'px';

	CenterLayer('preview',wwidth,wheight,doc);
	
	obj1.style.visibility='visible';

	obj2.src=isrc;
	
	if(document.all && typeof(SelectFix)!='undefined')
		SelectFix.repairFloatingElement(obj1);
}

function HideProd () {
	var obj1=doc.getElementById('preview');
	var obj2=doc.getElementById('previewimg');
	var objLoad=doc.getElementById("loaddata");
	objLoad.innerHTML='';
	objLoad.style.display='none';
	obj2.src='/i/dot.gif';
	obj1.style.visibility='hidden';
}

function CenterLayer (layer,width,height,target,xoffset,yoffset) {
	if (!target)
		target=doc;
	
	if (!xoffset)
		xoffset = 0;
		
	if (!yoffset)
		yoffset = 0;

	var leftLayer = ((target.body.clientWidth - width)/2);
	var topLayerABS = (target.body.clientHeight - height)/2;

	var topLayer=target.body.scrollTop;
	
	var newTop = topLayer + topLayerABS;
	if (newTop < 0)
		newTop=0;
		
	var nTop = topLayer + topLayerABS + yoffset;
	var nLeft = leftLayer + xoffset;
	
	if (nTop < target.body.scrollTop)
		nTop = target.body.scrollTop + 5;
	
	var obj = target.getElementById(layer);
	if (!obj) return; 
	
	obj.style.left = nLeft + 'px';
	obj.style.top = nTop + 'px';
	if(!obj.style.width)
		obj.style.width = width+ 'px';
	if(!obj.style.height)
	obj.style.height = height+ 'px';
}

function hide(tag,clear)
{
	var obj = doc.getElementById(tag);
	if (!obj) return; 
	
	obj.style.visibility = 'hidden';
	if(clear) obj.innerHTML = '';
}
window.setTimeout(function(){objs=doc.getElementsByTagName("object"); for(var i=0;i<objs.length;i++) objs[i].outerHTML=objs[i].outerHTML;},1000);


// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  
  this.isIE = true;
  this.version = parseFloat(ua.substr(i + s.length));
  return;
  
}

var browser = new Browser();
var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;
  
  obj = doc.getElementById(id);
  obj.style.cursor = 'move';

  if (id)
    dragObj.elNode = obj;
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    else
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  if (browser.isIE) {
    x = window.event.clientX + doc.documentElement.scrollLeft
      + doc.body.scrollLeft;
    y = window.event.clientY + doc.documentElement.scrollTop
      + doc.body.scrollTop;
  }
  else
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  //dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    doc.attachEvent("onmousemove", dragGo);
    doc.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else
  if (browser.isNS) {
    doc.addEventListener("mousemove", dragGo,   true);
    doc.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + doc.documentElement.scrollLeft
      + doc.body.scrollLeft;
    y = window.event.clientY + doc.documentElement.scrollTop
      + doc.body.scrollTop;
  }
  else
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {
	
  dragObj.elNode.style.cursor = 'default';

  if (browser.isIE) {
    doc.detachEvent("onmousemove", dragGo);
    doc.detachEvent("onmouseup",   dragStop);
  }
  else
  if (browser.isNS) {
    doc.removeEventListener("mousemove", dragGo,   true);
    doc.removeEventListener("mouseup",   dragStop, true);
  }
}

function set_cart_count()
{
	var cook = GetCookie('order');
	var obj = doc.getElementById('cart_count');
	var cnt = cook.toString().split(';').length-1;
	if(obj) obj.innerHTML = cnt;
	
	var obj = doc.getElementById('cart_countok');
	if(obj) obj.innerHTML = CheckNumberSuffix(cnt);
}

function CheckNumberSuffix (num) 
{
	if(num>=5 && num <= 20) return 'й';
	str = num.toString();
	dig = str.substr(str.length-1,1);
	switch(dig)
	{
		case '1': return 'я';
		case '2':
		case '3':
		case '4': return 'и';
		default: return 'й';		
	}
}
	
function make_nbsp(price)
{
	var res = '';
	price = price.toString();
	var l = price.length;
	var c = Math.floor(l / 3);
	if(!c) return price;
	var p = l % (3*c);
	if(p) res = price.substr(0,p);
	for(var i=0;i<c;i++)
		res += (res?' ':'')+price.substr(i*3+p,3);
	return res;	
}


//ru
error_messages = 
{
	'formlogin': 
	{
		'login': 'Заполните поле "Логин"',
		'password': 'Введите "Пароль"'
	},
	
	'formreg': 
	{
		'login': 'Заполните поле "Логин"',
		'password': 'Введите "Пароль"',
		'email': 'Заполните поле "E-mail"',
		
		'caption': 'Заполните поле "Название"',
		'fax': 'Заполните поле "Тел./факс"',
		'unp': 'Заполните поле "УНП"',
		'okpo': 'Заполните поле "ОКПО"',
		'uradres': 'Заполните поле "Юр. Адрес."',
		'schet': 'Заполните поле "Расчётный счёт"',
		'bank': 'Заполните поле "Банк"',
		'adrbank': 'Заполните поле "Адрес банка"',
		'kod': 'Заполните поле "Код"',
		'fio': 'Заполните поле "ФИО"',
		'tel': 'Заполните поле "Телефон"'
	}
};

function echeck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)  return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1)  return false;
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
    if (str.indexOf(dot,(lat+2))==-1) return false;
    if (str.indexOf(" ")!=-1)  return false;
    return true;
}

function trim(s,what) 
{
	while (s.substring(0,1) == what) s = s.substring(1,s.length);
	while (s.substring(s.length-1,s.length) == what) s = s.substring(0,s.length-1);
	return s;
}


function ValidateSendForm (formname, aFields) 
{
	var f = doc.forms[formname];
	if(!f) return;
	if (formname == 'formreg') 
	{
		if (f.login) 
		{
			pattern = new RegExp("^[a-zA-Z0-9]{2,20}$", "g");
			if (!pattern.test(f.login.value)) 
			{
				alert('В поле "Логин" мало букв или использованы недопустимые символы!','Ошибка');
				f.login.focus();
				return false;
			}
		}

		if (f.email && f.email.value && !echeck(f.email.value)) 
		{
			alert('Введите E-mail правильно','Ошибка');
			f.email.focus();
			return false;
		}
	}

	for (i = 0; i < aFields.length; i++) {
		if (f.elements[aFields[i]]) {
			if (((f.elements[aFields[i]].getAttribute('type') == 'select-one') && (f.elements[aFields[i]].selectedIndex == 0) && (f.elements[aFields[i]].style.display != 'none')) 
			|| 
			((f.elements[aFields[i]].getAttribute('type') == 'text') && (trim(f.elements[aFields[i]].value,' ') == '') && (f.elements[aFields[i]].style.display != 'none'))
			|| 
			((f.elements[aFields[i]].getAttribute('type') == 'password') && (trim(f.elements[aFields[i]].value,' ') == '') && (f.elements[aFields[i]].style.display != 'none'))
			|| 
			((f.elements[aFields[i]].getAttribute('type') == 'textarea') && (trim(f.elements[aFields[i]].value,' ') == '') && (f.elements[aFields[i]].style.display != 'none'))
			|| 
			((f.elements[aFields[i]].getAttribute('type') == 'hidden') && ((trim(f.elements[aFields[i]].value,' ') == '') || (trim(f.elements[aFields[i]].value,' ') == '0')) && (f.elements[aFields[i]].style.display != 'none'))
			|| 
			((f.elements[aFields[i]].getAttribute('type') == 'checkbox') &&  (!f.elements[aFields[i]].checked))
			|| 
			((f.elements[aFields[i]].getAttribute('type') == null) && (trim(f.elements[aFields[i]].value,' ') == '') && (f.elements[aFields[i]].style.display != 'none'))
			) {
				if(error_messages[formname] && error_messages[formname][aFields[i]])
					alert(error_messages[formname][aFields[i]],'Ошибка');
				else {
					alert('Не заполнено обязательное поле!','Ошибка');
				}
				try {
					f.elements[aFields[i]].focus();
				}
				catch(e) {;}
				return false;
			}
		}
	}
	return true;
}


function limg(id,p)
{
	AjaxSendRequest('/ajax/img','task=view&id='+id+'&p='+p+'&g=b','img_'+id);
}

function rimg(id,p)
{
	AjaxSendRequest('/ajax/img','task=view&id='+id+'&p='+p+'&g=f','img_'+id);		
}


function SetCookie(name, value) {
   var argv    = SetCookie.arguments;
   var argc    = SetCookie.arguments.length;
   var expires = (argc > 3) ? new Date(argv[3]) : null;
   //var path    = (argc > 4) ? argv[4] : null;
	var path    = '/';
   var domain  = (argc > 5) ? argv[5] : null;
   var secure  = (argc > 6) ? argv[6] : false;
   expires = 'Friday, 01-Jan-2399 00:00:00 GMT';

   document.cookie = name + "=" + escape(value)
      + ((expires == null) ? "" : ("; expires=" + expires))
      + ((path == null) ? "" : ("; path=" + path))
      + ((domain == null) ? "" : ("; domain=" + domain))
      + ((secure == true) ? "; secure" : "");
}

function GetCookie(name) {
   var arg  = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i    = 0;

   while(i < clen) {
      var offset = i + alen;

      if(document.cookie.substring(i, offset) == arg) {
         var iEnd  = document.cookie.indexOf(";", offset);

         if(iEnd == -1) {
            iEnd = document.cookie.length;
         }

         return unescape(document.cookie.substring(offset, iEnd));
      }

      i = document.cookie.indexOf(" ", i) + 1;

      if(i == 0) {
         break;
      }
   }

   return '';
}

function setcmp(id,cid,obj)
{
	var cook = GetCookie('compare_'+cid);
	cook = cook.replace(id+';','');
	if(obj.src.indexOf('nocheck')>=0)
	{
		cook += id+';';
		obj.src = '/i/check.gif';
	}
	else
	{ 
		
		obj.src = '/i/nocheck.gif';
	}
	SetCookie('compare_'+cid,cook);
}

function remcmp(id,cid)
{
	var cook = GetCookie('compare_'+cid);
	if(id==-1)
		cook = '';
	else
		cook = cook.replace(id+';',''); 
	SetCookie('compare_'+cid,cook);
}

function setorder(id)
{
	var cook = GetCookie('order');
	cook += id+':1;';
	SetCookie('order',cook);
	
	set_cart_count();
	
	alert('Товар добавлен!');
}

function remorder(id)
{
	prices[id][1] = 0;
	
	var cook = '';
	sum = 0;
	for(var i in prices)
	{
		if(!prices[i][1]) continue;
		cook += i+':'+prices[i][1]+';';
		
		sum += prices[i][0] * prices[i][1];
	}
	SetCookie('order',cook);

	if(!sum) window.location.href=window.location.href;
		
	var objl = doc.getElementById('sum');
	objl.innerHTML = make_nbsp(sum)+' pуб';
	
	var objl = doc.getElementById('good_'+id);
	objl.style.display='none';
	
	set_cart_count();
	
	alert('Товар удален!');
}


function update_order(id, _this)
{
	var c = parseInt(_this.value);
	c = isNaN(c)?0:c;
	prices[id][1] = c;

	var cook = '';
	sum = 0;
	for(var i in prices)
	{
		if(!prices[i][1]) continue;
		cook += i+':'+prices[i][1]+';';
		
		sum += prices[i][0] * prices[i][1];
	}
	SetCookie('order',cook);
	
	var objl = doc.getElementById('sum');
	objl.innerHTML = make_nbsp(sum)+' pуб';
	return true;
}

function find(id)
{
	var obj = doc.getElementById(id);
	if(!obj || !obj.value) return;
	var str = obj.value.toString(); 
	str = str.substr(0,100);
	str = str.replace(/^\s+/, '');
    str = str.replace(/\s+$/, '');
    str = str.replace(/\s+/g, ' ');
	str = str.replace(/\%/g,'');
	str = str.replace(/\?/g,'');
	str = str.replace(/\//g,'');
	obj.value = str;
	if(str == '') return;
	
	window.location.href = '/find/'+encodeURIComponent(str);	
}

function tr(obj,event)
{
	str = obj.value.toString().replace(/\s+/g, '');
	obj.value = make_nbsp(str);	
}

function active_menu(id)
{
	var obj;
	
	if(!(obj = document.getElementById(id))) return;
	obj.className += ' noactive';
}

function sethr(num)
{
	SetCookie('per_page',num);
	return true;
}

window.setTimeout('set_cart_count();',500);

function oprub(id)
{
	var obj = document.getElementById(id);
	if(!obj) return;
	obj.style.display = obj.style.display != 'block'?'block':'none';
	return false; 
}


