// STOCK CAFE Labs Gadgets "CORE" with YUI Library [20071225]
YAHOO.namespace('SCL');

// stockcafe url
YAHOO.SCL.SCAFE_URL = 'http://www.stockcafe.jp/';

// last oid
YAHOO.SCL.lastOID = 0;

//
// Gadget class
//
YAHOO.SCL.Gadget = function(id, args) {
    this.oid = ++YAHOO.SCL.lastOID;

    this.id = id ? id : this.CLASSNAME.toLowerCase() + this.oid;

    this.init(args);
}

// static values
YAHOO.SCL.Gadget.prototype.CLASSNAME = 'SCL_Gadget';

// default attributes
YAHOO.SCL.Gadget.prototype.DEFAULTS = {};

// instance variables


// init method
YAHOO.SCL.Gadget.prototype.init = function(args) {
    this.attrs = {};
    for (var i in this.DEFAULTS) {
        this.attrs[i] = this.DEFAULTS[i];
    }

    if (args) {
        for (var i in args) {
            this.attrs[i] = args[i];
        }
    }
};

// espcae html
YAHOO.SCL.Gadget.prototype.escapeHTML = function(str) {
    var CHAR_AMP = "%AMP%";

    str = this.replaceAll(str, "&", CHAR_AMP);
    str = this.replaceAll(str, CHAR_AMP, "&amp;");
    
    str = this.replaceAll(str, "<", "&lt;");
    str = this.replaceAll(str, ">", "&gt;");
    str = this.replaceAll(str, '"', "&quot;");  

    return str;
};
// replace all
YAHOO.SCL.Gadget.prototype.replaceAll = function(str, oldWord, newWord) {
    while (str.indexOf(oldWord) >= 0) {
	str = str.replace(oldWord, newWord);
    }
    return str;
};


//
// Desktop class
//
YAHOO.SCL.Desktop = function(id, args) {
    YAHOO.SCL.Desktop.superclass.constructor.call(this, id, args);
};
YAHOO.lang.extend(YAHOO.SCL.Desktop, YAHOO.SCL.Gadget);

// static values
YAHOO.SCL.Desktop.prototype.CLASSNAME = 'SCL_Desktop';

// default attributes
YAHOO.SCL.Desktop.prototype.DEFAULTS = {
    x:         0,
    y:         0,
    position:  'absolute',
    zIndex:    1000
};

// instance variables
YAHOO.SCL.Desktop.prototype.gadgets = [];

// initialize method
YAHOO.SCL.Desktop.prototype.init = function(args) {
    YAHOO.SCL.Desktop.superclass.init.call(this, args);
    this.gadgets = [];
};

// render method
YAHOO.SCL.Desktop.prototype.render = function() {
    this.makeDOM();
    this.makeWidget();
    this.adjustStyle();
};

// makeDOM method
YAHOO.SCL.Desktop.prototype.makeDOM = function() {
    var desk = document.getElementById(this.id);
    if (desk == undefined) {
        desk = document.createElement('div');
        desk.id = this.id;
        document.body.appendChild(desk);
    }
    else {
        desk.innerHTML = '';
    }
    YAHOO.util.Dom.addClass(this.id, YAHOO.SCL.Desktop.prototype.CLASSNAME);

    YAHOO.util.Dom.setStyle(desk, 'left', this.attrs.x + 'px');
    YAHOO.util.Dom.setStyle(desk, 'top',  this.attrs.y + 'px');
    YAHOO.util.Dom.setStyle(desk, 'position', this.attrs.position);
    YAHOO.util.Dom.setStyle(desk, 'z-index', this.attrs.zIndex);

//     var head = document.createElement('div');
//     head.id = this.id + '_head';
//     head.className = 'hd';
//     desk.appendChild(head);

//     var body = document.createElement('div');
//     body.id = this.id + '_body';
//     body.className = 'bd';
//     desk.appendChild(body);

//     var foot = document.createElement('div');
//     foot.id = this.id + '_foot';
//     foot.className = 'ft';
//     desk.appendChild(foot);
};

// makeWidget method
YAHOO.SCL.Desktop.prototype.makeWidget = function() {
//    this.overlay = new YAHOO.widget.Overlay(this.id, this.attrs);
//    this.overlay.render();
};

// adjustStyle method
YAHOO.SCL.Desktop.prototype.adjustStyle = function() {
// BAD for Opera
//      YAHOO.util.Dom.setStyle(this.id, 'width', 
//                              YAHOO.util.Dom.getViewportWidth());
//      YAHOO.util.Dom.setStyle(this.id, 'height', 
//                              YAHOO.util.Dom.getViewportHeight());
};

// indexOf method
YAHOO.SCL.Desktop.prototype.indexOf = function(gadget) {
    var id = YAHOO.lang.isObject(gadget) ? gadget.id : gadget;
    
    for (var i = 0; i < this.gadgets.length; i++) {
	if (YAHOO.lang.isObject(this.gadgets[i]) && this.gadgets[i].id == id) {
	    return i;
	}
    }

    return -1;
}

// get method
YAHOO.SCL.Desktop.prototype.get = function(gadget) {
    var index = this.indexOf(gadget);
    if (index < 0)
	return null;

    return this.gadgets[index];
}

// put method
YAHOO.SCL.Desktop.prototype.put = function(gadget) {
    if (!YAHOO.lang.isObject(gadget))
	return;

    var old = this.get(gadget.id);
    if (old)
	this.remove(old);

    var desk = document.getElementById(this.id);

    var dom = document.createElement('div');
    dom.id = gadget.id;
    desk.appendChild(dom);

    this.gadgets.push(gadget);
};

// remove method
YAHOO.SCL.Desktop.prototype.remove = function(gadget) {
    var index = this.indexOf(gadget);
    if (index < 0)
	return;

    if (!YAHOO.lang.isObject(gadget))
	gadget = this.get(gadget);

    gadget.close();

    this.gadgets[index] = null;

    var desk = document.getElementById(this.id);
    var dom  = document.getElementById(gadget.id);
    var domC = document.getElementById(gadget.id + '_c');
    if (domC) {
	desk.removeChild(domC);
    }
    else if (dom) {
	desk.removeChild(dom);
    }
};

// class methods(wrapper)
YAHOO.SCL.Desktop.indexOf = function(gadget) {
    return -1;
};
YAHOO.SCL.Desktop.get = function(gadget) {
    return null;
};
YAHOO.SCL.Desktop.put = function(gadget) {
    if (!YAHOO.SCL._desktop) {
        YAHOO.SCL._desktop = new YAHOO.SCL.Desktop();
        YAHOO.SCL._desktop.render();
    }
    return YAHOO.SCL._desktop.put(gadget);
};
YAHOO.SCL.Desktop.remove = function(gadget) {
    // do nothing
};

//
// Window class
//
YAHOO.SCL.Window = function(id, args) {
    YAHOO.SCL.Window.superclass.constructor.call(this, id, args);
};
YAHOO.lang.extend(YAHOO.SCL.Window, YAHOO.SCL.Gadget);

// static values
YAHOO.SCL.Window.prototype.CLASSNAME = 'SCL_Window';

// default attributes
YAHOO.SCL.Window.prototype.DEFAULTS = {
    x:                   null,
    y:                   null,
    width:               '170px',
    height:              '190px',
    zIndex:              null,
    constraintoviewport: false,
    underlay:            'none',
    close:               false,
    draggable:           false,
    effect:              null
};

