﻿function initWidth() {
    if (document.getElementById('SearchBar1_tbSearchBar') != null) {
        var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 2;
        document.getElementById('ObjectDataGrid').style.width = vwidth;
        document.getElementById('tbObjectInputBar').style.width = vwidth;
    }
}

function ShowHide(panel) {
    if (document.getElementById(panel).style.display == "none") {
        document.getElementById(panel).style.display = "block";
    }
    else {
        document.getElementById(panel).style.display = "none";
    }
}

function Expand() {
    if (document.getElementById('ObjectDataGrid').style.display == "none") {
        document.getElementById('ObjectDataGrid').style.display = "block";
    }
    else {
        document.getElementById('ObjectDataGrid').style.display = "none";
    }
}

function ShowSection(objectname) {
    if (document.getElementById(objectname).style.display == "none") {
        document.getElementById(objectname).style.display = "block";
    }
    else {
        document.getElementById(objectname).style.display = "none";
    }
}

function ExpandGridView() {
    if (document.getElementById('tbGridViewBar').style.display == "none") {

        document.getElementById('tbGridViewBar').style.display = "block";

        if (document.getElementById('SubMenuBar1_tbGridViewBarLabel') != null) {
            document.getElementById('SubMenuBar1_tbGridViewBarLabel').style.display = "none";
        }

        if (document.getElementById('SearchBar1_tbSearchBar') != null) {
            if (document.getElementById('SearchBar1_tbSearchBar').style.display == "none") {
                var vwidth = document.body.offsetWidth - 3;
                document.getElementById('ObjectDataGrid').style.width = vwidth;
                document.getElementById('tbObjectInputBar').style.width = vwidth;
            }
            else {
                var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 3;
                document.getElementById('ObjectDataGrid').style.width = vwidth;
                document.getElementById('tbObjectInputBar').style.width = vwidth;
            }
        }

        document.getElementById("ObjectInput").style.display = "block";
        document.getElementById("InputZone").style.display = "none";
    }
    else {

        document.getElementById('tbGridViewBar').style.display = "none";
        if (document.getElementById('SubMenuBar1_tbGridViewBarLabel') != null) {
            document.getElementById('SubMenuBar1_tbGridViewBarLabel').style.display = "block";
        }

        if (document.getElementById('SearchBar1_tbSearchBar') != null) {
            if (document.getElementById('SearchBar1_tbSearchBar').style.display == "none") {
                var vwidth = document.body.offsetWidth - 3;
                document.getElementById('ObjectDataGrid').style.width = vwidth;
                document.getElementById('tbObjectInputBar').style.width = vwidth;
            }
            else {
                var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 3;
                document.getElementById('ObjectDataGrid').style.width = vwidth;
                document.getElementById('tbObjectInputBar').style.width = vwidth;
            }
        }

        document.getElementById("ObjectInput").style.display = "none";
        document.getElementById("InputZone").style.display = "block";
        document.getElementById("InputZone").style.height = "510px";
    }
}

function ExpandObjectInput() {
    if (document.getElementById('tbObjectInputBar').style.display == "none") {
        document.getElementById('tbObjectInputBar').style.display = "block";
        document.getElementById('SubMenuBar1_tbObjectInputBarLabel').style.display = "none";

        if (document.getElementById('SearchBar1_tbSearchBar').style.display == "none") {
            var vwidth = document.body.offsetWidth - 3;
            document.getElementById('ObjectDataGrid').style.width = vwidth;
            document.getElementById('tbObjectInputBar').style.width = vwidth;
        }
        else {
            var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 3;
            document.getElementById('ObjectDataGrid').style.width = vwidth;
            document.getElementById('tbObjectInputBar').style.width = vwidth;
        }
    }
    else {
        document.getElementById('tbObjectInputBar').style.display = "none";
        document.getElementById('SubMenuBar1_tbObjectInputBarLabel').style.display = "block";

        if (document.getElementById('SearchBar1_tbSearchBar').style.display == "none") {
            var vwidth = document.body.offsetWidth - 3;
            document.getElementById('ObjectDataGrid').style.width = vwidth;
            document.getElementById('tbObjectInputBar').style.width = vwidth;
        }
        else {
            var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 3;
            document.getElementById('ObjectDataGrid').style.width = vwidth;
            document.getElementById('tbObjectInputBar').style.width = vwidth;
        }
    }
}

