
// settings
//	emailURL = "/ct/email.html?title=%%title%%&url=%%url%%";
//	printURL = "/ct/article_print.html?id=%%id%%";
	similarURL = "/ct/search.html?similar=%%url%%";
	
// channel load
//	function channelLoad()
//	{
		// TEMP - find 'related' section and apply style
//		var anchorArray = document.getElementsByTagName("a");
//		for (var i = 0; i < anchorArray.length; i++)
//		{
//			if (anchorArray[i].href.indexOf("#related") >= 0)
//			{
//				anchorArray[i].id = "relatedLink";
//				break;
//			}
//		}
//	}

// dropdown menus
	// NEWS menu
	menu["channel_news"] = [];
	menu["channel_news"][0] = '<a href="/ct/features/news/weblog/">Weblog</a>';
	menu["channel_news"][1] = '<a href="/ct/features/news/northamerica/unitedstates/">U.S.</a>';
	menu["channel_news"][2] = '<a href="/ct/features/news/africa/">Africa</a>';
	menu["channel_news"][3] = '<a href="/ct/features/news/asia/">Asia</a>';
	menu["channel_news"][4] = '<a href="/ct/features/news/centralamerica/">Central America</a>';
	menu["channel_news"][5] = '<a href="/ct/features/news/europe/">Europe</a>';
	menu["channel_news"][6] = '<a href="/ct/features/news/northamerica/">North America</a>';
	menu["channel_news"][7] = '<a href="/ct/features/news/oceania/">Oceania</a>';
	menu["channel_news"][8] = '<a href="/ct/features/news/southamerica/">South America</a>';
	menu["channel_news"][9] = '<a href="/ct/features/news/">All News</a>';
	
	// OPINION menu
	menu["channel_opinion"] = [];
	menu["channel_opinion"][0] = '<a href="/ct/features/opinion/editorials/">Editorials</a>';
	menu["channel_opinion"][1] = '<a href="/ct/features/opinion/columns/">Columns</a>';
	menu["channel_opinion"][2] = '<a href="/ct/features/opinion/speakingout/">Speaking Out</a>';
	menu["channel_opinion"][3] = '<a href="/ct/features/opinion/">All Opinion</a>';
	
	// BLOGS menu
	menu["channel_blogs"] = [];
	menu["channel_blogs"][0] = '<a href="http://blog.christianitytoday.com/ctliveblog/">CT Liveblog</a>';
	menu["channel_blogs"][1] = '<a href="http://blog.christianitytoday.com/ctpolitics/">CT Politics Blog</a>';
	menu["channel_blogs"][2] = '<a href="http://blog.christianitytoday.com/ctentertainment/">CT Entertainment Blog</a>';
	menu["channel_blogs"][3] = '<a href="http://blog.christianitytoday.com/women/">Women</a>';
	menu["channel_blogs"][4] = '<a href="/ct/feeds/">All RSS Feeds</a>';

	// REVIEWS menu
	menu["channel_reviews"] = [];
	menu["channel_reviews"][0] = '<a href="/ct/special/books.html">Books</a>';
	menu["channel_reviews"][1] = '<a href="/ct/movies/">Movies &amp; TV</a>';
	menu["channel_reviews"][2] = '<a href="/ct/music/">Music</a>';
	menu["channel_reviews"][3] = '<a href="/ct/features/reviews/othermedia/">Other Media</a>';
	
	// INDEX menu
	menu["channel_index"] = [];
	menu['channel_index'].push(
		'<a href="http://www.christianitytoday.com/thisisourcity/">This Is Our City</a>',
		'<a href="/ct/features/index/hotissues/">Hot Issues</a>',
		'<a href="/ct/features/index/faithandthought/">Faith &amp; Thought</a>',
		'<a href="/ct/features/index/churchesandministry/">Churches &amp; Ministry</a>',
		'<a href="/ct/features/index/cultureandtechnology/">Culture &amp; Technology</a>'
	);
	
	// ARCHIVES menu
	menu["channel_archives"] = [];
	menu["channel_archives"][0] = '<a href="/ct/archives/printissues.html">Browse by Print Issue</a>';
	// menu["channel_archives"][1] = '<a href="/ct/archives/">Browse by Posted Date</a>';
	
	// CONTACT US menu
	menu["channel_contact"] = [];
	menu["channel_contact"][0] = '<a href="/ct/help/contactus.html">Send Letter to the Editor</a>';
	menu["channel_contact"][1] = '<a href="/ct/help/contactus.html">Report a Problem</a>';
	menu["channel_contact"][2] = '<a href="http://www.christianitytoday.com/myaccount/">Subscription Service</a>';
	menu["channel_contact"][3] = '<a href="/ct/help/guidelines.html">Writers&#39; Guidelines</a>';
	menu["channel_contact"][4] = '<a href="/ct/help/info.html#permission">Reprint Permission</a>';
	menu["channel_contact"][5] = '<a href="/ct/help/info.html">About Christianity Today</a>';
	menu["channel_contact"][6] = '<a href="/ct/help/privacy.html">Privacy Policy</a>';

