
var eBody = null ;
var sDefaultFontSize = "10pt" ;
var sDefaultStyleSheet = "standard" ;

var _dExpireDate = new Date() ;
var _iExpireDate = _dExpireDate.getTime() + ( 3 * 24 * 60 * 60 * 1000 ) ;
_dExpireDate.setTime(_iExpireDate) ;


function getCookieContent( sName ) {

  if ( navigator.cookieEnabled ) {
  	var _aItems = document.cookie.split(";") ;

		  	
  	sName += "=" ;
  	
  	for ( i = 0 ; i < _aItems.length ; i++ ) {
  		_aItems[i] = _aItems[i].replace( " ", "" ) ;
  	  if ( _aItems[i].substring( 0, sName.length ) == sName ) {
 			  return _aItems[i].replace( sName, "" ) ;
  		}
		}
  }
	
	return false ;
}

function getFontSize() {

	if ( getCookieContent("FontSize") ) {
		return getCookieContent("FontSize") ;
	}
  	
  return false ;
}

function getFirstStyleSheet() {
	
	for ( i = 0 ; ( _oLink = document.getElementsByTagName("link")[i] ) ; i++ ) {
		if (
		     _oLink.getAttribute("rel").indexOf("stylesheet") != -1
		    &&
		     _oLink.getAttribute("type").indexOf("text/css") != -1
		    &&
		     _oLink.getAttribute("title")
		    &&
		     _oLink.getAttribute("alt") == -1
		   ) {
		   	return _oLink.getAttribute("title") ;
		}
	}
	return sDefaultStyleSheet ;
}

function initFontSize() {

//  if ( document.getElementsByTagName('body') != null ) {
//    eBody = document.getElementsByTagName('body')[0] ;
//    if ( eBody == null ) {
//      eBody = document.body ;
//    }

  if ( document.getElementById('box_content') != null ) {
    eBody = document.getElementById('box_content') ;
    if ( eBody == null ) {
      eBody = document.box_content ;
    }
  	if ( getFontSize() ) {
	  	setFontSize(getFontSize()) ;
	  }
	  else {
		  setFontSize(sDefaultFontSize) ;
	  }
  }
}

function initStyleSheet() {
	var sStyle = getCookieContent("StyleSheet") ;
	sStyle = sStyle ? sStyle : getFirstStyleSheet() ;
	
	setStyleSheet(sStyle) ;
}


function setCookie( sName, sContent ) {

  if ( navigator.cookieEnabled ) {
		document.cookie = sName + "=" + sContent + "; expires=" + _dExpireDate.toGMTString() ;
	}

}


function setFontSize( sFontSize ) {

	if ( eBody == null ) {
		initFontSize() ;
		if ( eBody == null ) {
			return false ;
		}
	}

  setCookie( "FontSize", sFontSize ) ;

	eBody.style.fontSize = sFontSize ;
//	eBody.focus() ;
	
	sDefaultFontSize = sFontSize ;
}


function setStyleSheet( sStyle ) {
	if ( sStyle != null ) {
	  for( i = 0 ; ( _oLink = document.getElementsByTagName("link")[i] ) ; i++ ) {
	  	if (
		     _oLink.getAttribute("rel").indexOf("stylesheet") != -1
		    &&
		     _oLink.getAttribute("type").indexOf("text/css") != -1
		    &&
		     _oLink.getAttribute("title")
		   ) {
    	  _oLink.disabled = true ;
      	if( _oLink.getAttribute("title") == sStyle ) {
      		_oLink.disabled = false ;
      		sDefaultStyleSheet = sStyle ;
      		setCookie( "StyleSheet", sStyle ) ;
      	}
      }
    }
  }
  
  return true ;
}


window.onload = function(e) {
  initFontSize() ;
  initStyleSheet() ;
}
