/*
start with queryHTTP() function to understand flow.
*/
/**
 * 
 * This file will produce popup ajax search.
 * @file ajaxSearch.js
 * @author Uday Shiwakoti < uday@uday.com.np>
 * @version 1.0
 * @date 23rd, may 2006
 */
var fldName;
var results;
//var results = new array();
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}



function setOption(optionName,valArray){
	var length = valArray.length;
	var i;
	 document.getElementById(optionName).options.length = length;	
	  for(i=0;i<length;i++){
	  	tmpArray=valArray[i].split(':');
		
	  	 document.getElementById(optionName).options[i].text=tmpArray[1];
		 document.getElementById(optionName).options[i].value=	tmpArray[0];
	  }	

}

	

	function setSelect() {
	  if (http.readyState == 4) {
		// Split the comma delimited response into an array
		results =unescape(http.responseText);

			valSelect=results.split("|");

			setOption(fldName,valSelect);
			
	  }  
  	}



/***************************************************************************/

function queryHTTP(url,whichFunction,fieldName) {
/*
http is an object of getHTTPObject which is created just below
*/

 	if (queryHTTP.arguments.length == 3){
 			fldName=fieldName;
	 }
  http.open("GET", url , true);

		if(whichFunction=='setSelect')
			http.onreadystatechange = setSelect; 
		
			 


  http.send(null);
}

var http = getHTTPObject(); // We create the HTTP Objectect HTTP Object

