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 sendSemInfos(s,c,o){
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			switch(xhr.responseText){
				case "semtrue":
					strhref=window.location.href;
					lastdiezpos=strhref.lastIndexOf("#");
					if(lastdiezpos!=-1)
						strhref=strhref.substring(0,lastdiezpos);
					lastslashpos=strhref.lastIndexOf("/");
					validurl=strhref.substr(lastslashpos,11);
					if(validurl=="/validation")
						location.reload(true);
					else
						window.location.replace(strhref+"/validation");
				break;
				case "vwfalse":
					vwfalse();
				break;
				case "vwtrue":
					vwtrue("sem");
				break;
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/"+s+".php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(c);
}

function getWheres(s){
	document.getElementById('selectcity').innerHTML="";
	myIMG=document.createElement("img");
	myIMG.setAttribute("src","/assets/templates/images/misc/loading.gif");
	document.getElementById('selectcity').appendChild(myIMG);
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			document.getElementById('selectcity').innerHTML=s;
			resp=xhr.responseText.split("||");
			sel=document.getElementById('city');
			sel.innerHTML="";
			for(i=0;i<resp.length-1;i++){
				parts=resp[i].split(">");
				if(i==0){
					opt=document.createElement("option");
					opt.setAttribute("value","");
					opt.setAttribute("selected","true");
					opt.appendChild(document.createTextNode(s));
					sel.appendChild(opt);
				}
				opt=document.createElement("option");
				opt.setAttribute("value",parts[0]);
				opt.appendChild(document.createTextNode(parts[1]));
				sel.appendChild(opt);
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/getWheres.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("c="+document.getElementById('trainings').value);
}

function getSession(s){
	document.getElementById('selectsession').innerHTML="";
	myIMG=document.createElement("img");
	myIMG.setAttribute("src","/assets/templates/images/misc/loading.gif");
	document.getElementById('selectsession').appendChild(myIMG);
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			document.getElementById('selectsession').innerHTML=s;
			resp=xhr.responseText.split("||");
			sel=document.getElementById('session');
			sel.innerHTML="";
			for(i=0;i<resp.length-1;i++){
				parts=resp[i].split(">");
				if(i==0){
					opt=document.createElement("option");
					opt.setAttribute("value","");
					opt.setAttribute("selected","true");
					opt.appendChild(document.createTextNode(s));
					sel.appendChild(opt);
				}
				opt=document.createElement("option");
				opt.setAttribute("value",parts[0]);
				opt.appendChild(document.createTextNode(parts[1]));
				sel.appendChild(opt);
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/getSessions.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("c="+document.getElementById('city').value);
}

function getParts(s){
	document.getElementById('selectnbrpart').innerHTML="";
	myIMG=document.createElement("img");
	myIMG.setAttribute("src","/assets/templates/images/misc/loading.gif");
	document.getElementById('selectnbrpart').appendChild(myIMG);
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			document.getElementById('selectnbrpart').innerHTML=s;
			resp=xhr.responseText.split("||");
			sel=document.getElementById('nbrpart');
			sel.innerHTML="";
			for(i=0;i<resp.length-1;i++){
				parts=resp[i].split(">");
				if(i==0){
					opt=document.createElement("option");
					opt.setAttribute("value","");
					opt.setAttribute("selected","true");
					opt.appendChild(document.createTextNode(s));
					sel.appendChild(opt);
				}
				opt=document.createElement("option");
				opt.setAttribute("value",parts[0]);
				opt.appendChild(document.createTextNode(parts[1]));
				sel.appendChild(opt);
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/getParts.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("c="+document.getElementById('session').value);
}

function setParts(elt){
	form=document.getElementById("train_insc_form");
	hide=document.createElement("input");
	hide.setAttribute("id","nbpart");
	hide.setAttribute("type","hidden");
	hide.setAttribute("value",elt.value);
	form.appendChild(hide);
}

function sendTInscInfos(s,c){
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			switch(xhr.responseText){
				case "insctrue":
					if(/^[a-zA-Z0-9]+\/$/.test(window.location.href))
						window.location.replace(window.location.href+"validation");
					else
						window.location.replace(window.location.href+"/validation");
				break;
				case "vwfalse":
					vwfalse();
				break;
				case "vwtrue":
					vwtrue("tinsc");
				break;
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/"+s+".php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(c);
}

function sendContactForm(s,c){
	var xhr=getXhr();
	xhr.onreadystatechange=function(){
		if(xhr.readyState==4){
			switch(xhr.responseText){
				case "contacttrue":
					document.getElementById('forminfovalid').style.display="block";
					form=document.getElementById('form_information_demand');
					inputs=form.getElementsByTagName('input');
					selects=form.getElementsByTagName('select');
					selects[0].selectedIndex=0;
					selectChoose(selects[0]);
					for(i=0;i<inputs.length;i++){
						if(inputs[i].type=="text")
							inputs[i].value="";
					}
					form.message.value="";
					document.getElementById("ctformimgload").style.display="none";
					document.getElementById("subbtn").style.display="block";
					captcha=document.getElementById('captchadiv');
					img=captcha.getElementsByTagName('img')[0];
					lbl=captcha.getElementsByTagName('label')[0];
					inp=captcha.getElementsByTagName('input')[0];
					img.src="/manager/includes/veriword.php?rand="+Math.random();
				break;
				case "vwfalse":
					vwfalse();
				break;
				case "vwtrue":
					vwtrue("contact");
				break;
			}
		}
	};
	xhr.open("POST", "/assets/templates/js/ascripts/"+s+".php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(c);
}
