function chg_pref() {
	$('machi').options.length = 1;

	var pref_kana = $('pref').value;

	var url = "/common/area_ajax.php?pref_kana=" + pref_kana;

	exec_ajax( url );

	return;

}



function copy_select_elem( from_id, to_id ) {

	$(to_id).options.length = $(from_id).options.length;

	for( i = 0; i < $(from_id).options.length; i++ ) {

		$(to_id).options[i].value = $(from_id).options[i].value;

		$(to_id).options[i].text = $(from_id).options[i].text;

		$(to_id).options[i].selected = $(from_id).options[i].selected;

	}

	return;

}



function chg_brand_pref(top_or_bottom) {

	if( top_or_bottom == 'top' ) copy_select_elem( 'pref', 'pref_bottom' );

	if( top_or_bottom == 'bottom' ) copy_select_elem( 'pref_bottom', 'pref' );

	chg_tutor_pref();

	return;

}



function chg_brand_s_place(top_or_bottom) {

	if( top_or_bottom == 'top' ) copy_select_elem( 'machi', 'machi_bottom' );

	if( top_or_bottom == 'bottom' ) copy_select_elem( 'machi_bottom', 'machi' );

	return;

}



function chg_tutor_pref() {

	$('machi').options.length = 1;

	if( $('machi_bottom')) $('machi_bottom').options.length = 1;

	var pref_cd = $('pref').value;

	var tutor_id = $('tutor_id').value;

	var url = "/common/tutor_area_ajax.php?pref_cd=" + pref_cd + "&tutor_id=" + tutor_id;

	exec_ajax( url );

	return;

}



function readComplete()

{

	if( httpObj.readyState != 4 ) {

		return;

	}

	if( httpObj.status != 200 ) {

		return;

	}

	xmlData = httpObj.responseXML;

	s_place_cd_len = xmlData.getElementsByTagName("s_place_cd").length;

	s_place_name_len = xmlData.getElementsByTagName("s_place_name").length;

	if( s_place_cd_len == 0 || s_place_name_len == 0 ) {

		return;

	}

	if( s_place_cd_len != s_place_name_len ) {

		return;

	}

        var selected_value = $('selected_s_place').value;

	$('machi').options.length = s_place_cd_len + 1;

	for( i = 0; i < s_place_cd_len; i++ ) {

		s_place_cd = xmlData.getElementsByTagName("s_place_cd")[i].childNodes[0].nodeValue;

		s_place_name = xmlData.getElementsByTagName("s_place_name")[i].childNodes[0].nodeValue;



		$('machi').options[i+1].value = s_place_cd;

		$('machi').options[i+1].text = s_place_name;

//		alert(s_place_cd);

		if(selected_value && selected_value == s_place_cd ){

			$('machi').options[i+1].selected = true ;

		}

	}



	return;

}



function exec_ajax( url ) {

	httpObj = createXMLHttpRequest( readComplete );

	if (!httpObj) {

		return;

	}

	httpObj.open("GET",url );

	httpObj.onreadystatechange = readComplete;

	httpObj.send(null);

	return;

}



function createXMLHttpRequest() {

	if(window.XMLHttpRequest) {

		xmlHttp = new XMLHttpRequest();

	} else if(window.ActiveXObject) {

		// IE6ÈO

		try {

			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

		} catch(e) {

			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

		}

	}

	return xmlHttp;

}

function chk_input(mode){

  	var pref_value = $('pref').value;

  	var machi_value = $('machi').value;



	if($('pref').value == "" || $('machi').value == ""){

	//	alert("都道府県、及び市区町村は必ず指定してください");

//           $('msg').style.display = 'block';

		$('msg').className = "p_part1_01 p_eS_on";

           chg_pref();

	   return;

	}

	$('mode').value =mode;

	document.post.submit();

	return;



}



function chk_input2(mode){



  	var pref_value = $('pref').value;

  	var machi_value = $('machi').value;



	if($('pref').value == "" || $('machi').value == ""){

	alert("都道府県、及び市区町村は必ず指定してください");

       //    $('msg').style.display = 'block';

           chg_pref();

	   return;

	}

	$('mode').value =mode;

	document.post.submit();

	return;



}



function chk_input3(mode){

  	var pref_value  = $('pref').value;

  	var machi_value = $('machi').value;

  	var pro_value   = "";
	if( document.fm_search_sort.mode.checked == true ) {
		pro_value = "pro";
	}



	if($('pref').value == "" || $('machi').value == ""){

		alert("都道府県、及び市区町村は必ず指定してください");

		chg_pref();

	   return;

	}



	location.href = "/search/" + pref_value + "/" + machi_value + pro_value + ".html";

	return;

}



