var http_request = false;
var return_value =  false;
var loader = false;

function makeRequest(url) {
	
	if (loader) {
	
		document.getElementById(loader).innerHTML = "<img src='/images/loading_small.gif'>";
	
	}

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   http_request = new XMLHttpRequest();
   } else if (window.ActiveXObject) { // IE
	   http_request = new ActiveXObject("Microsoft.XMLHTTP");
   }
   http_request.onreadystatechange = setContents;
   http_request.open('GET', url, true);
   http_request.send(null);

}

function setContents() {

   if (http_request.readyState == 4) {
	   if (http_request.status == 200) {
		   return_value = http_request.responseText;
		   document.getElementById(loader).innerHTML = http_request.responseText;
	   } else {
		   alert('Er was een probleem met het afhandelen van uw verzoek. Probeer het later nog een keer.');
	   }
   }

}


/* ---------------------------------------------------- 
	SPECIALISMEN
   ---------------------------------------------------- */

function add_spec(id,loader_div) {

	if (loader_div) {
		loader = loader_div;
	}

	if (document.getElementById("spec_" + id).checked == true) {
		
		makeRequest('/lib/ajax/spec_add.php?id=' + id);
	
	} else {
	
		makeRequest('/lib/ajax/spec_del.php?id=' + id);
	
	}

}

function list_specs(branche,div) {
	
	url = '/lib/ajax/spec_selector.php?action=list_branche_specs&branche_id='+branche;
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Updater(div, url);
	
}

function search_specs(div) {
	
	val = $F('search');
	
	if (val.length > 2) {
		
		url = '/lib/ajax/spec_selector.php?action=search_branche_specs&q='+val;
		
		if (div) {
			loader = div;
		}
		
		new Ajax.Updater(div, url);
		
	}
	
}

function list_proj_spec(div) {
	
	url = '/lib/ajax/spec_selector.php?action=list';
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Updater(div, url);
	
}

function list_proj_spec_names(div) {
	
	url = '/lib/ajax/spec_selector.php?action=get_selected_names';
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Updater(div, url);
	
}

function get_proj_spec_ids(el) {
	
	url = '/lib/ajax/spec_selector.php?action=get_selected_ids';
	
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			var html_el = document.getElementById(el);
			html_el.value = transport.responseText;
			
			//window.close();
		}
	});	
	
}

function del_proj_spec(spec_id,div) {
	
	url = '/lib/ajax/spec_selector.php?action=del&id='+spec_id
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Request(url);
	
	list_proj_spec(div);
	
}

function add_proj_spec(id,name,div) {
	
	url = '/lib/ajax/spec_selector.php?action=add&id=' + id + '&title=' + name;
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Request(url);
	
	list_proj_spec(div);
	
}

function clear_proj_spec(div) {
	
	url = '/lib/ajax/spec_selector.php?action=clear';
	
	if (div) {
		loader = div;
	}
	
	new Ajax.Request(url);
	
	list_proj_spec(div);
	
}

function save_specs() {
	
	html = 'leeg';
	ids = '0';
	
	// waarden overzetten naar opener.docuent (tekstueel en id's)
	url = '/lib/ajax/spec_selector.php?action=get_selected_names';
	
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			var html_el = opener.document.getElementById("selected_specs");
			html_el.update(transport.responseText);
		}
	});	
	
	url = '/lib/ajax/spec_selector.php?action=get_selected_ids';
	
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			var html_el = opener.document.getElementById("spec_ids");
			html_el.value = transport.responseText;
			
			window.close();
		}
	});	
			
}

/* ---------------------------------------------------- 
	CV
   ---------------------------------------------------- */
function cv_add_opl() {
	
	new Insertion.Bottom($("cv_opleiding_container"), $('tpl_cv_opleiding_container').innerHTML);
	
}

function cv_del_opl(alink) {
	
	$($($(alink).parentNode).parentNode).remove();

}

function cv_add_wrk() {
	
	new Insertion.Bottom($("cv_werkgever_container"), $('tpl_cv_werkgever_container').innerHTML);
	
}

function cv_del_wrk(alink) {
	
	$($($(alink).parentNode).parentNode).remove();

}
