
		////////////////////////////////////////////////////////////////////////////////////////////////
		// Function TimeFillOutFast()
		// Purpose	: Function takes an input field, and automatically converts the inputted into a valid timeformat.
		// 
		// Returns	: False for failure.. True : The paramerized inputfield is altered by the funtion.
		// Post-Con.: 
		//
		// Usage	: E.g. : onblur="TimeFillOutFast(this);"
		// History	:
		//
		// Misc		: The function can handle 3 different types of input from the user :
		// HH			Converted to : HH:00
		// HHMM			Converted to : HH:MM
		//
		////////////////////////////////////////////////////////////////////////////////////////////////
		function TimeFillOutFast(obj)
		{
			var x = obj.value;
				
			// Validate that the length is not null
			if (x != "")
			{

				if (x.length == 1)
				{
					
					var anum=/(^[0-9]$)/;
					if (anum.test(x))
						obj.value = "0" + x + ":00";
										
				}

				// If the length of the date is 2, the user entered a time like (02 or 19)
				// Therefore insert ":00" at end.
				if (x.length == 2)
				{
					
					var anum=/(^0[0-9]|1[0-9]|2[0-3]$)/;
					if (anum.test(x))
						obj.value = x + ":00";
										
				}
				
				if (x.length == 4)
				{
					var regXDate = new RegExp("^(\\d{2})(\\d{2})$");
					var matchArray = x.match(regXDate);
					if (matchArray == null)
					{
						return false;
					}
					else
					{
						hour		= matchArray[1];
						minute		= matchArray[2]; 
						
						if (hour > 23)
							return false;
						if (minute > 59)
							return false;
						obj.value =  hour + ":" + minute;
					}
				}
			}
		}		
		
		////////////////////////////////////////////////////////////////////////////////////////////////
	    // Function DateFillOutFast()
	    // Purpose	: The functions purpose is to alter the inputted into a valid dateformat (DD-MM-YYYY).
	    // 
	    // Returns	: False for failure.. True : The paramerized inputfield is altered by the funtion.
	    // Post-Con.: 
	    //
	    // Usage	: E.g. : onblur="DateFillOutFast(this);"
	    // History	:
	    //
	    // Misc		: The function can handle 3 different types of input from the user :
	    //
	    // DDMM			Converts to : DD-MM-YYYY (where year is the current year)
	    // DDMMYY		Converts to : DD-MM-YYYY (where year is from the abbrevation applied)
	    // DDMMYYYY		Converts to : DD-MM-YYYY (Just fillout with "-")
	    //
	    // ****** NEW ******
	    // seperators allowed (- , _ , /)
	    // D-M-Y
	    // DD-MM-YY
	    //
	    ////////////////////////////////////////////////////////////////////////////////////////////////
	    function DateFillOutFast(obj)
	    {
		    var x = obj.value;
		    // Validate that the length is not null
		    
		    if (x != "")
		    {
		        //handles dates with seperators
		        var seperators = new Array("-","/","_");

                for(s = 0;s<seperators.length;s++) {
                    var newString = "";
                    if(x.indexOf(seperators[s]) > -1) {
                        var parts = x.split(seperators[s]);
                        if(parts.length >= 2) {
                            
                            for(var i=0;i<parts.length;i++) {
                                if(parts[i].length == 1)
                                    parts[i] = "0"+parts[i];
                                if(parts[i].length == 2 || (parts[i].length == 4 && i == 2)) {
                                    newString += parts[i];    
                                }
                                else {
                                    return false;
                                }
                            }
                        }
                    }
                    if(newString.length > 0)
                        x = newString;
                }
                
			    // If not all characters are numeric the fast-expression is not valid..return false
			    var anum=/(^\d+$)/;
			    if (!anum.test(x))
				    return false;
    			
			    // If the length of the date is 4, the user may has inputted a date without year
			    if (x.length == 4)
			    {
    				
				    var regXDate = new RegExp("^(\\d{2})(\\d{2})$");
				    var matchArray = x.match(regXDate);
				    if (matchArray == null)
				    {
					    return false;
				    }
				    else
				    {
					    day		= matchArray[1];
					    month	= matchArray[2]; 
					    // as we didn't get year fom input, get it from the system.
					    var today = new Date();
					    year = takeYear(today);
    					
					    if (CheckDateFromArrays(day, month, year))
					    {
						    obj.value = day + "-" + month + "-" + year;
						    return true;
						}
				    }
			    }	
    			
    			
			    // If the length of the date is 6, the user may has inputted a date with a year (year with 2 digits)
			    if (x.length == 6)
			    {
				    var regXDate = new RegExp("^(\\d{2})(\\d{2})(\\d{2})$");
				    var matchArray = x.match(regXDate);
				    if (matchArray == null)
				    {
					    return false;
				    }
				    else
				    {
					    day		= matchArray[1];
					    month	= matchArray[2]; 
					    // as we only got the last to digits of the year (abbrevation), apply 2000, in years front end
					    // Use 2000 (and not 20) because of they are ints.
					    year = matchArray[3];
					    // Check if year is bigger than 99. If true, number is not valid
					    if (year > 99)
						    return false;
					    // If year is less than 80, the year will become 20?? (e.g. 2031), else 19?? (e.g. 1996)
					    if (year > 20)
						    year = 19;
					    else
						    year = 20;
					    if (CheckDateFromArrays(day, month, year + matchArray[3]))
					    {
						    obj.value = day + "-" + month + "-" + year + matchArray[3];
						    return true;
						}
				    }
			    }
			    // If the length of the date is 8, the user may has inputted a date with a year (year with 4 digits)
    			
			    if (x.length == 8)
			    {
				    var regXDate = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
				    var matchArray = x.match(regXDate);
				    if (matchArray == null)
				    {
					    return false;
				    }
				    else
				    {
					    day		= matchArray[1];
					    month	= matchArray[2];
					    year	= matchArray[3];
    					
					    if (CheckDateFromArrays(day, month, year))
					    {
						    obj.value = day + "-" + month + "-" + year;
						    return true;
						}
				    }
			    }
			    
			    return false; // None of the lenghts of the string fitted the predefined ones.
		    }
	    }

	    ////////////////////////////////////////////////////////////////////////////////////////////////
	    // Function CheckDateFromArrays()
	    // Purpose	: Call this function to check if the date given from 3 parameters (int's), is a valid date.
	    //			  The function checks February from any leap years, and checks the length of each month (the 31 days issue)
	    //
	    // Returns	: Boolean for Success/Failure
	    // Post-Con.: 3 valid parameters are given
	    //
	    //
	    // History	:
	    ////////////////////////////////////////////////////////////////////////////////////////////////
    		 
	    function CheckDateFromArrays(day, month, year){
		    if (day < 1 || day > 31){
			    return false;
		    }
    		
		    if (month > 12)
			    return false;
    			
		    if ((month == 4 || month == 6 || month == 9 || month==11) && day == 31)
		    {
			    return false;
		    }
    		
		    // Check for leap year in February
		    if (month == 2)
		    { 
			    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			    if (day > 29 || (day==29 && !isleap))
			    {
    				
				    return false;
			    }
		    }
		    // If the upper if's succeeded return true.
		    return true;
    	
	    }

        //Cross-Browser getYear function 
        function takeYear(theDate) {
	        x = theDate.getYear();
	        var y = x % 100;
	        y += (y < 38) ? 2000 : 1900;
	        return y;
        }
        
        function validateDateFormat(sender, args)
        {
			var x = args.Value;
			var newString = "";
            if(x.indexOf("-") == -1) 
            {
				args.IsValid = false;
				return;
			}
			
            var parts = x.split("-");
            if(parts.length < 3) 
            {
				args.IsValid = false;
				return;
			}
            for(var i=0;i<parts.length;i++) 
            {
                if(parts[i].length == 1)
                    parts[i] = "0"+parts[i];
                if(parts[i].length == 2 || (parts[i].length == 4 && i == 2)) 
                {
                    newString += parts[i];    
                }
                else 
                {
					args.IsValid = false;
                    return;
                }
            }
            
            if(newString.length == 0)
			{
				args.IsValid = false;
				return;
			}
                            
			args.IsValid = CheckDateFromArrays(parts[0], parts[1], parts[2]);
        }
        