/*
 * smatch.ui.js - UI library for スマッチ Web Service
 * AUTHOR: Teruhisa Ishii
 * VERSION: 1.10
 */

// everything wrapped in jQuery -
// same effect as jQuery.noConflict() for use with prototype.js
(function($){

if( typeof( Smatch ) != 'function' ) {
    Smatch = function (){};
}
if( typeof( Smatch.UI ) != 'function' ) {
    Smatch.UI = function (){};
}


/*
 * Smatch.UI.Area.Pulldown - エリア選択プルダウン（親）
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.Area ) != 'function' ) {
    Smatch.UI.Area = function (){};
}
Smatch.UI.Area.Pulldown =
Class.create( Recruit.UI.Base.Hierarchy, {
    _get_definition : function (){
        var ret = [
            { cls: Smatch.UI.SmaevoArea.Pulldown },
            { cls: Smatch.UI.Pref.Pulldown },
            { cls: Smatch.UI.City.Pulldown }
        ];
        return ret;
    }
});



/*
 * Smatch.UI.SmaevoArea.Pulldown - スマエボエリア選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.SmaevoArea ) != 'function' ) {
    Smatch.UI.SmaevoArea = function (){};
}
Smatch.UI.SmaevoArea.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-area-sel',
            name  : 'area',
            label : 'スマエボエリア'
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/area/'
        });
    },
    _get_selections_material: function (){
    	var tmpArea = this.driver.results.area;
    	//「相談」は都道府県、市郡区とは紐づかないためリストから削除
    	delete tmpArea[4];
    	tmpArea.length = 4;
        return tmpArea;
    }
});

/*
 * Smatch.UI.Pref.Pulldown - 都道府県選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.Pref ) != 'function' ) {
    Smatch.UI.Pref = function (){};
}
Smatch.UI.Pref.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-pref-sel',
            name  : 'pref',
            label : '都道府県',
            has_parent     : true,
            parent         : 'area',
            area : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/pref/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.pref;
    }
});

/*
 * Smatch.UI.City.Pulldown - 市郡区選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.City ) != 'function' ) {
    Smatch.UI.City = function (){};
}
Smatch.UI.City.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-city-sel',
            name  : 'city',
            label : '市郡区',
            has_parent     : true,
            parent         : 'pref',
            pref : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/city/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.city;
    }
});

/*
 * Smatch.UI.Category.Pulldown - カテゴリ選択プルダウン（親）
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.Category ) != 'function' ) {
    Smatch.UI.Category = function (){};
}
Smatch.UI.Category.Pulldown =
Class.create( Recruit.UI.Base.Hierarchy, {
    _get_definition : function (){
        var ret = [
            { cls: Smatch.UI.SmaevoAreaForCategory.Pulldown },
            { cls: Smatch.UI.CategoryChild.Pulldown }
        ];
        return ret;
    }
});

/*
 * Smatch.UI.SmaevoAreaForCategory.Pulldown - スマエボエリア選択プルダウン(カテゴリ用)
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.SmaevoAreaForCategory ) != 'function' ) {
    Smatch.UI.SmaevoAreaForCategory = function (){};
}
Smatch.UI.SmaevoAreaForCategory.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-area-sel2',
            name  : 'area',
            label : 'スマエボエリア'
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/area/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.area;
    }
});

/*
 * Smatch.UI.CategoryChild.Pulldown - カテゴリ選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.CategoryChild ) != 'function' ) {
    Smatch.UI.CategoryChild = function (){};
}
Smatch.UI.CategoryChild.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-category-sel',
            name  : 'category',
            label : 'カテゴリ',
            has_parent     : true,
            parent         : 'area',
            area : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/category/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.category;
    }
});

/*
 * Smatch.UI.Line.Pulldown - 沿線選択プルダウン（親）
 * VERSION 1.10
 * CHANGES
 *   2009-01-01 v1.00 released
 *   2009-05-27 v1.10 released
 */
var tempLineArea = "";
if( typeof( Smatch.UI.Line ) != 'function' ) {
    Smatch.UI.Line = function (){};
}
Smatch.UI.Line.Pulldown =
Class.create( Recruit.UI.Base.Hierarchy, {
    _get_definition : function (){
        var ret = [
            { cls: Smatch.UI.SmaevoAreaForLineArea.Pulldown },
            { cls: Smatch.UI.LineArea.Pulldown },
            { cls: Smatch.UI.LineChild.Pulldown },
            //{ cls: Smatch.UI.Station.Pulldown }
            { cls: Smatch.UI.Station.Checkbox }
        ];
        return ret;
    }
});



/*
 * Smatch.UI.SmaevoAreaForLineArea.Pulldown - スマエボエリア選択プルダウン(沿線方面用)
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.SmaevoAreaForLineArea ) != 'function' ) {
    Smatch.UI.SmaevoAreaForLineArea = function (){};
}
Smatch.UI.SmaevoAreaForLineArea.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-area-sel3',
            name  : 'area',
            label : 'スマエボエリア'
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/area/'
        });
    },
    _get_selections_material: function (){
    
    	var area = this.driver.results.area;
    	//「関東」、「関西」以外は沿線方面、沿線とは紐づかないためリストから削除
    	var tmpArea = new Array(2);
    	tmpArea[0] = area[0];
    	tmpArea[1] = area[2];
        return tmpArea;
    }
});

/*
 * Smatch.UI.LineArea.Pulldown - 沿線方面選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-01-01 v1.00 released
 */
if( typeof( Smatch.UI.LineArea ) != 'function' ) {
    Smatch.UI.LineArea = function (){};
}
Smatch.UI.LineArea.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-line-area-sel',
            name  : 'line_area',
            label : '沿線方面',
            has_parent     : true,
            parent         : 'area',
            area : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/line_area/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.line_area;
    }
});

