var checkboxflag=false;
var oldHandler;
function stopRKey(evt) {

  var evt = (evt) ? evt : ((event) ? event : null);

  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
  
}
/*
function stopRKeyFortagEditor(tagname) {
	var tagedit = document.getElementById[tagname];
	if(tagedit){
		tagedit.onkeypress = stopRKey;
	}
}*/

/*document.onkeypress = stopRKey;*/


function UnSetGlobalCheckboxFlag(){
	//alert(flag);
	checkboxflag=false;
}
function SetGlobalCheckboxFlag(flag){
	//alert(flag);
	checkboxflag=true;
	window.setTimeout("UnSetGlobalCheckboxFlag()",100);
}

function ShowInfoPanel(divname){
	document.getElementById(divname).style.visibility='visible';
}

function HideInfoPanel(divname){
	document.getElementById(divname).style.visibility='hidden';
}

function CopyData(src,dst){
	src=document.getElementById(src).innerHTML;
	dst=document.getElementById(dst);
	dst.innerHTML=src;
}
function ShowHideVotePanel(divname){
	div=document.getElementById(divname);
	if(div.style.visibility=='hidden'){
		div.style.visibility='visible';
	}
	else{
		div.style.visibility='hidden';
	}
}
function ShowHideVotePanel2(divname,action){
	div=document.getElementById(divname);
	if(action=='show'){
		div.style.visibility='visible';
		window.setTimeout("ShowHideVotePanel('"+divname+"','hide')",4000);
	}
	else{
		div.style.visibility='hidden';
		
	}
}

function PrintPage(wnd){
	if (wnd.print){
		wnd.print();
	}
}
function PrintPhoto(filename,title){
	var popupWin = window.open(filename,title, 'location,width=800,height=600,top=0');
	//window.setTimeout('PrintPage(popupWin)',1000);
	popupWin.print();
//	popupWin.focus();
}

function encode_utf8( s ) 
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
function strreplace2(replacement,str,n){
	str = str.substr(0,(n-1)) + replacement +  str.substr(n);
	return str;
}
function showspan(obj,num) {
	var pic;
	pic=document.getElementById('nodepic'+num);
	if (document.getElementById(obj).style.display == 'none'){ 
			pic.src='http://i.spark-media.ru/gallery/minus.gif';
			document.getElementById(obj).style.display = 'block';
		}
	else {
			pic.src='http://i.spark-media.ru/gallery/plus.gif';
		document.getElementById(obj).style.display = 'none';
	};
}

function selectimg(imgname,flag){
	var img=document.getElementById(imgname);
	if(flag){
		img.style.background='#3399FF';
	}
	else{
		img.style.background='none';
	}
}

function quote_comment(username,bbcomment,bbtextid){
	var bbtext=document.getElementById(bbtextid).value;
	alert(bbtext);
	var textarea=document.getElementById('xbb_editor').contentWindow.document.getElementById('xbb_textarea');
	if(textarea){
		var message="[quote=\""+username+"\"]"+bbtext+"[/quote]";
		textarea.innerText=textarea.innerText+message;
	}
}
//
function hotkeys(e) {
  if (!e) e = window.event;
  var k = e.keyCode;
  if (e.ctrlKey) {
	var d;
    if (k == 37) { d = document.getElementById('previous_page'); } // Ctrl+Left
    if (k == 39) { d = document.getElementById('next_page'); } // Ctrl+Right
    if (d){location.href = d.value;};
  }
}
//
function initkeys() {
  document.onkeydown = hotkeys;
}

function checkAll(oForm, cbName, checked){
	for (var i=0; i < oForm[cbName].length; i++) oForm[cbName][i].checked = checked;
}
