/*
 *  UTILERIAS
 */

function saveBita(url)
{
    var aja = new Ajax('procesos.php',
    { 
        'method'        :   'get',
        'encoding'      :   'iso-8859-1',
        'data'          :   {
                                'action'    :   'saveBita', 
                                'url'       :   url
                            }, 
        'onComplete'    :   function()
                            {
                                $('mainContainer').src = url;
                            }
        
    }).request();
}

function ajustaInterface()
{
    var winW = window.ie ? ( document.body.offsetWidth - 25 ): ( window.innerWidth - 25 );
    var winH = window.ie ? document.body.offsetHeight : ( window.innerHeight - 10 );
    var newWidth = winW - $( 'mainMenu' ).getStyle('width').toInt();
    var newHeight= winH - $( 'mainHeader' ).getStyle('height').toInt();
    
    $( 'mainContainer' ).style.width = newWidth;
    $( 'mainContainer' ).style.height= newHeight;
    $( 'mainMenu' ).style.height= newHeight;
   // $( 'debug' ).innerHTML = "Width :" + newWidth + "px height : " + newHeight + "px";
}
function getSelectionStart(o) {
	if (o.createTextRange) {
		var r = document.selection.createRange().duplicate()
		r.moveEnd('character', o.value.length)
		if (r.text == '') return o.value.length
		return o.value.lastIndexOf(r.text)
	} else return o.selectionStart
}

function getSelectionEnd(o) {
	if (o.createTextRange) {
		var r = document.selection.createRange().duplicate()
		r.moveStart('character', -o.value.length)
		return r.text.length
	} else return o.selectionEnd
}

var activeCtrl = false;

function changeCell( evnt, el, maxCols, maxRows )
{
    code = ( window.ie ? evnt.keyCode : evnt.which );
    var pos = getSelectionStart( el );
    var id = el.id.split( '-' );
    var pre = id[0];
    var col = parseInt( id[ 1 ] );
    var row = parseInt( id[ 2 ] );

    if( code == 37 )
    {
        if( pos  == 0 )
        {
            if( col == 0 && row == 0 )
            {
                return false;
            }
            else
            {
                if( col == 0 )
                {
                    $( pre + '-' + maxCols + '-' + ( row - 1 ) ).focus();
                }
                else
                {
                    $( pre + '-' + ( col - 1 ) + '-' + row ).focus();
                }
            }
        }
    }
    else if ( code == 39 || code == 13 )
    {
        if( pos == el.value.length )
        {
            if( col == maxCols && row == maxRows )
            {
                return false;
            }
            else
            {
                if( col == maxCols )
                {
                    $( pre + '-0-' + ( row + 1 ) ).focus();
                }
                else
                {
                    $( pre + '-' + ( col + 1 ) + '-' + row ).focus();
                }
            }
        }
    }
    else if( code == 38 )
    {
        if( row > 0 )
        {
            $( pre + '-' + col + '-' + ( row - 1 ) ).focus();
        }
    }
    else if( code == 40 )
    {
        if( row < maxRows )
        {
            $( pre + '-' + col + '-' + ( row + 1 ) ).focus();
        }
    }
    else if( code == 36 )
    {
        if( activeCtrl )
        {
            $( pre + '-0-0' ).focus();
            activeCtrl = false;
        }
        else
        {
            $( pre + '-0-' + row).focus();
        }
    }
    else if( code == 35 )
    {
        if( activeCtrl )
        {
            $( pre + '-' + maxCols + '-' + maxRows ).focus();
            activeCtrl = false;
        }
        else
        {
            $( pre + '-' + maxCols + '-' + row ).focus();
        }
    }
    else if( code == 17 )
    {
        activeCtrl = true;
    }
    else
    {
        activeCtrl = false;
        //alert( code );
    }
}

function scrollTable( el )
{
    X = el.scrollLeft;
    Y = el.scrollTop;
    $( 'headerDiv' ).scrollTo( X, 0 );
    $( 'leftDiv' ).scrollTo(0, Y );
}

