function showNewResults(classification)
{
  document.forms[0].elements[1].value=classification;
  document.forms[0].elements[0].value=false;
  document.forms[0].submit();
  return false;
}
function showResults()
{
  document.forms[0].elements[0].value=true;
  document.forms[0].submit();
//  return false;
}
function showAlphaResults(regexp,classification)
{
  document.forms[0].elements[1].value=classification;
  document.forms[0].elements[2].value=regexp;
  document.forms[0].elements[0].value=false;
  document.forms[0].submit();
  return false;
}

function formHandler(form) {
var windowprops = "height=500,width=500,location=no,"
+ "scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes";

var URL = form.site.options[form.site.selectedIndex].value;
popup = window.open(URL,"MenuPopup",windowprops);
}

var opened=false;

function openBasket(){

var windowprops = "height=500,width=500,location=no,titlebar=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes";
basket = open("","company_basket",windowprops);
basket.document.writeln("<p align=center><font face=verdana size=3><a href='javascript:;' onClick='window.print();return false'> Print This Page <img src=images/print.gif border=0></a></font></p>");
opened = true;

}

function addCompany(company,address,town,county,ukpostcode,country,contactsls,url,phone,fax,email){
//open the basket window

if(!opened || basket.closed){
  openBasket();
}

basket.document.writeln("<table width=435 border=0 cellspacing=0 cellpadding=0>");
if(company != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Name :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+company+"</font></td></tr>");
}
if(address != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Address :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+address+"</font></td></tr>");
}
if(town != ''){
  basket.document.writeln("<tr><td width=100></td>"
	              +"<td width=335><font face=verdana size=2>"+town+"</font></td></tr>");
}
if(county != ''){
  basket.document.writeln("<tr><td width=100></td>"
	              +"<td width=335><font face=verdana size=2>"+county+"</font></td></tr>");
}
if(ukpostcode != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Postcode :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+ukpostcode+"</font></td></tr>");
}
if(country != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Country :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+country+"</font></td></tr>");
}
if(contactsls != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Contact :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+contactsls+"</font></td></tr>");
}
if(url != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Website :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+url+"</font></td></tr>");
}
if(phone != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>Tel :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+phone+"</font></td></tr>");
}
if(fax != ''){
  basket.document.writeln("<Tr><td width=100><font face=verdana size=2>Fax :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+fax+"</font></td></tr>");
}
if(email != ''){
  basket.document.writeln("<tr><td width=100><font face=verdana size=2>E-mail :</font></td>"
	              +"<td width=335><font face=verdana size=2>"+email+"</font></td></tr>");
}
 
basket.document.writeln("</table>");
basket.document.writeln("<hr>");

basket.focus(); 
return false;
}
var selectedCounty = '';
function setFocus(control)
{
  control.focus();
}
function showCounties(country,selected) {
selectedCounty = selected;
//form name is search
//Only do for E,S,W, N.I N I
if(country != 'England' &&
   country != 'Wales' &&
   country != 'Scotland' &&
   country != 'N.Ireland' &&
   country != 'N Ireland' &&
   country != 'United Kingdom'){
  document.search.counties.options.length = 0;
  document.search.counties.options[0] = new Option('------------','all');
  document.getElementById('countiesDiv').style.visibility = 'hidden';
  return false;
}
if(country == 'all')
{
  return false;
}
document.getElementById('countiesDiv').style.visibility = 'visible';
if (typeof window.ActiveXObject != 'undefined' ) {
  xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
  xmlDoc.onreadystatechange = processCounties;
}
else {
  xmlDoc = new XMLHttpRequest();
  xmlDoc.onload = processCounties;
}
xmlDoc.open( "GET", "getcounties.php?country="+country, true );
xmlDoc.send( null );
}

function processCounties() {
  if (xmlDoc.readyState == 4) {
	// only if "OK";
    if (xmlDoc.status == 200) {
  	delX= ":::";
	valArray = xmlDoc.responseText.split(delX);
	document.search.counties.options.length = 0;
        document.search.counties.options[0] = new Option('All counties','all');			
        count = 1;
        selectNo = 0;
	for (var i=0; i < valArray.length-1; i++ ) {
          if(isValidCounty(valArray[i])){
            if(selectedCounty == valArray[i]){
              document.search.counties.options[count] = new Option(valArray[i], valArray[i],true);
              selectNo = count;
            } else {
              document.search.counties.options[count] = new Option(valArray[i], valArray[i]);
            }
            count++;
          }
	} 
        document.forms[0].counties.options[selectNo].selected = true;
    } else {
	alert("There was a problem retrieving the data:\n" + xmlDoc.statusText);
    }
  }
}
counties = new Array();
counties.push("Co. Antrim");
counties.push("Co. Armagh");
counties.push("Avon");
counties.push("Bedfordshire");
counties.push("Berkshire");
counties.push("Borders");
counties.push("Bucks.");
counties.push("Cambridgeshire");
counties.push("Channel Islands");
counties.push("Cheshire");
counties.push("Cleveland");
counties.push("Clwyd");
counties.push("Cornwall");
counties.push("Cumbria");
counties.push("Derbyshire");
counties.push("Devon");
counties.push("Dorset");
counties.push("Co. Down");
counties.push("Dumfries and Galloway");
counties.push("Dunbartonshire");
counties.push("Co. Durham");
counties.push("Dyfed");
counties.push("Edinburgh");
counties.push("Essex");
counties.push("Co. Fermanagh");
counties.push("Fife");
counties.push("Glamorgan");
counties.push("Gloucestershire");
counties.push("Grampian");
counties.push("Gwent");
counties.push("Gwynedd");
counties.push("Hants.");
counties.push("Herefordshire");
counties.push("Herts.");
counties.push("Highland");
counties.push("I.O.M");
counties.push("I.O.W");
counties.push("Kent");
counties.push("Lancs.");
counties.push("Leicestershire");
counties.push("Lincs.");
counties.push("London");
counties.push("Co. Londonderry ");
counties.push("Lothian");
counties.push("Manchester");
counties.push("Merseyside");
counties.push("Middx.");
counties.push("Norfolk");
counties.push("Northants.");
counties.push("Northumberland");
counties.push("Notts.");
counties.push("Orkney");
counties.push("Oxfordshire");
counties.push("Pembrokeshire");
counties.push("Powys");
counties.push("Renfrew");
counties.push("Shropshire");
counties.push("Sark");
counties.push("Shetland");
counties.push("Somerset");
counties.push("Staffs.");
counties.push("Strathclyde");
counties.push("Suffolk");
counties.push("Surrey");
counties.push("E. Sussex");
counties.push("W. Sussex");
counties.push("Tayside");
counties.push("Tyne & Wear");
counties.push("Co. Tyrone");
counties.push("Warwickshire");
counties.push("Western Isles");
counties.push("W. Midlands");
counties.push("Wilts.");
counties.push("Worcs.");
counties.push("Teesside");
counties.push("Yorkshire");

function isValidCounty(testCounty) 
{
    for(i = 0; i < counties.length; i++)
    {
        if(testCounty == counties[i])
        {
             return true;
        }
    }
    return false;
}
