var Spry;
if (!Spry) Spry = {};
if (!Spry.Widget) Spry.Widget = {};

Spry.Widget.CollapsiblePanel = function(element, opts)
{
	this.element = this.getElement(element);
	this.focusElement = null;
	this.hoverClass = "CollapsiblePanelTabHover";
	this.openClass = "CollapsiblePanelOpen";
	this.closedClass = "CollapsiblePanelClosed";
	this.focusedClass = "CollapsiblePanelFocused";
	this.enableAnimation = true;
	this.enableKeyboardNavigation = true;
	this.animator = null;
	this.hasFocus = false;
	this.contentIsOpen = true;

	this.openPanelKeyCode = Spry.Widget.CollapsiblePanel.KEY_DOWN;
	this.closePanelKeyCode = Spry.Widget.CollapsiblePanel.KEY_UP;

	Spry.Widget.CollapsiblePanel.setOptions(this, opts);

	this.attachBehaviors();
};

Spry.Widget.CollapsiblePanel.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

Spry.Widget.CollapsiblePanel.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.CollapsiblePanel.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

Spry.Widget.CollapsiblePanel.prototype.hasClassName = function(ele, className)
{
	if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)
		return false;
	return true;
};

Spry.Widget.CollapsiblePanel.prototype.setDisplay = function(ele, display)
{
	if( ele )
		ele.style.display = display;
};

Spry.Widget.CollapsiblePanel.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj)
	{
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

Spry.Widget.CollapsiblePanel.prototype.onTabMouseOver = function(e)
{
	this.addClassName(this.getTab(), this.hoverClass);
	return false;
};

Spry.Widget.CollapsiblePanel.prototype.onTabMouseOut = function(e)
{
	this.removeClassName(this.getTab(), this.hoverClass);
	return false;
};

Spry.Widget.CollapsiblePanel.prototype.open = function()
{
	this.contentIsOpen = true;
	if (this.enableAnimation)
	{
		if (this.animator)
			this.animator.stop();
		this.animator = new Spry.Widget.CollapsiblePanel.PanelAnimator(this, true, { duration: this.duration, fps: this.fps, transition: this.transition });
		this.animator.start();
	}
	else
		this.setDisplay(this.getContent(), "block");

	this.removeClassName(this.element, this.closedClass);
	this.addClassName(this.element, this.openClass);
};

Spry.Widget.CollapsiblePanel.prototype.close = function()
{
	this.contentIsOpen = false;
	if (this.enableAnimation)
	{
		if (this.animator)
			this.animator.stop();
		this.animator = new Spry.Widget.CollapsiblePanel.PanelAnimator(this, false, { duration: this.duration, fps: this.fps, transition: this.transition });
		this.animator.start();
	}
	else
		this.setDisplay(this.getContent(), "none");

	this.removeClassName(this.element, this.openClass);
	this.addClassName(this.element, this.closedClass);
};

Spry.Widget.CollapsiblePanel.prototype.onTabClick = function(e)
{
	if (this.isOpen())
		this.close();
	else
		this.open();

	this.focus();

	return this.stopPropagation(e);
};

Spry.Widget.CollapsiblePanel.prototype.onFocus = function(e)
{
	this.hasFocus = true;
	this.addClassName(this.element, this.focusedClass);
	return false;
};

Spry.Widget.CollapsiblePanel.prototype.onBlur = function(e)
{
	this.hasFocus = false;
	this.removeClassName(this.element, this.focusedClass);
	return false;
};

Spry.Widget.CollapsiblePanel.KEY_UP = 38;
Spry.Widget.CollapsiblePanel.KEY_DOWN = 40;

Spry.Widget.CollapsiblePanel.prototype.onKeyDown = function(e)
{
	var key = e.keyCode;
	if (!this.hasFocus || (key != this.openPanelKeyCode && key != this.closePanelKeyCode))
		return true;

	if (this.isOpen() && key == this.closePanelKeyCode)
		this.close();
	else if ( key == this.openPanelKeyCode)
		this.open();
	
	return this.stopPropagation(e);
};

Spry.Widget.CollapsiblePanel.prototype.stopPropagation = function(e)
{
	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	
	return false;
};

Spry.Widget.CollapsiblePanel.prototype.attachPanelHandlers = function() {
    var tab = this.getTab();
    if (!tab)
        return;

    var self = this;
    Spry.Widget.CollapsiblePanel.addEventListener(tab, "click", function(e) {  return self.onTabClick(e); }, false);
    Spry.Widget.CollapsiblePanel.addEventListener(tab, "mouseover", function(e) { return self.onTabMouseOver(e); }, false);
    Spry.Widget.CollapsiblePanel.addEventListener(tab, "mouseout", function(e) { return self.onTabMouseOut(e); }, false);

    if (this.enableKeyboardNavigation) {
        // XXX: IE doesn't allow the setting of tabindex dynamically. This means we can't
        // rely on adding the tabindex attribute if it is missing to enable keyboard navigation
        // by default.

        // Find the first element within the tab container that has a tabindex or the first
        // anchor tag.

        var tabIndexEle = null;
        var tabAnchorEle = null;

        this.preorderTraversal(tab, function(node) {
            if (node.nodeType == 1 /* NODE.ELEMENT_NODE */) {
                var tabIndexAttr = tab.attributes.getNamedItem("tabindex");
                if (tabIndexAttr) {
                    tabIndexEle = node;
                    return true;
                }
                if (!tabAnchorEle && node.nodeName.toLowerCase() == "a")
                    tabAnchorEle = node;
            }
            return false;
        });

        if (tabIndexEle)
            this.focusElement = tabIndexEle;
        else if (tabAnchorEle)
            this.focusElement = tabAnchorEle;

        if (this.focusElement) {
            Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement, "focus", function(e) { return self.onFocus(e); }, false);
            Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement, "blur", function(e) { return self.onBlur(e); }, false);
            Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement, "keydown", function(e) { return self.onKeyDown(e); }, false);
        }
    }
};

