var aXmlHttp = new Array();
var aXmlResponse = new Array();
var httpRequest = null;
var fn = ob = null;
function xmlResult()
{
    //alert("phan1" + aXmlHttp.length);
    for (var i = 0; i < aXmlHttp.length; i++)
    {
        if (aXmlHttp[i] && aXmlHttp[i][0] && aXmlHttp[i][0].readyState == 4 && aXmlHttp[i][0].responseText)
        {
            if (aXmlHttp[i][0].status == 200) {
                //must null out record before calling function in case
                //function invokes another xmlHttpRequest.

                var f = aXmlHttp[i][2];
                var o = aXmlHttp[i][1];
                var s = aXmlHttp[i][0].responseText;
                aXmlHttp[i][0] = null;
                aXmlHttp[i][1] = null;
                aXmlHttp[i][2] = null;
                f.apply(o, new Array(s));
            }
        }
    }
}

// u -> url
// o -> object (can be null) to invoke function on
// f -> callback function
// p -> optional argument to specify POST

function call(u, o, f)
{
    var method = "GET";
//    var dat;
    /*if (arguments.length == 4) {
        method = "POST";
        tmp = u.split(/\?/);
        u = tmp[0];
        dat = tmp[1];

    }*/
    var idx = aXmlHttp.length;
    for (var i = 0; i < idx; i++)
        if (aXmlHttp[i] == null)
        {
            idx = i;
            break;
        }

    aXmlHttp[idx] = new Array(10);

    aXmlHttp[idx][0] = getXMLHTTP();

    aXmlHttp[idx][1] = o;
    aXmlHttp[idx][2] = f;
    if (aXmlHttp[idx])
    {
        aXmlHttp[idx][0].open(method, u, true);
        /*if (method == "POST") {
            aXmlHttp[idx][0].setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8; text/xml");
            aXmlHttp[idx][0].send(dat);
        }*/
        aXmlHttp[idx][0].onreadystatechange = xmlResult;
        if (method == "GET") {
            aXmlHttp[idx][0].send(null);
        }
    }
    //alert("111");
}


function getXMLHTTP()
{
    var A = null;
    if (!A && typeof XMLHttpRequest != "undefined")
    {
        A = new XMLHttpRequest();
        if (A.overrideMimeType) {
            A.overrideMimeType('text/xml');
        }

    }
    if (!A)
    {
        try
        {
            A = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                A = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(oc)
            {
                A = null
            }
        }
    }
    return A;
}

var ca = new Array("a", "à.á.ạ.ả.ã.â.ầ.ấ.ậ.ẩ.ẫ.ă.ằ.ắ.ặ.ẳ.ẵ.À.Á.Ạ.Ả.Ã.Â.Ầ.Ấ.Ậ.Ẩ.Ẫ.Ă.Ằ.Ắ.Ặ.Ẳ.Ẵ");
var ce = new Array("e", "è.é.ẹ.ẻ.ẽ.ê.ề.ế.ệ.ể.ễ.È.É.Ẹ.Ẻ.Ẽ.Ê.Ề.Ế.Ệ.Ể.Ễ");
var ci = new Array("i", "ì.í.ị.ỉ.ĩ.Ì.Í.Ị.Ỉ.Ĩ");
var co = new Array("o", "ò.ó.ọ.ỏ.õ.ô.ồ.ố.ộ.ổ.ỗ.ơ.ờ.ớ.ợ.ở.ỡ.Ò.Ó.Ọ.Ỏ.Õ.Ô.Ồ.Ố.Ộ.Ổ.Ỗ.Ơ.Ờ.Ớ.Ợ.Ở.Ỡ");
var cu = new Array("u", "ù.ú.ụ.ủ.ũ.ư.ừ.ứ.ự.ử.ữ.Ù.Ú.Ụ.Ủ.Ũ.Ư.Ừ.Ứ.Ự.Ử.Ữ");
var cy = new Array("y", "ỳ.ý.ỵ.ỷ.ỹ.Ỳ.Ý.Ỵ.Ỷ.Ỹ");
var cd = new Array("d", "đ.Đ");
//var cs = new Array("", "\'.~.@.#.%.^.&");
//var bangkitucoso = new Array(ca, ce, ci, co, cu, cy, cd, cs);
var bangkitucoso = new Array(ca, ce, ci, co, cu, cy, cd);
function mLocDau(bv)
{
    var markhongdau = new Array();
    markhongdau[0] = bv;
    for (var j = 0; j < bangkitucoso.length; j++) // max j = 8
    {
        var marthaythe = bangkitucoso[j][1].split('.'); // tach cac chuoi co dau thanh tung phan tu rieng biet
        for (var i = 0; i < marthaythe.length; i++)
        {
            markhongdau[i + 1] = mThayThe(markhongdau[i], marthaythe[i], bangkitucoso[j][0]);
            markhongdau[0] = markhongdau[i + 1].toLowerCase();
        }
    }

    return markhongdau[0];
}
function mThayThe(ccha, cbithay, cthaythe)
{
    var ccon = "/" + cbithay + "/gi";
    return ccha.replace(eval(ccon), cthaythe);
}

