﻿/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* w : 弹窗的宽度
* h : 弹窗的高度
* step : 移动的步长
* speed : 移动的速度
* timeout : 自动消失的时间 == timeout与speed相乘的结果，单位是:ms
* caption : 弹窗的标题
* content : 弹窗的内容(目前只支持<li>test</li>标记)
* 示例：
* var msgBox = new popBox('','','','','','testCaption','<li>test content</li>');
*     msgBox.show();
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function popBox(w,h,step,speed,timeout,caption,content){
    this.width = w ? w : 201;
    this.height = h ? h : 116;
    this.step = step ? step : 5;
    this.speed = speed ? speed : 5;
    this.timeout = 60;//timeout ? timeout : 300;
    this.content = content;
    this.pop = '';
    var boxStr = [];
        boxStr.push("<div style='z-index:99999; left:0px; width:{w}px; position:absolute; top:0px; height:{h}px;' hidefocus='true' >");
        boxStr.push("<table style=\"border-collapse:collapse;border-top:solid 4px #328AA4;border-bottom:solid 2px #1E5464;border-left:solid 3px #1E5464;border-right:solid 3px #1E5464;width:100%;height:100%;font:Arial, Helvetica, sans-serif;\">");
        boxStr.push("<tr>");
        boxStr.push("<th style=\"text-align:left;height:25px;background:#328aa4 repeat-x;color:#fff;filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#328aa4', endColorStr='', gradientType='0')\">&nbsp;&nbsp;</th>");
        boxStr.push("<th style=\"text-align:left;height:25px;background:#328aa4 repeat-x;color:#fff;filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#328aa4', endColorStr='', gradientType='0');width:96%\">系统提示</th>");
        boxStr.push("<th style=\"text-align:right;height:25px;background:#328aa4 repeat-x;color:#fff;filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#328aa4', endColorStr='', gradientType='0')\"><strong style=\"cursor:pointer;font-size:16px;\" id=\"btSysClose\">×</strong></th>");
        boxStr.push("<th style=\"text-align:left;height:25px;background:#328aa4 repeat-x;color:#fff;filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#328aa4', endColorStr='', gradientType='0')\">&nbsp;&nbsp;</th>");
        boxStr.push("</tr>");
        boxStr.push("<tr style=\"padding:0px;margin:0px;\">");
        boxStr.push("<td colspan=\"4\" style=\"filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#008080', endColorStr='snow', gradientType='0')\">");
        boxStr.push("<ul style='font-size:14px;margin:0 0 0 4px;padding:0 0 0 8px;list-style:none;'>");
        boxStr.push("<li style=\"list-style:none;\"></li>");
        boxStr.push( "{content}" );
        boxStr.push("</ul>");
        boxStr.push("</td></tr></table>");
        boxStr.push("</div>");
    this.fixInnerHTML = boxStr.join('');
    this.timer = 0;
    this.close = false;
}
popBox.prototype.show = function(){
    if ( !this.content ) return;
    if ( this.content.indexOf('张') <= 0 ) return;
    if ( this.pop ){
        this.pop = '';
    }
    var sH = window.screen.height;
    var sW = window.screen.width;
    var nW = this.width;
    var nH = 0;
    var nT = sH - nH;
    var nL = sW - nW;
    this.fixInnerHTML = this.fixInnerHTML.replace(/{w}/, nW);
    this.fixInnerHTML = this.fixInnerHTML.replace(/{h}/, this.height);
    this.fixInnerHTML = this.fixInnerHTML.replace(/{content}/, this.content);
    var oPop = window.createPopup();
    this.pop = oPop;
    var oBody = this.pop.document.body;
    oBody.style.border = 'none';
    oBody.innerHTML = this.fixInnerHTML;
    this.pop.show(nL,nT,nW,nH);
    var me = this;
    me.close = false;
    function s(){
        if ( (nH >= me.height) && (!me.close) ){
            nH = me.height;
            me.timeout--;
            if ( me.timeout > 0 ){
                me.pop.show( nL,nT,nW,nH );
            } else {
                if ( me.timer )
                    window.clearInterval( me.timer );
                me.hide();
                me.close = true;
            }
        } else {
            nH += me.step;
            me.pop.show( nL,nT,nW,nH );
        }
    }
    if ( !this.timer ){
        this.timer = window.setInterval( s, this.speed );
    }
    var btnClose = this.pop.document.getElementById( 'btSysClose' );
    with( btnClose ){
        btnClose.onclick = function(){
            window.clearInterval( me.timer );
            me.hide();
        }
    }
    var bt1 = this.pop.document.getElementById("bt1"); 
	if(bt1){
		bt1.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
		    document.URL = bt1.href;
	    }    
	} 
    var bt2 = this.pop.document.getElementById("bt2"); 
	if(bt2){
		bt2.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
            document.URL = bt2.href;
	    }    
	} 
	var bt3 = this.pop.document.getElementById("bt3"); 
	if(bt3){
		bt3.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
            document.URL = bt3.href;
	    }
	} 
	var bt4 = this.pop.document.getElementById("bt4"); 
	if(bt4){
		bt4.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
            document.URL = bt4.href;
	    }    
	} 
	var bt5 = this.pop.document.getElementById("bt5"); 
	if(bt5){
		bt5.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
            document.URL = bt5.href;
	    }    
	} 
	var bt6 = this.pop.document.getElementById("bt6"); 
	if(bt6){
		bt6.onclick = function(){
		    window.clearInterval( me.timer );
            me.hide();
            document.URL = bt6.href;
	    }
	}
	var bt7 = this.pop.document.getElementById('bt7');
	if ( bt7 ){
	    bt7.onclick = function(){
		    window.clearInterval( me.timer );
	        me.hide();
	        document.URL = bt7.href;
	    }
	}
}
popBox.prototype.hide = function(){/*
    this.timer = 0;
    var sH = window.screen.height;
    var sW = window.screen.width;
    var nW = this.width;
    var nH = this.height;
    var nT = sH - nH;
    var nL = sW - nW;
    this.pop.show(nL,nT,nW,nH);
    var me = this;
    function h(){
        if ( nH <= 0 ){
            nH = 0;
            if ( me.timer )
                window.clearInterval( me.timer );
            me.close = true;
            me.pop.hide();
            me.pop = null;
            CollectGarbage();
        } else {
            nH -= me.step;
            nT = sH - nH;
            me.pop.show(nL,nT,nW,nH);
        }
    }
    if ( !this.timer ){
        this.timer = window.setInterval( h, this.speed );
    }*/
    if ( this.pop )
        this.pop.hide();
}
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if(endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while(i < clen) {
        j = i + alen;    
        if(document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if(i == 0)
            break;
    }  
    return null;
}
function deleteCookie(name) {
    var exp = new Date();
    var cval = getCookie(name);
    exp.setTime(exp.getTime() - 1000);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var gCookieExpDays = 80;
function setCookie(name, value) {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var exp = (argc > 2) ? argv[2] : gCookieExpDays;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    var expires = new Date();
    deleteCookie(name);
    expires.setTime(expires.getTime() + (exp*24*60*60*1000));
    document.cookie = name + "=" + value +
        "; expires=" + expires.toGMTString() +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((secure == true) ? "; secure" : "");
}