var xhr; var community; Event.observe(window, 'load', function(){ community = new communityclass }); var communityclass = Class.create({ initialize: function() { var host_url = document.URL.split('/'); var host_anchor = document.URL.split('#comment_'); this.site_name = host_url[2]; this.anchor_comment = host_anchor[1]; //this.FO = new FlashTag('http://www.space.com/common/community/nomnom.swf', 1, 1); this.objBody = document.getElementsByTagName("body").item(0); //document.domain = 'sandbox5.newsarama.com'; //alert(document.domain); this.user = this.getCookie('HD'); this.cookieKey = 'HD'; this.phpbbcookieKey = 'phpbb3_4sx8g_'; this.sortOrder = 'asc'; if(domain == 'space' && $('sidebox')){ this.welcome = new Template('

Welcome, #{user}

#{msg}

#{log}#{accnt}
') } this.setModules(); }, action: function(act,doc,arg){ switch(act){ case 'logout': this.eatCookies("loginrd");this.eatCookies(this.cookieKey);break; } }, setModules: function(){ if($('pk_header') != null){ this.persona_lnk = '/common/community/profile.php?u='+this.user[0]; if(domain == 'space' && $('sidebox')){ if(this.user != false){ if (this.user[4].indexOf('#') != -1) str = this.welcome.evaluate({avatar: this.user[4].replace('#','='), user:''+this.user[1]+'', log: 'Log Out',accnt: 'Account Options',msg:''}); else str = this.welcome.evaluate({avatar: this.user[4], user:''+this.user[1]+'', log: 'Log Out',accnt: 'Account Options',msg:''}); }else{ str = this.welcome.evaluate({avatar: avatar[0], user:'Guest', log: 'Members: Log In',accnt: 'New? Register: Join Now!',msg:'Curious? Join our community!'}); } $('pk_header').innerHTML = str; } if(this.user != false){ this.Get_New_Messages(); } } var recapt = new Element('script',{ 'type': 'text/javascript','src':'http://api.recaptcha.net/js/recaptcha_ajax.js' }); this.objBody.appendChild(recapt); if($('pk_comments')){ this.LoadComments(); if(this.user != false){ this.LoadCommentForm(); //this.LoadComRec(); } } }, compare: function(obj){ var e1 = $(obj); var e2 = $(obj+"2"); this.form_err = (e1.getValue() != e2.getValue()); var c = (this.form_err)? "error" : "okdokay"; e1.className = e2.className = c; }, makePOSTRequest: function(url, parameters, f){ try { xhr = new XMLHttpRequest(); if (xhr.overrideMimeType) { xhr.overrideMimeType('text/html');} } catch (e) { try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e2) { try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e3) { xhr = false; } } } if (!xhr) {alert('Cannot create XMLHTTP instance');return false;} xhr.onreadystatechange = f; xhr.open('POST', url, true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-length", parameters.length); xhr.setRequestHeader("Connection", "close"); xhr.send(parameters); }, ShowReplies: function(comment_id,nb_replies){ $('replies_'+comment_id).style.display = 'block'; $('expandtext_'+comment_id).innerHTML = 'Close Replies ('+nb_replies+')'; }, HideReplies: function(comment_id,nb_replies){ $('replies_'+comment_id).style.display = 'none'; $('expandtext_'+comment_id).innerHTML = 'Expand to View Replies ('+nb_replies+')'; }, Permalink: function(comment_id){ $('permalink_'+comment_id).style.display = 'block'; }, alertpostComment: function (){ var commentText = $('commentText'); if(xhr.readyState == 4){ if(xhr.status == 200){ var url = window.location.toString().split('#'); //window.location.replace(url[0] + '#commentForm'); //window.location.reload(); $('commentText').disabled = true; // $('btnSubmitCommentDis').src = 'http://i.livescience.com/common/community/template_images/btn_submit_comment_inactive.gif'; $('btnSubmitComment').style.display = 'none'; $('btnSubmitCommentDis').style.display = 'block'; $('btnSubmitCommentDis').disabled = true; $('commentText').style.color = '#FF0000'; $('commentText').value = 'Your comment has been posted. It may take up to a minute for your comment to appear.'; }else{ commentText.innerHTML = xhr.status; } }else{ // commentText.innerHTML = "Error posting comment"; } }, Submit_Comment: function(){ if ($('commentText').value.replace(/^\s*|\s*$/g,'') != '') { var parameters = 'action=postComment&member_id='+this.user[0]+'&guid='+encodeURI(ArticleID)+'&comment_text='+escape($('commentText').value)+'&parent_id='+encodeURI($('parent_id').value); this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertpostComment); } return false; }, alertGetNewMessages: function () { if(xhr.readyState == 4) { if(xhr.status == 200) { var new_msgs = xhr.responseText.replace(/\r|\n|\r\n/g, ""); if (new_msgs > 0) $('pk_header_msg').innerHTML = 'View New Messages ('+new_msgs+')'; } } }, Get_New_Messages: function(){ if(document.domain=='newsarama.com') return false; var parameters = 'action=GetNbNewMessages&member_id='+this.user[0]; this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertGetNewMessages); return false; }, LoadComments: function(){ if(document.domain=='newsarama.com') return false; var host_url = document.URL.split('/'); var xhr2; try { xhr2 = new XMLHttpRequest(); if (xhr2.overrideMimeType) { xhr2.overrideMimeType('text/html');} } catch (e) { try { xhr2 = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e2) { try { xhr2 = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e3) { xhr2 = false; } } } if (!xhr2) {alert('Cannot create XMLHTTP instance');return false;} var parameters = 'action=getComments&user='+encodeURI(this.user[1])+'&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID)+'&anchor_comment='+this.anchor_comment; xhr2.onreadystatechange = function(){ var commentBlock = $('pk_comments'); var recBlock = $('pk_com_rec'); if(xhr2.readyState == 4) { if(xhr2.status == 200) { var resp = xhr2.responseText; var sep = resp.indexOf('<#breaker#>'); commentBlock.innerHTML = resp.substring(0,sep); recBlock.innerHTML = resp.substring(sep+11,resp.length); var e=document.getElementsByName("abuseelmts"); for(var i=0;iLogoutYou are logged in as: "+community.user[1]+"

"; $('commentText').disabled = $('btnSubmitComment').disabled = !community.user; $('btnSubmitCommentDis').disabled = community.user; $('commentText').value = (community.user) ? '' : 'You are currently not logged in.\nYou must be logged in to leave a comment.'; $('commentText').style.width = ($('pk_commentForm').offsetWidth - 40)+"px"; window.location.href='#commentForm'; } else ReplyForm.innerHTML = "Error loading reply: "+xhr.status; } else { ReplyForm.innerHTML = "Loading..."; } }, LoadPReply: function(comment_id){ var parameters = 'action=getReplyForm&user='+encodeURI(this.user[1])+'&guid='+encodeURI(ArticleID)+'&commentid='+encodeURI(comment_id); this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertLoadPReply); }, alertRecommendComment: function () { if(xhr.readyState == 4) { if(xhr.status == 200) { var mystr = xhr.responseText.replace(/\r|\n|\r\n/g, "").split("#"); //var recommendSpan = $('recommendspan_'+mystr[0]); //recommendSpan.innerHTML = 'Recommend ('+mystr[1]+') '; } else recommendSpan.innerHTML = xhr.status; } }, RecommendComment: function(comment_id){ var recommendSpan = $('recommendspan_'+comment_id); if (recommendSpan.innerHTML.indexOf('')) { reco_part1 = recommendSpan.innerHTML.split("Recommend ("); nb_comments = reco_part1[1].split(")"); recommendSpan.innerHTML = 'Recommend ('+(parseInt(nb_comments[0])+1)+') '; var parameters = 'action=RecommendComment&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID)+'&commentid='+encodeURI(comment_id); this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertRecommendComment); } }, alertRecommendAsset: function () { if(xhr.readyState == 4) { if(xhr.status == 200) { var recommendSpan = $('rec_asset_span'); recommendSpan.innerHTML = 'Recommended ('+xhr.responseText.replace(/\r|\n|\r\n/g, "")+')'; } else $('rec_asset_span').innerHTML = xhr.status; } }, Recommend: function(asset_guid){ var parameters = ''; if (asset_guid) parameters = 'action=RecommendAsset&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(asset_guid); else parameters = 'action=RecommendAsset&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID); this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertRecommendAsset); }, RecommendEtc: function(asset_guid,nb){ var host_url = document.URL.split('/'); var recommendSpan = $('rec_asset_span_'+nb); if (recommendSpan.innerHTML.indexOf('')) { reco_part1 = recommendSpan.innerHTML.split("Recommend ("); nb_recommends = reco_part1[1].split(")"); recommendSpan.innerHTML = 'Recommended ('+(parseInt(nb_recommends[0])+1)+')'; var xhr3 = new Ajax.Request('http://'+host_url[2]+'/common/community_interface/communityAjax.php', { parameters:{action:'RecommendAsset', user_id:encodeURI(this.user[0]), guid:encodeURI(asset_guid)}, onSuccess: function(transport) { //var recommendSpan = $('rec_asset_span_'+nb); //recommendSpan.innerHTML = 'Recommended ('+transport.responseText.replace(/\r|\n|\r\n/g, "")+')'; }}); } }, alertReportAbuse: function () { if(xhr.readyState == 4) { if(xhr.status == 200) { var abuseSpan = $('abusespan_'+xhr.responseText.replace(/\r|\n|\r\n/g, "")); abuseSpan.innerHTML = 'You have reported abuse on this comment.'; } else $('abusespan_'+xhr.responseText.replace(/\r|\n|\r\n/g, "")).innerHTML = xhr.status; } }, ReportAbuse: function(comment_id){ if (!this.user) alert('You must be logged in to Report Abuse.'); else { var parameters = 'action=ReportAbuse&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID)+'&commentid='+encodeURI(comment_id); this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertReportAbuse); } }, alertPage: function () { var commentBlock = $('commentbloc'); if(xhr.readyState == 4) { if(xhr.status == 200) { commentBlock.innerHTML = xhr.responseText; window.location.href='#comments'; } else commentBlock.innerHTML = xhr.status; } }, Page: function(page){ if (window.section != undefined) { refreshAds(); } var parameters = 'action=getCommentsPage&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID)+'&page='+page+'&sortby='+this.sortOrder; this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertPage); }, alertSortBy: function () { var commentBlock = $('commentbloc'); if(xhr.readyState == 4) { if(xhr.status == 200) { var resp = xhr.responseText; commentBlock.innerHTML = resp; } else commentBlock.innerHTML = xhr.status; //recBlock.innerHTML = xhr.status; } }, SortBy: function(sort_type){ if (sort_type == "asc") { this.sortOrder = "asc"; $('sortby').innerHTML = 'Sort by:'; } else if (sort_type == "recommended") { this.sortOrder = "recommended"; $('sortby').innerHTML = 'Sort by:'; } else { this.sortOrder = "desc"; $('sortby').innerHTML = 'Sort by:'; } var parameters = 'action=SortBy&user_id='+encodeURI(this.user[0])+'&guid='+encodeURI(ArticleID)+'&sortby='+sort_type; this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, this.alertSortBy); }, LoadComRec: function(){ var host_url = document.URL.split('/'); var xhr3 = new Ajax.Request('http://'+host_url[2]+'/common/community_interface/communityAjax.php', { parameters:{action:'getComRec', user:encodeURI(this.user[1]), user_id:encodeURI(this.user[0]), guid:encodeURI(ArticleID)}, onSuccess: function(transport) { $('pk_com_rec').innerHTML = transport.responseText; }}); }, LoadCommentForm: function(){ if(document.domain=='newsarama.com') return false; var cform = new Element('div',{ 'id': 'pk_commentForm' }); var host_url = document.URL.split('/'); var xhr2 = new Ajax.Request('http://'+host_url[2]+'/common/community_interface/communityAjax.php', { parameters:{action:'getCommentForm', guid:encodeURI(ArticleID)}, onSuccess: function(transport) { cform.update(transport.responseText); $('pk_comments').parentNode.appendChild(cform); $('SiteLife_Login').style.display = $('btnSubmitCommentDis').style.display = (community.user) ? 'none' : ''; $('SiteLife_Logout').style.display = $('btnSubmitComment').style.display = (community.user) ? '' : 'none'; $('SiteLife_Logout').innerHTML = "

LogoutYou are logged in as: "+community.user[1]+"

Post your comment:

"; $('commentText').disabled = $('btnSubmitComment').disabled = !community.user; $('btnSubmitCommentDis').disabled = community.user; $('commentText').value = (community.user) ? '' : 'You are currently not logged in.\nYou must be logged in to leave a comment.'; $('commentText').style.width = ($('pk_commentForm').offsetWidth - 40)+"px"; }}); } }); communityclass.addMethods({ ck_user: function(obj, bol){ if($('user_error')){ $('user_error').remove(); } if($('input_note')){ $('input_note').remove(); } if($(obj).getValue()) if(bol){ var url = 'http://'+this.site_name+'/common/community_interface/communityAjax.php'; var myRequest = new Ajax.Request(url, { parameters:{userName:$(obj).getValue(), action:'CheckUsernameAvailability'}, onSuccess: function(r) { if(r.responseText >= 1) { community.process_err($('user').parentNode, 'Sorry, the username you have requested is unavailable.'); $('user').className = 'error'; } else { $('user').className = 'okdokay'; community.process_ok($('user').parentNode, 'Your requested username is available.'); var w_note = $('pk_register').select('div#pk_note')[0]; w_note.className = ''; w_note.innerHTML = '

To join the community, please complete the registration form below. After that, we will send a confirmation email containing a validation link to the address you provide. Check your inbox!

'; } }}); } }, process_err: function(obj, error){ try{ var e = new Element('span',{ 'id': 'user_error','class':'error_msg' }); obj.appendChild(e); $('user_error').update(error); }catch(e){ alert(e); } }, process_ok:function(obj, note){ try{ var e = new Element('span',{ 'id': 'input_note','class':'okdokay' }); obj.appendChild(e); $('input_note').update(note); }catch(e){ alert(e); } } }); communityclass.addMethods({ autoLog: function(str){ //// returned from cookie monster //// var arg = str.split(","); this.setCookie(this.cookieKey, arg[0],arg[1],arg[2],arg[3],arg[4]); }, getCookie: function(ck){ var arrCookies = this.cookieJar(ck); var strValue = arrCookies ? arrCookies[1] : false; return strValue; }, setCookie: function(){ var arg = $A(arguments); var key = arg.shift(); var datearray = this.cookieExpDate.split("-"); if(this.keeplogged){ var expdate = new Date(datearray[0], datearray[1], datearray[2]); document.cookie = key + "=" +arg.join('|') + ";expires="+expdate+";path=/;"; }else{ document.cookie = key + "=" +arg.join('|') + ";path=/;"; } if(key == this.cookieKey){ this.user = arg; this.setModules(); } }, eatCookies: function(ck){ // no more cookie var strValue = this.getCookie(ck); if(strValue){ dtYesterday=new Date(); dtYesterday.setDate(dtYesterday.getDate()-10); var parameters = 'action=DeleteCookies'; this.makePOSTRequest('http://'+this.site_name+'/common/community_interface/communityAjax.php', parameters, function(){}); document.cookie = ck + "=;" + "path=/" + ";domain=.livescience.com" + ";expires=" + dtYesterday.toGMTString(); document.cookie = ck + "=;" + "path=/" + ";expires=" + dtYesterday.toGMTString(); } this.callCookieMonster('clearSSO','livescience.com'); this.user = false; setTimeout( function(){ window.location.href = document.URL; } , 1000); }, cookieJar: function(ck){ // gather cookies var cookies = document.cookie.split(";"); var aCookie = []; try{ cookies.each(function(c){ var t = c.strip().split("="); if(t[0]==ck){ if (t[1].indexOf('avatar') && typeof(t[2]) != "undefined") {t[1] = t[1]+'='+t[2];} var s = unescape(t[1]); t[1] = s.split("|"); aCookie.push(t)}}); } catch(err) { alert(err) } return aCookie.grep(ck)[0]; }, callCookieMonster: function(){ var qs; if (arguments.length != 0){ qs = 'functionName=' + escape(arguments[0]); if (arguments.length > 1){ var justArgs = new Array(); for (var i = 1; i < arguments.length; ++i) { qs += ('&d' + (i-1) + "=" + escape(arguments[i])); } } } var divName = $('om_nomnom'); if(!divName){ var divName = new Element('div',{ 'id': 'om_nomnom' }); this.objBody.appendChild(divName); } //this.FO.setFlashvars(qs); //divName.innerHTML = this.FO.toString(); this.setModules(); } });