function MultiLangPairAddLangPair( id ) {
	var d = $("#"+id+"_body" );
	var i = d.data("numoflanguages" );
		
	var trnew = $("<div></div>").attr( "class" , "row" ).attr( "id" , id + "_row_" + i );

	var tdsrclang = $("<div></div>").attr( "class" , "srcl" ).append( MultiLangMakeLangSelect( id + "_srclang_"+i ,0 ) );
	var tdsep = $("<div></div>").addClass( "sep" ).html("-");

	var tddstlang = $("<div></div>").attr( "class" , "dstl" ).append( MultiLangMakeLangSelect( id + "_dstlang_"+i , 0 ) );

	var tdinp = $("<div></div>" ).addClass( "inp" );
	var iinp = $("<input></input>").attr( "type" , "button" ).attr( "id" , id + "_rowbtn_" + i ).addClass( "minismb" ).data("parent",id).data("rownum",i).attr( "value" , aJSLangDefs.Delete_languagepair );
	iinp.click( function() { MultiLangPairDelLang( $(this ) ); } );

	tdinp.append( iinp );

	var tdclr = $("<div></div>" ).addClass( "clr" );

	trnew.append( tdsrclang );
	trnew.append( tdsep );	
	trnew.append( tddstlang );
	trnew.append( tdinp );
	trnew.append( tdclr );

	if (jQuery.browser.mozilla) trnew.css( "display" , "none" );
	d.append( trnew );
	if (jQuery.browser.mozilla) trnew.fadeIn("slow");
	d.data("numoflanguages",i+1);
}

function MultiLangPairDelLang( obj ) {
	var id = $(obj).data("parent");
	var n = $(obj).data("rownum");
	
	var trold = $("#" + id + "_row_" + n );
	var d = $("#"+id+"_body" );
	var maxlang = d.data("numoflanguages" );
	trold.remove();
	var x = n;
	x++;
	while (x<maxlang) {
		$("#" + id + "_row_" + x ).attr( "id" , id + "_row_" + (x-1) );
		$("#" + id + "_rowbtn_" + x ).attr( "id" , id + "_rowbtn_" + (x-1) ).data( "rownum" , (x-1) );
		$("#" + id + "_srclang_" + x).attr( "id" , id + "_srclang_" + (x-1) ).attr( "name" , id + "_srclang_" + (x-1) );
		$("#" + id + "_dstlang_" + x).attr( "id" , id + "_dstlang_" + (x-1) ).attr( "name" , id + "_dstlang_" + (x-1) );
		x++;
	}
	d.data( "numoflanguages" , maxlang - 1 );
}

function MultiLangMakeLangSelect( n , s ) {
	var x = $("<select></select>" ).addClass( "multilangsel" ).attr( "name" , n ).attr( "id" , n );
	var i;
	for (i=0;i<aLangs.length;i++)
		x.append( $("<option></option>").attr( "value" , aLangs[i][0] ).html( aLangs[i][1] ) );
	x.val( s );
	return x;
}

function MultiLangPairInit( id , a ) {
	var i;	
	var d = $("#"+id+"_body" );
	d.data( "numoflanguages" , a.length );

	for (i=0;i<a.length;i++) {
		var trnew = $("<div></div>");
		trnew.attr( "class" , "row" );
		trnew.attr( "id" , id + "_row_" + i );

		var tdsrclang = $("<div></div>");
		tdsrclang.attr( "class" , "srcl" );
		tdsrclang.append( MultiLangMakeLangSelect( id + "_srclang_" + i , a[i]["source_language_id"] ) );

		var tdsep = $("<div>-</div>");
		tdsep.attr( "class" , "sep" );

		var tddstlang = $("<div></div>");
		tddstlang.attr( "class" , "dstl" );
		tddstlang.append( MultiLangMakeLangSelect( id + "_dstlang_" + i , a[i]["target_language_id"] ) );

		var tdinp = $("<div></div>" ).addClass( "inp" );

		var iinp = $("<input></input>").attr( "type" , "button" ).attr( "id" , id + "_rowbtn_" + i ).addClass( "minismb" ).data( "parent" , id ).data( "rownum" , i ).attr( "value" , aJSLangDefs.Delete_languagepair );
		iinp.click( function() { MultiLangPairDelLang( $(this ) ); } );

		tdinp.append( iinp );

		var tdclr = $("<div></div>" ).addClass( "clr" );

		trnew.append( tdsrclang );
		trnew.append( tdsep );	
		trnew.append( tddstlang );
		trnew.append( tdinp );
		trnew.append( tdclr );

		d.append( trnew );
	}
}
