﻿// JScript 文件
function CtlClose(ctl) {
    if (typeof (ctl) != "object") {
        ctl = document.getElementById(ctl);
    }
    if (ctl != null)
        ctl.style.display = "none";
}

function CtlOpen(ctl) {
    if (typeof (ctl) != "object") {
        ctl = document.getElementById(ctl);
    }
    if (ctl != null)
        ctl.style.display = "";
}

function CtlOpenClose(ctl) {
    if (typeof (ctl) != "object") {
        ctl = document.getElementById(ctl);
    }
    if (ctl != null) {
        if (ctl.style.display == "none") {
            ctl.style.display = "";
        }
        else {
            ctl.style.display = "none";
        }
    }
}

function Show_OverflowDiv(ctlid, height) {
    var ctl = document.getElementById(ctlid);
    if (parseInt(ctl.style.height) + height / 10 <= height)
        ctl.style.height = (parseInt(ctl.style.height) + height / 10) + "px";
    else {
        ctl.style.height = height + "px";
        return;
    }

    setTimeout("Show_OverflowDiv('" + ctlid + "'," + height + ")", 30);
}

function Close_OverflowDiv(ctlid, height) {
    var ctl = document.getElementById(ctlid);
    if (parseInt(ctl.style.height) > height / 10)
        ctl.style.height = (parseInt(ctl.style.height) - height / 10) + "px";
    else {
        ctl.style.height = 0 + "px";
        return;
    }

    setTimeout("Close_OverflowDiv('" + ctlid + "'," + height + ")", 30);
}

function ShowHide_OverflowDiv(ctlid, height, callback) {
    var ctl = document.getElementById(ctlid);
    if (ctl.style.height == '' || parseInt(ctl.style.height) == 0)
        Show_OverflowDiv(ctlid, height);
    else
        Close_OverflowDiv(ctlid, height);
    if (typeof (callback) == "function")
        callback();
}

function clearBackGroup(ctlid) {
    var ctl = document.getElementById(ctlid);
    ctl.style.backgroundColor = "";
}


function WindowInit(id) {
    id =  id|| 'div_AuctionDream';
    if (id.indexOf('#') == -1)
        id = '#' + id;
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    $('#div_AjxBG').css({ 'width': maskWidth, 'height': maskHeight })
    .fadeIn(400)
    .fadeTo("slow", 0.8);

    $('div.popbg').css({ 'width': maskWidth, 'height': maskHeight })
    .fadeIn(400);

    var winH = $(window).height();
    var winW = $(window).width();

    $(id).css('top', Math.abs(winH / 2 - $(id).height() / 2 - 50 + $(document).scrollTop()));
    $(id).css('left', Math.abs(winW / 2 - $(id).width() / 2));

    $(id).fadeIn(800);
    $(id).show();

    $('div.close_float_lay a').click(function (e) {

        $('#div_AjxBG').hide();
        $('div.popbg').hide();
        $('#div_AuctionDream').hide();
    });
    //$(window||document).bind("resize",function() { WindowInit(); });
}



function Alert(message, title) {

    WindowInit();

    var div_title = document.getElementById("div_title");
    var div_info = document.getElementById("div_info");
    if (div_info != null && div_info.innerHTML != message) {
        if (!title || title.length == 0)
            title = '大鹅提示';
        div_title.innerHTML = title;
        if (!message || message.length == 0)
            message = '';
        div_info.innerHTML = message;
        div_info.style.display = '';
    }
}

function AlertTime(message, title, seconds) {

    WindowInit();

    var div_title = document.getElementById("div_title");
    var div_info = document.getElementById("div_info");

    if (!title || title.length == 0)
        title = '<img src="/image/v4.0/favicon.gif" style="padding:2px 4px 5px 0"/>大鹅提示';
    div_title.innerHTML = title;
    if (!message || message.length == 0)
        message = '';
    div_info.innerHTML = message;
    div_info.style.display = '';
    if (!seconds)
        seconds = 3000;
    div_info.innerHTML += "<span id=\"span_AutoCloseTime\" style=\"display:none;\">" + seconds / 1000 + "</span>";
    //div_info.innerHTML += "<br /><br />倒计时<span id=\"span_AutoCloseTime\">" + seconds / 1000 + "</span>后自动关闭<br /><br />";
    AutoCloseTime(seconds / 1000);
}