function ExpandSearch() {
    if (document.getElementById('SearchBar1_tbSearchBar').style.display == "none") {
        document.getElementById('SearchBar1_tbSearchBar').style.display = "block";
        document.getElementById('SubMenuBar1_tbSearchBarLabel').style.display = "none";
        var vwidth = document.body.offsetWidth - document.getElementById('SearchBar1_tbSearchBar').width - 3;
        document.getElementById('ObjectDataGrid').style.width = vwidth
        document.getElementById('tbObjectInputBar').style.width = vwidth
    }
    else {
        document.getElementById('SearchBar1_tbSearchBar').style.display = "none";
        document.getElementById('SubMenuBar1_tbSearchBarLabel').style.display = "block";

        var vwidth = document.body.offsetWidth - 3;
        document.getElementById('ObjectDataGrid').style.width = vwidth;
        document.getElementById('tbObjectInputBar').style.width = vwidth;
    }
}

function OnSelect(objectname) {
    var dropdown = document.getElementById("input_" + objectname + "_drpInput");
    var option = dropdown.getElementsByTagName("option");
    for (var i = 0; i < option.length; i++) {
        if (option[i].selected) {
            document.getElementById("input_" + objectname + "_txtInput").value = option[i].text;
        }
    }
}

function sAlert(strTitle, strContent) {
    var msgw, msgh, bordercolor;
    msgw = 300; //提示窗口的宽度 																											
    msgh = 100; //提示窗口的高度 																											
    titleheight = 25 //提示窗口标题高度 																											
    bordercolor = "#336699"; //提示窗口的边框颜色 																											
    titlecolor = "#99CCFF"; //提示窗口的标题颜色 																											
    var sWidth, sHeight;
    sWidth = document.body.offsetWidth;
    sHeight = screen.height;
    var bgObj = document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position = "absolute";
    bgObj.style.top = "0";
    bgObj.style.background = "#777";
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity = "0.6";
    bgObj.style.left = "0";
    bgObj.style.width = sWidth + "px";
    bgObj.style.height = sHeight + "px";
    bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);
    var msgObj = document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.style.background = "white";
    msgObj.style.border = "1px solid " + bordercolor;
    msgObj.style.position = "absolute";
    msgObj.style.left = "50%";
    msgObj.style.top = "50%";
    msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial,Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px";
    msgObj.style.marginTop = -75 + document.documentElement.scrollTop + "px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height = msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight = "25px";
    msgObj.style.zIndex = "10001";
    var title = document.createElement("h4");
    title.setAttribute("id", "msgTitle");
    title.setAttribute("align", "right");
    title.style.margin = "0";
    title.style.padding = "3px";
    title.style.background = bordercolor;
    title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
    title.style.opacity = "0.75";
    title.style.border = "1px solid " + bordercolor;
    title.style.height = "18px";
    title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color = "white";
    title.style.cursor = "pointer";
    title.title = "点击关闭";
    title.innerHTML = "<table border='0' width='100%'><tr><td align='left'>" + strTitle + "</td><td>关闭</td></tr></table></div>";
    title.onclick = function () {
        document.body.removeChild(bgObj);
        document.getElementById("msgDiv").removeChild(title);
        document.body.removeChild(msgObj);
    }
    document.body.appendChild(msgObj);
    document.getElementById("msgDiv").appendChild(title);
    var txt = document.createElement("p");
    txt.style.margin = "1em 0"
    txt.setAttribute("id", "msgTxt");
    txt.innerHTML = strContent;
    document.getElementById("msgDiv").appendChild(txt);
}

