/* http://www.desertdispatch.com/common/tools/load.php?js=common_sitelife,common_sitelife-registration */
		function submitRequest() {   
			
            pullCounts(articleid);

        }

		function pullCounts(articlekey) {

            var articleKey = new ArticleKey(articlekey);   

            var requestBatch = new RequestBatch();   

            requestBatch.AddToRequest(articleKey);    

            requestBatch.BeginRequest(serverUrl, renderArticle);    

        }  

           

        function renderArticle(responseBatch) { 

            if (responseBatch.Responses.length == 0) {    

				var commentCount = document.getElementById('articleCommentCount' + articleid);   

                var recommendCount = document.getElementById('articleRecommendCount' + articleid);   

                // update page elements  

				commentCount.style.visibility = 'hidden';

				recommendCount.style.visibility = 'hidden'; 

                commentCount.innerHTML = 0;   

                recommendCount.innerHTML = 0;

            } else {   

                // get article from response   

                var article = responseBatch.Responses[0].Article;

                // get page elements   

                var commentCount = document.getElementById('articleCommentCount' + article.ArticleKey.Key);   

                var recommendCount = document.getElementById('articleRecommendCount' + article.ArticleKey.Key);

                // update page elements   

                commentCount.innerHTML = article.Comments.NumberOfComments;   

                recommendCount.innerHTML = article.Recommendations.NumberOfRecommendations;

				var isRecommended = article.Recommendations.CurrentUserHasRecommended;

				if(isRecommended == "True") {

					var recommendLink = document.getElementById('recommendlink' + article.ArticleKey.Key);

					recommendLink.innerHTML = "<span class='Article_Recommended'>Recommended</span>";

				}

				commentCount.style.visibility = 'visible';

				recommendCount.style.visibility = 'visible';

            }   

        }

		function recommendReview(key) {  
		
			var requestBatch = new RequestBatch();   

            var articleKey = new ArticleKey(key);   

            var recommendAction = new RecommendAction(articleKey);   

            requestBatch.AddToRequest(recommendAction);    

            requestBatch.BeginRequest(serverUrl, recommendationComplete);     

        }   

           

        function recommendationComplete(responseBatch) {
            if(responseBatch.Responses.length > 0) {

                submitRequest();
			}
			else {
				//alert('did not exist');
				updateArticle();	
			}

        }


		function updateArticle() {   

            // get form elements and page info   

            var articleKey = new ArticleKey(articleid);   

            var pageUrl = document.location.href;
			
			var section = new Section(sectionTitle);
			
			var categories = new Array();

  

            // create and send request   

            var requestBatch = new RequestBatch();               

            var updateAction = new UpdateArticleAction(articleKey, pageUrl, pageTitle, section);   

            requestBatch.AddToRequest(updateAction);    

            requestBatch.BeginRequest(serverUrl, articleUpdated);    

        }   

           

        function articleUpdated(responseBatch) {   

            if (responseBatch.Messages[0].Message == 'ok') {   
                  submitRequest();
				  //recommendReview(articleid);

            } 

        }
		
		function recommendReviewAbox(key) {

            var requestBatch = new RequestBatch();   

            var articleKey = new ArticleKey(key);   

            var recommendAction = new RecommendAction(articleKey);   

            requestBatch.AddToRequest(recommendAction);    

            requestBatch.BeginRequest(serverUrl, recommendationCompleteAbox); 

        }
		
		function recommendationCompleteAbox(responseBatch) { 

                	SubmitListRequest();

        }
		
		function recommendReviewList(key) {

            var requestBatch = new RequestBatch();   

            var articleKey = new ArticleKey(key);   

            var recommendAction = new RecommendAction(articleKey);   

            requestBatch.AddToRequest(recommendAction);    

            requestBatch.BeginRequest(serverUrl, recommendationCompleteList); 

        }   

           

        function recommendationCompleteList(responseBatch) { 

                	getRecentActivity();

        }
		
		function getRecentActivity() {
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var activity = new Activity("Commented");
			var age = 2;
			var numItemsToGet = 5;
			
			if(cacheMostCommentedRecommended) {
				renderRecentContent(cacheMostCommentedRecommended.ResponseBatch, 5);  				
			}
			else {
				var requestBatch = new RequestBatch();
				var discoveryAction = new DiscoverArticlesAction(sections, categories, contributors, activity, age, numItemsToGet);
				requestBatch.AddToRequest(discoveryAction);
				requestBatch.BeginRequest(serverUrl, renderRecentContent, 5);
			}
		}
		
		function renderRecentContent(responseBatch, numItemsToGet) { 
		       
             if (responseBatch.Responses.length >= 1) {
                 var discoveryAction = responseBatch.Responses[0].DiscoverArticlesAction;
				if(!numItemsToGet) {
					numItemsToGet = discoveryAction.DiscoveredArticles.length;
				}
				else if(numItemsToGet > discoveryAction.DiscoveredArticles.length) {
					numItemsToGet = discoveryAction.DiscoveredArticles.length;
				}

                 var recentList = document.getElementById('mostcommented_list');
			
				 if(recentList) {
                 	var recentHTML = "<ul>";  
                 	for (var i = 0; i < numItemsToGet; i++) {
                     	recentHTML += getArticleLink(discoveryAction.DiscoveredArticles[i]);  
                 	}  
				 	recentHTML += "</ul>";
                 	recentList.innerHTML = recentHTML;
				 }
             }  
         }
           
         function getArticleLink(article) {
			 
			 var hashes = article.PageUrl.split('#');
			 var commentLink = hashes[0]+"#slComments";

             var html = "<li><a href='" + article.PageUrl + "' class='article_list_title'>" + unescape(article.PageTitle) + "</a><br>";
			 html += "<span id='commentsummary'><a href='" + commentLink + "' class='Article_Comment'>Comments <span id='articleCommentCount' class='Article_Comment_Count'>" + article.Comments.NumberOfComments + "</span></a></span> | ";
			 
			 if(article.Recommendations.CurrentUserHasRecommended == "True") {
				 html += "<span id='recommendations'><span id='recommendlink'><span class='Article_Recommended'>Recommended</span></span><span id='articleRecommendCount' class='Article_Recommend_Count'>" + article.Recommendations.NumberOfRecommendations + "</span></span>";
				// html += "<span id='recommendations'><span id='recommendlink'><span class='Article_Recommended'><a href='" + article.PageUrl +"' class='Article_Recommend_Count'>Recommended</a></span></span><span id='articleRecommendCount' class='Article_Recommend_Count'>" + article.Recommendations.NumberOfRecommendations + "</span></span>";
			 }
			 else {
			 	
				html += "<span id='recommendations'><span id='recommendlink'><a href='" + hashes[0] + "'  class='Article_Recommend'>Recommend </a></span><span id='articleRecommendCount' class='Article_Recommend_Count'>" + article.Recommendations.NumberOfRecommendations + "</span></span>";
				
				//html += "<span id='recommendations'><span id='recommendlink'><a href=\"#\" onclick='recommendReviewList(\"" + article.ArticleKey.Key + "\")' class=\"Article_Recommend\">Recommend </a></span><span id='articleRecommendCount' class='Article_Recommend_Count'>" + article.Recommendations.NumberOfRecommendations + "</span></span>";
				
			 }
			 html += "</li>\n";
             return html;  
         }  
		 
		 function getMostCommentedArticle() {
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var activity = new Activity("Commented");
			var age = 2;
			var numItemsToGet = 5;

			var requestBatch = new RequestBatch();
			var discoveryAction = new DiscoverArticlesAction(sections, categories, contributors, activity, age, numItemsToGet);
			requestBatch.AddToRequest(discoveryAction);
			requestBatch.BeginRequest(serverUrl, renderMostCommentedArticle);
		}
		
		
		
		function renderMostCommentedArticle(responseBatch) {  
             if (responseBatch.Responses.length == 1) {
                 var discoveryAction = responseBatch.Responses[0].DiscoverArticlesAction;
                 var recentList = document.getElementById('mostcommented_list_article');  
				 if(recentList) {
                 	var recentHTML = ""; 
                 	for (var i = 0; i < discoveryAction.DiscoveredArticles.length; i++) {
						if(discoveryAction.DiscoveredArticles[i])
						{
                    	 recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]);  
						}
                 	}  
                 	recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
				 }
             }
         }  
           
         function getArticleLinkArticle(article) { 
		 	 
              if(unescape(article.PageTitle) == "null")
			  {				 
				 return '';
			  }
			  else
			  {			  
			     var html = "<li><a href='" + article.PageUrl + "'>" + unescape(article.PageTitle) + "</a>";
				 html += "</li>\n";
				 return html; 		  
			  }
         }
		 
		 function getMostRecommendedArticle() {
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var activity = new Activity("Recommended");
			var age = 2;
			var numItemsToGet = 5;
			
			var requestBatch = new RequestBatch();
			var discoveryAction = new DiscoverArticlesAction(sections, categories, contributors, activity, age, numItemsToGet);
			requestBatch.AddToRequest(discoveryAction);
			requestBatch.BeginRequest(serverUrl, renderMostRecommendedArticle);
		}
		
		function renderMostRecommendedArticle(responseBatch) {  
             if (responseBatch.Responses.length == 1) {
                 var discoveryAction = responseBatch.Responses[0].DiscoverArticlesAction;
                 var recentList = document.getElementById('mostrecommended_list_article');  
				 if(recentList) {
                 	var recentHTML = "";  
                 	for (var i = 0; i < discoveryAction.DiscoveredArticles.length; i++) {  
						if(discoveryAction.DiscoveredArticles[i])
						{
                     		recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]);  
						}
                 	}  
                 	recentList.innerHTML = "<ul>" + recentHTML + "</ul>";  
				 }
             }  
         }
		 
		 var aboxMostCommented = new Array();
		 var aboxMostRecommended = new Array();
		 function getMostCommentedRecommendedArticleList(numItemsToGet) {
			 
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var commentactivity = new Activity("Commented");
			var recommendactivity = new Activity("Recommended");
			var age = 2;
			if(!numItemsToGet) {
				numItemsToGet = 5;
			}

			if(cacheMostCommentedRecommended) {
				renderMostCommentedArticle(cacheMostCommentedRecommended.ResponseBatch, numItemsToGet);
			}
			else {
				var requestBatch = new RequestBatch();
				var commentdiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, commentactivity, age, numItemsToGet);
				var recommendeddiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, recommendactivity, age, numItemsToGet);
				requestBatch.AddToRequest(commentdiscoveryAction);
				requestBatch.AddToRequest(recommendeddiscoveryAction);
				requestBatch.BeginRequest(serverUrl, renderMostCommentedArticle);
			}
			
		}
		
				            

		 
		 function getMostCommentedRecommendedArticleList2(numItemsToGet) {
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var commentactivity = new Activity("Commented");
			var recommendactivity = new Activity("Recommended");
			var age = 2;
			if(!numItemsToGet) {
				numItemsToGet = 3;
			}

			var requestBatch = new RequestBatch();
			var commentdiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, commentactivity, age, numItemsToGet);
			var recommendeddiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, recommendactivity, age, numItemsToGet);
			requestBatch.AddToRequest(commentdiscoveryAction);
			requestBatch.AddToRequest(recommendeddiscoveryAction);
			requestBatch.BeginRequest(serverUrl, renderMostCommentedArticle);
		}

		

		
		function renderMostCommentedArticle(responseBatch, numItemsToGet) {
             if (responseBatch.Responses.length >= 1) {
                 var discoveryAction = responseBatch.Responses[0].DiscoverArticlesAction;
				 if(!numItemsToGet) {
					numItemsToGet = 5;
				}
				if(numItemsToGet > discoveryAction.DiscoveredArticles.length) {
					numItemsToGet = discoveryAction.DiscoveredArticles.length;
				}
				
				 if(aboxMostCommented.length >= 1) {
					 for(var i = 0; i < aboxMostCommented.length; i++) {
						 var recentList = document.getElementById(aboxMostCommented[i]);  
						 if(recentList) {
                 		 	var recentHTML = ""; 
                 		 	for (var j = 0; j < numItemsToGet; j++) {
								if(discoveryAction.DiscoveredArticles[j])
								{
                     			  recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[j]);  
								}
                 		 	}  
                 		 	recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
						 }
					 }
				 }
				 else {
                 	var recentList = document.getElementById('mostcommented_list_article'); 
					if(recentList) {
                 		var recentHTML = ""; 
                 		for (var i = 0; i < numItemsToGet; i++) {
							if(discoveryAction.DiscoveredArticles[i])
							{
                     		  recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]); 
							}
                 		}  
                 		recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
					}
				 }
             }
			 if (responseBatch.Responses.length >= 2) {
				 var discoveryAction = responseBatch.Responses[1].DiscoverArticlesAction;
				 if(!numItemsToGet) {
					numItemsToGet = 5;
				}
				if(numItemsToGet > discoveryAction.DiscoveredArticles.length) {
					numItemsToGet = discoveryAction.DiscoveredArticles.length;
				}
				
				 if(aboxMostRecommended.length >= 1) {
					 for(var i = 0; i < aboxMostRecommended.length; i++) {
					 	var recentList = document.getElementById(aboxMostRecommended[i]);  
						if(recentList) {
                 			var recentHTML = "";  
                 			for (var j = 0; j < numItemsToGet; j++) { 
							   if(discoveryAction.DiscoveredArticles[j])
							   {
                     			recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[j]);  
							   }
                 			}  
                 			recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
						}
					 }
				 }
				 else {
                 	var recentList = document.getElementById('mostrecommended_list_article'); 
					if(recentList) {
                 		var recentHTML = "";  
                 		for (var i = 0; i < numItemsToGet; i++) { 
						   if(discoveryAction.DiscoveredArticles[i])
						   {
                     		recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]);
						   }
                 		}  
                 		recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
					}
				 }
			 } 
         }

				/*
				* Common function to process all responses in a batch
				* 
				* responseBatch - batch of items to process
				* numiItems     - array of integers identifying the maximum number
				*                 of items to display for each response in the batch
				*                 (max = 10)
				*                 numItems = [5,3];
				* divIds        - multidimensional array of divIds to put the response
				*                 source into. Each item in this list can either be a
				*                 string (a single element) or a list of strings
				*                 (indicating multiple elements) to receive the source
				*                 load into Recommended and skip Commented:
				*                 divIds = ['',recommendedDivs];
				*/
			function pluckProcessResponseBatch(responseBatch,responseType,numItems,divIds) {
				var loopCount=0;

				// Determine number of times to loop based on number of responses in batch and number of divIds
				if (responseBatch.Responses.length > divIds.length)
					loopCount= divIds.length;
				else
					loopCount= responseBatch.Responses.length;

				for (var i=0; i < loopCount; i++) {
					var renderAction = responseBatch.Responses[i]["Discover"+responseType+"Action"];
					var divId = divIds[i];
					var numItemsUsed = (renderAction["Discovered"+responseType].length < numItems[i]) ? renderAction["Discovered"+responseType].length : numItems[i];

					// generate content for div
					var out = "<ul>";
					for (var j = 0; j < numItemsUsed; j++) {  
						out += getArticleLinkArticle(renderAction["Discovered"+responseType][j]);  
					}
					out += "</ul>";

					//determine if divId is array of divIds. If so insert html (out) into each divId
					if (typeof(divId)=='string') {
						var docEl = document.getElementById(divId);
						if (docEl)
							docEl.innerHTML = out;
					} else {
						for (var k = 0; k < divId.length; k++) {  
							var docEl = document.getElementById(divId[k]);
							if (docEl)
								docEl.innerHTML = out;
						}
					}
				}
			}
		 
		 function renderMostCommentedArticle(responseBatch, numItemsToGet) {
                          
			    if (responseBatch.Responses.length >= 1) { 
                 var discoveryAction = responseBatch.Responses[0].DiscoverArticlesAction;
				 if(!numItemsToGet) {
					numItemsToGet = 5;
				}
				var numItemsToUse;
				if(numItemsToGet > discoveryAction.DiscoveredArticles.length)
					numItemsToUse = discoveryAction.DiscoveredArticles.length;
				else
					numItemsToUse = numItemsToGet;
				
				 if(aboxMostCommented.length >= 1) {
					 for(var i = 0; i < aboxMostCommented.length; i++) {
						 var recentList = document.getElementById(aboxMostCommented[i]);  
						 if(recentList) {
                 		 	var recentHTML = ""; 
                 		 	for (var j = 0; j < numItemsToUse; j++) { 
							   if(discoveryAction.DiscoveredArticles[j])
							   {
                     				recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[j]);  
							   }
							}
                 		 	recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
						 }
					 }
				 }
				 else {
                 	var recentList = document.getElementById('mostcommented_list_article'); 
					if(recentList) {
                 		var recentHTML = ""; 
                 		for (var i = 0; i < numItemsToUse; i++) {
							if(discoveryAction.DiscoveredArticles[i])
							{
                     		  recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]);  
							}
                 		}  
                 		recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
					}
				 }
             }
			 if (responseBatch.Responses.length >= 2) {
				 var discoveryAction = responseBatch.Responses[1].DiscoverArticlesAction;
				 if(!numItemsToGet) {
					numItemsToGet = 5;
				}
				if(numItemsToGet > discoveryAction.DiscoveredArticles.length)
					numItemsToUse = discoveryAction.DiscoveredArticles.length;
				else
					numItemsToUse = numItemsToGet;
				
				 if(aboxMostRecommended.length >= 1) {
					 for(var i = 0; i < aboxMostRecommended.length; i++) {
					 	var recentList = document.getElementById(aboxMostRecommended[i]);  
						if(recentList) {
                 			var recentHTML = "";  
                 			for (var j = 0; j < numItemsToUse; j++) { 
							   if(discoveryAction.DiscoveredArticles[j])
							   {
                     			  recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[j]);  
							   }
                 			}  
                 			recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
						}
					 }
				 } 
				 else {
                 	var recentList = document.getElementById('mostrecommended_list_article'); 
					if(recentList) {
                 		var recentHTML = "";  
                 		for (var i = 0; i < numItemsToGet; i++) { 
						  if(discoveryAction.DiscoveredArticles[i])
						  {
                     		recentHTML += getArticleLinkArticle(discoveryAction.DiscoveredArticles[i]);  
						  }
                 		}  
                 		recentList.innerHTML = "<ul>" + recentHTML + "</ul>";
					}
				 }
			 }
         }
		 
		 
		 
		 
		 
		 function isLoggedIn() {
			var ocCookies = document.cookie.split( ';' );
			var tempCookie = "";
			for(i=0; i < ocCookies.length; i++) {
				tempCookie = ocCookies[i].split('=');
				cookie_name = tempCookie[0].replace(/^\s+|\s+$/g, '');
				
				if(cookie_name == "at") {
					return true;
				}
			}
			return false;
		 }
		 
		 
		 function slLogout() {
			var cookie_date = new Date(2000, 01, 01);
			var ocCookies = document.cookie.split( ';' );
						var tempCookie = "";
			var domainName=window.document.domain;
			//alert(domainName);
            //var nameparts = domainName.split( '.' );
            //domainName=nameparts[1]+"."+nameparts[2];
			//alert(domainName);
			var found = false;
			for(i=0; i < ocCookies.length; i++) {
				tempCookie = ocCookies[i].split('=');
				cookie_name = tempCookie[0].replace(/^\s+|\s+$/g, '');
				
				if(cookie_name == "at" || cookie_name == "free_ak" || cookie_name == "free_prof" || cookie_name == "freeAuth") {
					document.cookie = cookie_name + "=;	expires=" + cookie_date.toGMTString() + "; path=/; domain=."+domainName+";";
					found = true;
				}
			}
			//if(found) location.reload(true); 
			if(found) location = "/";
		 }
		 
		 function changeWidgetLinks() {
			var commentsFrame = document.getElementById('commentsiframe');
			var login_text = "You must be logged in to contribute. <a href=\"javascript:parent.scroll(0,0);parent.show_login()\">Login</a> | <a href='javascript:parent.scroll(0,0);parent.show_registration()'>Register</a>";
			if(commentsFrame) {
				var sl_login_text = commentsFrame.contentWindow.document.getElementById('SiteLife_Login');
				if(sl_login_text) {
					sl_login_text.innerHTML = login_text;
				}
			}
			
			var messagesFrame = document.getElementById('messagesiframe');
			if(messagesFrame) {
				var sl_login_text = messagesFrame.contentWindow.document.getElementById('Messages_NewMessageHead');
				if(sl_login_text) {
					sl_login_text.innerHTML = login_text;
				}
			}
			
			var personaFrame = document.getElementById('personaprofileiframe');
			 if(personaFrame) {
				 //personaFrame.style.width = "600px";
				 var editLink = personaFrame.contentWindow.document.getElementById('ProfileEdit_SectionDescription_Link');
				 editLink.style.display = "none";
			 }
		 }
		 
		 function LoginPage() {
			var domainName=window.document.domain
			var login_link = "http://www." + domainName + "/sections/share/users/login";
			window.location.href = login_link;
		 }
		 
		 function RegPage() {
			var domainName=window.document.domain
			var reg_link = "http://www." + domainName + "/sections/share/users/register";
			window.location.href = reg_link;
		 }
		 
		 function changePluckLoginLinks() {
			if(!isLoggedIn()) {
			var login_link = "javascript:parent.LoginPage()";
			var reg_link = "javascript:parent.RegPage()";
			var commentsFrame = document.getElementById('commentsiframe');
			var login_text = "You must be logged in to contribute. <a href=\"" + login_link + "\">Login</a> | <a href='" + reg_link + "'>Register</a>";
			if(commentsFrame) {
				var sl_login_text = commentsFrame.contentWindow.document.getElementById('SiteLife_Login');
				if(sl_login_text) {
					sl_login_text.innerHTML = login_text;
				}
			}
			
			var messagesFrame = document.getElementById('messagesiframe');
			if(messagesFrame) {
				var sl_login_text = messagesFrame.contentWindow.document.getElementById('Messages_NewMessageHead');
				if(sl_login_text) {
					sl_login_text.innerHTML = login_text;
				}
			}
			
			var personaFrame = document.getElementById('personaprofileiframe');
			 if(personaFrame) {
				 //personaFrame.style.width = "600px";
				 var editLink = personaFrame.contentWindow.document.getElementById('ProfileEdit_SectionDescription_Link');
				 editLink.style.display = "none";
			 }
			 
			 	var login_btn = document.getElementById('CreateDiscussion1');
				var login_btn2 = document.getElementById('CreateDiscussion2');
				var reg_btn = document.getElementById('A1');
				var add_post_btn = document.getElementById('ForumDiscussionAddPost');
				if(login_btn) {
					login_btn.href = login_link;	
				}
				if(login_btn2) {
					login_btn2.href = login_link;	
				}
				if(reg_btn) {
					reg_btn.href = reg_link;
					reg_att = reg_btn.attributes;
					for(i=0;i<reg_att.length;i++) {
						if(reg_att[i].name == "onclick") {
							reg_att[i].value = reg_link;
						}
					}
				}
				if(add_post_btn) {
					add_post_btn.href = login_link;	
				}
			 
			}
		 }
		 
		 function changeForumLinks() {
			if(!isLoggedIn()) {
				var login_btn = document.getElementById('CreateDiscussion1');
				var login_btn2 = document.getElementById('CreateDiscussion2');
				var reg_btn = document.getElementById('A1');
				var add_post_btn = document.getElementById('ForumDiscussionAddPost');
				if(login_btn) {
					login_btn.href = "javascript:scroll(0,0);show_login();";	
				}
				if(login_btn2) {
					login_btn2.href = "javascript:scroll(0,0);show_login();";	
				}
				if(reg_btn) {
					reg_btn.href = "javascript:scroll(0,0);show_registration();";
					reg_att = reg_btn.attributes;
					for(i=0;i<reg_att.length;i++) {
						if(reg_att[i].name == "onclick") {
							reg_att[i].value = "scroll(0,0);show_registration();";
						}
					}
				}
				if(add_post_btn) {
					add_post_btn.href = "javascript:scroll(0,0);show_login();";	
				}
			}

		 }
		 
		 function createArticle(articleid, pageUrl, pageTitle, sectionTitle) { 

            // get form elements and page info   

            var articleKey = new ArticleKey(articleid);
			
			var section = new Section(sectionTitle);
			
			var categories = new Array();

            // create and send request   

            var requestBatch = new RequestBatch();               

            var updateAction = new UpdateArticleAction(articleKey, pageUrl, pageTitle, section);   

            requestBatch.AddToRequest(updateAction);    

            requestBatch.BeginRequest(serverUrl, articleCreated);    

        }   

	


           

        function articleCreated(responseBatch) {   
            if (responseBatch.Messages[0].Message == "ok") {   
            } 

        }
		
