/**
 * @author v_diaojiajia
 */ 
function g(element) { 
	return document.getElementById(element) || element;
}	
function jsonDecode(jsonString) {
	return (new Function("return " + jsonString))();
}
function show(id) {
	isShow(id, true);
}
function hide(id) {
	isShow(id, false);
}
function isShow(id, flag) {
	g(id).style.display = flag ? 'block' : 'none';
}
function trim(str){   
    return str.replace(/^(\s|\u00A0)+/,'').replace(/(\s|\u00A0)+$/,'');   
} 
/* 执行命令 */
function execOrder(order, key) { // console.log('order:'  + order + ',key:' + key)
    var info = '';
    try { 
        key = (key.length == 0 ? '0' : key); 
        info = JSON.parse(window.external.SyncRequest(order, key));
        if (typeof info.Type != 'undefined' && info.Type.length > 0) {
            info = info.Type;
        }
    } catch (e) {
        
    } 
    return info;
}
/* 绑定hover事件 */
function bindHover(obj) {
    obj.onmouseover = function () { 
        hover(true);
    }
    obj.onmouseout = function () { 
        hover(false);
    }   
    if (!obj.getAttribute('link')) {
        return;
    } 
    obj.onclick = function () {
        if (!this.getAttribute('link')) {
            return;
        }
        openPage(this);
	}
}
/* 鼠标悬停 */
function hover(isHover) {
    execOrder('MouseOver', '{"overCtrl":' + isHover + '}');
}
/*关闭窗口按钮*/
function closeWind() {
    execOrder("Close", '0');
}/*点击按钮应用*/
function apply() {
    execOrder("Apply", '');
}
function onloadBubble(){
	bindHover(g('closeBtn'));	
	bindHover(g('bubbleAction'));
	g('closeBtn').onclick = function(){
		closeWind();
	}
	g('bubbleAction').onclick = function(){
		apply();
	}
	var itemInfo = 	execOrder("QueryPageInfo", '');
	var bubbleType = {};
	if (bubbleItems[itemInfo]) {
		bubbleType = bubbleItems[itemInfo];		
	} else {
		bubbleType = bubbleItems.FuzzyPinyin;
	}
	g('showImg').setAttribute('src',bubbleType.img);
	g('bubbleAction').innerHTML = bubbleType.btn; 
}