function showRules() {
  window.open('rules.htm','rules','width=600,height=500,scrollbars=yes,menubar=no');
}
function iFocus(obj) {
  obj.className='input_on';
}
function iBlur(obj) {
  obj.className='input';
}
function updateWR(obj) {
	var word_count = CountWords(obj.value);	
	while (word_count > 300) {
		obj.value = obj.value.substr(0, obj.value.length-2)
		word_count = CountWords(obj.value);
	}
	document.getElementById('div_wr').innerHTML = 300 - word_count;
}

function CountWords (obj) {
	var char_count = obj.length;
	var fullStr = obj + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	if (fullStr.length <2) {
		word_count = 0;
	}
	return word_count;
}

function fnPaste(vEl) {
	var intMaxLength, intCurrLength, strClip ;
  var intClipLength, intAvailLength ;
  var blnReturn = true ;
  intMaxLength = 300; //vEl.getAttribute("maxlength") ;
  intCurrLength = CountWords(vEl.value);
  strClip = window.clipboardData.getData("Text") ;
  intClipLength = CountWords(strClip);
  intAvailLength = intMaxLength - intCurrLength;
	intTotalLength = intCurrLength + intClipLength;
	if ((intTotalLength) > intMaxLength) {
		if (confirm("You are trying to paste " + intClipLength + " words, which will bring the total # words to " + intTotalLength + "\nWould you like to truncate essay to fit this field?")) {
     	while (CountWords(strClip) > intAvailLength) {
				strClip = strClip.substr(0, strClip.length-2);
			}
    	window.clipboardData.setData("Text",strClip);
			document.getElementById('div_wr').innerHTML = "0";
		}
		else {
			blnReturn = false;
		}
  }
	else {
		document.getElementById('div_wr').innerHTML = intMaxLength - intTotalLength;
	}
	return blnReturn ;
}