function js_parser(htm){
    var tag="script>",begin="<"+tag,end="</"+tag,pos=pos_pre=0,result=script="";
    while(
        (pos=htm.indexOf(begin,pos))+1
    ){
        result+=htm.substring(pos_pre,pos);
        pos+=8;
        pos_pre=htm.indexOf(end,pos);
        if(pos_pre<0){
            break;
        }
        script+=htm.substring(pos,pos_pre)+";";
        pos_pre+=9;
    }
    result+=htm.substring(pos_pre,htm.length);
    
    return {
        htm:result,
        js:function(){eval(script)}
    };
}


function center(elem){
    return {
        left:(document.documentElement.offsetWidth-elem.offsetWidth)/2+'px',
        top:(document.documentElement.clientHeight-elem.offsetHeight)*.45+'px'
    }
}

function pop_win(htm){
    if(!window.__pop_win){
        var pop_win_bg=document.createElement("div");
        pop_win_bg.className="pop_win_bg"
        document.body.appendChild(pop_win_bg)
        var pop_win_body=document.createElement("div");
        pop_win_body.className="pop_win";
        document.body.appendChild(pop_win_body)
        __pop_win={
            bg:pop_win_bg,body:pop_win_body,
            body_j:$(pop_win_body),bg_j:$(pop_win_bg)
        };
    }
    var b=__pop_win.body,body_j=__pop_win.body_j,dom=js_parser(htm),h=dom.htm;
    if(pop_win.X)h='<a onclick="pop_win.close()" hidefocus="true" href="javascript:;" class="pop_win_close">X</a>'+h;
    b.innerHTML=h;
    body_j.css({display:"block"}).css(center(b));
    __pop_win.bg_j.css({
        height:b.offsetHeight+20+"px",
        width:b.offsetWidth+20+"px",
        left:b.offsetLeft-10+"px",
        top:b.offsetTop-10+"px",
        zIndex:100
    }).show()
    body_j.css({visibility:"visible",zIndex:101})
    dom.js();

    if(!window.XMLHttpRequest){
        __pop_win.bg.style.top=""
    }
}
pop_win.X=1
pop_win.close=function(){
    __pop_win.bg.style.display="none";
    __pop_win.body.innerHTML="";
    __pop_win.body.style.display="none";
}

pop_win.load=function(url,cache){
    pop_win("加载中,请稍等...")
    $.ajax({url:url,success:pop_win,cache:cache||false})
    return false
}
