var marked_row = new Array;
function markRowsInit() {
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
            continue;
        }
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        rows[i].onmousedown = function(e) {
            var e = window.event || e;
            var srcElement = e.srcElement||e.target;
            if(srcElement.className == 'published' || srcElement.className == 'recommend' || srcElement.className=='auth' || srcElement.className=='hot'){
                return;
            }
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }
            if( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
                isChecked(checkbox.checked);
            }
        }

        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ){
            labeltag.onclick = function() {
                return true;
            }
            var checkbox = rows[i].getElementsByTagName('input')[0];
            if (checkbox) {
                checkbox.onclick = function() {
                    this.checked = ! this.checked;
                }
            }
        }
    }
}
function checkAll(n, fldName, checked, toggle) {
    var rows = document.getElementById('adminForm').getElementsByTagName('tr');
    var unique_id;
    if (!fldName) {
        fldName = 'cb';
    }
    if(!toggle){
        toggle = 'toggle';
    }
    var f = document.adminForm;
    if(typeof(checked)=='undefined'){
        if(typeof $("input[@name='"+toggle+"']").get(0)!='undefined'){
            var c = eval('f.'+toggle+'.checked');
        }
    }else{
        var c = checked;
        if(typeof $("input[@name='"+toggle+"']").get(0) != 'undefined'){
            $("input[@name='"+toggle+"']").attr('checked', checked);
        }
    }
    var n2 = 0;
    for (i=0; i < n; i++) {
        cb = eval( 'f.' + fldName + '' + i );
        if (cb) {
            if(cb.disabled==true){
                continue;
            }
            cb.checked = c;
            unique_id = cb.name + cb.value;
            var trNode = cb.parentNode.parentNode;
            if(c){
                if (typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id]) {
                    trNode.className += ' marked';
                    marked_row[unique_id] = true;
                }
            }else{
                trNode.className = trNode.className.replace(' marked', '');
                marked_row[unique_id] = false;
            }
            n2++;
        }
    }
    if (c) {
        document.adminForm.boxchecked.value = n2;
    } else {
        document.adminForm.boxchecked.value = 0;
    }
}
function isChecked(isitchecked){
    var cval = $('#boxchecked').val();
    if (isitchecked == true){
        $('#boxchecked').val(cval+1);
    }else {
        $('#boxchecked').val(cval-1);
    }
}
function checkFormData(frmname){
    var objFormChecker = new formChecker;
    objForm = eval('document.' + frmname);
    if(objFormChecker.Check(objForm)){
        return true;
    }
    return false;
}
function previewImage(name, live_site){
    form = document.adminForm;
    var src = live_site+'/'+name;
    html = '<img border="1" src="'+src+'" name="imagelib" alt="No preview available" width="102" height="76" />';
    return overlib(html, CAPTION, '预览图像')
}
function changeDynaList( listname, source, key, orig_key, orig_val ) {
    var list = eval( 'document.adminForm.' + listname );
    for (i in list.options.length) {
        list.options[i] = null;
    }
    opt = new Option();
    opt.value = '';
    opt.text = '---请选择---';
    list.options[0] = opt;
    i = 1;
    for (x in source) {
        if (source[x][0] == key) {
            opt = new Option();
            opt.value = source[x][1];
            opt.text = source[x][2];

            if ((orig_key == key && orig_val == opt.value) || i == 0) {
                opt.selected = true;
            }
            list.options[i++] = opt;
        }
    }
    list.length = i;
}
// JavaScript Document
/** 兼容IE和Firefox的加入收藏的代码*/
function addFavorite(siteurl, title){
    if (document.all){
        window.external.addFavorite(siteurl, title);
    }else if (window.sidebar){
        window.sidebar.addPanel(title, siteurl, "");
    }
}
/** 兼容IE和Firefox设为首页的代码*/
function setHomepage(siteurl){
    if (document.all){
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(siteurl);
    }else if (window.sidebar){
        if (window.netscape){
            try{
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }catch (e){
                alert( "該操作被瀏覽器拒絕，如果想啟用該功能，請在地址欄內輸入about:config,然後將項signed.applets.codebase_principal_support值該為true" );
                return false;
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', siteurl);
    }
}
/**
* Default function.  Usually would be overriden by the component
*/
function submitbutton(pressbutton) {
    submitform(pressbutton);
}

/**
* Submit the admin form
*/
function submitform(pressbutton){
    document.adminForm.act.value=pressbutton;
    if (typeof document.adminForm.onsubmit == "function") {
        document.adminForm.onsubmit();
    }
    document.adminForm.submit();
}
function listItemTask( id, act ) {
    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        submitbutton(act);
    }
    return false;
}
function sendUrl(url){
    window.location=url;
}
function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p)
        d.MM_p = new Array();
        var i,j = d.MM_p.length,
        a = MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){
            d.MM_p[j]=new Image;
            d.MM_p[j++].src=a[i];
        }
    }
}