// JavaScript Document

// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject(){	
		var xmlHttp;		
		try{
				xmlHttp=new XMLHttpRequest();
		}catch(e){
			var xmlHttpVersions=new Array('Microsoft.XMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP');
			for(var i=0;i<xmlHttpVersions.length&&!xmlHttp;i++){
				try{
					xmlHttp=new ActiveXObject(xmlHttpVersions[i]);
				}
				catch(e) {}
			}
		}
		if(!xmlHttp)
			alert('Error! Cant not create object xmlHttp!');
			else return xmlHttp;
	}
	
function help_search(){
	if(xmlHttp.readyState==4||xmlHttp.readyState==0){
		var keywords=document.getElementById('kw');
		if(keywords){
			var str='?keywords='+keywords.value;
			//alert(str);
    xmlHttp.open("GET", "../ajax/help_articles.php"+str, true);  
	document.getElementById('content').innerHTML='<img width="300" height="300" src="../images/ajax-loader.gif">';
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse_search_help;
    // make the server request
    xmlHttp.send(null);
		}
	}
}
//people click the help theme link then this function will change the content of the page
function help_click(title){
	if(xmlHttp.readyState==4||xmlHttp.readyState==0){
		var keywords=document.getElementById('kw');
		if(keywords){
			var str='?keywords='+title;
			//alert(str);
    xmlHttp.open("GET", "../ajax/help_articles.php"+str, true);  
	document.getElementById('content').innerHTML='<img width="300" height="300" src="../images/ajax-loader.gif">';
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse_search_help;
    // make the server request
    xmlHttp.send(null);
		}
	}
}

function handleServerResponse_search_help(){
	if(xmlHttp.readyState==4){
			if(xmlHttp.Status==200){
				 var xmlResponse = xmlHttp.responseXML;
	  			xmlDoc = xmlResponse.documentElement;
				var result=xmlDoc.getElementsByTagName('title');
						if(result){
							var html='';
//							alert(result.length);
							for(var i=0;i<result.length;i++){
								var title=xmlDoc.getElementsByTagName('title')[i].firstChild.data;
//								var content=xmlDoc.getElementsByTagName('content')[i].firstChild.data;
								var url=xmlDoc.getElementsByTagName('url')[i].firstChild.data;
								html+='<a href=\''+url+'\'>'+title+'</a><br><br>';
							}
							if(document.getElementById('content'))
								if(html!='')
									document.getElementById('content').innerHTML=html;
								else{
var html_no_result = '';
html_no_result += '<div><img src="../images/spacer.gif" width="1" height="20" alt="" border="0"></div>';
html_no_result += '<div>';
html_no_result += '    <div><font size="-1" color="#FF0000">該当する検索結果が見当たりません。<br>';
html_no_result += 'キーワードを変更するなどして再度検索してみてください。';
html_no_result += '</font></div>';
html_no_result += '    <font size="-1" class="txgr">以下、ポイントを参考に再度検索を行うか、新しく質問をしてください。</font>';
html_no_result += '   </div>';
html_no_result += '   <div><img src="../images/spacer.gif" width="1" height="7" alt="" border="0"></div>';
html_no_result += '   <div>';
html_no_result += '    <table border="0" cellspacing="0" cellpadding="0" class="poback">';
html_no_result += '     <tr>';
html_no_result += '      <td>';
html_no_result += '       <ul class="powaku">';
html_no_result += '        <p class="potit"><font size="-1"><strong>検索のポイント</strong></font></p>';
html_no_result += '        <li class="potxt"><font size="-1">検索ワードに、誤字、脱字がないかを調べてください。</font></li>';
html_no_result += '        <li class="potxt"><font size="-1">検索ワードを、同じ意味の別の言葉に変えてください。</font></li>';
html_no_result += '        <li class="potxt"><font size="-1">絞り込みワードの数を減らして検索してください。</font></li>';
html_no_result += '       </ul>';
html_no_result += '      </td>';
html_no_result += '     </tr>';
html_no_result += '    </table>';
html_no_result += '   </div>';
				document.getElementById('content').innerHTML = html_no_result;
								}
						}
			}else
				alert('There was some problem asscessing server '+xmlHttp.statusText);
	}
}