function getXhr(){
	var xhr; 
	try{xhr=new ActiveXObject('Msxml2.XMLHTTP');}
	catch(e){
		try{xhr=new ActiveXObject('Microsoft.XMLHTTP');}
		catch(e2){
			try{xhr=new XMLHttpRequest();}
			catch(e3){
				xhr=false;
			}
		}
	}
	return xhr;
}

function sendInfos(s,c){
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			receiveInfos(xhr.responseText);
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/"+s+".php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("c="+c);
}

receiveInfos=function(answer){
	document.getElementById("asdisp").innerHTML=answer;
}

function getToolsChoiceResult(id,l){
	aSLoad();
	var choice="";var and="";
	if(l){
		choice+="c.`pagetitle` like '"+l+"%'";
		and=" and ";
	}
	var toolschoice = document.getElementsByTagName("input");
	var haveCh=false;
	for(var i=0;i<toolschoice.length;i++){
		if(toolschoice[i].id.substr(0,2) == "kw" && toolschoice[i].checked){
			choice+=and+"kw.`keyword` in (";
			haveCh=true;
			break;
		}
	}
	var kwchoice="";
	for(var i=0;i<toolschoice.length;i++){
		if(toolschoice[i].id.substr(0,2) == "kw" && toolschoice[i].checked){
			if(kwchoice.length!=0)
				kwchoice+=",";
			kwchoice+="'"+toolschoice[i].value+"'";
		}
	}
	if(haveCh)
		choice+=kwchoice+")";
	sendInfos("getToolsPages",choice+"&p="+id);
}

function getTrainChoiceResult(id){
	aSLoad();
	var choice="";var and="";
	var trainchoice=document.getElementsByTagName("input");
	var haveCh=false;
	for(var i=0;i<trainchoice.length;i++){
		if(trainchoice[i].id.substr(0,2) == "kw" && trainchoice[i].checked){
			choice+=and+"kw.`keyword` in (";
			haveCh=true;
			break;
		}
	}
	var kwchoice="";
	for(var i=0;i<trainchoice.length;i++){
		if(trainchoice[i].id.substr(0,2) == "kw" && trainchoice[i].checked){
			if(kwchoice.length!=0)
				kwchoice+=",";
			kwchoice+="'"+trainchoice[i].value+"'";
		}
	}
	if(haveCh)
		choice+=kwchoice+")";
	sendInfos("getTrainings",choice+"&p="+id);
}

function getLaboRessources(l){
	aSLoad();
	searchMotorBlur();
	var choice="";var and="";var searchmotor=document.getElementById("searchmotor").value;
	if(l){
		choice+="`title` like '"+l+"%'";
		and=" and ";
	}
	if(document.getElementById("doc").checked){
		choice+=and+"`type` in ('doc'";
		if(document.getElementById("media").checked)
			choice+=",'video','audio'";
		if(document.getElementById("cs").checked)
			choice+=",'casestudy'";
		choice+=")";
		and=" and ";
	}else{
		if(document.getElementById("media").checked){
			choice+=and+"`type` in ('video','audio'";
			if(document.getElementById("doc").checked)
				choice+=",'doc'";
			if(document.getElementById("cs").checked)
				choice+=",'casestudy'";
			choice+=")";
			and=" and ";
		}else{
			if(document.getElementById("cs").checked){
				choice+=and+"`type` in ('casestudy'";
				if(document.getElementById("media").checked)
					choice+=",'video','audio'";
				if(document.getElementById("doc").checked)
					choice+=",'doc'";
				choice+=")";
				and=" and ";
			}
		}
	}
	if(searchmotor!="Recherche" && searchmotor!="Search" && searchmotor!=""){
		choice+=and+"(`title` like '%"+searchmotor+"%' or `tags` like '%"+searchmotor+"%')";
	}
	sendInfos("getLaboRessources",choice);
}

