function openWin( url, width, height, windowName ) {
    openWin( url, width, height, "yes", windowName );
}

/**
	Opens a windows with specified parameters.
	
	@param url
	@param width
	@param height
	@param scrollbars yes, no. Default is yes.
	@param windowName
	*/
function openWin( url, width, height, scrollbars, windowName ) {
    if ( !windowName ) {
        windowName="newWindow";
    }
    var newWindow = open( url, windowName, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrollbars+",resizable=yes,copyhistory=no,width=" + width + ",height=" + height );
    newWindow.focus();
}

function openHelpWin( urlAnker ) {
    helpWin = open( urlAnker, "helpWindow", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=500" );
    helpWin.focus();
}

function isNumber( text ) {
    if ( text.length < 1 ) {
    	return false;
   	}
    for ( var i=0; i < text.length; i++ ) {
    	var character = text.charAt( i );
        if ( ( character < '0' || character > '9' ) && character != '.' && character != ',' ) {
            return false;
        }
    }
    return true;
}

function isInteger( text ) {
    if ( text.length < 1 ) {
    	return false;
   	}
    for ( var i=0; i < text.length; i++ ) {
    	var character = text.charAt( i );
        if ( character < '0' || character > '9'  ) {
            return false;
        }
    }
    return true;
}

function setDocumentElementVisibility( thisDocument, name, visibility ) {
	if( thisDocument != null && thisDocument.getElementById( name ) != null ) {
		thisDocument.getElementById( name ).style.display = visibility;
	}
}

/**
	Opens a progress bar message in specified document's body.
	
	@param document The message will be centered in this document's body and its location will be reset, if url is specified.
	@param message Message to display above image
	@param image Image to display beneath message
	@param url new location of document. Leave empty if the location shall not be reset.
	*/
function showProgress( document, message, image, url ) {
    var progressDiv = document.createElement( "div" );
    var dropShadow = document.createElement( "div" );
    progressDiv.id = "ProgressWindow";
    progressDiv.className = "Progress";
    dropShadow.className = "DropShadow";
    dropShadow.id = "ProgressWindowShadow";
    
    var progressText = document.createElement( "p" );
    progressText.appendChild( document.createTextNode( message ) );
    progressDiv.appendChild( progressText );

    var progressImage = document.createElement( "img" );
    progressImage.className = "Progress";
    progressImage.src = image;

    progressDiv.appendChild( progressImage );

	// creates a temporary body element to write div to... gulp
	if( !document.body ) {
		document.write( '<body/>') ;
	}
    // IE only finds them this way:
    var styleWidth = getStyle( "DIV.Progress", "width" );	
    var	styleHeight = getStyle( "DIV.Progress", "height" );	
	
    if( typeof styleWidth == 'undefined' ) {
    	// Firefox only like this:
		styleWidth = getStyle( "div.Progress", "width" );
    }
    if( typeof styleHeight == 'undefined' ) {
    	// Firefox only like this:
		styleHeight = getStyle( "div.Progress", "height" );
    }
    
    var centeredLeft = Math.round( ( document.body.clientWidth - parseInt( styleWidth ) ) / 2 );
    var centeredTop = Math.round( ( document.body.clientHeight - parseInt( styleHeight ) ) / 2 );
    
    progressDiv.style.top = centeredTop + 'px';
    progressDiv.style.left = centeredLeft + 'px';
    dropShadow.style.top = centeredTop + 10 + 'px';
    dropShadow.style.left= centeredLeft + 10 + 'px';
    
    
    document.body.appendChild( dropShadow );
    document.body.appendChild( progressDiv );
    
	if( url ) {
	    document.location.href = url;
	}
}

function hideProgress( document ) {
	var progressWindow = document.getElementById( 'ProgressWindow' );
	if( progressWindow ) {
		progressWindow.style.display = 'none';
	}
	var shadow = document.getElementById( 'ProgressWindowShadow' );
	if( shadow ) {
		shadow.style.display = 'none';
    }
}

/**
	Gets the specified property of the specified style class, e.g. the "border" value of the "DIV.Message" class.
	
	@param styleClass style class to find
	@param property style property to get 
	*/
function getStyle( styleClass, property ) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	}
	else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++) {
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			var currentRule = document.styleSheets[S][cssRules][R];
			if (currentRule.selectorText == styleClass) {
				return document.styleSheets[S][cssRules][R].style[property];
			}
		}
	}
}

