(function(){
    function getItem(k){
        try{
            //wuheng
            localStorage.setItem("rmdkk",111);
            localStorage.removeItem("rmdkk");

            var v = localStorage.getItem(k);
            return v == null ? "":v;
        }
        catch(e){
            return "";
        }
    }
    var url = window.location.href,
        params = url.substring(url.indexOf("?")+1),
        paramArray = params.split("&");

    var cid = getItem("rytf_cid"),
        campaignid = getItem("rytf_campid");

    if(cid == ""){
        cid = -1;
        campaignid = '_default_';
    }

    if((cid == '' || cid == -1 || cid == '-1') || (paramArray  && paramArray.length>0)){
        for(var i=0;i<paramArray.length;i++){
            var pp = paramArray[i].split("=");
            if(pp[0] == 'cid'){
                cid = pp[1];
            }
            if(pp[0] == 'campaignid'){
                var v = pp[1],vj = v.indexOf("#");
                if(vj > -1){
                    v = v.substring(0, vj);
                }
                campaignid = pp[1];
            }
        }

        if(!/^-?\d+$/.test(cid)){
            cid = -1;
        }
        localStorage.setItem("rytf_cid",cid);
        localStorage.setItem("rytf_campid",campaignid);
    }
})();
