﻿
//check browser type
var browser = {
    IE: !!(window.attachEvent && !window.opera),
    Opera: !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1, //firefox
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
}

//getElementById
function $(idStr) {
    if (idStr != null) {
        element = document.getElementById(idStr);
        return element;
    }
    return false;
}
//getElementsByName
function $N(nameStr) {
    if (nameStr != null) {
        var elements = new Array();
        elements = document.getElementsByName(nameStr);
        return elements;
    }
    return false;
}
//getElementsByTagName
function $T(nameStr) {
    if (nameStr != null) {
        var elements = new Array();
        elements = document.getElementsByTagName(nameStr);
        return elements;
    }
    return false;
}

//popup layer
function popupLayer(ev, id, sw, sh, cobj) {
    var e = window.event || ev;
    this.title = '';
    this.bottom = '';
    this.content = '';
    cobj = cobj || '__content__';
    var sw1 = sw == null ? 350 : sw;

    this.show = function() {
        var layer = '<div style="margin: 0px; padding: 0px; cursor: move; background: #255ba5; padding-left: 4px; font-size: 12px; color: #fff; height: 25px; line-height: 25px; border-left: 1px solid #255ba5; border-top: 1px solid #255ba5; border-right: 1px solid #255ba5;" onmousedown="oMove(parentNode,event)"><span style="float: right; padding-right: 3px;"><a href="javascript:;" onclick="closeLayer(\'' + id + '\')" style="color: #fff;">关闭</a></span><span id=\"__title__\">' + this.title + '</span></div>';
        layer += '<div style="margin: 0; background: #fff; font-size: 12px; border-left: 1px solid #255ba5; border-right: 1px solid #255ba5; clear: both; overflow: hidden; padding: 3px;" id="' + cobj + '">' + this.content + '</div>';
        var bb = '';
        if (this.bottom == '') bb = 'height: 20px; ';
        layer += '<div style="' + bb + 'background: #255ba5; text-align: center; padding: 4px; border-left: 1px solid #255ba5; border-bottom: 1px solid #255ba5; border-right: 1px solid #255ba5; margin: 0;" id="__bottom__">' + this.bottom + '</div>';

        if (!document.getElementById(id)) {
            var _div = document.createElement('div');
            _div.id = id;
            _div.style.left = (((window.innerWidth || document.body.offsetWidth) - sw1) / 2) + 'px';
            _div.style.bottom = '50%';
            _div.style.marginBottom = '-150px';
            _div.style.width = sw1 + 'px';
            if (sh != null) _div.style.height = sh + 'px';
            _div.style.background = '#fff';
            _div.style.position = 'absolute';
            _div.style.zIndex = '999';
            _div.innerHTML = layer;
            document.body.appendChild(_div);
        }
        var offTop = document.getElementById(id).offsetTop;
        if (offTop < 0) {
            if (offTop > -100) {
                offTop = -100;
            } else {
                offTop -= 100;
            }
            var marBot = -150;
            marBot += offTop;
            document.getElementById(id).style.marginBottom = marBot + 'px';
        } else {
            if (offTop > 300) document.getElementById(id).style.marginBottom = '-0px';
            if (offTop < 100) document.getElementById(id).style.marginBottom = '-220px';
        }
        document.getElementById(id).style.height = document.getElementById(id).offsetHeight + 'px';

    }
}
//remove popup layer
function closeLayer(id) {
    document.body.removeChild(document.getElementById(id));
}
//move popup layer
function oMove(obj, even) {
    var otop, oleft;
    var e = window.event || even;
    otop = e.clientY - obj.offsetTop;
    oleft = e.clientX - obj.offsetLeft;

    if (document.all) obj.setCapture();

    obj.onmousemove = function(e) {
        e = e || window.event;
        obj.style.left = (e.clientX - oleft) + 'px';
        obj.style.top = (e.clientY - otop) + 'px';
    }
    obj.onmouseup = function() {
        obj.onmousemove = null;
        if (document.all) obj.releaseCapture();
    }
}

