var xmlHttp

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function scrollboxinit(){
scrollboxinsert(resellers_output);
scroll();
}

i = 0
var speed = 1
function scroll() {
i = i + speed
var div = document.getElementById("resellerbox")
div.scrollTop = i
if (i > div.scrollHeight - 120) {i = 0}
t1=setTimeout("scroll()",100)
}

function scrollboxinsert(content){
document.getElementById("resellerbox").innerHTML=content;}

function getresellers(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX/ActiveX, change it in your settings or update it!");
return false;
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
resellers_output=xmlHttp.responseText;
return true;
}
}
xmlHttp.open("GET","stores_shopfunctions_ajax.php?mode=showresellers&storeid="+id,true);
xmlHttp.send(null);
}

function add(storeid,itemid,pamount,currency)
{
var theorderby = document.getElementById('orderby').value;
var thecountry = document.getElementById('thecountry').value;
if(pamount==0){
var theamount = document.getElementById('amount_'+itemid).value;
}else{
var theamount = pamount;}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX/ActiveX, change it in your settings or update it!");
return false;
}
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET","stores_shop_ajax.php?mode=add&storeid="+storeid+"&itemid="+itemid+"&amount="+theamount+"&currency="+currency+"&orderby="+theorderby+"&country="+thecountry,true);
xmlHttp.send(null);
}

function remove(storeid,itemid,pamount,currency)
{
var theorderby = document.getElementById('orderby').value;
var thecountry = document.getElementById('thecountry').value;
var theamount = pamount;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX/ActiveX, change it in your settings or update it!");
return false;
}
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET","stores_shop_ajax.php?mode=delete&storeid="+storeid+"&itemid="+itemid+"&amount="+theamount+"&currency="+currency+"&orderby="+theorderby+"&country="+thecountry,true);
xmlHttp.send(null);
}

