var j$ = jQuery;
function getFile(strurl, id) {
	$.ajax({
			url: strurl,
			type: 'GET',
			dataType: 'html',
			timeout: 1500,
			error: function() {
				if(id == "content") {
					$('.content').append('Error loading document');
				}else{
					$('#'+id).html('').append('Error loading document');
				}
			},
			complete: function(html) {
				if(id == "content") {
					$('.content').css('height', 'auto').css('background-image', 'none').html(html.responseText);
				}else{
					$('#'+id).html('').append(html.responseText);
				}
			}
	});
}


function winOpen(url, w, h) {
	window.open(url, 'nw', 'scrollbars=yes,resizable=yes,status=yes,width=' + w + ',height=' + h + '');
}
var DDSPEED = 10;
var DDTIMER = 15;
function ddMenu(id, d) {
    var h = document.getElementById('ddheader-' + id);
    var c = document.getElementById('ddcontent-' + id);
    clearInterval(c.timer);
    if (d == 1) {
        clearTimeout(h.timer);
        if (c.maxh && c.maxh <= c.offsetHeight) {
            return
        } else if (!c.maxh) {
            c.style.display = 'block';
            c.style.height = 'auto';
            c.maxh = c.offsetHeight;
            c.style.height = '0px';
        }
        c.timer = setInterval(function() {
            ddSlide(c, 1)
        },
        DDTIMER);
    } else {
        h.timer = setTimeout(function() {
            ddCollapse(c)
        },
        50);
    }
}
function ddCollapse(c) {
    c.timer = setInterval(function() {
        ddSlide(c, -1)
    },
    DDTIMER);
}
function cancelHide(id) {
    var h = document.getElementById('ddheader-' + id);
    var c = document.getElementById('ddcontent-' + id);
    clearTimeout(h.timer);
    clearInterval(c.timer);
    if (c.offsetHeight < c.maxh) {
        c.timer = setInterval(function() {
            ddSlide(c, 1)
        },
        DDTIMER);
    }
}
function ddSlide(c, d) {
    var currh = c.offsetHeight;
    var dist;
    if (d == 1) {
        dist = (Math.round((c.maxh - currh) / DDSPEED));
    } else {
        dist = (Math.round(currh / DDSPEED));
    }
    if (dist <= 1 && d == 1) {
        dist = 1;
    }
    c.style.height = currh + (dist * d) + 'px';
    c.style.opacity = currh / c.maxh;
    c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    if ((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)) {
        clearInterval(c.timer);
    }
}
j$.easing.quart = function(x, t, b, c, d) {
    return - c * ((t = t / d - 1) * t * t * t - 1) + b;
};
j$(document).ready(function() {
    j$('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var $target = j$(this.hash);
            $target = $target.length && $target || j$('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                j$('html,body').animate({
                    scrollTop: targetOffset
                },
                1200, 'quart');
                return false;
            }
        }
    });
});
$(function() {
    $("#accordion").each(function() {
        $(".accordion_toggle", this).each(function(index) {
            if (index > 0) $(this).next().hide();
            $(this).click(function() {
                var params = {
                    height: "toggle",
                    opacity: "toggle"
                };
                $(this).next("div").animate(params).siblings("div:visible").animate(params);
                return false;
            });
        });
    });
});

$(function() {
	$(".tab").each(function(index) {
		if(index == 0){ $(this).addClass("activo");}
		else{$("#" + $(this).attr("title")).addClass("dp");}
	});
	$(".tab").click(function() {
			$(".activo").removeClass("activo");
			$(this).addClass("activo");
			$(".tabBox").hide('slow');
			var muestra = $(this).attr("title");
			$("#" + muestra).show('slow');
	});
});

