var request = false;
try {
	request = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			request = false;
		}  
	}
}

if (!request) {
	alert("Ошибка инициализации XMLHttpRequest!");
} else {
	function saveAttempt(fio, email, country, index, address, discList) {
		var textDiscList = implode(',', discList);
		var url = 
			"/status/save_attpempt.php?f=" + encodeURIComponent(fio) + 
			"&e=" + email + 
			"&c=" + encodeURIComponent(country) + 
			"&i=" + index + 
			"&a=" + encodeURIComponent(address) + 
			"&d=" + textDiscList;
		request.open("GET", url, true);
		request.send(null);
	}
	
	function updateFio() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				lastCKLobj.value = request.responseText;
			}
		}
	}
	
	function correctKbLayout(obj) {
		lastCKLobj = obj;
		request.open("GET", "/status/correct_kb_layout.php?f=" + encodeURIComponent(obj.value), true);
		request.onreadystatechange = updateFio;
		request.send(null);
	}
}

function implode( glue, pieces ) {    // Join array elements with a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: _argos
	return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}
