function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

// Removes leading whitespaces
function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

// Removes ending whitespaces
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value ) {	
	return LTrim(RTrim(value));	
}


function LineNameOnChange()
{
   var stringlength;
 	var stringRoute;
	
	stringRoute = trim(document.schedule.LineAbbr.value.toUpperCase());

	if (stringRoute.indexOf('VIVA')>-1)
	{
		if(stringRoute.indexOf('BLUE')>-1)	{
			document.schedule.LineAbbr.value= '601';
		}
		else if(stringRoute.indexOf('PURPLE')>-1)	{
			document.schedule.LineAbbr.value= '603';
		}
		else if(stringRoute.indexOf('PINK')>-1)	{
			document.schedule.LineAbbr.value= '604';
		}
		else if(stringRoute.indexOf('ORANGE')>-1)	{
			document.schedule.LineAbbr.value= '605';
		}
		else if(stringRoute.indexOf('GREEN')>-1)	{
			document.schedule.LineAbbr.value= '606';
		}
		return true;	
	}
	
	
	if(stringRoute == '2A' || stringRoute == '02A')										 {
		stringRoute = '002A';
	}
	else if(stringRoute == '224B')				{
		stringRoute = '0224B';
	}
	
	stringlength = stringRoute.length;
	
	switch (stringlength)
		{
		 case 1:
		 			{
			 		 document.schedule.LineAbbr.value= "00" + stringRoute;
					 break;
					}
		
		case 2:
				 	{
					 if(!isDigit(document.schedule.LineAbbr.value.charAt(1))) 		
					 {
							document.schedule.LineAbbr.value= "00" + stringRoute;
					 }
					 else	
					 {
					 		document.schedule.LineAbbr.value= "0" + stringRoute;
					 }
			 		 //document.schedule.LineAbbr.value= "0" + stringRoute;
					 break;
					}	
		case 3:
				 	{
					 if(!isDigit(document.schedule.LineAbbr.value.charAt(2))) 		
					 {
							document.schedule.LineAbbr.value= "0" + stringRoute;
					 }
					 else	
					 {
					 		document.schedule.LineAbbr.value=stringRoute;
					 }									
					 break;
					}						
		default:
					{
						if(document.schedule.LineAbbr.value.indexOf('-') == -1) 														
						{
							document.schedule.LineAbbr.value=stringRoute;
						}
						else
						{
							document.schedule.LineAbbr.value=trim(stringRoute.substr(0, stringRoute.indexOf('-')));
						}
					}
		}	
	
	<!--var la = document.schedule.LineAbbr.value;-->
	var la = stringRoute;

	if (la.indexOf("'") != -1)
		{
			la = la.replace("'","");
			document.schedule.LineAbbr.value = la;
		}
}
