﻿//get SiteID
function __getSiteId() {
    var siteid = "";
    var url = location.href;
    var no=/^\d{5}$/gi;
    var re = /_(\d{5})_/gi;
    if (re.test(url)) {
        siteid = RegExp.$1;
        if (no.test(siteid)) {
            return siteid;
        }
    }
    re = /siteid=(\d{5})/gi;
    if (re.test(url)) {
        siteid = RegExp.$1;
        if (no.test(siteid)) {
            return siteid;
        }
    }
    siteid = ppkRead("siteid");
    if (siteid) {
        return siteid;
    }
    $.get("/config/IpAjax.aspx", function(res) {
        siteid = res;
        if (no.test(siteid)) {
            return siteid;
        }
    });
    return "10001";
}
//get CatID
function __getCatId() {
    var url = top.location.href;
    var catid="";
    var no = /^\d{3}$/gi;
    var re = /_\d{5}_(\d{3})/gi;
    if (re.test(url)) {
        catid = RegExp.$1;
        if (no.test(catid)) {
            return catid;
        }
    }
    re = /catid=(\d{3})/gi;
    if (re.test(url)) {
        catid = RegExp.$1;
        if (no.test(catid)) {
            return catid;
        }
    }
    return "";
}
//change location
function UrlRedirect() {
    var catid = __getCatId();
    var siteid = __getSiteId();
    switch(catid){
        case "230":
            location.href = '/shop/list.aspx?catid=230&siteid='+siteid;
            break;
        case "231":
            location.href = '/shop/list.aspx?catid=231&siteid='+siteid;
            break;
        case "270":
            location.href = "/shop/index_" + siteid + "_101.html";
            break;
        case "260":
            location.href = '/shop/list.aspx?catid=260&siteid='+siteid;
            break;
        case "280":
            location.href = '/shop/list.aspx?catid=280&siteid='+siteid;
            break;
        case "310":
            location.href = "/shop/index_" + siteid + "_102.html";
            break;
        case "300":
            location.href = "/shop/index_" + siteid + "_103.html";
            break;
        case "250":
            location.href = '/shop/list.aspx?catid=250&siteid=' + siteid;
            break;
        case "290":
            location.href = '/shop/list.aspx?catid=290&siteid=' + siteid;
            break;
        case "291":
            location.href = '/shop/list.aspx?catid=291&siteid=' + siteid;
            break;
        case "292":
            location.href = '/shop/list.aspx?catid=292&siteid=' + siteid;
            break;
        case "320":
            location.href = '/shop/list.aspx?catid=320&siteid=' + siteid;
            break;
    }
}
UrlRedirect();