function combo( obj )
{
    var url =   "elementos.php?elemento=combo";

    for( var o in obj )
    {
       url += "&" + o + "=" + obj[ o ];
    }
    var myAjax = new Ajax( url,
        {
            method  :   'get',
            encoding  :'iso-8859-1',
            update  :   $( obj.div ),
            onComplete : function()
            {
                //preLoader(0);
            }
        }
    ).request();
}


/*
 *  PRINT_R  como el de php pero para los arreglos esta haciendo algo raro por el momento
 *  solo esta funcionnando bien con los objetos
*/
function print_r( Obj )
{
    var string = "";
    var nivel = arguments[1] ? parseInt( arguments[1] ) : 0;
    var tabs = "";
    for( var i = 0; i < parseInt( nivel ); i++ )
    {
        tabs += "\t";
    }
    if( Obj.constructor == Array ||
        Obj.constructor == Object)
    {
        string += typeof( Obj ) + "\n" + tabs +"(\n";
        for( var p in Obj)
        {
            if( Obj[p].constructor == Array ||
                Obj[p].constructor == Object )
            {
                string +=   tabs + "\t[" + p + "] => " +
                            print_r( Obj[ p ], ( nivel + 1 ) ) ;
            } else {
                string += tabs + "\t[" + p + "] => " + Obj[ p ] + "\n";
            }
        }
        string += tabs + ")\n";
    }
    return string;
      
}

function numericInput( evnt, el )
{
    code = ( window.ie ? evnt.keyCode : evnt.which );
    if( ( code >= 48 && code <= 57 ) ||
        ( code >= 96 && code <= 105 ) || 
        ( code >= 33 && code <= 39 ) || 
        code == 8 || code == 9 || code == 46
    )
    {
        return true;
    }
    return false;
}

/**
* Campo numerico 
* Solo permite la captura de numeros
*/
function numerico( evnt, id )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    if(
        (   code >= 48 && code <= 57 ) ||
            code == 8 || code == 0 || code == 13
        )
        {
            return true;
        }
        return false;
}

function decimal( evnt, value, dec )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    if( (   code >= 48 && code <= 57 ) ||
            code == 8 || code == 0 || code == 13 ||
        ( code == 46 && value.indexOf( '.' ) < 0 )
      )
      {
      if( value.indexOf( '.' ) > 0 && code != 8 && code != 0 )
      {
            var tmp = value.split( '.' );
            if( tmp[1].length < dec )
            {
                return true;
            }
            return false;
      }
      return true;
      }
      return false;
}

function nextInput( ev, id )
{
    code = ( window.ie ? ev.keyCode : ev.which )

    if( code == 13 )
    {
        $( id ).focus();
        return true;
    }
}
/*
function preLoader( showHide )
{
    var cId = "tdContainer";
    var pId = "preloader";

    if( showHide == 'show' || showHide == 1 )
    {
        var display = 'inline';
        if( arguments[1] )
        {
            cId = arguments[1]
        }
        $( pId ).style.top      = $( cId ).getPosition().y ;
        $( pId ).style.left     = $( cId ).getPosition().x ;
        $( "preloaderTable" ).style.width    = $( cId ).getStyle('width').toInt();//$( cId ).style.width;
        $( "preloaderTable" ).style.height   = $( cId ).getStyle('height').toInt();//$( cId ).style.height;
        $( pId ).style.display = display;
    }
    else
    {
        var display = 'none';
       // $( pId ).style.display = display;
        return fadeOut( $( pId ) );
    }
    
}
*/

function fadeOut( box )
{
    var duracion = ( arguments[1] ? arguments[1] : 700 );
    var fx = box.effects({duration: duracion, transition: Fx.Transitions.Quart.easeOut});
    /* AJAX Request here... */
    
    fx.start(
        {
        }).chain(function()
            {
                this.start.delay(100, this,
                    {'opacity' : 0
                    });
            }).chain(function()
            {
                box.style.display="none";
                this.start.delay(50, this, {'opacity' : 1});
            });
    return true;
            // $( 'loader' ).style.display = 'none';
}

