function w3cMovie(fileName, width, height, autoStart, volume) {
	document.write("<embed id='WinMedia' src='"+fileName+"' width='"+width+"' height='"+height+"' autostart='"+autoStart+"' volume='"+volume+"' border='0' ShowControls='False' ShowStatusBar='False'></embed>");
}

function w3cMovieMem(fileName) {
	document.write("<embed src='"+fileName+"'></embed>");
}

function w3cFlash(fileName, width, height, wmode, play, loop) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+width+'" height="'+height+'">');
	document.write('	<param name=movie value="'+fileName+'">');
	document.write('	<param name=quality value="high">');
	document.write('	<param name="menu" value="false">');
	document.write('	<param name="play" value="'+play+'">');
	document.write('	<param name="loop" value="'+loop+'">');
	document.write('	<param name="wmode" value="'+wmode+'">');
	document.write('	<embed src="'+fileName+'" quality="high" play="'+play+'" loop="'+loop+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'">');
	document.write('	</embed></object>');
}
function updateChar(form,length_limit,innerText_show){
    var length = calculate_msglen(form.value);

    if (innerText_show==1){
      textlimit.innerText = length;
    }

    if (length > length_limit) {
		alert( length_limit + "byteを超過した文字は自動的に削除されます。");
        form.value = form.value.replace(/\r\n$/, "");
        form.value = assert_msglen(form.value, length_limit, innerText_show);
    } 
}

function calculate_msglen(message){
    var nbytes = 0;
        
    for (i=0; i<message.length; i++) {
        var ch = message.charAt(i);
        if(escape(ch).length > 4) {
            nbytes += 2;
        } else if (ch == '\n') {
            if (message.charAt(i-1) != '\r') {
                nbytes += 1;
            }
        } else if (ch == '<' || ch == '>') {
            nbytes += 4;
        } else {
            nbytes += 1;
        }         
    }               
    return nbytes;    
}

function assert_msglen(message, maximum, innerText_show){
    var inc = 0;
    var nbytes = 0;
    var msg = "";
    var msglen = message.length;

    for (i=0; i<msglen; i++) {
        var ch = message.charAt(i);
        if (escape(ch).length > 4) {
            inc = 2;
        } else if (ch == '\n') {
            if (message.charAt(i-1) != '\r') {
                inc = 1;
            }
        } else if (ch == '<' || ch == '>') {
            inc = 4;
        } else {
            inc = 1;
        }
        if ((nbytes + inc) > maximum) {
            break;
        }
        nbytes += inc;
        msg += ch;
    }

    if (innerText_show==1){
      textlimit.innerText = nbytes;
    }
    return msg;
}

function go_win(url,root,w,h) {
    var l = (screen.width - w)/2;
    var t = (screen.height - h)/2;
    w = eval(w);
    h = eval(h);
    NewWin = window.open(url,root,"titlebar=0, resizable=0, width="+w+", height="+h+", top="+t+", left="+l);
}

function go_win2(url,root,w,h) {
    var l = (screen.width - w)/2;
    var t = (screen.height - h)/2;
    w = eval(w);
    h = eval(h);
    NewWin = window.open(url,root,"titlebar=0, resizable=0,scrollbars=1, width="+w+", height="+h+", top="+t+", left="+l);
}
function go_win3(url,root,w,h) {
    var l = (screen.width - w)/2;
    var t = (screen.height - h)/2;
    w = eval(w);
    h = eval(h);
    NewWin = window.open(url,root,"titlebar=0, resizable=1,scrollbars=1, width="+w+", height="+h+", top="+t+", left="+l);
}

