var myCart="mycart";
function SoftXMLCart(){
		var myXpathObj = new SoftXpath();
		myXpathObj.registerNamespace("","");
		myXpathObj.load("data.xml");
		var myXMLObject = new SoftXMLLib();
		this.categoryID=0;
		this.categoryName="";
		this.setCategoryName=function(value){this.categoryName=value};
		this.getCategoryName=function(){return this.categoryName};
		this.setCategoryID=function(value){this.categoryID=value};
		this.setDefaultCategoryID=function(value){this.categoryID=value};
		this.getCategoryID=function(){return this.categoryID};
		this.productArray=new Array();
		this.totalproducts=0;
		this.totalcost=0;
		this.currency="";
		this.productsPerRow=1;
		this.totalitems=0;
		this.showCategories="*";
		this.queryXPath="";
		this.productBGColor="#E8E8E8";
		this.paypalemail="";
		this.setPayPalEmail=function(value){this.paypalemail=value};	
		this.getEmail=function(){return this.paypalemail};
		this.totalcostshipping=0;
		this.xml="";
		this.json="";
		this.cartHTML="";
		this.IP="";
		this.getIP = function(){
		    var _this=this;
		    var ajaxObj = myXMLObject.createAjaxObject();
		    ajaxObj.onreadystatechange=function() {
				if(ajaxObj.readyState == 4 && ajaxObj.status == 200) {
			   		_this.IP=ajaxObj.responseText;
				}
			}
			ajaxObj.open("GET","getIP.asp",true);
			ajaxObj.send(null);
		}
		//this.getIP();
		
		window.onload=function(){
			//alert(document.cookie);
		    mycart = myCart.getCartCookie("cartJS");
		    var myCookieObj = new SoftXpath();
		    myCookieObj.registerNamespace("","");
		    if(mycart!=null && mycart!=''){
		        if(myCookieObj.loadXML(mycart)){
		            prods = myCookieObj.selectNodes("//product");
		            for(var i=0;i<prods.length;i++){
		                curcatid = prods[i].me._.parentNode.getAttribute("catid");
		                curprodid = prods[i].me._.getAttribute("prodid");
		                curprodquantity = prods[i].me._.getAttribute("quantity");
		                curprodprice = prods[i].me._.getAttribute("price");
		                myCart.add(curcatid,{productid:curprodid,currencyid:myCart.currencySymbol(true),quantity:curprodquantity,price:curprodprice});
		            }
		            myCart.printProductsByCategory();
			        myCart.setCartStatus(myCart.totalCartItems(),myCart.totalCartCost());
		        }
		    }
			
		}
		
		this.setActiveCategory=function(){
			var curcategories = document.getElementById("categories_container").getElementsByTagName("INPUT");
			for(var i=0;i<curcategories.length;i++){
				if(curcategories[i].id==this.categoryID){
					curcategories[i].style.color="red";
					curcategories[i].style.borderWidth="3px";
				}
				else{
					curcategories[i].style.color="black";
					curcategories[i].style.borderWidth="1px";
				}
			}
		}
		this.getProductInfoByCategory=function(catid,id){
				var resObj;
				
				for(var i=0;i<this.productArray[catid].length;i++){
				    //alert(this.productArray[catid][i]["id"] +"=" + id);
					if(this.productArray[catid][i]["id"]==id){
						return this.productArray[catid][i]["quantity"]; 
					}
				}
				return 0;
		}
		this.resetCategories=function(){
			var curcategories = document.getElementById("categories_container").getElementsByTagName("INPUT");
			for(var i=0;i<curcategories.length;i++){
				curcategories[i].style.color="black";
				curcategories[i].style.borderWidth="1px";
			}
		}
		this.preloadImages=function(){
			var images = myXpathObj.selectNodes(this.queryXPath +"//image");
			var imagescount=images.length;
			for(i=0; i<imagescount; i++) 
			{
				var curImg=new Image();
				curImg.src=""+images[i].text;	
			}
		}
		this.add=function(categoryid,objparams){
				shippingcost = parseFloat(myXpathObj.selectNodes("//category[@id='"+categoryid+"']/product[@id='"+objparams["productid"]+"']/@shippingcost")[0].text);
				if(this.hasInCategory(categoryid,objparams["productid"])){
					for(var i=0;i<this.productArray[categoryid].length;i++){
						if(this.productArray[categoryid][i]["id"]===objparams["productid"]){
							this.productArray[categoryid][i]["quantity"]=parseFloat(objparams["quantity"]);
							this.productArray[categoryid][i]["total"]=(parseFloat(this.productArray[categoryid][i]["quantity"])*parseFloat(this.productArray[categoryid][i]["price"]))+(parseFloat(this.productArray[categoryid][i]["quantity"])*shippingcost);
						}
					}
				}
				else{
					this.totalproducts++;
					if(!this.productArray[categoryid]){
						this.productArray[categoryid]=new Array({catid:categoryid,catname:String(myXpathObj.selectNodes("//category[@id='"+categoryid+"']/@name")[0].text),prodname:String(myXpathObj.selectNodes("//product[@id='"+objparams["productid"]+"']/title")[0].text),id:objparams["productid"],currencyid:objparams["currencyid"],quantity:objparams["quantity"],price:objparams["price"],total:(parseFloat(objparams["quantity"])*parseFloat(objparams["price"]))+(parseFloat(objparams["quantity"])*shippingcost),shipping:shippingcost});
					}
					else{
						this.productArray[categoryid][this.productArray[categoryid].length]={catid:categoryid,catname:String(myXpathObj.selectNodes("//category[@id='"+categoryid+"']/@name")[0].text),prodname:String(myXpathObj.selectNodes("//product[@id='"+objparams["productid"]+"']/title")[0].text),id:objparams["productid"],currencyid:objparams["currencyid"],quantity:objparams["quantity"],price:objparams["price"],total:(parseFloat(objparams["quantity"])*parseFloat(objparams["price"]))+(parseFloat(objparams["quantity"])*shippingcost),shipping:shippingcost};
					}
				}
				this.totalShippingCost();
				
				this.updateDeleteSaveCartCookie(this.js2xml(),30);
				
		}
		this.hasInCategory=function(catid,id){
				try{
					for(var i=0;i<this.productArray[catid].length;i++){
						if(this.productArray[catid][i]["id"]==id){
							return true; 
						}
					}
					return false;
				}
				catch(e){
					return false;
				}	
		}
		this.remove=function(catid,id){
					if(catid){
						if(this.productArray[catid].length==0){
							this.productArray[catid]="";
							return false;
						}
						for(var i=0;i<this.productArray[catid].length;i++){
								if(this.productArray[catid][i]["id"]===id){
									this.productArray[catid].splice(i,1);
								}
						}
					}
					else{
						for(x in this.productArray){
							for(var i=0;i<this.productArray[x].length;i++){
								if(this.productArray[x][i]["id"]===id){
									this.productArray[x].splice(i,1);
								}
							}
						}
					}	
					this.totalproducts--;
					if(this.totalproducts<this.productArray[catid].length){
						this.totalproducts=this.productArray[catid].length;
					}
					this.updateDeleteSaveCartCookie(this.js2xml(),30);
					this.setCartStatus(this.totalitems,this.totalCartCost());
					
					
					
					
		}
		
		this.updateDeleteSaveCartCookie=function(value,expiredays){
		    //alert(value);
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			//alert(this.js2xml());
			document.cookie="cartJS=" + escape(value)+ ";expires="+exdate.toGMTString()+";path=/";
			
		}
		
		
		
		this.getCartCookie=function(name){
				cookieLen = String(document.cookie).split(";");
				for(var i=0;i<cookieLen.length;i++){
					if(String(cookieLen[i]).replace(" ","").split("=")[0]==name){
						return unescape(String(cookieLen[i]).split("=")[1]);
					}
				}
		
		}
		
		
		this.setCartStatus=function(icount,tcost){
			document.getElementById("curitemscount").innerHTML=this.totalitems;
			document.getElementById("curtotalcost").innerHTML=Number(this.totalCartCost()).toFixed(2);
		}
		this.isCartEmpty=function(){
			var cartIsEmpty = true;
			if(!this.productArray){
				return cartIsEmpty;
			}
			for(x in this.productArray){
				if(this.productArray[x].length>0){
					cartIsEmpty=false;
				}
			}
			return cartIsEmpty;
		}
		this.printLogo=function(){
			
			return "<img src='"+myXpathObj.selectNodes("//@logo")[0].text +"'/>";
		}
		this.printCartCategories=function(){
			var queryXPath="";
			var catlen = String(this.showCategories).split(",");
			if(catlen.length==1 && catlen[0]=="*"){
				queryXPath+="//category";
			}
			else{
				queryXPath+="//category[";
				for(var y=0;y<catlen.length;y++){
					if(y<catlen.length-1){
						var punct=" or ";
					}
					else{
						var punct="";
					}
					queryXPath+="@id='"+catlen[y] + "'" + punct + "";
				}
				queryXPath+="]";
			}	
			this.queryXPath=queryXPath;
			reCategoryO = myXpathObj.selectNodes(queryXPath);
			var catHTML="";
			for(var i=0;i<reCategoryO.length;i++){
				catHTML+="<table cellpadding='4' cellspacing='4' border='0'><tr><td><input style='font-family:arial;font-size:12px;border-width:1px;' type='button' id='"+reCategoryO[i].me._.getAttribute("id")+"' catname='"+reCategoryO[i].me._.getAttribute("name")+"' onclick='myCart.setCategoryID(this.id);myCart.setCategoryName(this.getAttribute(\"catname\"));myCart.setActiveCategory();myCart.printProductsByCategory();' value='"+reCategoryO[i].me._.getAttribute("name")+"'/></td></tr></table>";	
			}	
			return catHTML;
		}
		this.printProductsByCategory=function(displaydefault){
			reProductsO = myXpathObj.selectNodes("//product[./parent::category/@id='"+this.categoryID+"']");
			curCatName = myXpathObj.selectNodes("//category[@id='"+this.categoryID+"']")[0].me._.getAttribute("name");
			cartObj = myXpathObj.selectNodes("//cart")[0];
			this.categoryName=curCatName;
			var prodHTML="";
			var outerContainer="<table cellpadding='4' cellspacing='4' border='0' ><tr><td style='font-family:"+cartObj.me._.getAttribute("category-font-family")+";font-size:"+cartObj.me._.getAttribute("category-font-size")+";font-weight:bold;color:"+cartObj.me._.getAttribute("category-color")+"' colspan='"+this.productsPerRow+"'>"+this.getCategoryName()+"</td></tr><tr>";
			var parentObj = this.constructor;
			for(var i=0;i<reProductsO.length;i++){
				var curprodname = reProductsO[i].me._.getElementsByTagName("title")[0].childNodes[0].nodeValue;
				var curid=reProductsO[i].me._.getAttribute("id");
				var curlink = reProductsO[i].me._.getElementsByTagName("image")[0].getAttribute("link");
				if(curlink>""){
				    var imgclickevent="onclick=window.open('"+curlink+"') style='cursor:pointer;'";
				}
				else{
				    var imgclickevent="";
				}
				var curimg = "<img " + imgclickevent + " src='"+reProductsO[i].me._.getElementsByTagName("image")[0].childNodes[0].nodeValue+"' alt='"+curprodname+"' title='"+curprodname+"' width='"+reProductsO[i].me._.getElementsByTagName("image")[0].getAttribute("width")+"' height='"+reProductsO[i].me._.getElementsByTagName("image")[0].getAttribute("height")+"'/>";
				var price = reProductsO[i].me._.getAttribute("price");
				var currency = this.currency;
				var description = reProductsO[i].me._.getElementsByTagName("description")[0].childNodes[0].nodeValue;
				var curquantity=0;
				//alert(this.isCartEmpty());
				if(!this.isCartEmpty()){
					try{
						curquantity = this.getProductInfoByCategory(this.categoryID,curid);
					}
					catch(e){};	
				}
				if(i>0 && i%this.productsPerRow==0){
					outerContainer+="</tr><tr>";
				}	
				//alert(curquantity);
				outerContainer+="<td><table cellpadding='1' cellspacing='4' bgcolor='"+this.productBGColor+"' border='0' style='width:181px;font-family:arial;font-size:12px;'><tr><td align='center'><span style='font-weight:bold;color:"+cartObj.me._.getAttribute("product-title-color")+";font-family:"+cartObj.me._.getAttribute("product-title-font-family")+";font-size:"+cartObj.me._.getAttribute("product-title-font-size")+"'>"+curprodname+ "</span> - <span style='font-weight:bold;color:"+cartObj.me._.getAttribute("product-price-color")+";font-family:"+cartObj.me._.getAttribute("product-price-font-family")+";font-size:"+cartObj.me._.getAttribute("product-price-font-size")+"'>" + this.currencySymbol(true)+ price + "</span></td></tr><tr><td>"+curimg+"</td></tr><tr><td align='center' style='font-weight:normal;color:"+cartObj.me._.getAttribute("product-description-color")+";font-family:"+cartObj.me._.getAttribute("product-description-font-family")+";font-size:"+cartObj.me._.getAttribute("product-description-font-size")+"'>"+description+"</td></tr><tr><td align='center'><input type='text' style='width:60px;' catid='"+this.categoryID+"' onfocus='this.focus();this.select();'  currency='"+this.currency+"' value='"+curquantity+"' price='"+price+"' id='"+curid+"'/>  <input type='button' value='Add to cart' onclick='myCart.add2cart(this);'/></td></tr></table></td>";	
			}	
			outerContainer+="</tr></table>";
			if(displaydefault){
			    this.setActiveCategory();
			    return outerContainer;
			}
			else{
			    document.getElementById("productPage").innerHTML=outerContainer;
			}    
		}
		this.totalShippingCost=function(){
				var costshipping=0;
				for(x in this.productArray){
				for(var i=0;i<this.productArray[x].length;i++){
					costshipping+=parseFloat(this.productArray[x][i]["shipping"]).toFixed(2)*parseInt(this.productArray[x][i]["quantity"]);
				}
			}
			this.totalcostshipping=costshipping;
			return costshipping;
		}
		this.totalCartCost=function(){
			var totalcost=0;
				for(x in this.productArray){
				for(var i=0;i<this.productArray[x].length;i++){
					totalcost+=parseFloat(this.productArray[x][i]["total"]);
				}
			}
			return totalcost;
		}
		this.totalCartItems=function(){
		    var totalitems=0;
			for(x in this.productArray){
				for(var i=0;i<this.productArray[x].length;i++){
					totalitems+=parseInt(this.productArray[x][i]["quantity"]);
				}
			}
			this.totalitems=totalitems;
			this.setCartStatus(this.totalitems,this.totalCartCost());
		}
		this.add2cart=function(obj){
			sourceobj = obj.parentNode.getElementsByTagName("INPUT")[0];
			var quant = parseInt(sourceobj.value);
			sourceobj.value=quant;
			var id = sourceobj.id;
			var price = sourceobj.getAttribute("price");
			var catid = sourceobj.getAttribute("catid");
			var currency = sourceobj.getAttribute("currency");
			if(quant>0){
				this.add(catid,{productid:id,currencyid:currency,quantity:quant,price:price});
				this.setCartStatus(this.totalitems,this.totalCartCost());
			}	
			else{
				if(!this.isCartEmpty()){
					this.remove(catid,id);
				}	
				sourceobj.value="0"
			}
			this.totalCartItems();
			this.xml = this.js2xml();
			if(typeof this.xml !="undefined"){
				myXMLObject.loadXML(this.xml);
				this.json=this.xml2json(myXMLObject.DOM,"  ");
			}
				
			
		}
		this.updateCart=function(parentObj){
			
			var items = document.getElementById(parentObj).getElementsByTagName("INPUT");
			
			for(var i=0;i<items.length;i++){
				if(items[i].type=="text"){
					sourceobj = items[i];
					this.add2cart(sourceobj);
				}	
			}
			this.showCart();
		}
		this.emptyCar=function(){
			if(confirm("Delete content of your shopping cart!")){
				for(x in this.productArray){
					this.productArray[x].length=0;
				}
				this.totalitems=0;
				this.totalproducts=0;
				this.totalcost=0;
				this.totalcostshipping=0;
				this.updateDeleteSaveCartCookie("",-1);
				this.showCart();
			}	
		}
		this.currencySymbol = function(is4print) {		
			switch(this.currency){
				case "JPY":
					return "&yen;";
				case "USD":
					return "$";	
				case "EUR":
					return "&euro;";
				case "GBP":
					return "&pound;";
				case "SGD":
					return "&#36;";
				default:
					if(!is4print){
						return "";
					}	
					else{
						return this.currency;
					}
			}
		}
		this.currencyStringForPaypalCheckout = function( value ){
			if( this.currencySymbol() == "&#36;" ){
				return "$" + parseFloat(value).toFixed(2);
			} else {
				return "" + parseFloat(value ).toFixed(2);
			}
		}
		this.parseJSON = function (str) {
			
			try {
				if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(str)) {
					
					return eval('(' + str + ')');
				}
			} catch (e) {
			
			}
			//throw new SyntaxError("parseJSON");
		}
		this.js2xml=function(){
			try{
				var js2xmlstr="<ecart_js currency=\""+String(this.currencySymbol(true)).replace("&","&amp;")+"\" cart_total_cost=\""+parseFloat(this.totalCartCost()).toFixed(2)+"\" cart_items=\""+this.totalitems+"\" cart_item_cost=\""+parseFloat(parseFloat(this.totalCartCost()).toFixed(2)-parseFloat(this.totalcostshipping).toFixed(2)).toFixed(2)+"\" cart_shipping_cost=\""+parseFloat(this.totalcostshipping).toFixed(2)+"\">";
				var cnt=0;
				
				
				for(x in this.productArray){
				    if(this.productArray[x].length>0){
					    js2xmlstr+="<category catname=\""+this.productArray[x][0]["catname"]+"\" catid=\""+this.productArray[x][0]["catid"]+"\" >";
					    for(var i=0;i<this.productArray[x].length;i++){
    						
						    if(curcat!=x){
							    js2xmlstr+="<product prodname=\""+this.productArray[x][i]["prodname"]+"\" prodid=\""+this.productArray[x][i]["id"]+"\" price=\""+parseFloat(this.productArray[x][i]["price"]).toFixed(2)+"\" pricetotal=\""+parseFloat(parseFloat(this.productArray[x][i]["price"]).toFixed(2)*this.productArray[x][i]["quantity"]).toFixed(2)+"\" shipping_cost=\""+this.productArray[x][i]["shipping"]+"\" shippingtotal=\""+parseFloat(parseFloat(this.productArray[x][i]["shipping"]).toFixed(2)*this.productArray[x][i]["quantity"]).toFixed(2)+"\" quantity=\""+this.productArray[x][i]["quantity"]+"\"/>";
						    }
						    else{
							    js2xmlstr+="<product prodname=\""+this.productArray[x][i]["prodname"]+"\" prodid=\""+this.productArray[x][i]["id"]+"\" price=\""+parseFloat(this.productArray[x][i]["price"]).toFixed(2)+"\" pricetotal=\""+parseFloat(parseFloat(this.productArray[x][i]["price"]).toFixed(2)*this.productArray[x][i]["quantity"]).toFixed(2)+"\" shipping_cost=\""+this.productArray[x][i]["shipping"]+"\" shippingtotal=\""+parseFloat(parseFloat(this.productArray[x][i]["shipping"]).toFixed(2)*this.productArray[x][i]["quantity"]).toFixed(2)+"\"  quantity=\""+this.productArray[x][i]["quantity"]+"\"/>";
						    }
						    var curcat=x;
					    }	
					    cnt++;
					    js2xmlstr+="</category>";
					}    
				}	
				js2xmlstr+="</ecart_js>";
				
				return js2xmlstr;
			}
			catch(e){alert(e.description);};	
		}
		this.xml2json=function(xml, tab){
				var X = {
				toObj: function(xml) {
					var o = {};
					if (xml.nodeType==1) {
						if (xml.attributes.length)
						for (var i=0; i<xml.attributes.length; i++)
							o["@"+xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue||"").toString();
						if (xml.firstChild) {
						var textChild=0, cdataChild=0, hasElementChild=false;
						for (var n=xml.firstChild; n; n=n.nextSibling) {
							if (n.nodeType==1) hasElementChild = true;
							else if (n.nodeType==3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) textChild++;
							else if (n.nodeType==4) cdataChild++;
						}
						if (hasElementChild) {
							if (textChild < 2 && cdataChild < 2) {
								X.removeWhite(xml);
								for (var n=xml.firstChild; n; n=n.nextSibling) {
									if (n.nodeType == 3)
									o["#text"] = X.escape(n.nodeValue);
									else if (n.nodeType == 4)
									o["#cdata"] = X.escape(n.nodeValue);
									else if (o[n.nodeName]) {
									if (o[n.nodeName] instanceof Array)
										o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
									else
										o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
									}
									else 
									o[n.nodeName] = X.toObj(n);
								}
							}
							else { 
								if (!xml.attributes.length)
									o = X.escape(X.innerXml(xml));
								else
									o["#text"] = X.escape(X.innerXml(xml));
							}
						}
						else if (textChild) {
							if (!xml.attributes.length)
								o = X.escape(X.innerXml(xml));
							else
								o["#text"] = X.escape(X.innerXml(xml));
						}
						else if (cdataChild) {
							if (cdataChild > 1)
								o = X.escape(X.innerXml(xml));
							else
								for (var n=xml.firstChild; n; n=n.nextSibling)
									o["#cdata"] = X.escape(n.nodeValue);
						}
						}
						if (!xml.attributes.length && !xml.firstChild) o = null;
					}
					else if (xml.nodeType==9) {
						o = X.toObj(xml.documentElement);
					}
					else
						alert("unhandled node type: " + xml.nodeType);
					return o;
				},
				toJson: function(o, name, ind) {
					var json = name ? ("\""+name+"\"") : "";
					if (o instanceof Array) {
						for (var i=0,n=o.length; i<n; i++)
						o[i] = X.toJson(o[i], "", ind+"\t");
						json += (name?":[":"[") + (o.length > 1 ? ("\n"+ind+"\t"+o.join(",\n"+ind+"\t")+"\n"+ind) : o.join("")) + "]";
					}
					else if (o == null)
						json += (name&&":") + "null";
					else if (typeof(o) == "object") {
						var arr = [];
						for (var m in o)
						arr[arr.length] = X.toJson(o[m], m, ind+"\t");
						json += (name?":{":"{") + (arr.length > 1 ? ("\n"+ind+"\t"+arr.join(",\n"+ind+"\t")+"\n"+ind) : arr.join("")) + "}";
					}
					else if (typeof(o) == "string")
						json += (name&&":") + "\"" + o.toString() + "\"";
					else
						json += (name&&":") + o.toString();
					return json;
				},
				innerXml: function(node) {
					var s = ""
					if ("innerHTML" in node)
						s = node.innerHTML;
					else {
						var asXml = function(n) {
						var s = "";
						if (n.nodeType == 1) {
							s += "<" + n.nodeName;
							for (var i=0; i<n.attributes.length;i++)
								s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue||"").toString() + "\"";
							if (n.firstChild) {
								s += ">";
								for (var c=n.firstChild; c; c=c.nextSibling)
									s += asXml(c);
								s += "</"+n.nodeName+">";
							}
							else
								s += "/>";
						}
						else if (n.nodeType == 3)
							s += n.nodeValue;
						else if (n.nodeType == 4)
							s += "<![CDATA[" + n.nodeValue + "]]>";
						return s;
						};
						for (var c=node.firstChild; c; c=c.nextSibling)
						s += asXml(c);
					}
					return s;
				},
				escape: function(txt) {
					return txt.replace(/[\\]/g, "\\\\")
							.replace(/[\"]/g, '\\"')
							.replace(/[\n]/g, '\\n')
							.replace(/[\r]/g, '\\r');
				},
				removeWhite: function(e) {
					e.normalize();
					for (var n = e.firstChild; n; ) {
						if (n.nodeType == 3) {
						if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
							var nxt = n.nextSibling;
							e.removeChild(n);
							n = nxt;
						}
						else
							n = n.nextSibling;
						}
						else if (n.nodeType == 1) {
						X.removeWhite(n);
						n = n.nextSibling;
						}
						else                      
						n = n.nextSibling;
					}
					return e;
				}
			};
			if (xml.nodeType == 9)
				xml = xml.documentElement;
			var json = X.toJson(X.toObj(X.removeWhite(xml)), xml.nodeName, "\t");
			return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
			}
		this.printJSON=function(){
			var obj = this.parseJSON(this.json);
			var startLoop=obj["ecart_js"];
			loopJSON(startLoop);
			function loopJSON(sl){
				for(x in sl){
					if(typeof sl[x]!="object"){
						alert(x+"="+sl[x]);
					}
					if(typeof sl[x]=="object"){
						loopJSON(sl[x]);
					}
				}
			}
		}
		this.invokeDB=function(pageurl,datatype){
			/*alert(this[datatype]);
			var myXMLObjecta = new SoftXMLLib();
			var ajaxObja = myXMLObjecta.createAjaxObject();
			
				myXMLObjecta.loadXML(this["json"]);
			
				alert(myXMLObjecta.getDocXML());
				
			
			//if(myXMLObjecta.loadXMLError!=0){
				//myXMLObjecta.loadXML("<root>" + this[datatype] + "</root>");
			//}
			//alert("<root>"+this.json+"</root>");
			
			//myXMLObjecta.loadXML("<root>"+this.json+"</root>");
			
			
			//ajaxObja.open("POST",pageurl,true);
			//ajaxObja.onreadystatechange=function() {
			//if (ajaxObja.readyState==4) {
				//status=ajaxObja.responseText;
			//}
			//else{
				//status="executing db query...";
			//}
				//}
			//ajaxObja.send(myXMLObjecta.DOM);*/
			
		}
		this.paypalCheckout = function() {
			//alert(this.IP);
			//alert(this.json);
			//this.printJSON();
			//this.invokeDB("http://www.softxml.com","json");
			var winpar = "scrollbars,location,resizable,status";
			var strn  = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart"+"&upload=1"+"&business="+this.paypalemail+"&currency_code="+this.currency;
			var counter = 1;
			var itemsString = "";
			/*if( me.taxRate ){
				strn = strn + 
					"&tax_cart=" +  me.currencyStringForPaypalCheckout( me.taxCost );
			}*/
			for(x in this.productArray){
				for(var i=0;i<this.productArray[x].length;i++){
					var optionsString = "";
					itemsString = itemsString 	+ "&item_name_" 	+ counter + "=" + this.productArray[x][i]["prodname"]  +
					"&item_number_" 			+ counter + "=" + this.productArray[x][i]["id"] +
					"&quantity_"				+ counter + "=" + this.productArray[x][i]["quantity"] +
					"&amount_"					+ counter + "=" + this.currencyStringForPaypalCheckout(this.productArray[x][i]["price"]); 
					counter++;
				}
			}
			itemsString = itemsString + "&handling_cart="+parseFloat(this.totalShippingCost()).toFixed(2);
			strn = strn + itemsString ;
			//document.write(myCart.js2xml());
			//document.write(strn);
			window.open (strn, "paypal", winpar);
		}
		this.showCart=function(){
				var cnt=0;
				if(this.isCartEmpty()){
					this.setCartStatus();
					this.setActiveCategory();
					this.printProductsByCategory();
					alert("Your shopping cart is empty!");
					return;
				}
				this.resetCategories();
				var outHTML="<table cellpadding=\"4\" id=\"shopping_cart_details\" cellspacing=\"2\" bgcolor=\""+this.productBGColor+"\" border=\"0\" width=\"100%\" style=\"font-family:arial;font-size:12px;color:#000000;\"><tr style=\"font-weight:bold;\"><td>Category</td><td>Item #</td><td>Description</td><td>Price</td><td>Quantity</td><td>Shipping</td><td>Cost</td></tr>";
				
				for(x in this.productArray){
					for(var i=0;i<this.productArray[x].length;i++){
						shipping = parseFloat(myXpathObj.selectNodes("//product[@id='"+this.productArray[x][i]["id"]+"']/@shippingcost")[0].text);
						if(ct!=x){
							cnt++;
							if(cnt>1){
								outHTML+="<tr height=\"10\" bgcolor=\"#ffffff\"><td colspan=\"7\"></td></tr>";
							}	
						}
						if(i%2==0){
							curRowcolor="#F0F0F0";
						}
						else{
							curRowcolor="#ffffff";
						}
						var ct=x;
						outHTML+="<tr bgcolor=\""+curRowcolor+"\"><td>"+this.productArray[x][i]["catname"]+"</td><td>"+this.productArray[x][i]["id"]+"</td><td>"+this.productArray[x][i]["prodname"]+"</td><td>"+this.currencySymbol(true)+parseFloat(this.productArray[x][i]["price"]).toFixed(2)+"</td><td><input id='"+this.productArray[x][i]["id"]+"' catid='"+x+"'  currency='"+this.currency+"' price='"+this.productArray[x][i]["price"]+"' type='text' onfocus='this.focus();this.select();' value='"+this.productArray[x][i]["quantity"]+"' style='width:60px;'/></td><td>"+this.currencySymbol(true)+parseFloat(shipping*this.productArray[x][i]["quantity"]).toFixed(2)+"</td><td>" + this.currencySymbol(true) + "<span>" + parseFloat(this.productArray[x][i]["total"]).toFixed(2)+"</span></td></tr>";					
					}
				}
					outHTML+="<tr bgcolor=\"#ffffff\"><td colspan=\"6\" style=\"border-width:0px;\" valign=\"top\" align=\"right\">Item total:<br/>Shipping and handling:<br/><strong>Total:</strong></td><td>"+ this.currencySymbol(true) + parseFloat(parseFloat(this.totalCartCost()).toFixed(2)-parseFloat(this.totalcostshipping).toFixed(2)).toFixed(2)+"<br/>"+ this.currencySymbol(true) + parseFloat(this.totalShippingCost()).toFixed(2)+"<br/><strong>"+ this.currencySymbol(true) + parseFloat(this.totalCartCost()).toFixed(2) +"</strong></td></tr>";
					outHTML+="<tr><td colspan=\"6\" style=\"border-width:0px;\"><input type=\"button\" onclick=myCart.emptyCar() value=\"Empty Cart\" style=\"color:#ff0000;font-family:arial;\"/> </td><td align=\"right\"> <input type=\"button\" style=\"color:#000000;font-family:arial;\" onclick=myCart.updateCart(\"shopping_cart_details\") value=\"Update Cart\"/></td></tr>";
					outHTML+="</table>";
					outHTML+="<br/><br/><table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"100%\"><tr><td><input type=\"button\" onclick=\"myCart.printProductsByCategory();myCart.setActiveCategory();\" value=\"Continue shopping\" style=\"color:#000000;font-family:arial;\"/></td><td align=\"right\"><input type=\"button\" onclick=\"myCart.paypalCheckout();\" value=\"Proceed to checkout\" style=\"color:#000000;font-family:arial;\"/></td></tr></table>";
					this.cartHTML=outHTML;
					document.getElementById("productPage").innerHTML=outHTML;
				}
		 }