var toDisplay;
var len;
var len2;
var lenR;
var wildcard;
var lenSrch;
var strSrch;
var strSearch;
var strShip;
var strDate;
var strPort;
var xmlhttp=null;
var htmlResults="";
function refDtaLoad(){
	if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(e){
			try{
				xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e){
				xmlhttp=false;
				alert('Your internet browser is unsuitable for using this database. Suitable browsers include recent versions of Microsoft Internet Explorer, Mozilla Firefox	, Netscape and Safari.');
				if(window.history.length)window.history.back();
				return;
			}
		}
	}
	else if(window.XMLHttpRequest){
		try{
			xmlhttp=new XMLHttpRequest();
			xmlhttp.overrideMimeType('text/xml');
		}
		catch(e){
			xmlhttp=false;
			alert('Your internet browser is unsuitable for using this database. Suitable browsers include recent versions of Microsoft Internet Explorer, Mozilla Firefox	, Netscape and Safari. JavaScript must be enabled.');
			if(window.history.length)window.history.back();
			return;
		}
	}
	else{
		alert('Your internet browser is unsuitable for using this database. Suitable browsers include recent versions of Microsoft Internet Explorer, Mozilla Firefox	, Netscape and Safari.');
		if(window.history.length)window.history.back();
		return;
	}
	if(xmlhttp){
		xmlhttp.open('GET', 'shippingref.xml', true);
		xmlhttp.send(null);
		document.getElementById('strQuery').value="";
		document.getElementById('btnGo').disabled=false;
	}
	else{
		alert('Your internet browser is unsuitable for using this database. Suitable browsers include recent versions of Microsoft Internet Explorer, Mozilla Firefox	, Netscape and Safari.');
		if(window.history.length)window.history.back();
		return;
	}
}
function findQuery(){
	document.getElementById('btnGo').disabled='disabled';
	lenSrch=document.getElementById('strQuery').value.length;
	if(lenSrch>24)lenSrch=24;
	strSrch=document.getElementById('strQuery').value.toLowerCase();
	len=0;
	lenCont0=0;
	lenCont1=0;
	strName="";
	strSearch="";
	strSearchCont0="";
	strSearchCont1="";
	wildcard=0;
	for(var i=0; i<lenSrch; i++){
		if((strSrch.charAt(i) >= 'a' && strSrch.charAt(i) <= 'z') || strSrch.charAt(i) == "'" || strSrch.charAt(i) == "-" || strSrch.charAt(i) == " " || strSrch.charAt(i) == "*" || (strSrch.charAt(i) >= '0' && strSrch.charAt(i) <= '9') || strSrch.charAt(i) == "/" || strSrch.charAt(i) == "("){
			strSearch += strSrch.charAt(i);
			len++;
		}
	}
	for(var i=0; i<len; i++){
		switch(wildcard){
			case 0:
				if(strSearch.charAt(i) == "*")break;
				strSearchCont0 += strSearch.charAt(i);
				lenCont0++;
				break;
			case 1:
				if(strSearch.charAt(i) == "*")break;
				strSearchCont1 += strSearch.charAt(i);
				lenCont1++;
				break;
			default:
				if(strSearch.charAt(i) == "*")break;
				strSearchCont1 += strSearch.charAt(i);
				lenCont1++;
				break;
		}
		if(strSearch.charAt(i) == "*")wildcard++;
	}
	len=lenCont0 + lenCont1;
	lenR=len + 1;
	if(len < 3){
		document.getElementById('strResult').innerHTML="<table border='0' cellspacing='0' style='position:relative; margin-top:0.8em;'><tr><th class='error'>Data Entry Error</th></tr><tr><td class='error'>Fill in the box with at least 3 characters of the name or reference to be found.";
		document.getElementById('strQuery').focus();
		document.getElementById('btnGo').disabled=false;
		return;
	}
	else{
		xmlhttp.onreadystatechange=checkReadyState;
		if(xmlhttp.readyState == 4 && xmlhttp.status == '200')runSearch();
	}
}
function checkReadyState(){
	if(xmlhttp.readyState == 4 && xmlhttp.status == '200')runSearch();
	else if(xmlhttp.readyState == 4 && xmlhttp.status != '200'){
		alert('An error occurred while loading the index');
		if(window.history.length) window.history.back();
		return;
	}
}
function runSearch(){
	var limit=100;
	var strArray=new Array();
	var shpDoc=xmlhttp.responseXML;
	var vList=shpDoc.getElementsByTagName('v');
	var m;
	var count=0;
	var i=0;
	while(i<vList.length){
		strName=vList[i].firstChild.nodeValue.toLowerCase();
		if((m=strName.indexOf(strSearchCont0) >= 0) && strName.indexOf(strSearchCont1, m+lenCont0-1) >= 0){
			strArray [count]=vList[i].firstChild.nodeValue + "<br/> ";
			count++;
		}
		i++;
	}
	if(count){
		if(count > limit)toDisplay=limit;
		else toDisplay=count;
		document.getElementById('strResult').innerHTML='<h5 class="results" style="position:relative; margin-top:0.8em;">Search results <span style="font-size:13px; font-weight:normal;">(total of ' + toDisplay + ')</span></h5>';
		for (var i=0; i<toDisplay; i++) document.getElementById('strResult').innerHTML += strArray [i];
		document.getElementById('htmlProgress').innerHTML='View the results below...';
	}
	else{
		document.getElementById('strResult').innerHTML="<h5 class='results' style='position:relative; margin-top:0.8em;'>Search results <span style='font-size:13px; font-weight:normal;'>(total of 0)</span></h5>The data you entered, <b><i>" + document.getElementById('strQuery').value + "</i></b>, is not in this database.";
		document.getElementById('htmlProgress').innerHTML='There are no results to view.';
	}
	if(!document.getElementById('strQuery').disabled)document.getElementById('strQuery').focus();
	document.getElementById('btnGo').disabled=false;
}
function clearForm(){
	document.getElementById('htmlProgress').innerHTML="";
	document.getElementById('strResult').innerHTML="";
}// Copyright (c) 2003-2008 B Leadbeater, Australia. All rights reserved