//General useful functions

function fncAJAXSend(strAction, strMethod, blnAsync, strData, strResultFunc) {
	var objAJAX = null;
	try {// Firefox, Opera 8.0+, Safari
		objAJAX = new XMLHttpRequest();
		objAJAX.overrideMimeType('text/xml');
	}
	catch (e) {// Internet Explorer
		try {
			objAJAX = new ActiveXObject("Msxml2.ServerXMLHTTP");
		}
		catch (e) {
			objAJAX = new ActiveXObject("Microsoft.ServerXMLHTTP");
		}
	}
	
	if (objAJAX == null) {
		return false;
	} else {
		objAJAX.open(strMethod.toUpperCase, strAction, blnAsync);
		objAJAX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		if (strAsync == true) {
			objAJAX.onreadystatechange = function() {
				if (objAJAX.readyState == 4) {
					eval(strResultFunc + '(objAJAX.responseText;);');
				}
			};
		}
		objAJAX.send(strData);
		if (strAsync != true) {
			eval(strResultFunc + '(objAJAX.responseText;);');
		}
	}
	return true;
}

// The var docForm should be a reference to a <form>
function formData2QueryString(docForm) {

	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		
		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
				
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
				
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + escape(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + escape(formElem.value);
					}
					strSubmitContent += '&';
					strLastElemName = formElem.name;
				}
				break;
				
		}
	}
	
	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}
