// Function to Set Cookie
function setCookie(name,value,expire){
    document.cookie = name + '=' + escape(value) + ((expire==null)?'':('; expires='+expire.toGMTString()))+';path=/';
//    alert(document.cookie);
}

// Function to Get Cookie
function getCookie(name){
    var search = name + '=';
    if (document.cookie.length>0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1){
            offset += search.length;
            end = document.cookie.indexOf(';',offset);
            if(end == -1)
                end = document.cookie.length;
            return unescape(document.cookie.substring(offset,end));
        }
    }
    return null;
}

//保存した情報
function JS_preserve(name,data_all)
{
        var cookie = getCookie(name);
        
        if ( cookie==null ) { cookie = data_all; }
        else
        {
            cookie = data_all;
        }
        cD = new Date();
        cDate = cD.getDate();
        cD.setDate(cDate+30);

        setCookie(name,cookie,cD);
}

// 表示件数の保存
function JS_select_num(name_kind,data_num)
{
        var cookie = getCookie(name_kind);
        
        if ( cookie==null ) { cookie = data_num; }
        else
        {
            cookie = data_num;
        }
        cD = new Date();
        cDate = cD.getDate();
        cD.setDate(cDate+30);
        
        setCookie(name_kind,cookie,cD);
}

//最近見た物件追加
function JS_recently(name,b_num) {
    var c = getCookie(name);
    
    if ( c==null ) { c = b_num; }
    else if ( c.indexOf(b_num) == -1 ) { c = c+","+b_num; }
    else {
        //return(true);
    }
    cD = new Date();
    cDate = cD.getDate();
    cD.setDate(cDate+7);


    setCookie(name,c,cD);
//    alert('最近見た物件に追加');
//    setTotal(name);
    return(true);
}

function setTotal(name) {
    var c = getCookie(name);
    if ( c == null ) {
        var num=0;
    } else {
        var num = c.split(",").length;
    }
//    document.getElementById('recently_total').innerHTML = num+"件";
//    $("recently_total").innerHTML = num;
}