/****start of james edit 2/29 */ 
		// Fetch a cookie.
		function getCookieVal (offset) {
		  var endstr = document.cookie.indexOf (";", offset);
		  if (endstr == -1)
			endstr = document.cookie.length;
		  return unescape(document.cookie.substring(offset, endstr));
		}
		function GetCookie (name) {
		  var arg = name + "=";
		  var alen = arg.length;
		  var clen = document.cookie.length;
		  var i = 0;
		  while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
			  return getCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0)
			  break;
		  }
		  return null;
		}

		// read based off cookie
		function getUserInfoCookie() {
			uuId = "";
			var cookie_value = GetCookie('at');
			if(cookie_value)
			{
				var cookie_values = cookie_value.split('&'); 
				at = ''; 
				for(x = 0; x < cookie_values.length; x++)
				{
					if(cookie_values[x].indexOf('u=') >= 0)
					{
						userkey = cookie_values[x];
						
						uuId = userkey.substring(2,userkey.length); 
						break;
					}
				}
				//alert('logged in. userkey = ' + userkey);
			}
			//else
				//alert('not logged in ');
				
			
			if(uuId != "") {
				var userKey = new UserKey(uuId);
				var requestBatch = new RequestBatch();
				requestBatch.AddToRequest(userKey);
				requestBatch.BeginRequest(serverUrl, renderUserData);
			}
		}