Spry.Widget.CollapsiblePanel.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler);
	}
	catch (e) {}
};

Spry.Widget.CollapsiblePanel.prototype.preorderTraversal = function(root, func)
{
	var stopTraversal = false;
	if (root)
	{
		stopTraversal = func(root);
		if (root.hasChildNodes())
		{
			var child = root.firstChild;
			while (!stopTraversal && child)
			{
				stopTraversal = this.preorderTraversal(child, func);
				try { child = child.nextSibling; } catch (e) { child = null; }
			}
		}
	}
	return stopTraversal;
};

Spry.Widget.CollapsiblePanel.prototype.attachBehaviors = function()
{
	var panel = this.element;
	var tab = this.getTab();
	var content = this.getContent();

	if (this.contentIsOpen || this.hasClassName(panel, this.openClass))
	{
		this.addClassName(panel, this.openClass);
		this.removeClassName(panel, this.closedClass);
		this.setDisplay(content, "block");
		this.contentIsOpen = true;
	}
	else
	{
		this.removeClassName(panel, this.openClass);
		this.addClassName(panel, this.closedClass);
		this.setDisplay(content, "none");
		this.contentIsOpen = false;
	}

	this.attachPanelHandlers();
};

Spry.Widget.CollapsiblePanel.prototype.getTab = function()
{
	return this.getElementChildren(this.element)[0];
};

Spry.Widget.CollapsiblePanel.prototype.getContent = function()
{
	return this.getElementChildren(this.element)[1];
};

Spry.Widget.CollapsiblePanel.prototype.isOpen = function()
{
	return this.contentIsOpen;
};