// instance variables
YAHOO.SCL.Window.prototype.title = '';
YAHOO.SCL.Window.prototype.credit = '';

// init method
YAHOO.SCL.Window.prototype.init = function(args) {
    YAHOO.SCL.Window.superclass.init.call(this, args);

    if (!args)
        return;

    if (args['title'] != undefined)
        this.title = args['title'];
    if (args['credit'] != undefined)
        this.credit = args['credit'];
};

// render method
YAHOO.SCL.Window.prototype.render = function() {
    this.makeDOM();
    this.makeWidget();
    this.adjustStyle();
};

// destroy method
YAHOO.SCL.Window.prototype.destroy = function() {
    if (this.panel)
	this.panel.destory();
};

// makeDOM method
YAHOO.SCL.Window.prototype.makeDOM = function() {
    var panel = document.getElementById(this.id);
    if (panel == undefined) {
        panel = document.createElement('div');
        panel.id = this.id;
        document.body.appendChild(panel);
    }
    else {
        panel.innerHTML = '';
    }
    YAHOO.util.Dom.addClass(panel, YAHOO.SCL.Window.prototype.CLASSNAME);

    var head = document.createElement('div');
    head.id = this.id + '_head';
    head.className = 'hd';
    panel.appendChild(head);

    var tl = document.createElement('div');
    tl.className = 'tl';
    head.appendChild(tl);

    var title = document.createElement('span');
    title.id = this.id + '_title';
    title.innerHTML = this.title;
    head.appendChild(title);

    var tr = document.createElement('div');
    tr.className = 'tr';
    head.appendChild(tr);

    var body = document.createElement('div');
    body.id = this.id + '_body';
    body.className = 'bd';
    panel.appendChild(body);

    var foot = document.createElement('div');
    foot.id = this.id + '_foot';
    foot.className = 'ft';
    panel.appendChild(foot);

    var bl = document.createElement('div');
    bl.className = 'bl';
    foot.appendChild(bl);

    var credit = document.createElement('span');
    credit.id = this.id + '_credit';
    credit.innerHTML = this.credit;
    foot.appendChild(credit);

    var br = document.createElement('div');
    br.className = 'br';
    foot.appendChild(br);
};

// makeWidget method
YAHOO.SCL.Window.prototype.makeWidget = function() {
    this.panel = new YAHOO.widget.Panel(this.id, this.attrs);
    this.panel.render();
};

// adjustStyle method
YAHOO.SCL.Window.prototype.adjustStyle = function() {
    var head = document.getElementById(this.id + '_head');
    var body = document.getElementById(this.id + '_body');
    var foot = document.getElementById(this.id + '_foot');

    var headHeight = YAHOO.util.Dom.getStyle(head, 'height');
    if (headHeight == 'auto')
	headHeight = '22px';
    var footHeight = YAHOO.util.Dom.getStyle(foot, 'height');
    if (footHeight == 'auto')
	footHeight = '23px';
    
    var bodyHeight = parseInt(this.attrs.height)
        - parseInt(headHeight)
        - parseInt(footHeight)
        - parseInt(YAHOO.util.Dom.getStyle(body, 'padding-top'))
        - parseInt(YAHOO.util.Dom.getStyle(body, 'padding-bottom'));

     YAHOO.util.Dom.setStyle(body, 'height', bodyHeight + 'px');

    if (this.attrs.x == null || this.attrs.y == null) {
	YAHOO.util.Dom.setStyle(this.id + '_c', 'position', 'relative');
    }
    else {
	YAHOO.util.Dom.setStyle(this.id + '_c', 'position', 'absolute');
    }

//     var panelWidth  = YAHOO.util.Dom.getStyle(this.id, 'width');
//     var panelHeight = YAHOO.util.Dom.getStyle(this.id, 'height');
//     YAHOO.util.Dom.setStyle(this.id + '_c', 'width',  panelWidth);
//     YAHOO.util.Dom.setStyle(this.id + '_c', 'height', panelHeight);
};

// setTitle method
YAHOO.SCL.Window.prototype.setTitle = function(html) {
    this.title = html;

    var title = document.getElementById(this.id + '_title');
    if (title)
        title.innerHTML = html;
};

// setCredit method
YAHOO.SCL.Window.prototype.setCredit = function(html) {
    this.credit = html;

    var credit = document.getElementById(this.id + '_credit');
    if (credit)
        credit.innerHTML = html;
};

// open method
YAHOO.SCL.Window.prototype.open = function() {
    this.render();
};

// show method
YAHOO.SCL.Window.prototype.show = function() {
    if (this.panel)
	this.panel.show();
};

// hide method
YAHOO.SCL.Window.prototype.hide = function() {
    if (this.panel)
	this.panel.hide();
};

// close method
YAHOO.SCL.Window.prototype.close = function() {
//    this.destroy();
    this.hide();
};

//
// StockExplorer class
//
YAHOO.SCL.StockExplorer = function(id, args) {
    YAHOO.SCL.StockExplorer.superclass.constructor.call(this, id, args);
};
YAHOO.lang.extend(YAHOO.SCL.StockExplorer, YAHOO.SCL.Window);

// static values
YAHOO.SCL.StockExplorer.prototype.CLASSNAME = 'SCL_StockExplorer';
YAHOO.SCL.StockExplorer.prototype.ADVIEW_URL = 'http://www.stockcafe.jp/ad/adview.php?what=zone:171&amp;n=a6074f3c';
YAHOO.SCL.StockExplorer.prototype.ADCLICK_URL = 'http://www.stockcafe.jp/ad/adclick.php?n=a6074f3c';

// init method
YAHOO.SCL.StockExplorer.prototype.init = function(args) {
    YAHOO.SCL.StockExplorer.superclass.init.call(this, args);

    this.parse(showFlash.toString());

    this.title = 'テーマ：' + this.themeName;
    this.credit = '株エクスプローラ by <a href="' + YAHOO.SCL.SCAFE_URL + '" target="_blank" title="株式投資するなら！株式投資コミュニティ - ストックカフェ">ストックカフェ</a>';
};

// parse method
YAHOO.SCL.StockExplorer.prototype.parse = function(src) {
    var flashvars;
    if (src.match(/flashvars=\\?"([^\\""]+)\\?"/))
        flashvars = RegExp.$1;
    else
        return false;

    var params = {};
    var paramList = flashvars.split(/&/);
    for (var i = 0; i < paramList.length; i++) {
        var keyVal = paramList[i].split(/=/);
        if (keyVal.length == 2) {
            if (keyVal[0] == 'accessURL') {
                params[keyVal[0]] = keyVal[1];
            }
            else {
                params[keyVal[0]] = decodeURI(keyVal[1]);
            }
        }
    }

    this.themeID   = params['themeID'];
    this.themeName = params['mainChainName'];
    this.themeMode = (params['themaMode'] == 'true') ? true : false;
    this.chartUrl  = 'http://' + params['accessURL'];

    this.mainChain = [];
    if (this.themeMode) {
        var chainNum = parseInt(params['chainNum']);
        for (var i = 0; i < chainNum; i++) {
            var chainName = params['subChain' + i + 'Name'];
            var brandNum = parseInt(params['subChain' + i + 'StockNum']);
            var subChain = [];
            for (var j = 0; j < brandNum; j++) {
                var brandName = params['subChain' + i + 'Stock' + j + 'Name'];
                var brandCode = params['subChain' + i + 'Stock' + j + 'Code'];
                subChain[j] = {
                    'brandName': brandName,
                    'brandCode': brandCode
                };
            }

            this.mainChain[i] = {
                'chainName': chainName,
                'subChain':  subChain
            };
        }
    }
    else {
        var brandNum = parseInt(params['chainNum']);
        for (var i = 0; i < brandNum; i++) {
            var brandName = params['subChain' + i + 'StockName'];
            var brandCode = params['subChain' + i + 'StockCode'];

            this.mainChain[i] = {
                brandName: brandName,
                brandCode: brandCode
            };
        }
    }

    return true;
};