function kengaku_submitCheck(obj, n) {
    var warning = "";
    var flg = false;
    for (i = 0; i < obj.Q1.length; i++) {
        if (obj.Q1[i].checked) flg = true;
    }
    if (flg == false) {
        warning += "* 事務所見学希望\n";
    }
    if (obj.Q0NAME.value == "") {
        warning += "* 氏名\n";
    }
    if (obj.Q2field.value == "") {
        warning += "* 連絡先メールアドレス\n";
    }
    if (obj.Q3field.value == "") {
        warning += "* 連絡先電話番号\n";
    }
    if (n == 1) {
        var flg = false;
        for (i = 0; i < obj.Sex.length; i++) {
            if (obj.Sex[i].checked) flg = true;
        }
        if (flg == false) {
            warning += "* 性別\n";
        }
        if (obj.Age.value == "") {
            warning += "* 年齢\n";
        }
    }
    if (obj.Q4field.value == "") {
        warning += "* 最終学歴\n";
    }
    if (obj.Q5.value == "") {
        warning += "* 弁理士試験受験状況\n";
    }
    var flg = false;
    for (i = 0; i < obj.Q6.length; i++) {
        if (obj.Q6[i].checked) flg = true;
    }
    if (flg == false) {
        warning += "* 技術分野\n";
    }
    var flg = false;
    for (i = 0; i < obj.Q7.length; i++) {
        if (obj.Q7[i].checked) flg = true;
    }
    if (flg == false) {
        warning += "* 実務経験\n";
    }
    if (warning != "") {
        alert("次の項目の入力がされていません\n\n" + warning);
    } else {
        org = document.charset;
        document.charset = "utf-8";
        obj.submit();
        document.charset = org;
    }
}
var com = "";
var tit = "";
var regObj = document.location.href.match(/(http|https)(:\/\/www\.soei\.com\/)(.*?)(\/)/);
var dir = regObj[3];
if (dir == "jp" || dir == "kyoto") {
    com = "※スペースでAND検索が出来ます。<br />";
    com += " ※この状態からの２度目の検索は非常に高速です。";
    tit = "検索結果 ";
    nomatch = "一致するものはありませんでした。"
} else if (dir == "korea") {
    com = "* 단어 사이의 스페이스는 AND검색을 의미합니다.<br />";
    com += " * 현재상태에서 재검색을 하시면 매우 빠른 속도로 검색하실 수 있습니다.";
    tit = "검색 결과 ";
    nomatch = "페이지를 찾을 수 없습니다.";
} else if (dir == "chinese") {
    com = "* “AND”可用空格代替<br />";
    com += " * 从这开始的第二个检索为高速";
    tit = "检索结果 ";
    nomatch = "没有找到相关信息";
} else {
    com = "* AND can be retrieved in space.<br />";
    com += " * The second search from this state is very high-speed.";
    tit = "Search Results ";
    nomatch = "No pages were found containing.";
}
var jquery_loader = 'indicator.gif';
var json_search_data = 'search_data.txt';
var json_search_keyword = '';
var json_search_is_loaded = false;
var json_search_entries;
function json_search_archive() {
    var result_data = new Array();
    json_search_keyword = json_search_keyword.replace(/([\/\\\.\*\+\?\|\(\)\[\]\{\}\$\^])/g, "\\$1");
    json_search_keyword = json_search_keyword.replace(/( +|　+)/, ' ');
    json_search_keyword = json_search_keyword.replace(/( |　)$/, '');
    var keywords = json_search_keyword.split(/ |　/);
    var key = new Array();
    for (var i = 0; i < keywords.length; i++) {
        key[key.length] = new RegExp(keywords[i], "i");
    }
    for (var i = 0; i < json_search_entries.length - 1; i++) {
        var is_match = true;
        for (var j = 0; j < key.length; j++) {
            var res_body = key[j].exec(json_search_entries[i].body);
            var res_title = key[j].exec(json_search_entries[i].title);
            if (!res_body && !res_title) {
                is_match = false;
            }
        }
        if (is_match) {
            result_data[result_data.length] = json_search_entries[i];
        }
    }
    var result_html = '';
    if (result_data.length == 0) {
        result_html = nomatch;
    } else {
        result_html = json_search_result_html(result_data, keywords);
    }
    $('.content').css('height', 'auto').css('background-image', 'none').html(result_html);
}
function json_search_result_html(result_data, keywords) {
    var html = '<p id="search_notice" style="text-align:left;">' + com + '<br />';
    html += '<div class="entry-top"></div><div class="entry"><h3 class="entry-title">' + tit + '（ ' + result_data.length + ' HIT ）</h3>';
    html += '<div class="entry-body-top"></div><div class="entry-body"><div class="entry-body-text">';
    html += '<ol type=1 start=1 style="text-align:left;">';
    for (var i = 0; i < result_data.length; i++) {
        html += '<li><a href="' + result_data[i].link + '#search_word=' + json_search_keyword + '">';
        html += highlight(result_data[i].title, keywords) + '</a>';
        html += '<br />' + highlight(trunc(result_data[i].body, keywords[0]), keywords) + '</li>';
    }
    html += '</ol></div></div>';
    html += '<div class="entry-body-bottom"></div>';
    html += '<p class="meta"><span class="bo_so_copyright"><a href="#" title="Go Back page" onclick="location.reload(true); return false;" onkeypress="location.reload(true); return false;">[Go Back Page]</a><a href="/" title="Go Back Index" >[Go Back Index]</a></span></p>';
    html += '</div>';
    html += '<div class="entry-bottom"></div><div class="date-footer"></div>';
    return html;
}
function trunc(text, keyword) {
    var key = new RegExp(keyword, "i");
    var res = key.exec(text);
    if (res) {
        var index = res.index;
        var length = res[0].length;
        var start;
        var end;
        start = index - 20;
        end = 55;
        text = text.substring(start, index) + text.substr(index, length) + text.substr(index + length, end) + '...';
    } else {
        text = text.substring(start, 50);
    }
    return text;
}
function highlight(text, keywords) {
    var keyword = '';
    for (var i = 0; i < keywords.length; i++) {
        if (i == keywords.length - 1) {
            keyword += keywords[i];
        } else {
            keyword += keywords[i] + '|';
        }
    }
    return text.replace(new RegExp('(' + keyword + ')', "ig"), '<span style="background-color: #FFCC33;">' + "$1" + '</span>');
}
function json_search(json_search_data) {
    json_search_keyword = $('input#search_box').val();
    $('.content').html('').css('height', '100px').css('background', 'transparent url(' + jquery_loader + ') no-repeat center center');
    if (json_search_is_loaded) {
        json_search_archive();
    } else {
        $.ajax({
            url: json_search_data,
            type: 'GET',
            dataType: 'xml',
            timeout: 1500,
            error: function() {
                $('.content').css('height', 'auto').css('background-image', 'none').html('Error loading XML document');
            },
            complete: function(xml) {
                var data_string = xml.responseText;
                data_string = data_string.replace(new RegExp('<.*?>', "i"), '');
                json_search_entries = eval(data_string);
                json_search_archive();
                json_search_is_loaded = true;
            }
        });
    }
}
function clear_block(blockid) {
    $(blockid).html('');
}