//get upload ui
function getUploadUI(id, type, prev) {
    //id : 将上传结果地址返回给该ID
    //type : 上传文件类型
    //prev : 预览元素ID
    prev = prev || '';
    var html = '<div style="margin: 3px; font-weight: bold;">选择要上传的文件：</div>';
    html += '<div style="padding: 3px;"><iframe src="/admin/editor/filemanager/connectors/upload.html?tt=' + id + '&tp=' + type + '&prev=' + prev + '" width="330px" height="25px" style="overflow: hidden; background: transparent;" scrolling="no" frameborder="0" framewidth="0" frameheight="0"></iframe></div>';
    if (browser.IE) {
        if (prev != '' && type == 'Image') {
            html += '&nbsp;<img style="width: 150px; height: 120px; border: outset 1px #ddd; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);" alt="" id="prev" />';
        }
    }
    return html;
}
//check all checkbox
function checkAll(e, name) {
    var sub = $N(name);
    for (var i = 0; i < sub.length; i++) {
        if (!sub.item(i).disabled) sub.item(i).checked = e.checked;
    }
}
//get selected checkbox
function getAllSelected(name, split) {
    var sub = $N(name);
    var tmp = '';
    split = split || ',';
    for (var i = 0; i < sub.length; i++) {
        if (sub.item(i).checked) tmp += split + sub.item(i).value;
    }
    if (tmp != '') tmp = tmp.substring(split.length);
    return tmp;
}
//alt color
function setBGColor(e, color) {
    e.style.background = color;
}

//框架自适应高度
function SetWinHeight(obj) {
    var win = obj;
    if (document.getElementById) {
        if (win && !window.opera) {
            if (win.contentDocument && win.contentDocument.body.offsetHeight) {
                win.height = win.contentDocument.body.offsetHeight;
            }
            else if (win.Document && win.Document.body.scrollHeight) {
                win.height = win.Document.body.scrollHeight;
            }
        }
    }
}

//打开颜色选择器
function getColor(e, ic) {
    var m = window.showModalDialog('/js/color.html', ic, 'dialogWidth=254px; dialogHeight=223px; center=yes; help=no; status=no; scroll=no');
    if (m != null && m != undefined) {
        e.value = m;
        e.style.backgroundColor = m;
    }
}

//按语言隐藏与显示
function changeLanguage(value) {
    var url = document.URL;
    var purl = '';
    var pr = url;

    if (pr.indexOf('?') == -1) {
        purl = '?lang=' + value;
    } else {
        if (pr.indexOf('lang') == -1) {
            purl = '&lang=' + value;
        } else {
            pr = pr.replace(/([\?&]lang=)(?:\d+|en|zh)/, '$1' + value);
        }
    }
    purl = pr + purl;
    self.location.href = purl;
}
function setDisplayStyle(value, type) {
    var re = new RegExp('^lang_\\d+$', 'gi');
    if (type == null) type = 'TR';
    var nx = $T(type);
    var dis = '';
    if (value == '0') {
        dis = '';
    } else {
          dis = 'none';
    }

    for (var i = 0; i < nx.length; i++) {
        if (nx.item(i).id.match(re)) {
            $(nx.item(i).id).style.display = dis;
        }
    }
}

function isMoreThan(date1, date2) {
    if (date1 == null || date2 == null) return false;
    date1 = date1.toString();
    date2 = date2.toString();

    var dt = date1.split(' ');
    var dt1 = dt[0].split('-');
    var dt2 = [];
    if (dt1.length == 2) dt2 = dt[1].split(':');

    var d1 = null;

    if (dt2.length == 3) d1 = new Date(dt1[0], dt1[1], dt1[2], dt2[0], dt2[1], dt2[2]);
    if (dt2.length == 2) d1 = new Date(dt1[0], dt1[1], dt1[2], dt2[0], dt2[1]);
    if (dt2.length < 2) d1 = new Date(dt1[0], dt1[1], dt1[2]);

    dt = date2.split(' ');
    dt1 = dt[0].split('-');
    if (dt1.length == 2) dt2 = dt[1].split(':'); else dt2 = [];

    if (dt2.length == 3) d2 = new Date(dt1[0], dt1[1], dt1[2], dt2[0], dt2[1], dt2[2]);
    if (dt2.length == 2) d2 = new Date(dt1[0], dt1[1], dt1[2], dt2[0], dt2[1]);
    if (dt2.length < 2) d2 = new Date(dt1[0], dt1[1], dt1[2]);

    return d2 >= d1;
}

