var menuSpeed=10;

function getElementsByClassName(classname) {
	var node=document.getElementsByTagName("body")[0];
	var a=[];
	var re=new RegExp('\\b' + classname + '\\b');
	var els=node.getElementsByTagName("*");
	for(var i=0; i<els.length; i++)
		if(re.test(els[i].className))
			a.push(els[i]);
	return a;
}

function showTell(h,i) {
  if(!i) {
    i=parseInt(getElementsByClassName("tell")[0].style.height.replace("px",""));
    document.getElementById('tellBullet').src="images/tellBulletD.jpg";
  }
  
  if(!h) {
    h=370;
  }

  if(i<370) {
    i+=menuSpeed;
    getElementsByClassName("tell")[0].style.height=i+"px";
    setTimeout("showTell("+h+","+i+")",1);
  }
}

function showRead(h,i) {
  if(!i) {
    i=parseInt(getElementsByClassName("read")[0].style.height.replace("px",""));
    document.getElementById('readBullet').src="images/readBulletD.jpg";
  }
  
  if(!h) {
    h=370;
  }

  if(i<h) {
    i+=menuSpeed;
    getElementsByClassName("read")[0].style.height=i+"px";
    setTimeout("showRead("+h+","+i+")",1);
  }
}

function convertLineBreaks(str) {
  while(str.search("\n")>-1)
    str=str.replace("\n","<br/>")
  return str;
}

function submitComment() {
  var pass=true;
  
  if(document.forms[0].author.value=="") {
    document.getElementById("nameLabel").style.color="#F00";
    document.getElementById("nameLabel").style.fontWeight="bold";
    pass=false;
  }
  
  if(document.forms[0].email.value=="") {
    document.getElementById("emailLabel").style.color="#F00";
    document.getElementById("emailLabel").style.fontWeight="bold";
    pass=false;
  }
  
  if(document.forms[0].comment.value=="" ||
     document.forms[0].comment.value=="Please enter a comment before submission.") {
    document.forms[0].comment.value="Please enter a comment before submission.";
    pass=false;
  }

  if(pass) {
    getElementsByClassName("hidden")[1].src=""+
      "commentsRedirect.php?author="+document.forms[0].author.value+
      "&email="+document.forms[0].email.value+
      "&comment="+convertLineBreaks(document.forms[0].comment.value);
    
    getElementsByClassName("content")[0].innerHTML="<br/><br/><br/>Thank you for sharing your story!";
  }
}

function loadPage() {
  getElementsByClassName("tell")[0].style.height="40px";
  getElementsByClassName("read")[0].style.height="40px";
}
