var g_KeepList = new Array(); /* load keep list from cookie */ function loadKeepList() { var keepStores = $.cookie('KEEP_STORES'); if( keepStores != null && keepStores != undefined && keepStores.length ) { g_KeepList = keepStores.split(','); } reloadKeepList(); } /* recount keep list */ function reloadKeepList() { $('#keep_count').text( g_KeepList.length ); } /* if store already exists this function returns true */ function isInKeepList( storeId ) { return $.inArray( storeId , g_KeepList ) != -1; } /* add store id to keep list */ function addKeepList( storeId ) { jConfirm( 'Myリストに追加してもよろしいですか?', 'Myリスト追加', function(r){ if( r !== false ) { if( !isInKeepList( storeId , g_KeepList ) ) { g_KeepList.push( storeId ); reloadKeepList(); saveKeepList(); } else { jAlert( '既に登録されています。', 'Myリスト登録' ); } } } ); } /* remove store id in keep list */ function removeKeepList( storeId ) { jConfirm( 'Myリストから削除してもよろしいですか?', 'Myリスト削除', function(r){ if( r !== false ) { storeId = $.inArray( storeId , g_KeepList ); if( storeId != -1 ) { g_KeepList.splice( storeId, 1 ); saveKeepList(); location.reload(); } } } ); } /* save keep list to cookie */ function saveKeepList() { if( g_KeepList != null && g_KeepList != undefined ) { $.cookie( 'KEEP_STORES', g_KeepList.toString(), {path:'/'} ); } } $(document).ready( loadKeepList );