//输入日期并格式化
function SetDate(e, even) {
    even = even || window.event;

    var t = '';
    if (even.keyCode != 8 && even.keyCode != 46) {
        if (e.value.match(/^20[0-9]{2}$/g)) {
            t = e.value + '-';
            e.value = t;
        } else {
            if (!e.value.match(/^20[0-9]{2}\-$/g)) {
                if (e.value.length == 4) {
                    t = '';
                    e.value = t;
                }
            }
        }

        if (e.value.match(/^20[0-9]{2}\-(?:[0-9])$/g)) {
            var d = e.value.split('-');
            var d1 = parseInt(d[1], 10);

            if (d1 >= 2) {
                t = d[0] + '-' + '0' + d1 + '-';
                e.value = t;
            }
        }

        if (e.value.match(/^20[0-9]{2}\-(?:[0-1][0-9])$/g)) {
            var d = e.value.split('-');
            var d1 = parseInt(d[1], 10);

            if (d1 == 0) {
                t = d[0] + '-0';
                e.value = t;
            } else {
                if (d1 <= 12) {
                    t = e.value + '-';
                } else {
                    t = e.value.substring(0, 6);
                }
                e.value = t;
            }
        }

        if (!e.value.match(/^20[0-9]{2}\-(?:[0-1][0-9])\-(?:[1-31])$/g)) {
            var d = e.value.split('-');
            var d1 = parseInt(d[2], 10);

            if (d1.length == 1) {
                e.value = d[0] + '-' + d[1] + '-' + '0' + d1;
            } else {
                if (d1 >= 32) {
                    if (d1.length >= 3) {
                        t = e.value.substring(0, 10);
                    } else {
                        t = e.value.substring(0, 9);
                    }
                    e.value = t;
                }
            }
        }
    }
}
//弹出窗口
var isIe = (document.all) ? true : false;
//设置select的可见状态
function setSelectState(state) {
    var objl = document.getElementsByTagName('select');
    for (var i = 0; i < objl.length; i++) {
        objl[i].style.visibility = state;
    }
} //欢迎来到站长特效网，我们的网址是www.zzjs.net，很好记，zz站长，js就是js特效，本站收集大量高质量js代码，还有许多广告代码下载。
function mousePosition(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//弹出方法
function showMessageBox(wTitle, content, wWidth) {
    closeWindow();
    var bWidth = parseInt(document.documentElement.scrollWidth);
    var bHeight = parseInt(document.documentElement.scrollHeight);
    if (isIe) {
        setSelectState('hidden');
    }
    var back = document.createElement("div");
    back.id = "back";
    var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:2150px;";
    styleStr += (isIe) ? "filter:alpha(opacity=0);" : "opacity:0;";
    back.style.cssText = styleStr;
    document.body.appendChild(back);
    showBackground(back, 50);
    var mesW = document.createElement("div");
    mesW.id = "mesWindow";
    mesW.className = "mesWindow";
    mesW.innerHTML = "<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>" + wTitle + "</td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>" + content + "</div><div class='mesWindowBottom'></div>";
    var v_top = (document.body.clientHeight - mesW.clientHeight) / 2;
    v_top += document.documentElement.scrollTop;
    styleStr = "top:" + (v_top - 180) + "px;left:" + (document.body.clientWidth / 2 - mesW.clientWidth / 2) + "px;position:absolute;width:410px;margin-left:-300px;left:50%;z-index:9999;";
    mesW.style.cssText = styleStr;
    document.body.appendChild(mesW);
}
//让背景渐渐变暗
function showBackground(obj, endInt) {//欢迎来到站长特效网，我们的网址是www.zzjs.net，很好记，zz站长，js就是js特效，本站收集大量高质量js代码，还有许多广告代码下载。
    if (isIe) {
        obj.filters.alpha.opacity += 5;
        if (obj.filters.alpha.opacity < endInt) {
            setTimeout(function() { showBackground(obj, endInt) }, 5);
        }
    } else {
        var al = parseFloat(obj.style.opacity); al += 0.05;
        obj.style.opacity = al;
        if (al < (endInt / 100))
        { setTimeout(function() { showBackground(obj, endInt) }, 5); }
    }
}
//关闭窗口
function closeWindow() {//欢迎来到站长特效网，我们的网址是www.zzjs.net，很好记，zz站长，js就是js特效，本站收集大量高质量js代码，还有许多广告代码下载。
    if (document.getElementById('back') != null) {
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if (document.getElementById('mesWindow') != null) {
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if (isIe) {
        setSelectState('');
    }
}
//测试弹出
function testMessageBox() {//欢迎来到站长特效网，我们的网址是www.zzjs.net，很好记，zz站长，js就是js特效，本站收集大量高质量js代码，还有许多广告代码下载。
    var messContent;

       messContent = "<div style='padding:20px 10 20px 10;text-align:left'>";
//    messContent = "<div class='colR_1_2011'>";
//    messContent += "<div class='colR_t_2_2011' style='color: #FF3300; font-size: 14px'>2011年春节放假公告</div>"
//    messContent += "<div class = 'colR_c_2_2011'>";
  
     messContent="尊敬的非常票务网客户：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2011兔年新春佳节即将来临，非常票务全体员工深深感谢广大新老客户在过去一年对我们的关心和支持，恭祝各位新老客户在新的一年里：<FONT style='COLOR: #ff0000'>身体健康、事业有成、合家欢乐、万事如意！</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
                 messContent+="非常票务按照公司实际情况,对2011年春节放假作如下安排:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 放假时间：<FONT style='COLOR: #ff0000'>2011年2月2日(腊月三十)-2011年2月8日（正月初六），2月9日(正月初七)正常上班。</FONT><BR>";
                 messContent += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 春节假日期间，非常票务不安排值班人员，客户请合理安排订票时间，在春节期间订票者一律无法出票，请您谅解。非常票务所有员工再次感谢您的支持！&nbsp;</div>";
//                 messContent += "<div class='colR_b_2011'></div></div>"
    showMessageBox('非常票务-春节放假通知', messContent, 350);
}

var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0; 

function getMsg() 
{ 
  try 
  { 
   divTop = parseInt(document.getElementById("loft_win").style.top,10); 
   divLeft = parseInt(document.getElementById("loft_win").style.left,10); 
   divHeight = parseInt(document.getElementById("loft_win").offsetHeight,10); 
   divWidth = parseInt(document.getElementById("loft_win").offsetWidth,10); 
   docWidth = document.body.clientWidth; 
   docHeight = document.body.clientHeight; 
   document.getElementById("loft_win").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight 
   document.getElementById("loft_win").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth; 
   document.getElementById("loft_win").style.visibility="visible"; 
   objTimer = window.setInterval("moveDiv()",10); 
  } 
  catch(e){} 
} 

//初始化位置 
function resizeDiv() 
{ 
  i+=1; 
  //if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句 
  try 
  { 
   divHeight = parseInt(document.getElementById("loft_win").offsetHeight,10); 
   divWidth = parseInt(document.getElementById("loft_win").offsetWidth,10); 
   docWidth = document.body.clientWidth; 
   docHeight = document.body.clientHeight; 
   document.getElementById("loft_win").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10); 
   document.getElementById("loft_win").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10); 
  } 
  catch(e){} 
} 

//最小化 
function minsizeDiv() 
{ 
  i+=1 
  //if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句 
  try 
  { 
   divHeight = parseInt(document.getElementById("loft_win_min").offsetHeight,10); 
   divWidth = parseInt(document.getElementById("loft_win_min").offsetWidth,10); 
   docWidth = document.body.clientWidth; 
   docHeight = document.body.clientHeight; 
   document.getElementById("loft_win_min").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10); 
   document.getElementById("loft_win_min").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10); 
  } 
  catch(e){} 
} 

