
var win = window;
var doc = document;
var output = '';
output += '<form name="dataForm" method="post" ';
output += ' target = "_blank" action="http://wordscount.info/hw/service/smog/analyze.jsp" onsubmit="return validate_form(this);">';
output += '<p>';
output += '<input type="text" name="document_title" size="40" onfocus="focusNClearInput(this);" value="Type document title here (optional)" \/><br \/>';
output += ' <textarea onfocus="focusNClearInput(this);" name="user_text"';

output += ' cols=\"' + win.params["cols"] + '\"';
output += ' rows=\"' + win.params["rows"] + '\"';
/**/
output += ' wrap="virtual"> SMOG Calculator - Paste text to be analyzed here (2000 words maximum, 30 minimum)<\/textarea><br \/>';
output += ' <input class="stype" type="submit" value=" Calculate SMOG grade " \/>'
output += ' <input class="stype" type="button" value=" Reset Form " onclick="document.dataForm.reset();" \/>';
output += ' <input type="hidden" name="service_id" value=\"' + win.params["serviceID"] + '\">';
output += ' <input type="hidden" name="service_name" value=\"' + win.params["serviceName"] + '\">';

output += '<\/p><\/form>';

document.write(output);

function validate_required(field)
{
	var maximum_text_length = 10000;
	var maxErrorMessage = "SMOG Calculator \n\nYou may have exceeded the 10000 character limit (~2000 words). Your text has been truncated and the remaining portion is being submitted for analysis.";
	var minimum_text_length = 100;
	var minErrorMessage = "SMOG Calculator \n\nYou may not have fewer than the 30 words minimum. Please try again.";
	var emptyErrorMessage = "SMOG Calculator \n\nPlease paste text before submitting. Thank you.";

	if (field.value==null || field.value=="" || field.value.length < minimum_text_length)
	{
		alert(minErrorMessage);
		return false;
	} else if (field.value.length > maximum_text_length) 
	{
		field.value = field.value.substring(0, maximum_text_length);
		alert(maxErrorMessage);
		return true;
	} else 
	{
		return true;
	}
}

function validate_form(thisform)
{
	if (validate_required(thisform.user_text)==false)
	{
		thisform.user_text.focus();
		return false;
	}else
	{
		return true;
	}
}

function clear_text(thisform)
{
	if (thisform.user_text.value == " SMOG Calculator - Paste text to be analyzed here (2000 words maximum, 30 minimum)")
	{
		thisform.user_text.value == "";
		thisform.user_text.focus();
	}

}