// makeDOM method
YAHOO.SCL.StockExplorer.prototype.makeDOM = function() {
    YAHOO.SCL.StockExplorer.superclass.makeDOM.call(this);

    YAHOO.util.Dom.addClass(this.id, YAHOO.SCL.StockExplorer.prototype.CLASSNAME);

    var body = document.getElementById(this.id + '_body');
    YAHOO.util.Dom.setStyle(body, 'padding', '0px'); // why?

    var tree = document.createElement('div');
    tree.id = this.id + '_tree';
    YAHOO.util.Dom.setStyle(tree, 'overflow', 'auto');
    YAHOO.util.Dom.setStyle(tree, 'width', '100%');
    YAHOO.util.Dom.setStyle(tree, 'height', '100%');

    body.appendChild(tree);
};

// makeWidget method
YAHOO.SCL.StockExplorer.prototype.makeWidget = function() {
    YAHOO.SCL.StockExplorer.superclass.makeWidget.call(this);

    this.tree = new YAHOO.widget.TreeView(this.id + '_tree'); 
    this.makeTree();
    this.bindTree();
    this.tree.draw();
};

// makeTree method
YAHOO.SCL.StockExplorer.prototype.makeTree = function() {
    var themeNode = new YAHOO.widget.TextNode(this.themeName, this.tree.getRoot(), true);

    if (this.themeMode) {
        for (var i = 0; i < this.mainChain.length; i++) {
            var mainChainNode = new YAHOO.widget.TextNode(this.mainChain[i].chainName, themeNode, false);

            for (var j = 0; j < this.mainChain[i].subChain.length; j++) {
                var subChainNode = new YAHOO.widget.TextNode({
                    label: this.mainChain[i].subChain[j].brandName,
//                    href:  brandUrl,
//  	              target: '_blank',
                    explorer:  this,
                    brandCode: this.mainChain[i].subChain[j].brandCode,
                    brandName: this.mainChain[i].subChain[j].brandName
                }, mainChainNode, false);
                subChainNode.labelStyle = "icon-brand";
            }
        }
    }
    else {
        for (var i = 0; i < this.mainChain.length; i++) {
            var mainChainNode = new YAHOO.widget.TextNode({
                label: this.mainChain[i].brandName, 
//                href:  brandUrl,
//                target: '_blank',
                explorer:  this,
                brandCode: this.mainChain[i].brandCode,
                brandName: this.mainChain[i].brandName
            }, themeNode, false);
            mainChainNode.labelStyle = "icon-brand";
        }
    }
};

// bindTree method
YAHOO.SCL.StockExplorer.prototype.bindTree = function() {
    this.tree.subscribe('labelClick', function(node) {

        if (node.data.brandCode == undefined) return;

        node.data.explorer.openBrand(node.data.brandCode, node.data.brandName);
    });
};

// openBrand method
YAHOO.SCL.StockExplorer.prototype.openBrand = function(brandCode, brandName) {
    var brandUrl = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_brand_top&bc=' + brandCode;

    window.open(brandUrl, '_blank');
};
// openBrand method
// YAHOO.SCL.StockExplorer.prototype.openBrand = function(brandCode, brandName) {
//     var brandUrl = YAHOO.SCL.SCAFE_URL + '/index.php?m=stock&a=page_brand_top&bc=' + brandCode;
//     var chartUrl = this.chartUrl + '/' + brandCode.substring(0,1) + '/' + brandCode + '.gif';

//     var chartId = this.id + '_chart' + '_' + brandCode;
//     var explorerPos = YAHOO.util.Dom.getXY(this.id);

//     var viewer = new YAHOO.SCL.ChartViewer(chartId, {
//         x:         explorerPos[0] + 20,
//         y:         explorerPos[1] + 20,
//         width:     YAHOO.util.Dom.getStyle(this.id, 'width'),
//         height:    YAHOO.util.Dom.getStyle(this.id, 'height'),
//         brandCode: brandCode,
//         brandName: brandName,
//         brandUrl:  brandUrl,
//         chartUrl:  chartUrl,
//         close:     true,
//         draggable: true,
//         effect:    { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 }
//     });

//     // 20080108
// //    YAHOO.SCL.desktop.put(viewer);
//     YAHOO.SCL.Desktop.put(viewer);

//     viewer.open();
// };

//
// StockFinder class
//
YAHOO.SCL.StockFinder = function(id, args) {
    YAHOO.SCL.StockFinder.superclass.constructor.call(this, id, args);
};
YAHOO.lang.extend(YAHOO.SCL.StockFinder, YAHOO.SCL.Window);

// static values
YAHOO.SCL.StockFinder.prototype.CLASSNAME = 'SCL_StockFinder';
YAHOO.SCL.StockFinder.prototype.ADVIEW_URL = 'http://www.stockcafe.jp/ad/adview.php?what=zone:173&amp;n=ada221bb';
YAHOO.SCL.StockFinder.prototype.ADCLICK_URL = 'http://www.stockcafe.jp/ad/adclick.php?n=ada221bb';
YAHOO.SCL.StockFinder.prototype.SPACER_IMG_URL = YAHOO.SCL.SCAFE_URL + 'common/img/spacer.gif';
YAHOO.SCL.StockFinder.prototype.BUTTON_WIDTH = 71;
YAHOO.SCL.StockFinder.prototype.BUTTON_HEIGHT = 20;
YAHOO.SCL.StockFinder.prototype.BRAND_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_brand_search';
// YAHOO.SCL.StockFinder.prototype.TAG_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_brand_tag_search';
YAHOO.SCL.StockFinder.prototype.YUTAI_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_stockholder_keyword';
YAHOO.SCL.StockFinder.prototype.THEME_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_theme_keyword';
YAHOO.SCL.StockFinder.prototype.NEWS_SEARCH_URL  = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_news_search';
YAHOO.SCL.StockFinder.prototype.DIARY_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=pc&a=page_h_diary_list_all';
// YAHOO.SCL.StockFinder.prototype.COMMU_SEARCH_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_circle_search';
// YAHOO.SCL.StockFinder.prototype.CLIP_SEARCH_URL = 'http://clip.stockcafe.jp/search';
// YAHOO.SCL.StockFinder.prototype.BLOG_SEARCH_URL = 'http://www.technorati.jp/search.php';
YAHOO.SCL.StockFinder.prototype.BLOG_SEARCH_URL  = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_blog_search';
YAHOO.SCL.StockFinder.prototype.GEO_SEARCH_URL  = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_geo_keyword';
YAHOO.SCL.StockFinder.prototype.DICT_SEARCH_URL  = YAHOO.SCL.SCAFE_URL + 'cgi-bin/dictseek.cgi';
YAHOO.SCL.StockFinder.prototype.KEYWORD_SEARCH_URL  = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_keyword_search';
YAHOO.SCL.StockFinder.prototype.BRAND_SEARCH_TIP = 
    '企業名や証券コード、会社情報から該当する銘柄を検索することができます。';
