var $j = jQuery.noConflict();
$j(document).ready(function(){

   var base_url = $j('#base_url').val();
    /**
    * sumbit form in submitdata
    **/
	
	
	
	
	$j("#btnSaveCaseLog").click(function(){
		var caseLogContent = $j("#caseLogScroller").html();
		var user_data = escape(caseLogContent);
		var user_id = $j("#user_id").val();
		
		// Extract grade and score
		var gradeMatch = caseLogContent.match(/Grade:\s*(.*?)\n/);
		var scoreMatch = caseLogContent.match(/Score:\s*(.*?)\n/);
		
		var grade = gradeMatch ? gradeMatch[1].trim() : '';
		var score = scoreMatch ? scoreMatch[1].trim() : '';

		var action = 'userdata';
		if(user_data=='') {
			alert('Please add your data');
			$j("#user_data").focus();
			return false;
		}    
		$j('#loader').addClass("image_show");
		
		// Call Ajax to post data
		$j.ajax({
			type: "POST",
			url: "../actions/user/user_a.php",
			data: {
				'user_data': user_data,
				'user_id': user_id,
				'action': action,
				'case_grade': grade,
				'case_score': score
			},   		  
			success: function(html){
				$j("#user_data").val('');
				$j('#loader').removeClass("image_show");
				$j('#green').addClass("green_show");
				$j('#green').fadeOut(1600, "linear",'');
			}
		});
	});
    
    /**
    * logout
    **/
    $j("#logout").click(function(){
        
        
        var action = 'logout';
            
        $j.ajax({
            type:"POST",
            url: "actions/user/user_a.php",
	    data: {'action':action},   		  
            success: function(html){
                if(html=='1'){
                    window.location.href = base_url;
                }
            }
        });
    });	
			
       
		          
});
