Ext.BLANK_IMAGE_URL='/bats/ext-2.0/resources/images/default/s.gif';
Ext.SSL_SECURE_URL='/bats/ext-2.0/resources/images/default/s.gif';
Ext.ns("Highline");
Highline.Util = {};

Highline.Util.getTop=function()
{
    var p_frame=window;
    while (!p_frame.highlinetop)
        {
            p_frame=p_frame.parent;
        }
        return p_frame;
}

Highline.Util.showNA=function (val)
{
    return Ext.util.Format.defaultValue(val,'N/A');
};
Highline.Util.addCommas=function(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return Ext.util.Format.defaultValue(x1 + x2,'N/A');
} ;  
Highline.Util.validateNumberCommas=function(value){
        if (value.length > 0) {
            var regids=value.split(/[, ]/g);
            for (var i=0;i<regids.length;i++){
                if (isNaN( regids[i] )){
                                                    
                    return false;
                }
            }
        }
        return true;
    };

Ext.grid.CheckColumn = function(config){
    this.addEvents({
        click: true
    });
    Ext.grid.CheckColumn.superclass.constructor.call(this);
	
    Ext.apply(this, config, {
        init : function(grid){
	    this.grid = grid;
	    this.grid.on('render', function(){
	        var view = this.grid.getView();
	        view.mainBody.on('mousedown', this.onMouseDown, this);
	    }, this);
        },

        onMouseDown : function(e, t){
            if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
                e.stopEvent();
                var index = this.grid.getView().findRowIndex(t);
                var record = this.grid.store.getAt(index);
                record.set(this.dataIndex, !record.data[this.dataIndex]);
                this.fireEvent('click', this, e, record);
            }
        },

        renderer : function(v, p, record){
	    p.css += ' x-grid3-check-col-td'; 
	    return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
        }
    });
	
    if(!this.id){
        this.id = Ext.id();
    }
    this.renderer = this.renderer.createDelegate(this);
};


Ext.extend(Ext.grid.CheckColumn, Ext.util.Observable);   
  /**
    Created by: Michael Synovic
    on: 01/12/2003
   
    This is a Javascript implementation of the Java Hashtable object, 
	revisioned by Marco Bellocchi and Stefano Sambi
   
    Contructor(s):
     Ext.Hashtable
              Creates a new, empty hashtable
   
    Method(s):
     void clear()
              Clears this hashtable so that it contains no keys.
     boolean containsKey(String key)
              Tests if the specified object is a key in this hashtable.
     boolean containsValue(Object value)
              Returns true if this TI.Core.Hashtable maps one or more keys to this value.
     Object get(String key)
              Returns the value to which the specified key is mapped in this hashtable.
     boolean isEmpty()
              Tests if this hashtable maps no keys to values.
     Array keys()
              Returns an array of the keys in this hashtable.
     void put(String key, Object value)
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key)
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size()
              Returns the number of keys in this hashtable.
     String toString()
              Returns a string representation of this TI.Core.Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space).
     Array values()
              Returns a array view of the values contained in this TI.Core.Hashtable.
           
*/
/**
    Created by: Michael Synovic
    on: 01/12/2003
   
    This is a Javascript implementation of the Java TI.Core.Hashtable object.
   
    Contructor(s):
     TI.Core.Hashtable()
              Creates a new, empty hashtable
   
    Method(s):
     void clear()
              Clears this hashtable so that it contains no keys.
     boolean containsKey(String key)
              Tests if the specified object is a key in this hashtable.
     boolean containsValue(Object value)
              Returns true if this TI.Core.Hashtable maps one or more keys to this value.
     Object get(String key)
              Returns the value to which the specified key is mapped in this hashtable.
     boolean isEmpty()
              Tests if this hashtable maps no keys to values.
     Array keys()
              Returns an array of the keys in this hashtable.
     void put(String key, Object value)
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key)
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size()
              Returns the number of keys in this hashtable.
     String toString()
              Returns a string representation of this TI.Core.Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space).
     Array values()
              Returns a array view of the values contained in this TI.Core.Hashtable.
           
*/
Ext.Ajax.timeout=1200000;
Highline.Util.HttpProxy=Ext.extend(Ext.data.HttpProxy,{
    initComponent:function(){
        Ext.apply(this,
        {timeout:1200000}); 

        Highline.Util.HttpProxy.superclass.initComponent.apply(this,arguments);
    }
});
Ext.ux.Hashtable = function()
{
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    
    var items = {};
    var count = 0;
    //	serve per confrontare che non sia una proprieta nativa
	var testObject = {};


    /*=======Private methods for internal use only========*/

    function hashtable_clear(){
        items = {};
        count = 0;
    }

    function hashtable_containsKey(key){
        if (testObject[key]) {
			return false;
	    }
		return (items[key] != null);
    }

    function hashtable_containsValue(value){
        var a = getValueArray();
        for (var htIndex = 0; htIndex < a.length; htIndex++) {
            if (a[htIndex] == value) {
                return true;
            }
        }
        return false;     
    }

    function hashtable_get(key){
        if(key in items){
			return items[key];	//	object
		}
		return undefined;
    }

    function hashtable_isEmpty(){
        return (count == 0);
    }

    function hashtable_keys(){
        return getKeyArray();
    }

    function hashtable_put(key, value){
        if (key == null || value == null) {
            throw "NullPointerException {" + key + "},{" + value + "}";
        }else{
            var alreadyExists = (key in items);
		    items[key] = value;
		    if(!alreadyExists){
			    count++;
		    }
        }
    }

    function hashtable_remove(key){
		if(key in items && !testObject[key]){
			delete items[key];
			count--;
			return true;
		}
		return false;
    }

    function hashtable_size(){
       return count;
    }

    function hashtable_toString(){
        var result = '';
        var arrKeys = getKeyArray();
        for (var i = 0; i < arrKeys.length; i++)
        {     
            if (TI.Util.isNullOrUndefined(items[arrKeys[i]])){
                result += "{" + arrKeys[i] + "},{" + items[arrKeys[i]] + "}\n"; } 
        }
        return result;
    }

    function hashtable_values(){
        return getValueArray();
    }
    
    function getValueArray() {
        var a = [];
        for(var p in items){
		    if(!testObject[p]){
			    a.push(items[p]);
		    }
	    }
	    return a;
    }
    function getKeyArray() {
        var a = [];
        for(var p in items){
		    if(!testObject[p]){
			    a.push(p);
		    }
	    }
	    return a;
    }
};

