

var xmlHttp;
var cache = new Array();

// AJAX creator
function createXMLHttpRequestObject() {
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var xmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP",
		"Microsoft.XMLHTTP");

		for (var i = 0; i<xmlHttpVersions.length && !xmlHttp; i++) {
			try {
				xmlHttp = new ActiveXObject(xmlHttpVersions[i]);
			} catch (e) { }
		}
	}

	if (!xmlHttp) {
		displayError("Error creating XMLHttpRequest Object");
	} else {
		return xmlHttp;
	}

}

// Display Error to Browser
function displayError(message) {
	alert("AJAX ERROR: " + message.toString());
}

// AJAX creator
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}

}

function openComment(commentId) {
	var commentDiv = document.getElementById("comment_" + commentId);
	if (commentDiv.style.display == "") commentDiv.style.display = "none";
	else commentDiv.style.display = "";
}


// comments request
function startCommentsRequest(module, id) {
	createXMLHttpRequest();

	xmlHttp.onreadystatechange = doCommentsUpdate;
	xmlHttp.open("GET", "/index.php?design=comments;module=" + module + ";submodule=comments;id=" + id, true);
	xmlHttp.send("");
}

// comments update
function doCommentsUpdate() {
	if (xmlHttp.readyState == 4) {
		var commentsDiv = document.getElementById("comments")
		commentsDiv.innerHTML = xmlHttp.responseText;


	}
}


/* Onload events Loader */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
