
// get external data using AJAX
function getExternalData(jURL, jField, jSendData) {
	try {	var xmlHttpReq = false;
			var self = document.getElementById(jField);
			var jDate = new Date(); 

			if (window.XMLHttpRequest) {			// Mozilla/Safari
				self.xmlHttpReq = new XMLHttpRequest();
			} else if (window.ActiveXObject) {			// IE
				self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}

			// DO ACTIAL POST
			self.xmlHttpReq.open('POST','/forms/'+jURL+'.asp?dt='+escape(jDate),true);
			self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

			// Handle result
			self.xmlHttpReq.onreadystatechange = function() {
				if (self.xmlHttpReq.readyState == 4) {
					updatepage(self.xmlHttpReq.responseText, jField);
				} 
			}

			// Send FORM data
			self.xmlHttpReq.send(jSendData);

	} catch (excp) { alert(excp); }
}


// update webpage - handle when ajax request is finished
function updatepage(jHtml, jField){
    if (checkObject(jField))	{ document.getElementById(jField).innerHTML = jHtml; }
	if (jField=='Uitloggen')	{ window.location.reload(); }

}



// --------------------------------------------------------------------------------------------------------------
// VACATURE SEARCH FORM ACTION
// --------------------------------------------------------------------------------------------------------------
function doVacatureSearch(jObjForm, jScriptname) {
	try {	if (checkObject("VacatureZoeken")) {
				var jCity		= jObjForm.elements['VacatureCity'].options[jObjForm.elements['VacatureCity'].selectedIndex].value;
				var jFunction	= jObjForm.elements['VacatureFunction'].options[jObjForm.elements['VacatureFunction'].selectedIndex].value;
				var jKeyWords	= jObjForm.elements['VacatureKeyword'].value + ' ';
				var jPageID		= jObjForm.elements['pageID'].value;
				var jPageURL	= jObjForm.elements['pageURL'].value;

				// ensure we have only one keyword
				jKeyWords = jKeyWords.substring(0, jKeyWords.indexOf(' '));
				jObjForm.elements['VacatureKeyword'].value = jKeyWords;

				document.getElementById("VacatureOverzicht").innerHTML = '<img src="/images/loading_circle.gif" width=32 height=32 border=0 vspace=75 hspace=10 align=absmiddle alt="">Bezig op ophalen van het vacatureoverzicht...';
				getExternalData(jScriptname, 'VacatureOverzicht', 'id='+jPageID+'&u='+jPageURL+'&q='+jKeyWords+'&c='+escape(jCity)+'&f='+escape(jFunction)+'&do=true');
			}
		} catch (excp) { return false; }
	return false;
}


// -----------------------------------------------------------------------------------
// SIGNOUT
// -----------------------------------------------------------------------------------
function werknemerUitloggen() {
	getExternalData('ajax-werknemers-uitloggen', 'Uitloggen', '');
}
