﻿// JScript 文件
function DIVShow(i) {
    if (document.getElementById(i).style.display == '')
        document.getElementById(i).style.display = 'none';
    else
        document.getElementById(i).style.display = '';
}

var curTip = "";
function displayToolTip(id) {
    if (curTip != "") {
        hideToolTip(curTip);
    }

    tip = document.getElementById(id);
    tip.style.display = "block";
    tip.style.zIndex = 1000;
    curTip = id;
}

function hideToolTip(id) {
    tip = document.getElementById(id);
    tip.style.display = "none";
    curTip = "";
}

function calculateProject(formindex) {
    var p = document.getElementById("__s0_p_" + formindex);
    var n = document.getElementById("__s0_n_" + formindex);
    var l1 = document.getElementById("__s0_l1_" + formindex);
    var l2 = document.getElementById("__s0_l2_" + formindex);
    var l1v = parseInt((l1.value == "" ? "0" : l1.value), 10), l2v = parseInt((l2 == null ? "-1" : (l2.value == "" ? "0" : l2.value)), 10);
    document.getElementById("__s0_pr_" + formindex).value = "";
    document.getElementById("__s0_tm_" + formindex).value = "";
    if (l1v <= 0 || (l1v >= l2v && l2v != -1))
        return;
    GetProductInfo(p.value, n.value, l1v, l2v, formindex);
}

function changeProject(formindex) {
    document.getElementById("__s0_pr_" + formindex).value = "";
    document.getElementById("__s0_tm_" + formindex).value = "";
    var l1 = document.getElementById("__s0_l1_" + formindex);
    var l2 = document.getElementById("__s0_l2_" + formindex);
    if (l1 != null) { l1.value = ""; try { l1.selectedIndex = 0; } catch (e) { } }
    if (l2 != null) { l2.value = ""; try { l2.selectedIndex = 0; } catch (e) { } }
}

//初始化AJAX引擎
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) return new XMLHttpRequest();
    try { return new ActiveXObject('MSXML2.XMLHTTP.4.0'); }
    catch (e) {
        try { return new ActiveXObject('MSXML2.XMLHTTP.3.0'); }
        catch (e) {
            try { return new ActiveXObject('MSXML2.XMLHTTP.2.6'); }
            catch (e) {
                try { return new ActiveXObject('MSXML2.XMLHTTP'); }
                catch (e) {
                    try { return new ActiveXObject('Microsoft.XMLHTTP'); }
                    catch (e) { return null; } 
                } 
            } 
        } 
    }
}

function GetLevelInfo() {
    var s_l = document.getElementById("__l_sl").value;
    d = new Date();
    var e_l = document.getElementById("__l_el").value;
    document.getElementById("StartLevel").value = s_l;
    document.getElementById("EndLevel").value = e_l;
    if (parseFloat(s_l) > parseFloat(e_l)) {
        document.getElementById("__l_sl").value = document.getElementById("__l_sl").options[0].value;
        s_l = document.getElementById("__l_sl").value;
    }
    var pobj = document.getElementById("__l_char");
    var pguid;
    if (pobj != null) {
        pguid = pobj.value;
    }
    else
        pguid = "";
    document.getElementById("Profession").value = pguid;
    XMLHTTP = createXMLHttpRequest();
    if (XMLHTTP == null) {
        alert("对不起你的浏览器不支持XMLHTTP,请升级");
        return;
    }

    XMLHTTP.onreadystatechange = LevelInfoBack;
    XMLHTTP.open("GET", "PLLevelOutPut.aspx?gamecode=" + '<%= gamecode%>' + "&pguid=" + pguid + "&start=" + s_l + "&end=" + e_l + "&" + d.getTime().toString(), true);
    XMLHTTP.send(null);
}

function LevelInfoBack() {
    if (XMLHTTP.readyState != 4)
        return;
    var text = XMLHTTP.responseText;

    //分析文本并显示到页面
    var data = text.split("\n");
    if (data.length > 0) {
        if (data[0] != null && data[0] != "")
            document.getElementById("lblPrice").value = Math.round(parseFloat(data[0]) * 1000) / 1000;
        if (data[1] != null && data[1] != "")
            document.getElementById("lblTime").value = Math.round(parseFloat(data[1]) * 1000) / 1000;
    }
}