function cargaTab( idTab, idContainer, idContent )
{
    preLoader(1, ( $('tabContainer') ? 'tabContainer' : idContainer ));
    var url =   "funciones.php?action=getTabs" + 
                "&idTab=" + idTab +
                "&idContent=" + idContent +
                "&idContainer=" + idContainer;
    var myAjax = new Ajax( url,
        {
            method  :   'get',
            encoding  :'iso-8859-1',
            update  :   $( idContainer ),
            onComplete : function()
            {
                preLoader(0);
            }
        }
    ).request();

}

function imgSection( seccion )
{
    var url = "procesos.php?action=imgSection&seccion=" + seccion;
    var request = new Json.Remote(url, 
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    $( 'seccionTitulo' ).innerHTML = obj.pathImg;
                    correctPNG();
                }
            }
        }
    ).send();
}
function goTo( action )
{
    if( action == 'logout' )
    {
        logout();
    }
    else
    {
        if( action == 'users_pannel' )
        {   
            include( 'js/user.gestion.js',{'cache':false,'dom':true} );
        }
        if( action == 'clients_pannel' )
        {
            include( 'js/client.gestion.js',{'cache':false,'dom':true} );
        }

        preLoader(1 ,( arguments[1] ? arguments[1] : 'mainContainer' ) );
        imgSection( action );
        var url = "procesos.php?action=" + action;
        var myAjax = new Ajax( url,
            {
                method  :   'get',
                encoding  :'iso-8859-1',
                update  :   $(( arguments[1] ? arguments[1] : 'mainContainer' )),
                onComplete  :   function()
                {
                    preLoader(0);
                    if( action == 'interface_setup' )
                    {
                        goTo( 'menu_interface_setup', 'mainMenu' );
                    }
                    if( action == 'index' )
                    {
                        goTo( 'index_menu', 'mainMenu' );
                    }
                    if( action == 'menu_interface_setup' )
                    {
                        makeDraggableComponents();
                    }
                    if( action == 'clients_pannel' )
                    {
                        setTimeout( "startSlider( 50,'area')" , 1000 );
                        setTimeout( "startSliderTabla({'id':'area2','idTabla':'segDiv','idContent':'sliderContent'} )" , 1000 );
                        setTimeout( "startSliderTabla({'id':'area3','idTabla':'segDiv','idContent':'sliderContent','mode':'vertical'} )" , 1000 );
                    }
                }
            }
        ).request();
    }
}

function startSliderTabla( obj ) // startIn, id, idTabla, idContent )
{
    var mySlide = new Slider(
        $( obj.id ),
        $( obj.id + 'knob'),
        {
            steps:  (   obj.mode == 'vertical'
                    ?   $( obj.idContent ).getStyle('height').toInt() - $( obj.idTabla ).getStyle('height').toInt()  
                    :   $( obj.idContent ).getStyle('width').toInt() - $( obj.idTabla ).getStyle('width').toInt()
                    ),
            mode : ( obj.mode ? obj.mode : 'horizontal' ),
            onChange: function( step )
            {
                if( obj.mode == 'vertical' )
                {
                    $( obj.idTabla ).scrollTo( $( obj.idTabla).scrollLeft, step);
                }
                else
                {
                    $( obj.idTabla ).scrollTo(step,$( obj.idTabla ).scrollTop);
                }
            }
        }
    ).set( ( obj.startIn ? obj.startIn : 0 ) );
}                  
function getCombo( id, obj_table, obj_value, obj_text, obj_selected, obj_where )
{
    var url =   "funciones.php?action=getCombo" + 
                "&id_container=" + id +
                "&obj_table=" + obj_table +
                "&obj_value=" + obj_value +
                "&obj_text=" + obj_text +
                "&obj_selected=" + obj_selected + 
                "&obj_where=" + obj_where;

    $( id ).length = 0;
    add_option( id, 'Seleccione una opcion', '' );
    var request = new Json.Remote(
        url,
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    for( var i = 0; i < obj.rs.length; i++ )
                    {
                       add_option( obj.id_container, obj.rs[i].optionText, obj.rs[i].optionValue );
                    }
                }
            }
        }
    ).send();
}

function add_option(id,txt,val)
{
    var newOption = new Element('option',{});
    if( window.ie )
    {
        newOption.innerText = txt;
    }
    else
    {
        newOption.text = txt;
    }
    newOption.value = val;
    newOption.selected = arguments[3];
    newOption.inject( id );
}