// YAHOO.SCL.StockFinder.prototype.TAG_SEARCH_TIP = 
//     'ストックカフェ参加者が銘柄に付けたキーワード（タグ）から企業を検索することができます。';
YAHOO.SCL.StockFinder.prototype.YUTAI_SEARCH_TIP = 
    '企業名や証券コード、優待品の内容に関するキーワードから該当する銘柄を検索することができます。';
YAHOO.SCL.StockFinder.prototype.THEME_SEARCH_TIP = 
    '株式投資に役立つテーマと関連銘柄を検索することができます。';
YAHOO.SCL.StockFinder.prototype.NEWS_SEARCH_TIP = 
    '株式投資に関連する各種ニュースからキーワード検索することができます。';
YAHOO.SCL.StockFinder.prototype.DIARY_SEARCH_TIP = 
    'ストックカフェ参加者が日々書き留めている日記から検索することができます。';
// YAHOO.SCL.StockFinder.prototype.COMMU_SEARCH_TIP = 
//     'ストックカフェ内の様々なユーザコミュニティ掲示板のトピックやコメントから検索することができます。';
// YAHOO.SCL.StockFinder.prototype.CLIP_SEARCH_TIP = 
//     'ストックカフェクリップに登録された全てのニュース・記事から検索することができます。';
// YAHOO.SCL.StockFinder.prototype.BLOG_SEARCH_TIP = 
//     'ブログ検索サイト"Technorati"で、株式投資に役立つ情報を探してみては？';
YAHOO.SCL.StockFinder.prototype.BLOG_SEARCH_TIP = 
    'ストックカフェに登録されているブログからキーワード検索することができます。';
YAHOO.SCL.StockFinder.prototype.GEO_SEARCH_TIP = 
    '企業名や証券コード、会社情報を地図上で検索することができます。';
YAHOO.SCL.StockFinder.prototype.DICT_SEARCH_TIP = 
    '株式投資に関する用語を検索することができます。';
YAHOO.SCL.StockFinder.prototype.KEYWORD_SEARCH_TIP = 
    '株式投資に関する用語を検索することができます。';

// init method
YAHOO.SCL.StockFinder.prototype.init = function(args) {
    YAHOO.SCL.StockFinder.superclass.init.call(this, args);

    this.title = '株検索窓';
    this.credit = '株検索窓 by <a href="' + YAHOO.SCL.SCAFE_URL + '" target="_blank" title="株式投資するなら！株式投資コミュニティ - ストックカフェ">ストックカフェ</a>';
};

