var tStamp = 0;
var ePosts = Array();

function urlencode (str) {
    str = (str+'').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function shoutReq(){
    $.ajax({
       type: "GET",
       url: "http://www.vlcalais.com.au/shoutbox_ajax.php",
       data: "ts="+tStamp,
       success: function(msg){
           $(msg).prependTo('#sbox');
           setTimeout('shoutReq()', 10000);
           tStamp = $('#sbox tr').first().attr('rel');
       }
    });
}

function shoutMake(){
    shoutText = document.forms["fshout"].myShout.value;
    
	if (shoutText.replace(/ /g, '') == ''){
		alert('You must enter a shout!');
	}
	else{
        $.ajax({
           type: "GET",
           url: "http://www.vlcalais.com.au/shoutbox_ajax.php",
           data: "ts="+tStamp+"&post="+encodeURIComponent(shoutText),
           success: function(msg){
               $(msg).prependTo('#sbox');
               setTimeout('shoutReq()', 10000);
               tStamp = $('#sbox tr').first().attr('rel');
           }
        });
    }
    document.forms["fshout"].myShout.value = '';
	
    return false;
}

function forumEditPost( postID )
{
    ePosts['post' + postID] = $('#post' + postID).html();
    
    $('#post' + postID).load( "http://www.vlcalais.com.au/forum_edit.php", 'id=' + postID );
}

function forumSavePost( postID )
{
    cEdit = document.getElementById( 'edit' + postID );
    
    $('#post' + postID).load( "http://www.vlcalais.com.au/forum_edit.php", 'id=' + postID + '&editBody=' + encodeURIComponent(cEdit.value) );
}

function forumCancelPost( postID )
{
    $('#post' + postID).html( ePosts['post' + postID] );
}

function forumMoveThread( postID, moveID )
{
    if( moveID == 0 )
    {
        $('#threadOpt').load( "http://www.vlcalais.com.au/forum_move.php", 'id=' + postID );
    }
    else
    {
        $('#threadOpt').load( "http://www.vlcalais.com.au/forum_move.php", 'id=' + postID + '&move=' + $('#moveDestination').val() );
    }
}

function forumMoveCancel()
{
    $('#threadOpt').html('');
}

function confirmAction( cText )
{
    var isConfirmed = confirm( cText );
    if( isConfirmed )
    {
    	return true;
    }
    else
    {
    	return false;
    }
}

function allCheckUncheck( theElement )
{
    var theForm = theElement.form;
    var z = 0;
    for( z = 0; z < theForm.length; z++ )
    {
        if( theForm[z].type == 'checkbox' && theForm[z].name != 'doCUC' )
        {
            theForm[z].checked = theElement.checked;
        }
    }
}