/*****/
		function getUserInfo(uuId) {
			if(uuId != "" && uuId != "anonymous") {
				var userKey = new UserKey(uuId);
				var requestBatch = new RequestBatch();
				requestBatch.AddToRequest(userKey);
				requestBatch.BeginRequest(serverUrl, renderUserData);
			}
		}
		 
		function renderUserData(responseBatch) {
			if(responseBatch.Responses.length != 0) {
				var user = responseBatch.Responses[0].User;
				
				if(user.UserKey.Key != "anonymous") {
				
				var status_links = document.getElementById('status_links');
				var user_messages = document.getElementById('user_messages');
				var avatar = document.getElementById('status_avatar');
				var StatusBoxAvatar = document.getElementById('StatusBoxAvatar');
				var BillboardAvatarTabImg = document.getElementById('BillboardAvatarTabImg');
				var you_image = document.getElementById('you_image');
				var status_box_logged_in = document.getElementById('status_box_logged_in');
				var status_box_logged_out = document.getElementById('status_box_logged_out');
				var join_link = document.getElementById('SitelifeJoin');
				var login_link = document.getElementById('SitelifeLogin');
				var buttons = document.getElementById('BillboardButtons');
				
				//var AvatarTabImg = document.getElementById('AvatarTabImg');
				//AvatarTabImg.innerHTML = '<a href=/share/profiles/?plckPersonaPage=PersonaHome&slid='+ user.UserKey.Key + '&plckUserId=' + user.UserKey.Key + '> <img src='+user.AvatarPhotoUrl+' id=status_avatar border=0 height=44 width=44 /></a>'; 
				
				if(document.getElementById('StatusBoxHelp'))
				{
				   var StatusBoxHelp = document.getElementById('StatusBoxHelp');
				   StatusBoxHelp.style.display = "none";
				}
				
				
				status_box_logged_out.style.display = "none";
				status_box_logged_in.style.display = "block";
				
				if(join_link) {
					join_link.style.display = "none";
				}
				if(login_link) {
					login_link.style.display = "none";
				}
				if(buttons) {
					buttons.style.display = "none";
				}
				
				var status_html = "Welcome, " + user.DisplayName + "<br>";
				status_html += "<a href='/share/profiles/?plckPersonaPage=PersonaHome&slid=" + user.UserKey.Key + "&plckUserId=" + user.UserKey.Key + "'>My Profile</a> | <a href='javascript:slLogout()'>Logout</a><br>";
				var message_html = user.NumberOfMessages + " messages";
				
				status_links.innerHTML = status_html;
				user_messages.innerHTML = message_html;
				//avatar.src = user.AvatarPhotoUrl;
				
				StatusBoxAvatar.innerHTML = '<a href=/share/profiles/?plckPersonaPage=PersonaHome&slid='+ user.UserKey.Key + '&plckUserId=' + user.UserKey.Key + '> <img src='+user.AvatarPhotoUrl+' id=status_avatar border=0 height=40 width=40 /></a>';
				
				BillboardAvatarTabImg.innerHTML = '<a href=/share/profiles/?plckPersonaPage=PersonaHome&slid='+ user.UserKey.Key + '&plckUserId=' + user.UserKey.Key + '> <img src='+user.AvatarPhotoUrl+' id=you_image border=0 height=44 width=44 /></a>';
				
				if(document.getElementById('AvatarTabImg'))
				{
					
				  //var AvatarTabImg = document.getElementById('AvatarTabImg');
				  //AvatarTabImg.innerHTML = '<a href=/share/profiles/?plckPersonaPage=PersonaHome&slid='+ user.UserKey.Key + '&plckUserId=' + user.UserKey.Key + '> <img src='+user.AvatarPhotoUrl+' id=you_image border=0 height=44 width=44 /></a>';
				}
				
				//you_image.src = user.AvatarPhotoUrl;
				
				}
				
			}
		}
		
		var aboxArticles = new Array();
		function SubmitListRequest() {
			
			var requestBatch = new RequestBatch();
			
			for(var i=0;i<aboxArticles.length;i++) {
				requestBatch.AddToRequest(new ArticleKey(aboxArticles[i]));
			}
			
			requestBatch.BeginRequest(serverUrl, renderArticleList); 
		}
		
		function renderArticleList(responseBatch) { 

            if (responseBatch.Responses.length == 0) {    

				var commentCount = document.getElementById('articleCommentCount' + articleid);   

                var recommendCount = document.getElementById('articleRecommendCount' + articleid);   

                // update page elements  

				commentCount.style.visibility = 'hidden';

				recommendCount.style.visibility = 'hidden'; 

                commentCount.innerHTML = 0;   

                recommendCount.innerHTML = 0;

            } else {   
			
				for(var i=0;i<responseBatch.Responses.length;i++) {

                // get article from response   

                var article = responseBatch.Responses[i].Article;

                // get page elements   

                var commentCount = document.getElementById('articleCommentCount' + article.ArticleKey.Key);   

                var recommendCount = document.getElementById('articleRecommendCount' + article.ArticleKey.Key);

                // update page elements   

                commentCount.innerHTML = article.Comments.NumberOfComments;   

                recommendCount.innerHTML = article.Recommendations.NumberOfRecommendations;

				var isRecommended = article.Recommendations.CurrentUserHasRecommended;

				if(isRecommended == "True") {

					var recommendLink = document.getElementById('recommendlink' + article.ArticleKey.Key);

					recommendLink.innerHTML = "<span class='Article_Recommended'>Recommended</span>";

				}

				commentCount.style.visibility = 'visible';

				recommendCount.style.visibility = 'visible';
				
				}

            }  
			
			for(var i=0;i<aboxArticles.length;i++) {
				var commentCountcheck = document.getElementById('articleCommentCount' + aboxArticles[i]);
				var recommendCountcheck = document.getElementById('articleRecommendCount' + aboxArticles[i]);
				
				if(commentCountcheck) {
					if(commentCountcheck.innerHTML == "") {
						commentCountcheck.innerHTML = "0";
					}
				}
				if(recommendCountcheck) {
					if(recommendCountcheck.innerHTML == "") {
						recommendCountcheck.innerHTML = "0";
					}
				}
			}

        }
		
		function combineAboxRecommendedCommentedUser() {
			var requestBatch = new RequestBatch();
			
			// abox articles
			for(var i=0;i<aboxArticles.length;i++) {
				requestBatch.AddToRequest(new ArticleKey(aboxArticles[i]));
			} // end abox articles
			
			// most commented and recommended
			var sections = new Array(new Section("All"));
			var categories = new Array(new Category("All"));
			var contributors = new Array(new UserTier("All"));
			var commentactivity = new Activity("Commented");
			var recommendactivity = new Activity("Recommended");
			var age = 2;
			var numItemsToGet = 5;

			var commentdiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, commentactivity, age, numItemsToGet);
			var recommendeddiscoveryAction = new DiscoverArticlesAction(sections, categories, contributors, recommendactivity, age, numItemsToGet);
			requestBatch.AddToRequest(commentdiscoveryAction);
			requestBatch.AddToRequest(recommendeddiscoveryAction);
			// end most commented and recommended
			
			
			requestBatch.BeginRequest(serverUrl, renderMostCommentedArticle);
			
			
			

			requestBatch.BeginRequest(serverUrl, renderArticleList);
		}
		
		function combineAboxRecommendedCommentedUserRender(responseBatch) {
			if (responseBatch.Responses.length == 0) {    

				var commentCount = document.getElementById('articleCommentCount' + articleid);   

                var recommendCount = document.getElementById('articleRecommendCount' + articleid);   

                // update page elements  

				commentCount.style.visibility = 'hidden';

				recommendCount.style.visibility = 'hidden'; 

                commentCount.innerHTML = 0;   

                recommendCount.innerHTML = 0;

            } else {   
			
				for(var i=0;i<responseBatch.Responses.length;i++) {

                // get article from response   

                var article = responseBatch.Responses[i].Article;

                // get page elements   

                var commentCount = document.getElementById('articleCommentCount' + article.ArticleKey.Key);   

                var recommendCount = document.getElementById('articleRecommendCount' + article.ArticleKey.Key);

                // update page elements   

                commentCount.innerHTML = article.Comments.NumberOfComments;   

                recommendCount.innerHTML = article.Recommendations.NumberOfRecommendations;

				var isRecommended = article.Recommendations.CurrentUserHasRecommended;

				if(isRecommended == "True") {

					var recommendLink = document.getElementById('recommendlink' + article.ArticleKey.Key);

					recommendLink.innerHTML = "<span class='Article_Recommended'>Recommended</span>";

				}

				commentCount.style.visibility = 'visible';

				recommendCount.style.visibility = 'visible';
				
				}

            }   
		}
		
		function popUp(URL) {
			day = new Date();
			id = day.getTime();
			eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=300,left = 390,top = 312');");
		}
		
		function billboardNav(linktype) {
			var linkbox = document.getElementById(linktype);
			location.href = linkbox.value;
		}
		
		function getCookieUUID() {
			var ocCookies = document.cookie.split( ';' );
			var tempCookie = "";
			var tempCookie2 = "";
			var tempCookie3 = "";
			var uuid = "";
			for(i=0; i < ocCookies.length; i++) {
				tempCookie = ocCookies[i].split('=');
				cookie_name = tempCookie[0].replace(/^\s+|\s+$/g, '');
				
				if(cookie_name == "at") {
					var atcookie = tempCookie[1];
					tempCookie2 = atcookie.split("%26");
					for(j=0; j < tempCookie2.length; j++) {
						tempCookie3 = tempCookie2[j].split("%3D");
						if(tempCookie3[0] == "u") {
							uuid = tempCookie3[1];
						}
					}
				}
			}
			return uuid;
			
		}
		
		var showRecommendedOnly = false;
		var orderby = 'TimeStampDescending';
		var oncommentsPage = 1;
		var pstTimeDifference = 0;
		
		var vars = [], hash;
		var vars = [], cleanHash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		
		for(var i = 0; i < hashes.length; i++)
		{ 
			hash = hashes[i].split('='); 
			
			if(hash[0] == "orderby" || hash[0] == "oncommentsPage" || hash[0] == "showRecommendedOnly")
			  var cleanHash = hash[1].split('#');   //Remove #slComments from the value 	  
			
			if(hash[0] == "orderby")    	
				var orderby = cleanHash[0]; //var orderby = hash[1];
			
			if(hash[0] == "oncommentsPage")
				var oncommentsPage = cleanHash[0];
							
			if(hash[0] == "showRecommendedOnly")
			{	  
			  if(cleanHash[0] == 0)
				   var showRecommendedOnly = false;
			  else
				    var showRecommendedOnly = true;			 
			}
		}
		
		function pullComments(orderby, showRecommendedOnly, oncommentsPage, timeDifference, lang)
		{
			var windowLocation = window.location.href.split("?");
			var showAll = 'Show All Comments';
			var showRecommended = 'Show Recommended Comments Only';
			
			if (lang == 'es') {
				showAll = 'Ver todos comentarios';
				showRecommended = 'Ver s&oacute;lo comentarios recomendados';
			}
			
			//alert(timeDifference);
			pstTimeDifference = timeDifference;
			
			if(showRecommendedOnly == 1)
			    var showRecommendedOnly = true;
			else
			    var showRecommendedOnly = false; 
			
			 
			var showreconlylink = document.getElementById('showreconly');
			if(showreconlylink) {
				if(showRecommendedOnly)
				{			 
					showreconlylink.innerHTML = showAll;
				}
				else
				{
					showreconlylink.innerHTML = showRecommended;
				}
			}
			var requestBatch = new RequestBatch();  
			var articleKey = new ArticleKey(articleid);  
			var commentPage = new CommentPage(articleKey, 10, oncommentsPage, orderby);          
			requestBatch.AddToRequest(commentPage);   
			requestBatch.BeginRequest(serverUrl, renderCommentPage); 
		}
		
		
		
		
		function renderCommentPage(responseBatch)
		{
			
			var windowLocation = window.location.href.split("?");
			windowLocation[0] = windowLocation[0].replace(/#.+$/, '');
			var nextPage = ((oncommentsPage * 1) + 1) ;
			var prePage = ((oncommentsPage) - 1) ;
			
			if (responseBatch.Responses.length == 0)
			{  
				//alert('Article Not Found.');  
			}
			else
			{  
				var commentBlock = document.getElementById('slrenderedComments'); 
				var commentBlockHtml = "<div id='Comments_OuterContainer' class='Comments_Container'><table class='Comments_Table' cellspacing='0' cellpadding='0'>";  
				var commentPage = responseBatch.Responses[0].CommentPage;  
				var total_comments = commentPage.NumberOfComments;
				
				var uuid = getCookieUUID();
				for(var i=0; i < commentPage.Comments.length; i++) 
				{  
					if((showRecommendedOnly && commentPage.Comments[i].NumberOfRecommendations > 0) || !showRecommendedOnly)
					{
						if((commentPage.Comments[i].Author.IsBlocked == "False" && commentPage.Comments[i].AbuseReportCount < 4) || (commentPage.Comments[i].Author.IsBlocked == "True" && commentPage.Comments[i].Author.UserKey.Key == uuid))
						{
							commentBlockHtml += getCommentHtml(commentPage.Comments[i]);
							
						}
					}
				}
				
				commentBlockHtml += "</table><div class='commentPagination'>";
				var numPages = Math.ceil(total_comments / 10);
				//alert("pages="+numPages);
				
				if(showRecommendedOnly)
					showRecommendedOnly = 1;
				else
				    showRecommendedOnly = 0; 
			
				//alert(showRecommendedOnly);
				
					
				if(numPages > 1 && oncommentsPage != 1)
				{
					commentBlockHtml += ' <a href='+windowLocation[0]+'?orderby='+orderby+'&showRecommendedOnly='+showRecommendedOnly+'&oncommentsPage=1#slComments>&lt;&lt;First</a> |';
					
					commentBlockHtml += ' <a href='+windowLocation[0]+'?orderby='+orderby+'&showRecommendedOnly='+showRecommendedOnly+'&oncommentsPage='+prePage+'#slComments> &lt;Prev </a> |';
				}
				
				for(var j=1; j <= numPages; j++)
				{
					if(j == oncommentsPage)
					{
						commentBlockHtml += " " + j + " ";	
					}
					else
					{				
						commentBlockHtml += ' <a href='+windowLocation[0]+'?orderby='+orderby+'&showRecommendedOnly='+showRecommendedOnly+'&oncommentsPage='+j+'#slComments>' + j + '</a>';
						
					}
				}
				
				if(numPages > 1 && oncommentsPage != numPages)
				{			
					commentBlockHtml += ' | <a href='+windowLocation[0]+'?orderby='+orderby+'&showRecommendedOnly='+showRecommendedOnly+'&oncommentsPage='+nextPage+'#slComments>Next&gt; </a> |';
					commentBlockHtml += ' <a href='+windowLocation[0]+'?orderby='+orderby+'&showRecommendedOnly='+showRecommendedOnly+'&oncommentsPage='+numPages+'#slComments> Last&gt;&gt;</a>';
				}
				
				commentBlockHtml += "</div></div>";
				commentBlock.innerHTML = commentBlockHtml;  
			}  
		} 
	
   function getDays(month)
   {
	  var monthAry = new Array();
	  monthAry[1] = 31;
	  monthAry[2] = 28;
	  monthAry[3] = 31;
	  monthAry[4] = 30;
	  monthAry[5] = 31;
	  monthAry[6] = 30;
	  monthAry[7] = 31;
	  monthAry[8] = 31;
	  monthAry[9] = 30;
	  monthAry[10] = 31;
	  monthAry[11] = 30;
	  monthAry[12] = 31;
	  
	  return monthAry[month];	  
   }
	
 /*--------------------------For TimeStamp-------------------------------------*/
 function y2k(number) { return (number < 1000) ? number + 1900 : number; }
 
	function formatTimeStamp(dateStr)
	{
		//alert("date="+dateStr);
		
		var datesplit = dateStr.split(" ");
		var dateAry = datesplit[0].split("/");
		var timeAry = datesplit[1].split(":");
		
		var ampm    = datesplit[2];
		var year = dateAry[2];
		var month = dateAry[0];
		var day = dateAry[1];
		var hour = timeAry[0];
		var minute = timeAry[1];
		var sec = timeAry[2];
		
		var newhour = (hour*1) + (pstTimeDifference*1);
		
		if(newhour > 12)
		{
		   newhour = newhour - 12;
		   var newampm = (ampm == "AM") ? "PM" : "AM";
		   
		   if(ampm == "PM")
		   {
				 day = (day*1) + 1;
				 var daysinmonth = getDays(month);
				  if(day > daysinmonth)
				  {
					 month = (month*1) + 1;  
					 day = 1;
					 if(month > 12)
					 {
						 month = 1;
						 year = (year*1) + 1;
					 }
				  }						  
		    }
			
		  var newDate = month+"/"+day+"/"+year+" "+newhour+":"+minute+":"+sec+" "+newampm;
		}
		else
		{
			var newDate = month+"/"+day+"/"+year+" "+newhour+":"+minute+":"+sec+" "+ampm;
		}
				
		return newDate;
		
		/*		
		var date = new Date(dateStr);		
		var difference = pstTimeDifference;		
		
		var ampmFlag = "AM";		

		var dates = new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) + 8*60*60*1000 + (difference)*60*60*1000);
				
		var hrs = dates.getHours();
		
		if(hrs > 12)
  		{
    		hrs = (hrs-12);
			ampmFlag = "PM";	
  		}
  
  		var minutes = (dates.getMinutes() < 10) ? "0"+dates.getMinutes() : dates.getMinutes();
		var secs    = (dates.getSeconds() < 10) ? "0"+dates.getSeconds() : dates.getSeconds();
		
		var finalDate = (dates.getMonth()+1)+"/"+dates.getDate()+"/"+dates.getFullYear()+"&nbsp;"+hrs+":"+minutes+":"+secs+"&nbsp;"+ampmFlag; 
		
		return finalDate;
		*/
	}
 
 
 /*----------------------------------------------------------------------------*/		
		
		
          
		function getCommentHtml(comment) {
			var html = "";
			html += '<tr class="Comments_TableRowColor"><td class="Comments_UserImage">';
			html += '<a href="/share/profiles/?slid=' + comment.Author.UserKey.Key + '&plckUserId=' + comment.Author.UserKey.Key + '">';
			html += '<img src="' + comment.Author.AvatarPhotoUrl + '" border="0"></a>';
			html += '</td><td class="Comments_TableRight"><div class="Comments_From">';
			html += '<a href="/share/profiles/?slid=' + comment.Author.UserKey.Key + '&plckUserId=' + comment.Author.UserKey.Key + '">';
			html += comment.Author.DisplayName + '</a> wrote:</div>';
			html += '<div id="CommentBody" class="Comments_CommentText">' + comment.CommentBody + '</div>';
			
			
			
			var formatedDate = formatTimeStamp(comment.PostedAtTime);
			
						
			
			//html += '<div class="Comments_NestedDate">' + comment.PostedAtTime + '</div>';			
			html += '<div class="Comments_NestedDate">' + formatedDate + '</div>';			
			
			
			html += '<table class="Comments_NestedTable" cellspacing="0" cellpadding="0"><tr>';
			html += '<td class="Comments_NestedRecommend">';
			if(comment.CurrentUserHasRecommended == "True") {
				html += '<div id="recommend:' + comment.CommentKey.Key + '">';
				html += '<div style="display: inline;"><div class="Recommend_Container">';
				
				html += '<span class="SiteLife_Recommended">Recommended (' + comment.NumberOfRecommendations + ')</span></div></div></div>';
			}
			else {
				html += '<div id="recommend:' + comment.CommentKey.Key + '">';
				html += '<a class="SiteLife_Recommend" onclick="return gSiteLife.PostRecommendation(';
				html += "'Comment', '" + comment.CommentKey.Key + "', 'recommend:" + comment.CommentKey.Key + "', document.title);";
				html += '" href="#none">Recommend</a>(' + comment.NumberOfRecommendations + ')</div>';
			}
			html += '</td><td class="Comments_NestedReport">';
			if(comment.CurrentUserHasReportedAbuse == "True") {
				html += '<div id="rpt_' + comment.CommentKey.Key + '"><div style="display: inline;">';
				html += '<span class="SiteLife_Reported">Reported</span></div></div>';
			}
			else {
				html += '<div id="rpt_' + comment.CommentKey.Key + '"><span>';
				html += '<a id="' + comment.CommentKey.Key + '_RptAbuse" class="SiteLife_ReportAbuse" onclick="ShowReportAbuse(event,document.URL,gSiteLife.__baseUrl + \'/AbuseReport/ReportAbuse?plckElementId=rpt_' + comment.CommentKey.Key + '&plckTargetKey=' + comment.CommentKey.Key + '&plckTargetKeyType=Comment\');';
				html += 'return false;" href="#none">Report Abuse</a></span></div>';
			}
			html += '</td></tr></table></td></tr>';
			return html;  
		}
		
		function getMostRecentPhotos(numPhotos) {
			if(!numPhotos) {
				numPhotos = 5;
			}
			
			var recentPhotos = document.getElementById('recent_list_photos');  
				
			if(cacheMostRecentPhotos) {
				var photoHtml = '<div class="Summary_Container">';
				photoHtml += '<table class="Summary_PhotoTable" cellspacing="0" cellpadding="0"><tbody>';
				photoHtml += createPhotoHtml(cacheMostRecentPhotos.ResponseBatch, numPhotos);
				photoHtml += '</tbody></table></div>';
				
                recentPhotos.innerHTML = photoHtml;  
				
			}
			
		}
		
		function createPhotoHtml(ResponseBatch, numPhotos) {
			discoveredContent = ResponseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
			if(numPhotos > discoveredContent.length) {
				numPhotos = discoveredContent.length;
			}
			var html = "";
			for(var i = 0; i < numPhotos; i++) {
				if(discoveredContent[i].IsPendingApproval == "False" && discoveredContent[i].Author.IsBlocked == "False") {
					html += '<tr><td class="Summary_PhotoTableLeft">';
					html += '<a href="' + discoveredContent[i].PhotoUrl + '">';
					html += '<img src="' + discoveredContent[i].Image.Small + '" border="0"></a></td>';
					html += '<td class="Summary_PhotoTableRight">';
					html += '<div class="Summary_PhotoTitle">';
					html += '<a href="' + discoveredContent[i].PhotoUrl + '">' + discoveredContent[i].Title + '</a></div>';
					//html += '<div class="Summary_PhotoIn">';
					//html += 'In: <a href="/share/gallery?plckGalleryId=' + discoveredContent[i].GalleryKey.Key + '">';
					html += '<div class="Summary_PhotoBy">';
					html += 'By: <a href="/share/profiles/?slid=' + discoveredContent[i].Author.UserKey.Key + '&plckUserId=' + discoveredContent[i].Author.UserKey.Key + '">';
					html += discoveredContent[i].Author.DisplayName + '</a></div>';
				}
				else {
					numPhotos++;	
				}
			}
			return html;
		}
		
		function getBillboardLinks() {
			
			if(document.getElementById('photo1link'))
				var photo1link = document.getElementById('photo1link');
				
			if(document.getElementById('photo2link'))	
				var photo2link = document.getElementById('photo2link');
				
			if(document.getElementById('photo3link'))		
				var photo3link = document.getElementById('photo3link');
				
			if(document.getElementById('photo1img'))	
				var photo1img = document.getElementById('photo1img');
			
			if(document.getElementById('photo2img'))	
				var photo2img = document.getElementById('photo2img');
				
			if(document.getElementById('photo3img'))	
				var photo3img = document.getElementById('photo3img');
				
			if(cacheMostRecentPhotos) {
				discoveredContent = cacheMostRecentPhotos.ResponseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
                
                var numSet = 0;
                for(var i = 0; i < discoveredContent.length; i++) {
                	if(discoveredContent[i].IsPendingApproval == "False" && discoveredContent[i].Author.IsBlocked == "False" && numSet != 3) {
                    	if(numSet == 0) {
							if(photo1link)
							{
								photo1link.href = discoveredContent[0].PhotoUrl;
								photo1img.src = discoveredContent[0].Image.Small;
								numSet++;
							}
                        }
                        else if(numSet == 1) {
							if(photo2link)
							{
								photo2link.href = discoveredContent[1].PhotoUrl;
								photo2img.src = discoveredContent[1].Image.Small;
								numSet++;
							}
                        }
                        else if(numSet == 2) {
							if(photo3link)
							{
								photo3link.href = discoveredContent[2].PhotoUrl;
								photo3img.src = discoveredContent[2].Image.Small;
								numSet++;
							}
                        }
                    }
                }
			}
			else {
				var searchSections = new Array();  
				searchSections[0] = new Section("All");  
 
				var searchCategories = new Array();  
				searchCategories[0] = new Category("All");  

				var activityDisco = new Activity("Recent");  
				var contentType = new ContentType("PublicPhoto");  
				var limitToContributorsDisco = new Array();  
				limitToContributorsDisco[1] = new UserTier("All");  
				var age = 15;  
				var maximumNumberOfDiscoveries = 10;  

				var requestBatch = new RequestBatch();  
				var discoveryAction = new DiscoverContentAction(  
					searchSections,  
					searchCategories,  
					limitToContributorsDisco,  
					activityDisco,  
					contentType,  
					age,  
					maximumNumberOfDiscoveries);  

				requestBatch.AddToRequest(discoveryAction);  
				requestBatch.BeginRequest(serverUrl, renderBillboardLinks);	
			}
		}
		
		function renderBillboardLinks(responseBatch) {
			if (responseBatch.Responses.length >= 1) {
				
			if(document.getElementById('photo1link'))
				var photo1link = document.getElementById('photo1link');
				
			if(document.getElementById('photo2link'))	
				var photo2link = document.getElementById('photo2link');
				
			if(document.getElementById('photo3link'))		
				var photo3link = document.getElementById('photo3link');
				
			if(document.getElementById('photo1img'))	
				var photo1img = document.getElementById('photo1img');
			
			if(document.getElementById('photo2img'))	
				var photo2img = document.getElementById('photo2img');
				
			if(document.getElementById('photo3img'))	
				var photo3img = document.getElementById('photo3img');
				
				var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
				var numSet = 0;
                for(var i = 0; i < discoveredContent.length; i++) {
                	if(discoveredContent[i].IsPendingApproval == "False" && discoveredContent[i].Author.IsBlocked == "False" && numSet != 3) {
                    	if(numSet == 0) {
							if(photo1link)
							{
								photo1link.href = discoveredContent[0].PhotoUrl;
								photo1img.src = discoveredContent[0].Image.Small;
								numSet++;
							}
                        }
                        else if(numSet == 1) {
							if(photo2link)
							{
								photo2link.href = discoveredContent[1].PhotoUrl;
								photo2img.src = discoveredContent[1].Image.Small;
								numSet++;
							}
                        }
                        else if(numSet == 2) {
							if(photo3link)
							{
								photo3link.href = discoveredContent[2].PhotoUrl;
								photo3img.src = discoveredContent[2].Image.Small;
								numSet++;
							}
                        }
                    }
                }
			}
		}
		
		function getMostRecommendedPhotos(numPhotos) {
			if(!numPhotos) {
				numPhotos = 5;
			}
			
			var recommendedPhotos = document.getElementById('mostrecommended_list_photos');  
				
			if(cacheMostRecommendedPhotos) {
				var photoHtml = '<div class="Summary_Container">';
				photoHtml += '<table class="Summary_PhotoTable" cellspacing="0" cellpadding="0"><tbody>';
				photoHtml += createPhotoHtml(cacheMostRecommendedPhotos.ResponseBatch, numPhotos);
				photoHtml += '</tbody></table></div>';
				
                recommendedPhotos.innerHTML = photoHtml;  
			}
		}
		
		
var defaultEmptyOK = false;
var whitespace = " \t\n\r"; 
var alreadySubmitted = false;
var EMAIL = "email";
var EMAIL_MSG = "Please enter a valid email address.";
var USER_NAME = "userName";
var USER_NAME_MSG = "Please enter a username that is at least 6 characters long\nand contains only letters and numbers.";
var PASSWORD = "password";
var PASSWORD_MSG = "Please enter a password that is at least 6 characters long\ncontaining only letters and numbers.";
var PASSWORD2 = "password2";
var PASSWORD2_MSG = "Your password entries must match, please re-enter.";
var GENDER = "gender";
var GENDER_MSG = "Please select your gender.";
var BIRTHYEAR = "birthYear";
var BIRTHYEAR_MSG = "Please enter a valid year of birth. You must be at least 13 years of age to register.";
var TERMS = "submit";
var TERMS_MSG = "You must agree to the user agreement terms to register.";

errorMsgArr = new Array();
errorMsgArr[EMAIL] = EMAIL_MSG;
errorMsgArr[USER_NAME] = USER_NAME_MSG;
errorMsgArr[PASSWORD] = PASSWORD_MSG;
errorMsgArr[PASSWORD2] = PASSWORD2_MSG;
errorMsgArr[GENDER] = GENDER_MSG;
errorMsgArr[BIRTHYEAR] = BIRTHYEAR_MSG;
errorMsgArr[TERMS] = TERMS_MSG;

function trim(str) {
  	while (str.substring(0,1) == ' ') str = str.substring(1,str.length);
	while (str.substring(str.length-1,str.length) == ' ') str = str.substring(0,str.length-1);
	return str;
}
function isWhitespace (s) {
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}
function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}


