function BigCover(ID){
  document.getElementById('bookcover_'+ID).style.display = 'block';
}

function CloseCover(ID){
  document.getElementById('bookcover_'+ID).style.display = 'none';
}

currentExpanded=0;
collapsePrevious=0;

function ExpandNode(nodeId){
  clickedElement=document.getElementById(nodeId).style;
  if (!clickedElement)
    clickedElement=document.all.nodeId.style
  if (!clickedElement)
    return 1
  if (clickedElement.display=="block")
  {
    clickedElement.display="none";
    if (document.getElementById('img_'+nodeId))
      document.getElementById('img_'+nodeId).src = "/static/img/plus.gif";
  }
  else {
    if ((currentExpanded) && (collapsePrevious))
      currentExpanded.display="none"
    currentExpanded=clickedElement;
    currentExpanded.display="block";
    if (document.getElementById('img_'+nodeId))
    document.getElementById('img_'+nodeId).src = "/static/img/minus.gif";
  }
  ToggledAlready=1;
}

function chkgrp(itemname){
    SubItems=document.getElementById(itemname)
    for (i=0;i != SubItems.getElementsByTagName("input").length;i++){
      SubItems.getElementsByTagName("input").item(i).checked = document.getElementById('genre_'+itemname).checked
    }
}

function UnchPrnt(name){
  document.getElementById('genre_'+name).checked=0
}

function ShowHide(id)
{
  var itm = null;
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (!itm)
  {
    // do nothing
  }
  else if (itm.style)
  {
	if (itm.style.display == "none")
	{
	  itm.style.display = "";
	}
    else
	{
	  itm.style.display = "none";
	}
  }
  else
  {
    itm.visibility = "show";
  }
}

function AddAuth()
{
  document.subscribe_form.author_list.value=document.subscribe_form.author_list.value + document.subscribe_form.author_choose.value + '\n';
}

function ExpandSubscribeForm(val)
{
  document.getElementById('subscribe_options').style.display=val>0?'block':'none';
  document.getElementById('genres').style.display=val==2?'block':'none';
  document.getElementById('genres_text').style.display=val==2?'block':'none';
  document.getElementById('pattern').style.display=val==2?'block':'none';
  document.getElementById('pattern_text').style.display=val==2?'block':'none';
  document.getElementById('authors').style.display=val==2?'block':'none';
  document.getElementById('authors_text').style.display=val==2?'block':'none';

  if (document.getElementById('email'))
  {
    document.getElementById('email').style.display=val>0?'block':'none';
  }
}

function ChkLanguage(val)
{
  if (val == 2) {
		document.getElementById('langs').style.display = 'inline';
  } else {
		document.getElementById('langs').style.display = 'none';
  }
}

function switchVisibility (id) {
  el = document.getElementById (id).style;
	im = document.getElementById ('ei_' + id);

  if (el.display == "block") {
		el.display = "none";
		im.src = "/static/img/expand.gif";
	} else {
		el.display = "block";
		im.src = "/static/img/collapse.gif";
	}
}

function HideNavigation (e_pos,id) {
	e_pos.innerHTML = '<a href="DrawNavigation (this.parentNode,'+id+')">Папки</a>';
}

function DrawConfig (id,capt) {
	document.getElementById ("div_conf").style.display = "block";
	document.getElementById ("create_input").value = id;
	document.getElementById ("ren_input").value = id;
	document.getElementById ("ren_input_txt").value = capt;
	document.getElementById ("span_capt").innerHTML = capt;
	if (id == 0) {
		document.getElementById ("ren_input_txt").disabled = true;
	} else {
		document.getElementById ("ren_input_txt").disabled = false;
	}
}

function InsertOptInCombo (el,id) {
	el.innerHTML = '<option value="0" selected>Перенести в…</option>' + combo_text;
//  document.getElementById ("submit_move_" + id).style.display = "block";
}

function DrawSubmitButton (id,v) {
  document.getElementById ("submit_move_" + id).style.display = (v!=0)?"block":"none";
}

function CoolClk(id){
  document.getElementById(id).click();
}
function DButn(id){
  document.getElementById(id).disabled=true;
}

function ShowFrame (path, medium) {
  if (medium) {
    window.open (path, '', 'scrollbars=1,resizable=1,width=900,height=700');
  } else {
    window.open (path, '', 'scrollbars=1,resizable=1,width=500,height=300');
  }
}

