/*
 * CursorHelper.js
 *
 * Used to create create change the browser status bar for
 * selected elements.
 *
 * Should create a new instance of this helper, then as part
 * of the document.onload event, call addMessage();
 */
var cursorLock = true;

function CursorHelper() {
    var logger = LogFactory.getLog("CursorHelper.js");

    var self = this;
    var styleNode;
    var headNode;
    var css;

    this.setNewCursor = function(cursor) {
		try{
			if( cursorLock ){
				cursorLock = false;
				logger.debug("Enter setNewCursor()");
				if( document.createStyleSheet ) {
					css = document.createStyleSheet();
					css.disabled = false;
					css.addRule( "body", "{cursor: " + cursor + " !important; }");
					css.addRule( "a", "{cursor: " + cursor + " !important; }");
					css.addRule( "input", "{cursor: " + cursor + " !important; }");
					css.addRule( ".showHand", "{cursor: " + cursor + " !important; }");
				} else {
					headNode = document.getElementsByTagName("head")[0];
					styleNode = document.createElement("style");
					var text = document.createTextNode("body, a, input, .showHand {cursor: " + cursor + " !important; }");
					styleNode.appendChild( text );
					headNode.appendChild( styleNode );
				}

				logger.debug("Exit setNewCursor()");
			}
		}catch( ignoreError ){
		}finally{
			cursorLock = true;
		}
    }

    this.removeCursor = function() {
		try{
			if( cursorLock ){
				cursorLock = false;
				logger.debug("Enter removeCursor()");
				if( document.createStyleSheet ) {
					css.disabled = true;
					while( css.rules.length > 0 ) {
						css.removeRule( 0 );
					}
				} else {
					headNode.removeChild( styleNode );
				}
			}
		}catch( ignoreError ){
		}finally{
			cursorLock = true;
		}
        logger.debug("Exit removeCursor()");
    }

}