function confirm_ch(smsg,gurl){
  if(confirm(smsg)){
    self.location.href=gurl;
  }else{
    return;
  }
}
function paramEscape(paramValue)
{
   return encodeURIComponent(paramValue);
}
function formData2QueryString(docForm)
{
   var submitString = '';
   var formElement = '';
   var lastElementName = '';

   for(i = 0 ; i < docForm.elements.length ; i++)
   {
     formElement = docForm.elements[i];
     switch(formElement.type)
     {
        case 'text' :
        case 'select-one' :
        case 'hidden' :
        case 'password' :
        case 'textarea' :
           submitString += formElement.name + '=' + paramEscape(formElement.value) + '&';
           break;
        case 'radio' :
           if(formElement.checked)
           {
             submitString += formElement.name + '=' + paramEscape(formElement.value) + '&';
           }
           break;
        case 'checkbox' :
           if(formElement.checked)
           {
             if(formElement.name = lastElementName)
             {
                if(submitString.lastIndexOf('&') == submitString.length - 1)
                {
                   submitString = submitString.substring(0, submitString.length - 1);
                }
                submitString += ',' + paramEscape(formElement.value);
             }
             else
             {
                submitString += formElement.name + '=' + paramEscape(formElement.value);
             }
             submitString += '&';
             lastElementName = formElement.name;
           }
           break;
     }
   }
   submitString = submitString.substring(0, submitString.length - 1);
   //document.all("result").value = submitString;
   return submitString;
}
function xmlHttpPost(actionUrl, submitParameter, resultFunction)
{
   var xmlHttpRequest = false;

   //IE
   if(window.ActiveXObject)
   {
     xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
   }
   else
   {
     xmlHttpReq = new XMLHttpRequest();
     xmlHttpReq.overrideMimeType('text/xml');
   }

   xmlHttpRequest.open('POST', actionUrl, true);
   xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpRequest.onreadystatechange = function() {
     if(xmlHttpRequest.readyState == 4)
     {
        switch (xmlHttpRequest.status)
        {
           case 404:
             alert('error: ' + actionUrl + 'not found');
             break;
          case 500:
             alert('error: ' + xmlHttpRequest.responseText);
             break;
          default:
             eval(resultFunction + '(xmlHttpRequest.responseText);');
             break;
        }
     }
   }

   xmlHttpRequest.send(submitParameter);
}
var viewchk = true;
function keywordKeyDown(){
    if(viewchk){
        if(window.event.srcElement.nodeName=="INPUT"||window.event.srcElement.nodeName=="input"){
            var keyCode = window.event.keyCode;
            if(keyCode ==  9)   return;     //Tab key
            if(keyCode  == 13)   return;     //Enter key
            if(keyCode  == 16)   return;     //Shift key
            if(keyCode  == 16)   return;     //Ctrl key
            if(keyCode  == 18)   return;     //Alt key
            if(keyCode  == 45)   return;     //Ins key
            if(keyCode  == 33)   return;     //PgUp key
            if(keyCode  == 34)   return;     //PgDn key
            if(keyCode  == 35)   return;     //End key
            if(keyCode  == 36)   return;     //Home key
            if(keyCode  == 37)   return;
            if(keyCode  == 38)   return;
            if(keyCode  == 39)   return;
            if(keyCode  == 40){
                var searchKeywordDiv=document.getElementById("searchKeyword");
                if(searchKeywordDiv.style.visibility == "visible"){
                    if(typeof(document.getElementById("keytd0"))=="object"){
                        document.getElementById("keytd0").focus();
                        setKeyword(document.getElementById("keytd0").msg);
                    }
                }
                return;
            }
            if(document.getElementById("s_word").value!=""){
                setTimeout('submitSearchKeyword()',250);
            }else{
                var searchKeywordDiv=document.getElementById("searchKeyword");
                searchKeywordDiv.innerHTML = "";
                searchKeywordDiv.style.visibility = "hidden";
            }
        }
    }
}
function movenext(tar,word){
    var keyCode = window.event.keyCode;

    if(keyCode == 38){
        tar = tar - 1;
        var searchKeywordDiv = document.getElementById("searchKeyword");
        if(searchKeywordDiv.style.visibility == "visible"){
            if(tar >= 0){
                target = eval("document.all.keytd"+tar)
                if(typeof(target)=="object"){
                    target.focus();
                    setKeyword(target.msg);
                }
            }else{
                document.getElementById("s_word").focus();
            }
        }
        return;
    }
    if(keyCode == 40){
        tar = tar + 1;
        var searchKeywordDiv = document.getElementById("searchKeyword");
        if(searchKeywordDiv.style.visibility == "visible"){
            target = eval("document.all.keytd"+tar)
            if(typeof(target)=="object"){
                target.focus();
                setKeyword(target.msg);
            }
        }
        return;
    }

    if(keyCode == 13){
        var searchKeywordDiv = document.getElementById("searchKeyword");
        if(searchKeywordDiv.style.visibility == "visible"){
            sendrealsearch(word);
        }
        return;
    }
}
function submitSearchKeyword(){
    var url = '/lib/word_auto_com.php';
    var queryString = formData2QueryString(document.regist);
    var resultProcessMethod = 'viewSearchKeywordResult';

    xmlHttpPost(url, queryString, resultProcessMethod);
}
function viewSearchKeywordResult(result){
	try{
		if(document.getElementById("s_word").value!=""){
		    if(result == ""){
		        var searchKeywordDiv = document.all("searchKeyword");
		        searchKeywordDiv.innerHTML = "";
		        searchKeywordDiv.style.visibility = "hidden";
		    }else{
		        var resultList = result.split('|');
		        var viewResult = '';
				viewResult='<table border="0" cellspacing="0" cellpadding="1" width="100%">';
				viewResult += '<tr bgcolor="#efefef" height=22><td width=11><img src=/images/arrow_7.gif border=0 align=absmiddle></td><td style="font-size:8pt"><font color=336699>キーワード入力補助機能</font></td><td width=11 align="right" onmouseover="javascript:this.focus();" style="padding-right:3px"><A href="javascript:hiddenSearchKeywordResult();"><img src="/bbs/skin/freeboard/images/btn_comm_delete.gif" alt="close" border=0></A></td></tr></table>'
                viewResult += '<div style="width:100%;height:90px;overflow=auto" class="scroll_div">';
                viewResult += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
				for(i = 0 ; i < resultList.length; i++){
                    var makekey=resultList[i].split('{}');
					viewResult += '<tr name="keytb'+i+'"><td style="padding-top:2px;padding-bottom:2px;padding-left:1px;font-size:8pt;" id="keytd'+i+'" TABINDEX="'+(i+2)+'" colspan="2" onkeyup="javascript:movenext('+i+',\''+makekey[0]+'\')" onmouseover="javascript:this.focus();" onmouseout="javascript:this.blur();" onfocus="javascript:bgchk(this,1);" onblur="javascript:bgchk(this,2);" onclick="javascript:sendrealsearch(\'' + makekey[0] + '\');"  msg="'+makekey[0]+'" style="cursor:hand"><img src=/images/main2_dot_1.gif align=absmiddle hspace=5>' + makekey[1] + '</td></tr>';
                }
                viewResult += '</table></div>';
		        var searchKeywordDiv = document.all("searchKeyword");
		        searchKeywordDiv.innerHTML = viewResult;
		        searchKeywordDiv.style.visibility = "visible";
		    }
		}else{
			var searchKeywordDiv=document.getElementById("searchKeyword");
			searchKeywordDiv.innerHTML = "";
			searchKeywordDiv.style.visibility = "hidden";
		}
	}catch(e){
	}
}
function sendrealsearch(selectedKeyword){
    document.getElementById("s_word").value = selectedKeyword;
    f_send();
    document.regist.submit();
}
function hiddenSearchKeywordResult(){
    var searchKeywordDiv = document.all("searchKeyword");
    searchKeywordDiv.innerHTML = "";
    searchKeywordDiv.style.visibility = "hidden";
    viewchk = false;
}

function setKeyword(selectedKeyword){
    document.regist.s_word.value = selectedKeyword;
}
function bgchk(tar,chk){
    if(chk==1){
        tar.style.background  = "#FFF9EA";
    }else{
        tar.style.background  = "#ffffff";
    }
}
document.write('<STYLE type="text/css">');
document.write('<!--');
document.write('.scroll_div { scrollbar-face-color:#FFFFFF;');
document.write('scrollbar-highlight-color: #aaaaaa;');
document.write('scrollbar-3dlight-color: #FFFFFF;');
document.write('scrollbar-shadow-color: #aaaaaa;');
document.write('scrollbar-darkshadow-color: #FFFFFF;');
document.write('scrollbar-track-color: #FFFFFF;');
document.write('scrollbar-arrow-color: #aaaaaa;}');
document.write('-->');
document.write('</STYLE>');
