
function makeObject(){
        
        
        var x; 
        var browser = navigator.appName; 
       	
                        if (window.ActiveXObject) { // IE
						
                            try {
                                x = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try {
                                x = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e) {}
                            }
						
                        } else if (window.XMLHttpRequest) { // Mozilla, Safari,...
						
                            x = new XMLHttpRequest();
							
                        }
        
        
        return x; 
} 
         
        var request = makeObject(); 
        
        function makeRequest(pId, sessionId, spec, addProduct, giveAway) 
		{	
			var randNr = Math.floor(Math.random()*1000000);
        	request.open('get', '/Ajax/cartContent.php?uI=' + randNr + '&oI=' + sessionId + '&pId=' + pId + '&addProduct=' + addProduct + '&specProd=' + spec + '&giveAway=' + giveAway);
            request.onreadystatechange = parseInfo; 
            request.send(''); 
        } 
         
        
        function parseInfo()
		{ 
        	if(request.readyState == 4)
			{ 
              var answer = request.responseText;
              document.getElementById('cartContent').innerHTML = answer; 
        	} 
        }
		
function fadeBtnBuy(pId, giveAway){
	if(giveAway == '1'){
	var giveImgId = 'giveAwayImage' + pId;
	document.getElementById(giveImgId).src = '/images/geBort.gif';
	window.location.reload();
	} else {
	var buyImgId = 'buyImage' + pId;
	document.getElementById(buyImgId).src = '/images/btnBuy.gif';
	}
}

function addProduct (pId, sessionId, spec, giveAway) {
makeRequest(pId,sessionId,spec,'1', giveAway);
document.getElementById('cartImage').src = '/images/myCartFull.gif';
document.getElementById('buyImage').src = '/images/addProductAni.gif';

	if(giveAway == '1'){
	document.getElementById('giveAwayImage' + pId).src = '/images/geBortOff.gif';
	} else {
	document.getElementById('buyImage' + pId).src = '/images/btnBuyOn.gif';
	}
	
setTimeout("fadeBtnBuy(" + pId +"," + giveAway +")",2000);

}





  function checkRabatt(url) {
  var http_request = false;

  if (window.XMLHttpRequest) { 
  http_request = new XMLHttpRequest();
  if (http_request.overrideMimeType) {
  http_request.overrideMimeType('text/xml');
  }
  } else if (window.ActiveXObject) { 

  try { 
  http_request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
  try {
  http_request = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e) {}
  }
  }

  if (!http_request) {
  alert('Kunde inte skapa en XMLHTTP instans');
  return false;
  }

  http_request.onreadystatechange = function() { showRabatt(http_request); };
  http_request.open('GET', url, true);
  http_request.send(null);
  }
  
  
  function showRabatt(http_request) { 

  if (http_request.readyState == 4) { 
  if (http_request.status == 200) {
  	if(http_request.responseText != '0'){
  		document.getElementById('rabatt').innerHTML = 'Rabatt: <strong>'+http_request.responseText+':-</strong>';
		document.getElementById('rabattSpec').innerHTML = '<font color="#008000">Koden är korrekt!</font>';
		document.getElementById('totalSumStrong').innerHTML = (parseInt(document.getElementById('totalSumOrg').value)-parseInt(http_request.responseText))+':-';
		document.getElementById('presentkortSend').value = document.getElementById('presentkort').value;
  	}else{
		document.getElementById('rabatt').innerHTML = '';
		document.getElementById('rabattSpec').innerHTML = '<font color="#FF0000">Du har angivit en ogiltig kod!</font>';
		document.getElementById('totalSumStrong').innerHTML = document.getElementById('totalSumOrg').value+':-';
		document.getElementById('presentkortSend').value = '';
	}
  //FUNCTIONER HÄR...
  } else {
  //document.getElementById('rabattSpec').innerHTML = ""; 
  }
  }
  }

