var report_img_path;

ajax.reportBefore = function () {
	
};

ajax.reportComplete = function (data) {
	if (!data) return;
	
	var route = $('#report_form input[name="route"]').val();
	
	if (route == 'chat') {
		getMovieName("chatroom").swfFunc('screenShot');
        $('#chat_screen_cap').show();
		$('#inquiry_error_no_img').hide();
	}
	
    showPopPage();
    
	$('#report_close').click(function(){ clearPopWindow(); });
	
    $('#report_close, #report_block .close_button').bind('click', function(){
		if ($('#screen_shot_img').size() > 0) {
			$.post('/report/cancel', {'report_img_path' : report_img_path});
		}
    });
    
    $('#report_submit').click(function(){
        $('#report_form').submit();
    });
    
    $('#report_form').submit(function(){
		
		var params = new Object();
		
		if (route == 'chat') {
			if ($('#screen_shot_img').size() < 1) {
	            $('#inquiry_error_no_img').show();
	            return false;
	        } else {
	            params['report_img_path'] = report_img_path;
	        }
		}
        
        params['report_type'] = $('#report_form input[name="report_type"]:checked').val();
        params['report_text'] = $.trim( $('#report_form textarea[name="report_text"]').val() );
        params['route']       = route;
		params['id']          = $('#report_form input[name="id"]').val();
		params['prof_type']   = $('#report_form input[name="prof_type"]').val();
		params['user_id']     = $('#report_form input[name="user_id"]').val();
		params['chara_id']    = $('#report_form input[name="chara_id"]').val();
		params['back_id']     = $('#report_form input[name="back_id"]').val();
		params['report_book'] = typeof(chatting_book) == 'undefined' ? '' : chatting_book;
        
        $('#error_type').removeClass('inquiry_error');
        
        if (!params['report_type']) {
            $('#error_type').addClass('inquiry_error');
            return false;
        }
        
        $.post('/report/index', params,
              function(data){
                 var top = $('#pop_page').offset().top;
                 var height = $('#report_block').height();
                 
                 $('#report_input').hide('fast');
                 $('#report_finish').show('fast');
                 $('#pop_page').animate({height: '270px','top': (height/2+top-135)+'px'});
                 $('#report_close2').click(function(){
                     clearPopWindow();
                 });
              });
        
        return false;
    });
};

flash.screenShotPath = function (param) {
	report_img_path = param[0];
	
	$('#screen_loading').remove();
	$('#chat_screen_cap').prepend('<img id="screen_shot_img" src="/tmp' + param[0] + '" width="240px" height="144px" style="float:left;" alt="screen_shot"/>');
    $('#inquiry_error_no_img').hide();
};

