

function mentorsEdit(aID){
	$.post('mentors.php', { view: 'edit' , adviceid: aID } , function(data){
		newContext("MentorsEdit"+aID);
		$("#MentorsEdit"+aID).html(data);
	});
}

function mentorsDisBanDo(sTo){
	uID = $("#userid").attr('value');
	reason = $("#statusreason").attr('value');
	$.post('mentors.php', { act: sTo , userid: uID , statusreason: reason } , function(data){
		doneContext();
		$("#mentors").html(data);
	});
}

function mentorsApprove(uID){
	$.post('mentors.php', { act: 'approve_mentor' , userid: uID } , function(data){
		$("#mentors").html(data);
	});
}

function mentorsDecline(uID){
	$.post('mentors.php', { view: 'decline_mentor' , userid: uID } , function(data){
		newContext('mentorsDecline'+uID);
		$("#mentorsDecline"+uID).append(data);
	});
}

function mentorsBan(uID){
	$.post('mentors.php', { view: 'ban_mentor' , userid: uID } , function(data){
		newContext("#mentorsBan"+uID);
		$("#mentorsBan").append(data);
	});
}

function mentorsEnDis(sTo,uID){
	args = new Object();
	if(sTo == 'disable_mentor'){
		args.view = sTo;
	}else{
		args.act = sTo;
	}
	args.userid = uID;
	$.post('mentors.php', args , function(data){
		$("#mentors").html(data);
	});
}

function mentorsReload(){
	args = new Object();
	if(PerPage != ''){
		args.itemsperpage = PerPage;
	}
	if(PageNum != ''){
		args.pg = PageNum;
	}
	if(mStatus != ''){
		args.status = mStatus;
	}
	if(mUser != ''){
		args.username = mUser;
	}
	if(mDateRange == 'yes'){
		args.is_date_range = 'yes';
		args.date_range_start = mDateStart;
		args.date_range_end = mDateStop;
	}
	if(mSortBy != ''){
		args.sortby = mSortBy;
	}
	$.post('mentors.php', args , function(data){
		$("#mentors").html(data);
	});
}

function mentorsPage(pgN){
	PageNum = pgN;
	mentorsReload();
}

function mentorsPerPage(npPg){
	PerPage = npPg;
	// otherwise we will end up somewhere completely random ...
	PageNum = '';
	mentorsReload();
}

function mentorsSearch(){
	mStatus = $("#mStatus").val();
	mUser = $("#mUser").attr('value');
	mDateRange = $("input[name='is_date_range']:checked").val();
	if(mDateRange == "undefined"){
		mDateRange = "no";
	}
	if(mDateRange == "yes"){
		mDateStart = $("#date_range_start_form_field").attr('value');
		mDateStop = $("#date_range_end_form_field").attr('value');
	}
	// make sure to go back to the main page ..
	PageNum = '';
	mentorsReload();
}

function mentorsSortBy(field, direction){
	mSortBy = "ORDER BY " + field + ((direction == "Down")?" ASC":" DESC");
	mentorsReload();
}
