function force_reset (this_field)
{
    this_field.value = '';
}

function force_text_max_length(this_textarea, max_length)
{
    return (this_textarea.value.length <= max_length);
}

/*
function update_text_counter(this_textarea, max_length)
{
    div_id = this_textarea.name + '_counter';
    
    text_len = this_textarea.value.length;
    percent = (max_length - text_len) / max_length * 100;
    count = max_length - text_len;

    document.getElementById(div_id).innerHTML = ((count >= 0) ? count : 0);
    
    if (percent <= 5)
    {
        document.getElementById(div_id).style.color = '#990000';
    }
}
*/
function update_text_counter(this_textarea, max_length)
{
    var div_id = this_textarea.name + '_counter';
    
    if (document.getElementById(div_id)) 
    {
        var text_len = this_textarea.value.length;
        var percent = (max_length - text_len) / max_length * 100;
        var txt_count = max_length - text_len;
        
        document.getElementById(div_id).innerHTML = ((txt_count >= 0) ? txt_count : 0);
        
        if (percent <= 5) 
        {
            document.getElementById(div_id).style.color = '#990000';
        }
        else 
        {
            document.getElementById(div_id).style.color = '#666666';
        }
    }
}

function clear_comment_form (field_arr, max_textarea_len)
{
    for (var x = 0; x < field_arr.length; x++) 
    {
        var textbox_name = field_arr[x];

        document.forms['comment_form'][textbox_name].value = '';
        
        if (document.forms['comment_form'][textbox_name]) 
        {
            update_text_counter(document.forms['comment_form'][textbox_name], max_textarea_len);
        }
    }
}

function force_wordwrap (this_textarea, wrap_len)
{
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
    {
        if (this_textarea.value.length > wrap_len)
        {
            if((this_textarea.value.length % (wrap_len+1)) == 0 && this_textarea.value.length != (wrap_len+1))
            {
                this_textarea.value += "\n";
            }            
        }
        else if((this_textarea.value.length % wrap_len) == 0 && this_textarea.value.length > 1)
        {
            this_textarea.value += "\n";
        }
    }

    return true;    
}

//var ijk = 0;

function hide_div(id)
{
    document.getElementById(id).className = id + '_hide';
    document.getElementById('mlist_form').className = 'mlist_show';
}

function show_div(id)
{
    document.getElementById(id).className = id + '_show';
    document.getElementById('mlist_form').className = 'mlist_hide';
}

function rollover (id, img)
{
    if (id.indexOf(cur_page) == -1) 
    {
        document.getElementById(id).src = img;
    }
}

function show_rows(rows)
{
    for (var x = 0; x < rows.length; x++) 
    {
        document.getElementById(rows[x]).className = 'toggle_on';
    }
}

function hide_rows(rows)
{
    for (var x = 0; x < rows.length; x++) 
    {
        document.getElementById(rows[x]).className = 'toggle_off';
    }
}

function show_form ()
{
	
    if (document.getElementById('lightbox_head_form') && document.getElementById('lightbox_head_default')) 
    {
        document.getElementById('lightbox_head_form').className = 'toggle_on';
        document.getElementById('lightbox_head_default').className = 'toggle_off';
    }
    
    show_lightbox('index.php?page=app_sap', 700, 500);
    document.getElementById('lightbox_frame').scrolling = 'auto';
	
	
}

function kill_session()
{
    frames['lightbox_frame'].location.href = './scripts/php/kill_session.php';
}

function show_video_contest ()
{
    show_lightbox('../spring2009/video_contest.php', 700, 500);
    document.getElementById('lightbox_frame').scrolling = 'auto';
}

function tab_toggle (id, action)
{
    var classname;

    if (action == 'mouseover')
    {
        classname = 'tab_hilite';
    }
    else if (action == 'mouseout')
    {
        classname = 'tab_fade';        
    }

    if (document.getElementById(id)) 
    {
        document.getElementById(id).className = classname;
    }
}

function load_comment_form (this_form, blog_id)
{
    ajax_load('scripts/php/show_comment_form.php', '', 'div_comment', {'type': this_form, 'blog_id': blog_id}, 0)
}

function submit_complaint(this_form, comment_id)
{
    if (confirm('Do you really want to report this comment?'))
    {
        this_form.comment_id.value = comment_id;
        this_form.submit_complaint.value = 'true';
        
        this_form.submit();
    }
}

function delete_comment(this_form, comment_id)
{
    if (confirm('Do you really want to delete this comment?'))
    {
        this_form.comment_id.value = comment_id;
        this_form.delete_comment.value = 'true';
        
        this_form.submit();
    }
}