function validateNewOnlineOnly(form) {
	
	
	if(!isValidUserName(form.userName.value)) {
		alert(errorMsgArr[USER_NAME]); form.userName.focus();
		return false;
	}
	if(isWhitespace(form.password.value)) {
		alert(errorMsgArr[PASSWORD]); form.password.focus();
		return false;
	}	
	if(isWhitespace(form.password2.value)) {
		alert("Please confirm password"); 
		form.password2.focus();
		return false;
	}	
	if(form.password.value!=form.password2.value) {
		alert(errorMsgArr[PASSWORD2]); form.password2.focus();
		return false;
	}	
	if(!isValidUserName(form.password.value)) {
		alert(errorMsgArr[PASSWORD]); 
		form.password.focus();
		return false;
	}
	if(!isValidZipCode(form.zipCode.value)) {
		alert("Please enter a valid zip code"); 
		form.password.focus();
		return false;
	}
	
	if(!isValidEmail(form.email.value)) {
		alert(errorMsgArr[EMAIL]);
		form.email.focus();
		return false;
	}
	
	if(!isValidBirthYear(form.birthYear.value)) {
		alert(errorMsgArr[BIRTHYEAR]);
		form.birthYear.focus();
		return false;
	}
	
	if(!validateRadioButton(form.gender)) {
		alert(errorMsgArr[GENDER]);
		return false;
	}
	
	if(form.submit.checked == false) {
		alert(errorMsgArr[TERMS]);
		return false;
	}
	
	return true;
}