function moveToCenter( id )
{
    winW = window.ie ? document.body.offsetWidth : window.innerWidth;
    winH = window.ie ? document.body.offsetHeight : window.innerHeight;

    var sizeW   =   ( $( id ).style.width  ? ( parseFloat( $( id ).style.width.replace('px','') ) / 2 ) : 1 );
    var sizeH   =   ( $( id ).style.height ? ( parseFloat( $( id ).style.height.replace('px','')) / 2 ) : 1 );
    var elLeft  =   ( ( winW / 2 ) - sizeW ) + 'px';
    var elTop   =   ( ( winH / 2 ) - sizeH ) + 'px';

    $( id ).setStyles(
        {
         position   :   'absolute',
         left       :   elLeft,
         top        :   elTop   
        }
       );
    
}
currentZIndex = 1;
function showOver(id )
{
    currentZIndex++;
    $( id ).style.zIndex = currentZIndex;
}
function changePosition( obj )
{
    var TopPos  =   $( obj ).getPosition().y;
    var LeftPos =   $( obj ).getPosition().x;
}
function draggableElement( id )
{
    showOver(id);
    $( id ).makeDraggable(
        {
            'container' : $('mainContainer'),
            onComplete : function()
            {
                
                changePosition(id);
                updateInterface();
            },
            onDrag : function()
            {
                var pos = {
                    "x": this.element.getStyle('left').toInt() + 1, 
                    "y": this.element.getStyle('top').toInt() + 1
                };
                $( 'divId' ).value = this.element.id;
                $( 'coordX' ).value = pos.x;
                $( 'coordY' ).value = pos.y;
            }
        }
    );
}


var componentes = [];

function inArray( el, arr )
{
    var rs = false;
    for( var i = 0; i < arr.length; i++ )
    {
        rs = ( el == arr[ i ] ? true : rs );
    }
    return rs;
}

function getComponent( comp, divId )
{
    var url =   "procesos.php?action=getComponent&editable=1&componentName=" + comp +
                "&interface_id=1" +
                "&divContainer=" + divId ;
    var myAjax  =   new Ajax( url,
        {
            method  :   'get',
            encoding  :'iso-8859-1',
            update  :   $( divId ),
            onComplete : function()
            {
                $( divId ).setStyles(
                    { 
                        'border' : 'none',
                        'cursor' : 'move'
                    }
                );
                $( divId ).addEvent( 'mousedown', function(){ draggableElement(this.id) });
            }
        }
    ).request();
}
function makeDraggableComponents()
{
    var drop = $('mainContainer');
    var dropFx = drop.effect('background-color', {wait: false}); 
    
    $$('.menuImgComponent').each( 
        function( item )
        {  
            item.addEvent('mousedown',
            function(e) 
            {
                e = new Event(e).stop();    
                var clone = this.clone()
                .setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
                .setStyles({'opacity': 0.7, 'position': 'absolute'})
                .addEvent('emptydrop',
                function()
                {
                    this.remove();
                    drop.removeEvents();
                }
                ).inject( document.body );    
                
                drop.addEvents(
                    {
                        'drop': function() 
                        {
                            drop.removeEvents();
                            clone.remove();
                            //dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
                            var tmpId = item.id.split( '_' );
                            tmpId.reverse();
                            tmpId.pop();
                            tmpId.reverse();
                            var newId = tmpId.join('_');
                            if( !inArray( newId, componentes ) )
                            {
                                //alert( newId );

                                componentes.push( newId );
                                //$( 'debug' ).innerHTML += newId + ' ' ;
                                $( 'preloaderTable' ).setStyles({'width':'50px','height':'50px'});
                                var newClone = $( 'preloader' ).clone();
                                newClone.setStyles(
                                    {   
                                        'position'  :   'static',
                                        'float'     :   'left',
                                        'display'   :   'inline',
                                        'border'    :   'solid 1px #cdcdcd'
                                    }
                                );
                                newClone.id = newId; 
                                newClone.inject(drop);
                                getComponent( newId, newClone.id );
                            }
                            else
                            {
                                alert( 'El componente ya esta en el escritorio' );
                            }
                        },
                        'over': function() 
                        {
                            //dropFx.start('98B5C1');
                        },
                        'leave': function() 
                        {
                            //dropFx.start('ffffff');
                        }
                    }
                );    
                var drag = clone.makeDraggable(
                    {
                        droppables: [drop]
                    }
                ); // this returns the dragged element
    
                drag.start(e); // start the event manual
            }
            );
    
        }
    );
}
    
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if( window.ie && (version >= 5.5 && parseInt( version, 10 ) < 7 ) && (document.body.filters)) 
    {
        //alert( "Explorer : " + version );
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText 
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                img.outerHTML = strNewHTML
                i = i-1
            }
        }
    }    
}


