﻿function getPosition() {
    var top = document.documentElement.scrollTop;
    var left = document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;
    return { top: top, left: left, height: height, width: width };
}

function showPop(url) {
    var width = 600; //弹出框的宽度 
    var height = 450; //弹出框的高度 
    var obj = document.getElementById("pop");
    $('formEdit').src = url;
    obj.style.display = "block";
    obj.style.position = "absolute";
    obj.style.zindex = "999";
    obj.style.width = width + "px";
    obj.style.height = height + "px";

    var Position = getPosition();
    leftadd = (Position.width - width) / 2;
    topadd = (Position.height - height) / 2;
    obj.style.top = (Position.top + topadd) + "px";
    obj.style.left = (Position.left + leftadd) + "px";

    window.onscroll = function() {
        var Position = getPosition();
        obj.style.top = (Position.top + topadd) + "px";
        obj.style.left = (Position.left + leftadd) + "px";
    };
}

function hidePop() {
    document.getElementById("pop").style.display = "none";
} 

function openNotice(url) {
    DvWnd.open('提示', url, 600, 400, 1); 
    return false;
}
function submitPassword(objName)
{var obj=$(objName);if(obj.value!=null)
{if(window.location.href.indexOf("Password=")>0)
{window.location.href=window.location.href.substring(0,window.location.href.indexOf("Password="))+"Password="+obj.value;}
else
{if(window.location.href.indexOf("?")>0){window.location.href=window.location.href+"&Password="+obj.value;}
else{window.location.href=window.location.href+"?Password="+obj.value;}}}}
function showHideMore(obj)
{var more=document.getElementsByClassName("more",obj.parentNode);more.each(function changeDisplay(tr){tr.toggle();});}
var colorID;function ShowColorPicker(butID)
{DvWnd.open('选择颜色','/ColorPicker/ColorPickup.htm?id='+butID,300,310);}
function keyPress(event)
{if(event.keyCode==13)
{submitSearch();return false;}
return true;}
function submitSearch()
{window.location.href="/FormSearch.aspx?key="+escape($('key').value);}
function copyText(obj)
{if(obj.type!="hidden")
{obj.focus();}
obj.select();copyToClipboard(obj);alert("已经拷贝了！");}
function copyToClipboard(inElement){if(window.clipboardData){window.clipboardData.setData("Text",inElement.value);}else{var flashcopier='flashcopier';if(!$(flashcopier)){var divholder=document.createElement('div');divholder.id=flashcopier;document.body.appendChild(divholder);}
$(flashcopier).innerHTML='';var divinfo='<embed src="/Flash/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';$(flashcopier).innerHTML=divinfo;}}
function showHideChart(id)
{var chart=$(id);var search=$("searchBox");var flashes=$("resultFlashes");var divs=flashes.immediateDescendants();for(var i=0;i<divs.length;i++)
{divs[i].style.display='none';}
search.style.display='none';if(chart)
{chart.toggle();}
return false;}
function showHideSearch(id,hiddenID)
{var flashes=$("resultFlashes");var hidden=$(hiddenID);var divs=flashes.immediateDescendants();for(var i=0;i<divs.length;i++)
{divs[i].style.display='none';}
var search=$("searchBox");search.style.display='block';hidden.value=id;}
function changeFlashCode(obj)
{var link=$('formLink');if(link){link=String(link.value.match(/\d+-\d+/ig));var ids=link.split("-");if(ids.length!=2)
{alert("你输入的地址有错误，请重新输入！");return false;}}
var blog=$('bsp').options[$('bsp').selectedIndex].value;var theme=$('flashTheme').options[$('flashTheme').selectedIndex].value;var height=$('flashHeight').value;var width=$('flashWidth').value;var flashCode=HTMLDeCode($('flashPreviewCode').value);if(link){flashCode=flashCode.replace(/userid=[^&]+/ig,'userid='+ids[0]);flashCode=flashCode.replace(/formid=[^\"]+/ig,'formid='+ids[1]);
$('ctl00_MainContent_txtFlashUrl').value = $('ctl00_MainContent_txtFlashUrl').value.replace(/userid=[^&]+/ig,'userid='+ids[0]);
$('ctl00_MainContent_txtFlashUrl').value = $('ctl00_MainContent_txtFlashUrl').value.replace(/formid=[^\"]+/ig,'formid='+ids[1]);
$('ctl00_MainContent_txtFlashUBB').value = $('ctl00_MainContent_txtFlashUBB').value.replace(/userid=[^&]+/ig,'userid='+ids[0]);
$('ctl00_MainContent_txtFlashUBB').value = $('ctl00_MainContent_txtFlashUBB').value.replace(/formid=[^\"]+/ig,'formid='+ids[1]);}
flashCode=flashCode.replace(/theme=[^&]+/ig,'theme='+theme);flashCode=flashCode.replace(/width=\"\d{3}\"/ig,'width=\"'+width+'\"');flashCode=flashCode.replace(/height=\"\d{3}\"/ig,'height=\"'+height+'\"');$('flashPreview').innerHTML=flashCode;switch(blog)
{case"1":obj.value=flashCode.match(/<embed[\s\S]+<\/embed>/ig);break;case"2":obj.value=flashCode;break;case"3":obj.value=flashCode.match(/src=\"\S+\"/ig);obj.value=obj.value.substring(5,obj.value.length-1);break;}$('ctl00_MainContent_txtFlashUrl').value = $('ctl00_MainContent_txtFlashUrl').value.replace(/theme=[^&]+/ig,'theme='+theme);
$('ctl00_MainContent_txtFlashUBB').value = $('ctl00_MainContent_txtFlashUBB').value.replace(/theme=[^&]+/ig,'theme='+theme); $('ctl00_MainContent_txtFlashUBB').value = $('ctl00_MainContent_txtFlashUBB').value.replace(/flash=\d+,\d+/ig,'flash='+width+','+height);}
function HTMLDeCode(str)
{var s="";if(str.length==0)return"";s=str.replace(/&gt;/g,"&");s=s.replace(/&lt;/g,"<");s=s.replace(/&gt;/g,">");s=s.replace(/&nbsp;/g,"    ");s=s.replace(/&#39;/g,"\'");s=s.replace(/&quot;/g,"\"");s=s.replace(/<br>/g,"\n");return s;}
function initTab(target){var first=$(target);var len=first.getElementsByTagName("li").length;for(var i=0;i<len;i++){first.getElementsByTagName("li")[i].onclick=showTab;}}
function showTab(ev){var ev=ev||window.event
var temp=ev.target||ev.srcElement;var p=temp.parentNode.getElementsByTagName("li");var len=p.length;for(var node=temp.parentNode.parentNode.nextSibling;node!=null;node=node.nextSibling){if(node.tagName=="DIV"){var q=node;break;}}
for(var i=0;i<len;i++){var j=(q.childNodes[0].className)?i:(i*2+1);if(temp!=p[i]){p[i].className="normaltab";if(q.childNodes[j]){q.childNodes[j].className="undis";}}else{p[i].className="hovertab";if(q.childNodes[j]){q.childNodes[j].className="dis";}}}}
function intLi(obj){var list=$(obj).getElementsByTagName("div");for(var i=0;i<list.length;i++){list[i].onmouseover=function(){this.className=this.className.split(" ")[0]+" hli";}
list[i].onmouseout=function(){this.className=this.className.split(" ")[0]+" nli";}}}
var OS;var browser;function getPlatform(){if(checkIt('konqueror')){browser="Konqueror";OS="Linux";}
else if(checkIt('safari'))browser="Safari"
else if(checkIt('omniweb'))browser="OmniWeb"
else if(checkIt('opera'))browser="Opera"
else if(checkIt('webtv'))browser="WebTV";else if(checkIt('icab'))browser="iCab"
else if(checkIt('msie 7'))browser="Internet Explorer 7"
else if(checkIt('msie'))browser="Internet Explorer"
else if(!checkIt('compatible'))browser="Netscape Navigator"
else browser="Unknown Browser";if(!OS){if(checkIt('linux'))OS="Linux";else if(checkIt('x11'))OS="Unix";else if(checkIt('mac'))OS="Mac"
else if(checkIt('win'))OS="Windows"
else OS="Unknown Operating System";}}
function checkIt(string){var detect=navigator.userAgent.toLowerCase();return detect.indexOf(string)+1;}
Event.observe(window,'load',init,false);function init()
{getPlatform();initLightBox();}
function initLightBox()
{var title=$('lightBoxTitle');var content=$('lightBoxContent');if(title&&content&&!title.empty()&&!content.empty()&&typeof(DvWnd)!="undefined")
{DvWnd.open(title.innerHTML,content.innerHTML,300,200,2);Element.remove('lightBoxContent');}}
function getIFrameDocument(aID){var rv=null;if(document.getElementById(aID).contentWindow){rv=document.getElementById(aID).contentWindow.document;}else{rv=document.frames[aID].document;}
return rv;}
function showit(n){clearclosewin();$("submenu").style.display="block"}
function clearclosewin(){if(typeof dodo!="undefined")clearTimeout(dodo);}
function hiddenit(){closewinwait();}
function closewinwait(){dodo=setTimeout("closewin()",0764);}
function closewin() { $("submenu").style.display = 'none'; }
function initPager() {
    var last = 0;
    currentPage = 0;
    if (pager == 0) {
        $('previouspage').style.display = "none";
        $('nextpage').style.display = "none";
    }
    else {
        var lis = $(formContentID).getElementsByClassName('formField');
        var sections = $(formContentID).getElementsByClassName('sectionField');
        if (currentPage + 1 < lis.length / pager) {
            $(submitID).style.visibility = "hidden";
            $('nextpage').style.visibility = "visible";
        } else {
            $(submitID).style.visibility = "visible";
            $('nextpage').style.visibility = "hidden";
        }
        $("previouspage").style.visibility = "hidden";
        for (var i = 0; i < sections.length; i++) {
            sections[i].style.display = "none";

        }
        last = lis.length < pager * (currentPage + 1) ? lis.length : pager * (currentPage + 1);
        for (var i = pager * currentPage; i < last; i++) {
            lis[i].style.display = "";
            for (var j = 0; j < sections.length; j++) {
                if (Number(sections[j].id.substring(7)) == i + 1) {
                    sections[j].style.display = "";
                }
                if (Number(sections[j].id.substring(7)) == 0 && i == 0) {
                    sections[j].style.display = "";
                }
            }
        }
        for (var i = last; i < lis.length; i++) {
            lis[i].style.display = "none";
            enableVal(lis[i], false);
        }
    }
}

function changePager() {
    pagesize = 0;
    var last = 0;
    var lis = $(formContentID).getElementsByClassName('formField');
    var sections = $(formContentID).getElementsByClassName('sectionField');
    for (var i = 0; i < sections.length; i++) {
        sections[i].style.display = "none";  
    }
    if (currentPage > 0) {
        for (var i = 0; i < currentPage * pager; i++) {
            lis[i].style.display = "none";
            enableVal(lis[i], false);
        }
    } else {
        $("previouspage").style.visibility = "hidden";
    }
    last = lis.length < pager * (currentPage + 1) ? lis.length : pager * (currentPage + 1);
    for (var i = pager * currentPage; i < last; i++) {
        if (!lis[i].attributes["isRedirect"] || lis[i].attributes["isRedirect"].nodeValue == "false") {
            lis[i].style.display = "";
            enableVal(lis[i], true);
            for (var j = 0; j < sections.length; j++) {
                if (Number(sections[j].id.substring(7))==i+1) {
                    sections[j].style.display = "";
                }
                if (Number(sections[j].id.substring(7)) == 0 && i == 0) {
                    sections[j].style.display = "";
                }
            }
            pagesize++;
        } else {
            lis[i].style.display = "none";
            enableVal(lis[i], false);
        }
    }
    if (currentPage == 0 && sections.length>0 && Number(sections[j-1].id.substring(7)) == 0) {
        sections[0].style.display = "";
    }
    for (var i = last; i < lis.length; i++) {
        lis[i].style.display = "none";
        enableVal(lis[i], false);
    }
    
}

function toNextPage() {
    if (Page_ClientValidate("Vote")) {
        currentPage++;
        changePager();

        $("previouspage").style.visibility = "visible";
        if (currentPage + 1 < $(formContentID).getElementsByClassName('formField').length / pager) {
            $("nextpage").style.visibility = "visible";
            $(submitID).style.visibility = "hidden";
        } else {
        $("nextpage").style.visibility = "hidden";
        $(submitID).style.visibility = "visible";
        }
	if (pagesize == 0) {
        toNextPage();
    }
    }
    
}

function toPreviousPage() {
        currentPage--;
        changePager();
        $("nextpage").style.visibility = "visible";
        if (currentPage == 0) {
            $("previouspage").style.visibility = "hidden";
        } else {
        $("previouspage").style.visibility = "visible";
    }
    $(submitID).style.visibility = "hidden";
    if (pagesize == 0) {
        toPreviousPage();
    }
}
function redirectDisplay(current, start, end) {
    if (start > 0) {
        if ($(formContentID) != null) {
                var lis = $(formContentID).getElementsByClassName('formField');
                for (var i = current; i < start; i++) {
                    lis[i].style.display = 'none';
                    lis[i].setAttribute("isRedirect", "true");
                    clearValue(lis[i]);
                    enableVal(lis[i], false);
                }
                if (end == 0) {
                    end = lis.length;
                }
                for (var i = start-1; i < end; i++) {
                        lis[i].setAttribute("isRedirect", "false"); 
                        if (pager == 0 || (i >= currentPage * pager && i < (currentPage + 1) * pager)) {
                            lis[i].style.display = '';
                            enableVal(lis[i], true);
                            
                        }
                        else {
                            lis[i].style.display = 'none';
                            enableVal(lis[i], false);
                        }
                        
                }
                for (var i = end; i < lis.length; i++) {
                    if (lis[i].style.display != 'none') {
                        lis[i].style.display = 'none';
                        lis[i].setAttribute("isRedirect", "true");
                        clearValue(lis[i]);
                        enableVal(lis[i], false);
                    }
                }
            }
    }

}
function enableVal(obj, enabled) {
    var vals = obj.lastChild.getElementsByTagName("span");
    for (var i = 0; i < vals.length; i++) {
        vals[i].enabled = enabled;
    }
}
function clearValue(obj) {
    var inputs = obj.getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
        switch (inputs[i].type) {
            case "text":
                inputs[i].value = "";
                break;
            case "radio":
            case "checkbox":
                inputs[i].checked = false;
                break;
        }
    }
    var textareas = obj.getElementsByTagName("textarea");
    for (var i = 0; i < textareas.length; i++) {
        textareas.value = "";
    }
}

