function displayRemLength(fieldName) {
	remField = document.getElementById(fieldName);
        if (remField!=null)
        {
            
            remField.innerHTML = (maxCharCount - charCount > 0) ? maxCharCount - charCount : 0;
        }
}

function evalEntryLength(curField, maxLimit, discardXtra, errClass, normalClass) {
	maxCharCount = maxLimit;
        if (curField==null) return;
        
	var fieldLength = getCharCount(curField);
	
	if (fieldLength > maxLimit) 
	{	   
		if (errClass != "") {
			curField.className = errClass;			  
		}
		if (discardXtra) {
			showAllowedLength(curField, maxLimit);
		}
		 alert('Too much data in the text box!');
	} else if (normalClass != "") {
		curField.className = normalClass;
	}
}

function showAllowedLength(curField, maxLimit) {
   curField.value = curField.value.substr(0, maxLimit);
   window.status = curField.value;
}

function getCharCount(curField) {
        if (curField!=null)
        {
            // can't just do a length because firefox treats carriage return as 1 character but
            // the server treats it as 2 characters
            var temp = new String(curField.value);

            // this is for IE clients
            while (temp.indexOf('\r\n') >=0) {
                temp = temp.replace('\r\n', '  ');
            }

            //  this is for firefox clients
            while (temp.indexOf('\n') >=0) {
                temp = temp.replace('\n', '  ');
            }

           charCount = temp.length;
            return charCount;
        }
}

var k=0;
var instruct='describe your needs here, and get personalized responses from advertisers that compete for your business in real-time';
function typeTxt()
{
   if (!animationOn) return;
   k++;
   document.qform.admessage.value = instruct.substring(0,k);
   document.qform.admessage_compare.value = instruct.substring(0,k);
   if (k<instruct.length)
   {
        setTimeout('typeTxt()', 14)
   }
   else
   {
        document.getElementById('admessage').focus();
   }

}

function keyhandler(e) {
        if (pressflag) return true;
        setToEnteringQuestion(document.getElementById('admessage'));
        document.getElementById('admessage').focus();

}

function setToEnteringQuestion(element) {
    if (!pressflag)
    {
        animationOn = false;
        document.qform.admessage.value = '';
        pressflag = true;

    }
}

animationOn = true;
document.getElementById('admessage').onkeypress = keyhandler;
pressflag = false;
var charCount;
evalEntryLength(document.getElementById('admessage'), 140, true, '', '');
displayRemLength('charCount1');typeTxt();