function isValidEmail(email) {
	if(isWhitespace(email)) return false;
	email = trim(email);
	var reg1 = /\s/;
	if(reg1.test(email)) return false;
	var reg2 = /^.+@.+\.[a-zA-Z]+/;
	if(reg2.test(email)) return true;
	return false;
}
function isValidDiscusNum(discus) {
	if(isWhitespace(discus)) return false;
	discus = trim(discus);
	var reg1 = /\D/;
	return(!reg1.test(discus));
}
function isValidUserName(userName) {
	if(isWhitespace(userName)) return false;
	userName = trim(userName);
	var reg1 = /\s/;
	if(reg1.test(userName)) return false;
	var reg2 = /\W/;
	if(reg2.test(userName)) return false;
	if(userName.length<6) return false;	
	return true;
}

function isValidZipCode(userName) {
	if(isWhitespace(userName)) return false;
	userName = trim(userName);
	var reg1 = /\s/;
	if(reg1.test(userName)) return false;
	var reg2 = /\W/;
	if(reg2.test(userName)) return false;
	if(userName.length!=5) return false;	
	return true;
}
function isValidBirthYear(birthYear) {
	if(isWhitespace(birthYear)) return false;
	birthYear = trim(birthYear);
	var reg1 = /\D/;
	if(reg1.test(birthYear)) return false;
	var now = new Date();
	var ny = now.getFullYear();
	if(birthYear>(ny-13)) return false;
	return true;
}
function validateRadioButton(radioButton) {
	index = -1;
	for(i=0; i<radioButton.length; i++) {
		if(radioButton[i].checked) index = i;
	}
	return(index>-1);
}
function getRadioValue(radioButton) {
	index = -1;
	for(i=0; i<radioButton.length; i++) {
		if(radioButton[i].checked) { 
			return radioButton[i].value;	
		}
	}
	return("");
}
function validateSelect(select) {
	index = -1;
	for(i=0; i<select.length; i++) {
		if(select[i].selected) { 
			index = i;
			break;
		}
	}
	return(index>-1);
}
function getSelectedValue(select) {
	index = -1;
	for(i=0; i<select.length; i++) {
		if(select[i].selected) { 
			return select[i].value;	
		}
	}
	return("");
}