function AlertBack(message, title, seconds) {

    WindowInit();

    var div_title = document.getElementById("div_title");
    var div_info = document.getElementById("div_info");

    if (!title || title.length == 0)
        title = '<img src="/image/v4.0/favicon.gif" style="padding:2px 4px 5px 0"/>大鹅提示';
    div_title.innerHTML = title;
    if (!message || message.length == 0)
        message = '';
    div_info.innerHTML = message;
    div_info.style.display = '';
    if (!seconds)
        seconds = 3000;
    div_info.innerHTML += "<span id=\"span_AutoCloseTime\" style=\"display:none;\">" + seconds / 1000 + "</span>";
    //div_info.innerHTML += "<br /><br />倒计时<span id=\"span_AutoCloseTime\">" + seconds / 1000 + "</span>后自动跳转回上页<br /><br />";
    $('div.close_float_lay a').click(function() { window.history.back(); });
    AutoBackTime(seconds / 1000);
}

function AlertLogin(message, title) {

    WindowInit();

    var div_title = document.getElementById("div_title");
    var div_info = document.getElementById("div_info");
    divAuctionDream.innerHTML = divLogin.innerHTML;
    divLogin.innerHTML = "";
}

function AlertForgetPassword(n, m) {

    WindowInit();

    document.getElementById("div_title").innerHTML = "忘记密码";
    document.getElementById("div_info").style.display = "";
    document.getElementById("div_info").innerHTML = "请填写下列信息，填写完毕后我们会将重新设置您的密码的方法发到您注册所填写的Email里。<br /><br />" +
    "<table id='tblGetPass' cellspacing='10' cellpadding='0' style='text-align: center; width:100%' >" +
                    "<tr><td style='width: 150px;text-align: right'>用户名：</td>" +
                        "<td style='text-align: left;text-align: left'>" +
                            "<input ID='txt_FName' Style='border:solid 1px #ccc;padding:4px;width: 245px;' /></td></tr>" +
                    "<tr><td style='width: 150px;text-align: right'>注册时用的邮箱：</td>" +
                       "<td style='text-align: left'>" +
                            "<input ID='txt_FMobile' Style='border:solid 1px #ccc;padding:4px;width: 245px;' /></td></tr>" +
                    "<tr><td colspan='2'><input id='btn_FPost' type='button' value='提交' style='border:solid 1px #ccc;width:80px;padding:3px' onclick='AjaxForgetPassword()'></td> </tr></table>";
    if (n && n.length > 0)
        $('#txt_FName').val(n);
    if (m && m.length > 0)
        $('#txt_FMobile').val(m);
    AddDefaultEvents('#tblGetPass', 'btn_FPost');
}


function CheckIsOpen() {
    var divAuctionDream = document.getElementById("div_AuctionDream");
    if (divAuctionDream.style.display == "")
        return true;
    return false;
}

function AutoCloseTime(seconds) {

    var spanAutoCloseTime = document.getElementById("span_AutoCloseTime");

    if (spanAutoCloseTime != null && seconds >= 0) {
        spanAutoCloseTime.innerHTML = seconds;
        seconds--;
    }
    else if (seconds < 0) {
        CtlClose('div_AjxBG'); CtlClose('div_AuctionDream');
        return;
    }
    setTimeout("AutoCloseTime(" + seconds + ")", 1000);
}

function AutoBackTime(seconds) {

    if (!CheckIsOpen())
        return;
    var spanAutoCloseTime = document.getElementById("span_AutoCloseTime");

    if (spanAutoCloseTime != null && seconds >= 0) {
        spanAutoCloseTime.innerHTML = seconds;
        seconds--;
    }
    else if (seconds < 0) {
        CtlClose('div_AjxBG'); CtlClose('div_AuctionDream');
        window.history.back();
        return;
    }
    setTimeout("AutoBackTime(" + seconds + ")", 1000);
}

function AutoCloseTimeRedirect(seconds, url) {
    if (!CheckIsOpen())
        return;
    var spanAutoCloseTime = document.getElementById("span_AutoCloseTime");

    if (spanAutoCloseTime != null && seconds >= 0) {
        spanAutoCloseTime.innerHTML = seconds;
        seconds--;
    }
    else if (seconds < 0) {
        CtlClose('div_AjxBG'); CtlClose('div_AuctionDream');
        if (!url || url.length == 0)
            window.location.href = url;
        return;
    }
    setTimeout("AutoCloseTimeRedirect(" + seconds + ")", 1000);
}



