function DisplayOptionNumber(smallNum, bigNum, chooseNum){
    for(var i=smallNum;i<=bigNum;i++){
        if(i==chooseNum){
            document.write("<option value=\""+i+"\" selected>"+i+"</option>");
        }
        else{
            document.write("<option value=\""+i+"\">"+i+"</option>");
        }
    }
}

function CheckAddNewMovie(){
    var title = jQuery('#title').val();
    var poster = jQuery('#poster').val();
    var trailer = jQuery('#trailer').val();
    var content = jQuery('#content').val();
    var desc = jQuery('#desc').val();
    var keyword = jQuery('#keyword').val();
    var cate_id = jQuery('#cate_id').val();
    var cate_id2 = jQuery('#cate_id2').val();
    var cate_id3 = jQuery('#cate_id3').val();

    var error ='';
    var countError=0;

    if(!title){
        error +='- Title must be not empty\n';
        countError++;
    }
    if(!cate_id && !cate_id2 && !cate_id3){
        error +='- Least one category must be selected\n';
        countError++;
    }
    if(!poster){
        error +='- Poster must be not empty\n';
        countError++;
    }
    if(!trailer){
        error +='- Trailer must be not empty\n';
        countError++;
    }
    if(!content || content=='<p></p>' || content=='<br />'){
        error +='- Content must be not empty\n';
        countError++;
    }
    if(!desc){
        error +='- Description must be not empty\n';
        countError++;
    }

    // display error
    if(error)
    {
        alert('Have '+countError+' error bellow: \n\n'+error);
        return false;
    }else{
        return true;
    }
}
function CheckUpdateMovie(){
    var title = jQuery('#title').val();
    var trailer = jQuery('#trailer').val();
    var content = jQuery('#content').val();
    var desc = jQuery('#desc').val();
    var keyword = jQuery('#keyword').val();
    var cate_id = jQuery('#cate_id').val();
    var cate_id2 = jQuery('#cate_id2').val();
    var cate_id3 = jQuery('#cate_id3').val();
    
    var error ='';
    var countError=0;

    if(!title){
        error +='- Title must be not empty\n';
        countError++;
    }
    if(!cate_id && !cate_id2 && !cate_id3){
        error +='- Least one category must be selected\n';
        countError++;
    }
    if(!trailer){
        error +='- Trailer must be not empty\n';
        countError++;
    }
    if(!content || content=='<p></p>'){
        error +='- Content must be not empty\n';
        countError++;
    }
    if(!desc){
        error +='- Description must be not empty\n';
        countError++;
    }

    // display error
    if(error)
    {
        alert('Have '+countError+' error bellow: \n\n'+error);
        return false;
    }else{
        return true;
    }
}
function CheckRegister(){
    var user = jQuery('#user').val();
    var pw = jQuery('#pw').val();
    var repw = jQuery('#repw').val();
    var name = jQuery('#name').val();
    var email = jQuery('#email').val();
    var answer = jQuery('#answer').val();
    
    var error ='';
    var countError=0;

    if(user.length<4){
        error +='- Username must be at least 4 character \n';
        countError++;
    }

    if(pw.length<6){
        error +='- Password must be at least 6 character\n';
        countError++;
    }

    if(pw!=repw){
        error +='- Re-Password must be same password\n';
        countError++;
    }
    if(name.length<4){
        error +='- Name must be at least 4 character\n';
        countError++;
    }
    emailRE = new RegExp();
    emailRE = /^\w+([\-\.]\w+)*@\w+(\-\w+)*(\.[a-zA-Z]+)+$/;
    if(emailRE.test(email)==false){
        error +='- Email must be true format : abc@domain.com\n';
        countError++;
    }
    if(answer.length<4){
        error +='- Answer must be at least 4 character\n';
        countError++;
    }

    // display error
    if(error!='')
    {
        alert('Have '+countError+' error bellow: \n\n'+error);
        return false;
    }
    return true;
}

function CheckUpdateProfile(){
    var name = jQuery('#name').val();
    var email = jQuery('#email').val();
    var answer = jQuery('#answer').val();

    var error ='';
    var countError=0;

    if(name.length<4){
        error +='- Name must be at least 4 character\n';
        countError++;
    }
    emailRE = new RegExp();
    emailRE = /^\w+([\-\.]\w+)*@\w+(\-\w+)*(\.[a-zA-Z]+)+$/;
    if(emailRE.test(email)==false){
        error +='- Email must be true format : abc@domain.com\n';
        countError++;
    }
    if(answer.length<4){
        error +='- Answer must be at least 4 character\n';
        countError++;
    }

    // display error
    if(error!='')
    {
        alert('Have '+countError+' error bellow: \n\n'+error);
        return false;
    }
    return true;
}


// Toggle
        // Andy Langton's show/hide/mini-accordion - updated 23/11/2009
        // Latest version @ http://andylangton.co.uk/jquery-show-hide

        // this tells jquery to run the function below once the DOM is ready
        jQuery(document).ready(function toggle() {

            // choose text for the show/hide link - can contain HTML (e.g. an image)
            var showText='+/-';
            var hideText='+/-';

            // initialise the visibility check
            var is_visible = true;

            // append show/hide links to the element directly preceding the element with a class of "toggle"
            //jQuery('.toggle').prev().append(' [ <a href="#" class="toggleLink"><strong>'+showText+'</strong></a> ]');

            // hide all of the elements with a class of 'toggle'
            //jQuery('.toggle').hide();

            // capture clicks on the toggle links
            jQuery('a.toggleLink').click(function() {

                // switch visibility
                is_visible = !is_visible;

                // change the link depending on whether the element is shown or hidden
                jQuery(this).html( (!is_visible) ? showText : hideText);

                // toggle the display - uncomment the next line for a basic "accordion" style
                //$('.toggle').hide();$('a.toggleLink').html(showText);
                jQuery(this).parent().next('.toggle').toggle('slow');

                // return false so any link destination is not followed
                return false;

            });
        });
// end toggle