function show_registration() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.display = 'inline';
	reg_form.style.visibility = 'visible';
	reg_form.style.zIndex = '1000';
	
	var reg_form2 = document.getElementById('reg_form');
	reg_form2.style.display = 'inline';
	reg_form2.style.visibility = 'visible';
	reg_form2.style.zIndex = '1001';
}

function hide_registration() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.display = 'none';
	reg_form.style.visibility = 'hidden';
	reg_form.style.zIndex = '0';
	
	var reg_form2 = document.getElementById('reg_form');
	reg_form2.style.display = 'none';
	reg_form2.style.visibility = 'hidden';
	reg_form2.style.zIndex = '0';
}

function show_login() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.display = 'inline';
	reg_form.style.visibility = 'visible';
	reg_form.style.zIndex = '1000';
	
	var sl_login = parent.document.getElementById('sitelife_login');
	sl_login.style.display = 'inline';
	sl_login.style.visibility = 'visible';
	sl_login.style.zIndex = '1001';
	sl_login.focus();
}

function hide_login() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.display = 'none';
	reg_form.style.visibility = 'hidden';
	reg_form.style.zIndex = '0';
	
	var sl_login = parent.document.getElementById('sitelife_login');
	sl_login.style.display = 'none';
	sl_login.style.visibility = 'hidden';
	sl_login.style.zIndex = '0';
}

