var CollectionMyFavorite = " <ul><li class=\"dot_tc\">" + window.CollectionMyFavorite + "</li></ul>";
var showWindown = true;
var templateSrc = "/"; //set loading.gif path
var loadingImgSrc = templateSrc + "_Images/035loading.gif";
var loadingContent = "<div id=\"windown-pop_login_load\" class=\"pop_login_load\"><img width=\"16\" height=\"16\" style=\"vertical-align: middle;\"  src=\"/_Images/u164.gif\"> Loading...</div>"
var currentPageUrl;
var arrayList =
{
    spanClose: ".spanclose",
    contentId: "#windown-content",
    closeSpanClose: function () {
        $(arrayList.spanClose).css("display", "none")
    },
    resetWidth: function (_width) {
        $(arrayList.contentId).css("width", _width + "px");
    },
    resetHeight: function (_height) {
        $(arrayList.contentId).css("height", _height + "px");
    }
};
var _closeWindown_box = function () {
    $("#windown-box").remove();
}
var _setWindown_box_Title = function (_title) {
    $("#windown-title").find("h2").html($.trim(_title));
}
//first login
var PleaseFirstLoginIn = function () {
    var _UserId = 0;
    _UserId = window.UserID;
    if (_UserId <= 0) {
        //        var _content1 = window.FirstLogin;
        //        tipsWindown("tipsuccess", "", "490", "50", "true", "", "true");
        //        $("#windown-title h2").css("display", "none");
        //        arrayList.closeSpanClose();
        //        $("#windown-content").html(_content1);
        //setHiddien(3000);
        var returnUrl = window.location.href;
        $.cookie('ReturnUrl', returnUrl, { expires: 1, path: '/' });
        UIUserLogin();
        return false;
    }
    else {
        return true;
    }
}
var Submiting = function (typeId) {
    var submitingSuccess = window.SubmintingSuccess;
    var submitingFail = window.SubmintingFail;
    var _content1 = window.Subminting;
    var _content2 = submitingSuccess;
    var _content3 = submitingFail;
    if ($("#windownbg").is("div") == true && $("#windown-content").is("div") == true) {
        if (typeId == 10) {
            $("#windown-content").html(_content2);
        }
        else if (typeId == 20) {
            $("#windown-content").html(_content3);
        }
        setHiddien(3000);
        return;
    }
    $("#windownbg").remove();
    $("#windown-box").remove();
    tipsWindown("tipsuccess", "", "490", "50", "true", "", "true");
    $("#windown-title h2").css("display", "none");
    $("#windown-content").css("line-height", "50px");
    arrayList.closeSpanClose();
    $("#windown-content").html(_content1);
}

