function index(obj,cls)
{//проходит вверх по иерархии до объекта с классом cls (или доверху) и возвращает индекс объекта в списке объектов относительно их общего родственника
 while(obj&&obj.className!=cls)
  obj=obj.parentNode;
 if(!obj)
  return -1;
 var j=0;
 while(obj=obj.previousSibling)
 {
  if(obj.nodeType==1&&obj.className==cls)
   j++;
 }
 return j;
}

function clr(obj)
{//убираем комментарии/переносы строк
 var p;
 if(typeof(obj)=='object')
  p=obj;else
  p=de(obj);
 var t=p.childNodes;
 for(var i=0;i<t.length;i++)//clear
  if(t[i].nodeType!=1)
  {
   p.removeChild(t[i]);
   i--;
  }
}

function fillAr(arr,objs,par)
{//заполняет массив arr объектами из массива objs, у которых класс равен par
 for(var i=0,j=0;i<objs.length;i++)
  if(objs[i].className.indexOf(par)+1)
  {
   arr[j]=objs[i];
   j++;
  }
}

function inputFocusBlur(obj,text)
{//поведение элементов input
 de(obj).onfocus=function()
 {
  if(this.value==text)
   this.value='';
 }
 de(obj).onblur=function()
 {
  if(this.value=='')
  this.value=text;
 }			
}

function ieOperaSpanFix(cont,cls)
{//версткозависимая
 //добавляем в span-разделитель пробел (<span class="menu-line"><span></span></span>)
 //параметры: контейнер и класс элемента, в котором будет добавлен пробел
 var t=de(cont).getElementsByTagName('span');
 for(var i=0;i<t.length;i++)
  if(t[i].className==cls)
   if(!browser.opera)
    t[i].innerHTML='&nbsp;<span></span>';else//без содержимого в виде хоть 1 символа ие спан не покажет
    {
     t[i].className+=' operaSpanFix';
     t[i].getElementsByTagName('span')[0].style.bottom='-12px';
    }
}

function fixRadio(cont)
{
 var t=de(cont).getElementsByTagName('input');
 t[0].checked=true;
 for(var i=0;i<t.length;i++)
 {
  t[i].style.marginTop='3px';
  if(browser.ie7||browser.ie8)
   t[i].style.marginTop='-3px';else
   if(browser.firefox)
   {
    t[i].style.marginTop='1px';
	t[i].style.left='6px';
   }else
	if(browser.opera)
	 t[i].style.marginTop='2px';
 }
}

function checkForm(cont)
{
 var t=cont.getElementsByTagName('input');
 var t1=cont.getElementsByTagName('textarea');
 
 cont.onsubmit=function()
 {
  for(var i=0;i<t.length;i++)
   if((t[i].type=='text'||t[i].type=='password')&&trim(t[i].value)=='')
   {
    alert('At least one of the input fields is empty!');
    return false;
   }
  for(var i=0;i<t1.length;i++)
   if(trim(t1[i].value)=='')
   {
    alert('At least one of the input fields is empty!');
    return false;
   }
  return true;
 }
}

function trim(s)
{
 return s.replace(/(^\s+)|(\s+$)/g, "");
}

function tags(cont,ac)
{
 var o={src:de(cont).children[0].children,target:de(cont).children[1],overs:de(cont).children[2].children};
 
 for(var i=1;i<o.overs.length;i++)
  o.overs[i].onmouseover=function(i)
  {
   return function()
   {
    if(de(ac)!=this)
    {
     de(ac).style.border=0;
     de(ac).style.padding='4px 20px 4px 15px';
    
     de(ac).id='';
     this.id=ac;
     
     this.style.border='solid 1px #cdcdcd';
     this.style.borderLeft='solid 1px #fff';
     this.style.padding='3px 19px 3px 14px';
	 
	 o.target.src=o.src[i-1].src;
	}
   }
  }(i);
}
