
ajaxRequest = function(u,f,m,b,h,s)
{
    this.url      = u;
    this.wState   = f || function() { };
    this.method   = m || "GET";
    this.body     = b || null;
    this.headers  = h || false;
    this.sync     = s || true;
    this.abortReq = false;
    
    this.req = (window.XMLHttpRequest) 
           ?
           new XMLHttpRequest()
           :
           ((window.ActiveXObject)
           ?
           new ActiveXObject("Microsoft.XMLHTTP")
           :
           false
           );
    
    this.doRequest = function()
    {
        this.req.open(this.method,this.url,this.sync);
        if (this.headers)
        {
            for (var i=0; i<this.headers.length; i+=2)
            {
                this.req.setRequestHeader(
                    this.headers[i],this.headers[i+1]
                );
            }
        }
        this.req.onreadystatechange = this.wState;
        (!this.abortReq) ? this.req.send(this.body) : this.req.abort();
    }
}

var getAutoComplete = function(theSourceSelectFieldId, theAutocompleteTextFieldId, theAction, thePostValue2)
{	
    var t = document.getElementById(theAutocompleteTextFieldId);
    var s = document.getElementById(theSourceSelectFieldId);
    var query = "action=" + theAction;
    query = query + "&value=" + s.options[s.selectedIndex].value;
    if (thePostValue2 != "") query = query + "&value2=" + thePostValue2;
    
    var tBackgroundColor = getStyle(theAutocompleteTextFieldId, 'backgroundColor', 'background-color');
    t.style.backgroundColor = '#CCCCCC';
    
    var xmlhttp = new ajaxRequest(
        "../others/ajax_get_json_array.htm?extwin=1",
        function()
        {
            var r = xmlhttp.req;
            if (r.readyState == 4)
            {
                var resultArrayString = (r.status == 200) ? r.responseText : "ERROR";
                var resultArray = JSON.parse(resultArrayString);
				
				for(var i = 0; i < resultArray.length; i++)
				{
					if(String(typeof(resultArray[i])).toLowerCase() == "string")
					{
						acObj.actb_keywords[i] = acObj.actb_keywords_init[i] = resultArray[i];
						acObj.actb_values[i]   = acObj.actb_values_init[i]   = "";
					}
					else
					{
						acObj.actb_keywords[i] = acObj.actb_keywords_init[i] = resultArray[i][0];
						acObj.actb_values[i]   = acObj.actb_values_init[i]   = resultArray[i][1];
					}
				}
				
				t.style.backgroundColor = tBackgroundColor;
            }
        },
        "POST",
        query,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}
