function setADOVVisible()
{
	document.getElementById( "PlayerDIV" ).style.visibility = "visible";
	document.getElementById( "startImageADOV" ).style.visibility = "hidden";
}

function goToLoSite()
{
	var selectedURL;
	selectedURL = document.siteSelectionForm.siteSelection[document.siteSelectionForm.siteSelection.selectedIndex].value;
	if ( selectedURL == "unselected")
		return;
	else
		this.location.href = selectedURL;
}

function addZeroIfLessThenTen( value )
{	
	var retStr = value;
	var intVal = parseInt( value );

	
	if( value < 10 )
	{
		retStr = "0" + retStr;
	}
		
	return retStr;
}
					
function validateMail( mail )
{
	if( mail.length == 0 )
		return true;
	var re = new RegExp( /^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,3}$/i );
	return re.test( mail );
}

function validateRegEx( value, regex )
{
	if( value.length == 0 )
		return true;
	return regex.test( value );
}

function validateNumberField( field, defaultValue, allowNegative )
{
	var number = new Number( field.value );
	if ( isNaN( number ) ) 
	{
		if( field.value != null && field.value != "" )
		{
			var isNegative = allowNegative && field.value.length > 0 && field.value.substring( 0, 1 ) == "-";
			number = new Number( field.value.replace( /[^0-9]*/gim, "" ) );
			if( isNaN( number ) )
				field.value = defaultValue;
			else if( isNegative )
				field.value = -number;
			else
				field.value = number;
		}
		else
			field.value = defaultValue;			
	}
	else if ( !allowNegative && number < 0 )
		field.value = 0;
}

function validateInputForm( formElement )
{
	// Go through all the form fields and check if they are visible. If they are not, then remove them
	var tagNames = [ "select", "textarea", "input" ];
	for( var t = 0; t < tagNames.length; t++ )
	{
		var list = formElement.getElementsByTagName( tagNames[ t ] );
		for( var i = list.length - 1; i >= 0 ; i-- )
		{
			var field = list[ i ];
			var obj = field;
			while( obj != formElement && obj != null )
			{
				if( obj.currentStyle.display == 'none' || obj.currentStyle.visibility == 'hidden' || obj.name == "submit" )
				{
					if( obj.name == "submit" )
						obj.outerHTML = "Skickar...";
					else
						field.parentNode.removeChild( field );
					obj = null;
				}
				if( obj != null )
					obj = obj.parentNode;
			}
		}
	}
	
	//if( formElement.lastChild.firstChild != null )
	//	formElement.lastChild.firstChild.style.visibility = 'hidden';
		
	return true;
}

function numberInputCheck(field, e, allowNegative)
{
	var code = e.charCode;
	if(code == null)
		code = e.keyCode;
	
	// Delete and navigation
	if( code < 32 )
		return true;
	// Sign
	if( allowNegative && code == 45 && field.value.length == 0 )
		return true;
	// Number check
	if( code >= 48 && code <= 57 )
		return true;
	
	// Invalid
	return false;
}

function showRadioContainer( identifier, index )
{
	var container = eval( 'oCurrentRadioContainer' + identifier );
	if( container != null )
		container.style.display = "none";
	container = document.getElementById( "radiocontainer_" + identifier + "_" + index );
	eval( 'oCurrentRadioContainer' + identifier + ' = container' );
	container.style.display = "block";
}

function openMediaPlayer( idProduct, idCategory, idStream )
{
	if(document.all && navigator.platform == "Win32")
	{
		var url = "mediaplayer/default.aspx?mediaProduct=" + idProduct + "&mediaCategory=" + idCategory + "&stream=" + idStream;
		window.open( url, "LOplayer", "channelmode=no, directories=no, fullscreen=no, height=422, width=593, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, top=100, left=100", true);
	}	
}


function nextSlide( identifier )
{
	showSlide( identifier, eval( 'slideshowIndex' + identifier + ' + 1' ) );
}

function previousSlide( identifier )
{
	showSlide( identifier, eval( 'slideshowIndex' + identifier + ' - 1' ) );
}

function showSlide( identifier, index )
{
	var slideshowImages = eval( 'slideshowImages' + identifier );
	if( index >= 0 && index < slideshowImages.length )
	{
		eval( 'slideshowIndex' + identifier + ' = index' );
		var obj = document.getElementById( 'slideshowImageObject' + identifier );
		obj.src = slideshowImages[ index ];
	}
	updateButtonStatus( identifier );				
}

function updateButtonStatus( identifier )
{
	var slideshowIndex = eval( 'slideshowIndex' + identifier );
	var slideshowImages = eval( 'slideshowImages' + identifier );
	var previousbutton = document.getElementById( 'previousSlideButtonTop' + identifier );
	if( previousbutton != null )
	{
		var nextbutton = document.getElementById( 'nextSlideButtonTop' + identifier );
		previousbutton.style.visibility = 'inherit';
		nextbutton.style.visibility = 'inherit';
		if( slideshowIndex == 0 )
			previousbutton.style.visibility = 'hidden';
		if( slideshowIndex == slideshowImages.length - 1 )
			nextbutton.style.visibility = 'hidden';
		
		var indexIndicators = document.getElementById( 'progressIndicatorTop' + identifier );
		indexIndicators = indexIndicators.getElementsByTagName( 'img' );
		for( i = 0; i < indexIndicators.length; i+=2 )
		{
			if( i / 2 == slideshowIndex )
				indexIndicators[ i ].className = 'slideShowIndicatorActive';
			else
				indexIndicators[ i ].className = 'slideShowIndicatorInActive';
		}
	}
	previousbutton = document.getElementById( 'previousSlideButtonBottom' + identifier );
	if( previousbutton != null )
	{
		var nextbutton = document.getElementById( 'nextSlideButtonBottom' + identifier );
		previousbutton.style.visibility = 'inherit';
		nextbutton.style.visibility = 'inherit';
		if( slideshowIndex == 0 )
			previousbutton.style.visibility = 'hidden';
		if( slideshowIndex == slideshowImages.length - 1 )
			nextbutton.style.visibility = 'hidden';
		
		var indexIndicators = document.getElementById( 'progressIndicatorBottom' + identifier );
		indexIndicators = indexIndicators.getElementsByTagName( 'img' );
		for( i = 0; i < indexIndicators.length; i+=2 )
		{
			if( i / 2 == slideshowIndex )
				indexIndicators[ i ].className = 'slideShowIndicatorActive';
			else
				indexIndicators[ i ].className = 'slideShowIndicatorInActive';
		}
	}
}