// makeDOM method
YAHOO.SCL.StockFinder.prototype.makeDOM = function() {
    YAHOO.SCL.StockFinder.superclass.makeDOM.call(this);

    YAHOO.util.Dom.addClass(this.id, YAHOO.SCL.StockFinder.prototype.CLASSNAME);

    var body = document.getElementById(this.id + '_body');

    // BAD IE!!!!!!!!!!!!!!!!!
    // IE can't set name attribute!
    //
    // for <input type="hidden" name="dummy" value="&#65533;">
    // see http://bakera.jp/htmlbbs/inthread/3223
    // but not worked...
    body.innerHTML =
    '<div class="inputArea">' +
    '  <form id="' + this.id + '_input' + '" name="' + this.id + '_input"' +
    '   onSubmit="return (document.all ? false : true);">' + // IE ignore accept-charset
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_brand_search" />' +
    '    <input id="' + this.id + '_input_keyword" type="text" name="brand_search_keyword" />' +
    '  </form>' +
    '</div>' +
    '<div class="buttonArea">' +
    '  <table>' +
    '    <tr>' +
    '      <td id="' + this.id + '_findBrandArea" align="right"></td>' +
//     '      <td id="' + this.id + '_findTagArea"   align="left"></td>' +
    '      <td id="' + this.id + '_findYutaiArea" align="left"></td>' +
    '    </tr>' +
    '    <tr>' +
    '      <td id="' + this.id + '_findThemeArea" align="right"></td>' +
    '      <td id="' + this.id + '_findNewsArea"  align="left"></td>' +
    '    </tr>' +
    '    <tr>' +
    '      <td id="' + this.id + '_findDiaryArea" align="right"></td>' +
//     '      <td id="' + this.id + '_findCommuArea" align="left"></td>' +
    '      <td id="' + this.id + '_findBlogArea" align="left"></td>' +
    '    </tr>' +
//     '    <tr>' +
//     '      <td id="' + this.id + '_findClipArea" align="right"></td>' +
//     '      <td id="' + this.id + '_findBlogArea" align="left"></td>' +
//     '    </tr>' +
    '    <tr>' +
    '      <td id="' + this.id + '_findGeoArea"  align="right"></td>' +
//     '      <td id="' + this.id + '_findDictArea" align="left"></td>' +
    '      <td id="' + this.id + '_findKeywordArea" align="left"></td>' +
    '    </tr>' +
    '  </table>' +
    '</div>' +
    '<div class="outputArea">' +
    '  <form id="' + this.id + '_findBrand' + '" name="' + this.id + '_findBrand' + '">' + 
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_brand_search" />' +
    '    <input id="' + this.id + '_findBrand_keyword" type="hidden" name="brand_search_keyword" />' +
    '  </form>'+
    '  <form id="' + this.id + '_findYutai' + '" name="' + this.id + '_findYutai' + '">' +
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_stockholder_keyword" />' +
    '    <input id="' + this.id + '_findYutai_keyword" type="hidden" name="keyword" />' +
    '  </form>' +
    '  <form id="' + this.id + '_findTheme' + '" name="' + this.id + '_findTheme' + '">' +
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_theme_keyword" />' +
    '    <input id="' + this.id + '_findTheme_keyword" type="hidden" name="keyword" />' +
    '  </form>' +
    '  <form id="' + this.id + '_findNews' + '" name="' + this.id + '_findNews' + '">' +
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_news_search" />' +
    '    <input id="' + this.id + '_findNews_keyword" type="hidden" name="phrase" />' +
    '  </form>' +
//     '  <form id="' + this.id + '_findTag' + '" name="' + this.id + '_findTag' + '">' +
//     '    <input id="' + this.id + '_findTag_keyword" type="hidden" name="kw" />' +
//     '  </form>' +
    '  <form id="' + this.id + '_findDiary' + '" name="' + this.id + '_findDiary' + '">' + 
    '    <input id="' + this.id + '_findDiary_keyword" type="hidden" name="keyword" />' +
    '  </form>' +
//     '  <form id="' + this.id + '_findCommu' + '" name="' + this.id + '_findCommu' + '">' +
//     '    <input id="' + this.id + '_findCommu_keyword" type="hidden" name="menu_keyword" />' +
//     '    <input type="hidden" name="menu_tag" value="" />' +
//     '    <input type="hidden" name="menu_category_parent_id" value="0" />' +
//     '    <input type="hidden" name="menu_category_id" value="0" />' +
//     '    <input type="hidden" name="menu_category_id" value="0" />' +
//     '    <input type="hidden" name="bt" value="circle_search" />' +
//     '  </form>' +
//     '  <form id="' + this.id + '_findClip' + '" name="' + this.id + '_findClip' + '">' + 
//     '    <input id="' + this.id + '_findClip_keyword" type="hidden" name="keyword" />' +
//     '  </form>' +
//     '  <form id="' + this.id + '_findBlog' + '" name="' + this.id + '_findBlog' + '">' + 
//     '    <input id="' + this.id + '_findBlog_keyword" type="hidden" name="s" />' +
//     '    <input type="hidden" name="bucket" value="bucket" />' +
//     '    <input type="hidden" name="language" value="ja" />' +
//     '  </form>' +
    '  <form id="' + this.id + '_findBlog' + '" name="' + this.id + '_findBlog' + '">' +
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_blog_search" />' +
    '    <input id="' + this.id + '_findBlog_keyword" type="hidden" name="phrase" />' +
    '  </form>' +
    '  <form id="' + this.id + '_findGeo' + '" name="' + this.id + '_findGeo' + '">' + 
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_geo_keyword" />' +
    '    <input id="' + this.id + '_findGeo_keyword" type="hidden" name="brand_search_keyword" />' +
    '  </form>'+
//     '  <form id="' + this.id + '_findDict' + '" name="' + this.id + '_findDict' + '">' + 
//     '    <input id="' + this.id + '_findDict_keyword" type="hidden" name="phrase" />' +
//     '    <input type="hidden" name="enc" value="UTF-8" />' +
//     '  </form>'+
    '  <form id="' + this.id + '_findKeyword' + '" name="' + this.id + '_findKeyword' + '">' +
    '    <input type="hidden" name="m" value="stock" />' +
    '    <input type="hidden" name="a" value="page_keyword_search" />' +
    '    <input id="' + this.id + '_findKeyword_keyword" type="hidden" name="phrase" />' +
    '  </form>' +
    '</div>';


    var inputForm = document.getElementById(this.id + '_input');
//    inputForm.setAttribute('name', this.id + '_input');
    inputForm.setAttribute('method', 'get'); // post -> get
    inputForm.setAttribute('target', '_blank');
    inputForm.setAttribute('action', this.BRAND_SEARCH_URL);
    inputForm.setAttribute('accept-charset', 'utf-8');

    var inputKeyword = document.getElementById(this.id + '_input_keyword');
//    inputKeyword.setAttribute('size', 20);
//    inputKeyword.setAttribute('type', 'text');
//    inputKeyword.setAttribute('name', 'keyword');

    var inputLabel = document.createElement('span');
    inputLabel.innerHTML = '<br />に関する株式投資情報を';
    YAHOO.util.Dom.insertAfter(inputLabel, this.id + '_input_keyword');

    var findBrandArea = document.getElementById(this.id + '_findBrandArea');
//    var findBrandButton = document.createElement('img');
    var findBrandButton = document.createElement('a');
    findBrandButton.id = this.id + '_findBrandButton'
    findBrandButton.className = 'findBrandButton';
    findBrandButton.setAttribute('href', 'javascript:void(0)');
    findBrandButton.setAttribute('title', this.BRAND_SEARCH_TIP);
//     findBrandButton.setAttribute('alt', '');
//     findBrandButton.setAttribute('src', this.SPACER_IMG_URL);
//     findBrandButton.setAttribute('width', this.BUTTON_WIDTH);
//     findBrandButton.setAttribute('height', this.BUTTON_HEIGHT);
    findBrandArea.appendChild(findBrandButton);

//     var findTagArea = document.getElementById(this.id + '_findTagArea');
// //    var findTagButton = document.createElement('img');
//     var findTagButton = document.createElement('a');
//     findTagButton.id = this.id + '_findTagButton';
//     findTagButton.className = 'findTagButton';
//     findTagButton.setAttribute('href', 'javascript:void(0)');
//     findTagButton.setAttribute('title', this.TAG_SEARCH_TIP);
// //     findTagButton.setAttribute('alt', '');
// //     findTagButton.setAttribute('src', this.SPACER_IMG_URL);
// //     findTagButton.setAttribute('width', this.BUTTON_WIDTH);
// //     findTagButton.setAttribute('height', this.BUTTON_HEIGHT);
//     findTagArea.appendChild(findTagButton);

    var findYutaiArea = document.getElementById(this.id + '_findYutaiArea');
    var findYutaiButton = document.createElement('a');
    findYutaiButton.id = this.id + '_findYutaiButton';
    findYutaiButton.className = 'findYutaiButton';
    findYutaiButton.setAttribute('href', 'javascript:void(0)');
    findYutaiButton.setAttribute('title', this.YUTAI_SEARCH_TIP);
    findYutaiArea.appendChild(findYutaiButton);

    var findThemeArea = document.getElementById(this.id + '_findThemeArea');
    var findThemeButton = document.createElement('a');
    findThemeButton.id = this.id + '_findThemeButton';
    findThemeButton.className = 'findThemeButton';
    findThemeButton.setAttribute('href', 'javascript:void(0)');
    findThemeButton.setAttribute('title', this.THEME_SEARCH_TIP);
    findThemeArea.appendChild(findThemeButton);

    var findNewsArea = document.getElementById(this.id + '_findNewsArea');
    var findNewsButton = document.createElement('a');
    findNewsButton.id = this.id + '_findNewsButton';
    findNewsButton.className = 'findNewsButton';
    findNewsButton.setAttribute('href', 'javascript:void(0)');
    findNewsButton.setAttribute('title', this.NEWS_SEARCH_TIP);
    findNewsArea.appendChild(findNewsButton);

    var findDiaryArea = document.getElementById(this.id + '_findDiaryArea');
//    var findDiaryButton = document.createElement('img');
    var findDiaryButton = document.createElement('a');
    findDiaryButton.id = this.id + '_findDiaryButton';
    findDiaryButton.className = 'findDiaryButton';
    findDiaryButton.setAttribute('href', 'javascript:void(0)');
    findDiaryButton.setAttribute('title', this.DIARY_SEARCH_TIP);
//     findDiaryButton.setAttribute('alt', '');
//     findDiaryButton.setAttribute('src', this.SPACER_IMG_URL);
//     findDiaryButton.setAttribute('width', this.BUTTON_WIDTH);
//     findDiaryButton.setAttribute('height', this.BUTTON_HEIGHT);
    findDiaryArea.appendChild(findDiaryButton);

//     var findCommuArea = document.getElementById(this.id + '_findCommuArea');
// //    var findCommuButton = document.createElement('img');
//     var findCommuButton = document.createElement('a');
//     findCommuButton.id = this.id + '_findCommuButton';
//     findCommuButton.className = 'findCommuButton';
//     findCommuButton.setAttribute('href', 'javascript:void(0)');
//     findCommuButton.setAttribute('title', this.COMMU_SEARCH_TIP);
// //     findCommuButton.setAttribute('alt', '');
// //     findCommuButton.setAttribute('src', this.SPACER_IMG_URL);
// //     findCommuButton.setAttribute('width', this.BUTTON_WIDTH);
// //     findCommuButton.setAttribute('height', this.BUTTON_HEIGHT);
//     findCommuArea.appendChild(findCommuButton);

//     var findClipArea = document.getElementById(this.id + '_findClipArea');
// //    var findClipButton = document.createElement('img');
//     var findClipButton = document.createElement('a');
//     findClipButton.id = this.id + '_findClipButton';
//     findClipButton.className = 'findClipButton';
//     findClipButton.setAttribute('href', 'javascript:void(0)');
//     findClipButton.setAttribute('title', this.CLIP_SEARCH_TIP);
// //     findClipButton.setAttribute('alt', '');
// //     findClipButton.setAttribute('src', this.SPACER_IMG_URL);
// //     findClipButton.setAttribute('width', this.BUTTON_WIDTH);
// //     findClipButton.setAttribute('height', this.BUTTON_HEIGHT);
//     findClipArea.appendChild(findClipButton);

    var findBlogArea = document.getElementById(this.id + '_findBlogArea');
//    var findBlogButton = document.createElement('img');
    var findBlogButton = document.createElement('a');
    findBlogButton.id = this.id + '_findBlogButton';
    findBlogButton.className = 'findBlogButton';
    findBlogButton.setAttribute('href', 'javascript:void(0)');
    findBlogButton.setAttribute('title', this.BLOG_SEARCH_TIP);
//     findBlogButton.setAttribute('alt', '');
//     findBlogButton.setAttribute('src', this.SPACER_IMG_URL);
//     findBlogButton.setAttribute('width', this.BUTTON_WIDTH);
//     findBlogButton.setAttribute('height', this.BUTTON_HEIGHT);
    findBlogArea.appendChild(findBlogButton);

    var findGeoArea = document.getElementById(this.id + '_findGeoArea');
    var findGeoButton = document.createElement('a');
    findGeoButton.id = this.id + '_findGeoButton';
    findGeoButton.className = 'findGeoButton';
    findGeoButton.setAttribute('href', 'javascript:void(0)');
    findGeoButton.setAttribute('title', this.GEO_SEARCH_TIP);
    findGeoArea.appendChild(findGeoButton);

//     var findDictArea = document.getElementById(this.id + '_findDictArea');
//     var findDictButton = document.createElement('a');
//     findDictButton.id = this.id + '_findDictButton';
//     findDictButton.className = 'findDictButton';
//     findDictButton.setAttribute('href', 'javascript:void(0)');
//     findDictButton.setAttribute('title', this.DICT_SEARCH_TIP);
//     findDictArea.appendChild(findDictButton);

    var findKeywordArea = document.getElementById(this.id + '_findKeywordArea');
    var findKeywordButton = document.createElement('a');
    findKeywordButton.id = this.id + '_findKeywordButton';
    findKeywordButton.className = 'findKeywordButton';
    findKeywordButton.setAttribute('href', 'javascript:void(0)');
    findKeywordButton.setAttribute('title', this.KEYWORD_SEARCH_TIP);
    findKeywordArea.appendChild(findKeywordButton);

    var findBrandForm = document.getElementById(this.id + '_findBrand');
//    findBrandForm.setAttribute('name',this.id + '_findBrand');
    findBrandForm.setAttribute('method', 'get'); // post -> get
    findBrandForm.setAttribute('target', '_blank');
    findBrandForm.setAttribute('action', this.BRAND_SEARCH_URL);
    findBrandForm.setAttribute('accept-charset', 'utf-8');

//    var findBrandKeyword = document.getElementById(this.id + '_findBrand_keyword');
//    findBrandKeyword.setAttribute('type', 'hidden');
//    findBrandKeyword.setAttribute('name', 'brand_search_keyword');

    var findYutaiForm = document.getElementById(this.id + '_findYutai');
    findYutaiForm.setAttribute('method', 'get');
    findYutaiForm.setAttribute('target', '_blank');
    findYutaiForm.setAttribute('action', this.YUTAI_SEARCH_URL);
    findYutaiForm.setAttribute('accept-charset', 'utf-8');

//     var findTagForm = document.getElementById(this.id + '_findTag');
// //    findTagForm.setAttribute('name', this.id + '_findTag');
//     findTagForm.setAttribute('method', 'post');
//     findTagForm.setAttribute('target', '_blank');
//     findTagForm.setAttribute('action', this.TAG_SEARCH_URL);
//     findTagForm.setAttribute('accept-charset', 'utf-8');

//    var findTagKeyword = document.getElementById(this.id + '_findTag_keyword');
//    findTagKeyword.setAttribute('type', 'hidden');
//    findTagKeyword.setAttribute('name', 'kw');

    var findThemeForm = document.getElementById(this.id + '_findTheme');
    findThemeForm.setAttribute('method', 'get');
    findThemeForm.setAttribute('target', '_blank');
    findThemeForm.setAttribute('action', this.THEME_SEARCH_URL);
    findThemeForm.setAttribute('accept-charset', 'utf-8');

    var findNewsForm = document.getElementById(this.id + '_findNews');
    findNewsForm.setAttribute('method', 'get');
    findNewsForm.setAttribute('target', '_blank');
    findNewsForm.setAttribute('action', this.NEWS_SEARCH_URL);
    findNewsForm.setAttribute('accept-charset', 'utf-8');

    var findDiaryForm = document.getElementById(this.id + '_findDiary');
//    findDiaryForm.setAttribute('name', this.id + '_findDiary');
    findDiaryForm.setAttribute('method', 'post');
    findDiaryForm.setAttribute('target', '_blank');
    findDiaryForm.setAttribute('action', this.DIARY_SEARCH_URL);
    findDiaryForm.setAttribute('accept-charset', 'utf-8');

//    var findDiaryKeyword = document.getElementById(this.id + '_findDiary_keyword');
//    findDiaryKeyword.setAttribute('type', 'hidden');
//    findDiaryKeyword.setAttribute('name', 'keyword');

//     var findCommuForm = document.getElementById(this.id + '_findCommu');
// //    findCommuForm.setAttribute('name', this.id + '_findCommu');
//     findCommuForm.setAttribute('method', 'post');
//     findCommuForm.setAttribute('target', '_blank');
//     findCommuForm.setAttribute('action', this.COMMU_SEARCH_URL);
//     findCommuForm.setAttribute('accept-charset', 'utf-8');

//    var findCommuKeyword = document.getElementById(this.id + '_findCommu_keyword');
//    findCommuKeyword.setAttribute('type', 'hidden');
//    findCommuKeyword.setAttribute('name', 'menu_keyword');

//    var findCommuTag = document.getElementById(this.id + '_findCommu_tag');
//    findCommuTag.setAttribute('type', 'hidden');
//    findCommuTag.setAttribute('name', 'menu_tag');
//    findCommuTag.setAttribute('value', '');

//    var findCommuCate1 = document.getElementById(this.id + '_findCommu_cate1');
//    findCommuCate1.setAttribute('type', 'hidden');
//    findCommuCate1.setAttribute('name', 'menu_category_parent_id');
//    findCommuCate1.setAttribute('value', '0');

//    var findCommuCate2 = document.getElementById(this.id + '_findCommu_cate2');
//    findCommuCate2.setAttribute('type', 'hidden');
//    findCommuCate2.setAttribute('name', 'menu_category_id');
//    findCommuCate2.setAttribute('value', '0');

//     var findClipForm = document.getElementById(this.id + '_findClip');
// //    findClipForm.setAttribute('name', this.id + '_findClip');
//     findClipForm.setAttribute('method', 'get');
//     findClipForm.setAttribute('target', '_blank');
//     findClipForm.setAttribute('action', this.CLIP_SEARCH_URL);
//     findClipForm.setAttribute('accept-charset', 'utf-8');

//     var findBlogForm = document.getElementById(this.id + '_findBlog');
// //    findBlogForm.setAttribute('name', this.id + '_findBlog');
//     findBlogForm.setAttribute('method', 'post');
//     findBlogForm.setAttribute('target', '_blank');
//     findBlogForm.setAttribute('action', this.BLOG_SEARCH_URL);
//     findBlogForm.setAttribute('accept-charset', 'utf-8');

    var findBlogForm = document.getElementById(this.id + '_findBlog');
    findBlogForm.setAttribute('method', 'get');
    findBlogForm.setAttribute('target', '_blank');
    findBlogForm.setAttribute('action', this.BLOG_SEARCH_URL);
    findBlogForm.setAttribute('accept-charset', 'utf-8');

    var findGeoForm = document.getElementById(this.id + '_findGeo');
    findGeoForm.setAttribute('method', 'get');
    findGeoForm.setAttribute('target', '_blank');
    findGeoForm.setAttribute('action', this.GEO_SEARCH_URL);
    findGeoForm.setAttribute('accept-charset', 'utf-8');

//     var findDictForm = document.getElementById(this.id + '_findDict');
//     findDictForm.setAttribute('method', 'get');
//     findDictForm.setAttribute('target', '_blank');
//     findDictForm.setAttribute('action', this.DICT_SEARCH_URL);
//     findDictForm.setAttribute('accept-charset', 'utf-8');

    var findKeywordForm = document.getElementById(this.id + '_findKeyword');
    findKeywordForm.setAttribute('method', 'get');
    findKeywordForm.setAttribute('target', '_blank');
    findKeywordForm.setAttribute('action', this.KEYWORD_SEARCH_URL);
    findKeywordForm.setAttribute('accept-charset', 'utf-8');
};