var canceled = false;
function CountDownAndRedirect(message, redirectLocation, seconds, title) {
    if (!redirectLocation || redirectLocation.length == 0)
        redirectLocation = window.location.href;
    var mess;
    if (canceled) {
        CtlOpenClose('div_AuctionDream');
        CtlOpenClose('div_AjxBG');
        canceled = false;
        return;
        window.location.href = redirectLocation;
    }
    $('div.close_float_lay a').click(function() { window.location.href = redirectLocation; });
    if (seconds > 0) {

        if (window.location.href == redirectLocation) {
            mess = message;
        }
        else {
            mess = message;  //+ "<br>系统将在 <b>" + seconds + "</b> 秒后自动跳转到下面的页面:<br><br><a href='" + redirectLocation + "' target='_top'>" + redirectLocation + "</a><br><a href='javascript:void(0)' onclick='canceled=true;'>取消</a>";
        }
        Alert(mess, title);
        seconds--;
        countDownTimer = setTimeout("CountDownAndRedirect('" + message + "','" + redirectLocation + "'," + seconds + ")", 1000);
    }
    else {
        window.location.href = redirectLocation;
    }
}
//初始化产品分类菜单
initList = function () {
    if (typeof (alwaysOpen) == "undefined")
        return;
    alwaysOpen = (alwaysOpen == 'True');
    if (document.getElementById) {
        navBase = document.getElementById("all-items");
        navToggle = document.getElementById("J_Toggle");
        navTitle = document.getElementById("J_Allitems_Title");
        navContent = document.getElementById("J_Allitems_Content");
        navRoot = document.getElementById("J_Menu");
        if (!alwaysOpen) {
            navBase.style.top = "91px";
        }
        else {
            navBase.style.top = "91px";
            navTitle.className += " collapse-head";
            navContent.className += " show";
        }
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function () {
                    if (this.className != 'topclass') {
                        this.className += " current";
                    }
                    else {
                        this.className += " currenttop";
                    }

                    if (!alwaysOpen)
                        navContent.className += " show";
                };
                node.onmouseout = function () {
                    this.className = this.className.replace(" currenttop", "").replace(" current", "");
                };
            }
        }
        if (!alwaysOpen) {
            navBase.onmouseover = function () {
                navToggle.className += " extend-trigger";
                navTitle.className += " collapse-head";
                navContent.className += " show";
            };
            navBase.onmouseout = function () {
                navToggle.className = navToggle.className.replace(/ extend-trigger/g, "");
                navTitle.className = navTitle.className.replace(/ collapse-head/g, "");
                navContent.className = navContent.className.replace(/ show/g, "");
            };
        }
    }
};
//初始化产品分类菜单

function ShowDetial(o, id) {
    $("#s1_" + id).toggle();
    $("#s2_" + id).toggle();
    if ($(o).hasClass('textOpen')) {
        $(o).html("展开");
        $(o).removeClass().addClass('textClose');
    }
    else {
        $(o).html("收缩");
        $(o).removeClass().addClass('textOpen');
    }
}
function showDes(i) {
    $('#shorDes_' + i).toggle();
    $('#longDes_' + i).toggle();
    $('#openBtn' + i).css('display', $('#openBtn' + i).css('display') == 'none' ? 'inline' : 'none');
    $('#closeBtn' + i).css('display', $('#closeBtn' + i).css('display') == 'none' ? 'inline' : 'none');
}

function popUp(id) {
    WindowInit(id);
    $('#div_AuctionDream').hide();
    $('#' + id).show();
}
function ClosePopUp(id) {
    $('div.window-bg').hide();
    $('#' + id).hide();
}

