function displayMatches(keyword,type_index)
{
	doAjax("includes/getKeywordList.php","type_index="+type_index+"&keyword="+keyword,"msg","POST","Getting Keyword List...",0,"renderKeywordList");
}
function selectKeyword(obj,value)
{
	document.getElementById(obj).value=value;
	hide("keywordListBox");
}

function doAjax(strURL,strPostData,strObj,method,strProgressMessage,nTime,fn) {
    var xmlHttpReq = false;
    var self = this;
	var msg="";	
    // Mozilla/Safari
	
	www=(window.location.href.toLowerCase().indexOf("//www.")>0)?"http://www.":"http://";
	strURL=strURL.replace("http://",www);
	if (fn!="renderKeywordList")
	updateMessage(strObj,strProgressMessage);
	

    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open(method, strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
		
        if (self.xmlHttpReq.readyState == 4) 
		{
			
			msg=(strObj+"|"+self.xmlHttpReq.responseText).split("|");
			if (fn!="renderKeywordList")
			{
				for (i=0;i<msg.length;i=i+2)
				{
					updateMessage(msg[i],msg[i+1]);
				}
			}
	
	
			switch(fn)
			{
				case "renderKeywordList":	
					updateMessage("keywordListBox",self.xmlHttpReq.responseText);	
					break;
				case "renderProductOptions":
					removeItemRow();
					updateMessage(strObj,"Inventory updated successfully!");					
					renderProductOptions(self.xmlHttpReq.responseText);
					
					break;
				case null:
					break;
			}
			
			if (nTime>0) setTimeout("hide('"+strObj+"');",nTime);
        }
		else
		{
			//alert(self.xmlHttpReq.readyState);
		}
    }
    self.xmlHttpReq.send(strPostData);
}

function removeItemRow()
{
  var tbl = document.getElementById('tblGroups');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  for (i=3;i<iteration;i++)
  {
  	tbl.deleteRow(tbl.rows.length-1);
	
  }

}


function updateMessage(obj,str)
{
	show(obj);	
	document.getElementById(obj).innerHTML=str;
}

function showHide(id)
{
	if (document.getElementById(id).style.display=='')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='';
		
}
function show(id)
{
		document.getElementById(id).style.display='';
		
}
function hide(id)
{
		document.getElementById(id).style.display='none';
}