function InitMyLanguagesPane( id , datas ) {
	var o = $("#"+id);
	o.data( "datas" , datas );
	$("#"+id+"_selected_languages").sortable(
		{
			cancel: '.ui-not-sortable',
			connectWith: ".sortable",
			tolerance: 'pointer'
		}
	).disableSelection();
	$("#"+id+"_unselected_languages").sortable(
		{
			cancel: '.ui-not-sortable',
			connectWith: ".sortable",
			update: function(e,ui) { UpdateUnselectedLanguages( id , e , ui ); }
		}
	).disableSelection();

	$(document.frm_my_languages).data("id",id);
	FormChangeWarning( document.frm_my_languages , FormWarningMyLanguagesCallback );
}

function FormWarningMyLanguagesCallback( oF , formdata ) {
	formdata["retval"] = GetMyLanguages( $(oF).data( "id" ) );
	return formdata;
}

function GetMyLanguages( id ) {
	var sels = $("#"+id+"_selected_languages li");
	var i = 0;
	var retval = "";
	for (i=0;i<sels.length;i++) {
		var lid = sels[i].id;
		var lang_id = lid.substring( 5 );
		if (retval.length) retval+=",";
		retval+=lang_id;
	}
	return retval;
}

function ValidateMyLanguagesSubmit( id , oF ) {
	var datas = $("#"+id).data( "datas" );
	if (typeof datas.parttime != "undefined") {
		alert( aJSLangDefs.myprofilepage_Parttime_cannot_change_languages );
		return false;
	}
	var inp = $("#"+id+"_retval");
	inp.val( GetMyLanguages( id ) );
	ClearFormDirty( oF );
	return true;
}

function ClearAllLanguages( id ) {
	$("#"+id+"_unselected_languages").append( $("#"+id+"_selected_languages li" ) );
	$("#"+id+"_selected_languages").html("");
}

function AddAllLanguages( id ) {
	var o = $("#"+id);
	var datas = o.data( "datas" );
	var numofusedlanguages = $("#"+id+"_selected_languages li").length;
	var freespace = datas.available_languages - numofusedlanguages;
	var numofunusedlanguages = $("#"+id+"_unselected_languages li").length;
	if (numofunusedlanguages>freespace) {
		alert( aJSLangDefs.myprofilepage_Error_too_much_languages );
		return;
	}
	$("#"+id+"_selected_languages").append( $("#"+id+"_unselected_languages li" ) );
	$("#"+id+"_unselected_languages").html("");
}

function UpdateUnselectedLanguages( id , e , ui ) {
	var o = $("#"+id);
	var datas = o.data( "datas" );
	var numofusedlanguages = $("#"+id+"_selected_languages li").length;
	if (numofusedlanguages>=datas.available_languages) {
		$("#"+id+"_unselected_languages li").addClass( "ui-not-sortable" );
	} else {
		$("#"+id+"_unselected_languages li").removeClass( "ui-not-sortable" );
	}
}
