function loadImages()
{
	tabs_home_hover = new Image();
	tabs_home_hover.src = '/images/header/tabs/tabs-home-hover.jpg';
	tabs_news_hover = new Image();
	tabs_news_hover.src = '/images/header/tabs/tabs-news-hover.jpg';
	tabs_live_hover = new Image();
	tabs_live_hover.src = '/images/header/tabs/tabs-live-hover.jpg';
	tabs_videos_hover = new Image();
	tabs_videos_hover.src = '/images/header/tabs/tabs-videos-hover.jpg';
	tabs_photos_hover = new Image();
	tabs_photos_hover.src = '/images/header/tabs/tabs-photos-hover.jpg';
	tabs_forums_hover = new Image();
	tabs_forums_hover.src = '/images/header/tabs/tabs-forums-hover.jpg';
	tabs_advertise_hover = new Image();
	tabs_advertise_hover.src = '/images/header/tabs/tabs-advertise-hover.jpg';
}

function checkWindowSize()
{
	//828 = 775 BG image + 38 Top Border + 15px Scroll Bar
	if (window.innerHeight > 828)
	{
		document.getElementById('background_image_left').style.position = 'fixed';
		document.getElementById('background_image_right').style.position = 'fixed';
		document.getElementById('background_image_left').style.top = '38px';
		document.getElementById('background_image_right').style.top = '38px';
	}
}

function tabHover(tabID,image,mode,currentTab,selectedTab)
{
	if (selectedTab == undefined || currentTab != selectedTab)
	{
		if (mode == 'hover')
		{
			document.getElementById(tabID).src = image;
		}
		else if (mode == 'out')
		{
			document.getElementById(tabID).src = image;
		}
	}
}

function showHideItem(id)
{
	if (!document.getElementById(id).style.display || document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

function noSpam(user,domain)
{
	locationstring = "mailto:" + user +	"@" + domain;
	window.location = locationstring;
}

function validateLogin(form)
{
	if (form.email.value != '' && form.password.value != '')
	{
		if (validateEmail(form.email.value) == false)
		{
			return false;
		}
		else
		{
			var params = 'email=' + form.email.value + '&password=' + form.password.value + '&remember_me=' + form.remember_me.value + '&url=' + form.url.value;
			checkLoginStatus(params);
			return false;
		}
	}
	else
	{
		alert('You must fill out all fields in the login box to continue.');
		return false;
	}
}

function validateEmail(email)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(email) == false)
	{
		alert('The e-mail address you entered is invalid.');
		return false;
	}
	else
	{
		return true;
	}
}

