
function findObj(id) {
  var tmp;
	if(document.all)
	{
	  tmp = document.all[id];
	  if (tmp) return tmp;
	  else return null;
	} else {
	  tmp = document.getElementById(id);
	  if (tmp) return tmp;
	  else return null;
	}
}
//---------------------------------------------------------------------------

var OpenedLVL0;
var OpenedLVL1;
var OpenedAnsw = true;
//---------------------------------------------------------------------------

function FreeOnCklick(lvl1_id) {
  event.stopPropagation ? event.stopPropagation() : event.cancelBubble=true;
}
//---------------------------------------------------------------------------

function ChangeVisLVL1(lvl0, lvl1_id) {
  if (lvl0.tagName != 'TABLE') return;
      
  var lvl1 = findObj(lvl1_id);
  if (!lvl1) return;
    
  var img0;
  
  if (lvl1.style.display == 'none') {
    if (OpenedLVL0) {
      img0 = OpenedLVL0.getElementsByTagName('IMG')[0];
      if (img0) img0.src = 'design/exp_down.gif';
    }
    if (OpenedLVL1) OpenedLVL1.style.display = 'none';        
    
    img0 = lvl0.getElementsByTagName('IMG')[0];
    if (img0) img0.src = 'design/exp_up.gif';
    lvl1.style.display = 'block';
    
    OpenedLVL0 = lvl0;
    OpenedLVL1 = lvl1;
    
    //alert('block');
  } else {
    img0 = lvl0.getElementsByTagName('IMG')[0];
    if (img0) img0.src = 'design/exp_down.gif';
    lvl1.style.display = 'none';
    
    //alert('none');
  }
}

//---------------------------------------------------------------------------

var showMode = 'table-cell';
if (document.all) showMode='block';

function toggleVis(btn){

	btn = document.forms['tcol'].elements[btn];
	cells = document.getElementsByName('t'+btn.name);
	mode = btn.checked ? showMode : 'none';

	for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
}

//---------------------------------------------------------------------------

function ChangeVisStatus(id) {

  if (document.getElementById(id).style.display == 'none')
    document.getElementById(id).style.display = 'block';
  else
    document.getElementById(id).style.display = 'none';  
}
//---------------------------------------------------------------------------

function GetTextFromTag(TagId)
{
  var txt;
  var w = window.open('#','title','status=0, toolbar=0, location=0,menubar=0,directories=0,resizable=1,height=400,width=650');
  w.document.clear();
  w.document.write(TagId);

  if(w.window.opener) {
    txt = w.opener.document.getElementById(TagId).innerHTML;
    w.document.write(txt);
  }  
  w.stop();
  w.focus();

}
//---------------------------------------------------------------------------

sfHover_LeftNav1 = function() {
  if (!hl1_color || !hl2_color) return;

  var sfEls = document.body.getElementsByTagName('TR');
  if (!sfEls) return;
  for (var i=0, n=sfEls.length; i < n; i++) {
    if (sfEls[i].className.indexOf('hl1') != -1) {
      sfEls[i].onmouseover = function() {
        this.style.backgroundColor=hl1_color;
      }
      sfEls[i].onmouseout = function() {
        this.style.backgroundColor='Transparent';
      }
    }
    if (sfEls[i].className.indexOf('hl2') != -1) {
      sfEls[i].onmouseover = function() {
        this.style.backgroundColor=hl2_color;
      }
      sfEls[i].onmouseout = function() {
        this.style.backgroundColor='Transparent';
      }
    }
  }
}

if (window.addEventListener) {
  window.addEventListener('load', sfHover_LeftNav1, false); 
} else {
  if (window.attachEvent) {    
    window.attachEvent('onload', sfHover_LeftNav1);
  }
}

//---------------------------------------------------------------------------

function jsf_GetQSValue(qs_param) {
  var query = window.location.search.substring(1);
  if (query.length == 0) return null;
  var posA = query.indexOf('#');
  if (posA>0) query = query.substring(0,posA);
  query = query.split('&');
  for (var i=0, n=query.length; i<n; i++) {
    query[i] = query[i].split('=');
    if (query[i].length == 2) {
      if (query[i][0] == qs_param) {
        return query[i][1];
      }
    }
  }
  return null;
}
//---------------------------------------------------------------------------

function jsf_PrepareHLtext() {
  var hl_text = jsf_GetQSValue('hl');
  //alert(hl_text);
  if(!hl_text) return hl_text;
  
  try {
    hl_text = decodeURI(hl_text);
  } catch (e) {
    //alert(e.message);
    return null;
  }
  
  hl_text = hl_text.replace('+',' ');  //"+" это конкатенация слов, значит заменяем пробелом
  hl_text = hl_text.replace(/[^\|\w\u0400-\u04FF]/g,' ');  //выкидываем мусор
  //alert('hl_text=' + hl_text);
  
  hl_text = hl_text.replace(/\\/g,'\\\\');
  hl_text = hl_text.replace(/\</g,'&lt;');
  hl_text = hl_text.replace(/\./g,'\\.');
  hl_text = hl_text.replace(/\?/g,'\\?');
  hl_text = hl_text.replace(/\*/g,'\\*');
  hl_text = hl_text.replace(/\+/g,'\\+');
  hl_text = hl_text.replace(/\[/g,'\\[');
  hl_text = hl_text.replace(/\]/g,'\\]');
  hl_text = hl_text.replace(/\(/g,'\\(');
  hl_text = hl_text.replace(/\)/g,'\\)');
  hl_text = hl_text.replace(/\{/g,'\\{');
  hl_text = hl_text.replace(/\}/g,'\\}');
  return hl_text;
}
//---------------------------------------------------------------------------

