
function Utils() {

this.setCookie = function( sName, sValue, nSeconds, sPath, sDomain, bSecure ) {
    if ( ! navigator.cookieEnabled ) return false ;
    var sCookie = sName + "=" + escape ( sValue ) ;
    if ( typeof nSeconds != 'undefined' && nSeconds != null ) {
        var d = new Date() ;
        d.setTime( d.getTime() + 1000 * nSeconds ) ;
        sCookie += "; expires=" + d.toGMTString() ;
    }
    if ( typeof sPath != 'undefined' && sPath != null )
        sCookie += "; path=" + escape ( sPath ) ;
    if ( typeof sDomain != 'undefined' && sDomain != null )
        sCookie += "; domain=" + escape ( sDomain ) ;
    if ( bSecure )
        sCookie += "; secure" ;
    document.cookie = sCookie ;
    return true ;
} ;

this.getCookie = function( sName ) {
    if ( ! navigator.cookieEnabled ) return null ;
    var oRegExp = new RegExp( '\\b' + sName + '=([^;]*)', 'i' ) ;
    var a = oRegExp.exec( unescape( document.cookie ) ) ;
    if ( a == null ) return null ; else return a[ 1 ] ;
} ;

this.deleteCookie = function( sName ) {
    if ( ! navigator.cookieEnabled ) return false ;
    // this doesn't remove the cookie immediately
    setCookie( sName, "", -1 ) ;  
    return true ;
} ;

this.incrCookie = function( sName, nSeconds, sPath, sDomain, bSecure ) {
    if ( ! navigator.cookieEnabled ) return null ;
    var s = this.getCookie( sName ) ;
    var i = parseInt( s ) ;
    if ( isNaN( i ) ) i = 0 ;
    this.setCookie( sName, ++i, nSeconds, sPath, sDomain, bSecure ) ;
    return this.getCookie( sName ) ;  // playing safe
} ;

this.parsePathname = function( sPathname ) {
    // returns an array where the elements are:
    // [1]=drive [2]=path [3]=filename [4]=extension
    // the pattern matches all strings, so element [0] will always = sPathname
    // missing parts have typeof == 'undefined'
    var oRegexp = /(?:(.):)?(?:(.*)\\)?((?:[^.]|.(?=[^.]*\.))*)(?:\.(.*))?/ ;
    return oRegexp.exec( sPathname ) ;
} ;

this.computedStyle = function( vElem, sProperty ) {
    if ( typeof vElem == 'string' )
        var oElem = document.getElementById( vElem ) ;
    else
        var oElem = vElem ;
    if ( oElem == null ) return null ;
    if ( typeof window.getComputedStyle == 'undefined' )
        // IE(8) doesn't return the calculated (numeric) value of the property,
        // just its "cascaded value" which may be something like "auto"
        return oElem.currentStyle[ sProperty ] ;
    else
        // the MF method works just as it should, of course
        return window.getComputedStyle( oElem, null)[ sProperty ] ;
} ;

this.getURLparm = function( sName ) {
    sName = sName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]") ;
    var oRegExp = new RegExp( "[\\?&]" + sName + "=([^&#]*)", "i" ) ;
    var a = oRegExp.exec( document.URL ) ;
    if ( a == null ) return "" ; else return a[1] ;
} ;

this.stripTags = function( sHTML, sTagName) {
    var oRegExp = new RegExp('<' + sTagName + '(\\s*|\\s+[^>]*)>', 'ig');
    sHTML = sHTML.replace( oRegExp, '' ) ;
    oRegExp = new RegExp( '<\\s*\\/' + sTagName + '\\s*>', 'ig' ) ;
    sHTML = sHTML.replace( oRegExp, '' ) ;
    return sHTML ;
} ;

this.isInClass = function( oElement, sClass ) {
    if ( typeof oElement.className == "undefined" ) return false ;
    // rolling own case insensitivity because IE having trouble with 'i'
    var sRegExp = "\\b" + sClass.toLowerCase() + "\\b" ;
    return ( -1 < oElement.className.toLowerCase().search( sRegExp ) ) ;
} ;

