var cmn = 
{ 
    msg : 
    {
        INFO :
        {
            LOGIN_SUCCESS  : "INFO: [{D}] %user% was authorized successfully. "
        },
        WARNING :
        {
            DELETE_CONFIRM : "Are you sure need to delete this record?",
            CANCEL_UPDATE_CONFIRM : "Editing record was not saved. Are you sure need to cancel current edit?",
            LOGOFF_CONFIRM : "Are you sure need to log off?"
        },
        ERROR :
        {
            NO_CONNECTION : "ERROR: No connection to the server.",
            NO_FOUNDED    : "ERROR: No element(s) with such ID was founded: ",
            NO_ARGUMENTS  : "ERROR: Missing argument(s).",
            NO_PARAMETERS : "ERROR: Missing parameter(s).",
            NO_CONTROLS   : "ERROR: Missing control(s)."
        },
        VALIDATOR :
        {
            FIELD_NOT_FILLED : "VALIDATOR: %field% field not filled!",
            OPTION_NOT_SET   : "VALIDATOR: %option% option not set!"
        }
    },
    checks : 
    {
        isObjectExist : function( obj ){ return ( obj && ( typeof obj != "undefined" ) ); },
        isNumberValue : function( event )
        {
            var key;
            if ( window.event ) key = window.event.keyCode;
            else if ( event ) key = event.which;
            else return true;
            if ( key == null || key == 0 || key == 8 || key == 13 || key == 27 ) return true;
            var keyChar = String.fromCharCode( key );
            if ( /\d|\|/.test( keyChar ) ) return true;
            else return false;
        }
    },
    gets :
    {
        getElementByPartIdAndTagName : function( idPart, tagName, parentElement )
        {
            if ( cmn.checks.isObjectExist( idPart ) && cmn.checks.isObjectExist( tagName ) )
            {
                var tmp = cmn.checks.isObjectExist( parentElement ) ? parentElement : document;
                tmp = tmp.getElementsByTagName( tagName );
                for ( var i = 0; i < tmp.length; i++ )
                {
                    if ( tmp[i].id && ( tmp[i].id.indexOf( idPart ) > -1 ) ) return tmp[i];
                }
            }
            return null;
        }
    },
    string : 
    {
        trim : function( str ){ return str.replace(/^\s+/, '').replace(/\s+$/, '');}
    },
    validator :
    {
        isEmpty : function( object )
        {
            if ( cmn.checks.isObjectExist( object ) && object.value )
            {
                if( cmn.string.trim( object.value ).length > 0 ) return true;
                return false;
            }
        },
        isSelected : function( object )
        {
            if ( cmn.checks.isObjectExist( object ) )
            {
                if ( object.options && object.options.length > 0 )
                {
                    if ( object.options.selectedIndex == 0 ) return true;
                }
            }
            return false;
        }
    },
    net :
    {
        READY_STATE_UNINITIALIZED : 0,
        READY_STATE_LOADING       : 1,
        READY_STATE_LOADED        : 2,
        READY_STATE_INTERACTIVE   : 3,
        READY_STATE_COMPLETE      : 4,
        ContentLoader : function( url, onload, onerror, method, params, contentType )
        {
            this.req      = null;
            this.onload   = onload ? onload : alert("no onload");
          
            this.defaultError = function()
            {
                alert( "Error fetching data!\n\n"
                + "ReadyState:" + this.req.readyState
                + "\nStatus: " + this.req.status
                + "\nHeaders: " + this.req.getAllResponseHeaders() );
            };
            this.onerror  = ( onerror != null ) ? onerror : this.defaultError;
            this.loadXMLDoc = function( url, method, params, contentType )
            {
                if ( !method ) method = "GET";
                if ( !contentType && method == "POST" ) contentType = 'application/x-www-form-urlencoded';
                if (window.XMLHttpRequest) this.req = new XMLHttpRequest();
                else if ( window.ActiveXObject ) this.req = new ActiveXObject( "Microsoft.XMLHTTP" );
                if ( this.req )
                {
                    try
                    {
                        var loader = this;
                        this.req.onreadystatechange = function()
                        {
                            cmn.net.ContentLoader.onReadyState.call( loader );
                        }
                        this.req.open( method, url, true );
                        if ( contentType ) this.req.setRequestHeader( 'Content-Type', contentType );
                        this.req.send( params );
                    }
                    catch ( err )
                    {
                        this.onerror.call( this );
                    }
                }
            };
            this.loadXMLDoc( url, method, params, contentType );
        }
    },
    date :
    {
        getHHMM : function()
        {
            var tmp = new Date(), tmpH = tmp.getHours(), tmpM = tmp.getMinutes();
            return ( ( ( tmpH < 10 ) ? '0' + tmpH : tmpH ) + ':' + ( ( tmpM < 10 ) ? '0' + tmpM : tmpM ) );
        }
    }
};
cmn.net.ContentLoader.onReadyState = function()
{
    var req         = this.req;
    var ready       = req.readyState;
    var httpStatus  = null;
    
    try {httpStatus = req.status;}
    catch(e){}
    
    if ( ready == cmn.net.READY_STATE_COMPLETE )
    {
        try {
            if ( httpStatus == 200 || httpStatus == 0 )
            {
            if (this.onload != null)
                this.onload.call( this );
            }
            else this.onerror.call( this );
        }
        catch(e){
            alert( "An error has occured during procesing... " + e.message );
        }
    }
}