var xmlHttp
var xmlHttp2

function showItem(str) { 

  if (navigator.userAgent.indexOf("Opera")>=0) {
    //alert("This example doesn't work in Opera") 
    return 
  } else {
    var url="/shop_box.php?id=" + str
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
  }
} 

function addItem(item) {
        var url="/add_cart.php?itemid=" + item
        xmlHttp=GetXmlHttpObject (cartChanged)
        xmlHttp.open("GET", url, true)
        xmlHttp.send(null)

        opacity('cartactions', 0, 100, 1500);
        //shiftOpacity('cartactions', 1000);
        setTimeout("opacity('cartactions', 100, 0, 1000)",4000)
        setTimeout("cart_count();",6000)
        cart_count();
}

function cart_count() {
  if (navigator.userAgent.indexOf("Opera")>=0) {
    //alert("This example doesn't work in Opera") 
    return 
  } else {	
    var url="/cart_count.php"
    xmlHttp2=GetXmlHttpObject (cart_countChanged)
    xmlHttp2.open("GET", url, true)
    xmlHttp2.send(null)
  }

}

function cart_countChanged() {
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") {
        	document.getElementById("cartcount").innerHTML=xmlHttp2.responseText
        }
}

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

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

function GetXmlHttpObject(handler) { 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0) {
		//alert("This example doesn't work in Opera") 
		return 
	}

	if (navigator.userAgent.indexOf("MSIE")>=0) { 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		} try { 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e) { 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 

	if (navigator.userAgent.indexOf("Mozilla")>=0) {
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 

// Opcaity stuff

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++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 