function showCalendar( inputIdCalendar )
{
    var DivCal = new Element( 'div',{'id':'calendarDiv'}).inject(document.body);
    DivCal.setStyles(
        {
            'position' : 'absolute',
            'top'   :   $( inputIdCalendar ).getPosition().y,
            'left'  :   $( inputIdCalendar ).getPosition().x,
            'width' :   '100px',
            'hegiht'    :   '100px'
        }
    );
    var url =   "calendar.php?inputId=" + inputIdCalendar + 
                "&contentId=" + DivCal.id +
                "&date=" + arguments[1];
    //alert( DivCal.id );
    var aja = new Ajax( url,
        {
            method : 'get',
            encoding  :'iso-8859-1',
            update : $( DivCal.id )
        }
    ).request();
}

function showBuscador( inputIdCalendar )
{
    var DivCal = new Element( 'div',{'id':'calendarDiv'}).inject(document.body);
    DivCal.setStyles(
        {
            'position' : 'absolute',
            'top'   :   $( inputIdCalendar ).getPosition().y,
            'left'  :   $( inputIdCalendar ).getPosition().x,
            'width' :   '100px',
            'hegiht'    :   '100px'
        }
    );
    var url =   "prueba_buscador.php?inputId=" + inputIdCalendar + 
                "&contentId=" + DivCal.id +
                "&date=" + arguments[1];
    //alert( DivCal.id );
    var aja = new Ajax( url,
        {
            method : 'get',
            encoding  :'iso-8859-1',
            update : $( DivCal.id )
        }
    ).request();
}

/**
*   Buscador de lineas por nombre de articulo
*/
function findCustomer(el)
{
    if( el.value.length > 3 )
    {
        var divFindCustomer = new Element( 'div', {'id':'divCustomerSearch'} ).inject(document.body);
        $('divCustomerSearch').setStyles(
            {
                'position' : 'absolute',
                'top'       :   ( $( el.id).getPosition().y.toInt() + 20 ),
                'left'      :   $( el.id ).getPosition().x,
                'background'    :   '#ffffff',
                'border-style'  :   'solid',
                'border-width'  :   '1px',
                'border-color'  :   '#d1d3d5',
                'width'         :   '250px',
                'height'        :   '300px',
                'overflow'      :   'auto'
            }
        );
        
        var dataObj = {};
        if( arguments[ 1 ] )
        {
            dataObj = arguments[ 1 ];
        }
        dataObj.action = 'findCustomer';
        dataObj.customerName = el.value;
        
        var aja = new Ajax( 'procesos.php',
            {
                'method'    :   'post',
                'encoding'  :   'iso-8859-1',
                'update'    :   $('divCustomerSearch'),
                'data'      :   dataObj
            }
        ).request();
    }
    else
    {
        if( $( 'divCustomerSearch' ) ) $( 'divCustomerSearch' ).remove();
    }
}


/*
 *  Buscador de lineas
 */

