/** 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;
}



//--------------------------------------------

var baseText = null;

function showbackgroundmask(){
	var background = document.getElementById("popupbackpage");
	background.style.top = "0px";
	background.style.left = "0px";
	background.style.width = "100%";
	background.style.height = "100%";
	
	background.style.visibility = "visible";
	
}
function showPopupaddpage(w,h){
	showbackgroundmask();
	var popUp = document.getElementById("popupcontentaddpage2");
	
	popUp.style.top = "200px";
	popUp.style.left = "0px";
	//popUp.style.width = w + "px";
	popUp.style.width = "100%";
	popUp.style.height = h + "px";
	

	if (baseText == null) baseText = popUp.innerHTML;
	popUp.innerHTML = baseText +
	"<div id=\"statusbar\"><button onclick=\"hidePopupaddpage();\">Close window<button></div>";
	
	var sbar = document.getElementById("statusbar");
	sbar.style.marginTop = (parseInt(h)-40) + "px";
	popUp.style.visibility = "visible";
}

function hidePopupaddpage(){
	var popUp = document.getElementById("popupbackpage");
	popUp.style.visibility = "hidden";
	var background = document.getElementById("popupcontentaddpage2");
	background.style.visibility = "hidden";
}

function showPopupeditpage(w,h){
	showbackgroundmask();

	var popUp = document.getElementById("body1");
	long1 = popUp.offsetWidth;

	var popUp = document.getElementById("popupcontentedit");

	popUp.style.top = "30px";
	popUp.style.left = "0px";
	//popUp.style.width = w + "px";
	popUp.style.width = "100%";
	//popUp.style.height = h + "px";

	popUp.style.visibility = "visible";
}

function addarticleinpage(){
	var popUp = document.getElementById("actiontype");
	popUp.value = "newarticle";
	showPopupeditpage(0,0);

}

function editarticleinpage(id){
	//recupe le text and title
	var text1 = document.getElementById("arttitle"+id).innerHTML;
    document.getElementById("titlearticle").value = text1;
		
	var text1 = document.getElementById("arttext"+id).innerHTML;
    document.getElementById("content").value = text1;
	
	document.getElementById("updateid").value = id;	
	
	var text1 = document.getElementById("artenable").value;
	document.getElementById("isvisible_"+text1).checked=true;
	
	var popUp = document.getElementById("actiontype");
	popUp.value = "updatearticle";
	showPopupeditpage(0,0);
	
}

function hidePopupeditpage(){
	var elm = document.getElementById('content');
	
	if (tinyMCE.getInstanceById('content') != null) {  
	    tinyMCE.execCommand('mceRemoveControl', false, 'content');
	}
	
	var popUp = document.getElementById("popupbackpage");
	popUp.style.visibility = "hidden";
	var background = document.getElementById("popupcontentedit");
	background.style.visibility = "hidden";

}

function deletearticleinpage(id){
	var text1 = document.getElementById("arttitle"+id).innerHTML;
	
	input_box=confirm("Are you sure to want to delete the article ["+ text1 +"]");
	if (input_box==true) { 
		input_box=confirm("Sure? It will be definitly lost!");
		if (input_box==true) { 
			document.getElementById("iddelete").value = id;
			document.getElementById("formdeletearticle").submit();
		}
	}
}