function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

window.onload = function() {
    if (!document.getElementsByTagName)
        return;

    var a, i = 0;
    while ((a = document.getElementsByTagName("a")[i++])) {
        if ("#" == a.getAttribute("href")) {
            a.onclick = function() { backToTop(); return false; }
        }
    }
}

function expand(e, index) {
    var subzone = document.getElementById('subzone' + index);
    if (e.checked) {
       // subzone.style.display = "block";
       // updateSub(e, index);
        document.getElementById('ctl00_bodyContent_ctl00_chkAll').checked = false;
    }
//    else
//        subzone.style.display = 'none';
}
function updateSub(e, index) {
    var id = "f" + index + "_chkSubZones_";
    for (i = 0; i < 10; i++) {
        var sub = document.getElementById(id + i);
        if (sub != null) sub.checked = e.checked;
    }

}
//function selectAll(e) {
//    if (e.checked) {
//        var theForm = e.form;
//        var z = 0;
//        for (z = 0; z < theForm.length; z++) {
//            if (theForm[z].type == 'checkbox' && (theForm[z].name.indexOf('chkRoot') > 0 || theForm[z].name.indexOf('chkSubZones') > 0)) {
//                theForm[z].checked = false;
//            }
//        }
//    }
//}

//function selectAll(e) {
//    if (e.checked) {
//        var theForm = e.form;
//        var z = 0;
//        for (z = 0; z < theForm.length; z++) {
//            if (theForm[z].type == 'checkbox' && (theForm[z].name('ctl00_bodyContent_ctl00_chkAll').checked = true) || theForm[z].name.indexOf('chkSubZones') > 0)) {
//                theForm[z].checked = false;
//            }
//        }
//    }
//}

function checkAll(checkname, exby) {
	  for (i = 0; i < checkname.length; i++)
	  checkname[i].checked = exby.checked? true:false
	}




// phan tags
function tagClouds_Callback()
{
    var keywordList = '';
    for(i = 0; i < 10 ; i++)
    {                
        key = 'keyword' + i ;                
        tb = document.getElementById(key);   
       // alert(tb.value);
//        if (tb.value != '')
//        {
//            keywordList = keywordList + tb.value + ",";
//            
//        }
    }
    if (keywordList != '')
    {
        document.getElementById('updateProgress').style.display = "";
        WebForm_DoCallback('ctl00$bodyContent$ctl00',keywordList,changeTagClouds,null,null,true);
    }
}

function changeTagClouds(value, context)
{
    $j('#tagCloudHolder').html(value);
    $j('#updateProgress').hide();
}
            
function addKeyword(keyword)
{                                    
    added = 0;
    for(i = 1; i < 10 ; i++)
    {
        key = 'keyword' + i ;                
        tb = document.getElementById(key);                                
        if (tb.value == '')
        {
            tb.value = keyword;
            added = 1;
            tagClouds_Callback();
            break;
        }
    }                        
    if (added == 0)
        alert('Danh sách đã kín, không thể thêm từ khóa!');                
}
function removeKeyword(index)
{            
    key = 'keyword' + index ;   
    tb = document.getElementById(key);                          
    tb.value = '';
    tagClouds_Callback();
}        
function selectall(e)
{
    alert(e);
}

//phan nguon tin

function allcheck() {
    checkAll = document.getElementById('ctl00_bodyContent_ctl00_cbAll');
    var theForm = document.form1;//document.forms[0];
//    alert(theForm.length);
    if (checkAll.checked) {
        var i = 0;
        for (i = 0; i < theForm.length; i++)
        	//alert(theForm[i].type);
            if (theForm[i].type == 'checkbox' && theForm[i].id != checkAll.id && theForm[i].id != '') {
            theForm[i].checked = true;
        }
    }
}
function itemcheck() {
    checkAll = document.getElementById('ctl00_bodyContent_ctl00_cbAll');
    var theForm = document.form1;//document.forms[0];
    var i = 0;
    for (i = 0; i < theForm.length; i++)
        if (theForm[i].type == 'checkbox' && !theForm[i].checked && theForm[i].id != checkAll.id && theForm[i].id != '') {
        checkAll.checked = false;
        return;

    }
    checkAll.checked = true;
}
function uncheck() {

    checkAll = document.getElementById('ctl00_bodyContent_ctl00_cbAll');
    checkAll.checked = false;

    var theForm = document.form1;//document.forms[0];
    var i = 0;
    for (i = 0; i < theForm.length; i++)
        if (theForm[i].type == 'checkbox' && theForm[i].id != checkAll.id)
        theForm[i].checked = false;
}