//移动 
function moveDiv() 
{ 
try 
{ 
  if(parseInt(document.getElementById("loft_win").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10))) 
  { 
   window.clearInterval(objTimer); 
   objTimer = window.setInterval("resizeDiv()",1); 
  } 
  divTop = parseInt(document.getElementById("loft_win").style.top,10); 
  document.getElementById("loft_win").style.top = divTop -1; 
} 
  catch(e){} 
} 

function minDiv() 
{ 
  closeDiv(); 
  objTimer = window.setInterval("minsizeDiv()",1); 
} 

function maxDiv() 
{ 
 
  document.getElementById('loft_win').style.visibility='visible'; 
  objTimer = window.setInterval("resizeDiv()",1); 
  //resizeDiv() 
  getMsg(); 
} 

function closeDiv() 
{ 
  document.getElementById('loft_win').style.visibility='hidden'; 
 
  if(objTimer) window.clearInterval(objTimer); 
}

//右下角
function tips_pop() {
    var MsgPop = document.getElementById("winpop");
    var popH = parseInt(MsgPop.style.height); //将对象的高度转化为数字
    if (popH == 0) {
        MsgPop.style.display = "block"; //显示隐藏的窗口
        show = setInterval("changeH('up')", 2);
    }
    else {
        hide = setInterval("changeH('down')", 2);
    }
}
function changeH(str) {
    var MsgPop = document.getElementById("winpop");
    var popH = parseInt(MsgPop.style.height);
    if (str == "up") {
        if (popH <= 260) {
            MsgPop.style.height = (popH + 30).toString() + "px";
        }
        else {
            clearInterval(show);
        }
    }
    if (str == "down") {
        if (popH >= 4) {
            MsgPop.style.height = (popH - 30).toString() + "px";
        }
        else {
            clearInterval(hide);
            MsgPop.style.display = "none"; //隐藏DIV
        }
    }
}
function couplet() {
    if (arguments.length >= 1) this.objID = document.getElementById(arguments[0]);
    if (arguments.length >= 2) this.divTop = arguments[1];
    if (arguments.length >= 3) this.divPlane = arguments[2];
    if (arguments.length >= 4) this.scrollDelay = arguments[4];
    if (arguments.length >= 5) this.waitTime = arguments[5];
    if (!this.objID) {
        alert("对象名【" + arguments[0] + "】无效，对联无法初始化，请检查对象名称是否正确！");
        this.objID = null; return;
    } else {
        this.objID.style.position = "absolute";
        this.objID.style.display = "block";
        this.objID.style.zIndex = 9999;
    }
    if ("" == this.objID.style.top) {
        if (isNaN(this.divTop)) {
            alert("对象垂直位置(top)参数必须为数字。"); return;
        } else {
            this.objID.style.top = this.divTop + "px";
        }
    }
    if ("" == this.objID.style.left && "" == this.objID.style.right) {
        if (isNaN(this.divPlane)) {
            alert("对象水平位置(left||right)参数必须为数字。"); return;
        }
        if (this.divPlane > 0) this.objID.style.left = this.divPlane + "px";
        if (this.divPlane < 0) this.objID.style.right = Math.abs(this.divPlane) + "px";
    }
    if (this.scrollDelay < 15 || isNaN(this.scrollDelay)) this.scrollDelay = 15;
    if (this.waitTime < 500 || isNaN(this.waitTime)) this.waitTime = 500;
    if (arguments.length >= 1) this.start();
}
couplet.prototype.start = function() {
    if (null == this.objID) return;
    var objCouplet = this;
    timer = this.scrollDelay;
    objCouplet.lastScrollY = 0;
    objCouplet.timerID = null;
    objCouplet.startID = function() {
        if ("block" == objCouplet.objID.style.display) {
            objCouplet.run();
        } else {
            clearInterval(objCouplet.timerID);
        }
    }
    objCouplet.Begin = function() {
        objCouplet.timerID = setInterval(objCouplet.startID, timer);
    }

    setTimeout(objCouplet.Begin, this.waitTime);
}
couplet.prototype.run = function() {
    if (document.documentElement && document.documentElement.scrollTop) {
        uu_scrY = parseFloat(document.documentElement.scrollTop);
    } else if (document.body) {
        uu_scrY = parseFloat(document.body.scrollTop);
    }
    uu_divX = parseFloat(this.objID.style.top.replace("px", ""));
    uu_curTop = .1 * (uu_scrY - this.lastScrollY);
    uu_curTop = uu_curTop > 0 ? Math.ceil(uu_curTop) : Math.floor(uu_curTop);
    this.objID.style.top = parseFloat(uu_divX + uu_curTop) + "px";
    this.lastScrollY += uu_curTop;
}