// rating functions
	function toggleEdit(currItem, editItem)	{
		if (document.getElementById) {	
			my_div = document.getElementById(currItem).style;
			my_div.display = (my_div.display == "none") ? "inline" : "none";	
			my_div = document.getElementById(editItem).style;
			my_div.display = (my_div.display == "inline") ? "none" : "inline";	
			return false;
		}
		else {				
			return true;
		}
	}
	
	function returnStar(hidestar, showstars, reminder, starimg, theRating, theForm)	{
		if (document.getElementById) {	
			my_vote = document.getElementById(hidestar).style;
			my_result = document.getElementById(showstars).style;
			my_reminder = document.getElementById(reminder).style;
			my_img = document.getElementById(starimg);
			my_reminder.display = (my_reminder.display === 'none') ? 'block': 'none';
			my_vote.display = (my_vote.display == "none") ? "block" : "none";
			my_result.display = (my_result.display == "block") ? "none" : "block";
			my_form = document.getElementById(theForm);
			
			switch(theRating) {
				case "1":
					my_img.src = "/ct/img/stars-1.gif";
					my_form.rating.value = '20';
					break;
				case "2":
					my_img.src = "/ct/img/stars-2.gif";
					my_form.rating.value = '40';
					break;
				case "3":
					my_img.src = "/ct/img/stars-3.gif";
					my_form.rating.value = '60';
					break;
				case "4":
					my_img.src = "/ct/img/stars-4.gif";
					my_form.rating.value = '80';
					break;
				case "5":
					my_img.src = "/ct/img/stars-5.gif";
					my_form.rating.value = '100';
					break;
				default:
					my_img.src = "/ct/img/stars-0.gif";
					my_form.rating.value = '0';
					break;
				}
			return false;
		}
		else {				
			return true;
		}
	}
	

	function validateDelete(theName){
		msg = confirm("Are you sure you want to delete the comment from " + theName + "?");
		if (msg==true) {
			return true;
		}
		return false;
	}	

	function validateUserDelete(){
		msg = confirm("Are you sure you want to delete your comment?");
		if (msg==true) {
			return true;
		}
		return false;
	}		
	
	function checkStarRate(theForm){
		if (theForm.rating.value == '0') {
			alert("Please select a Star Rating")
			return false;
		}
		return true;
	}

	var form_submitted = false;	
	
	function submitRateForm(theForm) {
		if (checkStarRate(theForm)) {
			if (form_submitted) {
				alert ("Your form has already been submitted. Please wait...");
				return false;
			} else {
				form_submitted = true;
				return true;
			}	
			return true;	
		} else {
			return false;
		}		
	}