function buscarLinea(el)
{
    if( el.value.length > 3 )
    {
        var divFindCustomer = new Element( 'div', {'id':'divCustomerSearch'} ).inject(document.body);
        $('divCustomerSearch').setStyles(
            {
                'position' : 'absolute',
                'top'       :   ( $( el.id).getPosition().y.toInt() + 20 ),
                'left'      :   $( el.id ).getPosition().x,
                'background'    :   '#ffffff',
                'border-style'  :   'solid',
                'border-width'  :   '1px',
                'border-color'  :   '#d1d3d5',
                'width'         :   '250px',
                'height'        :   '300px',
                'overflow'      :   'auto'
            }
        );
        
        var dataObj = {};
        if( arguments[ 1 ] )
        {
            dataObj = arguments[ 1 ];
        }
        dataObj.action = 'buscarLinea';
        dataObj.customerName = el.value;
        
        var aja = new Ajax( 'procesos.php',
            {
                'method'    :   'post',
                'encoding'  :   'iso-8859-1',
                'update'    :   $('divCustomerSearch'),
                'data'      :   dataObj
            }
        ).request();
    }
    else
    {
        if( $( 'divCustomerSearch' ) ) $( 'divCustomerSearch' ).remove();
    }
}


/**
 *  verifica el formato de la hora capturada
 */
function formatoHora( id )
{
    var error = false;
    if( $( id ).value.indexOf( ':' ) > 0)
    {
        var dat = $( id ).value.split( ':' );
        var hora = dat[0].toInt();
        var minutos = dat[1].toInt();
        if( isNaN( hora ) || isNaN( minutos ) )
        {
            alert( "La hora y los minutos deben ser numeros" );
            error = true;
        }
        if( hora > 24 || hora < 0 )
        {   
            alert( "La hora debe ser de 0 a 24 " );
            error = true;
        }
        if( minutos < 0 || minutos > 59 )
        {
            alert( "Los minutos deben ser de 0 a 59 " );
            error = true;
        }
    }
    else
    {
        alert( "Formato incorrecto\nUtilice 'HH:MM' " );
        error = true;
    }

    if( error == true )
    {
        $( id ).value = '';
    }
}
/**
 *  rellena el input con la hora segun la mascara
 */
function completaHora( el )
{
    if( el.value.indexOf( ":" ) == 0 )
    {
        el.value = "00" + el.value;
    }
    if( el.value.length == 1 )
    {
        el.value = "0" + el.value + ":00";
    }
    if( el.value.length == 3 )
    {
        el.value += "00";
    }
    if( el.value.length == 4 )
    {
        el.value += "0";
    }
    if( el.value.indexOf( ":" ) > 0 )
    {
        var tmp = el.value.split( ":" );
        var v1 = tmp[0];
        var v2 = tmp[1];
        if( tmp[0].length == 1 )
        {
            v1 = "0" + parseInt( tmp[0] );
        }
        if( tmp[1].length == 1 )
        {
            v2 = "0" + parseInt( tmp[1] );
        }
        el.value = v1 + ":" + v2;
    }
    if( el.value.indexOf(":") < 0 )
    {
        var tmp = el.value;
        el.value = tmp.substr(0,2) + ":" + tmp.substr(2,4);
    }
    if( el.value.length > 5 )
    {
        el.value = el.value.substr(0,5);
    }
}
/**
 *  crea marcara de captura con formato HH:MM
 */
function mascaraHora( el, evnt )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    if( 
        ( code >= 48 && code <= 57 ) ||
        ( code >= 96 && code <= 105 ) ||
        code == 8 || code == 0 || code == 13
    )
    {
        if( el.value.length == 1 )
        {
            if( parseInt( el.value ) > 2 )
            {
                el.value = "0" + el.value;
            }
        }
        if( el.value.length == 2 )
        {
            if( parseInt( el.value ) > 23 )
            {
                 el.value = "0" + el.value.substr(0,1) + ":" + el.value.substr(1,1);
            }
            else  if( code != 8 )
            {
                el.value += ":";
            }
        }
        if( el.value.length == 4 )
        {
            var tmp = el.value.split(":");
            if( parseInt( tmp[1] ) > 5 )
            {
                el.value = tmp[0] + ":0" + tmp[1].substr(0,1);   
            }
        }
        return true;
    }
    else
    {
        if( code == 9 )
        {
            return true;
        }
        return false;
    }
}

/**
*
*/
function switchDisplay( id )
{
    var displ = $( id ).getStyle( 'display' ) == 'none' ? 'block' : 'none' ;
    $( id ).setStyle( 'display', displ );
}

