function show_or_hide(elem)
{
    childs=elem.parentNode.childNodes;
    if (elem.href==document.location.href | elem.href=="")
    {
      for (var i=0; i<childs.length; i++)
      {
        if (childs[i].tagName=="UL")
        {
          if (elem.openmode=="open")
          {
            childs[i].style.display="none";
            elem.openmode="close";
            elem.parentNode.className="";
          }
          else
          {
            childs[i].style.display="block";
            elem.openmode="open";
            elem.parentNode.className="open";
          }
          break;
        }
      }
      return false;
    }
    else
    {
      return true;
    }
} 
   
navHover = function() 
{
    var lis = document.getElementById("main_menu").getElementsByTagName("A");
    for (var i=0; i<lis.length; i++)
    {
		lis[i].onclick=function()
		{
         	return show_or_hide(this);
      	}
    }
    url=window.location.href;
    reg=new RegExp("http://([www.]*)smao.ru/([0-9a-z_.\/]+)/([0-9a-zA-Z_-]+).html");
    if (ur = reg.exec(url))
    {
     for (var i=0; i<lis.length; i++)
     {
        reg_href=new RegExp("http://([www.]*)smao.ru/([a-z_.\/]+)/([0-9a-zA-Z_-]+).html");
        if (href = reg_href.exec(lis[i].href))
		{
			reg=new RegExp(href[2]);			
		}
        url=ur[2];
        search=url.search(reg);
        if (search>=0)
        {
			elem=lis[i].parentNode.parentNode;
			elem.style.display='block';
        }
     }
   }
}

// Cross Browser
function bul_ie()
{
   IE='\v'=='v'
   if (IE)
   {
     document.getElementById('bul').style.zIndex=100;
   }
}

// Bookmark
function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}

// Print page
function printit()
{
 if (window.print)
 {
  window.print() ;
 }
 else {
 var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
 document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
 WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
 }
}


// Comments form
function show_comments_form()
{
  form_block=document.getElementById('comment_form');
  if (form_block.style.display=="none")
  {
    form_block.style.display="block";
  }
  else
  {
    form_block.style.display="none";        
  }
}


// AJAX load html data
function load_html(url) 
{  
  if (window.XMLHttpRequest) 
  { 
	   request = new XMLHttpRequest();  
  }
  else if (window.ActiveXObject) 
  {
	   request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  request.open("GET", url, false);   
  request.send(null);
  response=request.responseText;

  return response;
}


function partner_rotation_init()
{
  setInterval("load_partners_block_content()", 30000);
}

function load_partners_block_content()
{
    Jet_DeleteScenario();
    jet_move_scenario[0]='partner_scene_1()';    
    jet_move_scenario[1]='partner_scene_2()';   
    jet_move_scenario[2]='partner_scene_3()';
    Jet_PlayScenario(); 
}

function partner_scene_1()
{
   jet_move_id[0]='random_partner_logo';
   jet_move_property[0]='opacity';
   jet_move_value_current[0]=100;
   jet_move_value_new[0]=0;
   jet_move_value_dimension[0]='0';
   jet_move_end_flag[0]=0;   
}

function partner_scene_2()
{
   url="http://" + document.location.hostname + "/ru/ajax/partner.html"; 
   response=load_html(url);
   //response='<table style="width: 100%; margin-top: 20px;"><tr><td style="width: 20%;"><p align="center"><a href="http://www.profsro.ru/"><img height="40" width="140" border="0" alt="" src="http://smao.ru/files/banner/partner_logo/profsro_140_40.gif" /></a></p></td><td style="width: 20%;"><p align="center"><a href="http://www.RWAY-Online.ru"><img height="70" alt="" width="120" border="0" src="http://smao.ru/files/news/2009/11/rway120_70.jpg" /></a></p></td><td style="width: 20%;"><p align="center"><a href="http://www.raexpert.ru"><img height="32" alt="" width="130" border="0" src="http://smao.ru/files/banner/partner_logo/logo.jpg" /></a></p></td><td style="width: 20%;">&nbsp;<p align="center"><a href="http://www.labrate.ru"><img height="31" alt="" width="88" align="absMiddle" border="0" src="http://smao.ru/files/banner/partner_logo/ba88x31_labrate_3.gif" /></a></p></td><td style="width: 20%;"><p align="center"><a href="http://www.ocenka.net/"><img alt="" border="0" src="http://smao.ru/files/banner/partner_logo/ipo.gif" /></a></p></td></tr></table>'
   document.getElementById('random_partner_logo').innerHTML=response;
}

function partner_scene_3()
{
   jet_move_id[0]='random_partner_logo';
   jet_move_property[0]='opacity';
   jet_move_value_current[0]=0;
   jet_move_value_new[0]=100;
   jet_move_value_dimension[0]='0';
   jet_move_end_flag[0]=0;   
}


/* NEWS CALENDAR */
function open_news_calendar()
{
  block=document.getElementById('news_calendar_content');
  // Загрузка календаря
  if (document.getElementById('news_calendar_text').firstChild.nodeType==3)
  {
     load_news_calendar(0,0);
  }
  if (block.clientWidth<100)
  {
     block.style.width='187px';
  }
  else 
  {
     block.style.width='32px';
  }
}

function load_news_calendar(month, year)
{
   url="http://" + document.location.hostname + "/script/news_calendar/?month="+month+"&year="+year; 
   response=load_html(url);
   document.getElementById('news_calendar_text').innerHTML=response;
}

/* EVENT CALENDAR */
function open_event_calendar()
{
  block=document.getElementById('event_calendar_content');
  // Загрузка календаря
  if (document.getElementById('event_calendar_text').firstChild.nodeType==3)
  {
     load_event_calendar(0,0);
  }
  if (block.clientWidth<100)
  {
     block.style.width='187px';
  }
  else 
  {
     block.style.width='32px';
  }
}

function load_event_calendar(month, year)
{
   url="http://" + document.location.hostname + "/script/event_calendar/?month="+month+"&year="+year; 
   response=load_html(url);
   document.getElementById('event_calendar_text').innerHTML=response;
}