// limit characters in a text area
	//
	// Usage:
	// <span id="limitText"><strong>1000</strong> characters remaining</span>
	// <textarea name="#" id="#" onkeyup="charCount(this,1000)" />
	//
	// Note: change limit of characters as needed
	//
	
	function charCount(what, maxCount) {
		var str = new String(what.value);
		var len = str.length;
		var limitSpan = document.getElementById('limitText');
		
		len = maxCount - len;
		
		if (document.getElementById) {	
			if (len < 0) {
				what.value = what.value.substring(0, maxCount);
			} else if (len > 1) {
				limitSpan.innerHTML = "<strong>" + len + "</strong> characters remaining";
			} else {
				limitSpan.innerHTML = "<strong>" + len + "</strong> character remaining";
			}
		}
	}
		
	function validateMessageBox() {
		var my_textarea = document.getElementById("message");
		if (my_textarea && my_textarea.value.length > 1000) {
			alert("Please limit your response to 1000 characters maximum.");
			return false;
		} else {
			return true;
		}
	}

	function stripURL(urlinput) { 
		urlString = new String(urlinput.value)
		strip_start = urlString.lastIndexOf('/');
		strip_end = urlString.length;
		strip_string = (urlString.substring(strip_start+1, strip_end)); 
		urlString ='http://christianitytoday.com/ct/comments/admin?url='+strip_string ;
		return(urlString);
		
	}
	
	function clearFilters()
		{
			var elements = document.getElementsByTagName("input");
			for (var i = 0; i < elements.length; i++)
			{
				if (elements[i].type == "checkbox" && elements[i].attributes.filter)
				{
					elements[i].checked = false;
				}
				if (elements[i].type == "radio" && elements[i].attributes.filter)
				{
					elements[i].checked = false;
				}
			}
			var element = document.getElementById("toneAny");
			if (element) element.checked = true;
		}
	
	function selectAll()
		{
			var elements = document.getElementsByTagName("input");
			for (var i = 0; i < elements.length; i++)
			{
				if (elements[i].type == "checkbox" && elements[i].attributes.filter)
				{
					elements[i].checked = true;
				}
				
			}
			var element = document.getElementById("toneAny");
			if (element) element.checked = true;
		}
		
		// This is a very simple function that will allow for basic AJAX functionality on the site.
		// The function is passed an object of options, with the following options available:
		// method: string; defaults to 'post'
		// url: string; which server file? defaults to current page
		// onRequest: function; what to do when the request is sent
		// onComplete: function; what to do when the request is completed
		// onSuccess: function; what to do when the request is completed and successful
		// onFailure: function; what to do when the request is completed but failed
		//
		// Usage:
		// var requester = request({
		//		method: 'get',
		//		url: '/path/to/file.html',
		//		onRequest: function() {
		//			// do something like display ajax loader
		//		},
		//		onSuccess: function(response) {
		//			// do something like display response
		//		},
		//		onFailure: function() {
		//			// do something like display error message
		//		}
		//	});
		var request = function(options) {
			var that = {},
				url = options.url || location.href,
				method = options.method.toLowerCase() || 'post',
				xhr, onStateChange;
				
			try {
				xhr = new XMLHttpRequest();
			} catch (e) {
				try {
					xhr = new ActiveXObject('MSXML2.XMLHTTP');
				} catch (e) {
					try {
						xhr = new ActiveXObject('Microsoft.XMLHTTP');
					} catch (e) {
						xhr = null;
					}
				}
			}
			
			onStateChange = function() {
				if (xhr.readyState !== 4) return;
				if (options.onComplete !== undefined) options.onComplete(xhr.responseText, xhr.responseXML);
				if (xhr.status === 200 || xhr.status === 304) {
					if (options.onSuccess !== undefined) options.onSuccess(xhr.responseText, xhr.responseXML);
				} else {
					if (options.onFailure !== undefined) options.onFailure(xhr.responseText, xhr.responseXML);
				}
			};
			
			that.send = function(data) {
				if (xhr) {
					if (data && (method === 'get' || method === 'put')) {
						url += (url.indexOf('?') !== -1 ? '&' : '?') + data;
						data = null;
					}
					
					if (method === 'post') xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xhr.open(method, url, true);
					xhr.onreadystatechange = onStateChange;
					if (options.onRequest !== undefined) options.onRequest();
					xhr.send(data);
				}
			};
			
			return that;
		};
		
		var yourRating = function (elem, i, id) {
			var classnames = ['halfstar', 'onestar', 'oneandhalfstar', 'twostar', 'twoandhalfstar', 'threestar', 'threeandhalfstar', 'fourstar', 'fourandhalfstar', 'fivestar'],
				contenttype = (location.href.indexOf('/movies/') === 1) ? 'movie' : 'album',
				requester = request({
					method: 'get',
					url: '/ct/channel/ajax/rate_media.html',
					onRequest: function() {
						var ul = elem.nodeName === 'A' ? elem.parentNode.parentNode : elem.parentNode;
						for (var j = 0, l = classnames.length; j < l; j += 1) {
							cti.removeClass(ul, classnames[j]);
						}
						cti.addClass(ul, classnames[i-1]);
					},
					onSuccess: function(response) {
						if (response.indexOf('<!-- Error: Invalid rating -->') === -1) {
							if (response.indexOf('<!-- User has already rated this article -->') === -1) {
								alert('Thank you! Your rating has been submitted.');
							} else {
								alert('Thank you! Your rating has been changed.');
							}
						} else {
							alert('There was an error with submitting your rating. Please try again later.');
						}
					}
				});
			
			requester.send('id=' + id + '&rating=' + i + '&type=' + contenttype);
		};
		


