function highlight( e )
{
    e.focus();
    e.select();
}

function hideAlldetailTabs()
{
	document.getElementById( 'detailTabEmail' ).style.display = 'none';
	document.getElementById( 'detailTabReport' ).style.display = 'none';
	document.getElementById( 'detailTabShare' ).style.display = 'none';
	
	if ( document.getElementById( 'detailTabEmbed' ) )
	{
		document.getElementById( 'detailTabEmbed' ).style.display = 'none';
	}
	
	document.getElementById( 'detailTabEmailTitle' ).className = '';
	document.getElementById( 'detailTabReportTitle' ).className = '';
	document.getElementById( 'detailTabShareTitle' ).className = '';
	
	if ( document.getElementById( 'detailTabEmbedTitle' ) )
	{
		document.getElementById( 'detailTabEmbedTitle' ).className = '';
	}
	
	document.getElementById( 'processDetailResults' ).innerHTML = '';
}

function detailsTabShow( tabContentId )
{
	hideAlldetailTabs();
	
	content = document.getElementById( tabContentId );
	content.style.display = 'block';
	
	contentTitle = document.getElementById( tabContentId + 'Title' );
	contentTitle.className = 'current';
}

function processDetailsAction( url, action )
{
	hideAlldetailTabs();
	
	url = url + '/?event=' + action;
	
	document.getElementById( 'processDetailResults' ).innerHTML = 'Please wait ...';
	
	if ( action == 'report' )
	{
		url += '&dup=' + document.getElementById('dup').checked;
		url += '&inp=' + document.getElementById('inp').checked;
		url += '&crp=' + document.getElementById('crp').checked;
		url += '&url=' + document.getElementById('detailTabFieldURL').value;
		document.getElementById('dup').checked = false;
		document.getElementById('inp').checked = false;
		document.getElementById('crp').checked = false;
	}
	else if ( action == 'email' )
	{
		url += '&address=' + document.getElementById('detailTabFieldEmail').value;
		url += '&url=' + document.getElementById('detailTabFieldURL').value;
		document.getElementById('detailTabFieldEmail').value = '';
	}

	cbaUpdateElement('processDetailResults', url);
}

function showPanel( id )
{
	document.getElementById( id ).style.display = 'block';
}

function hidePanel( id )
{
	document.getElementById( id ).style.display = 'none';
}

function isShown( id )
{
	if ( document.getElementById( id ).style.display != 'none' )
	{
		return true;
	}
	
	return false;
}

function setCommentMessage( obj )
{
	if ( obj.value == 'Message' )
	{
		obj.value = '';
	}
}

function addCommentEmotion( objId, number )
{
	document.getElementById( objId ).value += ' :emo' + number + 'emo: ';
}

function submitContent( type, projectURL )
{
	if ( type != '' )
	{
		document.location = projectURL + 'submit' + type + '/';
	}
}

function validateData( type )
{
	if ( type == 'games' )
	{
		if ( document.getElementById('title').value == '' )
		{
			document.getElementById('title').style.border = '1px solid red';
			alert('Please fill in game title');
			return false;
		}
		
		if ( isShown('dynamicPanelURL') )
		{
			if ( ( document.getElementById('url').value == '' ) )
			{
				document.getElementById('url').style.border = '1px solid red';
				alert('Please fill in URL of web page');
				return false;
			}
		}
		
		if ( isShown('dynamicPanelUpload') )
		{
			if ( document.getElementById('gameFile').value == '' )
			{
				document.getElementById('gameFile').style.border = '1px solid red';
				alert('Please choose game\'s file');
				return false;
			}
		}
		
		if ( document.getElementById('screenshot').value == '' )
		{
			document.getElementById('screenshot').style.border = '1px solid red';
			alert('Please choose screenshot file');
			return false;
		}
		
		if ( document.getElementById('fdesc').value == '' )
		{
			document.getElementById('fdesc').style.border = '1px solid red';
			alert('Please fill in game\'s description');
			return false;
		}
	}
	
	if ( type == 'videos' )
	{
		if ( document.getElementById('title').value == '' )
		{
			document.getElementById('title').style.border = '1px solid red';
			alert('Please fill in video title');
			return false;
		}
		
		if ( !document.getElementById('fupl').checked && ( document.getElementById('url').value == '' ) )
		{
			document.getElementById('url').style.border = '1px solid red';
			alert('Please fill in URL of web page');
			return false;
		}
		
		setUploadRange(1);
	}
	
	if ( type == 'pranks' )
	{
		if ( document.getElementById('title').value == '' )
		{
			document.getElementById('title').style.border = '1px solid red';
			alert('Please fill in prank title');
			return false;
		}
		
		if ( isShown('dynamicPanelDescription') )
		{
			if ( document.getElementById('fdesc').value == '' )
			{
				document.getElementById('fdesc').style.border = '1px solid red';
				alert('Please fill in prank description');
				return false;
			}
		}
		
		if ( isShown('dynamicPanelContent') )
		{
			if ( document.getElementById('fcontent').value == '' )
			{
				/*
				document.getElementById('fcontent').style.border = '1px solid red';
				alert('Please fill in prank content');
				return false;
				*/
			}
		}
		
		if ( isShown('dynamicPanelURL') )
		{
			if ( (document.getElementById('url').value == '') )
			{
				document.getElementById('url').style.border = '1px solid red';
				alert('Please fill in prank URL');
				return false;
			}
		}
		
		if ( isShown('dynamicPanelUpload') )
		{
			if ( (document.getElementById('uploadFile').value == '') && ( document.getElementById('directURLFile').value == '' ) )
			{
				document.getElementById('uploadFile').style.border = '1px solid red';
				alert('Please choose a file to upload or specify direct URL');
				return false;
			}
		}
	}
	
	return true;
}

function submitContentForm( type, submitUploadURL, submitSiteUrl )
{
	if ( !validateData( type ) )
	{
		return;
	}
	
	form = document.getElementById('theform');
	
	if ( upload = document.getElementById('fupl') )
	{
		if ( upload.checked )
		{
			form.action = submitUploadURL;
			uploadFiles();
			return;
		}
	}
	
	form.action = submitSiteUrl;
	form.submit();
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}