
    String.prototype.ltrim = fncLTrim;
    String.prototype.rtrim = fncRTrim;
    String.prototype.trim = fncTrim;
    String.prototype.strip = fncStrip;
    String.prototype.left = fncLeft;
    String.prototype.right = fncRight;
	String.prototype.withIn = fncWithIn;
	Number.prototype.withIn = fncWithIn;
	String.prototype.isNumeric = fncIsNumeric;
	Number.prototype.isNumeric = fncIsNumeric;
	String.prototype.isDateFormat = fncIsDateFormat;
	String.prototype.isDateList = fncIsDateList;
	String.prototype.isDate = fncIsDate;
    String.prototype.isModulus11 = fncIsModulus11;
    String.prototype.formatDigit = fncFormatDigit;
    String.prototype.isValidChar = fncIsValidChar;
    String.prototype.isEmail = fncIsEmail;
    String.prototype.isExpression = fncIsExpression;
    String.prototype.isIn = fncIn;
    String.prototype.isNotIn = fncNotIn;
    String.prototype.parseFloat = fncParseFloat;
    String.prototype.toFixed = fncToFixed;
    String.prototype.endsWith = fncEndsWith;
    String.prototype.beginsWith = fncBeginsWith;
	String.prototype.formatDate = fncFormatDate;
	String.prototype.formatDateTime = fncFormatDateTime;
    Date.prototype.getMillennium = fncGetMillennium;
    Date.prototype.isTodayOrFuture = fncIsTodayOrFuture;
	Number.prototype.toYear = fncToYear;
	String.prototype.toDate = fncToDate;
	String.prototype.formatTime = fncFormatTime;
	String.prototype.isEAN = fncIsEAN;

	
	function fncBeginsWith()
	{
		var l = this.length;
		var snip = "";
		for ( var i=0; i<arguments.length; i++ )
		{
			snip = this.substring( 0, arguments[i].length ).toLowerCase();
			if ( snip == arguments[i].toLowerCase() )
			{
				return true;
			}
		}
		return false;
	}
	
	function fncEndsWith()
	{
		var l = this.length;
		var snip = "";
		for ( var i=0; i<arguments.length; i++ )
		{
			snip = this.substring( l - arguments[i].length, l ).toLowerCase();
			if ( snip == arguments[i].toLowerCase() )
			{
				return true;
			}
		}
		return false;
	}
	
	
	function fncToFixed() 
	{   
		var x = arguments[0];
		return Math.round(this*Math.pow(10,x))/Math.pow(10,x);   
	}

	function fncParseFloat(){
		var f = this.replace(",", ".");
		return parseFloat(f); 
	}

	function fncIn(){
		for(i=0; i<arguments.length; i++){
			if(this.toLowerCase() == arguments[i].toString().toLowerCase()) {
				return true;
			}
		}
		return false;
	}

	function fncNotIn(){
		for(i=0; i<arguments.length; i++){
			if(this.toLowerCase() == arguments[i].toString().toLowerCase()) {
				return false;
			}
		}
		return true;
	}

	function fncIsExpression(){
		var Exprssn;
		if(arguments.length==0){
			Exprssn = "";
		}
		 else {
			Exprssn = arguments[0];
		}
	
		var myRegExp1 = new RegExp(Exprssn); 

		if (!myRegExp1.test(this)){
			return false;
		} else {
			return true;
		}
	}

	function fncIsValidChar() {
		var ValidChars;
		
		if(arguments.length==0){
			ValidChars = "";
		}
		 else {
			ValidChars = arguments[0];
		}
		
		var IsValidChars=true;
		var Char;

	   for (i = 0; i < this.length && IsValidChars == true; i++) 
	      { 
	      Char = this.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsValidChars = false;
	         }
	      }
	   return IsValidChars;
	}

	function fncIsEmail(){
		
		// Modified 16.09.2004 due to Mac IE 5.0 behaviour 
		//var myRegExp1 = new RegExp(/^([a-zA-Z0-9][\w\.-]*)?[a-zA-Z0-9]@[\w-\.]*[a-zA-Z0-9]\.[a-zA-Z]{2,7}$/)
		//var myRegExp1 = /^([a-zA-Z0-9][\w\.-]*)?[a-zA-Z0-9]@[\w-\.]*[a-zA-Z0-9]\.[a-zA-Z]{2,7}$/
	      
	    var myRegExp1 = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
		
		if (myRegExp1.test(this)) {
			return true;
		} else {
			return false;
		}
	}

	function fncLeft(index){
		return this.substr(0, index);
	}

	function fncRight(index){
		return this.substr(index, this.length-index);
	}
	
	function fncFormatDigit(DigitLength){
		
		var tmpVal = "";
		for(i=this.length; i<DigitLength; i++) {
			tmpVal = "0" + tmpVal;
		}
		return tmpVal + this;

	}
    
    function fncLTrim() {
        return this.replace(/^\s+/,'');
    }
    function fncRTrim() {
        return this.replace(/\s+$/,'');
    }
    function fncTrim() {
        return this.replace(/^\s+/,'').replace(/\s+$/,'');
    }
    function fncStrip() {
        return this.replace(/\s+/g,'');
    }

	function fncWithIn(NumStart, NumStop){
		if (this.isNumeric()!=true){
			return false;
		}

		if (this > NumStart && this <= NumStop) {
			return true;
		} else {
			return false;
		}			
	}
	
	
	function fncIsNumeric() {
		
		// Argument 1: Decimal separator streng, default er ".";
		// Argument 2: Unsigned boolean, default er false - tillad ikke negative tal.
		
		var decimalSep;
		if( arguments.length > 0 )
		{ 
			decimalSep = arguments[0];
		}
		 else {
			decimalSep = "\\.";
		}

		var expr = "^\\d*" + decimalSep + "{0,1}\\d+$";

		if( arguments.length > 1 )
		{
			if ( arguments[1] == true )
			{ 
				expr = "^-{0,1}\\d*" + decimalSep + "{0,1}\\d+$";
			}
		}
		
		var myRegExp = new RegExp( expr );
		
		return myRegExp.test(this);

   }



	function fncIsDateFormat(){
		var	strMask = "^\\d\\d-\\d\\d-\\d\\d\\d\\d$;^\\d\\d-\\d\\d-\\d\\d\\d\\d \\d\\d:\\d\\d:\\d\\d$;^\\d\\d\/\\d\\d\/\\d\\d\\d\\d$";
		var arrMask = strMask.split(';')
		var blnMatch = false
		
		for(i=0;i<arrMask.length;i++){
			var myRegExp = new RegExp(arrMask[i])
			if (myRegExp.test(this)){
				blnMatch = true;
				break;
			}
			else{
				blnMatch = false;
			}
		}
		return blnMatch;
	}


	function fncIsDateList(dateSeparator){
		var dates = this.trim().split(dateSeparator)
		var i = 0;
		for (i=0;i<dates.length;i++){
			if(!dates[i].trim().isDateFormat() || !dates[i].trim().isDate() ){
				return false;
			};
		}
		return true;
	}


	function y2k(number){ 
			return (number < 1000) ? number + 1900 : number; 
		 } 
 
	function fncIsDate () { 
		
		if (this.isDateFormat()!=true){
			return false;
		}
			
		var day = this.substring(0,2)
		var month = this.substring(3,5)
		var year = this.substring(6,10)
			
	    var today = new Date(); 
	    year = ((!year) ? y2k(today.getYear()):year); 
	    month = ((!month) ? today.getMonth():month-1); 
		
		if (year < 1900 || year >= 2300){
			return false;
		}
		
    	var test = new Date(year,month,day); 
 
   	 	if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) &&  (day == test.getDate()) ){ 
 	    		return true; 
			}	 
		    else{ 
   		  	   return false; 
			} 
	} 
	
	function fncIsModulus11(){
		var Check = new String("4327654321");
		var lngSum = new Number(0);
		for(i=0;i<this.length;i++){
			lngSum = lngSum + (this.substr(i,1) * Check.substr(i,1))
		}

		if (lngSum%11==0) {
			return true;
		} else {
			return false;
		}		
	}

	function fncIsEAN(){
		var Check = new String("131313131313");
		var lngSum = new Number(0);
		for(i=0;i<this.length;i++){
			lngSum = lngSum + (this.substr(i,1) * Check.substr(i,1))
		}
		return (10-lngSum %10)%10 == this.substr(this.length-1, 1);
	}

	var actObjct;

	function fncVBMakeDate(dateString){
		var _day = dateString.substr(0,2)
		var _month = dateString.substr(3,2)
		var _year = dateString.substr(6,4)
		Date1 = new Date(_year, _month, _day);
		return Date1.toString();
	}

	function VBDateDiff(DateUnit, Date1, Date2){
		Date1 = fncVBMakeDate(Date1)
		Date2 = fncVBMakeDate(Date2)
		switch (DateUnit){ 
			case "year" : 
				var UnitDivide = 1000*60*60*24*365; 
				break; 
			case "day" : 
				var UnitDivide = 1000*60*60*24; 
				break; 
		}
			
		myDate = new Date()
		myDate.setTime(Date.parse(Date1))
		
		return Math.floor ((Date.parse(Date2)-Date.parse(Date1))/(UnitDivide));
		
	}



	function fncGetMillennium()
	{
		return  Math.round( this.getFullYear() / 1000 ) * 1000;
	}

	function fncToDate()
	{
		var day = new Number(this.substring(0,2));
		var month = new Number(this.substring(3,5)) - 1;
		var year = new Number(this.substring(6,this.length)) ;
		return new Date( year, month, day);
	}

	function fncIsTodayOrFuture()
	{
		return this.setDate( this.getDate()+1 ) > new Date(); 
	}

	function fncToYear()
	{
		
		if ( this > -1 && this < 100) 
		{
			var now = new Date();
			var mil = now.getMillennium();
			var tens = now.getFullYear() - mil;
			
			if ( this > (tens + 50) )
				return this + mil - 100;
			else
				return this + mil;

		}
		else
		{
			return this;
		}
			
	}
	
	
	function fncFormatDate()
	{
		if(this.isExpression("^\\d{6}$") || this.isExpression("^\\d{8}$"))
		{
				//"241205" -> "24-12-2005"
				//"24122005" -> "24-12-2005"
				var day = this.substring(0,2);
				var month = this.substring(2,4);
				var year = this.substring(4,this.length);
				year = (parseInt(year)).toYear();
				return (day + "-" + month + "-" + year);
		}
		if(this.isExpression("^\\d{2}-\\d{2}-\\d{2}$")){

			//"24-12-05" -> "24-12-2005"
			var day = this.substring(0,2)
			var month = this.substring(3,5)
			var year = this.substring(6,this.length)
			year = (parseInt(year)).toYear();
			return (day + "-" + month + "-" + year );
		}	
		return this;		
	}

	function fncFormatTime()
	{
		if ( this.isExpression("^\\d{2}$") )
		{
				//"18" -> "18:00"
				var hour = this.substring(0,2);
				return (hour + ":00");
		}
		if ( this.isExpression("^\\d{4}$") )
		{
				//"1800" -> "18:00"
				var hour = this.substring(0,2);
				var minute = this.substring(2,4);
				return (hour + ":" + minute);
		}
		return this;		
	}

	
	function fncFormatDateTime()
	{
		if ( this.isExpression("^\\d{6}$") || this.isExpression("^\\d{8}$") )
		{
			return this.formatDate();
		}
			
		if ( this.isExpression("^\\d{10}$") ) 
		{
			//"2412051200" -> "24-12-2005 12:00"
			var datepart = this.substring(0,6);
			var timepart = this.substring(6,10);
			return datepart.formatDate() + " " + timepart.formatTime();
		}	
							
		if ( this.isExpression("^\\d{12}$") )
		{
			//"241220051800" -> "24-12-2005"
			var datepart = this.substring(0,8);
			var timepart = this.substring(8,12);
			return datepart.formatDate() + " " + timepart.formatTime();
		}	

		if ( this.isExpression("^\\d{6} \\d{4}$") ) 
		{
			//"241205 1800" -> "24-12-2005 18:00"
			var datepart = this.substring(0,6);
			var timepart = this.substring(7,11);
			return datepart.formatDate() + " " + timepart.formatTime();
		}	

		if ( this.isExpression("^\\d{8} \\d{4}$") )
		{
			//"24122005 1800" -> "24-12-2005 18:00"
			var datepart = this.substring(0,8);
			var timepart = this.substring(9,13);
			return datepart.formatDate() + " " + timepart.formatTime();
		}	
		return this;		
	}
