﻿function Request(URL, Params, Element) {
	var RequestASP = "request.asp", xmlHttpReq = false, self = this;
	if (URL == "") URL = location.pathname;
	URL = URL.toLowerCase();
	if (URL.indexOf(RequestASP) > -1) Params = "url=" + encodeURIComponent(Params);
	if (window.XMLHttpRequest) { // Mozilla/Safari
		self.xmlHttpReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open("POST", URL, true);
	self.xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			if (Element != "") {
				document.getElementById(Element).innerHTML = self.xmlHttpReq.responseText;
			} else {
				return self.xmlHttpReq.responseText;
			}
		}
	}
	if (Params == "") {
		Params = "target=" + Element;
	} else {
		Params += "&target=" + Element;
	}
	self.xmlHttpReq.send(Params);
}

function RequestParams(theForm) {
	if (theForm.form != undefined) theForm = theForm.form;
	var Params = "", ParamsCount = 0;
	for (Idx = 0; Idx < theForm.elements.length; Idx++) {
		if (theForm.elements[Idx].type == "checkbox") {
			ParamsCount++;
			if (ParamsCount > 1) Params += "&";
			Params += theForm.elements[Idx].name + "=";
			if (theForm.elements[Idx].checked) Params += "on"; 
		} else if (theForm.elements[Idx].type == "radio") {
			if (theForm.elements[Idx].checked) {
				ParamsCount++;
				if (ParamsCount > 1) Params += "&";
				Params += theForm.elements[Idx].name + "=" + encodeURI(theForm.elements[Idx].value);
			}
		} else if (theForm.elements[Idx].type == "select-multiple") {
			for (var Idx2 = 0; Idx2 < theForm.elements[Idx].options.length; Idx2++) {
				if (theForm.elements[Idx].options[Idx2].selected) {
					ParamsCount++;
					if (ParamsCount > 1) Params += "&";
					Params += theForm.elements[Idx].name + "=" + encodeURI(theForm.elements[Idx].options[Idx2].value);
				}
			}				
		} else if (theForm.elements[Idx].type != undefined) {
			ParamsCount++;
			if (ParamsCount > 1) Params += "&";
			Params += theForm.elements[Idx].name + "=" + encodeURI(theForm.elements[Idx].value);
		}
	}
	return Params;
}