﻿function update_search() {
    keyword = '';
    catagory = document.getElementById('catagory').value;
    if (document.getElementById('keyword').value != "Search By" && document.getElementById('keyword').value != "輸入搜尋內容" && document.getElementById('keyword').value != "输入搜寻内容")
        keyword = document.getElementById('keyword').value;
    document.location.href = 'default.aspx?catagory=' + catagory + "&keyword=" + keyword;
}
function update_page() {
    keyword = '';
    catagory = document.getElementById('catagory').value;
    if (document.getElementById('keyword').value != "Search By" && document.getElementById('keyword').value != "輸入搜尋內容" && document.getElementById('keyword').value != "输入搜寻内容")
        keyword = document.getElementById('keyword').value;
    page = document.getElementById('page').value - 1;
    if (!is_num(page + ''))
        page = 0;
    document.location.href = 'default.aspx?catagory=' + catagory + "&keyword=" + keyword + "&page=" + page;
}
function update_rating() {
    id = document.getElementById('vid').value;
    rating_1 = document.getElementById('rating_1').checked;
    rating_2 = document.getElementById('rating_2').checked;
    rating_3 = document.getElementById('rating_3').checked;
    rating_4 = document.getElementById('rating_4').checked;
    rating_5 = document.getElementById('rating_5').checked;
    if (rating_1 == false && rating_2 == false && rating_3 == false && rating_4 == false && rating_5 == false)
        alert("Please select the rating of this video.");
    else {
        if (rating_1)
            document.location.href = 'videos.aspx?id=' + id + '&point=' + 1;
        if (rating_2)
            document.location.href = 'videos.aspx?id=' + id + '&point=' + 2;
        if (rating_3)
            document.location.href = 'videos.aspx?id=' + id + '&point=' + 3;
        if (rating_4)
            document.location.href = 'videos.aspx?id=' + id + '&point=' + 4;
        if (rating_5)
            document.location.href = 'videos.aspx?id=' + id + '&point=' + 5;
    }
}
function is_num(num)
{
    numbers = "0123456789";
    result = true;
    for (i = 0; i < num.length && result == true; i++)
    {
        character = num.charAt(i);
        if (numbers.indexOf(character) == -1)
        {
            result = false;
        }
    }
    return result;
}