function GetXmlHttpObject(){
var xmlHttp=null;
try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}catch (e) {
 //Internet Explorer
	try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}
return xmlHttp;
}


var type;

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		var txt;
		var opt;
		txt = xmlHttp.responseText;
		//alert(txt);
		txtarray = txt.split("||");
		if (txtarray[0]=="subinfo"){
			document.getElementById(type+"_sub").innerHTML="<select style='margin-left:230px;' name='"+type+"_sub' >"+txtarray[1]+"</select>";
		} 
		if (txtarray[0]=="courses"){
			clearOptions();
			//alert(txtarray[1]);
			opt = txtarray[1];
			if (opt=="Algemene brochure|"){
				appendOptionLast('courses','Algemene brochure','algemeen');
			}else{
				txtarray2 = opt.split("|");
				for (var loop = 0; loop <txtarray2.length; loop++){
					//alert(txtarray2[loop]);
					if(txtarray2[loop]=="Algemene brochure"){
						appendOptionLast('courses','Algemene brochure','algemeen');
					}
					if (txtarray2[loop].indexOf("^^")>0){
						optionarr = txtarray2[loop].split("^^");
						appendOptionLast('courses',optionarr[1],optionarr[0]);
					}
				}
			}
			document.getElementById('courses').selectedIndex = 0;
		}
		
		if (txtarray[0]=="changeItem"){
			//alert(txtarray[1]);
			document.getElementById('shoppingcart').innerHTML = txtarray[1];
		}
	 } 
}


function addItem(form){
	selectlist = form.courses;
	selecteditem = form.courses.selectedIndex;
	selectlist_inst = form.institute;
	selecteditem_inst = form.institute.selectedIndex;
	
	//alert(selectlist.options[selecteditem].value);
	//alert(selectlist_inst.options[selecteditem_inst].value);
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/shared/ajax.php";
	url=url+"?action=add&course="+selectlist.options[selecteditem].value+"&institute="+selectlist_inst.options[selecteditem_inst].value+"&type=brochure";
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addGuide(name){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/shared/ajax.php";
	url=url+"?action=add&guide="+name+"&type=guide";
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function clearItems(){
	//alert('test');
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/shared/ajax.php";
	url=url+"?action=clear";
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function deleteItem(instid,courseid,type){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/shared/ajax.php";
	url=url+"?action=delete&course="+courseid+"&institute="+instid+"&formtype="+type;
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function deleteGuide(guidecode,type){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/shared/ajax.php";
	url=url+"?action=deleteGuide&guide="+guidecode+"&formtype="+type;
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