jsf_MakeHLtext.HLtext = null;
//---------------------------------------------------------------------------

function jsf_MakeHLtext(in_node) {
  if (!jsf_MakeHLtext.HLtext) jsf_MakeHLtext.HLtext = jsf_PrepareHLtext();
  if (!jsf_MakeHLtext.HLtext) return;
  if (jsf_MakeHLtext.HLtext.length == 0) return;

  var lArr;
  var RuleRE, newRE;
  
  var lOrArray = jsf_MakeHLtext.HLtext.split('|');
  if (!lOrArray) return;
  
  for (var j=0, j_len=lOrArray.length; j<j_len; j++) {
    //alert(lOrArray[j]);
    
    lArr = lOrArray[j].split(' ');
    RuleRE = '';
    if (lArr) {
      for (var i=0; i<lArr.length; i++) {
        if (RuleRE != '') RuleRE = RuleRE + '.{1,10}?';
        RuleRE = RuleRE + lArr[i];
      }
    }
    RuleRE = '(?!<[^<>]*)(' + RuleRE + ')(?![^<>]*>)';
    //alert(RuleRE);
    
    newRE = new RegExp(RuleRE,'ig');

    var node_html = in_node.innerHTML;
    in_node.innerHTML = node_html.replace(newRE, '<span class="hl">$1</span>');
  }
}
//---------------------------------------------------------------------------

function jsf_MakeHLurl(in_node) {
  var node_html = in_node.innerHTML;
  in_node.innerHTML = node_html.replace(/((http(s)?|ftp)[^\s\<\)]+)/gi, '<a target="_blank" rel="nofollow" href="$1">$1</a>');
}
//---------------------------------------------------------------------------

function jsf_MakeHLmail(in_node) {
  var node_html = in_node.innerHTML;
  in_node.innerHTML = node_html.replace(/(\w+([-\+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4})/gi, '<a href="mailto:$1">$1</a>');
}
//---------------------------------------------------------------------------

function HL_node(parent_element, parent_hl_text, parent_hl_url) {
  //glob_i++;
  
  if (!parent_element) return;  
  if (!parent_element.childNodes) return;
  var child_node, cur_tagname, cur_hl_text, cur_hl_url;
  
  for (var i=0, n=parent_element.childNodes.length; i<n; i++) {
    child_node = parent_element.childNodes[i];
    if (!child_node) continue;
    
    cur_tagname = (child_node.tagName) ? child_node.tagName.toLowerCase() : '';
        
    if ((parent_hl_text) || (parent_hl_url)) {
      if ((cur_tagname == 'p') || (cur_tagname == 'td') || (cur_tagname == 'span')) {
        if (parent_hl_url) {        
          jsf_MakeHLurl(child_node);
          jsf_MakeHLmail(child_node);
        }      
        if (parent_hl_text) {
          //alert(child_node.innerHTML);
          jsf_MakeHLtext(child_node);
        }
      } else {
        if (child_node.hasChildNodes()) HL_node(child_node, parent_hl_text, parent_hl_url);
      }      
    } else {
      if (child_node.hasChildNodes()) {
        if (child_node.attributes) {
          cur_hl_text = (child_node.attributes['hl_text']) ? (child_node.attributes['hl_text'].value=='1') : false;
          cur_hl_url = (child_node.attributes['hl_url']) ? (child_node.attributes['hl_url'].value=='1') : false;
        } else {
          cur_hl_text = false;
          cur_hl_url = false;
        }
        //alert('cur_hl_text=' + cur_hl_text + '; cur_hl_url=' + cur_hl_url);
        HL_node(child_node, cur_hl_text, cur_hl_url);
      }
    }
    
  }
}
//---------------------------------------------------------------------------

//var glob_i = 0;
HL_html.glob_MakeHL = null;
//---------------------------------------------------------------------------

function HL_html() {
  if (HL_html.glob_MakeHL) HL_node(findObj('pagecontentid'), false, false);
  //alert(glob_i);
}

if (window.addEventListener) {
  window.addEventListener('load', HL_html, false); 
} else {
  if (window.attachEvent) {    
    window.attachEvent('onload', HL_html);
  }
}
//---------------------------------------------------------------------------

function LoadNewYear() {
  var curDate = new Date();
//  return;
  if ((curDate.getMonth() != 0) && (curDate.getMonth() != 11)) return;
  if ((curDate.getMonth() == 11) && (curDate.getDate() < 29)) return;
  if ((curDate.getMonth() == 0) && (curDate.getDate() > 8)) return;

  var ny_script = document.createElement('script');
  ny_script.type = 'text/javascript';
  ny_script.src = '/script/newyear.js';
  document.body.appendChild(ny_script);
}

if (window.addEventListener) {
  window.addEventListener('load', LoadNewYear, false); 
} else {
  if (window.attachEvent) {    
    window.attachEvent('onload', LoadNewYear);
  }
}

