var ie = (document.all) ? true : false;
var ie6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
var lightboxHeight = 250;

function SetFirstFocus()
{
	var list = $$('.first_focus');
	
	if (list.length > 0) list[0].focus();
}
document.observe('dom:loaded', SetFirstFocus);

window.onresize = function() 
{
	ResizeLightBox(0);
}

window.onerror = function () { return true; }

function ResizeLightBox(currentHeight, action)
{
    var divLightBox = GetObject('divLightBox');
	var divAreaContentContainer = GetObject('divAreaContentContainer');
	
	lightboxHeight = (currentHeight > 0) ? currentHeight : lightboxHeight;
	
    if (divLightBox)
    {
		divLightBox.style.width = document.body.clientWidth + 'px';
		
		if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1)
			divLightBox.style.height = (screen.height + 70) + 'px';
		else
			divLightBox.style.height = ((document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight) + 'px';
		
		if (divAreaContentContainer)
		{
			var height = parseInt(((document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight));
			
			if ((screen.height <= 800 && lightboxHeight >= 450) || (height < lightboxHeight))
			{
				divAreaContentContainer.style.top = '0';
			}
			else
			{
				divAreaContentContainer.style.top = Math.abs(((((screen.height < height) ? screen.height : height) - lightboxHeight) / 3)) + 'px';
			}
			
			
			var currentWidth = parseInt(divAreaContentContainer.style.width);
			
			if (document.body.clientWidth <= currentWidth)
				divAreaContentContainer.style.left = '0';
			else
				divAreaContentContainer.style.left = Math.abs(((document.body.clientWidth - currentWidth) / 2)) + 'px';
		}
    }
	
	return;
}


// --- HELPER METHODS --- //
function GetObject(obj)
{
	return (typeof(obj) != 'object') ? document.getElementById(obj) : obj;
}


function SwapCSSClassName(obj, name, replacement)
{
	if (typeof(obj) != 'object' && obj == 'aPlayFlash')
	{
		tempSwap();
		return;
	}
		
	obj = GetObject(obj);

	if (obj)
		obj.className = obj.className.replace(name, replacement);
	
	return;
}


function tempSwap()
{
	var h2Title1 = GetObject('h2PlayFlashTitle1');
	h2Title1.className = h2Title1.className.replace('show', 'hide');
	
	var h2Title2 = GetObject('h2PlayFlashTitle2');
	h2Title2.className = h2Title2.className.replace('hide', 'show');
	
	return;
}


function HasSelectionInRadioGroup(radioGroup)
{
	var isSelected = false;
	
	for (var r = 0; r < parseInt(radioGroup.length); r++)
	{
		if (radioGroup[r].checked)
		{
			isSelected = true;
			break;
		}
	}
	
	return isSelected;
}


function GetSelectionInRadioGroup(radioGroup)
{
    var selectedValue = null;
    
	for (var r = 0; r < parseInt(radioGroup.length); r++)
	{
		if (radioGroup[r].checked)
		{
			selectedValue = radioGroup[r].value;
			break;
		}
	}
	
	return selectedValue;
}


function RemoveSelectionInRadioGroup(radioGroup)
{
    for (var r = 0; r < parseInt(radioGroup.length); r++)
	{
	    radioGroup[r].checked = false;
	}
}



// --- PROTOTYPES --- //
String.prototype.trim  = function() 
						 {
							 return this.replace(/^\s+|\s+$/g, '');
						 }
						
String.prototype.ltrim = function() 
						 {
							 return this.replace(/^\s+/, '');
						 }

String.prototype.rtrim = function() 
						 {
							 return this.replace(/\s+$/, '');
						 }

String.prototype.IsEmpty = function()
						   {
								return this.search(/\S/);
						   }
