/*
	This note must stay intact.
	
	Author:
		Mattias Rundqvist, Webparts (www.webparts.se)
	License:
		Creative Commons Attribution-Share Alike 3.0 License
		http://creativecommons.org/licenses/by-sa/3.0/
*/

var wp_Prototypes = true;

Array.prototype.find = function( value ) {
    for(count = 0; count<this.length; count++) {
        if( this[count] == value ) return count;
    }
    return -1;
}

Array.prototype.intersection = function( value ) {

	var result = new Array();
	
	if( typeof value != "object" ) {
		value = new Array(value);
	}
	
    for( var tc = 0; tc<this.length; tc++) {
		for( var vc = 0; vc < value.length; vc++ ) {
	        if( this[tc] == value[vc] ) {
				result.push_back(value[vc]);
			}
		}
    }
    return result;
}

Array.prototype.push_back = function( value ) {
	if( typeof value == "object" && value.length ) {
		for( var count = 0; count < value.length; count++ ) {
			this[this.length] = value[count];
		}
	} else {
		this[this.length] = value;
	}
}

Array.prototype.remove = function( index ) {
	var tmp = new Array();
	for( count = 0; count < this.length; count++ ) {
		if( index != count ) {
			tmp[tmp.length]=this[count];
		}
	}
	return tmp;
}

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 if( sign=="(" || sign==")" || sign=="+") {
				expression+=("\\"+sign+"{1}");
			} 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.isEmail = function() {
	return this.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i) ? true : false;
}

String.prototype.trim = function() {
	return this.replace(/^\s*/,'').replace(/\s*$/,'');
};

String.prototype.right = function( length ) {
	return this.substring(this.length-length,this.length);
}

Date.prototype.getWeek = function() {
    var determinedate = new Date();
    determinedate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate());
    var D = determinedate.getDay();
    if(D == 0) D = 7;
    determinedate.setDate(determinedate.getDate() + (4 - D));
    var YN = determinedate.getFullYear();
    var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
    var WN = 1 + Math.floor(ZBDoCY / 7);
    return WN;
}