function bkAjaxLoad(id){
    this.target = id;
    cbfunc="";
    this.ajaxLoadJson = function(link,func){
    		cbfunc=func;
    		llink=link;
        sendRequestGet(llink,this, 'json',true,cbfunc);
    }
    this.ajaxLoadAlert = function(link){
        sendRequestGet(link,this, 'alert');
    }
    this.loadToDiv = function(link){
        sendRequestGet(link,this);
    };
    function callBack(result,type,obj,cbfunc){
    		target=obj.target;
        if (type == 'script') {
            globalEval(result);
            return;
        }
        if (type == 'alert') {
            alert(result);
            return;
        }
        if(type=='json'){
        	if(typeof cbfunc == "function"){
	        	if(result!=undefined&&result!=""){
	        		cbfunc(eval("(" + result + ")"));
	        	}
        	}
        	return;
        }
        //榛樿鍥炶皟鍑芥暟
        if (target != undefined) {
            obj = document.getElementById(target);
            if (obj != undefined) {
                obj = document.getElementById(target);
                obj.innerHTML = result;
                var head = document.getElementsByTagName("head")[0];
                sp = /<script(.|\s)*?\/script>/g;
                scripts = result.match(sp);
                if (scripts) {
                    for (i = 0; i < scripts.length; i++) {
                        if (/src=/i.test(scripts[i])) {
                            link = scripts[i].match(/src\s?=("|')?[^"']*("|')?/)[0];
                            link = link.replace(/(src\s?=)?("|')?/g, "");
                            var script = document.createElement("script");
	                        script.src = link;
                            head.appendChild(script);
                        }
                        else {
                            a = scripts[i].replace(/<(\\\/)?script[^>]*?>/g, "");
                            a = a.replace(/<\/script>/g, "");
                            globalEval(a);
                        }
                    }
                }
                sp = /<link[^>]*>/g;
                scripts = result.match(sp);
                if (scripts) {
                    for (i = 0; i < scripts.length; i++) {
                        if (/href=/i.test(scripts[i])) {
                            link = scripts[i].match(/href\s?=("|')?[^"']*("|')?/)[0];
                            link = link.replace(/(href\s?=)?("|')?/g, "");
                            var script = document.createElement("link");
                            script.href = link;
                            script.rel = "stylesheet";
                            head.appendChild(script);
                        }
                    }
                }
            }
        }
    }
    function sendRequestGet(link,obj, type, async,cbfunc){
        var req = null;
        var console = null;
        var READY_STATE_UNINITIALIZED = 0;
        var READY_STATE_LOADING = 1;
        var READY_STATE_LOADED = 2;
        var READY_STATE_INTERACTIVE = 3;
        var READY_STATE_COMPLETE = 4;
        var replace = false;
        var asynct = true;
        if (async) {
            asynct = async;
        }
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        }
        else 
            if (window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        if (req) {
            req.onreadystatechange = function(){
                if (req.readyState == READY_STATE_COMPLETE) {
                    callBack(req.responseText, type,obj,cbfunc);
                }
            };
            var contentType = "text/html; charset=utf-8";
            req.open("GET", link, asynct);
            req.setRequestHeader("Content-Type", contentType);
            req.send(null);
        }
    }
    
    function globalEval(data){
        if (data) {
            var userAgent = navigator.userAgent.toLowerCase();
            if (window.execScript) {
                window.execScript(data);
            }
            else {
                if (/safari/.test(userAgent)) {
                    // safari doesn't provide a synchronous global eval
                    window.setTimeout(data, 0);
                }
                else {
                    eval.call(window, data);
                }
            }
        }
    }
}
