﻿var IputDia = {
    $id1: "SBOX", $id2: "SBIV",
    author:"wyulang QQ595545402 input输入提示JS",
    $get: function (obj) { return document.getElementById(obj); },
    $left: function (e) { var l = 0; while (e) { l += e.offsetLeft; e = e.offsetParent; } return l }, //left值
    $top: function (e) { var t = 0; while (e) { t += e.offsetTop; e = e.offsetParent; } return t }, //top值
    $InLeTo: function (e) {
        var _left = IputDia.$left(e); var _top = IputDia.$top(e); var _width = e.offsetWidth; var _height = e.offsetHeight;
        IputDia.$get(IputDia.$id1).style.left = _left + "px"; IputDia.$get(IputDia.$id2).style.left = _left + "px";
        IputDia.$get(IputDia.$id1).style.top = _top + _height + 'px'; IputDia.$get(IputDia.$id2).style.top = _top + _height + 'px';
    },
    replaceHtml: function (el, html) { var oldEl = typeof el == "string" ? IputDia.$get(el) : el; var newEl = oldEl.cloneNode(false);
        newEl.innerHTML = html; oldEl.parentNode.replaceChild(newEl, oldEl); return newEl;
    },
    $colse: function () { if (IputDia.$get(IputDia.$id1)) { document.body.removeChild(IputDia.$get(IputDia.$id1)); document.body.removeChild(IputDia.$get(IputDia.$id2)); } }, //关闭层
    $hide: function (event) {//点击任何处关闭层
        if (event.target) targ = event.target; else if (event.srcElement) targ = event.srcElement;
        if (targ.tagName != 'LI' && targ.tagName != 'A') {
            if (IputDia.$get(IputDia.$id1)) {document.body.removeChild(IputDia.$get(IputDia.$id1));document.body.removeChild(IputDia.$get(IputDia.$id2)); } }
    },
    $PopIm: function (e) {
        var objBody = document.getElementsByTagName("body").item(0);
        var objiFrame = document.createElement("iframe");
        var objform = document.createElement("div");
        objiFrame.setAttribute('id', IputDia.$id1);
        objiFrame.setAttribute("src", "about:blank");
        objiFrame.style.zindex = '100';
        objiFrame.frameBorder = "0";
        objiFrame.style.width = "0px";
        objiFrame.style.height = "0px";
        objiFrame.style.position = 'absolute';
        objform.setAttribute('id', IputDia.$id2);
        objform.setAttribute('align', 'left');
        objform.style.position = 'absolute';
        objform.style.background = 'transparent';
        if (e) {
            if (!e) e = window.event; e.stopPropagation;e.cancelBubble = true;
            if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement;
            if (targ.nodeType == 3) targ = targ.parentNode;
        }
        if (objBody) {
            if (IputDia.$get(IputDia.$id1)) { IputDia.$colse(); IputDia.$colse(); }
            objBody.appendChild(objiFrame);
            if (objiFrame) { objiFrame.ownerDocument.body.appendChild(objform); }
        }
        if (!document.all) {window.document.addEventListener("click", IputDia.$hide, false);} else {window.document.attachEvent("onclick", IputDia.$hide);}
    },
    show: function (objid, e, html) {IputDia.$PopIm(e);IputDia.replaceHtml(IputDia.$get(IputDia.$id2), html);IputDia.$InLeTo(objid);}
}
