var isIE = false ;
var isNav = false ;
var oldColor ;

function checkBrowser()
{
 if( navigator.appName.indexOf("Netscape") != -1 )
                isNav = true ;
          else 
                isIE = true ;

// alert( isIE + " " + isNav ) ;
}


// -------- Dynamic elements color:

var oldColor, oldWhat = null ;

function changeColor( what, clr )
{
 oldColor = eval("document.getElementById('" + what + "').style.color" ) ;
 oldWhat = what ;
 eval("document.getElementById('" + what + "').style.color='" + clr + "'" ) ;
}

function restoreColor()
{
 if( oldWhat != null )
  {
   changeColor( oldWhat, oldColor) ;
   oldWhat = null ;
  } 
}


// ------- Control of the spin-windows input:          

function WinIncr( w, min, max )
{
 var n = w.value ;

 n ++ ;
  if( n > max ) 
               n = min ;

 w.value = n ;
}

function WinDecr( w, min, max )
{
 var n = w.value ;

 n -- ;
  if( n < min ) 
               n = max ;

 w.value = n ;
}

// ------- Check if a given date string is correct:

function CheckDateFormat( string, title )
{
 a = string.split(" ") ;

 b = a[0].split(".") ;
  if( b.length != 3 )
   {
    alert("Bad 'DATE' value in" + title ) ;
                      return null ;
   }

 t = new Date() ;
 d = new Number( b[ 0 ] ) ;
 m = new Number( b[ 1 ] ) ;
 y = new Number( b[ 2 ] ) ;
  if( d < 1 || d > 31 || d.toString().search("NaN") != -1 )
   {
    alert("Bad 'DATE' field in" + title ) ;
                      return null ;
   }
  if( m < 1 || m > 12 || m.toString().search("NaN") != -1 )
   {
    alert("Bad 'MONTH' field in" + title ) ;
                      return null ;
   }
  if( y < 0 || y > t.getFullYear() || y.toString().search("NaN") != -1 )
   {
    alert("Bad 'YEAR' field in" + title ) ;
                      return null ;
   }

 t.setMonth( 0 ) ;  // sic!
  
 t.setDate( d ) ; 
 t.setMonth( m - 1 ) ; 
 t.setFullYear( y ) ;
 t.setHours( 0 ) ;
 t.setMinutes( 0 ) ;
 t.setSeconds( 0 ) ;
 return t ;                            
}




//                            ++++ 12 / XI 2008.
// ------- Remember & restore the address of an initial page:

var title_page ;

function remember_title()
{
 title_page = parent.document.referrer ;
// alert( "-"+title_page+"-" ) ;
}


function restore_title()
{
 parent.document.location.href = title_page ;
}







//                        ++++ rewritten: IV 2011.
// ------ Fill initially the input date fields:
function initial_fills( z )
{
 n = 10 ;
 if( z != undefined )
   n = z ;
 
 var today = new Date() ;
 var yestr = new Date() ;
 yestr.setTime( today.getTime() - 86400000 * n ) ; // minus 'n' days duration
 today.setTime( today.getTime() )                  // set in milliseconds.

 document.frmDBAccess.inpSince1.value =  yestr.getDate() ;
 document.frmDBAccess.inpSince2.value =  yestr.getMonth() + 1 ;
 document.frmDBAccess.inpSince3.value =  yestr.getFullYear() ;

 document.frmDBAccess.inpUntil1.value =  today.getDate() ;
 document.frmDBAccess.inpUntil2.value =  today.getMonth() + 1 ;
 document.frmDBAccess.inpUntil3.value =  today.getFullYear() ; 
}




function check_dates()
{
 if( CheckDateFormat( document.frmDBAccess.inpSince1.value + "." +
                      document.frmDBAccess.inpSince2.value + "." +
                      document.frmDBAccess.inpSince3.value + " 0",
                                "'Since' parameter" ) == null )
                                                           return false ;

 if(  CheckDateFormat( document.frmDBAccess.inpUntil1.value + "." +
                       document.frmDBAccess.inpUntil2.value + "." +
                       document.frmDBAccess.inpUntil3.value + " 0",
                                "'Until' parameter" ) == null )
                                                           return false ;
 return true ;
}




function draw_chans( z )
{
 t = document.frmDBAccess.slcChans.options[
                 document.frmDBAccess.slcChans.selectedIndex ].value.split(':') ;
 if( t.length < 2 )
  {
   c = t[ 0 ] ;
  }
 else
  {
   c = t[ 3 ] ;
  }


 s = "<html><head>" + 
     "<link rel=stylesheet href='../instructreg/tish.css' type='text/css'>" +
     "</head><body><form name='frmDBAccess'><table style='width:100%'>" + 
     "<tr><td class=menu>" +
     "Channels:<br><input type='text' name='inpChans' size=1 style='width:100%' " +
     "value='" + c  + "'>"

 if( z != undefined )
                s += z ;
 else
     s += "</td></tr><tr><td class=menu style='text-align:right'>" + 
          "Sum:&nbsp;&nbsp;<input type='checkbox' name='ckSum'></td></tr>" ;

 s += "<table></form></body></html>" ;
     
 parent.frameMenu1.document.open() ;
 parent.frameMenu1.document.write( s ) ;
 parent.frameMenu1.document.close() ;
}