// makeWidget method
YAHOO.SCL.StockFinder.prototype.makeWidget = function() {
    YAHOO.SCL.StockFinder.superclass.makeWidget.call(this);

    YAHOO.util.Event.addListener(this.id + '_findBrandButton', 'click', this.findBrand, this);
//     YAHOO.util.Event.addListener(this.id + '_findTagButton',   'click', this.findTag,   this);
    YAHOO.util.Event.addListener(this.id + '_findYutaiButton', 'click', this.findYutai, this);
    YAHOO.util.Event.addListener(this.id + '_findThemeButton', 'click', this.findTheme, this);
    YAHOO.util.Event.addListener(this.id + '_findNewsButton', 'click', this.findNews, this);
    YAHOO.util.Event.addListener(this.id + '_findDiaryButton', 'click', this.findDiary, this);
//     YAHOO.util.Event.addListener(this.id + '_findCommuButton', 'click', this.findCommu, this);
//     YAHOO.util.Event.addListener(this.id + '_findClipButton', 'click', this.findClip, this);
    YAHOO.util.Event.addListener(this.id + '_findBlogButton', 'click', this.findBlog, this);
    YAHOO.util.Event.addListener(this.id + '_findGeoButton', 'click', this.findGeo, this);
//     YAHOO.util.Event.addListener(this.id + '_findDictButton', 'click', this.findDict, this);
    YAHOO.util.Event.addListener(this.id + '_findKeywordButton', 'click', this.findKeyword, this);

//     this.findBrandTT = new YAHOO.widget.Tooltip(this.id + '_findBrandTT', {
// 	    context: this.id + '_findBrandButton',
// 	    text: this.BRAND_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
//     this.findTagTT = new YAHOO.widget.Tooltip(this.id + '_findTagTT', {
// 	    context: this.id + '_findTagButton',
// 	    text: this.TAG_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
//     this.findDiaryTT = new YAHOO.widget.Tooltip(this.id + '_findDiaryTT', {
// 	    context: this.id + '_findDiaryButton',
// 	    text: this.DIARY_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
//     this.findCommuTT = new YAHOO.widget.Tooltip(this.id + '_findCommuTT', {
// 	    context: this.id + '_findCommuButton',
// 	    text: this.COMMU_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
//     this.findClipTT = new YAHOO.widget.Tooltip(this.id + '_findClipTT', {
// 	    context: this.id + '_findClipButton',
// 	    text: this.CLIP_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
//     this.findBlogTT = new YAHOO.widget.Tooltip(this.id + '_findBlogTT', {
// 	    context: this.id + '_findBlogButton',
// 	    text: this.BLOG_SEARCH_TIP,
// 	    showDelay: 500,
// 	    effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 },
// 	    zIndex: (this.attrs.zIndex) ? this.attrs.zIndex + 1 : 10 });
};