Ext.Ajax.on("requestcomplete",function(conn,response,opts){

if (response.getResponseHeader.ERIGHTS && response.getResponseHeader.ERIGHTS.indexOf("LOGIN")!=-1)
    {
        location.reload();
    }
});

Ext.Ajax.on("requestexception",function(conn,response,opts){

Ext.Msg.alert("Error",  "There has been an error in requesting your data.  Please try your request again. <br/>"+
"If the error persists, please call support at 1-877-305-6657<br/>Error code "+response.status+" ("+response.statusText+")");
});

var tabkeymap=new Ext.KeyMap(document,[
{   key:188,
    alt:true,
      fn:function(){
           top.Highline.main.Util.previousTab();
         }
},
{   key:190,
    alt:true,
    fn:function(){
        top.Highline.main.Util.nextTab();
    }
}
]
);
    tabkeymap.stopEvent=true;



Highline.MatchCombo=Ext.extend(Ext.form.ComboBox,{
    initComponent:function(){
        Ext.apply(this);
        Highline.company.fullsearch.CompanyFullSearchItemsGrid.superclass.initComponent.apply(this,arguments);
    },
        doQuery : function(q, forceAll){
        if(q === undefined || q === null){
            q = '';
        }
        var qe = {
            query: q,
            forceAll: forceAll,
            combo: this,
            cancel:false
        };
        if(this.fireEvent('beforequery', qe)===false || qe.cancel){
            return false;
        }
        q = qe.query;
        forceAll = qe.forceAll;
        if(forceAll === true || (q.length >= this.minChars)){
            if(this.lastQuery !== q){
                this.lastQuery = q;
                if(this.mode == 'local'){
                    this.selectedIndex = -1;
                    if(forceAll){
                        this.store.clearFilter();
                    }else{
                this.anyMatch = this.anyMatch === undefined? false : this.anyMatch;
                this.caseSensitive = this.caseSensitive === undefined? false : this.caseSensitive;
                        this.store.filter(this.displayField, q, this.anyMatch, this.caseSensitive);
                    }
                    this.onLoad();
                }else{
                    this.store.baseParams[this.queryParam] = q;
                    this.store.load({
                        params: this.getParams(q)
                    });
                    this.expand();
                }
            }else{
                this.selectedIndex = -1;
                this.onLoad();
            }
        }
    }
 
});


Ext.apply(Ext.util.Format, {
	numberFormat: {
		decimalSeparator: '.',
		decimalPrecision: 2,
		groupingSeparator: ',',
		groupingSize: 3,
		currencySymbol: '$'
	},
	formatNumber: function(value, numberFormat) {
		var format = Ext.apply(Ext.apply({}, this.numberFormat), numberFormat);
		if (typeof value !== 'number') {
			value = String(value);
			if (format.currencySymbol) {
				value = value.replace(format.currencySymbol, '');
			}
			if (format.groupingSeparator) {
				value = value.replace(new RegExp(format.groupingSeparator, 'g'), '');
			}
			if (format.decimalSeparator !== '.') {
				value = value.replace(format.decimalSeparator, '.');
			}
			value = parseFloat(value);
		}
		var neg = value < 0;
		value = Math.abs(value).toFixed(format.decimalPrecision);
		var i = value.indexOf('.');
		if (i >= 0) {
			if (format.decimalSeparator !== '.') {
				value = value.slice(0, i) + format.decimalSeparator + value.slice(i + 1);
			}
		} else {
			i = value.length;
		}
		if (format.groupingSeparator) {
			while (i > format.groupingSize) {
				i -= format.groupingSize;
				value = value.slice(0, i) + format.groupingSeparator + value.slice(i);
			}
		}
		if (format.currencySymbol) {
			value = format.currencySymbol + value;
		}
		if (neg) {
			value = '-' + value;
		}
		return value;
	}
});

Ext.ns('Ext.ux.layout');


Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
	// private
    setItemSize : function(item, size){
        this.container.addClass('ux-layout-center');
        item.addClass('ux-layout-center-item');
        if(item && size.height > 0){
            if(item.width){
                size.width = item.width;
            }
            item.setSize(size);
        }
    }
});
Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;


String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str);};
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str);};
String.prototype.trim = function(){return
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));};
