// JavaScript Document

var r = 0;
try{
r ;
}
catch(e){
}

//ファイルを読み込み表示する関数
function searchPopup(){
	//関数によってhttpObjという非同期通信オブジェクトを生成
	httpObj = createXMLHttp();
	//オブジェクトが生成された場合
	if(httpObj){
	//通信発生時の処理
	httpObj.onreadystatechange = function (){
			//readyState=通信状態 1.openが呼ばれていない2.openは呼ばれたがsendが呼ばれていない3.データの一部を受け取った4.全データ読み込み完了
			//status=状態200.リクエスト成功401.認証が必要で、認証されなかった404.対象データがない500.INTERNALサーバーエラー
			if(httpObj.readyState == 4 && httpObj.status ==200){
				//responseText=受信したテキストデータ。XMLデータの場合はresponseXML
				if(httpObj.responseText == ""){
					document.getElementById("pop_result").style.display = "none";
				}else{
					document.getElementById("pop_result").style.display = "block";
					document.getElementById("pop_result").innerHTML = httpObj.responseText;
				}
			}
		}
		//送信処理open(メソッド・URL・送信フラグ(trueだと非同期))
		httpObj.open("get","/search/soft-ajax.php?search=" + encodeURI(document.getElementById("searchtxt").value),true);
		//送信データ
		httpObj.send(null);
	}
	//オブジェクト生成失敗
}
//XMLHTTPオブジェクト作成。オブジェクトの概要を示す
function createXMLHttp(){
	//例外処理(エラー発生時の処理)
	try{
		//エラーを引き起こす可能性のある命令
		//IE7.他ブラウザで非同期通信オブジェクト作成
		return new XMLHttpRequest;
	//エラー発生時処理eはエラー内容を自動的に受け取る引数
	}catch(e){
		try{
			//IE6で非同期通信オブジェクト作成
			return new ActiveXObject("Microsoft.XMLHTTP");
		//どれもできなかったらヌル
		}catch(e){
	
		}
	}

}

//--------------環境設定-------------------//



//--------------/環境設定------------------//
	
	
//タイマー用
var timer = 0;
//タイムカウント用
var count = 600;


//ポップアップウインドウマウスアウト時、消えるまでを計るタイマーです。
function popupClose(){
	document.getElementById("pop_result").style.display = "none";
	clearInterval(timer);
}


//ページの要素に予め仕込んでおく内容です。
function popup(){

	//各要素をページ末尾に隠し配置(プルダウン表示用)しています。
	
	var element = document.createElement("div");
	element.id =  "pop_result"; 
	element.className = "popmenu";
	//配列内容(ポップアップ内HTML)を参照しています。
	element.innerHTML = '';
	//element.style.display = "none";
	element.onmouseover = function(){
		clearInterval(timer);
	}
	element.onmouseout = function(){
		clearInterval(timer);
		timer = setInterval("popupClose()",count);
	}
	
	//element.style.display = "block";
	
	var objBody = document.getElementsByTagName("body").item(0); 
	objBody.appendChild(element);
	
	
	if(navigator.userAgent.indexOf("MSIE 6.0") != -1 || navigator.userAgent.indexOf("MSIE 7.0") != -1){
		if(location.href.indexOf("soft.php") != -1){
			element.style.top = document.getElementById("container").offsetTop + document.getElementById("wrap").offsetTop + document.getElementById("softsearch").offsetTop + 34 +"px";
			element.style.left = document.getElementById("container").offsetLeft + 256 + "px";
		}else{
			element.style.top = document.getElementById("container").offsetTop + document.getElementById("wrap").offsetTop + document.getElementById("topsearch").offsetTop + 34 +"px";
			element.style.left = document.getElementById("container").offsetLeft + document.getElementById("wrap").offsetLeft + document.getElementById("searchtxt").offsetLeft + "px";
		}
	}else if(navigator.userAgent.indexOf("MSIE") != -1){
		element.style.top = document.getElementById("searchtxt").offsetTop + 22 + "px";
		element.style.left = document.getElementById("searchtxt").offsetLeft + "px";
	}else{
		element.style.top = document.getElementById("searchtxt").offsetTop + 23 + "px";
		element.style.left = document.getElementById("searchtxt").offsetLeft + "px";
	}
	element.style.display = "none";
	
	document.getElementById("searchtxt").onkeyup = function(){
		searchPopup();
	}
	
	document.getElementById("submit").onclick = function(){
		if(document.getElementById("searchtxt").value == "" || document.getElementById("searchtxt").value == "ソフト名、メーカー名などを入力"){
			document.getElementById("searchtxt").style.background = "#fffeef";
			alert("検索キーワードを入力してください。");
			return false;
		}
	}
	
	if(document.getElementById("searchtxt").value == "" || document.getElementById("searchtxt").value == "ソフト名、メーカー名などを入力"){
		document.getElementById("searchtxt").value = "ソフト名、メーカー名などを入力";
		document.getElementById("searchtxt").style.color = "#999999";
	}
	
	document.getElementById("searchtxt").onclick = function(){
		if(this.value == "ソフト名、メーカー名などを入力"){
			this.value = "";	
		}
		this.style.color = "#333333";
	}
	
	document.getElementById("searchtxt").onmouseout = function(){
		clearInterval(timer);
		timer = setInterval("popupClose()",count);
	}
}


//onloadイベント処理
try{
	//For IE
    window.attachEvent("onload",popup);
}catch(e){
	//For FireFox & Safari & Opera
    window.addEventListener("load",popup, false);
}

document.onclick = function(){
	popupClose();
}
