//---------------------------------------------------------------------------
// 通常の手順以外のボタン送信用オブジェクト
//---------------------------------------------------------------------------
var SearchArea2 = Class.create();

SearchArea2.prototype = {
  prefId: "",
  sendPath: "",
  isCheckDisplay: false,
  // コンストラクタ
  //
  initialize: function(prefId) {
	this.prefId = prefId;
	Event.observe($(this.prefId), 'change', this.changePref.bindAsEventListener(this));

	Event.observe($("stickbtn"), 'click', this.searchCheckDisplay.bindAsEventListener(this));
    var pathAry= document.location.pathname.split("/");
	
	/*
	for (i = 1; i < pathAry.size() - 3; i++) {
	  this.sendPath += "/" + pathAry[i];
	}
	*/
	var isAdmin = false;
	var isNumeric = false;
	pathAry.each (function (value) {

	  if (value.match(/admin/)) {
		isAdmin = true;
	  } else if (value.match(/\d+/)) {
		isNumeric = true
	  }
	});
	var loopSize = 0;
	if (isAdmin == true) {
	  loopSize = pathAry.size() - 3;
	} else {
	  loopSize = pathAry.size() - 2;
	}
	if (isNumeric == true) {
	  loopSize--;
	}

	for (i = 1; i < loopSize; i++) {
	  this.sendPath += "/" + pathAry[i];
	}
  },

  // 送信する。
  changePref: function(event) {
    var prefElm = $(this.prefId);
	var index = prefElm.selectedIndex;
	var oReq = new Ajax.Updater("areaId",
								'/advertisement/area_list/' + prefElm.options[index].value,
								{method: "post",
								 onComplete: null,
//								 evalScripts:true,asynchronous: true,
								 requestHeaders:["If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT"]});




  },
  
  searchCheckDisplay: function(event) {
	if (this.isCheckDisplay == false) {
	  $("stickbox").style.display = 'block';
	} else {
	  $("stickbox").style.display = 'none';
	}
	this.isCheckDisplay = !this.isCheckDisplay;
	Event.stop(event);
  }
/*
  ,
  searchCheckHide: function(event) {
	$("stickbtn").style.display = 'block';
	$("stickbox").style.display = 'none';
	Event.stop(event);
  }
*/
}

//---------------------------------------------------------------------------
// ページロード完了時に多言語ブラウザ自動判定処理実行
//---------------------------------------------------------------------------

Event.observe (window, 'load', function() {
  if ($("prefId") && $("areaId") && $("stickbtn") && $("stickbox"))
	oAddEvent = new SearchArea2("prefId");

}, false);

