if(window.XMLHttpRequest){
	var xmlHttpReq = new XMLHttpRequest();
} else {
	if(window.ActiveXObject){
		var xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
}



function buildpc_ajax_call(data, imgl, divl, formdata){

	var queryStr = 'id=' + escape(data); // this is a URL variable to the php //
	var strURL = 'javascript/ajax_buildpc.php?' + queryStr;
	
	xmlHttpReq.open('GET', strURL, true);
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
	xmlHttpReq.send(null);
	
	xmlHttpReq.onreadystatechange =
	
		function(){

			document.getElementById(imgl).style.display = "none";
			//document.getElementById(divl).innerHTML = "";// dont reset the div show the last product //

			if(xmlHttpReq.readyState == 4){
			
				var response = xmlHttpReq.responseText;
				
				if(response != ""){
				
					document.getElementById(divl).innerHTML = response;
					
					// once there is a response, do the below //
					buildpc_total(formdata, 'price_div', 'buildpc_order_img'); // run buildpc_total ajax script //
					document.getElementById(imgl).style.display = "none"; // remove the loader... doesnt seem to be working so added this line in //
					
				}				
			
			} else {
				document.getElementById(imgl).style.display = "block";
			}
		  
		}

}



function buildpc_total(data, price_div, imgl){

	var ids = '';
	
	for(i=0; i<data.length-1; i++){ // -1 becuase we dont want "submit" value //		
		ids = ids + '-' + data[i].value;		
	}
	
	
	var queryStr = 'ids=' + escape(ids); // this is a URL variable to the php //
	var strURL = 'javascript/ajax_buildpc_price.php?' + queryStr;
	
	xmlHttpReq.open('GET', strURL, true);
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
	xmlHttpReq.send(null);
	
	xmlHttpReq.onreadystatechange =
	
		function(){
		
			document.getElementById(imgl).style.display = "none";

			if(xmlHttpReq.readyState == 4){
			
				var response = xmlHttpReq.responseText;
				document.getElementById(price_div).innerHTML = response;
			
			} else {
				document.getElementById(imgl).style.display = "block";
			}
		  
		}

}
