function MM_findObj(n, d) { //v4.0
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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function trim(val, count, maxlen) {
obj1=MM_findObj(val);
obj2=MM_findObj(count);
 if (obj1.value.length > maxlen) {
 obj1.value=obj1.value.substring(0,maxlen);
 }
 obj2.value = maxlen - obj1.value.length;
}

var req;
function brands() {
url = "/cgi-bin/brands.cgi";
 if (window.XMLHttpRequest) {
 req = new XMLHttpRequest();
  if (req) {
  req.onreadystatechange = processReqChange;
  req.open("GET", url, true);
  req.setRequestHeader('Accept-Charset', 'utf-8');
  req.send(null);
  }
 } else if (window.ActiveXObject) {
 req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
  req.onreadystatechange = processReqChange;
  req.open("GET", url, true);
  req.setRequestHeader('Accept-Charset', 'utf-8');
  req.send();
  }
 }
return true;
}

function processReqChange() {
// only if req shows "complete"
 if (req.readyState == 4) {
// only if "OK"
  if (req.status == 200) {
   if (req.responseText) {
   objmenu = MM_findObj('menu');
   objmenu.innerHTML += unescape(req.responseText);
   }
  } else {
  alert("There was a problem retrieving the XML data:" + req.statusText);
  }
 }
}

function changeImg(imgname, newaddress) {
img = MM_findObj(imgname);
img.src = newaddress;
}

function openOptions(heightmin, heightmax) {
objopener = MM_findObj("opener");
objoptions = MM_findObj("options");
 if (objoptions.style.overflow == "auto") {
 objopener.innerHTML = "свернуть список";
 objoptions.style.overflow = "visible";
 objoptions.style.height = heightmax;
 } else {
 objopener.innerHTML = "раскрыть список";
 objoptions.style.overflow = "auto";
 objoptions.style.height = heightmin;
 }
}
