var StenoIs = {}
function getID( strId ) { return document.getElementById( strId ); }

StenoIs.getCategoryDiv = function() 
{
    
    var objDivs = document.getElementById( 'TableCenter' ).getElementsByTagName( 'div' );
    for ( i = 0; i < objDivs.length; i++ ) {
        if ( 
            ( ( document.all ) ? objDivs[i].getAttribute( 'className' ) : objDivs[i].getAttribute( 'class' ) ) == 'category'  
        ) {    
            return objDivs[i];    
        }
    }
}

StenoIs.writeToCategoryDiv = function( strHtml ) 
{
   StenoIs.getCategoryDiv().innerHTML += strHtml;       
}

StenoIs.Calendar = {
    
        nextMonth: function()
        {
            setMonth = getID( 'iMonth' ).value;
            intMonth = parseInt( setMonth );
            if ( setMonth == '08' ) intMonth = 8;
            if ( setMonth == '09' ) intMonth = 9;
        
            if ( intMonth < 12 ) intMonth++;
            location.replace( 
                '?op=steno&stcommand=calendar&year=' 
              + getID( 'iYear' ).value 
              + '&month=' 
              + intMonth );    
        },
        
        prevMonth: function()
        {
            setMonth = getID( 'iMonth' ).value;
            intMonth = parseInt( setMonth );
            if ( setMonth == '08' ) intMonth = 8;
            if ( setMonth == '09' ) intMonth = 9;
        
            if ( intMonth > 1 ) intMonth--;
            location.replace( 
                '?op=steno&stcommand=calendar&year=' 
              + getID( 'iYear' ).value 
              + '&month=' 
              + intMonth );
        },
        
        prevYear: function()
        {
            setYear = getID( 'iYear' ).value;
            intYear = parseInt( setYear );
            if ( intYear > 1992 ) intYear--;
            location.replace( 
                '?op=steno&stcommand=calendar&year=' 
              + intYear 
              + '&month=' 
              + getID( 'iMonth' ).value );
        },
        
        nextYear: function()
        {
            setYear = getID( 'iYear' ).value;
            intYear = parseInt( setYear );
            d = new Date();
            yr = d.getFullYear();
            if(intYear < yr+1)intYear++;
            location.replace( 
                '?op=steno&stcommand=calendar&year=' 
              + intYear 
              + '&month=' 
              + getID( 'iMonth' ).value );
        }
}

StenoIs.openWin = function( strUrl, strName, strWidth, strHeight, strSettings )
{
   var leftPosition = (screen.width) ? (screen.width-strWidth)/2 : 0;
   var topPosition = (screen.height) ? (screen.height-strHeight)/2 : 0;
   var strSettings = 'height='+strHeight+',width='+strWidth+',top='+topPosition+',left='+leftPosition+','+strSettings;
   var objWin = window.open( strUrl, strName, strSettings );
   return objWin;
}

StenoIs.printSteno = function( strHref )
{
    var objWin = StenoIs.openWin( 
       strHref,
       'PrintIstung',
       '800',
       '600',
       'scrollbars=yes,menubar=no,resizable=yes,location=no' 
   );    
   return false;
}

StenoIs.terviktekstPaevakord = function( strHref )
{
    var objWin = StenoIs.openWin( 
       strHref,
       'TerviktekstPaevakord',
       '800',
       '600',
       'scrollbars=yes,menubar=no,resizable=yes,location=yes' 
   );    
   return false;
}

StenoIs.loaded = function(i,f,c){
    if (!c) {
        c = function(){return false;}
    }
    if ( c() ) {
        if (
                document.getElementById &&
                document.getElementById( i ) != null ) 
        { 
            f();
        } else {
            setTimeout('StenoIs.loaded(\''+i+'\','+f+','+c+')',100);
        }
    }
    return false;
}

// Hide steno category div. It's contents get inserted to header category div( yellow bar ).

/*
StenoIs.loaded( 
    'StenoCategoryDiv', 
    function () {
        var objCatDiv = document.getElementById( 'StenoCategoryDiv' );
        objCatDiv.style.display = 'none';
        StenoIs.writeToCategoryDiv( objCatDiv.innerHTML );
        //StenoIs.getCategoryDiv().setAttribute( 'class', 'category' );
    },
    function() {
        var arrCheck =[
            //'stcommand=isikusonavotud',
            //'stcommand=isikusonavotudpaevakord',
           // 'stcommand=stenogramm',
           // 'stcommand=calendar'
        ];
        for ( var i = 0; i < arrCheck.length; i++ ) {
            if ( (( window.location).toString()).indexOf( arrCheck[i] ) != -1 
                || (( window.location).toString()) == 'http://www.riigikogu.ee/?op=steno'
            ) {
                return true;
            }
        }
        return false;
    }
);*/
