var shuncolleStrUrl = "";
var shuncolleTimeID = 0;

function execSearch() {
    var url = '/multimaker/maker/keywordmaster_count';
    var params = "q=";
    shuncolleStrUrl = document.f.Text.value;
    
	var len = 0;
	var str = escape(shuncolleStrUrl);
	for (i = 0; i < str.length; i++, len++) {
		if (str.charAt(i) == "%") {
			if (str.charAt(++i) == "u") {
				i += 3;
				len++;
			}
		i++;
		}
	}
	if(len>256){
        shuncolleTimeID=setTimeout("hideBalloon('searchBalloon');",3000);
        showBalloon("searchBalloon");
        return false;
	}
    
    if(shuncolleStrUrl == "" || shuncolleStrUrl == null) {
//      shuncolleTimeID=setTimeout("hideBalloon('searchBalloon');",3000);
//        showBalloon("searchBalloon");
        return false;
    }
    params = params + encodeURI(shuncolleStrUrl).replace("+","%2B");

    var myAjax = new Ajax.Request(
        url, 
        {
            method: 'get', 
            parameters: params, 
            onSuccess: checkSearchResult, 
            onFailure: forwardErrorPage
        });
        
    return false;
}

function initSearchBalloon() {
    document.write('<div id="searchBalloon">');
    document.write('<div class="inner">');
    document.write('<p><span id="shuncolleBalloon" onmouseover="mouseoverBalloon();" onmouseout="mouseoutBalloon();"></span></p>');
    document.write('</div>');
    document.write('</div>');

    hideBalloon("searchBalloon");
}

function checkSearchResult(httpObj) {
    var baseUrl = "/shuncolle/word/"
    var result = httpObj.responseText;
    if(parseInt(result) == 0) {
        shuncolleTimeID=setTimeout("hideBalloon('searchBalloon');",3000);
        showBalloon("searchBalloon");
    } else if (parseInt(result) == -1) {
        hideBalloon("searchBalloon");
        location.href = "/colleguide/error/error_system.htm";
    } else {
        hideBalloon("searchBalloon");
        location.href = baseUrl + (encodeURI(shuncolleStrUrl)).replace("%2F","/") + ".htm";
    }
    return false;
}

function forwardErrorPage(httpObj) {
    hideBalloon("searchBalloon");
    location.href = "/colleguide/error/error_system.htm";
}

function mouseoverBalloon(){
    clearTimeout(shuncolleTimeID);
}

function mouseoutBalloon(){
    shuncolleTimeID=setTimeout("hideBalloon('searchBalloon');",3000);
}

function showBalloon(id) {
    setDivVisibility(id,"visible");
    setDivDisplay(id,"block");
    writeBalloonString();
}

function hideBalloon(id) {
    clearTimeout(shuncolleTimeID);
    setDivVisibility(id,"hidden");
    setDivDisplay(id,"none");
    clearBalloonString();
}

function writeBalloonString() {
    var str = shuncolleStrUrl;
	str = str.replace("&","&amp;");
	str = str.replace(">","&gt;");
	str = str.replace("<","&lt;");
	str = str.replace("\"","&quot;");
	str = str.replace("\'","&#039;");
    document.getElementById("shuncolleBalloon").innerHTML = '“' + str + '”についての瞬！コレは見つかりませんでした。<br />このキーワードの瞬！コレが欲しい！という場合は、<a href="https://enq.nifty.com/qa/fm/CMM061000/shuncolle">ご意見・ご要望ページ</a>から作成依頼をしてください。';
}

function clearBalloonString() {
    document.getElementById("shuncolleBalloon").innerHTML = null;
}

function setDivVisibility(objName,val){
    if(browserType.IE){
        document.all[objName].style.visibility=val;
    } else {
        document.getElementById(objName).style.visibility=val;
    }
}

function setDivDisplay(objName,val){
    if(browserType.IE){
        document.all[objName].style.display=val;
    } else {
        document.getElementById(objName).style.display=val;
    }
}

document.write('<scr'+'ipt language="javascript" src="/colleguide/js/lib/prototype.js">');
document.write('</scr'+'ipt>');

