function AddCarByID(productID, comID, quantity, price, points, pointsDeductible, myCallBack) {
    var result;
    var postData = "{productID:'" + productID + "',comID:'" + comID + "',quantity: '" + quantity + "', price: '" + price + "', points: '" + points + "', pointsDeductible: '" + pointsDeductible + "'}";
    var url = WebSite + "Services/WebService.asmx/AddProductIntoCar";
    $.ajax({
        url: url,
        type: "POST",
        data: postData,
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function (data) {
            if (typeof CarData != 'undefined')
                CarData = data.d;
            if (typeof myCallBack != 'undefined')
                myCallBack(data.d);
            if (typeof CarChanged != 'undefined')
                CarChanged();
        },
        error: function (f) {
        }
    });
}

function DeleteOrderProductSubmit(orderDetailID, myCallBack) {
    var postData = "{orderDetailID: '" + orderDetailID + "'}";
    var url = WebSite + "Services/WebService.asmx/DeleteOrderProductSubmit";
    $.ajax({
        url: url,
        type: "POST",
        data: postData,
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function (data) {
            CarData = data.d;
            myCallBack(data.d);
            CarChanged();
        },
        error: function (f) {
        }
    });
}

function ChangeQuantitySubmit(quantityNum, price, orderDetailID, points, pointsDeductible, myCallBack) {

    var postData = "{quantityNum:'" + quantityNum + "',price: '" + price + "', orderDetailID: '" + orderDetailID + "', points: '" + points + "', pointsDeductible: '" + pointsDeductible + "'}";
    var url = WebSite + "Services/WebService.asmx/ChangeQuantitySubmit";
    $.ajax({
        url: url,
        type: "POST",
        data: postData,
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function (data) {
            CarData = data.d;
            myCallBack(data.d);
            CarChanged();
        },
        error: function (f) {
        }
    });
    return false;
}

//取得上级网页地址
function GetPageReferX() {
    var tempReferrer = "";
    var tempNow = new Date();
    var tempDate = new Date();
    tempDate.setDate(tempDate.getDate() + 30);
    try {
        tempReferrer = SetPageDataX(document.referrer, tempReferrer);
        tempReferrer = SetPageDataX(top.document.referrer, tempReferrer);
        tempReferrer = SetPageDataX(window.parent.document.referrer, tempReferrer);
    } catch (e) {
    }
    if (GetCookie("SaveSourceTime") == "") {
        SetCookie("SaveSourceTime", tempNow.toLocaleDateString(), tempDate);
    }
    if (GetCookie("SaveSourceRefer") == "") {
        SetCookie("SaveSourceRefer", tempReferrer, tempDate);
    }
   
}
function SetPageDataX(dataSource, data) {
    tempdata = data;
    try {
        if (dataSource && dataSource != '') {
            if (tempdata == '')
                tempdata = dataSource;
        }
    }
    catch (e) { }
    return tempdata;
}
//存cookie
function SetCookie(name, value, expiry, path, domain, secure) {
    var nameString = escape(name) + "=" + escape(value);
    var expiryString = (expiry == null) ? "" : " ;expires = " + expiry.toGMTString();
    var pathString = (path == null) ? "" : " ;path = " + path;
    var domainString = (path == null) ? "" : " ;domain = " + domain;
    var secureString = (secure) ? ";secure" : "";
    document.cookie = nameString + expiryString + pathString + domainString + secureString;
}
//读cookie
function GetCookie(name) {
    var CookieFound = false;
    var start = 0;
    var end = 0;
    var CookieString = document.cookie;
    var i = 0;
    while (i <= CookieString.length) {
        start = i;
        end = start + name.length;
        if (CookieString.substring(start, end) == name) {
            CookieFound = true;
            break;
        }
        i++;
    }
    if (CookieFound) {
        start = end + 1;
        end = CookieString.indexOf(";", start);
        if (end < start)
            end = CookieString.length;
        return unescape(CookieString.substring(start, end));
    }
    return "";
}

//取得上级网页地址
GetPageReferX();