		String.prototype.trim = function() {
        a = this.replace(/^\s+/, '');
        return a.replace(/\s+$/, '');
        };

        //validating url
        function checkURL(url)
        {
            var theurl="http://www."+url;
            return /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(theurl);
        }
        
        //date format should be dd/mm/yyyy
        function validateDates(aStartDate,aEndDate)
        {
	        var endDate = aEndDate;
	        var startDate = aStartDate;

	        startYear = startDate.substr(6,4) -0;
	        startMonth = startDate.substr(0,2) - 1;
	        startDay = startDate.substr(3,2) - 0;

	        startDate = new Date (startYear, startMonth, startDay);

	        endYear = endDate.substr(6,4) -0;
	        endMonth = endDate.substr(0,2) - 1;
	        endDay = endDate.substr(3,2) - 0;

	        endDate = new Date (endYear, endMonth, endDay);

	        if (startDate > endDate)
	        {
		        return false;
	        }
	        else
	        {
		        return true;
	        }
        }

		function removeBreaks(oldValue)
		{

			var para = 1;
			var nopara = true;
			var noBreaksText = oldValue;

			noBreaksText = noBreaksText.replace(/(\n\r|\n|\r)/gm,"<1br />");

			re1 = /<1br \/><1br \/>/gi;
			re1a = /<1br \/><1br \/><1br \/>/gi;

			if(nopara == 1 || nopara ==  true){
			noBreaksText = noBreaksText.replace(re1," ");
			}else{
			noBreaksText = noBreaksText.replace(re1a,"<1br /><2br />");
			noBreaksText = noBreaksText.replace(re1,"<2br />");
			}

			re2 = /\<1br \/>/gi;
			noBreaksText = noBreaksText.replace(re2, " ");

			re3 = /\s+/g;
			noBreaksText = noBreaksText.replace(re3," ");

			re4 = /<2br \/>/gi;
			noBreaksText = noBreaksText.replace(re4,"\n\n");
			return noBreaksText;
		}
						
		function enableControl(oCntrl)
		{
			if(document.getElementById(oCntrl) != null)
			{
				document.getElementById(oCntrl).disabled=true
			}
		}
		
		function disableControl(oCntrl)
		{
			if(document.getElementById(oCntrl) != null)
			{
				document.getElementById(oCntrl).disabled=false
			}
		}
			
		function doCountrySelect(oDropdown,checkText,disableControlName,enableControlName)
		{
			var x=document.getElementById(oDropdown.name)
			selectedText = x.options[x.selectedIndex].text;
            
           if(selectedText == "Select Country")
            {
               enableControl('State1');
               disableControl('State');
               document.getElementById(enableControlName).value = "";
            }
            else
            {
       		    if(selectedText != checkText)
			    {
				    enableControl(disableControlName);
				    disableControl(enableControlName);
			    }
			    else
			    {	
			        document.getElementById(enableControlName).value = "";
				    disableControl(disableControlName);
				    enableControl(enableControlName);
			    }
			}
		}	
		function htmlEncode(s)
		{
			var str = new String(s);
			str = str.replace(/&/g, "&amp;");
			str = str.replace(/</g, "&lt;");
			str = str.replace(/>/g, "&gt;");
			str = str.replace(/"/g, "&quot;");
			return str;
		}
	
		function getFocus(fieldName)
		{
			document.getElementById(fieldName).focus();
		}
		
		function hideControl(val,divName)
		{
			if(val!="Yes")
			{
				document.getElementById(divName).style.display = "none";
			}
			else
			{
				document.getElementById(divName).style.display = "";
			}
		}
		
		function numbersonly(event) 
		{ 
		    var strDisplay = (navigator.appName.indexOf("Internet Explorer") != -1) ? "MSIE" :"Mozilla";
			if(strDisplay=="Mozilla")
			{
		
					if (event.charCode==0)
					{
						return true;
					}
					else
					{
						if (event.charCode<48||event.charCode>57||event.charCode==0)
						{ 
							return false; 
						} 
					}
					
			}
			else
			{
				if (event.keyCode<48||event.keyCode>57||event.keyCode==8) 
				{ 
					event.returnValue = false; 
				} 
			}
		}

        function numbersonly(event,IsDecimal) 
		{ 
		    var strDisplay = (navigator.appName.indexOf("Internet Explorer") != -1) ? "MSIE" :"Mozilla";
			if(strDisplay=="Mozilla")
			{
					if (event.charCode==0)
					{
					    return true;
					}
					else
					{
					    if (event.charCode == 46)
						{
						    return true;
						}
						if (event.charCode<48||event.charCode>57||event.charCode==0)
						{ 
							return false; 
						} 
					}
					
			}
			else
			{
				if (event.keyCode<48||event.keyCode>57||event.keyCode==8) 
				{ 
				    event.returnValue = false; 
				} 
			    if(IsDecimal == true)
			    {
			        if(event.keyCode == 46)
			        {
			            event.returnValue = true;
			        }
				}
			}
		}
		
		
		function replace(string,text,by)
		{
			// Replaces text with by in string
				var strLength = string.length, txtLength = text.length;
				if ((strLength == 0) || (txtLength == 0)) return string;

				var i = string.indexOf(text);
				if ((!i) && (text != string.substring(0,txtLength))) return string;
				if (i == -1) return string;

				var newstr = string.substring(0,i) + by;

				if (i+txtLength < strLength)
					newstr += replace(string.substring(i+txtLength,strLength),text,by);

				return newstr;
		}

		
		function isValidateSpecialChar(fieldname)
		{
			 var iChars = "0123456789~`!@#$%^*+=\\\';,{}|\":<>?_";
			 for (var i = 0; i < fieldname.length; i++) 
			 {
			 	if (iChars.indexOf(fieldname.charAt(i)) != -1)
				{
					return false;
				}
			 }
		}
		
		function isAlphanumericsOnly(aValue)
		{
			if (aValue.search(/^[a-zA-Z0-9]+$/) == -1)
				return false;
			else
				return true;
		}


		function isAlphabetsOnly(aValue)
		{
			if (aValue.search(/^[a-zA-Z]+$/) == -1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function isNumber(nValue)
		{
			if (nValue.search(/^-{0,1}\d*\.{0,1}\d+$/) == -1 )
				return false;
			else
				return true;
		}

		function ReplaceComma(sOrgVal,sSearchVal,sReplaceVal) 
		{ 
		   var sVal; 
		   try 
		   { 
		      sVal = new String(sOrgVal); 
		      if (sVal.length < 1) { return sVal; } 
		      var sRegExp = eval("/" + sSearchVal + "/g"); 
		      sVal = sVal.replace(sRegExp,sReplaceVal); 
		   } 
		   catch (exception)  { } 
		   return sVal; 
		
		} 
		function removeComma()
		{
			var MilesValue;
			MilesValue = document.frm_Register.apc01_1p_v01_p1_miles.value;
			var NewValue = ReplaceComma(MilesValue,",",""); 
			document.frm_Register.apc01_1p_v01_p1_miles.value = NewValue;
		}

        function isEmailId(eValue)
        {

	        if (eValue.search(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == -1)
        	
		        return false;
	        else
		        return true;
        }


        function Trim(TRIM_VALUE)
        {
        if(TRIM_VALUE.length < 1){
        return"";
        }
        TRIM_VALUE = RTrim(TRIM_VALUE);
        TRIM_VALUE = LTrim(TRIM_VALUE);
        if(TRIM_VALUE==""){
        return "";
        }
        else{
        return TRIM_VALUE;
        }
        } //End Function

        function RTrim(VALUE){
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
        if(v_length < 0){
        return"";
        }
        var iTemp = v_length -1;

        while(iTemp > -1){
        if(VALUE.charAt(iTemp) == w_space){
        }
        else{
        strTemp = VALUE.substring(0,iTemp +1);
        break;
        }
        iTemp = iTemp-1;

        } //End While
        return strTemp;

        } //End Function

        function LTrim(VALUE){
        var w_space = String.fromCharCode(32);
        if(v_length < 1){
        return"";
        }
        var v_length = VALUE.length;
        var strTemp = "";

        var iTemp = 0;

        while(iTemp < v_length){
        if(VALUE.charAt(iTemp) == w_space){
        }
        else{
        strTemp = VALUE.substring(iTemp,v_length);
        break;
        }
        iTemp = iTemp + 1;
        } //End While
        return strTemp;
        } 

        function s(num, val) {
        amount = num * 1; // amount is the num or NaN
        sum = (!num ? 0 : num) * val;  // the sum for that bill or coin

        if (isNaN(amount)) { // if the entire is not a number

        alert(
        "' " + num + " ' is not a valid entry and that field will "
        + "not be included in the total money calculation."
        );

        return 0;
        }
        else
        return sum; // if it is OK, send sum back
        }

        function money(cntrlID) 
        {

        one = s(document.getElementById(cntrlID).value, 1);

        // add up all the amounts
        var ttl = one ;

        // rounds total to two decimal places

        ttl = "" + ((Math.round(ttl * 100)) / 100);

        dec1 = ttl.substring(ttl.length-3, ttl.length-2);
        dec2 = ttl.substring(ttl.length-2, ttl.length-1);

        if (dec1 != '.') { // adds trailing zeroes if necessary
        if (dec2 == '.') ttl += "0";
        else ttl += ".00";
        }
        document.getElementById(cntrlID).value = ttl; 
        }

        function ValidateTextAreaLength(field, maxlen,msg) 
        {
            if (field.value.length > maxlen + 1)
            alert(msg);
            if (field.value.length > maxlen)
            field.value = field.value.substring(0, maxlen);
        } 
        
        
    function __Trim(value)
    {
	    value = value.replace(/^\s+/g, "" );
	    value = value.replace( /\s+$/g, "" );
	    return value;
    }
