﻿//在莫窗口中打开传入的网站页面
//url：要在莫窗口中打开打开的页面地址
var __win_timeout;
function OpenWin(url, callback, options) {// = function (url, args, callback, clear, callback2)
    var isurl = false;
    if (typeof url == 'object') {
        Win(url.html);
    } else if (url == "") {
        return;
    } else if (url.indexOf('#') > -1) {
        Win(dg(url.replace('#', '')).innerHTML);
    } else {
        isurl = true;
        Win('<span style="display:block;margin-left:50px;height:25px;line-height:25px;background:url(http://www.pedaily.cn/top/images/ajaxloader.gif) left center no-repeat;padding-left:18px;">请稍后。。。</span>');
        var myAjax = Request.sendGET(
         url + "?t=" + Math.random(),
	      "",
          function (html) {
              Win(html);
              if (callback) {
                  callback();
              }
              if (options && options.autoclose) {
                  __win_timeout = setTimeout(function () { CloseWin(); }, options.autoclose);
              }
          }
	   );
    }
    if (!isurl) {
        if (callback) {
            callback();
        }
        if (options && options.autoclose) {
            __win_timeout = setTimeout(function () { CloseWin(); }, options.autoclose);
        }
    }
}

//创建莫窗口
function CreateWin() {
    if (!dg("CoverBox")) { ChangeCoverBox(); }
    if (!dg("WinBox")) {
        var winBox = document.createElement("div");
        winBox.setAttribute("id", "WinBox");
        document.body.appendChild(winBox);
    }
    if (!dg("WinBorder")) {
        var winBorder = document.createElement("div");
        winBorder.setAttribute("id", "WinBorder");
        document.body.appendChild(winBorder);
    }
}

function ChangeHeight() {
    dg("WinBorder").style.height = (dg("WinBox").offsetHeight + 20) + "px";
}

//报告下载留言窗口 显示/隐藏 需要服务表单
function WinChange() {
    if (dg("needservice").checked) {
        dg("reason").style.display = "block";
    }
    else {
        dg("reason").style.display = "none";
    }
    dg("WinBorder").style.height = (dg("WinBox").offsetHeight + 20) + "px";
}

function Win(html) {
    CreateWin();
    if (html.responseText)
        dg("WinBox").innerHTML = html.responseText;
    else
        dg("WinBox").innerHTML = html;
    if (dg("isContact")) {
        if (dg("isContact").checked) {
            if (dg("Reason")) {
                dg("Reason").style.display = "block";
            }
        }
    }
    if (dg('win_vcode')) {
        dg('win_vcode').src = "http://news.pedaily.cn/vcode.ashx?t=" + new Date().getTime();
        dg('win_vcode').onclick = function () { dg('win_vcode').src = "http://news.pedaily.cn/vcode.ashx?t=" + new Date().getTime(); }
    }
    ChangeHeight();
}

//关闭莫窗口
function CloseWin() {
    if (dg("WinBox")) {
        if (dg("CoverBox")) { document.body.removeChild(dg("CoverBox")); }
        if (dg("WinBox")) { document.body.removeChild(dg("WinBox")); }
        if (dg("WinBorder")) { document.body.removeChild(dg("WinBorder")); }
    }
    clearTimeout(__win_timeout);
}

function ChangeCoverBox() {
    if (dg("CoverBox")) {
        document.body.removeChild(dg("CoverBox"));
    }
    else {
        var coverBox = document.createElement("div");
        document.body.appendChild(coverBox);
        coverBox.id = 'CoverBox';
        coverBox.onclick = function () { CloseWin(); }
    }
}
