function $(id) {
	if (document.getElementById)
		return document.getElementById(id);
	if (document.all)
		return document.all[id];
	if (document.layers)
		return document.layers[id];
	return null;
}


var quickreply = {
	wysiwyg: false,
	wysiwyg_initialized: false,

	init: function() {
		var qr_toggle = $("quickreply-toggle");

		if (!qr_toggle)
			return;

		if (qr_toggle.addEventListener)
			qr_toggle.addEventListener("click", quickreply.toggle, false);
		else
			qr_toggle.onclick = quickreply.toggle;

		try {
			$("quickreply-row").style.display = 'table-row';
		}
		catch (e) {
			$("quickreply-row").style.display = 'block';
		}


		if (document.getElementsByTagName("html")[0].lang == "pt-br")
			quickreply.translate = function(en, pt){ return pt; };
		else
			quickreply.translate = function(en, pt){ return en; };
	},

	load_start: function(indicator) {
		document.body.style.cursor = "wait";
		var buttons = $("quickreply-row").getElementsByTagName("button");
		for (var i = 0; i < buttons.length; i++) {
			buttons[i].disabled = true;
		}
		if (indicator) {
			quickreply.load_indicator = indicator;
			quickreply.load_original = indicator.innerHTML;
			indicator.style.cursor = "wait";
			indicator.innerHTML = quickreply.translate("Loading...", "Carregando...");
		}
	},

	load_end: function() {
		document.body.style.cursor = "";
		var buttons = $("quickreply-row").getElementsByTagName("button");
		for (var i = 0; i < buttons.length; i++) {
			buttons[i].disabled = false;
		}
		if (indicator = quickreply.load_indicator) {
			indicator.style.cursor = "";
			indicator.innerHTML = quickreply.load_original;
		}
	},

	toggle: function(e) {
		var already_initialized = quickreply.wysiwyg_initialized;

		if (quickreply.wysiwyg != false && !quickreply.wysiwyg_initialized) {
			quickreply.load_start($("quickreply-toggle"));
			try {
				var oFCKeditor = new FCKeditor("content", "100%", "200");
				oFCKeditor.BasePath = '/shared/FCKeditor/';
				oFCKeditor.Config['CustomConfigurationsPath'] = '/shared/fckconfig_ddronline.js';
				oFCKeditor.Config['ToolbarCanCollapse'] = false;
				oFCKeditor.Value = "";
				oFCKeditor.ToolbarSet = "QuickReply";
				oFCKeditor.ReplaceTextarea();

				quickreply.wysiwyg = true;
				quickreply.wysiwyg_initialized = true;
			}
			catch (e) {
				quickreply.wysiwyg = false;
			}
		}

		var body = $("quickreply-body"), body_style = body.style;

		if (body_style.display == "none") {
			body_style.display = "block";

			if (!quickreply.wysiwyg)
				$("content").focus();
			else if (already_initialized)
				window.setTimeout("FCKeditorAPI.GetInstance('content').Focus()", 10);

			if (body.scrollIntoView)
				body.scrollIntoView();
		}
		else {
			body_style.display = "none";
		}

		if (e && e.preventDefault)
			e.preventDefault();
		return false;
	},

	post: function(act) {
		if (quickreply.wysiwyg) {
			FCKeditorAPI.GetInstance("content").UpdateLinkedField();
		}
		$("quickreply-content").value = $("content").value;
		$("quickreply-act").value = act;
		$("quickreply-form").submit();
	}
}




if (window.addEventListener)
	window.addEventListener("load", quickreply.init, false);
else if (window.attachEvent)
	window.attachEvent("onload", quickreply.init);


function FCKeditor_OnComplete(instance) {
	if (quickreply.wysiwyg_initialized) {
		instance.Focus();
		quickreply.load_end();
	}
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

