function xmlhttpPost(strURL,resultID,textArr) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            make(resultID,self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(serialize(textArr));
}

function serialize(textArr) {
	var qstr = "";
	for(value in textArr) {
      qstr = qstr + value + '=' + encodeURIComponent(textArr[value]) + "&";
    }
    return qstr;
}

function make(objID,content) {
	document.getElementById(objID).innerHTML = content;
}

function cForm() {
	make('mainlist','<img class="ajax-loader" src="/media/images/ajax-loader_2.gif" />');
    var postArr = new Array();
    postArr['saq'] = document.getElementById('saq').value;
	postArr['st']  = document.getElementById('st').value;
    xmlhttpPost('/request/','mainlist',postArr);
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function sel() {
	document.getElementById('saq').select();
}

window.onload = function() {
    q = document.getElementById('saq');
	m = document.getElementById('mainlist');
	ml = m.getElementsByTagName('li');
    if (q.addEventListener) { // EOMB
		q.addEventListener('keyup',cForm,false);
		q.addEventListener('focus',sel,false);
	}
	else { // IE
		q.attachEvent('onkeyup',cForm);
		q.attachEvent('onfocus',sel);
	}
	/*
	for(var i=0; i<ml.length; i++) {
		if(ml[i].addEventListener) {
			ml[i].addEventListener('mouseover',function() { this.style.backgroundColor = '#ddd'; }, false);
			ml[i].addEventListener('mouseout',function() { this.style.backgroundColor = 'transparent'; }, false);
		}
		else {
			ml[i].attachEvent('onmouseover', function() { this.style.backgroundColor = '#ddd'; } );
			ml[i].attachEvent('onmouseout', function() { this.style.backgroundColor = 'transparent'; } );
		}
	}
	*/
	f = document.getElementById('searchform');
	f.action = "";
	f.method = "post";
	f.setAttribute('autocomplete','off');
	
	hides = getElementsByClassName(document,'*','jshide');
	for(i=0;i<hides.length;i++) {
	    hides[i].style.display = "none";
	}
	
	im = new Image;
	im.src = "/media/images/ajax-loader.gif";
	
}

