// JavaScript Document
var id;
var func;
var baseUrl = "http://waterfalls.jacobemerick.com/php/commenter.php";
function getObj(id) {
return document.getElementById(id);}
function addEvents(id,func) {
if(getObj(id).addEventListener) {
getObj(id).addEventListener('click',func,false);}
if(getObj(id).attachEvent) {
getObj(id).attachEvent('onclick',func);}}
function addNewEvents() {
var replyLinks = getObj('comment_box').getElementsByTagName('a');
for(var i in replyLinks) {
if(replyLinks[i].id) {
addEvents(replyLinks[i].id,newComment);}}}
function newComment() {
if(this.id) {
var type = this.id.substring(13);}
else if(window.event) {
if(window.event.srcElement!=null) {
var type = window.event.srcElement.id.substring(13);}
else {
var type = getObj('login').parentNode.id.substring(8);
getObj('login').parentNode.removeChild(getObj('login'));}}
else {
var type = getObj('login').parentNode.id.substring(8);
getObj('login').parentNode.removeChild(getObj('login'));}
var url = baseUrl+"?action=new&type="+type+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
if(getObj('commenter')) {
var old_type = getObj('commenter').parentNode.id.substring(8);
if(old_type=='new') {
getObj('commenter').parentNode.innerHTML = getObj('commenter').parentNode.innerHTML + '';}
else {
getObj('commenter').parentNode.innerHTML = getObj('commenter').parentNode.innerHTML + '';}
addEvents('comment_link_'+old_type,newComment);
getObj('commenter').parentNode.removeChild(getObj('commenter'));}
else if(getObj('login')) {
var old_type = getObj('login').parentNode.id.substring(8);
if(old_type=='new') {
getObj('login').parentNode.innerHTML = getObj('login').parentNode.innerHTML + '';}
else {
getObj('login').parentNode.innerHTML = getObj('login').parentNode.innerHTML + '';}
addEvents('comment_link_'+old_type,newComment);
getObj('login').parentNode.removeChild(getObj('login'));}
if(getObj('comment_link_'+type)) {
getObj('comment_link_'+type).parentNode.removeChild(getObj('comment_link_'+type));}
getObj('comment_'+type).innerHTML = getObj('comment_'+type).innerHTML+xmlHttp.responseText;
if(xmlHttp.responseText.substring(10,15)=='login') {
addEvents('login_comment',login);
addEvents('register_comment',register);}
else {
addEvents('submit_comment_'+type,submitComment);}}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}
function submitComment() {
if(this.id) {
var type = this.id.substring(15);}
else if(window.event) {
var type = window.event.srcElement.id.substring(15);}
var data = getObj('comment').value;
if(data.length>1000) {
alert("Your comment is too long. Please shorten it to less then a thousand characters.");}
else {
var url = baseUrl+"?action=submit&type="+type+"&data="+escape(data)+"&url="+escape(document.URL)+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
if(xmlHttp.responseText=='Error 1') {
alert("You must type a comment to submit it.");}
else if(xmlHttp.responseText=='Error 2') {
alert("Sorry, you tried to enter a character that wasn't acceptable. Please simplify your comment and try again.");}
else if(xmlHttp.responseText=='Error 3') {
alert("There seems to be a problem with the database. Please try again later.");}
else if(xmlHttp.responseText=='Error 4') {
alert("You cannot post comments on this page. Please try again.");}
else {
getObj('commenter').parentNode.removeChild(getObj('commenter'));
if(type=='new') {
var new_type = xmlHttp.responseText.substring(0,9);
var new_div = document.createElement('div');
new_div.id = 'comment_'+new_type;
new_div.className = 'comment';
new_div.innerHTML = xmlHttp.responseText.substring(9);
getObj('comment_new').parentNode.insertBefore(new_div,getObj('comment_new'));
addEvents('comment_link_'+new_type,newComment);
getObj('comment_new').innerHTML = '';
addEvents('comment_link_new',newComment);}
else {
getObj('comment_'+type).innerHTML = getObj('comment_'+type).innerHTML+xmlHttp.responseText;
addEvents('comment_link_'+type,newComment);}}}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}}
function login() {
var uname = getObj('uname').value;
var upass = getObj('upass').value;
var url = baseUrl+"?action=login&uname="+escape(uname)+"&upass="+escape(upass)+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
if(xmlHttp.responseText=='Error 1') {
alert("You must type in values to submit it.");}
else if(xmlHttp.responseText=='Error 2') {
alert("Sorry, you tried to enter a character that wasn't acceptable. Please try again.");}
else if(xmlHttp.responseText=='Error 3') {
alert("There seems to be a problem with the database. Please try again later.");}
else if(xmlHttp.responseText=='Error 4') {
alert("Your login failed. Please try again or register for an account.");}
else if(xmlHttp.responseText=='Error 5') {
alert("You must enable your cookies to login.");}
else {
newComment();}}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}
function register() {
var uname = getObj('runame').value;
var upass = getObj('rupass').value;
var email = getObj('remail').value;
var url = baseUrl+"?action=register&uname="+escape(uname)+"&upass="+escape(upass)+"&email="+escape(email)+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
if(xmlHttp.responseText=='Error 1') {
alert("You must type in values to submit it.");}
else if(xmlHttp.responseText=='Error 2') {
alert("Sorry, you tried to enter a character that wasn't acceptable. Please try again.");}
else if(xmlHttp.responseText=='Error 3') {
alert("Both your username and password must be at least six characters long. Please try again.");}
else if(xmlHttp.responseText=='Error 4') {
alert("There seems to be a problem with the database. Please try again later.");}
else if(xmlHttp.responseText=='Error 5') {
alert("This username is taken. Please try a different one.");}
else if(xmlHttp.responseText=='Error 6') {
alert("Your email seems to not work. Please try again.");}
else {
var old_type = getObj('login').parentNode.id.substring(8);
if(old_type=='new') {
getObj('login').parentNode.innerHTML = getObj('login').parentNode.innerHTML + '';}
else {
getObj('login').parentNode.innerHTML = getObj('login').parentNode.innerHTML + '';}
addEvents('comment_link_'+old_type,newComment);
getObj('login').parentNode.removeChild(getObj('login'));
alert("Your account has been created but is not active yet. Please check your email for an activation link.");}}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}
if(document.addEventListener) {
document.addEventListener("DOMContentLoaded",addNewEvents,false);}
else {
if (document.all && !window.opera){
document.write('