function sAlertCustom(strTitle, strContent) {
    var msgw, msgh, bordercolor;
    msgw = 1000; //提示窗口的宽度 																											
    msgh = 250; //提示窗口的高度 																										
    titleheight = 25 //提示窗口标题高度 																											
    bordercolor = "#336699"; //提示窗口的边框颜色 																											
    titlecolor = "#99CCFF"; //提示窗口的标题颜色 																											
    var sWidth, sHeight;
    sWidth = document.body.offsetWidth;
    sHeight = screen.height;
    var bgObj = document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position = "absolute";
    bgObj.style.top = "0";
    bgObj.style.background = "#777";
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity = "0.6";
    bgObj.style.left = "0";
    bgObj.style.width = sWidth + "px";
    bgObj.style.height = sHeight + "px";
    bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);
    var msgObj = document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.style.background = "white";
    msgObj.style.border = "1px solid " + bordercolor;
    msgObj.style.position = "absolute";
    msgObj.style.left = "407";
    msgObj.style.top = "135";
    msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial,Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px";
    msgObj.style.marginTop = -75 + document.documentElement.scrollTop + "px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height = msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight = "25px";
    msgObj.style.zIndex = "10001";
    var title = document.createElement("h4");
    title.setAttribute("id", "msgTitle");
    title.setAttribute("align", "right");
    title.style.margin = "0";
    title.style.padding = "3px";
    title.style.background = bordercolor;
    title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
    title.style.opacity = "0.75";
    title.style.border = "1px solid " + bordercolor;
    title.style.height = "18px";
    title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color = "white";
    title.style.cursor = "pointer";
    title.title = "点击关闭";
    title.innerHTML = "<table border='0' width='100%'><tr><td align='left'>" + strTitle + "</td><td>关闭</td></tr></table></div>";
    title.onclick = function () {
        document.body.removeChild(bgObj);
        document.getElementById("msgDiv").removeChild(title);
        document.body.removeChild(msgObj);
    }
    document.body.appendChild(msgObj);
    document.getElementById("msgDiv").appendChild(title);
    var txt = document.createElement("p");
    txt.style.margin = "1em 0"
    txt.setAttribute("id", "msgTxt");
    txt.innerHTML = strContent;
    document.getElementById("msgDiv").appendChild(txt);
}

function OpenInput(obj, target) {
    document.getElementById("InputZone").src = target;
    ExpandGridView();
}

function AdjustInput(target) {
    document.getElementById("InputZone").src = target;
}

function resize_iframe() {
    document.getElementById("MainZone").height = document.body.offsetHeight - document.getElementById("MainZone").offsetTop;
}

function resize_iframe_Statistics() {
    document.getElementById("Statistics").height = document.body.offsetHeight - document.getElementById("Statistics").offsetTop - 60;
}

function FindChecked(name, value1) {

    for (i = 0; i < 20; i++) {
        if (document.getElementById(name + '_' + i.toString()) != null) {
            var check = CheckItemExist(document.getElementById(name + '_' + i.toString()).value.toString(), value1);
            if (check == "1") {
                document.getElementById(name + '_' + i.toString()).checked = true;
            }
        }
    }
}

function CheckItemExist(name, value2) {
    var values = value2.split(",");
    var result = "0";

    for (j = 0; j < values.length; j++) {

        if (values[j].toString() == name) {
            result = "1";
            break;
        }
        else {
            result = "0";
        }
    }

    return result;
}

function NewDetailLine(name, pre, firstline) {
    document.getElementById('GridInputDataLine_' + name).innerHTML += document.getElementById('GridInputData_' + name).innerHTML;

    var line1 = firstline.split("|");

    for (i = 0; i < line1.length; i++) {
        document.getElementById(pre + line1[i]).value = "";
    }
}

function SelectedItem(name, value) {
    document.getElementById(name).value = value;
}

var lastnode = "";
function SetNode(node) {
    document.getElementById(node).style.color = '#ff0000';
    if (lastnode != "" && lastnode != node) {
        document.getElementById(lastnode).style.color = '#0000ff';
    }
    lastnode = node;
}

