
/**
 * @author florin
 */
 
var editContent = function (index, baseUrl){
	
    var form = new Ext.FormPanel({
		baseCls: 'x-plain',
		url: baseUrl + '/save_dictio/',
		labelAlign: 'top',
		items: [{
			fieldLabel: 'Continutul intrebarii:',
			allowBlank: false,
			labelAlign: 'top',
			name: 'intrebare',
			id: 'intrebare-id',
			xtype:'htmleditor',
			anchor: '99%',
			height: 190
		}]
    });

    var window = new Ext.Window({
        title: 'Formular Editare continut intrebare',
        width: 600,
        height: 300,
        minWidth: 500,
        minHeight: 300,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,
        listeners: {
        	'show': {
        		fn: function (cmp){
        			Ext.Ajax.request({
						url: baseUrl + '/load_content_intrebare/' + index,
						method: 'POST',
	            		success: function (res, op){
							var rez = Ext.decode(res.responseText);
							if(rez['response']!="failed"){
								Ext.getCmp('intrebare-id').setValue(rez['response']);	
							}
						}
					});	
        		},scope: this
        	}
        },
        buttons: [{
            text: 'Salveaza',
            handler: function (){
            	var val = Ext.getCmp('intrebare-id').getValue();
            	if(val.length>15){
	            	Ext.Ajax.request({
						url: baseUrl + '/edit_intrebare',
						method: 'POST',
						params: {
							id: index,
							intrebare: val
						},
		        		success: function (res, op){
		        			window.close();
		        			my_Post('http://www.telemed.ro/index.php/ajax.html','intrebari_tip','total_pagenr_elements');
						}
					});
            	}else{
            		Ext.MessageBox.alert('Eroare', 'Completati continutul intrebarii corespunzator !');
            	}
            }
        },{
            text: 'Inchide',
            handler: function (){
	            window.close();
            }
        }]
    });

    window.show();
    
    return;
	
}


var addRaspuns = function (index, baseUrl, docId){
	
    var form = new Ext.FormPanel({
		baseCls: 'x-plain',
		url: baseUrl + '/add_raspuns/',
		labelAlign: 'top',
		items: [{
			fieldLabel: 'Adauga raspuns:',
			allowBlank: false,
			labelAlign: 'top',
			name: 'raspuns',
			id: 'raspuns-id',
			xtype:'htmleditor',
			anchor: '99%',
			height: 190
		}]
    });

    var window = new Ext.Window({
        title: 'Formular Adaugare raspuns',
        width: 600,
        height: 300,
        minWidth: 500,
        minHeight: 300,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,
        buttons: [{
            text: 'Salveaza',
            handler: function (){
            	var val = Ext.getCmp('raspuns-id').getValue();
            	if(val.length>15){
	            	Ext.Ajax.request({
						url: baseUrl + '/add_raspuns',
						method: 'POST',
						params: {
							id: index,
							docid: docId,
							raspuns: val
						},
		        		success: function (res, op){
		        			window.close();
		        			my_Post('http://www.telemed.ro/index.php/ajax.html','intrebari_tip','total_pagenr_elements');
						}
					});
            	}else{
            		Ext.MessageBox.alert('Eroare', 'Completati continutul corespunzator !');
            	}
            }
        },{
            text: 'Inchide',
            handler: function (){
	            window.close();
            }
        }]
    });

    window.show();
    
    return;
	
}



var editRaspuns = function (index, baseUrl){
	
    var form = new Ext.FormPanel({
		baseCls: 'x-plain',
		url: baseUrl + '/edit_raspuns/',
		labelAlign: 'top',
		items: [{
			fieldLabel: 'Continutul raspunsului:',
			allowBlank: false,
			labelAlign: 'top',
			name: 'raspuns',
			id: 'raspuns-id',
			xtype:'htmleditor',
			anchor: '99%',
			height: 190
		}]
    });

    var window = new Ext.Window({
        title: 'Formular Editare raspuns',
        width: 600,
        height: 300,
        minWidth: 500,
        minHeight: 300,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,
        listeners: {
        	'show': {
        		fn: function (cmp){
        			Ext.Ajax.request({
						url: baseUrl + '/load_content_raspuns/' + index,
						method: 'POST',
	            		success: function (res, op){
							var rez = Ext.decode(res.responseText);
							if(rez['response']!="failed"){
								Ext.getCmp('raspuns-id').setValue(rez['response']);	
							}
						}
					});	
        		},scope: this
        	}
        },
        buttons: [{
            text: 'Salveaza',
            handler: function (){
            	var val = Ext.getCmp('raspuns-id').getValue();
            	if(val.length>15){
	            	Ext.Ajax.request({
						url: baseUrl + '/edit_raspuns',
						method: 'POST',
						params: {
							id: index,
							raspuns: val
						},
		        		success: function (res, op){
		        			window.close();
		        			my_Post('http://www.telemed.ro/index.php/ajax.html','intrebari_tip','total_pagenr_elements');
						}
					});
            	}else{
            		Ext.MessageBox.alert('Eroare', 'Completati continutul corespunzator !');
            	}
            }
        },{
            text: 'Inchide',
            handler: function (){
	            window.close();
            }
        }]
    });

    window.show();
    
    return;
	
}

function delRaspuns(index, baseUrl){
	Ext.MessageBox.confirm('Confirmare', 'Doriti sa stergeti aceast raspuns ?', function (btn){
		if(btn=='yes'){
			Ext.Ajax.request({
				url: baseUrl + '/del_raspuns',
				method: 'POST',
				params: {
					id: index
				},
        		success: function (res, op){
					var rez = Ext.decode(res.responseText)
					if(!rez['error']){
						my_Post('http://www.telemed.ro/index.php/ajax.html','intrebari_tip','total_pagenr_elements');
						Ext.MessageBox.alert('Info', 'Raspunsul a fost sters !');
					}
				}
			});	
		}
	});
}

function delContent(index, baseUrl){
	Ext.MessageBox.confirm('Confirmare', 'Doriti sa stergeti aceasta intrebare?', function (btn){
		if(btn=='yes'){
			Ext.Ajax.request({
				url: baseUrl + '/del_content',
				method: 'POST',
				params: {
					id: index
				},
        		success: function (res, op){
					var rez = Ext.decode(res.responseText)
					if(!rez['error']){
						my_Post('http://www.telemed.ro/index.php/ajax.html','intrebari_tip','total_pagenr_elements');
						Ext.MessageBox.alert('Info', 'Intrebarea a fost stersa !');
					}
				}
			});	
		}
	});
}