function show_getpass() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.display = 'inline';
	reg_form.style.visibility = 'visible';
	reg_form.style.zIndex = '1000';
	
	var sl_login = parent.document.getElementById('forgotten_password');
	sl_login.style.display = 'inline';
	sl_login.style.visibility = 'visible';
	sl_login.style.zIndex = '1001';
}

function hide_getpass() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.visibility = 'hidden';
	reg_form.style.zIndex = '0';
	
	var sl_login = parent.document.getElementById('forgotten_password');
	sl_login.style.visibility = 'hidden';
	sl_login.style.zIndex = '0';
}

function show_faq() {
	var faq = parent.document.getElementById('faq_page');
	if(faq) {
		faq.style.display = 'inline';
		faq.style.visibility = 'visible';
		faq.style.zIndex = '1001';
	}
}
function hide_faq() {
	var faq = parent.document.getElementById('faq_page');
	faq.style.display = 'none';
	faq.style.visibility = 'hidden';
	faq.style.zIndex = '0';
}
function show_help() {
	var help = parent.document.getElementById('pluckhelp_page');
	if(help) {
		help.style.display = 'inline';
		help.style.visibility = 'visible';
		help.style.zIndex = '1001';
	}
}
function hide_help() {
	var help = parent.document.getElementById('pluckhelp_page');
	help.style.display = 'none';
	help.style.visibility = 'hidden';
	help.style.zIndex = '0';
}
function show_resend() {
	var reg_form = document.getElementById('RegistrationContainer');
	if(reg_form) {
		reg_form.style.display = 'inline';
		reg_form.style.visibility = 'visible';
		reg_form.style.zIndex = '1000';
	}
	
	var sl_login = parent.document.getElementById('resend_confirmation');
	sl_login.style.display = 'inline';
	sl_login.style.visibility = 'visible';
	sl_login.style.zIndex = '1001';
}

