  	// Get the HTTP Object
	function getHTTPObject(){
	   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	   else if (window.XMLHttpRequest) return new XMLHttpRequest();
	   else {
	      alert("Your browser does not support AJAX.");
	      return null;
	   }
	}

function GetXmlHttpObject3(){
    if (window.XMLHttpRequest){
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
    }
    if (window.ActiveXObject){
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

	// Change the value of the outputText field
	function setOutput(){
        if(httpObject.readyState == 4){
            updatecart();
	    }
	}

    function updatecart(){

        var response=" "+httpObject.responseText;
        if (response.indexOf('|')>0){
            var y=response.substr(0,(response.indexOf('|')));
            response=response.substring(response.indexOf('|')+1);
            var partstr=response.substr(0,response.indexOf('|'));
            response=response.substring(response.indexOf('|')+1);
            document.getElementById('cartnotify').innerHTML = "<div id='notifybox' style='background-image:url(/images/background/addtocart.png); width: 311px; height:111px; filter:alpha(opacity=0);-moz-opacity:.0;opacity:.0; '><div style='padding:10px; height:75px; width:250px; position:absolute;'><span>The "+partstr+" has been added to your cart</span><div style='text-align:right; position:absolute; bottom:10px;left:0px; width:250px;'><span class='text_gn10'>Don't show this box again <input type='checkbox' id='dontshow' onclick='stopbox()'></span></div></div></div>";
            y=parseInt(48+(y*21));
            document.getElementById('cartnotify').style.top=y+'px';
            document.getElementById('cartnotify').style.right='291px';
            //opacity('notifybox', 0, 100, 500);
            //setTimeout ("opacity('notifybox', 100, 0, 500)", 3000 );
            fadeIn("notifybox",10,0,100);
            setTimeout("fadeOut('notifybox',10,100,0)",3000);
        }

        document.getElementById('cart').innerHTML = response;
        document.getElementById('buynow'+buynowid).innerHTML="";
        top.location='#top'
        clearTimeout(reloadtimer);
    }

    function timedRefresh(timeoutPeriod) {
    	reloadtimer = setTimeout("location.reload(true);",timeoutPeriod);
    }

	function setcartOutput(){
        if(httpObject.readyState == 4){
            var response=httpObject.responseText;
            document.getElementById('cart').innerHTML =response;
            hideshade(50);
	    }
	}

    function showshade(speed){
        var b=document.getElementById('shade');
        b.style.height=getheight()+'px';
        b.style.visibility='visible';
        b.style.width='100%';
        top.location='#top';
        b.innerHTML="<div style='text-align:middle; position:absolute; top:40%; background-color:#FFFFFF; height:50px; width:60px; padding-top:14px; border:solid 3.0px silver;'><img id='image1' src='/images/round-loader2.gif' alt='' /></div>";
        opacity("shade", 0, 80, speed);
    }

    function hideshade(speed){
        opacity("shade", 80, 0, speed)
//        b=document.getElementById('shade');
//        b.style.visibility='hidden';
    }

    function showimagebox(speed){
//        a=document.getElementById('image_box_off');
//        a.style.visibility='visible';
//        opacity("image_box_off", 0, 100, speed);
        fadeIn("image_box_off",4,0,speed);
    }

    function hideimagebox(speed){
//        a=document.getElementById('image_box_off');
//        a.style.visibility='hidden';
        opacity("image_box_off", 100, 0, speed)
    }

    function hideboth(){
        fadeOut("image_box_off",3,100,0);
        fadeOut("shade",3,80,0);

    }

	function addproduct(id, partno, cat, price, man, i, quantity){
	  buynowid=i;
        if (typeof quantity == 'undefined') quantity = '1';
	    httpObject = getHTTPObject();
        if (httpObject==null)
        {
          alert ("Browser does not support HTTP Request");
          return;
        }
        timedRefresh(7000);
	    document.getElementById('buynow'+i).innerHTML="<div style='width:148px; height:32px; BACKGROUND-IMAGE: url(/images/background/pinkblank.png); padding-top:7px; cursor:hand;'><img src='/images/background/loader.gif' alt='' /></a>";
        cat = cat.replace(/&/g, "+");
        man = man.replace(/&/g, "+");
        partno=convertpart_no(partno);

        var url="/cart.php";
        url=url+"?id="+id;
        url=url+"&quantity="+quantity;
        url=url+"&part-number="+partno;
        url=url+"&description="+cat;
        url=url+"&price="+price;
        url=url+"&man="+man;
        httpObject.onreadystatechange=setOutput;
        httpObject.open("GET",url,true);
        httpObject.send(null);

	}

function savestar(rating, part_no)
{
    xmlhttp=GetXmlHttpObject3();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="/ajax.php";
    url=url+"?type=rating&rating="+rating+"&part_no="+part_no;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged3;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged3()
{
if (xmlhttp.readyState==4)
{
document.getElementById("response").innerHTML=xmlhttp.responseText;
}
}

function stateChanged4()
{
if (xmlhttp.readyState==4)
{
responsetxt = xmlhttp.responseText;
maincontent = responsetxt.substring(0, responsetxt.indexOf("|||"));
filtercontent = responsetxt.substring(responsetxt.indexOf("|||")+3)
document.getElementById('contentdiv').innerHTML=maincontent;
document.getElementById('contsidefilter').innerHTML=filtercontent;
document.getElementById('shade').innerHTML="";
fadeOut("shade",10,50,100);
}
}

function convertpart_no(partno){
    partno = partno.replace(/&/g, ":");
    return partno;
}

    function updatequantity(newquantity, id, field){
// id is the part number, and field is the field in which the part number should be found
//        alert (newquantity+" "+id);
	    httpObject = getHTTPObject();
	    if (httpObject != null) {
           showshade(10);
	        if (typeof newquantity == 'undefined' ) quantity = '';
            id=convertpart_no(id)
//            alert(id);
	        httpObject.open("GET", "/cart.php?type=edit&quantity="+newquantity+"&id="+id+"&field="+field, true);
	        httpObject.send();

	        httpObject.onreadystatechange = setcartOutput;
	    }
        setcartOutput;
    }

function getwidth(){
    var scrwide;

         if (typeof window.innerWidth != 'undefined')
         {
              scrwide = window.innerWidth
         }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

         else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
         {
               scrwide = document.documentElement.clientWidth
         }

         // older versions of IE

         else
         {
               scrwide = document.getElementsByTagName('body')[0].clientWidth
         }
    return scrwide

}

function getheight(){
        var scrhigh;

         if (typeof window.innerWidth != 'undefined')
         {
              scrhigh = window.innerHeight
         }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

         else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
         {
               scrhigh = document.documentElement.clientHeight
         }

         // older versions of IE

         else
         {
               scrhigh = document.getElementsByTagName('body')[0].clientHeight
         }
    return scrhigh;
}

	function stopbox(){
	    httpObject = getHTTPObject();
	    if (httpObject != null) {
	        httpObject.open("GET", "/cart.php?stopbox=1", true);
	        httpObject.send(null);
	    }
	}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
//    if (opacEnd==0) document.getElementById(id).innerHTML = "";
}

function sendemail(){
    if (document.getElementById("emailtype").src=='http://www.dcperformance.co.uk/images/background/email_on.png'){
        nameto=document.getElementById("full_name").value;
        emailto=document.getElementById("email_address").value;
        strcomments=document.getElementById("strcomment").value;
        namefrom=document.getElementById("namefrom").value;
        link=document.getElementById("link").value;
        querystr="nameto="+nameto+"&namefrom="+namefrom+"&emailto="+emailto+"&link="+link+"&comments="+strcomments;
    } else if (document.getElementById("emailtype").src=='http://www.dcperformance.co.uk/images/background/question_on.png'){
        name=document.getElementById("full_name").value;
        emailto=document.getElementById("email_address").value;
        phone=document.getElementById("phone_number").value;
        vehicle=document.getElementById("vehicle_details").value;
        part_nostr=document.getElementById("part_no2").value;
        question=document.getElementById("strquestion").value;
        querystr="name="+name+"&email="+emailto+"&phone="+phone+"&vehicle="+vehicle+"&question="+question+"&part_no="+part_nostr;
    } else if (document.getElementById("emailtype").src=="http://www.dcperformance.co.uk/images/background/seenitcheaper_on.png"){
        name=document.getElementById("full_name").value;
        emailto=document.getElementById("email_address").value;
        phone=document.getElementById("phone_number").value;
        link=document.getElementById("strquestion").value;
        part_nostr=document.getElementById("part_no2").value;
        querystr="name="+name+"&email="+emailto+"&phone="+phone+"&theirlink="+link+"&part_no="+part_nostr;
    }
//    alert (querystr);
    httpObject = getHTTPObject();
	    if (httpObject != null) {
	        httpObject.open("GET", "/classes/email.class.php?"+querystr, true);
	        httpObject.send(null);
	        httpObject.onreadystatechange = setemailOutput;
	    }
        setemailOutput;
}

	function setemailOutput(){
        if(httpObject.readyState == 4){
            var response=httpObject.responseText;
            document.getElementById('image_box_off').innerHTML = "<center><div style='width:500px; height:400px; background-color:#FFFFFF;'><br /><br /><br /><img src='/images/tick.png' alt='' /><br /><p class='text_r14b'>"+response+"</p></center></div>";
//            opacity('notifybox', 0, 100, 500);
            setTimeout ("close_image()", 3000 );
        }
    }

    function adddelivery(type){
	    httpObject = getHTTPObject();
	    if (httpObject != null) {
//            showshade(80);
            fadeIn("shade",3,0,80);
            httpObject.open("GET", "/delivery.php?type="+type, true);
	        httpObject.send(null);
	        httpObject.onreadystatechange = setaddressOutput;
	    }
    }

    function ajax_close_image()
{
        ajax_fadeOut("image_box_off",3,100,0);
        ajax_fadeOut("shade",3,80,0);
}

function ajax_fadeOut(eID, speed, start, end) {
    if (ajax_getElm(eID).style.display=="none") return false;
    var timer = 0;
    for (var i=start; i>=end; i--) {
        setTimeout("setOpacity('"+eID+"',"+i+")", timer * speed);
        timer++;
    }
   setTimeout("ajax_hide('"+eID+"')", 310);
}

function ajax_getElm(eID) {
    return document.getElementById(eID);
}
function ajax_show(eID) {
    getElm(eID).style.display='block';
}
function ajax_hide(eID) {
    getElm(eID).style.display='none';
    getElm("whole").style.display='none';
}

	function setaddressOutput(){
        if(httpObject.readyState == 4){
            var response=httpObject.responseText;
            if (response=="COMPLETE"){
                top.location.reload(true);
            } else {
                var scrwide;
                var scrhigh;
                scrwide=getwidth();
                scrhigh=getheight();
                var a=document.getElementById('image_box_off');
                a.style.visibility="VISIBLE";
                wdth=450;
                if (response.indexOf("error")>0){
                    hght=450;
                } else {
                    hght=300;
                }
                a.style.width=wdth+40+'px';
                a.style.height=hght+80+'px';

                var leftval=(scrwide/2)-(wdth/2)-20;
                var topval=(scrhigh/2)-(hght/2)-100;
                if (topval<0)topval=0;
                a.style.top=topval+'px';
                a.style.left=leftval+'px';
                showimagebox(100);

                a.innerHTML="<div style='text-align:left; background-color:#FFFFFF; height:100%; width:100%; border:solid 2.0px silver;'><img src='/images/background/deladdbar.png' alt='' /><div style=' padding-left:20px; padding-right:20px;'>"+response+"</div></div>";
            }
	    }
	}

    function checkaddress(){
        inputs=document.getElementsByTagName('input');
        link="";
        for(var i=0;i<inputs.length;i++){
            if(/\btextbox\b/.test(inputs[i].className)){
                d=inputs[i];
                if (link) link=link+"&";
                link=link+d.name+"="+d.value;
            }
        }
        link="/delivery.php?"+link;
	    if (httpObject != null) {
            httpObject.open("GET", link, true);
	        httpObject.send(null);
	        httpObject.onreadystatechange = setaddressOutput;
	    }
    }

    function getloadingicon(){
        return "<img style='position:absolute; left:48%; top:48%;' src='/images/background/loader.gif' alt='' />";
    }

    function filterproducts(filtertype, filtervalue, cat, vspec){
        document.getElementById("shade").innerhtml=getloadingicon();
        fadeIn("shade",10,0,50);
        filterboxvalue = document.getElementById('filtervalues').value;

        if (document.getElementById(filtervalue).checked){
            if (filterboxvalue!=""){
                filtervalue = filterboxvalue+":"+filtervalue;
            } else {
                filtervalue = filtervalue;
            }
        } else {
            if (filterboxvalue.indexOf(filtervalue)!=-1){
                //alert(filterboxvalue);
                filtervalue = filterboxvalue.replace(filtervalue, "")
            }
        }

        filtervalue=filtervalue.replace("::",":");
        if (filtervalue.indexOf(':',0)==0){
            filtervalue=filtervalue.substring(1);
        }
        if (filtervalue.substring((filtervalue.length-1))==":"){
            filtervalue=filtervalue.substring(0,(filtervalue.length-1));
        }
        document.getElementById('filtervalues').value = filtervalue;

        car_man=document.getElementById("car_mantextbox").value;
        car_model=document.getElementById("car_modeltextbox").value;

//        if ((cat=="") || (car_man=="") || (car_model=="")) return false;
        if (cat=="") return false;
        xmlhttp=GetXmlHttpObject3();
        if (xmlhttp==null)
          {
          alert ("Browser does not support HTTP Request");
          return;
          }

        var url="/products.php";
        if (vspec=="0"){
            url=url+"?filter="+filtervalue+"|&cat="+cat+"&ajaxfilter=1";
        } else {
            url=url+"?filter="+filtervalue+"|&cat="+cat+"&car="+car_man+"&model="+car_model+"&ajaxfilter=1";
        }
        //alert(url);
        url=url+"&sid="+Math.random();
        xmlhttp.onreadystatechange=stateChanged4;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);

    }



	var httpObject = null;
