var _cmb = new function(){
	this.url = '/ranking/cmb.php';
	this.request = function(mode, sflg){
		var parameters = null;
		if(sflg)
			parameters = $H({mode:mode, b:$F("b"), s:$F("s")}).toQueryString()
		else
			parameters = $H({mode:mode, b:$F("b")}).toQueryString()
		var ajax = new Ajax.Request(this.url, {
			method:'get',
			parameters:parameters,
			onComplete:function(res){ _cmb._response(res, mode); }
		});
	}
	this._response = function(res, mode){
		eval('var data = ' + res.responseText)
		_cmb._load((mode == 1) ? "b" : "s", data);
	}
	this._load = function(id, data){
		$(id).options.length = 0;
		for(var i = 0 ; i < data.length ; i++){
			$(id).options.length++;
			$(id).options[i].value = data[i].cd;
			$(id).options[i].text = data[i].text;
			$(id).options[i].selected = data[i].select;
		}
	}
}
window.onload = function(){
	$("b").onchange = _chgBr;
	_cmb.request(1, true);
	_cmb.request(2, true);
	if($("map")){
		var el = _findChild($("map"), "A");
		el.each(function(e){ if(e.id) e.onclick = _chgAr; });
	}
}
var _chgBr = function(){
	_cmb.request(2);
}
var _chgAr = function(){
	this.id.match(/mapa(.*)/);
	var p = "/car/rank" + $F("b").toLowerCase() + $F("s").toLowerCase() + RegExp.$1 + "/";
	window.location.href = p;
	return false;
}
function onrank(){
	if(!$F("b")){
		alert("ブランドを選択してください。");
		return false;
	}
	var p = "/car/rank" + $F("b").toLowerCase() + $F("s").toLowerCase() + $F("k").toLowerCase() + "/";
	window.location.href = p;
	return false;
}
function onmap(mode){
	if(!$F("b")){
		alert("ブランドを選択してください。");
		return false;
	}
	if(mode) $("map").style.display = "block";
	else $("map").style.display = "none";
	return false;
}
function _findChild(obj, type){
    var childs = new Array;
    for(var i = 0 ; i < obj.childNodes.length ; i++){
        if(obj.childNodes[i].nodeName == type) childs.push(obj.childNodes[i]);
        var r = _findChild(obj.childNodes[i], type);
        for(var j = 0 ; j < r.length ; j++){
            childs.push(r[j]);
        }
    }
    return childs;
}