function sleep(ms){
var zeit=(new Date()).getTime();
var stoppZeit=zeit+ms;
while((new Date()).getTime()<stoppZeit){};
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{
var xmlDoc=xmlHttp.responseXML.documentElement;
sleep(500);
var storeid=xmlDoc.getElementsByTagName("storeid")[0].childNodes[0].nodeValue;
var itemid=xmlDoc.getElementsByTagName("itemid")[0].childNodes[0].nodeValue;
var currency=xmlDoc.getElementsByTagName("currency")[0].childNodes[0].nodeValue;
var itemname=xmlDoc.getElementsByTagName("itemname")[0].childNodes[0].nodeValue;
var itemprice=xmlDoc.getElementsByTagName("itemprice")[0].childNodes[0].nodeValue;
var itemweight=xmlDoc.getElementsByTagName("itemweight")[0].childNodes[0].nodeValue;
var itemvolume=xmlDoc.getElementsByTagName("itemvolume")[0].childNodes[0].nodeValue;
var itemdiscount=xmlDoc.getElementsByTagName("itemdiscount")[0].childNodes[0].nodeValue;
var itemamount=xmlDoc.getElementsByTagName("itemamount")[0].childNodes[0].nodeValue;
var totalprice=xmlDoc.getElementsByTagName("totalprice")[0].childNodes[0].nodeValue;
var totalweight=xmlDoc.getElementsByTagName("totalweight")[0].childNodes[0].nodeValue;
var totalvolume=xmlDoc.getElementsByTagName("totalvolume")[0].childNodes[0].nodeValue;
var totaldiscount=xmlDoc.getElementsByTagName("totaldiscount")[0].childNodes[0].nodeValue;
var totaldiscountpercentage=xmlDoc.getElementsByTagName("totaldiscountpercentage")[0].childNodes[0].nodeValue;
var shippingresellerid=xmlDoc.getElementsByTagName("shippingresellerid")[0].childNodes[0].nodeValue;
if(shippingresellerid!="NO"){
var shippingprice=xmlDoc.getElementsByTagName("shippingprice")[0].childNodes[0].nodeValue;
var shippingweight=xmlDoc.getElementsByTagName("shippingweight")[0].childNodes[0].nodeValue;
var shippingname=xmlDoc.getElementsByTagName("shippingname")[0].childNodes[0].nodeValue;
var shippingtime=xmlDoc.getElementsByTagName("shippingtime")[0].childNodes[0].nodeValue;
var shippingisletter=xmlDoc.getElementsByTagName("shippingisletter")[0].childNodes[0].nodeValue;
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
document.getElementById("shipping_name").innerHTML=shippingname;
document.getElementById("shipping_price").innerHTML=shippingprice;
document.getElementById("shipping_weight").innerHTML=shippingweight;
document.getElementById("shipping_time").innerHTML=shippingtime;
document.getElementById("shipping_isletter").innerHTML=shippingisletter;
document.getElementById("shipping_country").innerHTML=shippingresellerid;
}else{
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
}
document.getElementById("cartprice_total").innerHTML=totalprice;
document.getElementById("cartweight_total").innerHTML=totalweight;
document.getElementById("cartvolume_total").innerHTML=totalvolume;
document.getElementById("cartdiscount_total").innerHTML=totaldiscountpercentage;
document.getElementById("cartdiscount_price").innerHTML=totaldiscount;
document.getElementById("cartdiscount_percentage").innerHTML=totaldiscountpercentage;
document.getElementById("total_price").innerHTML=totalprice2;
document.getElementById("total_weight").innerHTML=totalweight2;
document.getElementById("total_discount").innerHTML=totaldiscount2;


if(document.getElementById("tr_"+itemid)!=null){
removeRow(itemid);
}

var tbl = document.getElementById('shoppingcart');
var row = tbl.insertRow(2);

row.id="tr_"+itemid;

var cellLeft = row.insertCell(0);
cellLeft.width="32%";
cellLeft.align="left";
cellLeft.id="itemname_"+itemid;
var cellLeftitemname = document.createTextNode(itemname);
cellLeft.appendChild(cellLeftitemname);

var cellLeft2 = row.insertCell(1);
cellLeft2.width="12%";
cellLeft2.align="left";
cellLeft2.id="itemprice_"+itemid;
var cellLeft2price = document.createTextNode(itemprice);
cellLeft2.appendChild(cellLeft2price);

var cellLeft3 = row.insertCell(2);
cellLeft3.width="11%";
cellLeft3.align="left";
cellLeft3.id="itemweight_"+itemid;
var cellLeft3weight = document.createTextNode(itemweight);
cellLeft3.appendChild(cellLeft3weight);

var cellLeft4 = row.insertCell(3);
cellLeft4.width="11%";
cellLeft4.align="left";
cellLeft4.id="itemvolume_"+itemid;
var cellLeft4volume = document.createTextNode(itemvolume);
cellLeft4.appendChild(cellLeft4volume);

var cellLeft5 = row.insertCell(4);
cellLeft5.width="9%";
cellLeft5.align="center";
cellLeft5.id="itemamount_"+itemid;
var cellLeft5amount = document.createTextNode(itemamount);
cellLeft5.appendChild(cellLeft5amount);

var cellLeft6 = row.insertCell(5);
cellLeft6.width="10%";
cellLeft6.align="center";
cellLeft6.id="itemamount_"+itemid;
var cellLeft6discount = document.createTextNode(itemdiscount);
cellLeft6.appendChild(cellLeft6discount);

var cellRight = row.insertCell(6);
cellRight.width="15%";	
cellRight.align="center";
cellRight.id="actions_"+itemid;
var spaceholder_text = document.createTextNode(" | ");
var spaceholder_text2 = document.createTextNode(" | ");
var pluslink_text = document.createTextNode("+");
var pluslink = document.createElement('a');
pluslink.href="javascript:add("+ storeid +","+ itemid +",1,'"+currency+"');";
pluslink.onClick="add("+ storeid +","+ itemid +",1,'"+currency+"');";
pluslink.appendChild(pluslink_text);
var minuslink_text = document.createTextNode("-");
var minuslink = document.createElement('a');
minuslink.href="javascript:remove("+ storeid +","+ itemid +",1,'"+currency+"');";
minuslink.onClick="remove("+ storeid +","+ itemid +",1,'"+currency+"');";
minuslink.appendChild(minuslink_text);
var deletelink_text = document.createTextNode("X");
var deletelink = document.createElement('a');
deletelink.href="javascript:remove("+ storeid +","+ itemid +",0,'"+currency+"');";
deletelink.onClick="remove("+ storeid +","+ itemid +",0,'"+currency+"');";
deletelink.appendChild(deletelink_text);
cellRight.appendChild(pluslink);
cellRight.appendChild(spaceholder_text);
cellRight.appendChild(minuslink);
cellRight.appendChild(spaceholder_text2);
cellRight.appendChild(deletelink);
}
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4)
{
var xmlDoc=xmlHttp.responseXML.documentElement;
sleep(400);
var itemid=xmlDoc.getElementsByTagName("itemid")[0].childNodes[0].nodeValue;
var itemname=xmlDoc.getElementsByTagName("itemname")[0].childNodes[0].nodeValue;
var currency=xmlDoc.getElementsByTagName("currency")[0].childNodes[0].nodeValue;
if(itemname=="DELETE"){
var totalprice=xmlDoc.getElementsByTagName("totalprice")[0].childNodes[0].nodeValue;
var totalweight=xmlDoc.getElementsByTagName("totalweight")[0].childNodes[0].nodeValue;
var totalvolume=xmlDoc.getElementsByTagName("totalvolume")[0].childNodes[0].nodeValue;
var totaldiscount=xmlDoc.getElementsByTagName("totaldiscount")[0].childNodes[0].nodeValue;
var totaldiscountpercentage=xmlDoc.getElementsByTagName("totaldiscountpercentage")[0].childNodes[0].nodeValue;
var shippingresellerid=xmlDoc.getElementsByTagName("shippingresellerid")[0].childNodes[0].nodeValue;
if(shippingresellerid!="NO"){
var shippingprice=xmlDoc.getElementsByTagName("shippingprice")[0].childNodes[0].nodeValue;
var shippingweight=xmlDoc.getElementsByTagName("shippingweight")[0].childNodes[0].nodeValue;
var shippingname=xmlDoc.getElementsByTagName("shippingname")[0].childNodes[0].nodeValue;
var shippingtime=xmlDoc.getElementsByTagName("shippingtime")[0].childNodes[0].nodeValue;
var shippingisletter=xmlDoc.getElementsByTagName("shippingisletter")[0].childNodes[0].nodeValue;
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
document.getElementById("shipping_name").innerHTML=shippingname;
document.getElementById("shipping_price").innerHTML=shippingprice;
document.getElementById("shipping_weight").innerHTML=shippingweight;
document.getElementById("shipping_time").innerHTML=shippingtime;
document.getElementById("shipping_isletter").innerHTML=shippingisletter;
document.getElementById("shipping_country").innerHTML=shippingresellerid;
}else{
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
}
document.getElementById("cartprice_total").innerHTML=totalprice;
document.getElementById("cartweight_total").innerHTML=totalweight;
document.getElementById("cartvolume_total").innerHTML=totalvolume;
document.getElementById("cartdiscount_total").innerHTML=totaldiscountpercentage;
document.getElementById("cartdiscount_percentage").innerHTML=totaldiscountpercentage;
document.getElementById("cartdiscount_price").innerHTML=totaldiscount;
document.getElementById("total_price").innerHTML=totalprice2;
document.getElementById("total_weight").innerHTML=totalweight2;
document.getElementById("total_discount").innerHTML=totaldiscount2;
removeRow(itemid);
}else{
var storeid=xmlDoc.getElementsByTagName("storeid")[0].childNodes[0].nodeValue;
var itemprice=xmlDoc.getElementsByTagName("itemprice")[0].childNodes[0].nodeValue;
var itemweight=xmlDoc.getElementsByTagName("itemweight")[0].childNodes[0].nodeValue;
var itemvolume=xmlDoc.getElementsByTagName("itemvolume")[0].childNodes[0].nodeValue;
var itemamount=xmlDoc.getElementsByTagName("itemamount")[0].childNodes[0].nodeValue;
var itemdiscount=xmlDoc.getElementsByTagName("itemdiscount")[0].childNodes[0].nodeValue;
var totalprice=xmlDoc.getElementsByTagName("totalprice")[0].childNodes[0].nodeValue;
var totalweight=xmlDoc.getElementsByTagName("totalweight")[0].childNodes[0].nodeValue;
var totalvolume=xmlDoc.getElementsByTagName("totalvolume")[0].childNodes[0].nodeValue;
var totaldiscount=xmlDoc.getElementsByTagName("totaldiscount")[0].childNodes[0].nodeValue;
var totaldiscountpercentage=xmlDoc.getElementsByTagName("totaldiscountpercentage")[0].childNodes[0].nodeValue;
var shippingresellerid=xmlDoc.getElementsByTagName("shippingresellerid")[0].childNodes[0].nodeValue;
if(shippingresellerid!="NO"){
var shippingprice=xmlDoc.getElementsByTagName("shippingprice")[0].childNodes[0].nodeValue;
var shippingweight=xmlDoc.getElementsByTagName("shippingweight")[0].childNodes[0].nodeValue;
var shippingname=xmlDoc.getElementsByTagName("shippingname")[0].childNodes[0].nodeValue;
var shippingtime=xmlDoc.getElementsByTagName("shippingtime")[0].childNodes[0].nodeValue;
var shippingisletter=xmlDoc.getElementsByTagName("shippingisletter")[0].childNodes[0].nodeValue;
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
document.getElementById("shipping_name").innerHTML=shippingname;
document.getElementById("shipping_price").innerHTML=shippingprice;
document.getElementById("shipping_weight").innerHTML=shippingweight;
document.getElementById("shipping_time").innerHTML=shippingtime;
document.getElementById("shipping_isletter").innerHTML=shippingisletter;
document.getElementById("shipping_country").innerHTML=shippingresellerid;
}else{
var totalprice2=xmlDoc.getElementsByTagName("totalprice2")[0].childNodes[0].nodeValue;
var totalweight2=xmlDoc.getElementsByTagName("totalweight2")[0].childNodes[0].nodeValue;
var totaldiscount2=xmlDoc.getElementsByTagName("totaldiscount2")[0].childNodes[0].nodeValue;
}
document.getElementById("cartprice_total").innerHTML=totalprice;
document.getElementById("cartweight_total").innerHTML=totalweight;
document.getElementById("cartvolume_total").innerHTML=totalvolume;
document.getElementById("cartdiscount_total").innerHTML=totaldiscountpercentage;
document.getElementById("cartdiscount_percentage").innerHTML=totaldiscountpercentage;
document.getElementById("cartdiscount_price").innerHTML=totaldiscount;
document.getElementById("total_price").innerHTML=totalprice2;
document.getElementById("total_weight").innerHTML=totalweight2;
document.getElementById("total_discount").innerHTML=totaldiscount2;

if(document.getElementById("tr_"+itemid)!=null){
removeRow(itemid);
}

var tbl = document.getElementById('shoppingcart');
var row = tbl.insertRow(2);

row.id="tr_"+itemid;

var cellLeft = row.insertCell(0);
cellLeft.width="32%";
cellLeft.align="left";
cellLeft.id="itemname_"+itemid;
var cellLeftitemname = document.createTextNode(itemname);
cellLeft.appendChild(cellLeftitemname);

var cellLeft2 = row.insertCell(1);
cellLeft2.width="12%";
cellLeft2.align="left";
cellLeft2.id="itemprice_"+itemid;
var cellLeft2price = document.createTextNode(itemprice);
cellLeft2.appendChild(cellLeft2price);

var cellLeft3 = row.insertCell(2);
cellLeft3.width="11%";
cellLeft3.align="left";
cellLeft3.id="itemweight_"+itemid;
var cellLeft3weight = document.createTextNode(itemweight);
cellLeft3.appendChild(cellLeft3weight);

var cellLeft4 = row.insertCell(3);
cellLeft4.width="11%";
cellLeft4.align="left";
cellLeft4.id="itemvolume_"+itemid;
var cellLeft4volume = document.createTextNode(itemvolume);
cellLeft4.appendChild(cellLeft4volume);

var cellLeft5 = row.insertCell(4);
cellLeft5.width="9%";
cellLeft5.align="center";
cellLeft5.id="itemamount_"+itemid;
var cellLeft5amount = document.createTextNode(itemamount);
cellLeft5.appendChild(cellLeft5amount);

var cellLeft6 = row.insertCell(5);
cellLeft6.width="10%";
cellLeft6.align="center";
cellLeft6.id="itemdiscount_"+itemid;
var cellLeft6discount = document.createTextNode(itemdiscount);
cellLeft6.appendChild(cellLeft6discount);

var cellRight = row.insertCell(6);
cellRight.width="15%";	
cellRight.align="center";
cellRight.id="actions_"+itemid;
var spaceholder_text = document.createTextNode(" | ");
var spaceholder_text2 = document.createTextNode(" | ");
var pluslink_text = document.createTextNode("+");
var pluslink = document.createElement('a');
pluslink.href="javascript:add("+ storeid +","+ itemid +",1,'"+currency+"');";
pluslink.onClick="add("+ storeid +","+ itemid +",1,'"+currency+"');";
pluslink.appendChild(pluslink_text);
var minuslink_text = document.createTextNode("-");
var minuslink = document.createElement('a');
minuslink.href="javascript:remove("+ storeid +","+ itemid +",1,'"+currency+"');";
minuslink.onClick="remove("+ storeid +","+ itemid +",1,'"+currency+"');";
minuslink.appendChild(minuslink_text);
var deletelink_text = document.createTextNode("X");
var deletelink = document.createElement('a');
deletelink.href="javascript:remove("+ storeid +","+ itemid +",0,'"+currency+"');";
deletelink.onClick="remove("+ storeid +","+ itemid +",0,'"+currency+"');";
deletelink.appendChild(deletelink_text);
cellRight.appendChild(pluslink);
cellRight.appendChild(spaceholder_text);
cellRight.appendChild(minuslink);
cellRight.appendChild(spaceholder_text2);
cellRight.appendChild(deletelink);
}
}
}

function removeRow(itemid){
var tbl = document.getElementById('shoppingcart');
var rowtodelete = document.getElementById("tr_"+itemid);
tbl.deleteRow(rowtodelete.rowIndex);
}