var browser=0;	//Navigatorを調べる
if (window.opera) browser=4;	//Opera
else {
if (document.all){
   browser=3;	//MS Internet Explorer
}else {
if (document.getElementById){
  browser=1;	//Mozilla, NN6
}
else {if (document.layers) browser=2;}	//Netscape 4
}
}

okFlg = false;

// XMLHttpRequestオブジェクト生成
function createHttpRequest()
{
  var xmlhttp = null;
  if(window.ActiveXObject){
	  
		try {
	
			xmlhttp = new XMLHttpRequest();
		}catch(e1){
			try {
		      // MSXML2以降用
		      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
				try {
					// 旧MSXML用
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
			}
		}
		}
	} else if(window.XMLHttpRequest){
		// Win Mac Linux m1,f1,o8 Mac s1 Linux k3用
		xmlhttp = new XMLHttpRequest();
	} else {

  }
  if (xmlhttp == null) {
    alert("Can not create an XMLHTTPRequest instance");
  }
  return xmlhttp;
} 

// ファイルにアクセスし受信内容を確認します
function sendRequest (method, url, data, async)
{
    // XMLHttpRequestオブジェクト生成
    var xmlhttp = createHttpRequest();
    
    // 受信時に起動するイベント
    xmlhttp.onreadystatechange = function() { 
        // readyState値は4で受信完了
        if (xmlhttp.readyState == 4) { 
            //コールバック
//            callback(xmlhttp);
        }
    }
    // open メソッド
    xmlhttp.open(method, url, async);
    // HTTPリクエストヘッダを設定
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // send メソッド
    xmlhttp.send(data);

    return xmlhttp;
}
function call_php(query, elName){
    var data = "";
	
    xmlhttp = sendRequest("GET", "/ajax/get_list.php" + query, data, false);
    // readyState = 4ならレスポンスがきた後
    if (xmlhttp.readyState == 4){
	callback(xmlhttp, elName);
    }
}
// コールバック関数
function callback(xmlhttp, elName){
    var return_window = document.getElementById(elName);
	var window_container = document.getElementById(elName + 'Container');
    return_window.innerHTML = '';
	ngFlg = false;
	
    if (xmlhttp.responseText != ''){
		var php_return = xmlhttp.responseText;
		var ret_ar = php_return.split('\\n');

		if (php_return == 'error'){
			return_window.innerHTML = '';
	//		return_window.style.display = 'none';
	//	    alert('該当する住所が見つかりませんでした');
			return_window.innerHTML = '登録がありません';
		}else if(php_return == '-2'){
			window_container.style.backgroundColor='#CCCCCC';
			return_window.innerHTML = '勤務地を選択してください';
		}else if(php_return == '-1'){
			window_container.style.backgroundColor='#CCCCCC';
			return_window.innerHTML = 'ジャンルを選択してください';
		}else{
			return_window.innerHTML = php_return;
		}
    }
}
function searchShop(elType, elName){
	var taiguContainer = document.getElementById('boxTaiguContainer');
	var saContainer = document.getElementById('boxSmallAreaContainer');
	taiguContainer.style.backgroundColor='#CCCCCC';
	saContainer.style.backgroundColor='#CCCCCC';
	
	// ジャンルの選択状態を取得開始
	var genre = document.search_form.elements['gl[]'];
	var gl = Array();
	var j = 0;
	
	for (i=1; i < genre.length; i++){
		if(elType == 'genre'){
			if(elName != 'gl0'){
				genre[0].checked = false;
			}else{
				genre[i].checked = genre[0].checked;
			}
		}
		if(genre[i].checked == true){
			gl[j] = genre[i].value;
			j++;
		}
	}
	if(genre[0].checked == true){
		gl[j] = -1;
	}

    // エリアの選択状態を取得開始
	var sa = document.search_form.elements['sa[]'];
	var area = Array();
	j=0;
	if(sa){
	for (i=1; i < sa.length; i++){
		if(elType == 'area'){
			if(elName != 'area0'){
				sa[0].checked = false;
			}else{
				sa[i].checked = sa[0].checked;
			}
		}
		if(sa[i].checked == true){
			area[j] = sa[i].value;
			j++;
		}
	}
	if(sa[0].checked == true){
		area[j] = -1;
	}
	}
	
// 待遇の選択状態を取得開始
	var taigu = document.search_form.elements['taigu[]'];
	var taiguAr = Array();
	j=0;
	if(taigu){
	for (i=1; i < taigu.length; i++){
		if(elType == 'taigu'){
			if(elName != 'taigu0'){
				taigu[0].checked = false;
			}else{
				taigu[i].checked = taigu[0].checked;
			}
		}
		if(taigu[i].checked == true){
			taiguAr[j] = taigu[i].value;
			j++;
		}
	}
	if(taigu[0].checked == true){
		taiguAr[j] = -1;
	}
	}


	if (elType == 'genre'){
		var query = '?target=area&genre=' + gl + '&sa=' + area + '&taigu=' + taiguAr;
		call_php(query, 'boxSmallArea');
			
	}
	if (elType != 'taigu'){
	var query = '?target=taigu&genre=' + gl + '&sa=' + area + '&taigu=' + taiguAr;
	call_php(query, 'boxTaigu');
	}
	if(taiguAr.length > 0 && gl.length > 0){
		taiguContainer.style.backgroundColor='#CCFFFF';
	}else{
		taiguContainer.style.backgroundColor='#CCCCCC';
	}
	if(area.length > 0 && gl.length > 0){
		saContainer.style.backgroundColor='#CCFFFF';
	}else{
		saContainer.style.backgroundColor='#CCCCCC';
	}

	if( area.length > 0 && gl.length > 0){//taiguAr.length > 0 &&
		okFlg = true;
	}else{
		okFlg = false;
	}

}
function chgbg(elName, mode){
		var el = document.getElementById(elName);

	if(el == null){
		return false;
	}
	if(mode == 'on'){
		el.className= "green-box_on";
//	el.style.backgroundColor = '#fff';
	}else{
		//el.className= "green-box_off";


	el.style.backgroundColor = 'transparent';
	}

return true;
}