this.calcSeconds = function( sTime ) {
    var nSeconds = 0 ;
    var oParts = sTime.split( ':' ) ;
    var nParts = oParts.length - 1 ;
    var nFactor = 1 ;
    var nNewFactor = 1 ;
    for ( var n = nParts; n >=0; n-- ) {
        switch( nParts - n ) {
            case 1 : 
            case 2 : nNewFactor = 60 ; break ;
            case 3 : nNewFactor = 24 ;
        }
        nFactor = nFactor * nNewFactor ; 
        nSeconds += parseInt( oParts[ n ] ) * nFactor ;
    }
    return nSeconds ;
} ;

this.formatSeconds = function( sSeconds ) {
    // converts seconds to days:hours:minutes:seconds
    var sTime = "" ;
    if ( sSeconds == "" ) sSeconds = "0" ;
    var iNumerator = parseInt( sSeconds ) ;
    if ( iNumerator < 0 ) iNumerator = 0 ;
    for ( var i = 1; i <= 3; i++ ) {
        var iDenominator = i < 3 ? 60 : 24 ;
        var iRemainder = iNumerator % iDenominator ;
        iNumerator = ( iNumerator - iRemainder ) / iDenominator ;
        if ( iNumerator > 0 || i == 1 || iRemainder >= 10 ) {       
            var sPart = ( "" + ( 100 + iRemainder ) ).substr( 1 ) ;
            if ( iNumerator > 0 || i == 1 ) sPart = ":" + sPart ;
        } else
            var sPart = "" + iRemainder ;
        sTime = sPart + sTime ;
        if ( iNumerator == 0 ) break ;  
    }
    if ( iNumerator > 0 || i == 1 ) sTime = iNumerator + sTime ;
    return sTime ;
} ;

this.lTrim = function( sString ) {
    return sString.replace( /^\s+/, '' ) ;
} ;

this.rTrim = function( sString ) {
    return sString.replace( /\s+$/, '' ) ;
} ;

this.trim = function( sString ) {
    return this.lTrim( this.rTrim( sString ) ) ;	
} ;

this.clearObject = function( o ) {
    for ( s in o ) delete o[ s ] ;
} ;

this.getScrollTop = function( oElem ) {
	var iScrollTop ;
	var oErr ;
	try { iScrollTop = oElem.scrollTop }
        catch ( oErr ) { iScrollTop = 0 } 
	return iScrollTop ;
} ;

this.setScrollTop = function( oElem, y ) {
	var oErr ;
	try { oElem.scrollTop = y }
	catch ( oErr ) {}  
} ;

} // end function Utils()

////////////////////////////////////////////////////////////////////////

function BinaryOption( bValue, sID, bReadCookie ) {

    // sID is the name of a cookie and/or id of a checkbox

    var oUtils = new Utils() ;

    if ( typeof bValue == 'undefined' ) bValue = false ;
    if ( typeof sID == 'undefined' ) sID = '' ;

    this.readCookie = function() {
        if ( sID == '' ) return null ;
        var s = oUtils.getCookie( sID ) ;
        if ( s != null && s != '' ) bValue = ( s != '0' ) ;
        return bValue ;
    } ;

    this.writeCookie = function() {
        if ( sID == '' ) return false ;
        var s = ( bValue ? '1' : '0' ) ;
        return oUtils.setCookie( sID, s, 60*60*24*365 ) ;
    } ;

    this.value = function( b ) {
        if ( typeof b == 'undefined' ) return bValue ;
        bValue = b ;
        return this.writeCookie() ;
    } ;

    this.initCheckbox = function() {
        var o = document.getElementById( sID ) ;
        if ( o == null ) return ;
        // next line triggers onclick event?    
        if ( o.checked != bValue ) o.checked = bValue ;
    } ;

    this.id = function( s, bReadCookie ) {
        if ( typeof s == 'undefined' ) return sID ;
        sID = s ;
        if ( bReadCookie ) this.readCookie() ;        
    } ;

    if ( bReadCookie ) this.readCookie() ;

} ; // end function BinaryOption()