Spry.Widget.CollapsiblePanel.prototype.getElementChildren = function(element)
{
	var children = [];
	var child = element.firstChild;
	while (child)
	{
		if (child.nodeType == 1 /* Node.ELEMENT_NODE */)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

Spry.Widget.CollapsiblePanel.prototype.focus = function()
{
	if (this.focusElement && this.focusElement.focus)
		this.focusElement.focus();
};

/////////////////////////////////////////////////////

Spry.Widget.CollapsiblePanel.PanelAnimator = function(panel, doOpen, opts)
{
	this.timer = null;
	this.interval = 0;

	this.fps = 60;
	this.duration = 500;
	this.startTime = 0;

	this.transition = Spry.Widget.CollapsiblePanel.PanelAnimator.defaultTransition;

	this.onComplete = null;

	this.panel = panel;
	this.content = panel.getContent();
	this.doOpen = doOpen;

	Spry.Widget.CollapsiblePanel.setOptions(this, opts, true);

	this.interval = Math.floor(1000 / this.fps);

	var c = this.content;

	var curHeight = c.offsetHeight ? c.offsetHeight : 0;
	this.fromHeight = (doOpen && c.style.display == "none") ? 0 : curHeight;

	if (!doOpen)
		this.toHeight = 0;
	else
	{
		if (c.style.display == "none")
		{
			// The content area is not displayed so in order to calculate the extent
			// of the content inside it, we have to set its display to block.

			c.style.visibility = "hidden";
			c.style.display = "block";
		}

		// Clear the height property so we can calculate
		// the full height of the content we are going to show.

		c.style.height = "";
		this.toHeight = c.offsetHeight;
	}

	this.distance = this.toHeight - this.fromHeight;
	this.overflow = c.style.overflow;

	c.style.height = this.fromHeight + "px";
	c.style.visibility = "visible";
	c.style.overflow = "hidden";
	c.style.display = "block";
};

Spry.Widget.CollapsiblePanel.PanelAnimator.defaultTransition = function(time, begin, finish, duration) { time /= duration; return begin + ((2 - time) * time * finish); };

Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.start = function()
{
	var self = this;
	this.startTime = (new Date).getTime();
	this.timer = setTimeout(function() { self.stepAnimation(); }, this.interval);
};

Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stop = function()
{
	if (this.timer)
	{
		clearTimeout(this.timer);

		// If we're killing the timer, restore the overflow property.

		this.content.style.overflow = this.overflow;
	}

	this.timer = null;
};

Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stepAnimation = function() {
    ChangeDIVloacl(0);
	var curTime = (new Date).getTime();
	var elapsedTime = curTime - this.startTime;

	if (elapsedTime >= this.duration)
	{
		if (!this.doOpen)
			this.content.style.display = "none";
		this.content.style.overflow = this.overflow;
		this.content.style.height = this.toHeight + "px";
		if (this.onComplete)
		    this.onComplete();
		ChangeDIVloacl(1);
		return;
	}

	var ht = this.transition(elapsedTime, this.fromHeight, this.distance, this.duration);

	this.content.style.height = ((ht < 0) ? 0 : ht) + "px";

	var self = this;
	this.timer = setTimeout(function() { self.stepAnimation(); }, this.interval);
	ChangeDIVloacl(1);
};

Spry.Widget.CollapsiblePanelGroup = function(element, opts)
{
	this.element = this.getElement(element);
	this.opts = opts;

	this.attachBehaviors();
};

Spry.Widget.CollapsiblePanelGroup.prototype.setOptions = Spry.Widget.CollapsiblePanel.prototype.setOptions;
Spry.Widget.CollapsiblePanelGroup.prototype.getElement = Spry.Widget.CollapsiblePanel.prototype.getElement;
Spry.Widget.CollapsiblePanelGroup.prototype.getElementChildren = Spry.Widget.CollapsiblePanel.prototype.getElementChildren;

Spry.Widget.CollapsiblePanelGroup.prototype.setElementWidget = function(element, widget)
{
	if (!element || !widget)
		return;
	if (!element.spry)
		element.spry = new Object;
	element.spry.collapsiblePanel = widget;
};

Spry.Widget.CollapsiblePanelGroup.prototype.getElementWidget = function(element)
{
	return (element && element.spry && element.spry.collapsiblePanel) ? element.spry.collapsiblePanel : null;
};

Spry.Widget.CollapsiblePanelGroup.prototype.getPanels = function()
{
	if (!this.element)
		return [];
	return this.getElementChildren(this.element);
};

Spry.Widget.CollapsiblePanelGroup.prototype.getPanel = function(panelIndex)
{
	return this.getPanels()[panelIndex];
};

Spry.Widget.CollapsiblePanelGroup.prototype.attachBehaviors = function()
{
	if (!this.element)
		return;

	var cpanels = this.getPanels();
	var numCPanels = cpanels.length;
	for (var i = 0; i < numCPanels; i++)
	{
		var cpanel = cpanels[i];
		this.setElementWidget(cpanel, new Spry.Widget.CollapsiblePanel(cpanel, this.opts));
	}
};

Spry.Widget.CollapsiblePanelGroup.prototype.openPanel = function(panelIndex)
{
	var w = this.getElementWidget(this.getPanel(panelIndex));
	if (w && !w.isOpen())
		w.open();
};

Spry.Widget.CollapsiblePanelGroup.prototype.closePanel = function(panelIndex)
{
	var w = this.getElementWidget(this.getPanel(panelIndex));
	if (w && w.isOpen())
		w.close();
};

Spry.Widget.CollapsiblePanelGroup.prototype.openAllPanels = function()
{
	var cpanels = this.getPanels();
	var numCPanels = cpanels.length;
	for (var i = 0; i < numCPanels; i++)
	{
		var w = this.getElementWidget(cpanels[i]);
		if (w && !w.isOpen())
			w.open();
}
};

Spry.Widget.CollapsiblePanelGroup.prototype.closeAllPanels = function() {
    var cpanels = this.getPanels();
    var numCPanels = cpanels.length;
    for (var i = 0; i < numCPanels; i++) {
        var w = this.getElementWidget(cpanels[i]);
        if (w && w.isOpen())
            w.close();
    }

};

var DIVIsHidden = true;
function ChangeDIVloacl(index) {
    
    if ($('searchShopInput') != null && $('searchShopInput') != undefined) {
        if (index == 0 && $("AjaxAutoCompleteDIV").style.display == '') {
            $("AjaxAutoCompleteDIV").style.display = 'none';
            DIVIsHidden = false;
        }
        else if (index = 1 && !DIVIsHidden) {
            showdiv_showAuto($("AjaxAutoCompleteDIV"), $('searchShopInput'));
            $("AjaxAutoCompleteDIV").style.display = '';
            DIVIsHidden = true;
        }
    }
}

//页面加载时判断cookie中是否有已选商品
function GetShopInfo()
{

  
    
        
    var xml = '';
    try
    {
        xml = getCookie("shopinfo"); 
    }
    catch(e)
    {
        alert(e.message);
    }
    
//    var _OrderType=getCookie("OrderType");
//    var oneset="1";
//    if(xml != '<NewDataSet />')//如果购物车中有已选商品
//    {
//    
//         var _xml=xml.responseXML;
//        var _Equipmentlist = _xml.getElementsByTagName("Table");
//        var _length = _Equipmentlist.length;
//        
//        for(var i = 0; i < _length; i++) {
//        
//             var order_Type = _Equipmentlist[i].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
//             
//             if(order_Type!=_OrderType)
//             {
//                oneset="0";
//             }
//        }
//        
//    }
    
    
    
    
    
    if(xml != '<NewDataSet />')//如果购物车中有已选商品
    {
        
        url = "ashx/getShopInfoById.ashx";
        
        try
        {
            var myAjax = new Ajax.Request(   
                                            url,   
                                            {
                                                method: "post", 
                                                postBody: xml, 
                                                onComplete: ShowShopInfo
                                            }   
                                        ); 
       }
       catch(err)
       {
            alert(err.description);
       }
    }
    else//如果购物车无已选商品
    {
        $('MyCart').innerHTML = "<div style='cursor: pointer;' class='CollapsiblePanelTab' tabindex='0'><a  class='shoptitle'>Shopping " + 
        "Cart</a></div><div id='MyCart3' class='shopno'><img src='images/cart.png' width='20' height='13'/>THERE IS NOTHING IN YOUR SHOPPING TROLLEY ATM</div>";
        var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel('MyCart');
    }    
}
//将所选商品信息显示到页面
function ShowShopInfo(xmlhttp)
{
    if(xmlhttp.responseText != '<NewDataSet />')//如果购物车中有已选商品
    {
        var xml = xmlhttp.responseXML;
        var Equipmentlist = xml.getElementsByTagName("Table");
        var length = Equipmentlist.length;
       
        var _OrderType=getCookie("OrderType");
        var _gameid = getCookie("gtype");
        var _gameids = getCookie("gtypes");
        for(var x = 0; x < length; x++) {
        
             var order_Type = Equipmentlist[x].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
             
             if(order_Type!=_OrderType && _gameid!=getCookie("gameId"))
             {
                setCookie("shopinfo","<NewDataSet />",2);
                return;
            }

            if (order_Type != _OrderType && _gameids != getCookie("gameId")) {
                setCookie("shopinfo", "<NewDataSet />", 2);
                return;
            }
        }
        
       
       
        var div = $('MyCart');
        str = "<div style='cursor: pointer;' class='CollapsiblePanelTab' tabindex='0'><a class='shoptitle'>Shopping " + 
        "Cart</a></div><div id='MyCart1'><div class='shopno01'><span class='shopwidth01'>Name</span> <span class='shopwidth02'>Lv or Ap</span>" + "<span class='shopwidth02'>Picture</span> <span class='shopwidth02'>Price</span> <span class='shopwidth02'>Delivery</span>" + "<span class='shopwidth02'>Quantity</span> <span class='shopwidth02'></span></div><div class='shopno02'>";
        
        

        
        
        for(var i = 0; i < length; i++) {
            orderType = Equipmentlist[i].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
            imgurl = '';
            id = Equipmentlist[i].getElementsByTagName("pid")[0].childNodes[0].nodeValue;
            productName = Equipmentlist[i].getElementsByTagName("pname")[0].childNodes[0].nodeValue;
            lv = '';
            try {
                lv = Equipmentlist[i].getElementsByTagName("pLevel")[0].childNodes[0].nodeValue;
                
                if(orderType=='EDENITEM')
                {
                    lv=Equipmentlist[i].getElementsByTagName("productstock")[0].childNodes[0].nodeValue;
                }
                
                
            } catch (e) { }
            try
            {
                 if(orderType=='PVP')
                {
                   imgurl=""; 
                }
                else{
                    imgurl = Equipmentlist[i].getElementsByTagName("purl")[0].childNodes[0].nodeValue;
                    imgurl = imgurl.replace('~/','');
                
                }
                
                if(orderType=='RIFTITEM')
                {
                    imgurl="riftimg/"+imgurl;
                }
                
                if(orderType=='EDENITEM')
                {
                    imgurl="edenimg/"+imgurl;
                }
                
            }catch(e)
            {}
            number  = getShopNumberById(id);
            //ptid = Equipmentlist[i].getElementsByTagName("ptid")[0].childNodes[0].nodeValue;
            sid = Equipmentlist[i].getElementsByTagName("sid")[0].childNodes[0].nodeValue;
            productPrice = 0;
            productDelivery = 0;
            pbeizhu = '';
            try
            {
                productPrice = Equipmentlist[i].getElementsByTagName("productPrice")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                productPrice = 0;
            }
            try
            {
                productDelivery = Equipmentlist[i].getElementsByTagName("productDelivery")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                productDelivery = 0;
            }
            try
            {
                pbeizhu = Equipmentlist[i].getElementsByTagName("pbeizhu")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                pbeizhu = '';
            }
            if(i % 2 != 0)
            {
                str += "<div id='items" + id + "' class='shopno03'>";
            }
            else
            {
                str += "<div id='items" + id + "' class='shopno04'>";
            }            
            str += "<input type='hidden' id='productPrice" + id + "' value='" + productPrice + "' />";
            //str += "<span id='productName" + id + "' class='shopname'>" + productName + " X " + sid + "</span> <span id='lv" + id + "' class='shopmunber01'>";
           
            if(orderType == "EDENITEM")
            {
                str += "<span id='productName" + id + "' class='shopname'>" + productName + "</span> <span id='lv" + id + "' class='shopmunber01'>";
            }
            else
            {
                str += "<span id='productName" + id + "' class='shopname'>" + productName + " X " + sid + "</span> <span id='lv" + id + "' class='shopmunber01'>";
            }
            
            if(orderType == "EDENITEM")
            {
                  str += lv + " <img id='imgs" + id + "' src=\"images/yxb.png\" width='11px' height='11px' /></span>";
            }
            else
            {
                  //str += "<td align='center' class='ac2'>" + lv + "</td>";
                   str += lv + "</span>";
            }
            
            
            str += "<span class='shopprictrue'>";
            if (orderType == "EUITEM" || orderType == "ITEM" || orderType == "RAID") {
                str += "<input type='hidden' id='Spbeizhu" + id + "' value='" + pbeizhu + "' />";
                str += "<img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "' src='" + imgurl + "' width='31' height='28' /></span> <span class='shopmunber01'>" + getMoneyType() + changeRate(productPrice) + "</span>";
            }
            
            
            else if (orderType == "RIFTITEM") {
                 str += "<input type='hidden' id='Spbeizhu" + id + "' value='" + pbeizhu.replace("'","").replace(">\'",">").replace("\'<","<") + "' />";
                str += "<img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "'  src=\"" + imgurl + "\" width='31' height='28' /></span> <span class='shopmunber01'>" + getMoneyType() + changeRate(productPrice) + "</span>";
            }
            
            else if (orderType == "EDENITEM") {
                str += "<img id='img" + id + "'  src=\"" + imgurl + "\" width='31' height='28' /></span> <span class='shopmunber01'>" + getMoneyType() + changeRate(productPrice) + "</span>";
            }

            else if (orderType == "DRAGONNESTITEM") {
                str += "<img id='img" + id + "' src='" + imgurl + "' width='31' height='28' /></span> <span class='shopmunber01'>" + getMoneyType() + changeRate(productPrice) + "</span>";
            }
            
            else {
                 str += "<input type='hidden' id='Spbeizhu" + id + "' value='" + pbeizhu + "' />";
                str += "<img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "' src='" + imgurl + "' width='31' height='28' /></span> <span class='shopmunber01'>" + getMoneyType() + changeRate(productPrice) + "</span>";
            }
//<input id='number" + id + " class='munber' value='"+ number +"'/>
            if (orderType == "EUITEM" || orderType == "ITEM" || orderType == "RIFTITEM" || orderType == "EDENITEM" || orderType == "DRAGONNESTITEM") {
                str += "<span id='productDelivery" + id + "' class='shopmunber02'>&lt; " + productDelivery + " Hr</span><span class='shopmunber03'><span class='munberpure'>";
                //str += "<img onclick=\"javascript:minishNumber('number" + id + "');\" src='images/Minus.png' /></span> <span id='number" + id + "' class='munber'>" + number + "</span> <span class='munberpure'>";
                str += "</span><input id='number" + id + "' value='"+ number +"' style='width:40px;height:12px' onkeypress=\"onlyNumber(event);\" onmouseout=\"allnumber('number" + id + "');\" onblur=\"allnumber('number" + id + "');\"  onchange=\"allnumber('number" + id + "');\" /><span class='munberpure'>";
                str += "</span></span><span class='shopmunber01'>";
            }
            
            
            else if (orderType == "RIFTITEM") {
                str += "<span id='productDelivery" + id + "' class='shopmunber02'>&lt; " + productDelivery + " Hr</span><span class='shopmunber03'><span class='munberpure'>";
                //str += "<img onclick=\"javascript:minishNumber('number" + id + "');\" src='images/Minus.png' /></span> <span id='number" + id + "' class='munber'>" + number + "</span> <span class='munberpure'>";
                str += "</span><input id='number" + id + "'  value='"+ number +"' style='width:40px;height:12px' onkeypress=\"onlyNumber(event);\" onmouseout=\"allnumber('number" + id + "');\" onblur=\"allnumber('number" + id + "');\"  onchange=\"allnumber('number" + id + "');\" /><span class='munberpure'>";
                str += "</span></span><span class='shopmunber01'>";
            }
            
            else {
                str += "<span id='productDelivery" + id + "' class='shopmunber02'>&lt; " + productDelivery + " DAY</span><span class='shopmunber03'><span class='munberpure'>";
                str += "</span> <span id='number" + id + "' class='munber'>" + number + "</span> <span class='munberpure'>";
                str += "</span> </span><span class='shopmunber01'>";
            }
            str += "<img onclick=\"javascript:deleteProduct('" + id + "','"+orderType+"');\" src='images/blackcartby.png' border='0' /></span>";           
            str += "</div>";
        }
        str += "</div><div id='MyCart2' class='shopno05'><span class='shopwidth03'><img src='images/cart.png' width='20' height='13'/>Total: <span id='rate' " + 
        "class='test07'>" + getMoneyType() + "</span><span id='Total' class='test07'></span></span><span class='shopwidth04'><img id='checkoutId' src='images/checkout.jpg'" + 
        " style='cursor: pointer;' border='0' onclick='window.location=\"checkbuy.html\"' /><img id='checkoutId2' src='images/ckck2.jpg' style='cursor:pointer;display:none;' border='0'/><img id='checkoutId3' src='images/clear.jpg' style='cursor:pointer;' border='0' onclick='csCollapsiblePanelTab1();'/></span></div></div>";        
        div.innerHTML = str;        
        TotalAccount();        
    }
    else//如果购物车无已选商品
    {
        $('MyCart').innerHTML = "<div style='cursor: pointer;' class='CollapsiblePanelTab' tabindex='0'><a class='shoptitle'>Shopping " + 
        "Cart</a></div><div id='MyCart3' class='shopno'><img src='images/cart.png' width='20' height='13' />THERE IS NOTHING IN YOUR SHOPPING TROLLEY ATM</div>";
    }
    var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel('MyCart');
    
}

function getShopNumberById(id)
{
    xml = getCookie("shopinfo");    
    xmlDoc = getXmldoc(xml);
    for(var i = 0; i < xmlDoc.getElementsByTagName("Table").length; i++)
    {
        if(xmlDoc.getElementsByTagName("Table")[i].getElementsByTagName("pid")[0].childNodes[0].nodeValue == id)
        {
            return xmlDoc.getElementsByTagName("Table")[i].getElementsByTagName("number")[0].childNodes[0].nodeValue;
        }
    }
}


//页面加载时判断cookie中是否有已选商品
function GetShopInfo_new()
{
    var xml = '';
    try
    {
        xml = getCookie("shopinfo"); 
    }
    catch(e)
    {
        alert(e.message);
    }
    
    
//    var _OrderType=getCookie("OrderType");
//    var oneset="1";
//    if(xml != '<NewDataSet />')//如果购物车中有已选商品
//    {
//    
//        var _xml=xml.responseXML;
//        var _Equipmentlist = _xml.getElementsByTagName("Table");
//        var _length = _Equipmentlist.length;
//        
//        for(var i = 0; i < _length; i++) {
//        
//             var order_Type = _Equipmentlist[i].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
//             
//             if(order_Type!=_OrderType)
//             {
//                oneset="0";
//             }
//        }
//        
//    }
    
    
    if(xml != '<NewDataSet />')//如果购物车中有已选商品
    {
        var url="";
     
        url = "ashx/getShopInfoById.ashx";
         
       
        try
        {
            var myAjax = new Ajax.Request(   
                                            url,   
                                            {
                                                method: "post", 
                                                postBody: xml, 
                                                onComplete: ShowShopInfo_new
                                            }   
                                        ); 
       }
       catch(err)
       {
            alert(err.description);
       }
    }
    else//如果购物车无已选商品
    {
        $('MyCart').innerHTML = "<DIV style='cursor:pointer;' class='CollapsiblePanelTab1'><a class='shoptitle'>Shopping Cart</a></DIV><DIV class='shopno1'><img src='images/cart.png' width='20px' height='13px' /> THERE IS NOTHING IN YOUR SHOPPING TROLLEY ATM</DIV><DIV class='shopno1'></DIV></DIV>";
        var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel('MyCart');
    }    
 
}
//将所选商品信息显示到页面
function ShowShopInfo_new(xmlhttp)
{
    if(xmlhttp.responseText != '<NewDataSet />')//如果购物车中有已选商品
    {
        var xml = xmlhttp.responseXML;
        var Equipmentlist = xml.getElementsByTagName("Table");
        var length = Equipmentlist.length;
       
       
        var _OrderType=getCookie("OrderType");
        var _gameid = getCookie("gtype");
        var _gameids = getCookie("gtypes");
        for(var x = 0; x < length; x++) {
        
             var order_Type = Equipmentlist[x].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
             var Game_Id = Equipmentlist[x].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
             if(order_Type!=_OrderType && _gameid!=getCookie("gameId"))
             {
                setCookie("shopinfo","<NewDataSet />",2);
                return;
            }

            if (order_Type != _OrderType && _gameids != getCookie("gameId")) {
                setCookie("shopinfo", "<NewDataSet />", 2);
                return;
            }


        }
       
       
        var div = $('MyCart');
       

        str = "<DIV style='cursor:pointer;' class='CollapsiblePanelTab1'><a class='shoptitle'>Shopping Cart</a></DIV><DIV class='shopno1'><table width='100%' border='0' cellspacing='0' cellpadding='0' class='tablebb'><tr class='tablebb1 tablebrn'><td height='25' align='center'>Name</td><td align='center'>Lv or Ap</td><td align='center'>Picture</td><td align='center'>Price</td><td align='center'>Delivery</td><td align='center'>Quantity</td><td id='aaaa'>&nbsp;</td></tr>";
        
        
        
        for(var i = 0; i < length; i++) {
            imgurl = '';
            orderType = Equipmentlist[i].getElementsByTagName("OrderType")[0].childNodes[0].nodeValue;
            id = Equipmentlist[i].getElementsByTagName("pid")[0].childNodes[0].nodeValue;
            productName = Equipmentlist[i].getElementsByTagName("pname")[0].childNodes[0].nodeValue;
            lv = '';
            try {
                lv = Equipmentlist[i].getElementsByTagName("pLevel")[0].childNodes[0].nodeValue;
                
                if(orderType=='EDENITEM')
                {
                    lv=Equipmentlist[i].getElementsByTagName("productstock")[0].childNodes[0].nodeValue;
                }
                
            } catch (e) { }
            try
            {
                if(orderType=='PVP')
                {
                   imgurl=""; 
                }
                else{
                    imgurl = Equipmentlist[i].getElementsByTagName("purl")[0].childNodes[0].nodeValue;
                    imgurl = imgurl.replace('~/','');
                
                }
                if(orderType=='RIFTITEM')
                {
                    imgurl="riftimg/"+imgurl;
                }
                
                if(orderType=='EDENITEM')
                {
                    imgurl="edenimg/"+imgurl;
                }
                
            }
            catch(e){}
            number  = getShopNumberById(id);
            ptid = "";
            sid = Equipmentlist[i].getElementsByTagName("sid")[0].childNodes[0].nodeValue;
            productPrice = 0;
            productDelivery = 0;
            pbeizhu = '';
            try {
                ptid = Equipmentlist[i].getElementsByTagName("ptid")[0].childNodes[0].nodeValue;
            }
            catch (e)
            { }
            try
            {
                productPrice = Equipmentlist[i].getElementsByTagName("productPrice")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                productPrice = 0;
            }
            try
            {
                productDelivery = Equipmentlist[i].getElementsByTagName("productDelivery")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                productDelivery = 0;
            }
            try
            {
                pbeizhu = Equipmentlist[i].getElementsByTagName("pbeizhu")[0].childNodes[0].nodeValue;
            }
            catch(e)
            {
                pbeizhu = '';
            }
            if(i % 2 != 0)
            {
                str += "<tr bgcolor='#bdbdbd' class='tablebb1 tablebrn' id='items" + id + "'><td height='40' bgcolor='#bdbdbd' class='pl10 fwb ac1'>";
            }
            else
            {
                str += "<tr bgcolor='#9c9c9c' class='tablebb1 tablebrn' id='items" + id + "'><td height='40' bgcolor='#9c9c9c' class='pl10 fwb ac1'>";
            }          
            //str += "<input type='hidden' id='productPrice" + id + "' value='" + productPrice + "' />" + productName + " X " + sid+ "</td>"; 
            
            
            if(orderType == "EDENITEM")
            {
                  str += "<input type='hidden' id='productPrice" + id + "' value='" + productPrice + "' />" + productName + "</td>"; 
            }
            else
            {
                 str += "<input type='hidden' id='productPrice" + id + "' value='" + productPrice + "' />" + productName + " X " + sid+ "</td>"; 
            }
            
            
            
            if(orderType == "EDENITEM")
            {
                  str += "<td align='center' class='ac2'>" + lv + " <img id='imgs" + id + "' src=\"images/yxb.png\" width='11px' height='11px' /></td>";
            }
            else
            {
                  str += "<td align='center' class='ac2'>" + lv + "</td>";
            }


              if (orderType == "EUITEM" || orderType == "ITEM" || orderType == "RAID") {
                str += "<td align='center'><img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' width='31' height='28' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "' src='" + imgurl + "' /></td>";
            } 
            
            else  if (orderType == "RIFTITEM") {
               
                str += "<td align='center'><img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' width='31' height='28' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "' src=\"" + imgurl + "\" /></td>";
            } 
            
            else if (orderType == "EDENITEM") {

            str += "<td align='center'><img id='img" + id + "' src=\"" + imgurl + "\" width='31' height='28' /></td>";
            }

            else if (orderType == "DRAGONNESTITEM") {

            str += "<td align='center'><img id='img" + id + "' src=\"" + imgurl + "\" width='31' height='28' /></td>";
            } 
            
            
            else {
            str += "<td align='center'><img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' width='31' height='28' onmouseout='$(\"showShopReamark\").style.display=\"none\";' width='31' height='28' id='img" + id + "' src='" + imgurl + "' /></td>";
            }
            
            
//             if (orderType == "RIFTITEM") {
//                str += "<td align='center'><img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showShopReamark\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' width='31' height='28' onmouseout='$(\"showShopReamark\").style.display=\"none\";' id='img" + id + "' src='" + imgurl + "' /></td>";
//            } 
//            
//            else {
//            str += "<td align='center'><img onmouseover='$(\"showShopReamark\").style.display=\"\";$(\"showBeiZhu\").innerHTML=$F(\"Spbeizhu" + id + "\");showdiv($(\"showShopReamark\"),this);' width='31' height='28' onmouseout='$(\"showShopReamark\").style.display=\"none\";' width='31' height='28' id='img" + id + "' src='" + imgurl + "' /></td>";
//            }
            
            str += "<td align='center' class='ac2'><input type='hidden' id='Spbeizhu" + id + "' value='" + pbeizhu.replace("'","").replace(">\'",">").replace("\'<","<") + "' />" + getMoneyType() + changeRate(productPrice) + "</td>";
            if (orderType == "EUITEM" || orderType == "ITEM" || orderType == "RIFTITEM" || orderType == "EDENITEM") {
                str += "<td align='center' class='ac1'>&lt; " + productDelivery + " Hr</td>";
            } else {
                str += "<td align='center' class='ac1'>&lt; " + productDelivery + " DAY</td>";
            }

// if (orderType == "ITEM") {
//                str += "<td align='center' class='ac3'><img onclick=\"javascript:minishNumber('number" + id + "');\" src='images/Minus.png' /><span style='width:20px' id='number" + id + "'>" + number + "</span><img onclick=\"javascript:addnumber('number" + id + "');\" src='images/Plus.png' /></td>";
//            }

            if (orderType == "EUITEM" || orderType == "ITEM") {
                str += "<td align='center' class='ac3' ><input id='number" + id + "' value='"+ number +"' style='width:40px;height:12px;' onkeypress=\"onlyNumber(event);\" onkeyup=\"allnumber('number" + id + "');\" /></td>";
            }
            
            else if (orderType == "RIFTITEM") {
                str += "<td align='center' class='ac3'><input id='number" + id + "'  value='"+ number +"' style='width:40px;height:12px;' onkeypress=\"onlyNumber(event);\" onkeyup=\"allnumber('number" + id + "');\" /></td>";
            }
            
            else if (orderType == "EDENITEM") {
                str += "<td align='center' class='ac3'><input id='number" + id + "'  value='"+ number +"' style='width:40px;height:12px;' onkeypress=\"onlyNumber(event);\"  onkeyup=\"allnumber('number" + id + "');\"/></td>";
            }
            else if (orderType == "DRAGONNESTITEM") {
                str += "<td align='center' class='ac3'><input id='number" + id + "'  value='" + number + "' style='width:40px;height:12px;' onkeypress=\"onlyNumber(event);\"  onkeyup=\"allnumber('number" + id + "');\"/></td>";
            }
            else {
                str += "<td align='center' class='ac3'><span style='width:20px' id='number" + id + "'>" + number + "</span></td>";
            }


            str += "<td align='center' id='aaaa' class='ac2'><a style='cursor:pointer;' onclick=\"javascript:deleteProduct('" + id + "','" + orderType + "')\";>Delete</a></td>";         
            str += "</tr>";
        }
        str += "<tr><td height='30' colspan='7'><span class='shopwidth03'><img src='images/cart.png' width='20' height='13' /> Total: <span class='test07'>" + getMoneyType() + "</span><span id='Total' class='test07'></span></span><span class='shopwidth04'><img id='checkoutId' src='images/checkout.jpg' style='cursor:pointer;' border='0' onclick='window.location=\"checkbuy.html\"' /><img id='checkoutId2' src='images/ckck2.jpg' style='cursor:pointer;display:none;' border='0'/> <img id='checkoutId3' src='images/clear.jpg' style='cursor:pointer;' border='0' onclick='csCollapsiblePanelTab1();'/></span></td></tr></table></DIV>";
        div.innerHTML = str;        
        TotalAccount();        
    }
    else//如果购物车无已选商品
    {
        $('MyCart').innerHTML = "<DIV style='cursor:pointer;' class='CollapsiblePanelTab1'><a class='shoptitle'>Shopping Cart</a></DIV><DIV class='shopno1'><img src='images/cart.png' width='20px' height='13px' /> THERE IS NOTHING IN YOUR SHOPPING TROLLEY ATM</DIV><DIV class='shopno1'></DIV></DIV>";
    }
    
    var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel('MyCart');
    
}




function csCollapsiblePanelTab1()
{
//Are you sure to empty your shopping kart ?
    if(confirm('Are you sure to empty your shopping kart ?'))
    {
        $('MyCart').style.display="none";
        setCookie("shopinfo","<NewDataSet />",-1);
        var html=this.location.href;
        
        var arr_html=html.split("#");
        
        var html_url="";
        
        if(arr_html.length>1)
        {
            html_url=arr_html[0];
        }
        else
        {
            html_url=html;
        }
        
        window.location.href=html_url;
    }
    else
    {
        return;
    }
}
