/*

(C) 2008 - MeerServices B.V. Maassluis.
Design en programmering door Tom van Eijmeren.

*/

var tmpDATA;

function makeXmlHttp()
{
var xmlhttp = null;
        if(window.XMLHttpRequest)
		{
        	xmlhttp = new XMLHttpRequest();
        }
		else
		{
            try
			{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
			catch(e)
			{
                window.alert("Uw browser ondersteunt het XMLHttpRequest object niet!");
            }
        }
        return xmlhttp;
}

var txtOud;

function searchChange() {
	
	var txtZoek = document.getElementById("txtSearch").value;
	
	if(txtZoek != "" || txtZoek != "Snel zoeken.." && txtZoek != txtOud){
		searchBar();
		txtOud = txtZoek;
	}
	
}

function OpenChat(naam, cat, id) {
	var xmlhttp = makeXmlHttp();
	xmlhttp.open("POST", "livechat/includes/php/medewerker_count.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.responseText == "banned"){
				alert('U bent tijdelijk uitgesloten van onze chat.');
			}else{
				if(xmlhttp.responseText != "0"){
					if(window.open('http://www.meerservices.nl/livechat/?naam=' + naam + '&cat=' + cat + '&id=' + id,'chatbox', 'width=430,height=500,scrollbars=yes,toolbar=no,location=no')){
					location = '?page=home';
					}else{
					alert('Er kan geen pop-up worden geopent, staat uw pop-up blokkering aan?');
					}
				}else{
			
				alert('Er zijn momenteel geen medewerkers beschikbaar, probeer het later opnieuw.');
				
				}
			}
		}
	}
	xmlhttp.send("");

}


function PostClick(id, target) {
	var zoekWaarde = document.getElementById("txtSearch").value;
	
	var xmlhttp = makeXmlHttp();
	xmlhttp.open("POST", "includes/php/post_click.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			window.location = target;
		}
	}
	xmlhttp.send("txtSearch=" + zoekWaarde + "&id=" + id);
}


function searchBar() {
	document.getElementById("gif_zoek_aan").style.display = "";
	document.getElementById("gif_zoek_uit").style.display = "none";
	var zoekWaarde = document.getElementById("txtSearch").value;
	
	var xmlhttp = makeXmlHttp();
	xmlhttp.open("POST", "includes/php/zoek_resultaten.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			document.getElementById('div_zoek_results').innerHTML = xmlhttp.responseText;
			document.getElementById("gif_zoek_aan").style.display = "none";
			document.getElementById("gif_zoek_uit").style.display = "";
			if(document.getElementById("div_results_panel").style.display == "none"){
				document.getElementById("div_results_panel").style.display = "";
			}
		}
	}
	xmlhttp.send("txtSearch=" + zoekWaarde);
}

function loadDiv(div, url) {
	var xmlhttp = makeXmlHttp();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			document.getElementById(div).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send("");
}