﻿function $id(id) {
            return document.getElementById(id);
        };

function Save(imageURL, productID, prdouctName, price) {

    if (imageURL != null && imageURL != '') {

        if (GetCookie('ViewImageURL') != null) {
            var ar = GetCookie('ViewImageURL').split('#')
            var cook = '';

            for (var i = ar.length - 1; i >= 0; i--) {
                if (ar[i] != imageURL) {
                    if (cook != '') {
                        cook = ar[i] + '#' + cook;
                    }
                    else {
                        cook = ar[i];
                    }
                }
            }
            if (cook != "")
                imageURL += '#' + cook
        }

        var arrimageURL = imageURL.split('#')

        if (arrimageURL.length > 5) {

            imageURL = arrimageURL[4];
            for (var i = 3; i >= 0; i--) {
                imageURL = arrimageURL[i] + '#' + imageURL;
            }
        }

        SetCookie('ViewImageURL', imageURL)
    }




    if (productID != null && productID != '') {

        if (GetCookie('ViewProductID') != null) {
            var arp = GetCookie('ViewProductID').split('#')
            var cookp = '';

            for (var i = arp.length - 1; i >= 0; i--) {
                if (arp[i] != productID)
                    if (cookp != '') {
                    cookp = arp[i] + '#' + cookp;
                }
                else {
                    cookp = arp[i]
                }
            }
            if (cookp != "")
                productID += '#' + cookp
        }


        var arrproductID = productID.split('#')

        if (arrproductID.length > 5) {



            productID = arrproductID[4];
            for (var i = 3; i >= 0; i--) {
                productID = arrproductID[i] + '#' + productID;
            }
        }

        SetCookie('ViewProductID', productID)
    }


    if (prdouctName != null && prdouctName != '') {

        if (GetCookie('ViewPrdouctName') != null) {
            var arn = GetCookie('ViewPrdouctName').split('#')
            var cookn = arn[arn.length - 1];

            for (var i = arn.length - 2; i >= 0; i--) {
                if (arn[i] != prdouctName)
                    if (cookn != '') {
                    cookn = arn[i] + '#' + cookn;
                }
                else {
                    cookn = arn[i]
                }
            }
            if (cookn != "")
                prdouctName += '#' + cookn
        }
        var arrprdouctName = prdouctName.split('#')

        if (arrprdouctName.length > 5) {

            prdouctName = arrprdouctName[4];
            for (var i = 3; i >= 0; i--) {
                prdouctName = arrprdouctName[i] + '#' + prdouctName;
            }
        }

        SetCookie('ViewPrdouctName', prdouctName)
    }

    if (price != null && price != '') {

        if (GetCookie('ViewPrice') != null) {
            var arn = GetCookie('ViewPrice').split('#')
            var cookn = arn[arn.length - 1];

            for (var i = arn.length - 2; i >= 0; i--) {
                if (arn[i] != price)
                    if (cookn != '') {
                    cookn = arn[i] + '#' + cookn;
                }
                else {
                    cookn = arn[i]
                }
            }
            if (cookn != "")
                price += '#' + cookn
        }
        var arrprdouctName = price.split('#')

        if (arrprdouctName.length > 5) {

            price = arrprdouctName[4];
            for (var i = 3; i >= 0; i--) {
                price = arrprdouctName[i] + '#' + price;
            }
        }

        SetCookie('ViewPrice', price)
    }


    //  AutoCreatTable()

    return false

}
function AutoCreatTable() {

    var span = document.getElementById("histRec");


    var childs = span.childNodes;
    for (var i = childs.length - 1; i >= 0; i--) {
        span.removeChild(childs[i]);
    }

    //创建一个table对象
    var vTable = document.createElement("TABLE");
    //设置table的属性
    vTable.setAttribute("CELLPADDING", "0");
    vTable.setAttribute("CELLSPACING", "0");
    vTable.setAttribute("BORDER", "2");

    //插入一行
    //vTrt=vTable.insertRow();

    //插入一列
    //vTdt=vTrt.insertCell();
    //vTdt.innerHTML='<span id="dd">最近访问商品</span>';
    span.appendChild(vTable);

    if (GetCookie('ViewImageURL') == null || GetCookie('ViewProductID') == null || GetCookie('ViewPrdouctName') == null) {

        return;
    }
    var arrimageURL = GetCookie('ViewImageURL').split('#');

    var arrproductID = GetCookie('ViewProductID').split('#');
    var arrprdouctName = GetCookie('ViewPrdouctName').split('#');
    var arrPrice = GetCookie("ViewPrice").split('#');
    var listHTML = "<table width='180px'>";
    var count = arrproductID.length > 5 ? 5 : arrproductID.length;
    for (var i = 0; i < count; i++) {
        listHTML += "<tr><td rowspan='2'>";
        listHTML+="<a href='product-"+arrproductID[i]+".html' target='_blank'>";
        listHTML += "<img title="+arrprdouctName[i]+" height='50' onerror=\"this.src='images/none_100.gif'\" src='"+arrimageURL[i]+"' width='50' border='0'></a>";
        listHTML += "</td><td align='left'><a id='6' href='product-"+arrproductID[i]+".html' target='_blank'>";
        listHTML += arrprdouctName[i]+"</a></td></tr><tr><td align='left'><font class='proprice'>￥"+arrPrice[i]+"</font>";
        listHTML += "</td></tr>";
        if(i!=arrproductID.length-1)
            listHTML += "<tr><td colspan='2' valign='top'><div class='divLinePTW'>&nbsp;</div></td></tr>";
    }
    listHTML += "</table>";
    span.innerHTML = listHTML;
}
function XmlPost(webFileUrl) {
    var result = "";
    var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    xmlHttp.open("POST", webFileUrl, false);
    xmlHttp.send(null);
    result = xmlHttp.responseText;
    return (result);
}
function CPos(x, y) {
    this.x = x;
    this.y = y;
}
function addFavorites(proid, thisY) {
    var userid = GetCookie('www.uke92.com'); 
    if (userid == "" || userid == null) {
        location.href = "http://member." + domainhost + "/memberlogin.aspx?PageBack=" + location.href; ;
    }
    else {
        var url = "addFavorites.aspx?userid=" + userid.split('#')[0] + "&proid=" + proid; 
        XmlPost(url)
        var target = thisY;
        var pos = new CPos(target.offsetLeft, target.offsetTop);
        var target = target.offsetParent;
        while (target) {
            pos.x += target.offsetLeft;
            pos.y += target.offsetTop;
            target = target.offsetParent
        }
        var msg = "<div id='info' style='background: #ffffff;width: 300px; height: 120px; border: 1px; border-color: #93bede; border-style: solid;'>";
        msg += "<div style='background: #dff2fd; width: 300px; height: 30px;'>"
        msg += "<table width='100%'><tr><td style='height: 30px'><img src='http://member." + domainhost + "/images/icon-cart-1.gif' />成功添加到收藏夹";
        msg += "</td><td valign='top' align='right'>";
        msg += "<img src='http://member." + domainhost + "/images/icon-2.gif' onclick=\" document.all.ISShow.style.display='none'\" style='cursor: pointer' />";
        msg += "</td></tr></table></div><table width='100%'><tr><td style='height: 40px' align='center'>";
        msg += "已成功添加到收藏夹!";
        msg += "</td></tr><tr><td align='center'><img src='images/favorites.gif' onclick=' location.href=\"http://member." + domainhost + "/favorites.aspx\"' style='cursor: pointer' />";
        msg += "&nbsp;&nbsp;&nbsp;<img src='http://member." + domainhost + "/images/icon-cart-4.gif' onclick=\" document.all.ISShow.style.display='none'\" style='cursor: pointer' /></td></tr></table></div>";
        document.all("sortDisplay").innerHTML = msg;
        document.all("sortDisplay").style.left = pos.x - 200,
	    document.all("sortDisplay").style.top = pos.y - 160;
        document.all("ISShow").style.display = "";
    }
}

function Switch(thisC) {
    if (thisC == "a") {
        document.getElementById("basic").style.display = "";
        document.getElementById("divbasic").style.background = "url(images/kapian-1.gif)";
        document.getElementById("details").style.display = "none";
        document.getElementById("divdetails").style.background = "url(images/kapian-2.gif)";
    }
    else {
        document.getElementById("basic").style.display = "none";
        document.getElementById("divbasic").style.background = "url(images/kapian-2.gif)";
        document.getElementById("details").style.display = "";
        document.getElementById("divdetails").style.background = "url(images/kapian-1.gif)";
    }
}