// JavaScript Document
function story(){
	
	inputtitle=document.form.title.value;
	inputnewauthor=document.form.newauthor.value;
	inputprevauthor=document.form.prevauthor[document.form.prevauthor.selectedIndex].value;
	inputemail=document.form.email.value;
	inputtype=document.form.type[document.form.type.selectedIndex].value;
	inputtext=document.form.text.value;
	var boxCheck = false;
	if (document.form.copyright.checked) {
	boxCheck = true; }

		
	if (inputtitle==""){
	document.form.title.focus();
	alert("Please type in a title for your story.");
	return false;
	}
	else if (inputnewauthor=="" && inputprevauthor==""){
	document.form.prevauthor.focus();
	alert("Please either choose the drop down menu if you are a returning author OR type in your author's name.");
	return false;
	}
	else if (inputprevauthor!="" && inputnewauthor!=""){
	document.form.prevauthor.focus();
	alert("Please choose only one of the author fields.");
	return false;
	}	
	
	else if (inputemail==""){
	document.form.email.focus();
	alert("Type in an email address - this is just so we can contact you and you can protect your author name.");
	return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(inputemail))){
	document.form.email.focus();
	alert("This is an invalid email.");
	return false;
	}
	else if (inputtype=="" ){
	document.form.type.focus();
	alert("Please choose a category");
	return false;
	}
	
	else if (!boxCheck) {
	
	alert("Please tick this box to confirm this statement.");
	return false;
	}
	else{
	repl(this.form['text'].value);
	return true;
	}

}

function repl(str) {
var tmpStr ="", i=0, start=0;

	while(i< str.length) {
		var c =str.charAt(i), d =str.charAt(i+1)

		tmpStr += (!start)? c : "";
			start =(c == '<')? tmpStr += d.toLowerCase() : 
			(start && d != '>')? tmpStr += d.toLowerCase() : 0; 
				
	i++;
	}
	document.forms[0]['text'].value = tmpStr;
}