function hide_resend() {
	var reg_form = document.getElementById('RegistrationContainer');
	if(reg_form) {
		reg_form.style.visibility = 'hidden';
		reg_form.style.zIndex = '0';
	}
	
	var sl_login = parent.document.getElementById('resend_confirmation');
	sl_login.style.visibility = 'hidden';
	sl_login.style.zIndex = '0';
}

function show_changepw() {
	var reg_form = document.getElementById('RegistrationContainer');
	if(reg_form) {
		reg_form.style.display = 'inline';
		reg_form.style.visibility = 'visible';
		reg_form.style.zIndex = '1000';
	}
	
	var sl_login = parent.document.getElementById('change_password');
	
	sl_login.style.display = 'inline';
	sl_login.style.visibility = 'visible';
	sl_login.style.zIndex = '1001';
}
function hide_changepw() {
	var reg_form = document.getElementById('RegistrationContainer');
	reg_form.style.visibility = 'hidden';
	reg_form.style.zIndex = '0';
	
	var sl_login = parent.document.getElementById('change_password');
	sl_login.style.visibility = 'hidden';
	sl_login.style.zIndex = '0';

}


function checkLogin() {
	var xmlHttp;
	var login_status = document.getElementById('login_result');
	var username = document.sitelife_login_form.userName.value;
	var password = document.sitelife_login_form.password.value;
	var redirect = document.sitelife_login_form.redirect.value;
	var remember = document.sitelife_login_form.remember.checked;
	var scriptname = "/share/passport_login.php?userName=" + username + "&password=" + password + "&remember=" + remember  + "&redirect=" + redirect;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			login_status.innerHTML = xmlHttp.responseText;
			if(xmlHttp.responseText == "logged in") {
				//hide_login();
				setTimeout('location.reload(true)', 1000);
			}
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}

function checkLoginCommon() {
	var xmlHttp;
	var login_status = document.getElementById('login_result');
	var username = document.sitelife_login_form.userName.value;
	var password = document.sitelife_login_form.password.value;
	var redirect = document.sitelife_login_form.redirect.value;
	var remember = document.sitelife_login_form.remember.checked;
	var scriptname = "/common/pluck/share/passport_login.php?userName=" + username + "&password=" + password + "&remember=" + remember  + "&redirect=" + redirect;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			login_status.innerHTML = xmlHttp.responseText;
			if(xmlHttp.responseText == "logged in") {
				//hide_login();
				setTimeout('location.reload(true)', 1000);
			}
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}

function RetrievePassword() {
	var xmlHttp;
	var password_retrieved = document.getElementById('password_retrieved');
	var username = document.retrieve_password.userName.value;
	var email = document.retrieve_password.email.value;
	var scriptname = "/share/retrieve_password.php?username=" + username + "&email=" + email;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			password_retrieved.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}

function RetrievePasswordCommon() {
	var xmlHttp;
	var password_retrieved = document.getElementById('password_retrieved');
	var username = document.retrieve_password.userName.value;
	var email = document.retrieve_password.email.value;
	var scriptname = "/common/pluck/share/retrieve_password.php?username=" + username + "&email=" + email;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			password_retrieved.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}

function ResendConfirm() {
	var xmlHttp;
	var email_sent = document.getElementById('email_sent');
	var username = document.resend_confirmation.userName.value;
	var email = document.resend_confirmation.email.value;
	var scriptname = "/share/resend_confirmation.php?userName=" + username + "&email=" + email;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			email_sent.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}

function ResendConfirmCommon() {
	var xmlHttp;
	var email_sent = document.getElementById('email_sent');
	var userName = document.getElementById('userName');
	
	//var resend_confirmation = document.getElementById('resend_confirmation');
	
	//var username = document.resend_confirmation.userName.value;
	var username = document.getElementById('userName').value;
	
	var email = document.resend_confirmation.email.value;
	var scriptname = "/common/pluck/share/resend_confirmation.php?userName=" + username + "&email=" + email;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      	}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			email_sent.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null);
}


function ChangePassword()
{

	var xmlHttp;
	var changePw_status = document.getElementById('changePw_status');
	var userName 			= document.frmChangePassword.userName.value;
	var oldPassword		= document.frmChangePassword.oldPassword.value;
	var newPassword		= document.frmChangePassword.newPassword.value;
	var confirmNewPassword 	= document.frmChangePassword.confirmNewPassword.value;

	
	var scriptname = "/share/change_password.php?userName=" +userName+ "&oldPassword=" +oldPassword+ "&newPassword=" +newPassword+ "&confirmNewPassword=" +confirmNewPassword;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    		catch (e)
		{
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("not supported");
			}
      		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState == 4) {
			changePw_status.innerHTML = xmlHttp.responseText;  
		}
	}
	
	xmlHttp.open("GET",scriptname, true);
	xmlHttp.send(null); 	

}
function changeFaqLink()
        {
            var domainName=window.document.domain
			var faq_link = "http://" + domainName + "/sections/share/faq/";
			window.location.href = faq_link;
         }