// AJAX Function
// This function is used to make an ajax request
function ajaxFunction(str, params, where, method) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
		  try {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  catch (e) {
			// If Browser does not support AJAX
			alert("Your browser does not support AJAX!");
			return false;
		   }
		}
	}
	xmlHttp.onreadystatechange=function()
	{
	  if(xmlHttp.readyState==4)	{
		// When data is received   
		consoleelem = document.getElementById(where);
		consoleelem.innerHTML=xmlHttp.responseText;
		closeLoadingWindow();
	  }
	}
	if (method == "get") {
		// Send using GET
		xmlHttp.open("GET",str+"?"+params,true);
		xmlHttp.send(null);
	} else {
		// Send using POST
		xmlHttp.open("POST",str,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		try {
			clearping();
		} catch (ex) { }
	}
	return xmlHttp;
}

// This function is used to Submit forms using AJAX.  
// This function parses the page using HTML DOM and returns get/post request
function ajaxSubmitForm(elem) {
	var str = "";
	// For all elements in form "elem"
	for (var i=0; i<elem.length; i++) {
		// get element
		var itemelem = elem.elements[i];
		// Init
		var enabled = false;
		var itemvalue = "";
		// according to the element's type do
		switch (itemelem.type) {
			// Radio Button
			case "radio":
				// If Radio Button is Checked send value
				if (itemelem.checked) {
					enabled = true;
				}
				break;
			// Check Box
			case "checkbox":
				// If Check Box is Checked send value
				if (itemelem.checked) {
					enabled = true;
				}
				break;
			// Combo Box
			case "select-one":
				// Send selected option
				itemvalue = itemelem.options[itemelem.selectedIndex].value;
				// If Combo Box has a corresponding value, send value else send name
				if (itemvalue.length <= 0) { 
					itemvalue = itemelem.options[itemelem.selectedIndex].text;
				}
				enabled = true;
				break;
			default : 
				enabled = true;
		}
		if (enabled) {
			// Concatenate Values
			if (i>0) {
				str += "&";
			}
			if (itemvalue.length > 0) {
				str += itemelem.name + "=" + itemvalue;
			} else {
				str += itemelem.name + "=" + itemelem.value;
			}
		}
	}
	return str;
}
function ajaxParamValue(elem) {
	return elem+"="+document.getElementById(elem).value;
}
