function getXmlHttp()
{
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined')  xmlhttp = new XMLHttpRequest();
  return xmlhttp;
}




function alarm(text)
{

 as.$$("#alarm").innerHTML=text;
 as.$$("#alarm").style.display="block";
};


function cover(i,src)
{
 document.getElementById(i).src='i/'+src;
};

function sopen()
{
 setTimeout(function() { document.getElementById("calendar").className="calendar calendaractive"; }, 10)
};

function sclose()
{
 if (document.getElementById("calendar") && document.getElementById("calendar").className=="calendar calendaractive") 
  {
   document.getElementById("calendar").className="calendar";
  };

 if (document.getElementById("alarm"))
  {
   document.getElementById("alarm").style.display="none";
  };
};




function  mark_form(n,elem)
{
 if (n==1) elem.style.background="#ffc4c4"; else elem.style.background="#FFF";
};


function checkform(formid)
{
 
 var alarm="Необходимо заполнить обязательные поля";

 var required_arr=as.$(".required");
 var required_flag=0;

 for (var i=0; i<required_arr.length; i++)
  {
   if (required_arr[i].tagName=="select")
    {
     if (required_arr[i].options[required_arr[i].selectedIndex].value=="") 
       {
        required_flag=1;
        mark_form(1,required_arr[i]);
       } else mark_form(0,required_arr[i]);
    }
     else
    {
     switch(required_arr[i].type)
      {
       default:
      
         if (required_arr[i].value=='')
          {
           required_flag=1;
           mark_form(1,required_arr[i]);
          } else mark_form(0,required_arr[i]);
      
       break;
      
       case("checkbox"):
      
         if (required_arr[i].checked==false)
          {
           required_flag=1;
           mark_form(1,required_arr[i]);
          } else mark_form(0,required_arr[i]);
      
       break;
      };
    };
  };

 if (document.getElementById("signature_").value=="" && formid=="form_register")  alarm=alarm+" и поставить электронную подпись";

 if (required_flag) alert(alarm); else as.$$("#"+formid).submit();
};

function set_input_value(id,value)
{
 if (document.getElementById(id)) document.getElementById(id).value=value;
};

function rov(n,id) 
{
 document.getElementById("ratepic"+id).src="/i/r"+n+".gif";
};

function rout(n,id) 
{
 document.getElementById("ratepic"+id).src="/i/r"+n+".gif";
};


function vote(id,name)
{
 var xmlhttp = getXmlHttp()
 var elem=document.getElementById("ratewrap"+id);

 if (elem) 
  {
   xmlhttp.open('GET', '/vote/'+id+'/'+name+'/', true);
   xmlhttp.onreadystatechange = function() 
   {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
     {
      elem.innerHTML=xmlhttp.responseText; 
      document.getElementById("ratewrap"+id).innerHTML='<img src="/i/r'+name+'.gif">';
     }
   };
   
   xmlhttp.send(null);
  };

};




function auth_close()
{

 document.getElementById("Body").className='';
 document.getElementById("html").className='';
 document.getElementById("shadow").style.display="none";
 document.getElementById("authframe").style.display="none";

 var l=document.getElementsByTagName('select');
 for (var i=0; i<l.length; i++) l[i].style.display="inline";

};

function auth_open(lnk)
{
 document.getElementById("Body").className='dark';
 document.getElementById("html").className='dark';
 document.getElementById("shadow").style.display="block";
 document.getElementById("authframe").style.display="block";

 document.getElementById("continuelink").href=lnk;

 var l=document.getElementsByTagName('select');
 for (var i=0; i<l.length; i++) l[i].style.display="none";


};

function game()
{
 auth_close()
 popupWin=window.open("/game/", 'goods_photo', 'location=no,resizable=yes,width=700,height=500,top=0');  
 popupWin.focus(); 
 
};

function bar()
{
 auth_close();
 popupWin=window.open("/cabinet/edit/", 'goods_photo2', 'location=no,resizable=yes,width=900,height=600,top=0');  
 popupWin.focus(); 

};


function bar2(i)
{
 auth_close();
 popupWin=window.open("/quiz/details/"+i+"/", 'goods_photo2', 'location=no,resizable=yes,width=900,height=600,top=0');  
 popupWin.focus(); 

};