/* JavaScript below added by Vivin John (gP) */
window.addEvent('domready', function() {
	// for print page popup window
	smallWindow('.printPage', 700, 500);
	// for email page popup window
	smallWindow('.emailPage', 700, 500);
	// for login box
	if ($('loginUser')) {
		new Lightbox({
			elems: $$('.loginUserLink'),
			containerId: 'loginDiv',
			closeId: 'closeLightbox',
			url: '/ct/ajax/login.html?bck='+ $('loginUser').get('href'),
			onResponse: function(container, elems, i) { 
			//New InputClear($('loginForm').getElements('.clearField'));
			new InputClear('.clearInput'); // Will be applied to all elements with the class "clearInput".
			}
		});
	}
	// for slideshow
	if ($('headlines')) {
	var headlines = new Slideshow(('.headlinePanel'), {
		previous: 'previousPanel',
		pause: 'pausePanel',
		next: 'nextPanel',
		progressButton: true,
		onInit: function(slides, index) {
			 slides[index].retrieve('button').setStyle('background-position', 'bottom');
			slides.each(function(slide, i) {
				slide.retrieve('button').addEvents({
					'click': function(event) {
						event.preventDefault();
						headlines.display(false, i, true);
					},
					'mouseover': function(event) {
						event.preventDefault();
						headlines.display(false, i, true);
				
						if (i !== headlines.index) slide.retrieve('button').setStyle('background-position', 'bottom');
					},
					'mouseout': function() {
						if (i !== headlines.index) slide.retrieve('button').setStyle('background-position', 'top');
					}
				});
			});
	},
		onHide: function(slides) { 
			for (var i = 0, l = slides.length; i < l; i += 1) slides[i].retrieve('button').setStyle('background-position', 'top');
		},
		onShow: function(slides, index) { 
			slides[index].retrieve('button').setStyle('background-position', 'bottom');
		}
	});
	}
	//for right navigation tabs
	var ctiNavConsole = {
	mostReads: new AjaxTabs('#navConsoleTabs li', $('navConsole'), {
		urls: '/ct/ajax/console_tabs.html',
		onShow: function(tabs, containers, index) {
			for (var i = 0, l = tabs.length; i < l; i += 1) {
				if (i !== index) tabs[i].removeClass('showTab');
			}
			tabs[index].addClass('showTab');
		}
	}),
	shopping: new Tabs('#shoppingTabs li', [$('christianbook'), $('moreShopping')], {
		hideClass: 'hideElement',
		onShow: function(tabs, containers, index) {
			for (var i = 0, l = tabs.length; i < l; i += 1) {
				if (i !== index) tabs[i].removeClass('showTab');
			}
			tabs[index].addClass('showTab');
		}
	}),
	education: new AjaxTabs('#educationTabs li', $('education'), {
		urls: '/ct/ajax/console_tabs.html',
		onShow: function(tabs, containers, index) {
			var inputs = $('education').getElementsByTagName('input');
			for (var i = 0, l = tabs.length; i < l; i += 1) {
				if (i !== index) tabs[i].removeClass('showTab');
			}
			tabs[index].addClass('showTab');
			new InputClear(inputs[0]);
		}
	}),
	donate: new AjaxTabs('#donateAdvertiseTabs li', $('donateAdvertise'), {
		urls: '/ct/ajax/console_tabs.html',
		onShow: function(tabs, containers, index) {
			for (var i = 0, l = tabs.length; i < l; i += 1) {
				if (i !== index) tabs[i].removeClass('showTab');
			}
			tabs[index].addClass('showTab');
		}
	})
};
	ctiNavConsole.mostReads;
	ctiNavConsole.shopping;
	ctiNavConsole.education;
	ctiNavConsole.donate;
	//code for register thanks lightbox
	if ($('showthanks')){
	var registered =	new Lightbox({
			containerId: 'thanksDiv',
			url: '/ct/register/thanks.html',
			onResponse: function(container, elems, i) {
				//new InputClear($('loginForm').getElements('.clearField'));
			}
		});
	}
});

//for email
var emailNewURL = '/ct/email.html?title=%%title%%&url=%%url%%';
function emailPage(url){if (url != null){
			windowArray[windowArray.length] = window.open(url);
		}
		else
		{
			thisURL = emailNewURL.replace('%%title%%', escape(document.title)).replace('%%url%%', escape(pageURL));
			windowArray[windowArray.length] = window.open(thisURL, 'emailWindow', 'width=600,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');
		}
	}


