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(id)
{
  document.getElementById('comment_form_block').style.display="block";

  form_item=document.getElementById('comment_form');
  clone_item=form_item.cloneNode(true);
  form_item.parentNode.removeChild(form_item);

  new_parent=document.getElementById('reply_'+id);
  new_parent.appendChild(clone_item);
  document.getElementById('reply_id').value=id;
}

function trim(str){
  if (str.length>0)return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function check_comment_form()
{
  var error_code='';
  check_arr= new Array();
  check_arr['input_comment_name']='Имя';
  check_arr['input_comment_email']='Электронная почта';
  check_arr['input_comment_captcha']='Число с картинки';
  check_arr['input_comment_text']='Комментарий';
  for (var key in check_arr) 
  {
    var check_input=document.getElementById(key);
    if (trim(check_input.value + ' ')=='')
    {
      error_code = error_code + "\n  не заполнено поле «" + check_arr[key] + "»";
    }
  }

  if (error_code)
  {
    alert("При заполнении полей формы возникли следующие ошибки: \n" + error_code + "\n\nПожалуйста, заполните все поля!");
    return false;
  }
  else
  {
    return true;
  }

}



// 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;
}


/* SMEO BLOCK */

var enc_current_width=32;
var enc_new_width=32;

function open_enc_block()
{
  block=document.getElementById('enc_block');
  // Загрузка календаря
  if (block.clientWidth<50)
  {
     max_width=(block.parentNode.clientWidth+64);
     enc_current_width=32;
     enc_new_width=max_width;
  }
  else 
  {
     enc_current_width=block.clientWidth;
     enc_new_width=32;
  }
  play_smeo_scenes();
}


function play_smeo_scenes()
{
    Jet_DeleteScenario();
    jet_move_scenario[0]='smeo_scene_1()';    
    Jet_PlayScenario(); 
}

function smeo_scene_1()
{
   jet_move_id[0]='enc_block';
   jet_move_property[0]='width';
   jet_move_value_current[0]=enc_current_width;
   jet_move_value_new[0]=enc_new_width;
   jet_move_value_dimension[0]='px';
   jet_move_end_flag[0]=0;   
}

/* Magazine header replace */
function magazine_header_replace()
{
  custom_style='<style type="text/css">'+
               'div.index_blue_top_block {display: block;}'+
               'div.page_submenu a{color: #ffffff; margin-right: 15px; font-size: 11px; position: relative; top: -2px;}'+
               'div.header_replace{Z-INDEX: 10000; RIGHT: 8%; BACKGROUND: url(http://smao.ru/templates/ru/od_header_background.jpg) #ffffff no-repeat 80% 50%; WIDTH: 60%; width: expression(eval(document.body.clientWidth)*0.6 + "px"); POSITION: absolute; TOP: 15px; HEIGHT: 230px}'+
               '</style>';
  document.write(custom_style);

  sub_menu='<div class="page_submenu"><a href="http://smao.ru/ru/magazine/about/index.html">Об издании</a> <a href="http://smao.ru/ru/magazine/about/editorial.html">Редакционный совет</a> <a href="http://smao.ru/ru/magazine/about/distribution.html">Распространение</a> <a href="http://smao.ru/ru/magazine/about/authors.html">Наши авторы</a> <a href="http://smao.ru/ru/magazine/about/adv.html">Реклама</a> <a href="http://smao.ru/ru/magazine/index.html">Все&nbsp;выпуски</a></div>';
  document.getElementById('blue_block_top').innerHTML=sub_menu;
  document.getElementById('header_replace').className='header_replace';
}


/* Magazine contents links */
function check_magazine_contents_links()
{
   links=document.getElementById('contents_links').getElementsByTagName('A');
   for(i=0; i<links.length; i++) 
   {   
     if (links[i].href==window.location)
     {     
        links[i].style.color="#008dbf";
        links[i].removeAttribute('href');
        links[i].parentNode.style.color='#008dbf';   
     } 
   }
}
