// JavaScript Document

function getjson( vars , func )
{
	$('#ajaxloading').fadeIn('fast');
	
	try{
		$.post( 'ajax.php' , 'function='+func+'&'+vars , function( data ){
			
			var json = data;
			
			for( var i = 0 ; i < json.response.length; i++ )
			{
				
				switch( json.response[i].type )
				{
					case 'HTML':
						$( json.response[i].container ).html( json.response[i].data );	
						break;
					case 'SUCCESS':
						success( json.response[i].data );
						break;
					case 'WARNING':
						warn( json.response[i].data );
						break;
					case 'JSCRIPT':
						eval( json.response[i].data );
						break;
				}
				
			}
			
			$('#ajaxloading').hide();
			
		},'json');
	}
	catch(e){
		warn(e);
		$('#ajaxloading').hide();
	}
	
}

function update_login_status( json )
{
	for( var i = 0 ; i < json.response.length; i++ )
	{
		switch( json.response[i].type )
		{
			case 'HTML':
				$( '#login_holder' ).html( json.response[i].data );	
				break;
		}		
	}
}

function del( target , id )
{
	question("Are you sure you want to delete \"" + ($('#description_' + id ).html()) + "\"? <br /><br /><a href=\"#\" id=\"red_btn\" onclick=\"hidequestion(); return permadel('" + target + "','" + id + "')\">Delete</a> <a href=\"#\" id=\"grey_btn\" onclick=\"return hidequestion();\"')\">Cancel</a>");
}

function permadel( target , id )
{
	getjson( "target="+target+"&id=" + id , 'delete' );
	return false;	
}

function rem( target , id )
{
	question("Are you sure you want to delete \"" + ($('#description_' + id ).html()) + "\"? <br /><br /><a href=\"#\" id=\"red_btn\" onclick=\"hidequestion(); return permarem('" + target + "','" + id + "')\">Delete</a> <a href=\"#\" id=\"grey_btn\" onclick=\"return hidequestion();\"')\">Cancel</a>");
}

function permarem( target , id )
{
	getjson( "target="+target+"&id=" + id , 'remove' );
	return false;
}

function pub( target , id )
{
	getjson( "target="+target+"&id=" + id , 'publish' );
	return false;
}

function res( target , id )
{	
	getjson( "target="+target+"&id=" + id , 'restore' );
	return false;
}