				function doRTrim(control){
				    
				    while(''+control.value.charAt(control.value.length-1)==' '){
				        control.value = control.value.substring(0,control.value.length-1);
				    }
				    return control; 
				}				
				function validateForm(activeForm) {
					//alert("testing");
					var firstBadElement = null
					var isValid = true
					var collectAll = true
					var errorMessage = ""
					    for (i=0;i < activeForm.elements.length  && (isValid || collectAll);i++) {
					        elm = activeForm.elements[i]
					        if (elm.type == "text") doRTrim(elm);
							//if (elm["required"] == "true")
							//	alert(elm["required"] );
					        if (elm.required == "true" && elm.value.length < 1){
					                    isValid = false;
					                    errorMessage += "You must enter a " + elm.name + ".\n"
					                    if (firstBadElement == null) 
					                    	firstBadElement = elm
					        }
					    }
					    if (firstBadElement != null && firstBadElement.type != "hidden") {
					        firstBadElement.focus();
					    }
					if (!isValid)
						alert(errorMessage);
					return isValid;
				}

				function validateAndSubmitForm(activeForm) {
	    
					if (validateForm(activeForm))
//						alert("good");
						activeForm.submit();
						
				}
/*function removeFromString(text, chars) {
	
	pos = text.indexOf(chars,0);
	while (pos > -1) {
		text = text.substring(0,pos) + text.substring(pos+chars.length, text.length);
		pos = text.indexOf(chars, pos);
	}
	return text

}*/

function wrap(text, lineSize, newlinechar) 
{
	var output = "";
	if (newlinechar == "\n" && text.indexOf("\r\n", 0) > -1)
		newlinechar = "\r\n";

	//base case when single short line
	if (text == undefined || lineSize <= 0) 
	{
		return "";
	}
	else 
	{
		var lines = text.split(newlinechar);
		for (var i = 0; i < lines.length ; i++) 
		{
//			alert("'"+lines[i]+"'");
			// Insert line feed after first line: 
			// Note: extra space is needed to fake out JavaScript/<pre> tag issue 
			// in which multiple adjacent new lines are collapsed into a single new line
			if (i > 0) output += " " + newlinechar;

			output += wrapLine(lines[i], lineSize, newlinechar);
		}
	}
	return output;
}


// Convert given line of 'text' into multiple lines separated by 'newlinechar' with each line no greater than 
// 'lineSize' in length.
function wrapLine(text, lineSize, newlinechar) 
{
	if (text.length <= lineSize)
	{
		return text;
	}

	var output = "";

	// Locate last space before boundary
	var pos = -1;
	for (i = lineSize; i >= 0 && pos == -1; i--) 
	{
		if (text.charAt(i) == ' ') 
		{
			pos = i;	
		}
	}
	
	// If space not found, chop at the boundary
	if (pos == -1) pos = lineSize;
	
	output = text.substring(0,pos+1) + newlinechar;
	output += wrapLine(text.substring(pos+1, text.length), lineSize, newlinechar);			
	return output;	
}		
