var ltIE7 = false;
if ( /MSIE ([0-9]*)/.test( navigator.userAgent.toString() ) )
{
	var m = navigator.userAgent.toString().match( /MSIE ([0-9]*)/ );
	if ( parseInt( m[1] ) < 7 )
	{
		ltIE7 = true;
	}
}
function fixSize( el )
{
	if ( ltIE7 )
	{
		if( el.offsetWidth & 1 )
		{
			el.style.width = 
					el.offsetWidth - 
					parseInt( Element.getStyle( el, 'padding-left' ) ) -
					parseInt( Element.getStyle( el, 'padding-right' ) ) + 1 + 'px';
		}
		if( el.offsetHeight & 1 )
		{
			el.style.height = 
					el.offsetHeight - 
					parseInt( Element.getStyle( el, 'padding-top' ) ) -
					parseInt( Element.getStyle( el, 'padding-bottom' ) ) + 1 + 'px';
		}
	}
	return;
}

function repaintCorners(el)
{
		if ( ltIE7 )
		{
			['tl','tr','bl','br'].each(function(cl){
				var img = Selector.findChildElements(el,$A(['img.'+cl])).first();
				img.parentNode.replaceChild(img,img);
			});
		}
}

function loadFlash( fname, w, h, className )
{
	var Flash = ' \
		<object class="'+className+'" type="application/x-shockwave-flash" data="' + fname + '" width="' + w + '" height="' + h + '"> \
			<param name="quality" value="high" /> \
			<param name="scale" value="noscale" /> \
			<param name="devicefont" value="true" /> \
			<param name="bgcolor" value="#ffffff" /> \
			<param name="movie" value="' + fname + '" /> \
		</object> \
	';

	document.write( Flash );
}

Event.observe( window, 'load', function()
{
// Add Events onfocus and onblur for login form
	var loginForm = $('loginForm');
	if ( loginForm )
	{
		Event.observe( loginForm, 'submit', function(e){
			Event.stop(e);
		});
		[[loginForm.user,loginForm.user.value],
		[loginForm.pass,loginForm.pass.value]].each(function(obj)
		{
			Event.observe( obj[0], 'focus', function(e){
				var el = Event.element(e);
				if ( el.value == obj[1] ) {
					el.value = '';
				}
			});
			Event.observe( obj[0], 'blur', function(e){
				var el = Event.element(e);
				if ( el.value == '' ) {
					el.value = obj[1];
				}
			});
		} );
	}
	
	var butViewMore = $('butViewMore');
	var moreDetails = $('moreDetails');
	
	if ( butViewMore && moreDetails )
	{
		Event.observe(butViewMore,'click',function(){
			Element.toggle(moreDetails);
			repaintCorners( butViewMore.parentNode.parentNode );
		});
	}
	
	var rndElements = document.getElementsByClassName('rnd');
	if ( rndElements.length )
	{
		var classes = ['tl','tr','bl','br'];
		var imgPreloaded = [];
		classes.each(function(cl,ind){
			imgPreloaded[ind] = new Image();
			imgPreloaded[ind].src = 'images/img_rnd_' + cl + '.gif';
		});
		
		rndElements.each(function(el){
			fixSize( el );
			classes.each(function(cl,ind){
				var img = document.createElement('img');
						img.className = cl;
						img.src = imgPreloaded[ind].src;
				el.appendChild(img);
				delete img;
			});
		});
	}
	
} );