function tipsWindownBuffer(width, height, drag, intype) {
    $("#windown-box").remove(); //remove content
    var width = width >= 950 ? this.width = 950 : this.width = width;     //set the biggest width
    var height = height >= 527 ? this.height = 527 : this.height = height;  //set the biggest height
    if (showWindown == true) {
        var simpleWindown_html = new String;
        simpleWindown_html += "<div id=\"windown-box\" class=\"title1\">";
        simpleWindown_html += "<div id=\"windown-border\" >";
        simpleWindown_html += "<div id=\"windown-pop_login_load\" class=\"pop_login_load\"><img width=\"16\" height=\"16\" style=\"vertical-align: middle;\"  src=\"/_Images/u164.gif\"> Loading...</div>"
        simpleWindown_html += "</div>";
        simpleWindown_html += "</div>";
        $("body").append(simpleWindown_html);
        show = false;
    }
    $("#windown-box").show();
    if (height >= 527) {
        $("#windown-pop_login_load").css({ width: (parseInt(width) + 17) + "px" });
    } else {
        if (typeof height == "undefined" || $.trim(height).length < 1) {
            $("#windown-pop_login_load").css({ width: width + "px" });
            height = $("#windown-pop_login_load").css("height");
        }
        else {
            $("#windown-pop_login_load").css({ width: width + "px", height: height + "px" });
        }
        //$("#windown-content").css({ width: width + "px", height: height + "px" });
        //$("#windown-content").css({ width: width + "px" });
    }
    var cw = document.documentElement.clientWidth, ch = document.documentElement.clientHeight, est = document.documentElement.scrollTop;
    var _version = $.browser.version;

    if (_version == 6.0) {
        $("#windown-box").css({ left: "50%", top: (parseInt((ch) / 2) + est) + "px", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    } else {
        $("#windown-box").css({ left: "50%", top: "50%", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    };
    var Drag_ID = document.getElementById("windown-box"); //, DragHead = document.getElementById("windown-title");
    var moveX = 0, moveY = 0, moveTop, moveLeft = 0, moveable = false;
    if (_version == 6.0) {
        moveTop = est;
    } else {
        moveTop = 0;
    }
    var sw = Drag_ID.scrollWidth, sh = Drag_ID.scrollHeight;
    //$("#windown-content").attr("class", "windown-" + cssName);
    var closeWindown = function () {
        //$("#windownbg").remove();
        $("#windown-box").fadeOut("slow", function () { $(this).remove(); });
    }
    SelectFun(intype);
}

function tipsWindown(title, content, width, height, drag, time, showbg) {
    $("#windown-box").remove(); //remove content
    var width = width >= 950 ? this.width = 950 : this.width = width;     //set the biggest width
    var height = height >= 527 ? this.height = 527 : this.height = height;  //set the biggest height
    if (showWindown == true) {
        var simpleWindown_html = new String;
        simpleWindown_html += "<div id=\"windown-box\" class=\"title1\">";
        simpleWindown_html += "<div id=\"windown-border\" >"
        simpleWindown_html += "<span class=\"spanclose\"><a id=\"a_tips_windclose\" class=\"windclose\"><img width=\"16\" height=\"16\" src=\"/_Images/login_btn_del.png\"></a></span>";
        //simpleWindown_html += "<div class=\"pop_1_top\"></div>";
        simpleWindown_html += "<div id=\"windown-title\"><h2></h2></div>";
        simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\" class=\"windown-content-class\"></div><div id='tmp1' style='display:none; '></div>";
        //simpleWindown_html += "<div class=\"pop_1_bottom\"></div>";
        simpleWindown_html += "<div class=\"login_footer\">";
        simpleWindown_html += "<div style=\"float: right;\"><a id=\"a_tips_profinal_big_btn_g\" class=\"profinal_big_btn_g pop_profinal_big_btn_g\" href=\"javascript:void(0);\">" + window.Cancel + "</a></div>";
        simpleWindown_html += "<div style=\"margin-right: 5px; float: right;\"><a id=\"profinal_big_btn_blue\" class=\"profinal_big_btn_blue pop_profinal_big_btn_blue\" href=\"javascript:void(0);\"></a></div>";
        simpleWindown_html += "<font id=\"windown-content-font\" style=\" display: none;\">" + window.IsAccounts + " <a href=\"/home/signin\" class=\"blue\">" + window.SignIn + "</a></font></div>";
        simpleWindown_html += "</div></div>";
        $("body").append(simpleWindown_html);
        show = false;
    }

    $("#windown-title h2").html(title);
    if (showbg == "true") { $("#windownbg").show(); } else { $("#windownbg").remove(); };
    $("#windownbg").animate({ opacity: "0.5" }, "normal"); //set opacity
    $("#windown-box").show();
    if (height >= 527) {
        //$("#windown-title").css({ width: (parseInt(width) + 22) + "px" });
        //$("#windown-content").css({ width: (parseInt(width) + 17) + "px", height: height + "px" });
        $("#windown-content").css({ width: (parseInt(width) + 17) + "px" });
    } else {
        //$("#windown-title").css({ width: (parseInt(width) + 10) + "px" });
        if (typeof height == "undefined" || $.trim(height).length < 1) {
            $("#windown-content").css({ width: width + "px" });
            height = $("#windown-content").css("height");
        }
        else {
            $("#windown-content").css({ width: width + "px", height: height + "px" });
        }
        //$("#windown-content").css({ width: width + "px", height: height + "px" });
        //$("#windown-content").css({ width: width + "px" });
    }
    var cw = document.documentElement.clientWidth, ch = document.documentElement.clientHeight, est = document.documentElement.scrollTop;
    var _version = $.browser.version;

    if (_version == 6.0) {
        $("#windown-box").css({ left: "50%", top: (parseInt((ch) / 2) + est) + "px", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    } else {
        $("#windown-box").css({ left: "50%", top: "35%", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    };
    var Drag_ID = document.getElementById("windown-box"), DragHead = document.getElementById("windown-title");
    var moveX = 0, moveY = 0, moveTop, moveLeft = 0, moveable = false;
    if (_version == 6.0) {
        moveTop = est;
    } else {
        moveTop = 0;
    }
    var sw = Drag_ID.scrollWidth, sh = Drag_ID.scrollHeight;
    DragHead.onmouseover = function (e) {
        if (drag == "true") { DragHead.style.cursor = "move"; } else { DragHead.style.cursor = "default"; }
    };

    DragHead.onmousedown = function (e) {
        if (drag == "true") { moveable = true; } else { moveable = false; }
        e = window.event ? window.event : e;
        var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop - moveTop;
        moveX = e.clientX - ol;
        moveY = e.clientY - ot;
        document.onmousemove = function (e) {
            if (moveable) {
                e = window.event ? window.event : e;
                var x = e.clientX - moveX;
                var y = e.clientY - moveY;
                if (x > 0 && (x + sw < cw) && y > 0 && (y + sh < ch)) {
                    Drag_ID.style.left = x + "px";
                    Drag_ID.style.top = parseInt(y + moveTop) + "px";
                    Drag_ID.style.margin = "auto";
                }
            }
        }
        document.onmouseup = function () { moveable = false; };
        Drag_ID.onselectstart = function (e) { return false; }
    }

    //$("#windown-content").attr("class", "windown-" + cssName);
    var closeWindown = function () {
        $("#windownbg").remove();
        $("#windown-box").fadeOut("slow", function () { $(this).remove(); });
    }
    if (time == "" || typeof (time) == "undefined") {
        $("#windown-close").click(function () {
            $("#windownbg").remove();
            $("#windown-box").fadeOut("slow", function () { $(this).remove(); });
        });
    } else {
        setTimeout(closeWindown, time);
    }
    $("#a_tips_windclose").click(function () {
        closeWindown();
    });
    $("#a_tips_profinal_big_btn_g").click(function () {
        closeWindown();
    });
    $("#windownbg").click(function () {
        $("#windownbg").remove();
        $("#windown-box").fadeOut("slow", function () { $(this).remove(); });
    });
}


//unction tipsWindown(title, content, width, height, drag, time, showbg) {
function tipsWindown_TestQuestion(title, pageURL) {
    var innerWidth = 790;
    var innerHeight = 830;

    var ScreenWidth = screen.availWidth
    var ScreenHeight = screen.availHeight
    var StartX = (ScreenWidth - innerWidth) / 2
    var StartY = (ScreenHeight - innerHeight) / 2
    window.open(pageURL, 'newwindow', 'left=' + StartX + ', top=' + StartY + ', Width=' + innerWidth + ', height=' + innerHeight + ', resizable=no, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}
function CloseTestQuestion() {
    window.close();
}

function TipMessage(Mes) {
    var _content1 = "<div style=\"padding:10px;\">" + Mes + "</div>";
    tipsWindown(window.TooltipTitleTips, "", "470", "", "true", "", "true");
    $("#windown-content").html(_content1);
    $("#profinal_big_btn_blue").css("display", "none");
    $("#a_tips_profinal_big_btn_g").html(colse);
}

function TipMessageRefresh(Mes) {
    var _content1 = "<div style=\"padding:10px;\">" + Mes + "</div>";
    tipsWindown(window.TooltipTitleTips, "", "470", "", "true", "", "true");
    $("#windown-content").html(_content1);
    $("#profinal_big_btn_blue").css("display", "none");
    $("#a_tips_profinal_big_btn_g").html(colse);
    $("#a_tips_profinal_big_btn_g").click(function () {
        window.location.href = document.URL;
    });
}

function TipMessageRedirect(Mes, Url) {
    var _content1 = "<div style=\"padding:10px;\">" + Mes + "</div>";
    tipsWindown(window.TooltipTitleTips, "", "470", "", "true", "", "true");
    $("#windown-content").html(_content1);
    $("#profinal_big_btn_blue").css("display", "none");
    $("#a_tips_profinal_big_btn_g").html(colse);
    $("#a_tips_profinal_big_btn_g").click(function () {
        window.location.href = Url; //document.URL;
    });
}

function TipMessageRetrievePassWord() {
    var txtEmail = $("#txtUserEmail").val();
    var getUrl = GetUrl(txtEmail);
    var _content1 = $("#TipMessageRetrievePassWord").clone();
    tipsWindown(window.TooltipTitle, "", "470", "", "true", "", "true");
    $("div.login_content", _content1).find("a").html(txtEmail);
    $("div.login_content", _content1).find("a").attr("href", getUrl);
    $("#windown-content").html(_content1.html());
    $("#profinal_big_btn_blue").css("display", "none");
}

function TipMessageAttestation(obj) {
    var txtEmail = $(obj).parents("#windown-content-border").find(".txtUserEmail").val();
    var getUrl = "";
    if (txtEmail != null) {
        getUrl = GetUrl(txtEmail);
    }
    var _content1 = $("#TipMessageAttestationContent").clone();
    tipsWindown(window.TooltipTitle, "", "470", "", "true", "", "true");
    $("div.login_content", _content1).find("a").html(txtEmail);
    $("div.login_content", _content1).find("a").attr("href", getUrl);
    $("#windown-content").html(_content1.html());
    $("#profinal_big_btn_blue").css("display", "none");
}


function GetUrl(txtEmail) {
    var query = txtEmail.split("@")[1];
    var activateUrl = "";
    if (txtEmail.indexOf("@hotmail") > -1) {
        activateUrl = "http://www.hotmail.com";
    } else if (txtEmail.indexOf("@sina") > -1) {
        activateUrl = "http://www.sina.com";
    } else if (txtEmail.indexOf("@gmail") > -1) {
        activateUrl = "http://gmail.google.com";
    } else if (txtEmail.indexOf("@foxmail") > -1) {
        activateUrl = "http://www.foxmail.com/";
    } else if (txtEmail.indexOf("@126") > -1) {
        activateUrl = "http://www.126.com/";
    } else if (txtEmail.indexOf("@163") > -1) {
        activateUrl = "http://www.163.com/";
    } else if (txtEmail.indexOf("@189") > -1) {
        activateUrl = "http://www.189.com/";
    } else if (txtEmail.indexOf("@qq") > -1) {
        activateUrl = "http://www.mail.qq.com/";
    } else if (txtEmail.indexOf("@yeah") > -1) {
        activateUrl = "http://www.yeah.com/";
    } else if (txtEmail.indexOf("@eyou") > -1) {
        activateUrl = "http://www.eyou.com/";
    } else {
        activateUrl = "http://mail." + query;
    }
    return activateUrl;
}

function setHiddien(_time) {
    var closeWindown = function () {
        $("#windownbg").remove();
        $("#windown-box").fadeOut("slow", function () { $(this).remove(); });
    }
    setTimeout(closeWindown, _time);
}


