function id2obj(id){
return document.getElementById(id)
}
function remobj(obj){
obj.parentNode.removeChild(obj)
}
function addtext(o,t){
o.appendChild(document.createTextNode(t))
}
function add_hdlr(obj, event, handler){
if(!obj)
return
if(obj.attachEvent)
obj.attachEvent("on" + event, handler)
else
obj.addEventListener(event, handler, false)
}
function del_hdlr(obj, event, handler){
if(!obj)
return
if(obj.detachEvent)
obj.detachEvent("on" + event, handler)
else
obj.removeEventListener(event, handler, false)
}
function stop_event(ev){
if (ev.preventDefault)
ev.preventDefault()
else
ev.returnValue = false
}
function get_id(pref){
if(typeof(id_counter) == 'undefined')
id_counter = 0
return pref + id_counter++
}
function set_msg(obj, msg, color){
obj.innerHTML = msg
obj.style.color = color
}
function add_btn_handlers(obj, h, remove){
var objs = obj.getElementsByTagName('a')
for(var i = objs.length; i > 0;)
if(remove)
for(var j = h.length; j > 0;)
del_hdlr(objs[--i], "click", h[--j])
else
for(var j = h.length; j > 0;)
add_hdlr(objs[--i], "click", h[--j])
}
function show_tr(r){
try{r.style.display = "table-row"}
catch(e){r.style.display = "block"}
}
function append_row(tid, row, rid, h){
var t = id2obj(tid).lastChild
var rows = t.getElementsByTagName("tr")
var r = rows[1].cloneNode(true)
var cells = r.getElementsByTagName("td")
for(var i = row.length; --i >= 0;)
cells[i].appendChild(document.createTextNode(row[i]))
add_btn_handlers(r, h, true)
add_btn_handlers(r, h)
r.id = rid
show_tr(r)
t.insertBefore(r, rows[rows.length-1])
return r
}
function edit_row(r){
var rows = r.parentNode.getElementsByTagName("tr")
var inputs = rows[rows.length-1].getElementsByTagName("td")
var cells = r.getElementsByTagName("td")
for(var i = cells.length - 1; --i >= 0;){
var inp = inputs[i].firstChild.cloneNode(true)
if(cells[i].childNodes.length == 0)
cells[i].old = inp.value = ""
else{
cells[i].old = inp.value = cells[i].firstChild.nodeValue
cells[i].removeChild(cells[i].firstChild)
}
cells[i].appendChild(inp)
}
r.edit = true
}
function cancel_edit_row(r){
var cells = r.getElementsByTagName("td")
for(var i = cells.length - 1; --i >= 0;){
cells[i].removeChild(cells[i].firstChild)
cells[i].appendChild(document.createTextNode(cells[i].old))
}
r.edit = false
}
function update_row(r){
var cells = r.getElementsByTagName("td")
for(var i = cells.length - 1; --i >= 0;){
var s = cells[i].firstChild.value
cells[i].removeChild(cells[i].firstChild)
cells[i].appendChild(document.createTextNode(s))
}
r.update = false
}
function get_array(r){
var cells = r.getElementsByTagName("td")
var arr = new Array(cells.length - 1)
for(var i = cells.length - 1; --i >= 0;)
arr[i] = cells[i].firstChild.value
return arr;
}
function anim_pbar(d){
var img = document.createElement('img')
img.src = '/files/images/pbar2.gif';
if(d.icnt++ >= d.mcnt){
d.innerHTML = ''
d.icnt = 0
}
d.appendChild(img)
}
function del_pbar(r){
clearInterval(r.pbar.timer)
r.parentNode.removeChild(r.pbar)
show_tr(r)
}
function show_pbar(r){
var p = r.parentNode, trs = p.getElementsByTagName('tr'), b = trs[2].cloneNode(true)
show_tr(b)
var d = b.firstChild.firstChild
d.icnt = 0
d.mcnt = 36
d.id = get_id('pbar')
b.timer = setInterval('anim_pbar(id2obj("' + d.id + '"))', 50)
r.pbar = b
p.insertBefore(b, r);
r.style.display = 'none';
}
function creat(t){
return document.createElement(t)
}

function showComment(id,ins) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Не вышло :( Невозможно создать экземпляр класса XMLHTTP ');
return false;
}
http_request.onreadystatechange = function() { if(ins==1) alertShow(http_request, id); else alertButtons(http_request, id);};
http_request.open('GET', "/?act=lite&type=showComment&id="+id, true);
http_request.send(null);
}
function writeComment(id) {
	commentText = document.getElementById('currentComment'+id);
	oldCommentText = document.getElementById('oldCurrentComment'+id);
	if(commentText.value==oldCommentText.value){
		alertWrite(0, http_request, id);
		return 1;
		}
	else{
		var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) {
			alert('Не вышло :( Невозможно создать экземпляр класса XMLHTTP ');
			return false;
		}
		http_request.onreadystatechange = function() { alertWrite(1, http_request, id); };
		http_request.open('GET', "/?act=lite&type=writeComment&id="+id+"&comment="+commentText.value, true);
		http_request.send(null);
	}
}
function alertShow(http_request, id) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			spn = document.getElementById('comment'+id);
			prnttxt ="";
			for(i=0;i<http_request.responseText.length-7;i++)
				if(i>5) prnttxt += http_request.responseText[i];
			spn.innerHTML = "<input type=hidden id=oldCurrentComment"+id+" value='"+prnttxt+"'><input type=text id=currentComment"+id+" value='"+prnttxt+"'><img src='files/images/tableicons/comment_on.jpg' width=20 height=20 onclick=writeComment("+id+")>";
		} else {
//		alert('С запросом возникла проблема.');
		}
	}
}
function alertWrite(wrt, http_request, id) {
	if(wrt==1){
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				spn = document.getElementById('comment'+id);
			if(http_request.responseText!="") 
				if(commentText.value!="") spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_on.jpg' width=20 height=20 onclick=openEmptyComment("+id+",1)>";
					else spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_off.jpg' width=20 height=20 onclick=showComment("+id+",1)>";
			} else {
//				alert('С запросом возникла проблема.');
			}
		}
	}
	else{
		if(commentText.value!="") spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_on.jpg' width=20 height=20 onclick=openEmptyComment("+id+",1)>";
			else spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_off.jpg' width=20 height=20 onclick=showComment("+id+",1)>";
	}
	
}
function alertButtons(http_request, id) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			spn = document.getElementById('comment'+id);
			prnttxt ="";
			for(i=0;i<http_request.responseText.length-7;i++)
				if(i>5) prnttxt += http_request.responseText[i];
			if(prnttxt=="") spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_off.jpg' width=20 height=20 onclick=openEmptyComment("+id+",1)>";
			else spn.innerHTML="<input type=hidden id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_on.jpg' width=20 height=20 onclick=showComment("+id+",1)>";
		} else {
//			alert('С запросом возникла проблема.');
		}
	}
}
function openEmptyComment(id){
	spn = document.getElementById('comment'+id);
	spn.innerHTML = "<input type=hidden id=oldCurrentComment"+id+" value=''><input type=text id=currentComment"+id+" value=''><img src='files/images/tableicons/comment_on.jpg' width=20 height=20 onclick=writeComment("+id+")>";
}

