function showorder(str1, str2, script) {
 	xmlHttp=GetXmlHttpObject();
 	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request");
 		return;
  } 
	
	// Convert to uppercase for Canada postal codes.
	str2 = str2.toUpperCase();
	
  // If any fields are blank, does not continue.
  if (!(validate_required(str1, str2))) {
 		return;
	}

	script=script+"?id="+str1+"&zip="+str2;
	script=script+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function() {stateChanged("txtHint", xmlHttp);}
	xmlHttp.open("GET",script,true);
	xmlHttp.send(null);
}

function validate_required(id,zip) {
 	// Validate all aspects of field1 (Order ID / RI #)
 	// Verify the field is not blank
	if (id==null || id=="") {
		document.getElementById("txtHint").innerHTML = "<b>An order ID must be entered!</b>";
		return false;
  }

	// Verify the field is the correct length
	if (id.length < 7) {
		document.getElementById("txtHint").innerHTML = "<b>Order ID / RI number must be 7 digits long.</b>"
		return false;
	}

	// Verify the field contains only numbers
	if (!isNum(id)) {
		document.getElementById("txtHint").innerHTML = "<b>Order ID / RI number must contain only numbers.</b>"
		return false;
	}			 

	// Validate all aspects of field2 (Zip code)
	// Verify the field is not blank
	if (zip==null || zip=="") {
		document.getElementById("txtHint").innerHTML = "<b>A zip code must be entered!</b>";
		return false;
	}

	// Determine if zip code is U.S. or Canada	
	if( isNum(zip) ) {
		// U.S. Zip code validation			
		// Verify the field is the correct length
		if (zip.length != 5) {
			document.getElementById("txtHint").innerHTML = 	
			"<b>Invalid postal or zip code length.</b><br />U.S. zip codes must contain 5 digits only (do not include zip + 4)<br />Canadian postal codes must be formatted 'A1A1A1' (no spaces)"
			return false;
		}
	}
	else {
		// Canada postal code validation
		// Verify the field is the correct length		
		if (zip.length != 6) {
			document.getElementById("txtHint").innerHTML =
			"<b>Invalid postal or zip code length.</b><br />U.S. zip codes must contain 5 digits only (do not include zip + 4)<br />Canadian postal codes must be formatted 'A1A1A1' (no spaces)"
			return false;
		}

		// Verify it is a correctly formatted Canadian postal code i.e. A2A2B3
		if (zip.charAt(0).match(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/) == null
			 || zip.charAt(2).match(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/) == null
			 || zip.charAt(4).match(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/) == null) {
			 		document.getElementById("txtHint").innerHTML = 
					"<b>Invalid postal or zip code length.</b><br />U.S. zip codes must contain 5 digits only (do not include zip + 4)<br />Canadian postal codes must be formatted 'A1A1A1' (no spaces)"			 		
					return false;
		}
		else {
			var vNums = zip.charAt(1) + zip.charAt(3) + zip.charAt(5);
			if (vNums.match(/[0-9][0-9][0-9]/) == null) {
				document.getElementById("txtHint").innerHTML = 
				"<b>Invalid postal or zip code length.</b><br />U.S. zip codes must contain 5 digits only (do not include zip + 4)<br />Canadian postal codes must be formatted 'A1A1A1' (no spaces)"
				return false;
			}
		}
	}	
	return true;			
}

// Simple function returns true if num is a numeric character, false if not
function isNum( num ) {
	var valid = "0123456789";
	for (var i=0; i < num.length; i++) {
		temp = "" + num.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			return false;
		}
	}
	return true;
}

function submitEnter(e,script) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if (keycode == 13) {
    showorder(document.getElementById('orderid').value, document.getElementById('zipcode').value, script)
    return false;
    }
  else
    return true;
}