var rt24hHearingWindow;
var width, height, left, top, styleStr;
function NgheNhac(songId, type, autoStart) {
    width = "600";
    height = "630";
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    rt24hHearingWindow = window.open('nghenhac.jsp?id=' + songId + '&type=' + type + '&autoStart=' + autoStart, "Rt24hHearingWindow", styleStr);

    var topviewPlayer;
    if (navigator.appName.indexOf("Microsoft") != -1) {
        topviewPlayer = parent.frames['topviewf'].frames['tvPlayer'].document.getElementById('thePlayer');
        topviewPlayer.controls.pause();
    } else {
        var topviewf = parent.frames['topviewf'].document.getElementById('tvPlayer');
        var topviewfSrc = topviewf.src;
        var find = topviewfSrc.indexOf('start=');
        if (find > 0) {
            topviewfSrc = topviewfSrc.substr(0, find) + 'start=false&ran=' + (new Date()).getTime();
        } else {
            topviewfSrc = topviewfSrc + '&start=false';
        }
        topviewf.src = topviewfSrc;
    }

    rt24hHearingWindow.focus();
}

function NgheNhac2(songId, type, autoStart) {
    width = "600";
    height = "630";
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    rt24hHearingWindow = window.open('nghenhac.jsp?id=' + songId + '&type=' + type + '&autoStart=' + autoStart, "Rt24hHearingWindow", styleStr);

    rt24hHearingWindow.focus();
}

function NgheAlbum(albumId) {
    width = "600";
    height = "630";
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    rt24hHearingWindow = window.open('../v2/nghe-album.jsp?id=' + albumId, "Rt24hHearingWindow", styleStr);

    var topviewPlayer;
    if (navigator.appName.indexOf("Microsoft") != -1) {
        topviewPlayer = parent.frames['topviewf'].frames['tvPlayer'].document.getElementById('thePlayer');
        topviewPlayer.controls.pause();
    } else {
        var topviewf = parent.frames['topviewf'].document.getElementById('tvPlayer');
        var topviewfSrc = topviewf.src;
        var find = topviewfSrc.indexOf('start=');
        if (find > 0) {
            topviewfSrc = topviewfSrc.substr(0, find) + 'start=false&ran=' + (new Date()).getTime();
        } else {
            topviewfSrc = topviewfSrc + '&start=false';
        }
        topviewf.src = topviewfSrc;
    }

    rt24hHearingWindow.focus();
    //topviewf.src
}

var gopyWindow;
function gopy() {
    width = "767";
    height = "360";
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    gopyWindow = window.open('../v2/gopy.jsp', "gopyWindow", styleStr);

    gopyWindow.focus();
}

var keepIt = false;

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];
            }
    }
}