///usage: onclick="openChat({orderid:21})"
function openChat(args) {
    if (args && args.orderid > 0) {
        newWindow = window.open('/user/chat.aspx?orderid=' + args.orderid, "ChatWindow", "width=800,height=680");
        window.opener = null;
        window.open("", "_self");
    }
}
function openWindow(args) {
    if (args && args.url && args.url.length > 0) {
        var ww = args.width || 800;
        var wh = args.height || 600;
        newWindow = window.open(args.url, "LWindow", "scrollbars=yes,width=" + ww + ",height=" + wh);
        window.opener = null;
        window.open("", "_self");
    }
}
function switchFilter(i) {
    $('div.filterbar table').each(function(idx) {
        if (idx == i)
            $(this).show();
        else
            $(this).hide();
    });
}
function autoHeight(id) { $("#" + id).load(function() { $(this).height($(this).contents().find("html").height() + 50); }); };
function SelectType(o, d) {

    $('#ulTypeSelect li').each(function() { $(this).removeClass(); });
    if (typeof (o) == "object")
        $(o).addClass('selected');
    else
        $('#ulTypeSelect li:eq(' + o + ')').addClass('selected');
    var id, prc, unt, mt, mtn;
    id = d.id;
    prc = d.prc;
    unt = d.unt;
    mt = d.mt;
    mtn = d.mtn;

    $('#J_LinkBuy').attr('href', '/user/Account/order.aspx?id=' + id + '&mt=' + mt + '&qt=1');
    $('#J_LinkAdd').attr('href', '/user/account/DreamsICare.aspx?id=' + id);

    $('#unit1').html(unt);
    $('#unit2').html(unt);
    $('#unit3').html(unt);
    $('#unitPrice1').html(prc);
    $('#unitPrice2').html(prc);
    $('#buyQuantity').val('1');
    $('#totalPrice').html(prc);
    $('#sMT').html(mtn);
    $('#sUC').html('1' + unt);
}
function SelectCourse(o, d) {

    $('#ulTypeSelectM li').each(function() { $(this).removeClass(); });
    if (typeof (o) == "object")
        $(o).addClass('selected');
    else
        $('#ulTypeSelectM li:eq(' + o + ')').addClass('selected');
    var id, prc, unt, mt, mtn, grp, st, dis;
    id = d.id;
    prc = d.prc;
    mt = d.mt;
    mtn = d.mtn;
    grp = d.grp || false;
    st = d.st;
    dis = d.discount;
    if (parseFloat(dis) > 0 && parseFloat(dis) < 10) {
        prc = prc * dis / 10;
        $('#pricePerUser1').css("text-decoration", "line-through");
    }
    var timeNow, timeStart, timeEnd;
    var maxA, curA;
    timeNow = $('#timeNow').html().Trim().replace(/\-/g, '/');
    timeEnd = $('#timeEnd').html().Trim().replace(/\-/g, '/');
    if (typeof (d.st) != "undefined")
        timeStart = d.st.replace(/\-/g, '/');

    curA = $('#reserved').html().Trim();
    maxA = $('#maxUsers').html().Trim();
    if (curA.Trim() == "")
        curA = 0;
    var tmaxA = maxA.replaceAll("至多", "").replaceAll("人", "");
    if (new Date(timeNow) < new Date(timeEnd) && (maxA == "无上限" || parseInt(curA, 10) < parseInt(tmaxA, 10)) && (!grp || (grp && new Date(timeStart) <= new Date(timeNow)))) {
        $('#J_LinkReserve').attr('href', '/user/Account/order.aspx?id=' + id + '&mt=' + mt + '&qt=1');

    }
    else {
        $('#J_LinkReserve').attr('href', 'javascript:');
        $('#J_LinkReserve').parent().removeClass().addClass('btn-resv-g');
        $('#reserveQuantity').attr('disabled', 'disabled');
    }
    $('#J_LinkAddReserve').attr('href', '/user/account/DreamsICare.aspx?id=' + id);
    $('#pricePerUser1').html(d.prc);
    $('#pricePerUser2').html(prc);
    $('#reserveQuantity').val('1');
    $('#totalPriceReserved').html(prc);
    $('#rMT').html(mtn);
    $('#rUC').html('1人');
}
function SelectTask(id) {
    var qt, prc;


    qt = $('#buyQuantityTask').val();
    prc = $('#unitPriceTask').html();
    if (qt > 0 && prc > 0) {
        $('#totalPriceTask').html(qt * prc);
        $('#tUC').html(qt);
    }
    else {
        qt = 1;
        $('#totalPriceTask').html(prc);
        $('#tUC').html(qt);
    }
    $('#J_LinkTask').attr('href', '/user/Account/order.aspx?id=' + id + '&mt=4&qt=' + qt);
    $('#J_LinkAddTask').attr('href', '/user/account/DreamsICare.aspx?id=' + id);
}
function CaclTotal(q, u, t, s, d) {
    var num = /^\d+$/;
    var qty = $.trim($('#' + q).val());
    if (!num.test(qty) || qty <= 0 || qty > 100) {
        alert('请输入一个正确的购买数量！');
        $('#J_LinkReserve').click(function() { return false; });
        $('#J_LinkAddReserve').click(function() { return false; });
        $('#J_LinkBuy').click(function() { return false; });
        $('#J_LinkAdd').click(function() { return false; });
        return false;
    }
    var up = $.trim($('#' + u).html());
    var sel = $('#' + s);
    sel.html(qty + sel.html().replace(/\d/g, ''));
    var tpc = qty * up;
    var dis = $.trim($('#' + d).html());
    if (dis && parseFloat(dis) > 0 && parseFloat(dis) < 10)
        tpc = tpc * parseFloat(dis) / 10;
    $('#' + t).html(tpc);

    var lk_buy, lk_add;
    if (q == "buyQuantity") {
        lk_buy = $('#J_LinkBuy').attr('href');
        lk_add = $('#J_LinkAdd').attr('href');
    }
    else if (q == "reserveQuantity") {
        lk_buy = $('#J_LinkReserve').attr('href');
        lk_add = $('#J_LinkAddReserve').attr('href');
    }
    else {
        lk_buy = $('#J_LinkTask').attr('href');
        lk_add = $('#J_LinkAddTask').attr('href');
    }

    lk_buy = lk_buy.substring(0, lk_buy.length - 1) + qty;

    $('#J_LinkBuy').attr('href', lk_buy);
    $('#J_LinkReserve').attr('href', lk_buy);
    $('#J_LinkTask').attr('href', lk_buy);

    lk_add = lk_add.substring(0, lk_add.length - 1) + qty;
    $('#J_LinkAdd').attr('href', lk_add);
    $('#J_LinkAddReserve').attr('href', lk_add);
    $('#J_LinkAddTask').attr('href', lk_add);
}
function showPreview() {
    var curleft = curtop = 0;
    var obj = document.getElementById("thumbs");
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj.offsetParent) {
            obj = obj.offsetParent;
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    $('#star-picture')
	    .css("left", curleft - 12)
	    .css("top", curtop - 248)
	    .show('fast');
}
function AddDefaultEvents(container, btnid) {
    $(container).find('input[type=text]').each(function() {

        $(this).keydown(function(e) {
            if (e.keyCode == 13) {
                if (btnid && document.getElementById(btnid))
                    document.getElementById(btnid).click();
                return false;
            }
        });
    });
}
function showLicense(url, title) {
    var id = '#corpFunnelPopup';
    $('#license-frm').attr('src', url);
    $(id + ' .titleLeft').html(title);

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    $('#div_InfoBG').css({ 'width': maskWidth, 'height': maskHeight });

    var winH = $(window).height();
    var winW = $(window).width();

    $(id).css('top', Math.abs(winH / 2 - $(id).height() / 2 - 50 + $(document).scrollTop()));
    $(id).css('left', Math.abs(winW / 2 - $(id).width() / 2));

    $('#div_InfoBG').show('slow');
    $(id).show('slow');
}
function hideLicense() {
    $('#div_InfoBG').hide('slow');
    $('#corpFunnelPopup').hide('slow');
}
function typeChanged(o) {
    var v = scht.val();
    if (v == '' || v == dpt || v == dut) {
        var su = o.id == "lu";

        if (su)
            scht.val(dut);
        else
            scht.val(dpt);
        scht.css({ color: '#ccc' });
    }
}
function SearchInit() {
    $('#search-selector').cssRadio(typeChanged);
    scht
        .focus(function (e) { if (this.value == dpt || this.value == dut) this.value = ''; $(this).css({ color: '#000' }); })
        .blur(function (e) {
            if (this.value == '') {
                var su = $('#search-selector input:radio')[1].checked;

                if (su)
                    this.value = dut;
                else
                    this.value = dpt;
                $(this).css({ color: '#ccc' });
            }
        })
        .keydown(function (e) {
            var evt = window.event | e;
            if (e.keyCode == 13) {
                document.getElementById(schb).click();
                return false;
            }
        });
    $('#' + schb)
        .click(function () {
            if (scht.val() == dpt || scht.val() == dut)
                scht.val('');
        });
    }
    function lp(o, d) {
        $('#ulTypeSelect li').each(function () { $(this).removeClass(); });
        if (typeof (o) == "object")
            $(o).addClass('selected');
        else
            $('#ulTypeSelect li:eq(' + o + ')').addClass('selected');
        var id, prc, unt, mt, mtn,dis;
        id = d.id;
        prc = d.prc;
        unt = d.unt;
        mt = d.mt;
        mtn = d.mtn;
        dis = d.discount;
        if (parseFloat(dis) > 0 && parseFloat(dis) < 10) {
            prc = prc * dis / 10;
            //$('#unitPrice').css("text-decoration", "line-through");
        }
        $('#J_LinkBuy').attr('href', '/deal/buy.aspx?id=' + id + '&mt=' + mt);

        $('#unit1').html(unt);
        $('#unit2').html(unt);
        $('#unitPrice').html(d.prc);
        $('#buyQuantity').val('1');
        $('#totalPrice').html(prc);
    }
    function cq() {
        var num = /^\d+$/;
        var qty = $.trim($('#buyQuantity').val());
        if (!num.test(qty) || qty <= 0 || qty > 100) {
            alert('请输入一个正确的购买数量！');
            $('#J_LinkBuy').click(function () { return false; });
            return false;
        }

        var lk_buy= $('#J_LinkBuy').attr('href');
           

        lk_buy = lk_buy.substring(0, lk_buy.lastIndexOf('=')+1) + qty;

        $('#J_LinkBuy').attr('href', lk_buy);       
    }