function SelAvatar (id) {
  window.opener.document.getElementById ('avatar_img').src = '/static/users/' + id;
  window.opener.document.getElementById ('avatar_id').value = id;
  self.close ();
}

function AddRecArt (id,capt) {
	var art_id_input = window.opener.document.getElementById ('art_id');

	if (art_id_input.value.search (id) >= 0) {
		return;
	}

	window.opener.document.getElementById ('art_name_div').innerHTML += '<h2>«' + capt + '»</h2>';
	art_id_input.value += id + ';';
	self.close ();
}

function switchDisplay (el_capt,link_capt,vis_txt,unvis_txt) {
  var el = document.getElementById (el_capt);
  var link = document.getElementById (link_capt);
  if (el.style.display == 'none') {
    el.style.display = 'block';
    link.innerHTML = vis_txt;
  } else {
    el.style.display = 'none';
    link.innerHTML = unvis_txt;
  }
}

function TextAreaMaxLength(Object, MaxLen) {
  Object.value = Object.value.substring(0,MaxLen);
}


function SearchResultsHL(hlstrings){
  var HLStrings=hlstrings.split(' ');
  for (i=0;i < HLStrings.length;i++){
    HLStrings[i]=HLStrings[i].replace('.','\.');
    HLStrings[i]=HLStrings[i].replace(/[&<>]/,'.');
    HLStrings[i]='(>[^<>]*)('+HLStrings[i]+')';
    var SearchToReplace=new RegExp(HLStrings[i],'gi');
    document.getElementById('searchresults').innerHTML=
      document.getElementById('searchresults').innerHTML.replace(SearchToReplace,'$1<span class="searchresults">$2</span>');
  }
}

function run_movie(arg,w,h) 
{ 
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+w+'" HEIGHT="'+h+'" ALIGN=""><PARAM NAME=movie VALUE="'+arg+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="'+arg+'" quality=high bgcolor=#FFFFFF WIDTH="'+w+'" HEIGHT="'+h+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>'); 
}

// -- expand news features

var news_open_id=0;

function expand_news (newsid){
    long=document.getElementById(newsid);
    short=document.getElementById('s'+newsid);
    if(long.style.display == 'none'){
            long.style.display = "block";
            short.style.display = "none";
    }else{
            long.style.display = "none";
            short.style.display = "block";
    }
            expand_off_prev(newsid);
	    news_open_id=newsid;
    }
				    
function expand_off_prev(newsid){
    if(news_open_id>0 && news_open_id != newsid){
            long=document.getElementById(news_open_id);
    	    short=document.getElementById('s'+news_open_id);
	    long.style.display = "none";
	    short.style.display = "block";
    }
}
												    
function strip_news (elem){
    msg=elem.innerHTML;
    reg = new RegExp("<([^<>\s]*)(\s[^<>]*)?>", "g");
    msg_strip=msg.replace(reg, "");
    msg_strip=msg_strip.substr(0,200)+"...";
    return msg_strip;
}

function set_short_news(){
    var e=document.getElementsByName("news");
    for(var i=0;i<e.length;i++){
    e[i].style.backgroundColor = "#FFFFFF";
    short=document.getElementById('s'+e[i].id);
    long=document.getElementById(e[i].id);
    msg=e[i].innerHTML;
    reg = new RegExp("<([^<>\s]*)(\s[^<>]*)?>", "g");
    msg_strip=msg.replace(reg, "");
    msg_strip=msg_strip.substr(0,128)+"...";
		
    long.style.display = "none";
//        long.style.border = "dotted 1px #E5E5E5";
    short.innerHTML=msg_strip+short.innerHTML;
    }
}

var bookmarkurl="http://www.elkniga.ru"
var bookmarktitle="Elkniga.ru - купить электронные книги"

function addbookmark(){
if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle)
} 

// search strings


var q_text="Поиск книг и авторов";

function loadsearchfly(){
    var qfield = document.getElementById('q');
    if(qfield.value == q_text || qfield.value == ''){
	qfield.style.color='#95bddb';
        document.searchsite.q.value=q_text;
    }
}

function searchfly(){
    var qfield = document.getElementById('q');
    if(qfield.value == q_text){
	qfield.style.color='black';
	document.searchsite.q.value='';
    }
}
						    						    