function resetArrayIndex( ar )
{
	var tmp = new Array();
	for( var i = 0, l = ar.length; i < l; i++ )
	{
		if( ar[i] !== null ) tmp[tmp.length] = ar[i];
	}
	ar = null;
	return tmp;
}

function createFadedBlocker()
{
	var blocker = $( document.createElement( 'div' ) );

	blocker.attr( 'id', 'blocker' );
	blocker.css( 'opacity', 0.5 );
	blocker.css( 'height', getPageSize().height + 'px' );
	$( document.body ).append( blocker );
}

function deleteFadedBlocker()
{
	$( '#blocker' ).remove();
}

function jsonEsc( str )
{
	return str.replace( /"/g, '\"' );
}

function copyPrototype( descendant, parent ) 
{
	var sConstructor = parent.toString();
	var aMatch = sConstructor.match( /\s*function (.*)\(/ );
	if( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
	for( var m in parent.prototype ) 
	{
		if( !descendant.prototype[m] ) descendant.prototype[m] = parent.prototype[m];
		else descendant.prototype['__super_'+ m] = parent.prototype[m];
	}
};

function showValidationError( str, jelement )
{
	var id = jelement.attr( 'id' ) + '_validationerror';

	var pos = jelement.getPos();
	var div = $( '#'+ id );
	if( !div.length )
	{
		var div = $( document.createElement( 'div' ) );
		div.attr( 'id', id );
		div.css( 'position', 'absolute' );
		div.css( 'top', pos.top +'px' );
		div.css( 'left', pos.left + jelement.get(0).offsetWidth +'px' );
		div.css( 'z-index', 99999999 );
		div.css( 'cursor', 'pointer' );
		div.addClass( 'validationerror' );
		div.click( function() { $( this ).remove(); } );
	}
	var p = $( document.createElement( 'p' ) ).html( str );
	div.append( p );

	$( document.body ).append( div );
}

function clearValidationErrors()
{
	if( arguments.length )
	{
		for( var i = 0, l = arguments.length; i < l; i++ )
		{
			var jelement = arguments[i];
			var id = jelement.attr( 'id' ) + '_validationerror';
			$( '#'+ id ).remove();
		}
	}
	else $( 'div.validationerror' ).remove();
}

/*function e( str )
{
	str = str.replace( "ä", unescape( '%E4' ) );
	str = str.replace( "å", unescape( '%E5' ) );
	str = str.replace( "ö", unescape( '%F6' ) );
	str = str.replace( "Ä", unescape( '%C4' ) );
	str = str.replace( "Å", unescape( '%C5' ) );
	str = str.replace( "Ö", unescape( '%D6' ) );

	return str.substr( 0, 1 ).toUpperCase() + str.substr( 1, str.length );
}*/

function createUniqueId()
{
	var id = '';

	var chars = new Array(  'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 
				'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 
				'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 
				'V', 'v', 'X', 'x', 'Y', 'y', 'Z', 'z', 'W', 'w', 'Q', 'q' );

	for( var i = 0; i < 15; i++ )
	{
		var rnd = Math.floor( Math.random() * chars.length );
		id += chars[rnd];

		var rnd2 = Math.random() +'';
		rnd2 = rnd2.replace( /[^0-9]+/, '' ).replace( /^0/, '' );
		rnd2 = rnd2 * i +'';
		rnd2 = rnd2.substr( 0, 2 );
		id += rnd2;
	}
	return id;
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = {width:pageWidth,height:pageHeight,winwidth:windowWidth,winheight:windowHeight}; 
	return arrayPageSize;
}