Ext.namespace('posap');

posap.app = function() {
	return {
		init: function() {
			Ext.QuickTips.init();
		},
		
		getCommentForm: function(id, idComment, idRef){

		  Ext.Ajax.request({
		    url: '/scripts/actions.php',
		    success: function(r){
		      if(res = decodeResult(r)){
			        if(!res.error){
			        	commentPanel = new Ext.Panel({renderTo:idComment});
			        	Ext.DomHelper.overwrite(commentPanel, res.info);
			        }
		      }
		    },
		    params: { action: 'get-comment-form', id: id, idComment: idComment }
		  });  			

		
		}
		
	}
}();


function pos_FormatMoney(v){
            v = (Math.round((v-0)*100))/100;
            v = (v == Math.floor(v)) ? v + "" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
            v = String(v);
            var ps = v.split('.');
            var whole = ps[0];
            var sub = ps[1] ? '.'+ ps[1] : '';
            var r = /(\d+)(\d{3})/;
            while (r.test(whole)) {
                whole = whole.replace(r, '$1' + ' ' + '$2');
            }
            v = whole + sub;
            if(v.charAt(0) == '-'){
                return '-' + v.substr(1);
            }
            return "" +  v;
}

function waitStart(message, id){
  var par = id?Ext.get(id):Ext.getBody();
  par.mask(message?message:'Секундочку...', 'x-mask-loading');
}
function waitStop(id){
  var par = id?Ext.get(id):Ext.getBody();
  par.unmask()
}

function decodeResult(res){
  if((res.responseText+"").length>3){
    return(Ext.decode(res.responseText+""));
  }
}

