// JavaScript Document
/**
 * @filename: this file contains functions and other utilities related to AJAX only.
 * 
 * @author: CIPL/SW/013
 * @dated: Wednesday February 06, 2008
 * 
 * 
 * @modified date:
 * @reason to modify:
 * @modified by:
 */

/**
 * @uses:	The function GetXMLHttpRequest() is used to fetch an object of XMLHTTP.
 * @param:	none
 * @return:	XMLHTTP object: Otherwise blank(i.e. '').
 */
function GetXMLHttpRequest() {
	
	//	Check for Mozilla, Netscape, Safari, etc.
	if(window.XMLHttpRequest) {
		try {
			objxmlhttprequest = new XMLHttpRequest();
		} catch (e) {
			objxmlhttprequest = '';
		}
	}
	else if(window.ActiveXObject) {//	Microsoft or likewise.
		objxmlhttprequest = MicrosoftLikewise();
	}
	
	return objxmlhttprequest;
}

/**
 * @uses:	The function MicrosoftLikewise() is used to fetch an object of XMLHTTP in case
 * 			the browser is Microsoft or likewise.
 * @param:	none
 * @return:	XMLHTTP object; Otherwise, blank(i.e. '').
 */
function MicrosoftLikewise() {
	
	var arrxmlhttp = new Array("Msxml2.XMLHTTP", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP.4.0",
					  "Msxml2.XMLHTTP.5.0", "Microsoft.XMLHTTP");
	
	for(var i= 0; i < parseInt(arrxmlhttp.length); i++) {
		try {
			objxmlhttprequest = new ActiveXObject(arrxmlhttp[i]);
			
			return objxmlhttprequest;
		} 
		catch (e) {
			// Do nothing.
		} // End of catch.
		
	} // End of for.
	
	alert("Sorry! XMLHttpRequest object could not be created.");
	return '';
}

// get an object of XMLHttpRequest.
var objxmlhttprequest = GetXMLHttpRequest();

/**
 * @uses:	The function getParameters() is used to get parameters for a particular form.
 * @param:	string form id
 * @return:	string query string
 */
function getParameters(frm) {
	var frmobj;
	var param = '';
	
	frmobj	=	eval("document.getElementById('"+frm+"')");
	
	if(frmobj.elements.length > 0) {
		for(var i=0; i < frmobj.elements.length; i++) {
			param += frmobj.elements[i].name+'='+frmobj.elements[i].value;
			if(i != (frmobj.elements.length-1)) {
				param += '&';
			}
		} // End of for.
	}
	else
		alert("no form elements");
	//alert(param);
	return param;
} // End of function.