function changeSelectCate(newCate, cateName, jsp, status) {
    var current = document.getElementById('select-cate');
    var currentName = document.getElementById('select-cate-name');
    var currentJsp = document.getElementById('select-jsp');
    var currentStatus = document.getElementById('select-status');
    var html, nhtml;
    if (newCate != '') {
        var newC = document.getElementById(newCate);
        html = '<a class="scategory" ' +
               'onclick="return false;"' +
               'href="#">' + cateName +
               '</a>';
        if (status == '2') {
            html += '<img src="../images/cate/new.gif" alt="" width="28" height="11"/>';
        } else if (status == '3') {
            html += '<img src="../images/cate/hot.gif" alt="" width="20" height="16"/>';
        }
        newC.innerHTML = html;
    }
    var newStatus;
    if (currentStatus.value == 'undefined') {
        newStatus = '1';
    } else {
        newStatus = currentStatus.value;
    }
    if (current.value != '') {
        nhtml = '<a class="category" ' +
                'onclick="changeSelectCate(\'' + current.value + '\',\'' + currentName.value + '\',\'' + currentJsp.value + '\',\'' + newStatus + '\');displayItems(\'' + currentJsp.value + '\',\'' + current.value + '\',\'\',\'\',\'\');return false;"' +
                'href="#">' + currentName.value +
                '</a>';

        if (newStatus == '2') {
            nhtml += '<img src="../images/cate/new.gif" alt="" width="28" height="11"/>';
        } else if (newStatus == '3') {
            nhtml += '<img src="../images/cate/hot.gif" alt="" width="20" height="16"/>';
        }

        var oldC = document.getElementById(current.value);

        oldC.innerHTML = nhtml;
    }
    current.value = newCate;
    currentName.value = cateName;
    currentJsp.value = jsp;
    currentStatus.value = status;
}

var loading;
var pageText = new Object();
var lastView;
var lastSortBy = '';
var now;
function processStateChange(text) {
    document.getElementById("listSong").innerHTML = text;
    pageText[lastView] = text;
    hideLoading();

    window.scroll(0, 785);
    var titleValue = document.getElementById('titleValue');
    if ((null != titleValue) || (titleValue == 'undefined')) {
        document.title = titleValue.value + ' - Siêu thị nhạc chuông hài hước, độc đáo dành cho điện thoại. Uy tin và chất lượng nhất Việt Nam!';
    } else {
        document.title = 'Siêu thị nhạc chuông hài hước, độc đáo dành cho điện thoại. Uy tin và chất lượng nhất Việt Nam!';
    }
}

function showLoading() {
    loading = document.getElementById('loading');
    loading.style.visibility = 'visible';
    loading.style.display = 'inline';
    loading.style.left = '';
    loading.style.zIndex = '20';
}

function hideLoading() {
    loading = document.getElementById('loading');
    loading.style.visibility = 'hidden';
    loading.style.left = '-350px';
    loading.style.zIndex = '0';
}

function displayItems(jsp, cate, sortBy, page, searchStr, lId) {
    now = (new Date()).getTime();
    cancel();
    hideddrivetip();
    showLoading();

    var params;
    params = 'cate=' + cate;
    params += '&page=' + page;
    params += '&sortBy=' + sortBy;
    searchStr = mLocDau(searchStr);
    searchStr = encodeURIComponent(searchStr);
    params += '&search=' + searchStr;

    var compactAdd;
    compactAdd = "#";
    lastView = '';
    if (jsp != '') {
        compactAdd += 'j=' + jsp;
        lastView += jsp;
        if (jsp.indexOf('singerId') > 0) {
            compactAdd += '&t=singer';
            lastView += '&sg';
        }
    }
    if (cate != '') {
        compactAdd += '&c=' + cate;
        lastView += cate;
    }
    if (sortBy != '') {
        compactAdd += '&s=' + sortBy;
        //Reload pageText
        if (lastSortBy != sortBy) pageText = new Object();
        lastSortBy = sortBy;
    }

    if (page != '') {
        compactAdd += '&p=' + page;
        lastView += '&' + page;
    } else {
        lastView += '&1';
    }
    if (searchStr != '') {
        compactAdd += '&kw=' + searchStr;
        lastView += '&' + searchStr;
    }
    if ((arguments.length == 6) && (lId != '')) {
        document.getElementById(lId).href = compactAdd;
    } else {
        window.location = compactAdd;
    }

    var txt = pageText[lastView];
    if (null != txt) {
        document.getElementById("listSong").innerHTML = txt;
        hideLoading();

        window.scroll(0, 785);
        var titleValue = document.getElementById('titleValue');
        if ((null != titleValue) || (titleValue == 'undefined')) {
            document.title = titleValue.value + ' - Siêu thị nhạc chuông hài hước, độc đáo dành cho điện thoại. Uy tin và chất lượng nhất Việt Nam!';
        } else {
            document.title = 'Siêu thị nhạc chuông hài hước, độc đáo dành cho điện thoại. Uy tin và chất lượng nhất Việt Nam!';
        }
//        document.getElementById('lastpage').value = ((new Date()).getTime() - now) + '';
        return;
    }

    params += '&random=' + (new Date).getTime();
    var url = getJsp(jsp);
    if (url.indexOf('?') < 1) {
        url = url + '?' + params;
    } else {
        url = url + '&' + params;
    }
    call(url, null, processStateChange, 'POST');
}

