﻿// JScript 文件
function writeCookie(name, value, seconds) {
    var expire = "";
    if (seconds != null) {
        expire = new Date((new Date()).getTime() + seconds * 1000);
        expire = "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expire;
}
function readCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    return (arr != null) ? unescape(arr[2]) : null;
}
function contactUs() {
    if (!confirm('Please sign in and send Message to us, our ID:1000001[OK]\nIs there any trouble with sending us messages?[Cancel]')) {
        var e = 's' + 'u' + 'p' + 'por' + 't' + '@' + 'bus' + 'i' + 'ness-' + 'any' + '.c' + 'o' + 'm';
        alert('please send mail to ' + e);
        location.href = 'mailto:' + e;
    }
    else {
        location.href = '/Management/?enter=MessageList.aspx?FROMTOID=1000001';
    }
}

function setTip(obj, is) {
    if (is == 1) {
        if (obj.value == obj.title) {
            obj.value = '';
            obj.style.color = '#000000';
        }
    }
    else if (obj.value == '' || obj.value == obj.title) {
        obj.value = obj.title;
        obj.style.color = '#cccccc';
    }
}

var timers = new Array(10);
var timespan = 1000;
function IsImage(obj) {
    return (obj.className == "listNone" || obj.className == "listImage" || obj.className == "listNoImage");
}

function ShowFocus1(obj, flag) {
    var hasImg = false;
    var recover = false;
    var els = obj.parentNode.childNodes;
    for (var i = 0; i < els.length; i++) {
        if (els[i].id == obj.id) {
            if (IsImage(els[i])) {
                els[i].className = 'listImage';
                hasImg = true;
            }
            else {
                els[i].className = 'listTitleB';
            }
        }
        else {
            if (IsImage(els[i])) {
                if (els[i].className != 'listNone') {
                    recover = els[i];
                }
                els[i].className = 'listNone';
            }
            else {
                els[i].className = '';
            }
        }
    }
    if (!hasImg && recover) {
        recover.className = 'listNoImage';
    }
    return hasImg;
}
function ShowFocus(obj, flag) {
    var id = obj.parentNode.id.replace('Ul', '');
    if (flag) {
        clearInterval(timers[id]);
        ShowFocus1(obj, flag);
    }
    else {
        if (!IsImage(obj)) {
            obj.className = '';
        }
        timers[id] = setInterval('ShowPic("Ul' + id + '");', timespan);
    }
}

function ShowPic(id) {
    try {
        var els = document.getElementById(id).childNodes;
        var i = 0;
        var flag = false;
        var firstobj = false;
        var finished = false;
        for (; i < els.length; i++) {
            if (IsImage(els[i])) {
                if (!firstobj) {
                    firstobj = els[i];
                }
                if (!finished) {
                    if (!flag) {
                        if (els[i].className != 'listNone') {
                            els[i].className = 'listNone';
                            flag = true;
                        }
                    }
                    else {
                        els[i].className = 'listImage';
                        ShowFocus1(els[i], 1);
                        finished = true;
                    }
                }
                else {
                    els[i].className = 'listNone';
                }
            }
            else {
                //els[i].className = '';
            }
        }
        if (!finished) {
            firstobj.className = 'listImage';
            ShowFocus1(firstobj, 1);
        }
    }
    catch (e) { clearInterval(timers[id.replace('Ul')]); }

}
function StartShowPic() {
    var i = 0;
    for (; i < 10; i++) {
        timers[i] = setInterval('try{ShowPic("Ul' + i + '");}catch(e){}', timespan);
    }
}

function toLocalTime(obj) {
    var serverzone = 8;
    var a = obj.innerHTML.replace(/[ :-]/ig, ',').split(',');
    var date = new Date(a[0], a[1] - 1, a[2], a[3], a[4], 0);
    var offset = ((serverzone * 60) + new Date().getTimezoneOffset()) * 60000;
        date.setTime(date.getTime() - offset);
    var current = new Date();   
    if (current.getTime() - date.getTime() < 24 * 60 * 60 * 1000 && current.getDate()==date.getDate()) {
        obj.innerHTML = '<span>' + date.toLocaleTimeString() + '</span>';
    }
    else {
        obj.innerHTML = date.toLocaleDateString();
    }
}
function SetLocalTime() {
    var tags = document.getElementsByTagName("dt");
    for (var i = 0; i < tags.length; i++) {
        toLocalTime(tags[i]);
    }
}

