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 popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=388,height=450,left= 300,top = 200');");
}

function shoutReq(){
    $.ajax({
       type: "GET",
       url: "http://www.supercarnews.com/2010_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.supercarnews.com/2010_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.supercarnews.com/forum_edit.php", 'id=' + postID );
}

function forumSavePost( postID )
{
    cEdit = document.getElementById( 'edit' + postID );
    
    $('#post' + postID).load( "http://www.supercarnews.com/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.supercarnews.com/forum_move.php", 'id=' + postID );
    }
    else
    {
        $('#threadOpt').load( "http://www.supercarnews.com/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;
        }
    }
}

function resizeImages( maxWidth ) 
{ 
    for( i = 0; i < document.images.length; i++ ) 
    { 
        while ( !document.images[i].complete ) 
        { 
            break; 
        } 
        if ( document.images[i].width > maxWidth ) 
        { 
            myScale   = maxWidth / document.images[i].width;
            newHeight = document.images[i].height * myScale;
            document.images[i].width  = maxWidth; 
            document.images[i].height = newHeight; 
        } 
    } 
} 