function changeInputType(oldObject,oType)
{
	var newObject = document.createElement('input');
	newObject.type = oType;
	if (oldObject.size) newObject.size = oldObject.size;
	newObject.setAttribute('value','');
	if (oldObject.name) newObject.name = oldObject.name;
	if (oldObject.maxlength) newObject.maxlength = oldObject.maxlength;
	if (oldObject.id) newObject.id = oldObject.id;
	if (oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	setTimeout(focusOnPassword,10);
	return newObject;
}

function focusOnPassword()
{
	document.getElementById('topbar_password_text').focus();
}

function checkLoginStatus(params)
{
	var loginRequest;
	try
	{
		//firefox, opera, safari, chrome
		loginRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			loginRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				loginRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	loginRequest.onreadystatechange = function()
	{
		if (loginRequest.readyState == 4)
		{
			var response = loginRequest.responseText.split("|",4);
			if (response[0] == 'failed')
			{
				alert('Login Failed: ' + response[1]);
			}
			else if (response[0] == 'success')
			{
				document.getElementById('login_confirmation_box').innerHTML = '<div class="page_title">Welcome back' + ((response[2] != '') ? ', ' + response[2] : '') + '!</div><br /><br />' + response[1];
				document.getElementById('body_container').style.opacity = .2;
				document.getElementById('body_container').filter = "alpha(opacity=20)";
				document.getElementById('login_confirmation_box').style.top = (window.innerHeight / 2 - 125) + 'px';
				document.getElementById('login_confirmation_box').style.left = (window.innerWidth / 2 - 250 - 7) + 'px';
				document.getElementById('login_confirmation_box').style.visibility = 'visible';
				var reload = setTimeout(function() { window.location.href = response[3]; },5000);
			}
			else
			{
				alert('Login Failed: An unknown error occured while you tried to log in.');
			}
		}
	}
	loginRequest.open("POST","/login/",true);
	loginRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	loginRequest.setRequestHeader("Content-length", params.length);
	loginRequest.setRequestHeader("connection", "close");
	loginRequest.send(params);
}

function logout()
{
	var logoutRequest;
	var params = 'logout=1';
	try
	{
		//firefox, opera, safari, chrome
		logoutRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			logoutRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				logoutRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	logoutRequest.onreadystatechange = function()
	{
		if (logoutRequest.readyState == 4)
		{
			var response = logoutRequest.responseText.split("|",3);
			if (response[0] == 'failed')
			{
				alert('Log Out Failed: ' + response[1]);
			}
			else if (response[0] == 'success')
			{
				document.getElementById('login_confirmation_box').innerHTML = '<div class="page_title">You have successfully logged out!</div><br /><br />' + response[1];
				document.getElementById('body_container').style.opacity = .2;
				document.getElementById('body_container').filter = "alpha(opacity=20)";
				document.getElementById('login_confirmation_box').style.top = (window.innerHeight / 2 - 125) + 'px';
				document.getElementById('login_confirmation_box').style.left = (window.innerWidth / 2 - 250 - 7) + 'px';
				document.getElementById('login_confirmation_box').style.visibility = 'visible';
				var reload = setTimeout(function() { window.location.href = response[2]; },5000);
			}
			else
			{
				alert('Log Out Failed: An unknown error occured while you tried to log out.');
			}
		}
	}
	logoutRequest.open("POST","/logout/",true);
	logoutRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	logoutRequest.setRequestHeader("Content-length", params.length);
	logoutRequest.setRequestHeader("connection", "close");
	logoutRequest.send(params);
}

function loadLeaderboardBanner()
{
	//number of seconds between banner refreshes
	bannerRefreshRate = 120;
	
	var xmlHttp;
	try
	{
		//firefox, opera, safari, chrome
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		
		if (xmlHttp.readyState == 4)
		{
			document.getElementById('header_banner').innerHTML = xmlHttp.responseText;
			setTimeout('loadLeaderboardBanner()',bannerRefreshRate * 1000);
		}
	}
	xmlHttp.open("GET","/adserver/banner_display.php?plan_type=content_pages_leaderboard_banner_01&width=728&height=90",true);
	xmlHttp.send(null);
}

function loadRightSideBanners(separator)
{
	var xmlHttp;
	try
	{
		//firefox, opera, safari, chrome
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		
		if (xmlHttp.readyState == 4)
		{
			document.getElementById('local_ads_120x60_right_side').innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","/adserver/banner_display.php?plan_type=static_banner_01&width=120&num_banners=15&separator=" + separator + "&height=60",true);
	xmlHttp.send(null);
	
	var xmlHttp2;
	try
	{
		//firefox, opera, safari, chrome
		xmlHttp2 = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	xmlHttp2.onreadystatechange = function()
	{
		if (xmlHttp2.readyState == 4)
		{
			document.getElementById('main_content_ad_column_0').innerHTML = xmlHttp2.responseText;
		}
	}
	xmlHttp2.open("GET","/adserver/banner_display.php?plan_type=content_pages_mini_banner_01&width=286&num_banners=2&separator=" + separator + "&height=60",true);
	xmlHttp2.send(null);
}

function printSection(printElement)
{
	if (document.getElementById != null)
	{
		//alert(document.getElementById(printElement).innerHTML);
		var css_property = (document.getElementById(printElement).className != '') ? ' class="' + document.getElementById(printElement).className + '"' : '';
		
		var html = '<html>\n<head>\n';
		
		var printHead = document.getElementById('print_head_contents');
		if (printHead != null)
		{
			html += printHead.innerHTML;
		}
		else
		{
			alert("ERROR: Could not detect the header info to print. Try printing the whole page.");
			return;
		}
		
		html += '\n</head>\n<body style="background-color: #ffffff;">\n\n';
		html += '<div id="print_window">\n';
		html += '<img src="/images/liverc_logo_350x78.jpg" width="350" height="78" alt="LiveRC.com" title="LiveRC.com" /><br /><br />\n\n';

		var printReadyElem = document.getElementById(printElement);
		if (printReadyElem != null)
		{
			var content = printReadyElem.innerHTML;
			var content1 = content.substr(0,content.indexOf('<!-- start sharing icons container -->'));
			var content2 = content.substr(content.indexOf('<!-- end sharing icons container -->') + 36);
			
			html += content1;
			html += content2;
		}
		else
		{
			alert("ERROR: Could not detect the main content area to print. Try printing the whole page.");
			return;
		}

		html += '\n</div>\n';
		html += '\n</body>\n</html>';

		var printWin = window.open('','_blank');
		var doc = printWin.document.open();
		doc.write(html);
		doc.close();
		printWin.print();
		printWin.close();
	}
	else
	{
		alert("The print ready feature is only available if you are using a newer web browser. Please update your browswer.");
	}
}

  /*****************/
 /* USER COMMENTS */
/*****************/
var newCommentNum = 0;
function validateCommentPost(form)
{
	if (form.comment.value != '' && form.item_id.value != '' && form.item_id.value > 0 && form.item_type.value != '')
	{
		var params = 'comment=' + form.comment.value + '&item_id=' + form.item_id.value + '&item_type=' + form.item_type.value;
		form.comment.disabled = true;
		form.button.disabled = true;
		document.getElementById('comment_loading_info').style.display = 'block';
		postComment(params,form);
		return false;
	}
	else
	{
		alert('You must fill out all fields in the comments box to continue.');
		return false;
	}
}

function postComment(params,form)
{
	var postCommentRequest;
	try
	{
		//firefox, opera, safari, chrome
		postCommentRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		//internet explorer
		try
		{
			postCommentRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				postCommentRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//browser does not suppoer ajax
				return false;
			}
		}
	}
	
	postCommentRequest.onreadystatechange = function()
	{
		if (postCommentRequest.readyState == 4)
		{
			var response = postCommentRequest.responseText.split("|",4);
			if (response[0] == 'failed')
			{
				alert('ERROR: ' + response[1]);
			}
			else if (response[0] == 'success')
			{
				form.comment.value = '';
				
				var commentsDiv = document.getElementById('all_comments');
				newCommentNum++;
				var newElementID = 'new_comment_' + newCommentNum;
				var newComment = document.createElement('div');
				newComment.innerHTML = response[1];
				newComment.setAttribute('id',newElementID);
				newComment.setAttribute('class','comments_container');
				newComment.setAttribute('style','display: none;');
				commentsDiv.insertBefore(newComment,commentsDiv.firstChild);
				Effect.Appear(newElementID,{duration: 2.0});
			}
			else
			{
				alert('ERROR: An unknown error occured while you tried to post a comment.');
			}
			form.comment.disabled = false;
			form.button.disabled = false;
			document.getElementById('comment_loading_info').style.display = 'none';
		}
	}
	postCommentRequest.open("POST","/post_comment/",true);
	postCommentRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	postCommentRequest.setRequestHeader("Content-length", params.length);
	postCommentRequest.setRequestHeader("connection", "close");
	postCommentRequest.send(params);
}
/*****************/

  /****************/
 /* NAVLINK MENU */
/****************/
var menuTimeout = 500;
var menuCloseTimer = 0;
var menuItem = 0;
document.onclick = menuClose;

function menuOpen(id)
{
	menuCancelCloseTime();
	if (menuItem)
	{
		menuItem.style.visibility = 'hidden';
	}
	menuItem = document.getElementById('menu_' + id);
	menuItem.style.visibility = 'visible';
}

function menuClose()
{
	if (menuItem)
	{
		menuItem.style.visibility = 'hidden';
	}
}

function menuCloseTime()
{
	menuCloseTimer = window.setTimeout(menuClose,menuTimeout);
}

function menuCancelCloseTime()
{
	if (menuCloseTimer)
	{
		window.clearTimeout(menuCloseTimer);
		menuCloseTimer = null;
	}
}
/****************/
