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 showUser(str)

{
xmlHttp=GetXmlHttpObject2()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/scripts/getmodel.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("modelbox").innerHTML=xmlHttp.responseText
 }
}

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(){

// ############ first sort out the layout ############

     dynamicLayout()

// ############ then check for the mootools stuff

     if (document.getElementById("t1") != null){

          if (document.getElementById("t3") != null){

//################### this starts the mootools scripts if the t1 div is present ########################

  //          window.addEvent('domready', function() {   ############ this was taken out to allow fix the issue with the shrink script to work when loading and refreshing the page.
            var accordion = new Accordion('div.t1', 'div.t2', {
            //start:'all-closed',
            display:document.getElementById('box1').value,
            opacity: false,
            duration: 100,
            alwaysHide: true,
            onActive: function(togglers, stretchers){


            togglers.setStyle('background-image', 'url(/images/background/catbaron.png)');
            },
            onBackground: function(togglers, stretchers){
            togglers.setStyle('background-image', 'url(/images/background/catbar.png)');
            //togglers.setStyle('background-color', '#FFFFFF');
            stretchers.setStyle('height', stretchers.offsetHeight);
            $$('div.t3').setStyle('height','0'); //This closes all sub-accordions.
            }
            }, $('sidebar'));
            var accordion1 = new Accordion('div.t3o', 'div.t3', {
            //start:'all-closed',
            display:document.getElementById('box2').value,
            opacity: false,
            duration: 100,
            alwaysHide: true,
            onActive: function(togglers, stretchers){
            togglers.setStyle('background-image', 'url(/images/background/subcatbaron.png)');
            togglers.getParent().setStyle("height", "auto");
            },
            onBackground: function(togglers, stretchers){
            togglers.setStyle('background-image', 'url(/images/background/subcatbar.png)');
            stretchers.setStyle('height',stretchers.offsetHeight);
            }
            }, $('sidebar'));
  //          });
        } else {

            var accordion = new Accordion('div.t1', 'div.t2', {
            start:'all-closed',
            opacity: false,
            duration: 100,
            alwaysHide: true,
            onActive: function(togglers, stretchers){
            togglers.className='catbaron';
            },
            onBackground: function(togglers, stretchers){
            togglers.className='t1';
            }
            }, $('sidebar'));

        }

     }

// ############ then sort out the heights of the three panes ############

     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]="middlepad";

     maxHeight=0;

     for(var i=0;i<3;i++){
                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;
//                alert(maindivs[i]+" "+divHeight);
     }
//     alert(maxHeight);

     if (mainheight<maxHeight){
        for(var i=1;i<4;i++){
            if (i==3){
                newHeight=maxHeight - mainheight;
            } else {
                newHeight=maxHeight;
            }
//            alert (maindivs[i]+" = "+newHeight);
            document.getElementById(maindivs[i]).style.height=newHeight;
        }
     }
}

	function getBrowserWidth(){
		if (window.innerWidth){
			return window.innerWidth;}
		else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;	}
		else if (document.body){return document.body.clientWidth;}
			return 0;
	}

      function dynamicLayout(){
      	var browserWidth = getBrowserWidth();
      	if (browserWidth < 1050){
            document.getElementById("widecss").disabled=true;
            document.getElementById("widetxt").disabled=true;
      	}
      }

// changeLayout is based on setActiveStyleSheet function by Paul Sowdon
// http://www.alistapart.com/articles/alternate/
    function changeLayout(description){
       var i, a;
       for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
    	   if(a.getAttribute("title") == description){a.disabled = false;}
    	   else if(a.getAttribute("title") != "default"){a.disabled = true;}
       }
    }

window.onload=function(){
     if(document.getElementsByTagName){
          matchHeight();
     }
}


