function cAJAX(url, meth, stringToPost, afterFunc, errorFunc){
    url = url.replace(/amp;/,"");url = url.replace(/amp;/,"");
	
	errorFunc = errorFunc ? errorFunc : 'nonAJAX';
    var hrant;
    try{hrant = new ActiveXObject('Microsoft.XMLHTTP');} catch (e) 
	{try{hrant = new ActiveXObject('Msxml2.XMLHTTP');} catch (E)
	 {try{hrant = new XMLHttpRequest} catch(eE){eval(errorFunc+'();'); return;}}}
    hrant.onreadystatechange=function(){
	    if (hrant.readyState == 4){	if (hrant.status == 200){
		    Xxml = hrant.responseXML;
			eval(afterFunc + '(Xxml);');
	    }}
    };
    hrant.open(meth, url, true);
    hrant.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
    hrant.send(stringToPost);
}
var ARR; var cc;
function Import(node) { //es funkcian verjn a!!!
	if(node.nodeType==1) {
		var newNode = document.createElement(node.nodeName);
		if (node.attributes && node.attributes.length > 0)
			for (var i = 0, il = node.attributes.length; i < il;){
				nn = node.attributes[i++].nodeName;
				if(nn=='class') newNode.className = node.getAttribute(nn);
				else if(nn=='onclick') newNode.onclick = new Function(node.getAttribute(nn));
				else newNode.setAttribute(nn, node.getAttribute(nn));
				if (nn='style') newNode.style.cssText = node.getAttribute(nn); //IEi hamar
			}
		if (node.childNodes && node.childNodes.length > 0)
			for (var i = 0, il = node.childNodes.length; i < il;){
//				if(node.nodeName.toLowerCase() == 'script') {ARR[cc++] = node.childNodes[0].nodeValue; return false;} else {
					var p = Import(node.childNodes[i++]); //rekursia :)
					if(p){
						if(p.nodeName) newNode.appendChild(p);
						else newNode.innerHTML+=p;
					}
				//}
			}
		return newNode;
	} else if (node.nodeType==4){
		return node.nodeValue;
	} else {return document.createTextNode(node.nodeValue);}
};

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

function addCommentInit(id){
	document.getElementById('link'+id).style.display='none';
	document.getElementById('form'+id).style.display='block';
}
function addComment(id){
	content = document.getElementById('text'+id).value;
	email = document.getElementById('email'+id).value;
	user = document.getElementById('name'+id).value;
	button = document.getElementById('button'+id).value;
	if(content=='') return false;
	
	content = encodeURIComponent(content);
	user = encodeURIComponent(user);
	email = encodeURIComponent(email);
	
	button.innerHTML = 'Please wait...';
	button.disabled='disabled';
	cAJAX('addcomment.php', 'POST', 'content='+content+'&email='+email+'&name='+user+'&pid='+id, 'addCommentAfter', '');
}
function addCommentAfter(xml){
	if(xml){if(xml.getElementsByTagName('ready').length > 0){
		id = xml.getElementsByTagName('ready')[0].firstChild.data;
		id = parseInt(id);
		button = document.getElementById('button'+id);
		button.disabled='disabled';
		document.getElementById('comments'+id).removeChild(document.getElementById('c'+id));
		showCommentsInit(id);
	}}	
}
function showCommentsInit(id){
	var hh=Math.random(1);
	cAJAX('comments.php?id='+id+'&amp;ankap='+hh, 'GET', null, 'showComments', '');
	document.getElementById('commentsLink'+id).onclick = new Function('return false;');
	var L= document.createElement('div');
	L.innerHTML = 'Loading...';
	L.className = 'loader';
	L.id = 'loader'+id;
	document.getElementById('comments'+id).appendChild(L);
}
function showComments(xml){
	var html = xml.getElementsByTagName('div').item(0);
	var nnode = Import(html);
	var id = html.getAttribute('id').substr(1);
	document.getElementById('comments'+id).removeChild(document.getElementById('loader'+id));
	document.getElementById('comments'+id).appendChild(nnode);
}
function hideIfLarge(id){
	var e = document.getElementById('postcontent'+id)
	var ch = e.firstChild.offsetHeight;
	if (ch>200) {
		var F = document.createElement('a');
		F.innerHTML = '<img src="images/_full.gif" alt="Show full text" /><span>Ցույց տալ ամբողջը</span>';
		F.className = 'showFull';
		tt = 200 - ch;
		F.style.top = (tt - 15) + 'px';
		e.appendChild(F);
		F.onclick = new Function('var t = document.getElementById("postcontent'+id+'"); t.style.maxHeight="'+(ch+60)+'px"; t.removeChild(t.lastChild); return false;');
	}
}

function addBB(elem, starttag, endtag){
	if(starttag!=''){
		starttag = '['+starttag+']';
		endtag = '[/'+endtag+']';
	}
	elem.focus();
	if(document.selection){
		r = document.selection.createRange();
		r.text = starttag + r.text + endtag;
		r.select();
	}else{
		sk = elem.selectionStart;
		ve = elem.selectionEnd;
		txt = elem.value.substring(sk,ve);
		txt = starttag + txt + endtag;
		elem.value = elem.value.substring(0,sk) + txt + elem.value.substr(ve);
		elem.selectionStart = sk +3;
		elem.selectionEnd = ve +3;
	}
}
function textBold(id){addBB(document.getElementById('text'+id), 'b', 'b');}
function textItalic(id){addBB(document.getElementById('text'+id), 'i', 'i');}
function textUnderline(id){addBB(document.getElementById('text'+id), 'u', 'u');}
function smile(sm,id){addBB(document.getElementById('text'+id), '', sm);}