function setValue(id, newValue) {
    document.getElementById(id).value = newValue;
}

var jspMap = null;

function Onload() {
    var lc = window.location + '';
    var id = lc.indexOf('#');
    if (id > 0) {
        var jsp,cate,sortBy,search,searchW,page,searchType, view;
        var pr = lc.substr(id + 1, (lc.length - id) - 1);
        var spls = pr.split('&');
        jsp = '';
        cate = '';
        sortBy = '';
        search = '';
        page = '';
        searchType = '';
        searchW = '';
        view = '';
        var sub1;
        var sub2;

        for (var i = 0; i < spls.length; i++) {
            id = spls[i].indexOf('=');
            if (id > 0) {
                sub1 = spls[i].substr(0, id);
                sub2 = spls[i].substr(id + 1, (spls[i].length - id) - 1);
                if (('j' == sub1) || ('jsp' == sub1))jsp = sub2;
                if (('c' == sub1) || ('cate' == sub1)) {
                    var cateIdx = sub2.indexOf('?');
                    if (cateIdx > -1) {
                        sub2 = sub2.substring(0, cateIdx);
                    }
                    cate = sub2;
                }
                if (('s' == sub1) || ('sortBy' == sub1)) {
                    sortBy = sub2;
                    lastSortBy = sortBy;
                }
                if (('kw' == sub1) || ('search' == sub1))search = sub2;
                if (('p' == sub1) || ('page' == sub1))page = sub2;
                if (('t' == sub1) || ('searchType' == sub1))searchType = sub2;
                if ('v' == sub1)view = sub2;
            }
        }
        jsp = getJsp(jsp);
        if (jsp != '') {
            showLoading();
            lastView = jsp;
            var url;
            var params;
            params = 'cate=' + cate;
            if (cate != '') {
                lastView += cate;
            }
            if (page != '') {
                lastView += '&' + page;
                params += '&page=' + page;
            } else {
                lastView += '&1';
            }
            params += '&sortBy=' + sortBy;
            if (sortBy != '') {
                lastSortBy = sortBy;
            }
            params += '&search=' + search;
            if (search != '') {
                lastView += '&' + search;
            }
            params += '&searchType=' + searchType;
            if (jsp.indexOf('?') < 1) {
                url = jsp + '?' + params;
            } else {
                url = jsp + '&' + params;
            }
            call(url, null, processStateChange, 'POST');
        }
        if (view != '') {
            play(view);
        }
    }
}

function getJsp(jsp) {
    var simpleJsp, singerIdStr;
    var find;
    simpleJsp = jsp + '';
    singerIdStr = '';
    find = jsp.indexOf('?');
    if (find > 0) {
        simpleJsp = jsp.substring(0, find);
        singerIdStr = jsp.substring(find, jsp.length);
        if (singerIdStr.indexOf('singerId') >= 0)singerIdStr = singerIdStr + '&searchType=singer';
    }
    if (null == jspMap) {
        jspMap = new Object();
        jspMap['a'] = 'album.jsp';
        jspMap['sc'] = 'show-cate.jsp';
        jspMap['nc'] = 'nhac-che.jsp';
        jspMap['ncl'] = 'nhac-co-loi.jsp';
        jspMap['dda'] = 'don-da-am.jsp';
        jspMap['att'] = 'am-thanh-thuc.jsp';
        jspMap['g'] = 'gprs.jsp';
        jspMap['s'] = 'search.jsp';
        jspMap['sk'] = 'su-kien.jsp';
        jspMap['show-cate.jsp'] = 'show-cate.jsp';
        jspMap['nhac-che.jsp'] = 'nhac-che.jsp';
        jspMap['nhac-co-loi.jsp'] = 'nhac-co-loi.jsp';
        jspMap['don-da-am.jsp'] = 'don-da-am.jsp';
        jspMap['am-thanh-thuc.jsp'] = 'am-thanh-thuc.jsp';
        jspMap['gprs.jsp'] = 'gprs.jsp';
        jspMap['search.jsp'] = 'search.jsp';
    }
    var result;
    result = jspMap[simpleJsp];
    if (null == result) return '';
    return result + singerIdStr;
}