function GetProductInfo(pguid, nguid, start, end, index) {
    var d = new Date();
    var code = d.toLocaleTimeString();
    XMLHTTP = createXMLHttpRequest();
    if (XMLHTTP == null) {
        alert("对不起你的浏览器不支持XMLHTTP,请升级");
        return;
    }

    XMLHTTP.onreadystatechange = ProductInfoBack;
    //alert(pguid+"/"+nguid+"/"+start+"/"+end+"/"+index+"/"+d.getTime().toString());
    XMLHTTP.open("GET", "PLDataDispose.aspx?pguid=" + pguid + "&nguid=" + nguid + "&start=" + start + "&end=" + end + "&index=" + index + "&" + d.getTime().toString(), true);
    XMLHTTP.send(null);
}

function ProductInfoBack() {
    if (XMLHTTP.readyState != 4)
        return;
    var text = XMLHTTP.responseText;

    //分析文本并显示到页面
    var data = text.split("\n");
    if (data.length > 0) {
        if (data[0] != null && data[0] != "")
            document.getElementById("__s0_pr_" + data[2]).value = Math.round(parseFloat(data[0]) * 1000) / 1000;
        if (data[1] != null && data[1] != "")
            document.getElementById("__s0_tm_" + data[2]).value = Math.round(parseFloat(data[1]) * 1000) / 1000;
    }
}

function checksubmit() {
    var formsubmit = document.buysubmit;
    if (formsubmit == null) {
        alert('find a error!');
        return;
    }

    var product = null;
    try {
        product = formsubmit.interfaceProduct.options[formsubmit.interfaceProduct.selectedIndex].text;
    }
    catch (ex) {
        alert("please select product");
        return;
    }
    if (product == null || product == "" || product == "--Choose--") {
        alert("please select product");
        return;
    }
    if (formsubmit.tboxFullName.value == "") {
        alert('Please input your full name!'); formsubmit.tboxFullName.focus(); return;
    }
    if (formsubmit.tboxCharacterName.value == "") {
        alert('Please input your character name!'); formsubmit.tboxCharacterName.focus(); return;
    }
    if (formsubmit.tboxEmail.value == "") {
        alert('Please input your email! '); formsubmit.tboxEmail.focus(); return;
    }
    var reg = new RegExp("^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$", "i");
    if (!reg.test(formsubmit.tboxEmail.value)) {
        alert('Your email is error! '); formsubmit.tboxEmail.focus(); return;
    }

    //buysubmit.submit();
    document.getElementById('buysubmit').submit();

}

function checkplsubmit() {
    var formsubmit = document.plbuyform;
    if (formsubmit == null) {
        alert('find a error!');
        return;
    }

    if (formsubmit.gamepass.value == "") {
        alert('Please input your Password!'); formsubmit.gamepass.focus(); return;
    }
    if (formsubmit.chname.value == "") {
        alert('Please input your character name!'); formsubmit.chname.focus(); return;
    }
    if (formsubmit.realname.value == "") {
        alert('Please input your real name!'); formsubmit.realname.focus(); return;
    }
    if (formsubmit.useremail.value == "") {
        alert('Please input your email! '); formsubmit.useremail.focus(); return;
    }
    var reg = new RegExp("^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$", "i");
    if (!reg.test(formsubmit.useremail.value)) {
        alert('Your email is error! '); formsubmit.useremail.focus(); return;
    }

    //plbuyform.submit();
    document.getElementById('plbuyform').submit();
}

function getRandom() {
    var p = Math.random();
    var t = true;
    while (t) {
        if (p >= 0.5)
            t = false;
        else
            p = Math.random();
    }
    x = parseInt(p * (3000 - 1)) + 1;
    document.write(x);
}

var FFXILiveChat = {
    init: function(gameCode) {
        var ffxiLiveChat = document.getElementById("FFXILiveChat");
        var liveChat = document.getElementById("LiveChat");
        if (ffxiLiveChat == null && liveChat == null) return;
        if (gameCode == "001") {
            FFXILiveChat.show(ffxiLiveChat);
            FFXILiveChat.hide(liveChat);
        } else {
            FFXILiveChat.hide(ffxiLiveChat);
            FFXILiveChat.show(liveChat);
        }
    },
    show: function(obj) {
        if (obj.style.display == "none") {
            obj.style.display = "block";
        }
    },
    hide: function(obj) {
        if (obj.style.display != "none") {
            obj.style.display = "none";
        }
    }
}
