  
  var __rduiInit = new Array();
  var __rageDynamicUploadInputProcessor = '?dyn,articleFiles:processor';
  
  __rduiInit['URL_MAKER'] = function(){ return __rageDynamicUploadInputProcessor; };
  __rduiInit['ON_SUCCESS'] = function(XmlHttp){
     var __t = XmlHttp.responseText.split('#&*$');
     switch(__t[0]){ //action
        case 'GET_NEW_UPLOAD_FIELD':
          //document.getElementById('additional_fields').innerHTML = __t[1];
          var elem = document.getElementById('__rdaf_uploadfields_'+__t[1]+'_'+__t[2]);
          var child = document.createElement('DIV');
          child.innerHTML = __t[3];
          elem.appendChild(child);
        	break;
       	case 'LOAD_FILE_OPTIONS_AREA':
          //document.getElementById('additional_fields').innerHTML = __t[1];
          //alert(XmlHttp.responseText);
          //__rdaf_options_rf4cd6d46a16e39_body_rta
          var elem = document.getElementById('__rdaf_options_'+__t[1]+'_'+__t[2]);
          //alert('__rdaf_options_'+__t[1]+'_'+__t[2]);
          elem.innerHTML = __t[3];
          __rdaf_openTab('options', __t[1], __t[2]);
        	break;
   	    case 'DELETE_ARTICLE_FILE':
          //rv___rdaf_view_body_rta_rf4cd70b4681b35_container
          __rageViewController.getView('__rdaf_view_'+__t[2]+'_'+__t[1]).reload();
        	break;
        default:
     		  alert(XmlHttp.responseText);
     			break;
     }
  }
  
	var __rduiAjax = new __rageLib.rageAJAX(__rduiInit);
  //test.process();
  
	function __rduiCheckUploadStatus(form_id, file_id){
	  __rduiAjax.postParams = 'form_id='+form_id+
                            '&file_id='+file_id;
    __rduiAjax.process();
  }
  
  function __rdaf_openTab(tabName, form_id, field_key){
    var c = document.getElementById('__rdaf_tabscontent_'+form_id+'_'+field_key).childNodes;

    for(var i=0; i<c.length; i++){
      var e = c[i];
      if(e.tagName == 'DIV'){
        var t = e.id.split('_');
        var t_key = t[3];
 
        var tabElem = document.getElementById('__rdaf_tab_'+form_id+'_'+field_key+'_'+t_key);

        if(t_key != tabName){
          e.style.display = 'none';
          tabElem.className = 'rdafTab';
        }else{
          e.style.display = 'block';
          tabElem.className = 'rdafTab active';
        }
      }
    }
  }
  
  function __rdaf_AddNewUploadField(form_id, field_key){
	  __rduiAjax.postParams = 'request=GET_NEW_UPLOAD_FIELD'+
                            '&form_id='+encodeURIComponent(form_id)+
                            '&field_key='+encodeURIComponent(field_key);
    __rduiAjax.process();
  }
  
  function __rdaf_deleteFile(file_id, view_id, fname){
    if(confirm('Czy na pewno chcesz skasować ten plik?')){
  	  __rduiAjax.postParams = 'request=DELETE_ARTICLE_FILE'+
                              '&file_id='+encodeURIComponent(file_id)+
                              '&view_id='+encodeURIComponent(view_id)+
                              '&fname='+encodeURIComponent(fname);
      __rduiAjax.process();
    }
  }
  
  function __rduiOnSubmit(form_id, file_id){
    var fname = document.getElementById('rageDUI_frame_'+file_id).contentWindow.document.getElementById('file_'+file_id).value;
    //alert(document.getElementById('rageDUI_frame_'+form_id).contentWindow.document.getElementById());
    if(fname){
      __rduiStartUpload(form_id, file_id);
      return true;
    }else{
      return false; 
    }
  }

  function __rdaf_loadOptions(action, file_id, view_id, fname){
  	  __rduiAjax.postParams = 'request=LOAD_FILE_OPTIONS_AREA'+
  	                          '&action='+encodeURIComponent(action)+ 
                              '&file_id='+encodeURIComponent(file_id)+
                              '&view_id='+encodeURIComponent(view_id)+
                              '&fname='+encodeURIComponent(fname);
      __rduiAjax.process();
  }
  
  function __rduiSuccesfulUpload(p,form_id, file_id, field_key, inner_html){
    //alert(p);
    p.document.getElementById('file_substitute_area').innerHTML = inner_html;;
  	p.document.getElementById('body').style.backgroundColor = 'green';
  	//p.parent.__rXViewReload('rageSDBOFormImagesFor_'+field_key+'__SEPPP__'+form_id);
  }
  
  var __rduiFileLoadingIcon = '';
  
  function __rduiStartUpload(form_id, file_id){
	  document.getElementById('rageDUI_frame_'+file_id).contentWindow.document.getElementById('file_area').style.display = 'none';
  	document.getElementById('rageDUI_frame_'+file_id).contentWindow.document.getElementById('file_substitute_area').innerHTML 
      = "<img src='"+__rduiFileLoadingIcon+"' />" +document.getElementById('rageDUI_frame_'+file_id).contentWindow.document.getElementById('file_'+file_id).value + " [trwa wgrywanie]"; 
    document.getElementById('rageDUI_frame_'+file_id).contentWindow.document.getElementById('file_substitute_area').style.display = 'block';
  	
  	//__rduiCheckUploadStatus(form_id,file_id);
  }
	
	
	
	
