//Ajax requesting
var http_request = false;

function makeRequest(url) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url, true);
  http_request.send(null);
}

function alertContents() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        //processResults function is unique to page
        processResults(result);          
     } else {
        alert('There was a problem with the request.');
     }
  }
}


//SPECIFIC REQUESTS
var retFunction;

function processResults(result) {
	if(retFunction == 'sendtofriend') {	//product_info.php

		document.cart_quantity.to_name.value = '';
		document.cart_quantity.to_address.value = '';

	}
	
	if(retFunction == 'findapart_categories') {	//findapart.php
		Categories = getVariable(result);
	}
	if(retFunction == 'findapart_parts') {	//findapart.php
		PartTypes = getVariable(result);
	}
	if(retFunction == 'findapart_brands') {	//findapart.php
		Brands = getVariable(result);
	}
	if(retFunction == 'findapart_models') {	//findapart.php
		Models = getVariable(result);
	}
	if(retFunction == 'findapart_getItems') {	//findapart.php
		Items = getItems(result);
	}
	
	if(retFunction == 'pophelp') {	//products.php (includes/pophelp.php)
		document.getElementById('popHelp').innerHTML = result;
		document.getElementById('popHelp').style.visibility='visible';
	}
	
	
	
}