/*
 * Smatch.UI.LineChild.Pulldown - 沿線選択プルダウン
 * VERSION 1.10
 * CHANGES
 *   2009-01-01 v1.00 released
 *   2009-05-27 v1.10 released
*/
if( typeof( Smatch.UI.LineChild ) != 'function' ) {
    Smatch.UI.LineChild = function (){};
}
Smatch.UI.LineChild.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-line-sel',
            name  : 'line',
            label : '沿線',
            has_parent     : true,
            parent         : 'line_area',
            line_area : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/line/'
        });
    },
    _get_selections_material: function (){
    	//tempLineAreaは駅チェックボックス生成の際に使用する。
    	tempLineArea = this.line_area;
        return this.driver.results.line;
    }
});

/*
 * Smatch.UI.Station.Pulldown - 駅選択プルダウン
 * VERSION 1.00
 * CHANGES
 *   2009-05-27 v1.00 released
 */
if( typeof( Smatch.UI.Station ) != 'function' ) {
    Smatch.UI.Station = function (){};
}
Smatch.UI.Station.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-station-sel',
            name  : 'station',
            label : '駅',
            has_parent : true,
            parent : 'line',
            line : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/station/'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.station;
    },
    _fix_params: function ( prm ){
        //recruitUIでは親が1つしか指定できないため、沿線方面コードを独自にセット
    	prm.line_area = tempLineArea;
        return prm;
    }
    
});

/*
 * Smatch.UI.Station.Checkbox - 駅選択チェックボックス
 * VERSION 1.00
 * CHANGES
 *   2009-05-27 v1.00 released
 */
 
if( typeof( Smatch.UI.Station ) != 'function' ) {
    Smatch.UI.Station = function (){};
}
Smatch.UI.Station.Checkbox =
Class.create( Recruit.UI.Base.Checkbox.JSONP, {
    _get_def_props: function (){
        return {
            id    : 'smatch-station-sel',
            name  : 'station',
            label : '駅',
            template    : 'table_3c',
            has_parent : true,
            parent : 'line',
            line : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : 'http://api.smatch.jp/station/'
        });
    },
    _get_selections_material: function (){
    	//divエレメントのdisableがtrueになってしまうので、
    	//ここでdisable属性をはずす（IE向けの対応）
    	$(this.elm[0]).removeAttr("disabled");
        return this.driver.results.station;
    },
    _fix_params: function ( prm ){
        //recruitUIでは親が1つしか指定できないため、沿線方面コードを独自にセット
    	prm.line_area = tempLineArea;
        return prm;
    }
    
});


// end of jQuery no-conflict wrapper
})(jQuery);


