    var active  = 0;
    var pactive = 0;
    var dom = YAHOO.util.Dom;
    var opendiv="";
	
   function toggle(id, pid) {
        cat  = document.getElementById('c' + id);
        img  = document.getElementById('img' + id);
      
            if (cat.style.display == "none") {
                cat.style.display = "block";
                img.src = "images/up.png";
document.cookie= 'opendiv['+id+']='+id+';expires=' +new Date(( new Date() ).getTime() + ( 1000 * 31536000 ) ).toGMTString()+';domain='+document.domain;       
            } else {
                cat.style.display = "none";
                img.src = "images/dn.png";
document.cookie= 'opendiv['+id+']='+id+';expires=' +new Date( new Date() .getTime() ).toGMTString()+';domain='+document.domain;
            }
      
        return true;
    }
function for_mail()
{
document.all('mail_body').value = document.all('send_mail').innerHTML;
}



    function toggle_1(id, pid) {
        cat  = document.getElementById('c' + id);
        pcat = document.getElementById('c' + pid);
        img  = document.getElementById('img' + id);
        pimg = document.getElementById('img' + pid);

        if (cat) {
            if (cat.style.display == "none") {
                cat.style.display = "block";
                img.src = "images/minus.gif";
                if (pcat) {
                    pcat.style.display = "block";
                    pimg.src = "images/minus.gif";
                }
            } else {
                cat.style.display = "none";
                img.src = "images/plusbottom.gif";
            }
        }


        if (pactive != pid) {
            act = document.getElementById('c' + pactive);
            img = document.getElementById('img' + pactive);
            if (act) {
                act.style.display = "none";
                img.src = "images/plusbottom.gif";
            }
        }

        if (active  != id &&
            pactive == pid) {
            act = document.getElementById('c' + active);
            img = document.getElementById('img' + active);
            if (act) {
                act.style.display = "none";
                img.src = "images/plusbottom.gif";
            }
        }

        active  = id;
        pactive = pid;

        return true;
    }

    function tDiv(el, id) {
        div = document.getElementById(id);
        if (el) {
            div.style.display = "block";
        } else {
            div.style.display = "none";
        }
        return true;
    }

    function savePrice(e, obj) {
      var formObject = dom.get(obj.id); 

      YAHOO.util.Connect.setForm(formObject); 

      var cb_savePrice = { 
		        success: function(o) {
		            if (JSON.parse(o.responseText)) {
					          json = eval('(' + o.responseText + ')');

          					if (json.error) {
				                alert('Во время выполнения запроса произошла ошибка: ' + json.error);
						            return;		
					          }

				            alert('Операция успешно выполнена!');
				        } else {
				            alert('Ошибка при выполнении запроса!');
                }
		        },

		        failure: function(o) {
		            alert('Ошибка при получении данных! Попробуйте пожалуйста позже.');
		        }

      }

      YAHOO.util.Connect.asyncRequest('POST', 'price.php', cb_savePrice); 
    }

	  function showPrice(id) {
        var el = dom.get('price-' + id);
        
        if (el) {
            el.style.display = 'block';
            el.innerHTML = '<div class="ajaxMsg"><img src="images/loading.gif" alt="" /><i>Пожалуйста подождите...</i></div>'; 
        }

		    var cb_loadPrice = { 
		        success: function(o) {
		            var json, but;
		            var el = o.argument.el;

		            el.innerHTML = '';

		    	      if (JSON.parse(o.responseText)) {
					          json = eval('(' + o.responseText + ')');

          					if (json.error) {
				                alert(json.error);
						            return;		
					          }

                    if (!json.length) {
                        el.innerHTML = '<div class="ajaxMsg">Категория пуста!</div>';
                        return;
                    }

                    var str = '<form name="form-' + o.argument.id + '" id="form-' + o.argument.id + '" action="price.php"><table border="0">';

                    // показать все товары в выбранной категории
                    for (var i = 0; i < json.length; i++) {
					              str += '<tr><td width="400">' + json[i].cName + 
                               '</td><td width="50"><input name="fPrice[' + 
                               json[i].id + ']" value="' + json[i].fPrice + 
                               '" style="width: 40px;"></td></tr>';

                        // если у товаров есть модификации - показать и их
                        if (json[i].mod.length) {
                            for (var j = 0; j < json[i].mod.length; j++) {
                                str += '<tr><td width="400"><div class="left">' + json[i].mod[j].cModName + 
                                       '</div></td><td width="50"><input name="fModPrice[' + 
                                       json[i].mod[j].mid + ']" value="' + json[i].mod[j].fModPrice + 
                                       '" style="width: 40px;"></td></tr>';
                            }
                        }
					          }

                    str += '</table><div id="sb-' + o.argument.id + '" style="text-align: center;"></div><input type="hidden" name="cmd" value="loadPrice"></form>';

                    el.innerHTML = str;

                    but = new YAHOO.widget.Button({ label: 'Готово', id: 'sbut-' + o.argument.id, name: 'sbut-' + o.argument.id, container: 'sb-' + o.argument.id });
                    
                    but.addListener('click', savePrice, {id: 'form-' + o.argument.id});

		    	      } else {
		    		        alert('Ошибка при загрузке данных о продукции!');
		    		        o.argument.el.innerHTML = '';
		    	      }
    		    }, 

		        failure: function (o) {
		            alert('Ошибка при получении данных! Попробуйте пожалуйста позже.');
		            o.argument.el.innerHTML = '';
            },

		        argument: {id: id, el: el}
		    };

    		YAHOO.util.Connect.asyncRequest('POST', 'price.php', cb_loadPrice, 'cmd=getPrice&id=' + id);
	};

// script from Twey, http://www.dynamicdrive.com/forums/showpost.php?p=49194&postcount=3
function preloadImages() { if(typeof preloadImages.store === 'undefined') preloadImages.store = []; for(var i = 0; i < arguments.length; ++i) (preloadImages.store[preloadImages.store.length] = new Image()).src = arguments[i]; }