//menu     
var cf = false;
function mf(obj, flag) {
    obj.className = flag ? "" : "coverLi";
    cf.className = flag ? "coverLi" : "";
}
function smf() {
    var flag = false;
    for (var i = 1; i < 20; i++) {
        var cf = document.getElementById("menu" + i);
        if (cf && location.href.indexOf(cf.childNodes[0].href) == 0) {
            cf.className = "coverLi";
            flag = true;
            break;
        }
    }
    if (!flag) {
        var cf = document.getElementById("menu0");
        if (!cf) {
            setTimeout("smf();", 10);
        }
        else {
            cf.className = "coverLi";
        }
    }
}
function ld_switch(flag) {
    if (flag) {
        document.getElementById("DirectoryGuider").style.display = 'none';
        document.getElementById("LocationGuider").style.display = 'block';
    }
    else {
        document.getElementById("DirectoryGuider").style.display = 'block';
        document.getElementById("LocationGuider").style.display = 'none';
    }
}
function changeImage(obj) {
    obj.src = obj.src + "0";
}
function addFavriates() {
    try { window.external.addFavorite(document.location.href, document.title); } catch (e) { try { window.sidebar.addPanel(document.title, document.location.href, ''); } catch (e) { alert('auto add failed, please add by manual.'); } }
}

function GetPostion() {
    var W, H, SL, ST;
    var clientWidth, clientHeight;
    var w = window, d = document, dd = d.documentElement;

    if (w.innerWidth) W = w.innerWidth;
    else if (dd && dd.clientWidth) W = dd.clientWidth;
    else if (d.body) W = d.body.clientWidth;

    if (w.innerHeight) H = w.innerHeight;
    else if (dd && dd.clientHeight) H = dd.clientHeight;
    else if (d.body) H = d.body.clientHeight;

    if (w.pageXOffset) SL = w.pageXOffset;
    else if (dd && dd.scrollLeft) SL = dd.scrollLeft;
    else if (d.body) SL = d.body.scrollLeft;

    if (w.pageYOffset) ST = w.pageYOffset;
    else if (dd && dd.scrollTop) ST = dd.scrollTop;
    else if (d.body) ST = d.body.scrollTop;

    var scrollLeft = (document.documentElement.scrollLeft ?
            document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ?
            document.documentElement.scrollTop : document.body.scrollTop);
    W = W + scrollLeft;
    H = H + scrollTop;
    return { clientWidth: W, clientHeight: H };
}
function reseMessengerPosition() {
    var p = GetPostion();
    var container = document.getElementById("Pub");
    var containerLeft = p.clientWidth - container.clientWidth - 20;
    var containerTop = p.clientHeight - container.clientHeight;
    container.style.top = containerTop + "px";
    container.style.right = "1px";
}

