/*Not ajax but needed anyway */
function custom_showbox(loading_text, id) {
	document.getElementById('comment_box').style.display = 'block';
	document.getElementById("comment_box").innerHTML = loading_text;
	$("#comment_box").load("./includes/custom/build_comment.php", { did: id } );
}
function custom_hidebox() {
	document.getElementById('comment_box').style.display = 'none';
}
function custom_redirect(redirect, please_login) {
	if(confirm(please_login))
	location.href="index.php?p=login&c="+encodeURIComponent(redirect);
}
function custom_addcom(did, loading_text, no_comment, token) {
	var comment = document.getElementById('comment_field').value;
	if(trim(comment) == "") alert(no_comment);
	else {
		text = encodeURIComponent(comment);
		document.getElementById("comment_box").innerHTML = loading_text;
		$("#comment_box").load("./includes/custom/add_comment.php", { id: did, content: text, t: token  } );
	}
}
function custom_deletecom(did, confirmdelete, loading, token) {
	if(confirm(confirmdelete)) {
		document.getElementById("comment_"+did).innerHTML = loading;
		$("#comment_"+did).load("./includes/custom/delete_comment.php", { id: did, t: token } );
		document.getElementById("comment_"+did).style.display = "none";
	}
}
function custom_report(page, id, confir, loading) {
	document.getElementById("comment_report_"+id).innerHTML = loading;
	$("#comment_report_"+id).load("./includes/custom/report_comment.php", { id: id, p: page, c: confir } );
}

function getElementsByClassName(ClassName,tagName,parentElement){
 var elements=new Array();
 var d=parentElement ? parentElement : document;
 var allElements;
 if(tagName)
   allElements=d.all && d.all.tags(tagName)
    || d.getElementsByTagName && d.getElementsByTagName(tagName);
 else allElements=d.all || d.getElementsByTagName("*");
 for(var i=0,len=allElements.length; i<len; i++)
  if(allElements[i].className==ClassName)
   elements[elements.length]=allElements[i];
 return elements;
}

function removeElement(ele) {
	document.getElementById(ele).style.display='none';
}
/*1.3 */
function get_hoteditor_data(uncheckhtml, thetextarea){
	if (HTML_ON == "no"){
		alert (uncheckhtml);
		return false;
	} else {
		setCodeOutput();
		var bbcode_output=document.getElementById("hoteditor_bbcode_ouput_editor").value;
		document.getElementById(thetextarea).value = bbcode_output;
		return true;
	}
}

/*1.2.5 */
function trim(str) { 
	return str.replace(/^\s*|\s*$/g,'');
}

function show_reply(text, area) {
	document.getElementById(area).innerHTML = text;
}

/* Original Code: http://www.crackajax.net/ With some minor adjustments made for the 1024 System*/
function createREQ() {
try {
     req = new XMLHttpRequest(); 
     } catch(err1) {
       try {
       req = new ActiveXObject('Msxml2.XMLHTTP'); 
       } catch (err2) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP"); 
         } catch (err3) {
          req = false;
         }
       }
     }
     return req;
}

function requestGET(url, query, req) {
	myRand=parseInt(Math.random()*99999999);
	req.open("GET",url+'?'+query+'&rand='+myRand,true);
	req.send(null);
}

function requestPOST(url, query, req) {
	req.open("POST", url, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(query);
}

function doCallback(callback, callbackarea, item) {
	eval(callback + '(item, callbackarea)');
}

function doAjax(url,query,callback,reqtype,getxml, callbackarea) {
	var myreq = createREQ();
	if(myreq == false) alert("Sorry your browser is not supported for this process");
	myreq.onreadystatechange = function() {
		if(myreq.readyState == 4) {
			if(myreq.status == 200) {
			var item = myreq.responseText;
				  if(getxml==1) {
					 item = myreq.responseXML;
				  }
				  doCallback(callback, callbackarea, item);
			}
		}
	}
	if(reqtype=='post') {
		requestPOST(url,query,myreq);
	} else {
		requestGET(url,query,myreq);
	}
}