function play(songId) {
    document.getElementById('topviewf').src = 'topview.jsp?selectId=' + songId;

    var lc = window.location + '';
    var id = lc.indexOf('v=');
    if (id > 0) {
        lc = lc.substr(0, id) + 'v=' + songId;
    } else {
        id = lc.indexOf('#');
        if (id > 0) {
            lc = lc + '&v=' + songId;
        } else {
            lc = lc + '#v=' + songId;
        }
    }

    window.location = lc;
    window.scroll(0, 400);
}

var searchType = 0;
function showSt(idx) {
    document.getElementById('st' + idx).className = 'st' + idx + '1';
    document.getElementById('fst' + idx).className = 'st' + idx + '1';
}

function restoreSt() {
    var ext;
    for (var i = 0; i < 3; i++) {
        ext = (i == searchType) ? '1' : '0';
        document.getElementById('st' + i).className = 'st' + i + ext;
        document.getElementById('fst' + i).className = 'st' + i + ext;
    }
}

function changeSt(idx) {
    var ext;
    for (var i = 0; i < 3; i++) {
        ext = (i == idx) ? '1' : '0';
        document.getElementById('st' + i).className = 'st' + i + ext;
        document.getElementById('fst' + i).className = 'st' + i + ext;
    }
    searchType = idx;
}

function NChim(str) {
    var whitespace = ' \n\r\t\f';
    var counter;
    counter = 0;
    for (var i = 0; i < str.length; i++) {
        if (whitespace.indexOf(str.charAt(i)) == -1) {
            str = str.substring(i);
            break;
        }
        counter++;
    }
    if (counter == str.length)return '';

    for (i = str.length - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) == -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return whitespace.indexOf(str.charAt(0)) == -1 ? str : '';
}


function showVote(newVote, sId) {
    var elm;
    for (var i = 1; i <= 5; i++) {
        elm = document.getElementById(sId + '_' + i);
        elm.className = ((i <= newVote) ? 'saocam' : 'saoden');
    }
}

function restoreVote(originVote, sIdh) {
    var elm;
    for (var i = 1; i <= 5; i++) {
        elm = document.getElementById(sIdh + '_' + i);
        elm.className = ((i <= originVote) ? 'saovang' : 'saoden');
    }
}

function showResult(text) {
    var result = text.split(',');
    if (result.length == 2) {
        var voteStar = NChim(result[0]);
        var voteCount = NChim(result[1]);
        document.getElementById('voteImg').innerHTML = '<table><tr><td class="saovang' + voteStar + '"><img src="../images/spacer.gif" alt=""/></td></tr></table>';
        document.getElementById('voteCount').innerHTML = '&nbsp;(' + voteCount + ' lượt đánh giá)';
        setTimeout("alert('Cảm ơn bạn đã đánh giá!')", 500);
    }
}

function sendVote(v, sid) {
    document.getElementById('voteImg').innerHTML = '<img src="../images/vote/loading1.gif" alt="Đang xử lý..." border="0"/>';
    call('vote.jsp?v=' + v + '&sid=' + sid + '&ran=' + (new Date()).getTime(), null, showResult, 'POST');
}

function sendVoteAlbum(v, sid) {
    document.getElementById('voteImg').innerHTML = '<img src="../images/vote/loading1.gif" alt="Đang xử lý..." border="0"/>';
    call('vote.jsp?a=1&v=' + v + '&sid=' + sid, null, showResult, 'POST');
}

