// The cookie name to use for storing the blog-side comment session cookie. var mtCookieName = "mt_blog13_user"; var mtCookieDomain = ".sekine-souzoku.com"; var mtCookiePath = "/blog/"; var mtCookieTimeout = 14400; function mtHide(id) { var el = (typeof id == "string") ? document.getElementById(id) : id; if (el) el.style.display = 'none'; } function mtShow(id) { var el = (typeof id == "string") ? document.getElementById(id) : id; if (el) el.style.display = 'block'; } function mtAttachEvent(eventName,func) { var onEventName = 'on' + eventName; var old = window[onEventName]; if( typeof old != 'function' ) window[onEventName] = func; else { window[onEventName] = function( evt ) { old( evt ); return func( evt ); }; } } function mtFireEvent(eventName,param) { var fn = window['on' + eventName]; if (typeof fn == 'function') return fn(param); return; } function mtRelativeDate(ts, fds) { var now = new Date(); var ref = ts; var delta = Math.floor((now.getTime() - ref.getTime()) / 1000); var str; if (delta < 60) { str = '直前'; } else if (delta <= 86400) { // less than 1 day var hours = Math.floor(delta / 3600); var min = Math.floor((delta % 3600) / 60); if (hours == 1) str = '1 時間前'; else if (hours > 1) str = '2 時間前'.replace(/2/, hours); else if (min == 1) str = '1 分前'; else str = '2 分前'.replace(/2/, min); } else if (delta <= 604800) { // less than 1 week var days = Math.floor(delta / 86400); var hours = Math.floor((delta % 86400) / 3600); if (days == 1) str = '1 日前'; else if (days > 1) str = '2 日前'.replace(/2/, days); else if (hours == 1) str = '1 時間前'; else str = '2 時間前'.replace(/2/, hours); } return str ? str : fds; } function mtEditLink(entry_id, author_id) { var u = mtGetUser(); if (! u) return; if (! entry_id) return; if (! author_id) return; if (u.id != author_id) return; var link = '編集'; document.write(link); } function mtCommentFormOnFocus() { // if CAPTCHA is enabled, this causes the captcha image to be // displayed if it hasn't been already. mtShowCaptcha(); } var mtCaptchaVisible = false; function mtShowCaptcha() { var u = mtGetUser(); if ( u && u.is_authenticated ) return; if (mtCaptchaVisible) return; var div = document.getElementById('comments-open-captcha'); if (div) { div.innerHTML = ''; mtCaptchaVisible = true; } } var is_preview; var user; function mtSetUser(u) { if (u) { // persist this user = u; mtSaveUser(); // sync up user greeting mtFireEvent('usersignin'); } } function mtEscapeJS(s) { s = s.replace(/'/g, "'"); return s; } function mtUnescapeJS(s) { s = s.replace(/'/g, "'"); return s; } function mtBakeUserCookie(u) { var str = ""; if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';"; if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';"; if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';"; if (u.is_authenticated) str += "is_authenticated:'1';"; if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';"; if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';"; if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';"; str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';"; str += "is_author:'" + (u.is_author ? "1" : "0") + "';"; str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';"; str += "can_post:'" + (u.can_post ? "1" : "0") + "';"; str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';"; str = str.replace(/;$/, ''); return str; } function mtUnbakeUserCookie(s) { if (!s) return; var u = {}; var m; while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { s = s.substring(m[1].length); if (m[2].match(/^(is|can)_/)) // boolean fields u[m[2]] = m[3] == '1' ? true : false; else u[m[2]] = mtUnescapeJS(m[3]); } if (u.is_authenticated) { u.is_anonymous = false; } else { u.is_anonymous = true; u.can_post = false; u.is_author = false; u.is_banned = false; u.is_trusted = false; } return u; } function mtGetUser() { if (!user) { var cookie = mtGetCookie(mtCookieName); if (!cookie) return; user = mtUnbakeUserCookie(cookie); if (! user) { user = {}; user.is_anonymous = true; user.can_post = false; user.is_author = false; user.is_banned = false; user.is_trusted = false; } } return user; } var mtFetchedUser = false; function mtFetchUser(cb) { if (!cb) cb = 'mtSetUser'; if ( ( cb == 'mtSetUser' ) && mtGetUser() ) { var url = document.URL; url = url.replace(/#.+$/, ''); url += '#comments-open'; location.href = url; } else { // we aren't using AJAX for this, since we may have to request // from a different domain. JSONP to the rescue. mtFetchedUser = true; var script = document.createElement('script'); script.src = 'http://www.sekine-souzoku.com/cgi-bin/mt/gp-comments.cgi?__mode=session_js&blog_id=13&jsonp=' + cb; (document.getElementsByTagName('head'))[0].appendChild(script); } } function mtRememberMeOnClick(b) { if (!b.checked) mtClearUser(b.form); return true; } var mtRequestSubmitted = false; function mtCommentOnSubmit(f) { if (!mtRequestSubmitted) { mtRequestSubmitted = true; var text = f.text.value; if(!text){ alert("コメントが入力されておりません"); mtRequestSubmitted = false; return false; } if (f.armor) f.armor.value = 'fd6caf19c27c7c472907fbd3844f31d47d32cd53'; if (f.bakecookie && f.bakecookie.checked) mtSaveUser(f); // disable submit buttons if (f.preview_button) f.preview_button.disabled = true; if (f.post) f.post.disabled = true; var u = mtGetUser(); if ( !is_preview && ( u && u.is_authenticated ) ) { // validate session; then submit mtFetchedUser = false; mtFetchUser('mtCommentSessionVerify'); return false; } return true; } return false; } function mtCommentSessionVerify(app_user) { var u = mtGetUser(); var f = document['comments_form']; if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) { f.submit(); } else { alert('セッションの有効期限が切れています。再度サインインしてください。'); mtClearUser(); mtFireEvent('usersignin'); } } function mtUserOnLoad() { var u = mtGetUser(); // if the user is authenticated, hide the 'anonymous' fields // and any captcha input if already shown if ( document.getElementById('comments-form')) { if ( u && u.is_authenticated ) { mtShow('comments-form'); mtHide('comments-open-data'); if (mtCaptchaVisible) mtHide('comments-open-captcha'); } else { } if ( u && u.is_banned ) mtHide('comments-form'); // if we're previewing a comment, make sure the captcha // field is visible if (is_preview) mtShowCaptcha(); else mtShowGreeting(); // populate anonymous comment fields if user is cookied as anonymous var cf = document['comments_form']; if (cf) { if (u && u.is_anonymous) { if (u.email) cf.email.value = u.email; if (u.name) cf.author.value = u.name; if (u.url) cf.url.value = u.url; if (cf.bakecookie) cf.bakecookie.checked = u.name || u.email; } else { if (u && u.sid && cf.sid) cf.sid.value = u.sid; } } } } function mtEntryOnLoad() { mtFireEvent('usersignin'); } function mtEntryOnUnload() { if (mtRequestSubmitted) { var cf = document['comments_form']; if (cf) { if (cf.post && cf.post.disabled) cf.post.disabled = false; if (cf.preview_button && cf.preview_button.disabled) cf.preview_button.disabled = false; } mtRequestSubmitted = false; } return true; } mtAttachEvent('usersignin', mtUserOnLoad); function mtSignIn() { var doc_url = document.URL; doc_url = doc_url.replace(/#.+/, ''); var url = 'http://www.sekine-souzoku.com/cgi-bin/mt/gp-comments.cgi?__mode=login&blog_id=13'; if (is_preview) { if ( document['comments_form'] ) { var entry_id = document['comments_form'].entry_id.value; url += '&entry_id=' + entry_id; } else { url += '&return_url=http%3A%2F%2Fwww.sekine-souzoku.com%2Fblog%2F'; } } else { url += '&return_url=' + encodeURIComponent(doc_url); } mtClearUser(); location.href = url; } function mtSignInOnClick(sign_in_element) { var el; if (sign_in_element) { // display throbber el = document.getElementById(sign_in_element); if (!el) // legacy MT 4.x element id el = document.getElementById('comment-form-external-auth'); } if (el) el.innerHTML = 'サインインします...