function SelectNextPerson(index, value, text) {
    
    var resultText = "";
    var returnValue = "";

    if (document.getElementById(event.srcElement.id).checked == true) {
        resultText = resultText + (text + ",");
        returnValue = returnValue + (value + "|");
    }
    else {
        resultText = resultText.replace(text + ",", "");
        returnValue = returnValue.replace(value + "|", "");
    }

    document.getElementById(event.srcElement.id.replace('_lstInput_' + index, '_txtName')).value = resultText;
    document.getElementById(event.srcElement.id.replace('_lstInput_' + index, '_txtInput')).value = returnValue;
}
function BindInputObject() {
    document.getElementById(event.srcElement.id.replace('_lstInput', '_txtName')).value = event.srcElement.options[event.srcElement.selectedIndex].innerText;
    document.getElementById(event.srcElement.id.replace('_lstInput', '_txtInput')).value = event.srcElement.options[event.srcElement.selectedIndex].value;
}

function ActiveTabChanged(sender, e) {
    for (i = 0; i < 4; i++) {
        if (i == sender.get_activeTab().get_tabIndex()) {
            document.getElementById("tabpaneltitle" + i).style.backgroundColor = "#d8dfeb";
        }
        else {
            document.getElementById("tabpaneltitle" + i).style.backgroundColor = "#ffffff";
        }
    }
}



function AutoDivHeight(left, right) {
    if (left != null && right != null) {
        if (left.clientHeight < right.clientHeight) {
            left.style.minHeight = right.clientHeight + "px";
            if (window.ActiveXObject) {
                var browser = navigator.appName
                var b_version = navigator.appVersion
                var version = b_version.split(";");
                var trim_Version = version[1].replace(/[ ]/g, "");
                if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE6.0") {
                    left.style.height = right.clientHeight + "px";
                }
            }
            else {
                left.style.minHeight = right.clientHeight + "px";
            }
        }
        else {
            right.style.height = left.clientHeight + "px";
        }
    }
}

function openCont(URL) {
    window.open(URL, '', 'menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=yes,width=640,height=410,top=100,left=40');
}

function getQuery(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

function showShopCity(selecteditem) {
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.Open("GET", "/Common/ajaxinfo.aspx?type=area&r=" + Math.random(), false);
    xmlhttp.Send();
    var strRtn = xmlhttp.responseText;
    var strAry = strRtn.split(";");
    document.write("<select class='kuang' id='DropCity' name='select' onchange='getsftype();'>");
    document.write("<option value='' selected>所在城市</option>");
    for (i = 0; i < strAry.length - 1; i++) {
        if (strAry[i] != selecteditem)
            document.write("<OPTION value='" + strAry[i] + "'>" + strAry[i] + "</OPTION>");
        else
            document.write("<OPTION value='" + strAry[i] + "' selected='selected'>" + strAry[i] + "</OPTION>");
    }

    document.write("</select>");
}

function getsftype(selectedItem) {
    var city = document.getElementById("DropCity");

    var select = document.getElementById("DropType");
    while (select.options.length) {
        select.options.remove(0);
    }
    var oOption = document.createElement("option");
    document.all.DropType.add(oOption);
    oOption.text = "商户类别";
    oOption.value = "";

    if (city.value == '')
        return;

    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.Open("GET", "/Common/ajaxinfo.aspx?type=shoptype&city=" + encodeURI(document.getElementById("DropCity").value) + "&r=" + Math.random(), false);
    xmlhttp.Send();
    var strRtn = xmlhttp.responseText;
    var strAry = strRtn.split(";");

    for (i = 0; i < strAry.length - 1; i++) {
        var oOption = document.createElement("option");
        document.getElementById('DropType').add(oOption);
        oOption.text = strAry[i];
        oOption.value = strAry[i];
        if (selectedItem == oOption.value)
            oOption.setAttribute("selected", "selected");
    }
}


function getShopInfo() {
    var city = document.getElementById("DropCity").value;
    var type = document.getElementById("DropType").value;
    var url = "/Personal/Sunflower/SunflowerShopDetail.aspx?city=" + escape(city) + "&type=" + escape(type);
    open(url);
}

function getSunfInfo() {
    var city = document.getElementById("DropCity").value;
    var type = document.getElementById("DropType").value;
    var url = "/Personal/Sunflower/SunflowerShopDetail.aspx?city=" + escape(city) + "&type=" + escape(type);
    location.href = url;
}