function submit_cart(s_place_cd) {

	var ids = get_hidden_val( 'chk_tutor' );

	var limit = 3;

	//	alert(s_place_cd);

	var id_array= new Array();

	if( ids != "" ) {

		id_array = ids.split(",");

	}

	if(id_array.length > limit){

		    alert("資料請求は最大3社までとなっております。");

		return false;

	}

	var ajax = new Ajax.Request(

             "/cart/count.php?bbb="+Math.random() ,

               {"method":"get",

		onComplete:function(res){

		eval("var count=" +  res.responseText);

		if((id_array.length  + count) > limit ){

		    alert("資料請求は最大3社までとなっております。資料請求リストをご確認ください。");

		    return false;

		}

		var url  = '/cart/cart.php?tutor_id=' + ids + '&s_place_cd=' + s_place_cd;

	//	alert(url);

		location.href = url;

		}

          });



	return false;

}



function chg_chk_tutor( itm ) {

	chk_all = document.getElementsByClassName('chk_tutor');

	chk_cnt = 0;

	chk_flg = false;

	if( judge_chk_tutor_img_off( itm )) {

		chk_flg = true;

	}

	chk_arr = new Array();

	for( i = 0; i < chk_all.length; i++ ) {

		if( chk_flg ) {

			if( judge_chk_tutor_img_off( chk_all[i].id )) {

				chk_tutor_img_on( chk_all[i].id );

			}

		} else {

			if( judge_chk_tutor_img_on( chk_all[i].id )) {

				chk_tutor_img_off( chk_all[i].id );

			}

		}

	}

	return false;

}



function get_hidden_val( itm ) {

	if( itm == "chk_tutor" ) {

		chk_all = document.getElementsByClassName('a_cl01_on');

	} else {

		chk_all = document.getElementsByClassName(itm);

	}

	chk_cnt = 0;

	chk_arr = new Array();

	for( i = 0; i < chk_all.length; i++ ) {

		if( judge_chk_tutor_img_off( chk_all[i].id )) {

			continue;

		}



		id = "";

		if( chk_all[i].id.match(/^chk_tutor_([0-9]+)$/) ) {

			id = chk_all[i].id.match(/^chk_tutor_([0-9]+)$/)[1];

		}



		if( id != "" ) {

			chk_arr.push( id );

			chk_cnt++;

		}

	}

	if( chk_cnt == 0 ) {

		return "";

	}



	return chk_arr.join(",");

}





function chg_chk_tutor_itm( itm ) {

	chk_all = document.getElementsByClassName('chk_tutor');

	chk_cnt = 0;

	chk_flg = false;

	if( $(itm).checked ) {

		chk_flg = true;

	}

	chk_arr = new Array();

	for( i = 0; i < chk_all.length; i++ ) {

		if( chk_all[i].disabled ) continue;

		chk_all[i].checked = chk_flg;

	}

	if( chk_flg ) {

		class_name = 'a_cl01_of';

		chg_class_name = "a_cl01_on";

	} else {

		class_name = 'a_cl01_on';

		chg_class_name = "a_cl01_of";

	}

	chk_all_img = document.getElementsByClassName(class_name);

	var img_len = chk_all_img.length + 0;

	var a = new Array();

	for( i = 0; i < img_len; i++ ) {

		a[i] = chk_all_img[i].id;

	}

	for( i = 0; i < img_len; i++ ) {

		if( $(a[i]).style.display == "none" ) continue;

		$(a[i]).className = chg_class_name;

	}



	return true;

}



/*----- 上記に変更する

function chg_chk_tutor_itm( img_id ) {

	if( judge_chk_tutor_img_off( img_id )) {

		chk_tutor_img_on( img_id );

		return false;

	}

	if( judge_chk_tutor_img_on( img_id )) {

		chk_tutor_img_off( img_id );

		return false;

	}



	return false;

}

----------------*/



function chg_chk_box( itm, id) {

	if( $(itm).className == "a_cl01_on_checked" ) {

		return delCart(id);

	}

	if( $(itm).className == "a_cl01_of" ) {

		return addCart(id);

	}

	return true;

}





function judge_chk_tutor_img_on( img_id ) {

	if( $(img_id).src == get_img_name('/common/images/list/check_formimg_ov.gif')) {

		return true;

	}

	return false;

}



function judge_chk_tutor_img_off( img_id ) {

	if( $(img_id).src == get_img_name('/common/images/list/check_formimg.gif')) {

		return true;

	}

	return false;

}



function chk_tutor_img_on( img_id ) {

	$(img_id).src = '/common/images/list/check_formimg_ov.gif';

	return;

}

function chk_tutor_img_off( img_id ) {

	$(img_id).src = '/common/images/list/check_formimg.gif';

	return;

}



function get_img_name( img_name ) {

	return location.protocol + '//' + location.host + img_name;

}




