
var currentRating = 0;
var currentElearning = 0;

function changeRatingV2(id, cla) {
	
	sRat = new Array();
	
	currentRating = id;
	
	sRat[1] = getLanguageText('estimation.class.'+cla+'.rating1');
	sRat[2] = getLanguageText('estimation.class.'+cla+'.rating2');
	sRat[3] = getLanguageText('estimation.class.'+cla+'.rating3');
	sRat[4] = getLanguageText('estimation.class.'+cla+'.rating4');
	sRat[5] = getLanguageText('estimation.class.'+cla+'.rating5');
	
	for(i=1; i<=5; i++) {

		if(i <= id) {
			document.getElementById("ratingstar" + i).src = "/img/icons/ico_stern_voll_10x9.gif";
		}
		else {
			document.getElementById("ratingstar" + i).src = "/img/icons/ico_stern_leer_10x9.gif";
		}
	}
	
	document.getElementById("ratingtext").innerHTML = sRat[id];

}

function addPostCommentV2 (pk, clas) {
	
	if(!(currentRating >= 1 && currentRating <= 5) && !Ext.getCmp('estText').getValue().length)
		Ext.Msg.alert(getLanguageText('defaults.error'), getLanguageText('estimation.error.rating'))
	else
		if(Ext.getCmp('fEstimationField').getForm().isValid())
		{
		
			Ext.Ajax.request({
				url: '/index.cfm?event=estimation.postcomment',
				params: {
					pk: pk,
					clas: clas,
					rating: currentRating,
					desc: Ext.getCmp('estText').getValue()
				},
				method: 'POST',
				success: function(result, request){
					Ext.Msg.alert(getLanguageText('defaults.hint.thankyou'), getLanguageText('estimation.addsuccess'), function() { location.reload(); })
					
				},
				failure: function(result, request){
					return false;
				}
			});
		}
	
}

function renderDescFieldV2 (maxChars) {
	
	frmWindowConfirm = new Ext.FormPanel({
		id: 'fEstimationField',		
		renderTo: 'txtfield',
		items: [ 
			new Ext.form.TextArea({
		    	width:510,
				height: 100,
				hideLabel: true,
				allowBlank: true,
				id: 'estText',
				cls: 'reason-input',
				validateOnBlur: true,
				msgTarget: 'under',						
				maxLength: maxChars,
				enableKeyEvents: true				
		    })
		]
	});
	
	Ext.getCmp('estText').on('keyup', function() {		
		countTextareaCharsV2(maxChars, Ext.getCmp('estText').getValue());
	});
	
}

function countTextareaCharsV2(max,svalue) {

 svalue = svalue.substring(0,max);
 anz = svalue.length;
 document.getElementById('leftChars').innerHTML = max - anz;

  
}
