function DeactivateCode(codeId)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById(codeId+'_state').innerHTML='Desactivando...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById(codeId+'_state').innerHTML=xmlhttp.responseText;

xmlhttp = false;
}
	}
	xmlhttp.open("GET",deactivateCodeTarget+"?id="+codeId+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function GenerateInvoice(id)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('invoiceResult').innerHTML='Generando...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('invoiceResult').innerHTML=xmlhttp.responseText;
xmlhttp = false;
}
	}
	xmlhttp.open("GET",generateInvoiceTarget+"?order-id="+id+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}


function UpdateOrder(id, name, value)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('orderStatusUpdate').innerHTML='...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('orderStatusUpdate').innerHTML=xmlhttp.responseText;
xmlhttp = false;
}
	}
	xmlhttp.open("GET",orderUpdateTarget+"?id="+id+"&name="+name+"&value="+value+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}


function DecryptCard(encrypted,num)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

	var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		{
		document.getElementById('cardNumber'+num).innerHTML='....';
		}
	
		if(xmlhttp.readyState==4)
		{
			document.getElementById('cardNumber'+num).innerHTML=xmlhttp.responseText;
			xmlhttp = false;
		}
	}
	xmlhttp.open("GET",decryptionTarget+"?encstring="+encrypted+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function AddToBasket(id, amount, extras)
{
	if (!($("#minibasket").is(":visible")))
	$("#minibasket").show();
	if (!($("#topBarBasket").is(":visible")))
	$("#topBarBasket").show();


	var shown = false;
	var timestamp = new Date().getTime();
	if (shown == false)
		shown = $("#shoppingBasket").is(":visible");
		
	$.get(basketTarget+"?id="+id+"&extras="+extras+"&cantidad="+amount+"&anti-cache=" + timestamp, function(data){
		$("#miniCesta").html(data);
		if (shown)
		{
			$("#shoppingBasket").show();
			$(".detallesCesta").text("Ocultar detalles");
			shown == false;
		}
                var itemCount = $("#miniCesta").find("#cesta span.itemCount").text();
                if (itemCount == "0" || itemCount == "")
                  $("#topBarBasket").hide();
                else
                {
		  $("#topBarBasket").text("(" + itemCount + ")").show();	
                }
		
		$(".detallesCesta").click(basketClick);
	
	});
}

function UpdateBasketQuantities(quantities)
{
var shown = false;
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		
		if(xmlhttp.readyState==1)
		{
			//if (shown == false)
			//	shown = $("#shoppingBasket").is(":visible");
			//document.getElementById('miniCesta').innerHTML='Cargando...';
		}
	
		if(xmlhttp.readyState==4)
		{
			document.getElementById('cestaCompleta').innerHTML=xmlhttp.responseText;
			RemoveFromBasketCallback(xmlhttp.responseText);
blink('precioTotal');
			xmlhttp = false;
		}
	}
	xmlhttp.open("GET",basketUpdateTarget+"?update="+quantities+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}


function RemoveFromBasket(id)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		//if(xmlhttp.readyState==1)
		//document.getElementById('miniCesta').innerHTML='Cargando...';
	
		if(xmlhttp.readyState==4)
		{		
			document.getElementById('miniCesta').innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText.indexOf('EMPTY') > -1)
			  $('#shoppingBasket').hide();
			else
			$('#shoppingBasket').show();

			$(".detallesCesta").click(basketClick);
                        $(".detallesCesta").text("Ocultar detalles");

//RemoveFromBasketCallback(xmlhttp.responseText);
xmlhttp = false;
}
	}
	xmlhttp.open("GET",basketRemoveTarget+"?id="+id+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function RemoveFromBasket1(id)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		//if(xmlhttp.readyState==1)
		//document.getElementById('cestaCompleta').innerHTML='Cargando...';
	
		if(xmlhttp.readyState==4)
		{		
			document.getElementById('cestaCompleta').innerHTML=xmlhttp.responseText;
			RemoveFromBasketCallback(xmlhttp.responseText);
			xmlhttp = false;
}
	}
	xmlhttp.open("GET",basketRemoveTarget+"?id="+id+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function SendCodes()
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
document.getElementById('sendingStatus').style.display = 'block';		document.getElementById('sendingStatus').innerHTML='Enviando...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('sendingStatus').innerHTML=xmlhttp.responseText;

xmlhttp = false;
}
	}
	xmlhttp.open("GET",sendCodeTarget+"?anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}
function AddCode(code, feedback)
{

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
document.getElementById('codeResult').style.display = 'inline';
document.getElementById('codeResult').innerHTML='Verificando...';

	
		if(xmlhttp.readyState==4)
		{		document.getElementById('codeResult').innerHTML=xmlhttp.responseText;
updateBasketView();
fromFeedback = false;
if (feedback)
{
    if ($('#codeResult').text().indexOf('incorrecto') > -1)
    {
       isOK = false;
       alert('Por favor comprueba el código de descuento');
    }
    else
    {
      verifyCode = false;
      fromFeedback = true;
      $('#confirmButton').click();    

    }
}
xmlhttp = false;
}
	}
	xmlhttp.open("GET",addDiscountTarget +"?code="+code+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function CancelCode(codeId)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById(codeId+'_state').innerHTML='Cambiando...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById(codeId+'_state').innerHTML=xmlhttp.responseText;

xmlhttp = false;
}
	}
	xmlhttp.open("GET",cancelCodeTarget+"?id="+codeId+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}




function RemoveFromBasketCallback(content)
{
  if (content.indexOf("REDIRECT") > -1)
    window.location.href=homePageURL;
}
