// -- Infogate AB's standardfunktioner
// -- av Mattias Rundqvist
// --
// -- CVS version: $Revision: 4995 $

var IG_prototypes = true;

Array.prototype.exists = function( value ) {
    for(count = 0; count<this.length; count++) {
        if( this[count] == value ) return true;
    }
    return false;
}

Array.prototype.append = function( ar ) {
	if( typeof ar == "object" && ar.length ) {
		for( count = 0; count < ar.length; count++ ) {
			this[this.length] = ar[count];
		}
	}
}

String.prototype.isMatch = function( valid ) {
	for( count = 0; count < this.length; count++ ) {
		if( valid.indexOf(this.substring(count,count+1)) == -1 )
			return false;
	}
	return true;			
};

String.prototype.isPattern = function( pattern ) {
	
	if( typeof pattern == "string" ) {
		var expression = "/^";
		var sign = "";
		for( count = 0; count<pattern.length; count++ ) {
			sign=pattern.substring(count,count+1);
			if( sign == "?" ) {
				expression+=".{1}";
			} else if( sign=="." ) {
				expression+="\\.{1}";
			} else if( sign=="*" ) {
				expression+=".{0,}";
			} else {
				expression+=(sign+"{1}");
			}
		}
		expression += "$/";
		pattern=eval(expression);
	}
	if(this.search(pattern)==0)
		return true;
	return false;
};

String.prototype.isNum = function() {
	return this.isMatch("1234567890");
};

String.prototype.isDec = function() {
	return this.isMatch("1234567890,.");			
};

String.prototype.isAlpha = function() {
	return this.isMatch("abcdefghijklmnopqrstuvwxyzåäöæøüABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÆØÜ ");			
};

String.prototype.trim = function() {
	return this.replace(/^\s*/,'').replace(/\s*$/,'');
};
