var url = 'http://www.israelfishingforum.co.il/';

var xmlHttp;
var xmlHttp2;
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();
	}

}

// AJAX creator
function createXMLHttpRequest2() {
	if (window.ActiveXObject) {
		xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp2 = new XMLHttpRequest();
	}

}


// comments request
function startSignsRequest(module, id) {
	createXMLHttpRequest2();

	xmlHttp2.onreadystatechange = doSignsUpdate;
	xmlHttp2.open("GET", "index.php?design=empty;module=" + module + ";submodule=signs;id=" + id, true);
	xmlHttp2.send("");
}

// comments update
function doSignsUpdate() {
	if (xmlHttp2.readyState == 4) {
		var signsDiv = document.getElementById("signs")
		signsDiv.innerHTML = xmlHttp2.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();
    }
  }
}


/* Comments */
// Open Comment Box with styles
function openComment(commentId) {
	var commentDiv = document.getElementById("comment_" + commentId);
	var commentHeader = document.getElementById("comment_header_" + commentId);
	var commentFooter = document.getElementById("comment_footer_" + commentId);
	var commentInside = document.getElementById("comment_inside_" + commentId);
	if (commentDiv.style.display == "") {
		commentDiv.style.display = "none";
		commentHeader.style.display = "none";
		commentFooter.style.display = "none";
		commentInside.style.backgroundColor = "";
		commentInside.style.marginTop = "10px";
	}
	else {
		commentDiv.style.display = "";
		commentHeader.style.display = "";
		commentFooter.style.display = "";
		commentInside.style.backgroundColor = "#c5c5c5";
		commentInside.style.marginTop = "0px";
	}
}


// Comments - request comments from server
function startCommentsRequest(module, id) {
	xmlHttp = createXMLHttpRequestObject();
	

	xmlHttp.onreadystatechange = doCommentsUpdate;
	xmlHttp.open("GET", "index.php?design=empty;module=" + module + ";submodule=comments;id=" + id, true);
	xmlHttp.send("");
}

// Comments - update html
function doCommentsUpdate() {
	if (xmlHttp.readyState == 4) {
		var commentsDiv = document.getElementById("comments")
		commentsDiv.innerHTML = xmlHttp.responseText;
	}
}
