var dom = (document.getElementById)? true : false;
var ie = (dom && document.all && !window.opera) ? true : false;
var ie4 = (document.all && !dom)? true : false;
var nn6 = (!ie && dom) ? true : false
var nn4 = (document.layers)? true : false 

function popupWin(name, uri, wdt, hgt) {
	var posCode = ''
	if (nn4 || dom) {
		if ( (screen.height < 481) && (hgt > 400) ) { hgt = 400 }
		posX = Math.round((screen.width - wdt) / 2)
		posY = Math.round((screen.height - hgt) / 2 - 60)
//		posCode = (nn4 || nn6) ? ",screenX="+posX+",screenY="+posY : ",left="+posX+",top="+posY
		posCode = (ie) ? ",left="+posX+",top="+posY : ",screenX="+posX+",screenY="+posY
	}
//	alert(ie + '-' + screen.width + ' ' + screen.height + ' ' + posCode)
	popupedWin = window.open(uri, name, "status=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes,location=no,width="+wdt+",height="+hgt+posCode)
	popupedWin.focus()
}

function putStep(stepId) {
	for (var i=1; i<=3; i++) {
		if (dom) document.getElementById('step'+i).style.display = "none";
		else if (ie4) document.all['step'+i].style.display = "none";
	}
	if (ie) {
		if (dom) document.getElementById('step'+stepId).style.display = "block";
		else if (ie4) document.all['step'+stepId].style.display = "block";
	} else {
		if (dom) document.getElementById('step'+stepId).style.display = "table-row";
	}
}

function putElem(elemId) {
	if (dom) document.getElementById(elemId).style.display = "block";
	else if (ie4) document.all[elemId].style.display = "block";
}

function putElemTr(elemId) {
	if (ie) {
		if (dom) document.getElementById(elemId).style.display = "block";
		else if (ie4) document.all[elemId].style.display = "block";
	} else {
		if (dom) document.getElementById(elemId).style.display = "table-row";
	}
}

function putElemIn(elemId) {
	if (dom) document.getElementById(elemId).style.display = "inline";
	else if (ie4) document.all[elemId].style.display = "inline";
}

function removeElem(elemId) {
  if (dom) document.getElementById(elemId).style.display = "none";
  else if (ie4) document.all[elemId].style.display = "none";
}


function changeElem(elemId) {
	
	if (document.getElementById(elemId).style.display == "none") {
		putElem(elemId);
		}
	else	{
		removeElem(elemId);
		}
}

function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null )
                node = document;
        if ( tag == null )
               tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
	
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
               if ( pattern.test(els[i].className) ) {
                    classElements[j] = els[i];
                   j++;
              }
        }
        return classElements;
}

function sF()
{
	var el = getElementsByClass('btn_submit');
	for (var i=0; i<el.length; i++) {
		el[i].value="Пожалуйста подождите...";
		el[i].className="btn_wait";
		el[i].disabled="true";
	}	
}



function correctProducersList() {
	var li_min_width = 305;
	var li_max_width = 400;
	var field_width = Math.ceil(getDocumentWidth()-50-25);
	var columns_max = columns;
	if (field_width <= li_min_width*2+1){
		var columns = 1;
	} else if (field_width <= li_min_width*3+1) {
		var columns = 2;
	} else {
		var columns = 3;	
	}
	var li_width = Math.floor((field_width-16)/columns-2);
	if (li_width > li_max_width) {
		li_width = li_max_width;
	} 
	var ul = document.getElementById('producers_list');
	var liList= ul.getElementsByTagName('li');
	// document.getElementsByClass(producer_logo,,li).style.width=li_width+"%";
	for (var i=0;i<liList.length;i++)
	{
	   liList[i].style.width = li_width;
	} 
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function setPrintCSS(isPrint) {
// Определяем поддержку нужного нам элемента в броузерах
  if (document.getElementsByTagName)
      x = document.getElementsByTagName('link');
  else if (document.all)
      x = document.all.tags('link');
  else
  {
      // alert('Простите, этот скрипт не работает в вашем броузере');
      return;
  }
// Пробегая по всем элементам LINK в HTML  - включаем и отключаем нужные нам стили
// идентифицируя их по атрибуту title
// параметр isPrint - отвечает просто за вариант стилей для печти или монитора
  for (var i=0;i<x.length;i++) {
      if(x[i].title == 'printview'){x[i].disabled = !isPrint;}
      if(x[i].title == 'screenview'){x[i].disabled = isPrint;}
  }
}
if(document.location.hash=='#print') setPrintCSS(true);