function subscribe() {
    var v = document.getElementById("em1").value;
    if (!(isEmail(v))) {
        alert("Email格式不正确");
        return;
    }
    else {

        if (!String.prototype.format) {
            String.prototype.format = function() {
                var args = arguments;
                return this.replace(/\{(\d+)\}/g, function(word, i) {
                    return args[i];
                });
            }
        }
    
        var obj = null, url = '/aspx/DoAction.ashx/?action=ticektNotice&email={0}&op={1}';
        try {
            obj = new XMLHttpRequest();
        } catch (e) {
            try {
                obj = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        url = url.format(v, 4);
        obj.open('GET', url);
        obj.setRequestHeader("If-Modified-Since", "0");
        obj.send(null);
        obj.onreadystatechange = function() {
            if (obj.readyState == 4 && obj.status == 200) {
                var s = obj.responseText;
                if (s == 'failure') {
                    alert("系统发生错误，请待会尝试，谢谢！");
                }
                else {
                    alert("感谢您订阅非常票务网电邮通讯！您还可拨打400-820-1913，非常票务专业客服将为您服务！");
                }
            }
        }
    }
}

function isEmail(vEMail) {//判断邮箱函数， 
    if (vEMail != "") {
        var regInvalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
        var regValid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        return (!regInvalid.test(vEMail) && regValid.test(vEMail));
    }
}

function clean() {

    document.getElementById("em1").value = "";
}

