﻿//基本公用方法   开始
var $ = function(id) {
    return "string" == typeof (id) ? document.getElementById(id) : id;
};

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function getCookie(objName)
{
    var defaultValue="ZH-CN";
    var arrStr = document.cookie.split(";");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (objName.trim() == temp[0].trim()) {
            defaultValue = temp[1];
        }
    }
    return defaultValue;
}
//基本公用方法   结束

//全局变量      开始
var confirmExeControlID;
//全局变量      结束

//兼容处理代码区域  开始
function getCurrentStyle(obj) {
    browser = (window.navigator.userAgent).toLowerCase();
    if (/msie|opera/.test(browser)) {
        s = obj.currentStyle
    }
    else if (/gecko/.test(browser)) {
        s = document.defaultView.getComputedStyle(obj, null);
    }
    return s;
}
function getBrowserHeadSize(obj) {
    browser = (window.navigator.userAgent).toLowerCase();
    if (/msie|opera/.test(browser)) {
        height = window.screenTop;
        width = window.screenLeft;
    }
    else if (/gecko/.test(browser)) {
        height = window.outerHeight - window.innerHeight;
        width = window.outerWidth - window.innerWidth
    }
    if (obj == "height") { returnValue = height; }
    if (obj == "width") { returnValue = width; }
    return returnValue;
}
function getEventObj(obj) {
    var eObj;
    browser = (window.navigator.userAgent).toLowerCase();
    if (/msie|opera/.test(browser)) {
        eObj = event.button;
    }
    //    else if(/gecko/.test(browser)){ 
    //        eObj = obj.event.button;
    //    } 
    return eObj;
}
//兼容处理代码区域  结束

window.onload = function() {  
    QueMar(); 
    var oTbContent = $("tableContent");
    if (oTbContent != null) {

        var curObjectHeight = getCurrentStyle(oTbContent).height;
        curObjectHeight = curObjectHeight.substring(0, curObjectHeight.lastIndexOf('p'));

        var curObjectWidth = getCurrentStyle(oTbContent).width;
        curObjectWidth = curObjectWidth.substring(0, curObjectWidth.lastIndexOf('p'));

        oTbContent.style.top = (window.screen.height - curObjectHeight) / 2 - getBrowserHeadSize("height") + "px"; //FF要加PX
        oTbContent.style.left = (window.screen.width - curObjectWidth) / 2 - getBrowserHeadSize("width") + "px";
    }

    if (PanelConfirmtion != null) {
        PanelConfirmtion.style.height = document.documentElement.clientHeight + "px";
        //PanelConfirmtion.style.height = document.body.clientHeight + 15 + "px";
        PanelConfirmtion.style.width = document.documentElement.clientWidth + "px";
    }
}

window.onscroll = function() {
    if (PanelConfirmtion != null) {

        PanelConfirmtion.style.top = document.documentElement.scrollTop + "px";
        PanelConfirmtion.style.left = document.documentElement.scrollLeft + "px";
    }
}

function DisplayChangeOfPic(oImg) 
{
    oImg.className = oImg.className == "Div_Unfold_Ico" ? "Div_Fold_Ico" : "Div_Unfold_Ico";
    oImg.title = oImg.title == "展开" ? "折叠" : "展开";
    var oEle = oImg.parentNode;
    while (oEle.nodeName != "TR") {
        oEle = oEle.parentNode;
    }
    if (oEle.getAttribute("flag") == "folder" && oEle.nextSibling != null) {
        var MenuItem = oEle.nextSibling;
        while (MenuItem.nodeType != 1) {
            //加这段代码：主要是FF种会识别回车行换(本处属于别的原因，可能是padding-问题)当作一个#TEXT节点 而IE不会!!
            MenuItem = MenuItem.nextSibling;
            if (!MenuItem) return null;
        };
        while (MenuItem.getAttribute("flag") != "folder" && MenuItem.nodeName == "TR") {
            MenuItem.style.display = MenuItem.style.display == "none" ? "" : "none";
            if (MenuItem.nextSibling != null) {
                MenuItem = MenuItem.nextSibling;
                while (MenuItem.nodeType != 1) {
                    MenuItem = MenuItem.nextSibling;
                    if (!MenuItem) return null;
                };
            }
            else { break; }
        }
    }
}


function txtSearch_onfocus(oText) {
    var sysText = "搜索店铺和促销";
    if (oText.value.trim() == sysText) {
        oText.value = "";
        oText.style.color = "black";
        oText.style.backgroundColor = "#FFFFCC";
    }
}
function txtSearch_onblur(oText) {
    if (oText.value.trim() == "") {
        oText.value = "搜索店铺和促销";
        oText.style.color = "gray";
        oText.style.backgroundColor = "white";
    }
}
function ShowImgProcess() {
    imgProcess.style.display = "";
    //document.getElementById("imgProcess").style.display = "";
}

function CheckKeywordValue() {
    var txtValue = txtSearch.value.trim();
    if (txtValue == "" || txtValue == "搜索店铺和促销") {
        $("tdMsg").innerHTML = "&nbsp;请输入关键字！";
        PanelConfirmtion.style.display = "";
        $("btnConfirmSure").style.display = "none";
        btnSure.innerText = "确 定";
        return false;
    }
}