function ShowAndHide(obj1, obj2) {
    var div1 = document.getElementById(obj1);
    var div2 = document.getElementById(obj2);
    div1.style.display = div1.style.display == "none" ? "" : "none";
    div2.style.display = div2.style.display == "none" ? "" : "none";

    var container = document.getElementById("Pub");
    var p = GetPostion();
    var containerLeft = p.clientWidth - div2.clientWidth - 20;
    var containerTop = p.clientHeight - div2.clientHeight;
    container.style.top = containerTop + "px";
    //container.style.left=containerLeft+"px";
    container.style.right = "1px";
}
function Validate() {
    var objDiv = document.getElementById("divError");
    var objMessage = document.getElementById("Txt");
    if (objMessage.value.length < 1) {
        objDiv.style.display = "";
        objMessage.value = objDiv.innerHTML = "Please enter your information.";
        //return false;
    }
    /*else if(objMessage.value.length<500 || objMessage.value.length>2000)
    {
    objDiv.style.display="";
    objDiv.innerHTML = "Your information should be between 500-2000 characters, sign in for more.";
    return false;
    }*/
    return true;
}
function DoSubmit() {
    if (Validate()) {
        var f = document.getElementById("Info");
        f.target = "_blank";
        ShowAndHide('Pub3', 'Pub1');
        return true;
    }
    return false;
}
function TxtFocus() {
    var oTxt = document.getElementById("Txt");
    oTxt.value = "";
    oTxt.focus();
}
function QucikPublish() {
    document.writeln("<style type=\"text/css\">");
    document.writeln(".Box1 {");
    document.writeln("	CLEAR: right; BACKGROUND: #fff; FLOAT: right; WIDTH: 170px");
    document.writeln("}");
    document.writeln(".Box2 {");
    document.writeln("	CLEAR: right; BACKGROUND: #fff; FLOAT: right; WIDTH: 170px");
    document.writeln("}");
    document.writeln(".contContent {");
    document.writeln("	BORDER-RIGHT: #4173b0 1px solid; PADDING-RIGHT: 10px; BORDER-TOP: #4173b0 1px; PADDING-LEFT: 10px; PADDING-BOTTOM: 12px; BORDER-LEFT: #4173b0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #4173b0 1px solid");
    document.writeln("}");
    document.writeln(".Box3c {");
    document.writeln("	BORDER-RIGHT: #4173b0 1px solid; PADDING-RIGHT: 10px; PADDING-LEFT: 15px; PADDING-BOTTOM: 12px; BORDER-LEFT: #4173b0 1px solid; PADDING-TOP: 5px");
    document.writeln("}");
    document.writeln(".divmsg {");
    document.writeln("	LINE-HEIGHT: 28px; HEIGHT: 28px");
    document.writeln("}");
    document.writeln(".divmsg IMG {");
    document.writeln("	MARGIN-TOP: 5px; MARGIN-BOTTOM: -3px");
    document.writeln("}");
    document.writeln(".divmsg SPAN {");
    document.writeln("	MARGIN-TOP: -22px; FLOAT: right; MARGIN-RIGHT: 18px");
    document.writeln("}");
    document.writeln(".Box3 {");
    document.writeln("	CLEAR: right; BACKGROUND: #fff; FLOAT: right; WIDTH: 465px");
    document.writeln("}");
    document.writeln(".Btn {");
    document.writeln("	BORDER-RIGHT: #4173b0 1px solid; BORDER-TOP: #4173b0 1px; BACKGROUND: #cad9eb; BORDER-LEFT: #4173b0 1px solid; PADDING-TOP: 15px; BORDER-BOTTOM: #4173b0 1px solid; HEIGHT: 30px; TEXT-ALIGN: center");
    document.writeln("}");
    document.writeln(".Tit {");
    document.writeln("	BACKGROUND: url(http://www.business-any.com/Images/ico_5.gif) #cad9eb no-repeat right top; WIDTH: 100%; HEIGHT: 29px");
    document.writeln("}");
    document.writeln(".Tit H3 {");
    document.writeln("	PADDING-LEFT: 5px; BACKGROUND: url(http://www.business-any.com/Images/ico_4.gif) no-repeat left top; FLOAT: left; MARGIN: 0px; FONT: bold 12px/29px arial; WIDTH: 80%; COLOR: #000000; HEIGHT: 29px");
    document.writeln("}");
    document.writeln(".Tit IMG {");
    document.writeln("	MARGIN-TOP: 8px; FLOAT: right; MARGIN-RIGHT: 8px");
    document.writeln("}");
    document.writeln(".mar30-b {");
    document.writeln("	MARGIN-BOTTOM: 30px");
    document.writeln("}");
    document.writeln(".h110 {");
    document.writeln("	OVERFLOW: hidden; HEIGHT: 110px");
    document.writeln("}");
    document.writeln("</style>");
    document.writeln("    <form id=\"Info\" method=\"post\" action=\"http://www.business-any.com/Management/QuickPublish.aspx\" onsubmit=\"return DoSubmit();\"");
    document.writeln("        target=\"_blank\">");
    document.writeln("        <div id=\"Pub\" style=\"right: 1px; position: absolute\">");
    document.writeln("            <div class=\"Box1\" id=\"Pub1\">");
    document.writeln("                <div class=\"Tit\">");
    document.writeln("                    <h3>");
    document.writeln("                        Quick Publish & Inquiry</h3>");
    document.writeln("                    <img alt=\"\" onclick=\"ShowAndHide(\'Pub1\',\'Pub2\')\" src=\"http://www.business-any.com/Images/ico_1.gif\" /></div>");
    document.writeln("                <div class=\"contContent\">");
    document.writeln("                    <textarea style=\"font-size: 11px; width: 90%; color: #888\" onfocus=\"ShowAndHide(\'Pub1\',\'Pub3\');TxtFocus();\"");
    document.writeln("                        name=\"textfield2\" rows=\"4\" cols=\"12\">Click here to enter your information.</textarea>");
    document.writeln("                </div>");
    document.writeln("            </div>");
    document.writeln("            <div class=\"Box3\" id=\"Pub3\" style=\"display: none\">");
    document.writeln("                <div class=\"Tit\">");
    document.writeln("                    <h3>");
    document.writeln("                        Quick Publish & Inquiry</h3>");
    document.writeln("                    <img alt=\"\" onclick=\"ShowAndHide(\'Pub3\',\'Pub2\')\" src=\"http://www.business-any.com/Images/ico_1.gif\" /></div>");
    document.writeln("                <div class=\"Box3c\">");
    document.writeln("                    <div class=\"divmsg\">");
    document.writeln("                        Enter your information here</div>");
    document.writeln("                    <textarea id=\"Txt\" name=\"Txt\" style=\"width: 95%; color: #888\"  rows=\"8\"");
    document.writeln("                        cols=\"12\"></textarea>");
    document.writeln("                    <div class=\"error\" id=\"divError\" style=\"display: none\">");
    document.writeln("                        Your information should be between 500-2000 characters, sign in for more.</div>");
    document.writeln("                </div>");
    document.writeln("                <div class=\"Btn\">");
    document.writeln("                    <input type=\"submit\" value=\" Publish Now \" />");
    document.writeln("                </div>");
    document.writeln("            </div>");
    document.writeln("            <div class=\"Box2\" id=\"Pub2\" style=\"display: none\">");
    document.writeln("                <div class=\"Tit\">");
    document.writeln("                    <h3>");
    document.writeln("                        Quick Publish & Inquiry</h3>");
    document.writeln("                    <img alt=\"\" onclick=\"ShowAndHide(\'Pub2\',\'Pub1\')\" src=\"http://www.business-any.com/Images/ico_2.gif\" /></div>");
    document.writeln("            </div>");
    document.writeln("        </div>");
    document.writeln("    </form>");
    document.writeln("");
    setInterval('reseMessengerPosition()', 10);
}
function CheckMessage() {
    /*if (readCookie('lt') != null) {
        setTimeout('CheckMessage();', 10000);
        return;
    }
    writeCookie('lt', '0', 60);*/
    var img = new Image()
    img.src = "https://www.business-any.com/Management/CheckMessage.aspx?rid=" + new Date().getTime();
    img.onerror = function() {
        //setTimeout('CheckMessage();', 60000);
    };
    img.onload = function() {
    if (img.width == 16 &&
            (top == self || window.top.frames['mainFrame'].location.href.indexOf('/MessageList.aspx')==-1) &&
		    confirm('You have new message(s), Do you want to read it now?')) {
            if (top == self) {
                location.href = 'https://www.business-any.com/Management/?enter=/Management/MessageList.aspx?Type=1';
            }
            else {
                window.top.frames['mainFrame'].location.href = '/Management/MessageList.aspx?Type=1';
            }
        }
        else {
            //setTimeout('CheckMessage();', 60000);
        }
    };
}
function Init() {
    try { smf(); } catch (e) { }
    try { setTip(document.getElementById('Keywords'), 0); } catch (e) { }
    try { setTip(document.getElementById('Email'), 0); } catch (e) { }
    try { StartShowPic(); } catch (e) { }
    try { SetLocalTime(); } catch (e) { }
    try { QucikPublish(); } catch (e) { }
    CheckMessage();
}

