var item_type;

//都道府県変更に応じて市区町村を変更
function add_subload(elm){
var form = elm.form;
elm.blur();

  $(".addsub_span",form).html('<img height="16px" width="50px" src="./img/ajax-minibar.gif" />');
  
   jQuery.ajax({
      url : 'ajax.php' ,
      type : 'POST',
      dataType : "text",
	  data : "post=load_addsub&js=true&id="+form.adds.options[ form.adds.selectedIndex ].value,
      success : function(res){ $(".addsub_span",form).html(res);},
      error   : function(xml, status, e){$(".addsub_span",form).attr('id','error_msg'); $(".addsub_span",form).html("通信エラー"); }
    });
//    if( form.line1 || form.line2 || form.line3 || form.line10 ){
//        line_load(elm);
//    }
}

function line_load(elm){
return;
  var form = elm.form;
  elm.blur();
  
  if(form.type){
    if(form.type.length){
      for(i=0;i<form.type.length;i++){
        if(form.type[i].checked){ item_type = (form.type[i].value); break; }
      }
    }else{
      item_type = form.type.value;
    }
  }
  
  var type_parm = "";
  if(item_type)
      type_parm = "&type=" + item_type;

  jQuery.ajax({
    url : 'ajax.php' ,
    type : 'POST',
    dataType : "json",
    data : "post=load_line&js=true&id="+form.adds.options[ form.adds.selectedIndex ].value+type_parm,
    success : function(res){ 
      if(form.line1){
          $(form.line1).removeOption(/./);
          $(form.line1).addOption(res, false);
          if(form.station1){$(form.station1).removeOption(/./);}
      }
      if(form.line2){
          $(form.line2).removeOption(/./);
          $(form.line2).addOption(res, false);
          if(form.station2){$(form.station2).removeOption(/./);}
      }
      if(form.line3){
          $(form.line3).removeOption(/./);
          $(form.line3).addOption(res, false);
          if(form.station3){$(form.station3).removeOption(/./);}
      }
      if(form.line10){
          $(form.line10).removeOption(/./);
          $(form.line10).addOption(res, false);
          if(form.station10){$(form.station10).removeOption(/./);}
      }
    },
    error   : function(xml, status, e){$(".addsub_span",form).attr('id','error_msg'); $(".addsub_span",form).html("通信エラー"); }
  });
  
}

function station_load(elm,s_name){
var form = elm.form;
elm.blur();

  if(form.type){
    for(i=0;i<form.type.length;i++){
      if(form.type[i].checked){ item_type = (form.type[i].value); break; }
    }
  }
  
  var type_parm = "";
  if(item_type)
      type_parm = "&type=" + item_type;
      
  jQuery.ajax({
    url : 'ajax.php' ,
    type : 'POST',
    dataType : "json",
    data : "post=load_station&js=true&id="+elm.options[ elm.selectedIndex ].value+"&pref_id=PF40"+type_parm,
    success : function(res){
      $(s_name).removeOption(/./);
      $(s_name).addOption(res, false);
    },
    error   : function(xml, status, e){
        $(".addsub_span",form).attr('id','error_msg');
        $(".addsub_span",form).html("通信エラー");
    }
  });
}

function changeMaps(id){
	document.getElementById('googleMapArea' + id).style.display='block';
	document.getElementById('changeArea' + id).style.display='none';
      document.getElementById('toggleButton' + id + 'Left').innerHTML  = '<a href="javascript:changeImages(\''+id+'\');"><img src="sendmail_img/btn_pic_on.gif" alt="" /></a>';
      document.getElementById('toggleButton' + id + 'Right').innerHTML = '<img src="sendmail_img/btn_map_off.gif" alt="" />';
}

function changeImages(id){
	document.getElementById('googleMapArea' + id).style.display='none';
	document.getElementById('changeArea' + id).style.display='block';
      document.getElementById('toggleButton' + id + 'Left').innerHTML  = '<img src="sendmail_img/btn_pic_off.gif" alt="" />';
      document.getElementById('toggleButton' + id + 'Right').innerHTML = '<a href="javascript:changeMaps(\''+id+'\');"><img src="sendmail_img/btn_map_on.gif" alt="" /></a>';
}

function bookmark(b,p){

	e = document.getElementsByName('id[]');
	u = '';
	l = 0;

	for(i = 0 ; i < e.length ; i++)
	{
		if(e[i].checked)
			{l++;}
	}

	if(!l)
	{
		alert('チェックボックスが空です！');
		return;
	}
	else
	{
		if('true' == b)
			alert(l + '個の物件をチェックリストに登録しました');
		else
			alert(l + '個の物件をチェックリストから外しました');
	}

	for(i = 0 ; i < e.length ; i++)
	{
		if(e[i].checked)
			{u += 'id[]=' + e[i].value + '&';}
	}

	window.location.href = 'bookmark.php?' + u + 'bookmark=' + b + '&page=' + p;
}

function viewPrint(b,p)
{
	e = document.getElementsByName('id[]');
	u = '';

	for(i = 0 ; i < e.length ; i++)
	{
		if(e[i].checked)
			{u += 'id[]=' + e[i].value + '&';}
	}

	window.location.href = 'info.php?type=items&print=true&' + u;
}
