﻿function OptionOver(e) {
	if (e != null) {
		e.className = e.className.replace("_Off", "_On");
	}
}
function OptionOut(e) {
	if (e != null) {
		e.className = e.className.replace("_On", "_Off");
	}
}
function OptionClick(e) {
	var cb;
	for (var i = 0; i < e.childNodes.length; i++) {
		var n = e.childNodes[i];
		if (n.type == 'checkbox') {
			cb = n;
		}
	}
	if (cb) {
		cb.checked = !cb.checked;
		if (e.id == 'AllAges' ||
			e.id == 'AllCategories') {
			var parent = e.parentNode;
			for (var i = 0; i < parent.childNodes.length; i++) {
				ToggleFilterOption(parent.childNodes[i], cb.checked);
			}
		} else if (cb) {
			ToggleFilterOption(e, cb.checked);
		}
	}
}
function ToggleFilterOption(e, on) {
	var img;
	var cb;
	for (var i = 0; i < e.childNodes.length; i++) {
		var n = e.childNodes[i];
		if (n.type == 'checkbox') {
			cb = n;
		}
		if (n.tagName == 'IMG') {
			img = n;
		}
	}
	if (cb && img) {
		cb.checked = on;
		if (on) {
			e.onmouseover = '';
			e.onmouseout = '';
			e.className = e.className.replace("_off", "_on");
			img.src = img.src.replace('_off', '_on');
		} else {
			e.onmouseover = 'OptionOver(this);';
			e.onmouseout = 'OptionOut(this);';
			e.className = e.className.replace("_on", "_off");
			img.src = img.src.replace('_on', '_off');
		}
	}
}
function ToggleStateOn(id) {
	var img = document.getElementById(id);
	if (img) {
		img.src = img.src.replace("_off", "_on");
	}
}
function ToggleStateOff(id) {
	var img = document.getElementById(id);
	if (img) {
		img.src = img.src.replace("_on", "_off");
	}
}
function TopRatedClick() {
	HideElement('mostCommented');
	ShowElement('topRated');
}
function AgeFilterButtonClick() {
	var btn = document.getElementById('imgFilterByAge');
	if (btn) {
		btn.src = '/SiteCollectionImages/ChildrensSuccess/filters/age_filter_top.png';
		btn.onclick = AgeFilterClick;
	}
	ShowElement('ageFilter');
	return false;
}
function AgeFilterClick() {
	HideElement('ageFilter');
	var btn = document.getElementById('imgFilterByAge');
	if (btn) {
		btn.src = '/SiteCollectionImages/ChildrensSuccess/buttons/btn_filter_by_age.png';
		btn.onclick = AgeFilterButtonClick;
	}
	return false;
}
function CategoryFilterButtonClick() {
	var btn = document.getElementById('imgFilterByCategory');
	if (btn) {
		btn.src = '/SiteCollectionImages/ChildrensSuccess/filters/category_filter_top.png';
		btn.onclick = CategoryFilterClick;
	}
	ShowElement('categoryFilter');
	return false;
}
function CategoryFilterClick() {
	HideElement('categoryFilter');
	var btn = document.getElementById('imgFilterByCategory');
	if (btn) {
		btn.src = '/SiteCollectionImages/ChildrensSuccess/buttons/btn_filter_by_category.png';
		btn.onclick = CategoryFilterButtonClick;
	}
	return false;
}
function ShowSignInMessage() {
	ShowElement('SignInMessage');
	return false;
}
function HideSignInMessage() {
	HideElement('SignInMessage');
	return false;
}
function SignInClick(show, hide) {
	ShowElement(show);
	HideElement(hide);
	return false;
}
function SignInCloseClick(hide) {
	HideElement(hide);
	return false;
}
function PasswordRecoveryClick(show, hide) {
	HideElement(hide);
	ShowElement(show);
	return false;
}
function PasswordRecoveryCloseClick(show, hide) {
	HideElement(hide);
	ShowElement(show);
	return false;
}
function CreateAccountClick(show, hide) {
	ShowElement(show);
	HideElement(hide);
	return false;
}
function CreateAccountCloseClick(hide) {
	HideElement(hide);
	return false;
}
function MostCommentedClick() {
	HideElement('topRated');
	ShowElement('mostCommented');
}
function hide(element) {
	element.style.visibility = 'hidden';
	element.style.display = 'none';
}

function show(element) {
	element.style.visibility = 'visible';
	element.style.display = 'block';
}
function ShowElement(id) {
	var element = document.getElementById(id);
	if (element) {
		show(element);
	}
}
function HideElement(id) {
	var element = document.getElementById(id);
	if (element) {
		hide(element);
	}
}
function UploadPhoto_Click() {
	ShowElement('UploadPictureContainer');
	HideElement('EmbedVideoContainer');
}
function EmbedVideo_Click() {
	ShowElement('EmbedVideoContainer');
	HideElement('UploadPictureContainer');
}
function ToggleElementVisibility(id) {
	ToggleElementVisibility(id, false);
}
function ToggleElementVisibility(id, showFirst) {
	var element = document.getElementById(id);
	if (element) {
		alert(element.style.visibility);
		if (element.style.visibility == 'visible') {
			HideElement(id);
		} else if (element.style.visibility == 'hidden') {
			ShowElement(id);
		} else if (element.style.visibility == '') {
			showFirst ? ShowElement(id) : HideElement(id);
		}
	}
}
function SearchClick(e) {
	var searchInput = document.getElementById(e.id);
	if (searchInput.value == 'Search Stories') {
		searchInput.value = '';
	}
}
function ReportStory_Click() {
	return confirm('Are you sure you want to report this story?');
}
function DeleteStory_Click() {
	return confirm('Are you sure you want to delete this story?');
}
function ReportComment_Click() {
	return confirm('Are you sure you want to report this comment?');
}
function DeleteComment_Click() {
	return confirm('Are you sure you want to delete this comment?');
}
function RotateHeadlines() {
	var img = document.getElementById('imgHeadline');
	if (img) {
		if (img.src.indexOf('1.png') != -1) {
			img.src = img.src.replace('1.png', '2.png');
		} else if (img.src.indexOf('2.png') != -1) {
			img.src = img.src.replace('2.png', '3.png');
		} else if (img.src.indexOf('3.png') != -1) {
			img.src = img.src.replace('3.png', '1.png');
		}
	}
	setTimeout(RotateHeadlines, 3000);
}
function AlreadyLikeAlert() {
	alert('You already like this story');
	return false;
}
function OwnerLikeAlert() {
	alert('You can\'t like your own story');
	return false;
}
function OwnerReportAlert() {
	alert('You can\'t report your own story');
	return false;
}
function LoginToLikeAlert() {
	alert('Please login to like this story');
	return false;
}