var xmlHttp

function showResult(str, key)
{
if ((key==13)&&(document.all.toplink.value!=""))
{
    top.location='http://www.dcperformance.co.uk'+document.all.toplink.value;
}

if (str.length==0)
 {
 document.getElementById("livesearch").
 innerHTML="";
 document.getElementById("livesearch").style.borderTop="0px";
 return
 }

xmlHttp=GetXmlHttpObject2()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

var url="/scripts/livesearch.php"
url=url+"?q="+str.replace(/&/,"%26")
url=url+"&sid="+Math.random()
url=url+"&key="+key
xmlHttp.onreadystatechange=stateChanged2
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("livesearch").
 innerHTML=xmlHttp.responseText;
 document.getElementById("livesearch").style.borderTop="1px solid #A5ACB2";
 } 
}

function GetXmlHttpObject2()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

matchHeight=function(){

     var divs,contDivs,maxHeight,divHeight,d;
     // get all <div> elements in the document
     divs=document.getElementsByTagName('div');
     contDivs=[];

     var maindivs=new Array();
     maindivs[0]="nh_mm";
     maindivs[1]="rightnav";
     maindivs[2]="leftnav";
     maindivs[3]="t3";
     maindivs[4]="middlepad";

     maxHeight=0;

     for(var i=0;i<4;i++){
                if (typeof maindivs[i] != "undefined"){
                    d=document.getElementById(maindivs[i]);
                    if(d.offsetHeight){
                         divHeight=d.offsetHeight;
                    }
                    else if(d.style.pixelHeight){
                         divHeight=d.style.pixelHeight;
                    }
                    maxHeight=Math.max(maxHeight,divHeight);
                    if (i==0)mainheight=divHeight;
                    if (i==1)rightheight=divHeight;
                    if (i==2)leftheight=divHeight;
                    if (i==3)t3height=divHeight;
                } else {
                    divHeight=0;
                }

                alert(maindivs[i]+" height="+divHeight);
     }
//     if (mainheight<maxHeight){
        for(var i=1;i<5;i++){
                    if (i!=3){
                        if (i==4){
                            if (t3height==leftheight){
                                alert ("t3="+maxHeight+" "+mainheight);
                                newHeight=maxHeight - mainheight;
                            } else {
                                if ((mainheight>(Math.max(rightheight,leftheight))) && (typeof maindivs[3] != "undefined")){
                                    newheight=mainheight/3;
                                } else {
                                    newheight=mainheight;
                                }
                            }
                        } else {
                            newHeight=maxHeight;
                        }
                        alert(maindivs[i]+" new height="+newHeight);
                        document.getElementById(maindivs[i]).style.height=newHeight;
                    }

         }
//     }

}

window.onload=function(){
     if(document.getElementsByTagName){
          matchHeight();
     }
}


