// list of parameters with defaults
//__hs_site='TEMPLATE';
//__hs_div='hyperq'; // by default - whole document
//__hs_search_prefix='http://server.com/search?query=';
//__hs_search_suffix='&param1=value1';
//__hs_anchor_style="color: #008888;"
//__hs_forbidden_tags = [ 'A','H','BIG' ];
//__hs_max_highlights=20;
//__hs_max_singleword_highlights=2;
//__hs_title_prefix='Èñêàòü â àðõèâå: &quot;';
//__hs_title_suffix='&quot;';
if (!window.__hs_site) {
 __hs_site='NG';
}
var href=escape(document.location.href);
if (window.__hs_backend_script) {
document.write('<script src="'+__hs_backend_script+'?site='+__hs_site+'&url='+href+'"></scr'+'ipt>');
}else{
document.write('<script src="http://hypersearch.novoteka.ru/hypersearch_words.js?site='+__hs_site+'&url='+href+'"></scr'+'ipt>');
}
function __hs_isAlpha(c) {
	var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ';
	var q = letters.indexOf(c);
	if (q == -1) {
		return 0;
	} else {
		return 1;
	}
}
function __hs_make_hrefs() {
	var div='hypersearch';
	if (window.__hs_div) {
		div = __hs_div;
	}
	var obj = document.getElementById(div);
	if (obj == null) {
		return; // no highlight for whole document!
		// interesno, a skolbo <body> mozhet byt' v documente?
		obj = document.documentElement.getElementsByTagName('body')[0];
	}
	var itags;
	if (window.__hs_forbidden_tags) {
		itags = __hs_forbidden_tags;
	}
	if (itags == null) {
		itags = ['A', 'H', 'BIG'];
	}
	var max_hilights;
	if (window.__hs_max_highlights) {
		max_hilights = __hs_max_highlights;
	}
	if (max_hilights == null || max_hilights<=0) {
		max_hilights = 5;
	}
	var word_hilights;
	if (window.__hs_max_singleword_highlights) {
		word_hilights = __hs_max_singleword_highlights;
	}
	if (word_hilights == null || word_hilights<=0) {
		word_hilights = 2;
	}

	var htm = obj.innerHTML;
	if (htm == null) {
		//alert('no content?');
		return;
	}
	var anchor_style = "color: #008888;";
	if (window.__hs_anchor_style) {
		anchor_style = __hs_anchor_style;
	} 
	var tmp_search_prefix = '/search.html?query=';
	if (window.__hs_search_prefix) {
		tmp_search_prefix = __hs_search_prefix;
	}
        var search_prefix='href="'+tmp_search_prefix;

	var tmp_search_suffix = '&from_hs=1';
	if (window.__hs_search_suffix) {
		tmp_search_suffix = __hs_search_suffix;
	}
	var search_suffix = tmp_search_suffix+'"';
        var title_str='';
        var title_suff='" ';
        if( window.__hs_title_prefix) {
            title_str=__hs_title_prefix;
        }
        if( window.__hs_title_suffix) {
            title_suff=__hs_title_suffix;
        }
	tag_b1 = '<a style="' + anchor_style + '" ' + search_prefix;
	tag_b2 = search_suffix;
	tag_b3 = '>';
	tag_e = '</a>';

	words = __hs_words;
	num_hilights = 0;
	for (i=0; i<words.length; i++) {
		num_word_hilights = 0;
		q = words[i];
                if (q.length > 2) {
			word = q[0];
			word_qry = q[1];
                        word_hlt=q[2];
		}else if (q.length > 1) {
			word = q[0];
			word_qry = q[1];
                        word_hlt=q[0];
		} else {
			word = q[0];
			word_qry = q[0];
                        word_hlt=q[0];
		}
		len = word.length;

                if (title_str.length>0){
                    word_title=' title="'+title_str+word_hlt+title_suff+'"';
                }else {
                    word_title='';
                }
		pos = 0;
		for (j=0; j<1000; j++) { // while(1) but limited
			pos = word_qry.indexOf(' ', pos);
			if (pos==-1) break;
			word_qry = word_qry.substr(0, pos) + '+' + word_qry.substr(pos+1);
		}
		p_shift = tag_b1.length + word_qry.length + tag_b2.length + word_title.length + tag_b3.length + word.length + tag_e.length;
		h_data = tag_b1 + word_qry + tag_b2 + word_title + tag_b3 + word + tag_e;

		if(word_qry.match(/^ *http%3A%2F%2F/i) || word_qry.match(/^ *%2F[a-z]/i))
		{
		    h_data = '<a style="' + anchor_style + '" ' + 'href="' + unescape(word_qry) + '" ' + word_title + tag_b3 + word + tag_e;
		    p_shift = h_data.length;
		}

		mode = 'search'; // 'intag', 'ignore'
		pos = 0;
		while (pos<htm.length) {
			if (mode == 'search') {
				if (htm.substr(pos, len)==word && !__hs_isAlpha(htm.substr(pos+len,1)) && !__hs_isAlpha(htm.substr(pos-1,1))) {
					htm = htm.substr(0, pos) + h_data + htm.substr(pos+len);
					pos += p_shift;
					num_hilights++;
					num_word_hilights++;
					if (num_hilights >= max_hilights || num_word_hilights >= word_hilights) {
						break;
					}
				}
				if (htm.substr(pos,1)=='<') {
					mode = 'intag';
					for (j=0; j<itags.length; j++) {
						var tag = htm.substr(pos+1, itags[j].length).toUpperCase();
						if (tag == itags[j]) {
							mode = 'ignore';
							break;
						}
					}
				}
			} else if (mode=='intag') {
				if (htm.substr(pos,1)=='>') {
					mode = 'search';
				}
			} else if (mode=='ignore') {
				for (j=0; j<itags.length; j++) {
					var tag = htm.substr(pos, itags[j].length+2).toUpperCase();
					if (tag == '</'+itags[j]) {
						mode = 'intag';
						break;
					}
				}
			}
			pos ++;
		}
		if (num_hilights >= max_hilights) {
			break;
		}
	}
	obj.innerHTML = htm;
}
function __hs_install_handler (){
    document.onkeypress = function(e) { return __hs__handlekeypress(e) };
}
var __hs_has_events=1;

function __hs__handlekeypress(e) {
  var we = null;
  if (window.event) we = window.event;
  else if (parent && parent.event) we = parent.event;
  var pressed=0;
  if (we) {
	// IE & Opera
      pressed = we.keyCode==10 ||  // IE
      (we.keyCode == 13 && we.ctrlKey); // Opera 
  } else if (e) {
// NN
      pressed = 
      (e.which==10 && e.modifiers==2) || // NN4
      (e.keyCode==0 && e.charCode==106 && e.ctrlKey) ||
      (e.keyCode==13 && e.ctrlKey) // Mozilla
  }					 
if (pressed) {
var w = window;
var txt=null;
if (w.getSelection) {
   txt = w.getSelection();
} else if (w.document.getSelection) {
   txt = w.document.getSelection();
} else {
 var selection = w.document.selection;
 if (selection) {
      var r = selection.createRange(); if (!r) return;
      txt = r.text;
    }
}
if (txt && txt != "") {
window.open("http://hypersearch.novoteka.ru/users/edit_words.html?mode=added&utf=1&word="+escape(txt)+"&query="+escape('"'+txt+'"'), "HyperAdd");
 }
}
}

