function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}
	
function search(q) {
	if (q && q.length > 2) {

		if (document.getElementById('q').value) {
		
			var xmlhttp = getXmlHttp()
			xmlhttp.open('GET', '/xmlgets/xml_search_product.php?q='+q, true);
			xmlhttp.onreadystatechange = function() {
			  if (xmlhttp.readyState == 4) {
			     if(xmlhttp.status == 200) {
			       
				   search_show(xmlhttp.responseText);
				   
			         }
			  }
			};
			xmlhttp.send(null);

		}
	}
		
}

function search_show (serverResponse) {

document.getElementById("as_res").style.display="block";
				if (!document.getElementById("as_res").style.top) {
					document.getElementById("as_res").style.top = document.getElementById("as_res").offsetTop + 0 + "px";
				}
			
			
			document.getElementById("as_res_inner").innerHTML = serverResponse;
					
			if (!serverResponse) { 
				document.getElementById("as_res").style.display = "none";
			}
}



function ins(text) {
	document.forms['search_form'].query.value = stripHTML(text);
	document.getElementById("as_res").style.display = "none";
	document.forms['search_form'].submit();
}


function topdownloads () {

			var xmlhttp = getXmlHttp()
			xmlhttp.open('GET', '/xmlgets/xml_topdownloads.php', true);
			xmlhttp.onreadystatechange = function() {
			  if (xmlhttp.readyState == 4) {
			     if(xmlhttp.status == 200) {
			       
				   document.getElementById("topdownloadsdiv").innerHTML = xmlhttp.responseText;
				   
			         }
			  }
			};
			xmlhttp.send(null);
	
}


function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}