function HideWindowsPopup() {
    PanelConfirmtion.style.display = "none";
    return false;
}

//function UrlEncode(sStr) {
//    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F');
//}

//function DoSearch() {
//    url = "/Search.aspx?Keyword=" + UrlEncode(txtSearch.value);
//    window.open(url); window.open(url,"_self"); window.location = url; window.location.href = url;
//    return false;
//}

var moveable = false;
//开始拖动;
function startDrag(obj) {
    if (getEventObj(obj) == 1)  //IE
    {
        //锁定标题栏;
        obj.setCapture();
        //定义对象;
        var win = obj.parentNode;
        while (win.nodeName != "TABLE") {
            win = win.parentNode;
        }
        //记录鼠标和层位置;
        x0 = event.clientX;
        y0 = event.clientY;
        x1 = parseInt(win.style.left);
        y1 = parseInt(win.style.top);

        moveable = true;
    }
    else  //FF
    {
        event = arguments[0];
        //锁定标题栏;
        obj.CaptureEvent();
        //定义对象;
        var win = obj.parentNode;
        while (win.nodeName != "TABLE") {
            win = win.parentNode;
        }
        //记录鼠标和层位置;
        x0 = event.clientX;
        y0 = event.clientY;
        x1 = parseInt(win.style.left);
        y1 = parseInt(win.style.top);

        moveable = true;
    }
}
//拖动;
function drag(obj) {
    if (moveable) {
        var win = obj.parentNode;
        while (win.nodeName != "TABLE") {
            win = win.parentNode;
        }
        var sha = win.nextSibling;
        win.style.left = x1 + event.clientX - x0;
        if ((y1 + event.clientY - y0) > 0 && (y1 + event.clientY - y0) < 600) {
            win.style.top = y1 + event.clientY - y0;
        }
    }
}
//停止拖动;
function stopDrag(obj) {
    if (moveable) {
        var win = obj.parentNode;
        while (win.nodeName != "TABLE") {
            win = win.parentNode;
        }
        obj.releaseCapture();
        moveable = false;
    }
}

function CustomConfirm(confirmObj,txt) {
    confirmExeControlID = confirmObj.id;
    PanelConfirmtion.style.display = "";
    $("btnConfirmSure").style.display = "";
    btnSure.innerText = "取 消";
    if (txt == "" || txt == null || txt == undefined) { $("tdMsg").innerHTML = "&nbsp;您真的确认要这样操作吗？"; }
    else { $("tdMsg").innerHTML = txt; }
    return false;
}

function BtnConfirmSure() {
    $(confirmExeControlID).onclick = "return true;";
    $(confirmExeControlID).click();
    //__doPostBack(confirmExeControlID, "") is ok too.
}

//***************************************************************

var tc;
function QueMar()
{
var o=document.getElementById("info");hscroll(o);
window.setInterval(function(){window.clearTimeout(tc);o.firstChild.style.marginLeft="0px";scrollup(o,170,0);},6000);//修改100控制div高度,修改9000控制间隙时间
}
function scrollup(o,d,c){
if(d==c){
var t=o.firstChild.cloneNode(true);
o.removeChild(o.firstChild);o.appendChild(t);
t.style.marginTop=o.firstChild.style.marginTop="0px";
hscroll(o);
}
else{
ch=false;var s=3,c=c+s,l=(c>=d?c-d:0);
o.firstChild.style.marginTop=-c+l+"px";
window.setTimeout(function(){scrollup(o,d,c-l)},50);
}
}

function hscroll(o){
var w1=o.firstChild.offsetWidth,w2=o.offsetWidth;
if(w1<=w2)return;
tc=window.setTimeout(function(){hsObj(o,w1-w2,0,w1-w2)},3500);
}

function hsObj(o,d,c,p){
c++;var t=(c>0?-c:c);o.firstChild.style.marginLeft=t+"px";
if(c==d){if(d==0){tc=window.setTimeout(function(){hsObj(o,p,0,p)},2500);}else tc=window.setTimeout(function(){hsObj(o,0,-p,p)},3500);}
else tc=window.setTimeout(function(){hsObj(o,d,c,p)},5);
}

function DisplayControl(trObj,familyID)
{
    var TrObj = $("TrObj"+familyID);
    TrObj.style.display = TrObj.style.display == "none" ? "" : "none";
    
    var SpanObj = $("SpanObj"+familyID);
    SpanObj.innerText=SpanObj.innerText == "-" ? "+" : "-";
    SpanObj.className = SpanObj.className == "FoldSpan" ? "UnFoldSpan" : "FoldSpan";
    if (getCookie("Language") == "ZH-CN")
    {
        if(SpanObj.innerText == "+")
        {
            SpanObj.title = "单击将展开";
        }
        else
        {
            SpanObj.title = "单击将折叠";
        }
    }
    else
    {
        if(SpanObj.innerText == "+")
        {
            SpanObj.title = "Click to Unfold";
        }
        else
        {
            SpanObj.title = "Click to Fold";
        }
    }
}