// JavaScript Document
var isFireFox = 0
if (navigator.userAgent.indexOf("Firefox")!=-1) isFireFox = 1;

function xml_nieuwe_categorie() {
  xml_get("/xml_gets/categorie_nieuw.asp", "xmlControl1", "xml_nieuwe_categorie_onLoad()");
}
function xml_nieuwe_categorie_onLoad() {
  document.frmControl.inpCategorieNieuw.select();
}
function xml_nieuwe_categorie_bewaar() {
  var titel = document.getElementById("inpCategorieNieuw").value;
  var tekst = document.getElementById("txtOmschrijving").value;
  if (titel=="" || tekst=="") {
  	alert("Zowel categorienaam als korte omschrijving moeten ingevuld zijn.");
	document.frmControl.inpCategorieNieuw.select(); }
  else {
	xml_get("/xml_gets/categorie_nieuw.asp?save=1&titel=" + titel + "&omschrijving=" + tekst, "xmlControl1", "xml_nieuwe_categorie_bewaar_onLoad()");
  }
}
function xml_nieuwe_categorie_bewaar_onLoad() {
  //niets te doen...
}
function xml_kies_categorie() {
  xml_get("/xml_gets/categorie_kies.asp", "xmlControl1", "xml_kies_categorie_onLoad()");
}
function xml_kies_categorie_onLoad() {
}
function xml_kies_categorie_bewaar(cat_id) {
  xml_get("/xml_gets/categorie_kies.asp?cat_id=" + cat_id, "xmlControl1", "xml_kies_categorie_bewaar_onLoad()");
}
function xml_kies_categorie_bewaar_onLoad() {
  var categorie_gegevens = document.getElementById("xmlControl1").innerHTML;
  var arr_categorie_gegevens  = categorie_gegevens.split("xxxx");
  document.getElementById("resCategorie").innerHTML = arr_categorie_gegevens[0];
  document.getElementById("tmp_blog_cat_foto").value = "/images/categorie/" + arr_categorie_gegevens[1];
  xml_write("xmlControl1","<img src=\"/images/info.gif\" width=\"16\" height=\"18\" align=\"absmiddle\"> <b>De categorie is succesvol aangepast.</b>");
}
function xml_kies_redacteur() {
  xml_get("/xml_gets/redacteur_kies.asp", "xmlControl1", "xml_kies_redacteur_onLoad()");
}
function xml_kies_redacteur_onLoad() {
}
function xml_kies_redacteur_bewaar(red_id) {
  xml_get("/xml_gets/redacteur_kies.asp?red_id=" + red_id, "xmlControl1", "xml_kies_redacteur_bewaar_onLoad()");
}
function xml_kies_redacteur_bewaar_onLoad() {
  document.getElementById("resRedacteur").innerHTML = document.getElementById("xmlControl1").innerHTML;
  xml_write("xmlControl1","<img src=\"/images/info.gif\" width=\"16\" height=\"18\" align=\"absmiddle\"> <b>De redacteur is succesvol aangepast.</b>");
}

function xml_kies_video() {
  xml_get("/xml_gets/video_kies.asp", "xmlControl1", "xml_kies_video_onLoad()");
}
function xml_kies_video_onLoad() {
}
function xml_kies_video_bewaar() {
  var videoblob = document.getElementById("txtVideo").value;
  var ververs   = "0"; 
  if (document.getElementById("chkRefresh").checked) {ververs = "1";}
  
  xml_post("/xml_gets/video_kies.asp?bSave=1", "xmlControl1", "xml_kies_video_bewaar_onLoad()","chkRefresh=" + ververs + "&txtVideo=" + escape(videoblob));
}
function xml_kies_video_bewaar_onLoad() {
  var scriptcode = document.getElementById("xmlControl1").innerHTML;
  if (trim(scriptcode) != "") {
  	eval(document.getElementById("xmlControl1").innerHTML);
  }
  xml_write("xmlControl1","<img src=\"/images/info.gif\" width=\"16\" height=\"18\" align=\"absmiddle\"> <b>De video is succesvol aangepast.</b>");
}

function xml_postvideo(url, spanControl, js_loadfunctie, sendlist) {
	xmlhttp = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch(e) {
			xmlhttp = false;
		}
		// branch for IE/Windows ActiveX version
	} 
	else if(window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlhttp = false;
			}
		}
	}
	if(xmlhttp) {
		xmlhttp.onreadystatechange = function() {
 			if (xmlhttp.readyState==4) {
   				document.getElementById(spanControl).innerHTML = xmlhttp.responseText;
				eval(js_loadfunctie);
  			}
		}
		xmlhttp.open("POST", url, false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(sendlist);
	}
}




//Algemene xml-aansturingsroutines
var xmlhttp;

function xml_clear(spanControl) {
  document.getElementById(spanControl).innerHTML = "";
}

function xml_write(spanControl, sTekst) {
  document.getElementById(spanControl).innerHTML = sTekst;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


var xmlreqs = new Array();

function CXMLReq(freed) {
	this.freed = freed;
	this.xmlhttp = false;
	if (window.XMLHttpRequest) {
		this.xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function xml_get(url, retourspan, js_loadfunctie, toonloading) {
	var prosied = 1;
	if (retourspan!="") {
		if (!document.getElementById(retourspan)) prosied = 0;
	}
	
	if (prosied==1) {
		if (toonloading=="1" && retourspan!="") {
			xml_write(retourspan,"<table width='100%' cellpadding='0' cellspacing='0'><tr><td class='groen'><img src='/imgv2/loading/mozilla_blu.gif' alt='bezig met laden' align='absmiddle'> Even geduld...</td></tr><table>");
		}
		var pos = -1;
		for (var i=0; i<xmlreqs.length; i++) {
			if (xmlreqs[i].freed == 1) { pos = i; break; }
		}
		if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
		if (xmlreqs[pos].xmlhttp) {
			xmlreqs[pos].freed = 0;
			xmlreqs[pos].xmlhttp.open("GET",url,true);
			xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
			xmlreqs[pos].xmlhttp.onreadystatechange = function() {
				if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos, retourspan, js_loadfunctie); }
			}
			if (window.XMLHttpRequest) {
				xmlreqs[pos].xmlhttp.send(null);
			} else if (window.ActiveXObject) {
				xmlreqs[pos].xmlhttp.send();
			}
		}
	}
}

function xml_post(url, retourspan, js_loadfunctie, data, encodeextraweg) {
	var pos = -1;
	for (var i=0; i<xmlreqs.length; i++) {
		if (xmlreqs[i].freed == 1) { pos = i; break; }
	}
	if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
	if (xmlreqs[pos].xmlhttp) {
		xmlreqs[pos].freed = 0;
		xmlreqs[pos].xmlhttp.open("POST",url,true);
		xmlreqs[pos].xmlhttp.onreadystatechange = function() {
			if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos, retourspan, js_loadfunctie); }
		}
		xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlreqs[pos].xmlhttp.send(data);
	}
}

function xmlhttpChange(pos, retourspan, js_loadfunctie) {
	if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) {
		if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) {
			if (retourspan!="") {
				if (document.getElementById(retourspan)) document.getElementById(retourspan).innerHTML = xmlreqs[pos].xmlhttp.responseText;
			}
			if (js_loadfunctie!="") eval(js_loadfunctie);
		} else {
			//alert("Kon niet posten, probeer opnieuw: " + xmlreqs[pos].xmlhttp.status);
			if (document.getElementById(retourspan)) document.getElementById(retourspan).innerHTML = xmlreqs[pos].xmlhttp.responseText;
		}
		xmlreqs[pos].freed = 1;
	}
}
