function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Please upgrade your web browser.");
	}
}


var searchReq = getXmlHttpRequestObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSerial(uname) {
	leng = escape(document.getElementById('serial').value.length);
	//alert(leng);
	//3 or more chars required for lookup
	if(leng > 6) {
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {
			var str = escape(document.getElementById('serial').value);
			//alert(str);
			//alert('ascripts/js/serialcheckp.php?serial=' + str + '&uname=' + uname);
			searchReq.open("GET", 'ascripts/js/serialcheckp.php?serial=' + str + '&uname=' + uname, true);
			searchReq.onreadystatechange = handleSearchSuggest; 
			searchReq.send(null);
		}		
	}else{
	serial_message.style.display = 'none';
	}
}
	
	function handleSearchSuggest() {
	
		
		if (searchReq.readyState == 4) {
		var repstr = searchReq.responseText.split("|");
		
		//alert(repstr);
		
		switch(repstr[0]){
			
			case "1":
		   document.getElementById('serial_form').innerHTML = repstr[3]
		   serial_message.style.display = 'none';
			break;
			
			case "2":
			document.getElementById('serial_message').innerHTML = "<tr><td colspan=\"4\" align=\"center\"><br><b>Trinity is not registered yet</b><br><br><table width=500 border=0 cellspacing=0 cellpadding=0><tr><td align=left> 1. Download <a href=\"CMR/software/General_Software/DS_Downloader/DSDownloader_Installer_2.2.1.4.exe\">DSDownloader_Installer_2.2.1.4.exe</a><br>2. Download <a href=\"beta/Trinity_USB_Driver_Installer_1.1.1.1.exe\">Trinity_USB_Driver_Installer_1.1.1.1.exe</a><br>2. Install them both on your computer<br>3. Connect the trinity to the pc<br>4. Register your trinity in DSDL<br><br>You must do all of this before you can download this crom update.</td></tr></table><br><br></td></tr>";
			serial_message.style.display = '';
			break;
			
			default:
			document.getElementById('serial_message').innerHTML =  "<tr><td colspan=\"4\" align=\"center\"><br><b>The serial number " + repstr[1] + " does not exist. Please call DiabloSport at 561.908.0040 for more information.</b><br><br></td></tr>";
			serial_message.style.display = '';
			break;
			
		}
	}
	
}
