function assign_credits(class_name, section){

	//Setting all the necessary ids
	switch(section){
		case 1:
			section_id	= "available_section";
			modal_id	= "modalBoxAvailable";
			form_id		= "available_credit";
			break;
		case 2:
			section_id	= "not_started_section";
			modal_id	= "modalBoxNotStarted";
			form_id		= "not_started_credit";
			break;
		case 2.5:
			section_id	= "not_started_section";
			modal_id	= "modalBoxInProgress";
			form_id		= "in_progress_credit";
			break;	
		case 3:
			section_id	= "in_progress_section";
			modal_id	= "modalBoxInProgress";
			form_id		= "in_progress_credit";
			break;
		default:
			break;
	}
	
	//getting values for the form input fields....
	credit_ids = $("#"+ section_id +" tr." + class_name + " .creditids").text();
	
	//setting all the values for the form input fields...
	$("#" + form_id + " .frm_creditids").val(credit_ids);
	$("#" + form_id + " .frm_emails").text("");
	$("#" + form_id + " .frm_emails").val( $("#" + section_id + " tr." + class_name + " .given_to").text() );
	
	var supervisor_name = $("#" + section_id + " tr." + class_name + " .supervisor").text();
	supervisor_name = (supervisor_name != '' && supervisor_name != 'None') ? supervisor_name : $('#username').text(); 
	$("#" + form_id + " .frm_supervisor_email").val( supervisor_name );
	$("#" + form_id + " .frm_send_email").attr("checked", true);
	
	$("#" + modal_id).showModalBox();
	
	
	
	$("#" + form_id + " .frm_assign").click(function(){
		var text = $("#" + form_id).serializeArray();
		//disabling the button
		$("#" + form_id + " button").attr("disabled", "true");
		
		$.ajax({type	: "POST",
		   	url 	: "./manage_credits.php",
			data	: text,
			dataType: 'json',
			timeout : 59000,
			success	: callback_assign_credit,
			error	: err_assign_credit
		   });
	
	
	
	

	return false;	
	});
	
	
	
	$("#" + form_id + " .frm_cancel").click(function(){
		$("#" + modal_id).removeModalBox();
	});
	
	
	
	
	function callback_assign_credit(data, status){
	    //alert(data);
		if(data['errorcode'] == 'success' ){
			

			
			//putting newly retrieved divs...
			$("#available_section").after(data['available']);	
			$("#not_started_section").after(data['not_started']);
			$("#in_progress_section").after(data['in_progress']);
			
			
			//removing previous divs...
			$("#available_section").remove();
			$("#not_started_section").remove();
			$("#in_progress_section").remove();
			
			
			
			//parsing for the dojo binding..
			dojo.parser.parse(dojo.byId("available_section"));
			dojo.parser.parse(dojo.byId("not_started"));
			dojo.parser.parse(dojo.byId("in_progress"));
			
			$("#" + modal_id).removeModalBox();
		}else{
			var msg = data['errormsg'];
			msg = "Sorry there was a problem. Please try again \nPossible Error:\n" + msg;
			alert(msg);
		}
		
		$("#" + form_id + " button").removeAttr("disabled");
	}

	function err_assign_credit(xhr, reason, ex){
		alert(reason);
		$("#" + form_id + " button").removeAttr("disabled");
	}
	
	
	
	
	e.preventDefault();
	return false;
	
}
