function cleanData(str)
{
	str = removePunctuations(str);
	str = removeExtraSpaces(str);
	str = trim(str);
	str = toProperCase(str);

	return str;
}

function applyUSPostalStreetSuffixes(str)
{
	str = str.replace(/\bAlley$/i, "ALY");
	str = str.replace(/\bArcade$/i, "ARC");
	str = str.replace(/\bAvenue$/i, "AVE");
	str = str.replace(/\bBoulevard$/i, "BLVD");
	str = str.replace(/\bBypass$/i, "BYP");
	str = str.replace(/\bCanyon$/i, "CYN");
	str = str.replace(/\bCauseway$/i, "CSWY");
	str = str.replace(/\bCenter$/i, "CTR");
	str = str.replace(/\bCircle$/i, "CIR");
	str = str.replace(/\bCourt$/i, "CT");
	str = str.replace(/\bDrive$/i, "DR");
	str = str.replace(/\bEstate$/i, "Est");
	str = str.replace(/\bExpressway$/i, "EXPY");
	str = str.replace(/\bFreeway$/i, "FWY");
	str = str.replace(/\bJunction$/i, "JCT");
	str = str.replace(/\bLane$/i, "LN");
	str = str.replace(/\bParkway$/i, "PKWY");
	str = str.replace(/\bPlace$/i, "PL");
	str = str.replace(/\bPlaza$/i, "PLZ");
	str = str.replace(/\bPoint$/i, "PT");
	str = str.replace(/\bRanch$/i, "RNCH");
	str = str.replace(/\bRoad$/i, "RD");
	str = str.replace(/\bStreet$/i, "ST");
	str = str.replace(/\bTrail$/i, "TRL");
	str = str.replace(/\bSuite$/i, "STE");
	
	return str;
}

function cleanAddressLines(str)
{
	str = cleanData(str)
	str = applyUSPostalStreetSuffixes(str);
	str = toProperCase(str);

	return str;
}

function removePunctuations(str)
{
	return str.replace(/(\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\{|\}|\[|\]|\:|\;|\"|\'|\<|\,|\>|\.|\?|\||\\)/g, " ");
}

function removeExtraSpaces(str)
{
	return str.replace(/\s{2,}/g, " ");
}

function trim(str)
{
	return str.replace(/^\s*|\s*$/g, "");
}

function toProperCase(str)
{
	return str.toLowerCase().replace(/^(.)|\s(.)|\-(.)/g,
		function($1) { return $1.toUpperCase(); });
}

function limitTextLength(field, limit)
{
	if (field.value.length > limit) //trim it
			field.value = field.value.substring(0, limit);

}

function limitText(noteField, noteLimit, infoField)
{
	var charsLeft;

	if (noteField.value.length > noteLimit) //trim it
			noteField.value = noteField.value.substring(0, noteLimit);
			
	charsLeft = noteLimit - parseInt(noteField.getAttribute('value').length);
	infoField.setAttribute('innerText', 'Remaining characters: ' + charsLeft.toString());
}