function showCmResult(text) {
    var result = NChim(text);
    var commentResult = document.getElementById('commentResult');
    var enableSend;
    enableSend = true;
    if (result == '1') {
        commentResult.innerHTML = '<span class="success">Lời bình của bạn đã được gửi thành công!</span>';
        document.getElementById('comment').value = '';
    } else if (result == '2') {
        commentResult.innerHTML = '<span class="error">Tên người gửi quá dài<span>';
        document.getElementById('commenter').focus();
        document.getElementById('commenter').select();
    } else if (result == '3') {
        commentResult.innerHTML = '<span class="error">Lời bình quá dài<span>';
        document.getElementById('comment').focus();
        document.getElementById('comment').focus();
    } else if (result == '4') {
        commentResult.innerHTML = '<span class="error">Chưa nhập người gửi<span>';
        document.getElementById('commenter').focus();
        document.getElementById('commenter').select();
    } else if (result == '5') {
        commentResult.innerHTML = '<span class="error">Chưa nhập lời bình<span>';
        document.getElementById('comment').focus();
        document.getElementById('comment').focus();
    } else if (result == '6') {
        commentResult.innerHTML = '<span class="error">Bạn chỉ được phép gửi 3 lời bình cho 1 bài<span>';
        enableSend = false;
    } else {
        commentResult.innerHTML = '<span class="error">Hiện tại hệ thống chưa sẵn sàng, mời bạn thử lại<span>';
    }

    document.getElementById('sendbt').enabled = enableSend;
}

function sendComment(songId) {
    var commentResult = document.getElementById('commentResult');
    commentResult.innerHTML = '<img src="../images/vote/loading1.gif" alt="Đang xử lý..." border="0"/>';
    var sendBt = document.getElementById('sendbt');
    sendBt.enabled = false;

    var commenter = document.getElementById('commenter').value;
    var comment = document.getElementById('comment');

    var url;
    url = 'commenter.jsp?songId=' + songId +
          '&commenter=' + encodeURIComponent(commenter) +
          '&comment=' + encodeURIComponent(comment.value);

    call(url, null, showCmResult, 'POST');
}

function checkInput() {
    var commenter = document.getElementById('commenter');
    if (NChim(commenter.value) == '') {
        alert('Chưa nhập người gửi');
        commenter.focus();
        return false;
    }

    var comment = document.getElementById('comment');
    if (NChim(comment.value) == '') {
        alert('Chưa nhập lời bình');
        comment.focus();

        return false;
    }

    return true;
}

function showQuiz(quizId) {
    popup('quizResult.jsp?quizId=' + quizId, '240', '500');
}

function checkAndSubmit(theForm, quizId) {
    var chked;
    chked = false;
    var q;
    q = '';
    var checkedValue;
    checkedValue = '';
    for (var i = 0; i < theForm.length; i++) {
        var e = theForm.elements[i];
        if ((e.type.toLowerCase() == "checkbox") && e.checked) {
            checkedValue = e.value;
            chked = true;
            if (q != '')q = q + ',';
            q += e.value;
        }
    }
    if (!chked) {
        alert('Hãy chọn một trong các mục trước khi biểu quyết');
        return false;
    }
    /*
   if ((quizId == '1248938173544') && ((checkedValue == '1248938236019') || (checkedValue == '1248938244576'))) {
       popup('gopy.jsp?quizId=' + quizId + '&q=' + q, '275', '767')
       return true;
   } */
    popup('quizing.jsp?quizId=' + quizId + '&q=' + q, '240')

    return true;
}

var quizWindow;
function popup(url, height, width) {
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    quizWindow = window.open(url + '&ran=' + ((new Date()).getTime()), "QuizWindow", styleStr);

    quizWindow.focus();
}

function popup2(url, height, width) {
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
    quizWindow = window.open(url, "QuizWindow", styleStr);

    quizWindow.focus();
}

function chooseElement(theForm, chooseId, single) {
    var chooseCb = document.getElementById(chooseId);
    if (chooseCb.checked && single) {
        for (var i = 0; i < theForm.length; i++) {
            var e = theForm.elements[i];
            if ((e.type.toLowerCase() == "checkbox") && (e.id != chooseId)) {
                e.checked = false;
            }
        }
    }
}