YAHOO.SCL.StockFinder.prototype.submit = function(form, charset) {
    var orgCharset;

    // IE ignore accept-charset attribute...
    if (document.all && // IE
	document.charset &&
	document.charset.toLowerCase() != charset.toLowerCase()) {
	orgCharset = document.charset;
	document.charset = charset;
    }

    form.submit();

    if (orgCharset) {
	document.charset = orgCharset;
    }
};

YAHOO.SCL.StockFinder.prototype.findBrand = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findBrand'].brand_search_keyword.value = keyword;
//    document.forms[finder.id + '_findBrand'].submit();
    finder.submit(document.forms[finder.id + '_findBrand'], 'utf-8');

    finder.setTitle('銘柄検索：' + finder.escapeHTML(keyword));
};

// YAHOO.SCL.StockFinder.prototype.findTag = function(e, finder) {
//     var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
//     if (keyword == null || keyword.length == 0) {
// 	alert('キーワードを入力してください。');
// 	return;
//     }

//     document.forms[finder.id + '_findTag'].kw.value = keyword;
// //    document.forms[finder.id + '_findTag'].submit();
//     finder.submit(document.forms[finder.id + '_findTag'], 'utf-8');

//     finder.setTitle('タグ検索：' + finder.escapeHTML(keyword));
// };

YAHOO.SCL.StockFinder.prototype.findYutai = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findYutai'].keyword.value = keyword;
    finder.submit(document.forms[finder.id + '_findYutai'], 'utf-8');

    finder.setTitle('優待検索：' + finder.escapeHTML(keyword));
};

YAHOO.SCL.StockFinder.prototype.findTheme = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findTheme'].keyword.value = keyword;
    finder.submit(document.forms[finder.id + '_findTheme'], 'utf-8');

    finder.setTitle('テーマ検索：' + finder.escapeHTML(keyword));
};

YAHOO.SCL.StockFinder.prototype.findNews = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findNews'].phrase.value = keyword;
    finder.submit(document.forms[finder.id + '_findNews'], 'utf-8');

    finder.setTitle('News検索：' + finder.escapeHTML(keyword));
};

YAHOO.SCL.StockFinder.prototype.findDiary = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findDiary'].keyword.value = keyword;
//    document.forms[finder.id + '_findDiary'].submit();
    finder.submit(document.forms[finder.id + '_findDiary'], 'utf-8');

    finder.setTitle('日記検索：' + finder.escapeHTML(keyword));
};

