// Roshan's Ajax dropdown code with php
// This notice must stay intact for legal use
// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
// If you have any problem contact me at http://roshanbh.com.np
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

			}
			catch(e1){
				xmlhttp=false;
				alert("There was a problem");
				
			}
		}
	}
		
	return xmlhttp;
}

function initForm(numRows) {

	for (i=1;i<=numRows;i++) {
		
		getManufacturer(i);
		getPurpose(i);
	}

	for (i=9;i<=13;i++) {

			getModel(i,4);
			getPurpose(i);

	}
}

function getManufacturer(instance) {		
	
	var strURL="cosbatch_calculate_request.php?task=manufacturer&instance="+instance;
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.abort();
		req.open("GET", strURL, true);
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {
					document.getElementById('manufacturerdiv'+instance).innerHTML= req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		
		req.send(null);
	}		
}


function getModel(instance,manufacturerId) {		
	
	var strURL="cosbatch_calculate_request.php?task=model&instance="+instance+"&manufacturer="+manufacturerId;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('modeldiv'+instance).innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}
function getCpu(instance,manufacturerId,modelId) {		
	var strURL="cosbatch_calculate_request.php?task=cpu&instance="+instance+"&manufacturer="+manufacturerId+"&model="+modelId;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('cpudiv'+instance).innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
			
}
function getCore(instance,manufacturerId,modelId,cpuId) {		
	var strURL="cosbatch_calculate_request.php?task=core&instance="+instance+"&manufacturer="+manufacturerId+"&model="+modelId+"&cpu="+cpuId;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('corediv'+instance).innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
			
}

function getPurpose(instance) {		
	var strURL="cosbatch_calculate_request.php?task=purpose&instance="+instance;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('purposediv'+instance).innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
			
	}