// YAHOO.SCL.StockFinder.prototype.findCommu = function(e, finder) {
//     var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
//     if (keyword == null || keyword.length == 0) {
// 	alert('キーワードを入力してください。');
// 	return;
//     }

//     document.forms[finder.id + '_findCommu'].menu_keyword.value = keyword;
// //    document.forms[finder.id + '_findCommu'].submit();
//     finder.submit(document.forms[finder.id + '_findCommu'], 'utf-8');

//     finder.setTitle('コミュ検索：' + finder.escapeHTML(keyword));
// };

// YAHOO.SCL.StockFinder.prototype.findClip = function(e, finder) {
//     var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
//     if (keyword == null || keyword.length == 0) {
// 	alert('キーワードを入力してください。');
// 	return;
//     }

//     document.forms[finder.id + '_findClip'].keyword.value = keyword;
// //    document.forms[finder.id + '_findClip'].submit();
//     finder.submit(document.forms[finder.id + '_findClip'], 'utf-8');

//     finder.setTitle('Clip検索：' + finder.escapeHTML(keyword));
// };

// YAHOO.SCL.StockFinder.prototype.findBlog = function(e, finder) {
//     var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
//     if (keyword == null || keyword.length == 0) {
// 	alert('キーワードを入力してください。');
// 	return;
//     }

//     document.forms[finder.id + '_findBlog'].s.value = keyword;
// //    document.forms[finder.id + '_findBlog'].submit();
//     finder.submit(document.forms[finder.id + '_findBlog'], 'utf-8');

//     finder.setTitle('Blog検索：' + finder.escapeHTML(keyword));
// };

YAHOO.SCL.StockFinder.prototype.findBlog = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findBlog'].phrase.value = keyword;
    finder.submit(document.forms[finder.id + '_findBlog'], 'utf-8');

    finder.setTitle('Blog検索：' + finder.escapeHTML(keyword));
};

YAHOO.SCL.StockFinder.prototype.findGeo = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findGeo'].brand_search_keyword.value = keyword;
//    document.forms[finder.id + '_findBrand'].submit();
    finder.submit(document.forms[finder.id + '_findGeo'], 'utf-8');

    finder.setTitle('地図検索：' + finder.escapeHTML(keyword));
};

// YAHOO.SCL.StockFinder.prototype.findDict = function(e, finder) {
//     var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
//     if (keyword == null || keyword.length == 0) {
// 	alert('キーワードを入力してください。');
// 	return;
//     }

//     document.forms[finder.id + '_findDict'].phrase.value = keyword;
//     finder.submit(document.forms[finder.id + '_findDict'], 'utf-8');

//     finder.setTitle('用語検索：' + finder.escapeHTML(keyword));
// };

YAHOO.SCL.StockFinder.prototype.findKeyword = function(e, finder) {
    var keyword = document.forms[finder.id + '_input'].brand_search_keyword.value;
    if (keyword == null || keyword.length == 0) {
	alert('キーワードを入力してください。');
	return;
    }

    document.forms[finder.id + '_findKeyword'].phrase.value = keyword;
    finder.submit(document.forms[finder.id + '_findKeyword'], 'utf-8');

    finder.setTitle('用語検索：' + finder.escapeHTML(keyword));
};

//
// ChartViewer class
//
YAHOO.SCL.ChartViewer = function(id, args) {
    YAHOO.SCL.ChartViewer.superclass.constructor.call(this, id, args);
};
YAHOO.lang.extend(YAHOO.SCL.ChartViewer, YAHOO.SCL.Window);

// static values
YAHOO.SCL.ChartViewer.prototype.CLASSNAME = 'SCL_ChartViewer';
YAHOO.SCL.ChartViewer.prototype.ADVIEW_URL = 'http://www.stockcafe.jp/ad/adview.php?what=zone:172&amp;n=a47ea5b1';
YAHOO.SCL.ChartViewer.prototype.ADCLICK_URL = 'http://www.stockcafe.jp/ad/adclick.php?n=a47ea5b1';

YAHOO.SCL.ChartViewer.prototype.BRAND_URL = YAHOO.SCL.SCAFE_URL + 'index.php?m=stock&a=page_brand_top&bc=';
YAHOO.SCL.ChartViewer.prototype.CHART_WIDTH  = 160;
YAHOO.SCL.ChartViewer.prototype.CHART_HEIGHT = 142;
YAHOO.SCL.ChartViewer.prototype.CHART_URL = 'http://stockcafe.chartfolio.com/sf/m/3d/';

// init method
YAHOO.SCL.ChartViewer.prototype.init = function(args) {
    YAHOO.SCL.ChartViewer.superclass.init.call(this, args);

    if (!args)
        return;

    if (args['brandCode'] == undefined) 
        this.brandCode = '0000';
    else
        this.brandCode = args['brandCode'];

    if (args['brandName'] == undefined)
        this.brandName = 'undefined';
    else
        this.brandName = args['brandName'];

    if (args['brandUrl'] == undefined)
        this.brandUrl = this.BRAND_URL + this.brandCode;
    else
        this.brandUrl = args['brandUrl'];

    if (args['chartUrl'] == undefined)
        this.chartUrl = this.CHART_URL + this.brandCode.substring(0, 1) + '/' + this.brandCode + '.gif';
    else
        this.chartUrl = args['chartUrl'];

    this.title = '銘柄：' + this.brandName;
    this.credit = 'チャート窓 by <a href="' + YAHOO.SCL.SCAFE_URL + '" target="_blank" title="株式投資するなら！株式投資コミュニティ - ストックカフェ">ストックカフェ</a>/トライベッカ';
};

// makeDOM method
YAHOO.SCL.ChartViewer.prototype.makeDOM = function() {
    YAHOO.SCL.ChartViewer.superclass.makeDOM.call(this);

    YAHOO.util.Dom.addClass(this.id, YAHOO.SCL.ChartViewer.prototype.CLASSNAME);

    var panel = document.getElementById(this.id);
    var body = document.getElementById(this.id + '_body');

    var a = document.createElement('a');
    a.setAttribute('href', this.brandUrl);
    a.setAttribute('title', 'クリックして「' + this.brandName + '」の企業情報を見る');
    a.setAttribute('target', '_blank');
    body.appendChild(a);

    var img = document.createElement('img');
    img.id = this.id + '_img';
//    img.setAttribute('src', this.chartUrl); // Use YUI ImageLoader for IE
    img.setAttribute('alt', 'クリックして「' + this.brandName + '」の企業情報を見る');
    img.setAttribute('width', this.CHART_WIDTH);
    img.setAttribute('height', this.CHART_HEIGHT);
    img.setAttribute('border', '0'); // for IE
    a.appendChild(img);
};

// makeWidget method
YAHOO.SCL.ChartViewer.prototype.makeWidget = function() {
    YAHOO.SCL.ChartViewer.superclass.makeWidget.call(this);

//    var group = new YAHOO.util.ImageLoader.group(this.id, 'mouseover', 2);
    var group = new YAHOO.util.ImageLoader.group(document, 'mouseover', null);

    group.registerSrcImage(this.id + '_img', this.chartUrl, this.CHART_WIDTH, this.CHART_HEIGHT); 
};

