String.prototype.checkFor = function(ctr){
	var pattern;
	switch(ctr){
		case 'email':
			pattern = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			return pattern.test(this);

		case 'time':
			pattern = /^[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/;
			return pattern.test(this);

		case 'num':
			pattern = /^[0-9]+$/;
			return pattern.test(this);

		case 'float':
			pattern = /^\d+((\.\d+)|(\d*))$/;		
			return pattern.test(this);

		case 'ip':
			pattern = /^((([0-1]?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))\.(([0-1]?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))\.(([0-1]?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))\.(([0-1]?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))|([0-9]{1,10}))$/;
			return pattern.test(this);

		case 'date':
			pattern = /^((([0-9]{0,3}[1-9]|[0-9]{0,2}[1-9][0-9]|[0-9]?[1-9][0-9]{2}|[1-9][0-9]{3})[-\/](((0?[13578]|1[02]))[-\/](0?[1-9]|[12][0-9]|3[01])|((0?[469]|11)[-\/](0?[1-9]|[12][0-9]|30))|(0?2)[-\/](0?[1-9]|[1][0-9]|2[0-8])))|((([0-9]{0,2})(0[48]|[2468][048]|[13579][26])|((0?[48]|[2468][048]|[3579][26])00))[-\/]0?2[-\/]29))$/;
			return pattern.test(this);

		case 'postcode':
			pattern = /^[0-9]{3}\-[0-9]{4}/;
			return pattern.test(this);

		default: 
			return false;
	}
};

String.prototype.ltrim = function(_stripchars){
	var stripchars = " \t\n\r\0\x0B";
	if(_stripchars != undefined)
		stripchars = _stripchars;
	if(stripchars == '') return this;
	for(var i=0;i<this.length&&stripchars.indexOf(this.charAt(i))>=0;++i){}
	return this.substring(i, this.length);
};

String.prototype.rtrim = function(_stripchars){
	var stripchars = " \t\n\r\0\x0B";
	if(_stripchars != undefined)
		stripchars = _stripchars;
	if(stripchars == '') return this;
	for(var i=this.length-1;i>=0&&stripchars.indexOf(this.charAt(i))>=0;--i){}
	return this.substring(0, i+1);
};

String.prototype.trim = function(_stripchars){
	return this.ltrim(_stripchars).rtrim(_stripchars);
};

String.prototype.empty = function(){
	if(this.trim() == '') return true; else return false;
};

String.prototype.format = function(){
	var argSize = arguments.length;
	var str = this;
	var result = "";
	var pos = 0;
	for (var i=0; ; ++i){
		var reg = /%[ds]/i;
		var match = reg.exec(str)
		if(match == null) break;
		result += str.substring(pos,match.index);
		pos = match.index+2;
		str = str.replace(/%/, "#");
		if(i < argSize){
			var para = arguments[i];
			switch("" + match){
			case "%d":
				para = "" + parseInt(para);
			case "%f":
			case "%s":
			
			};
			result += para;
		}else
			break;
	}
	result+=str.substr(pos);
	return result;
};

String.prototype.strlen = function(){
	var len = 0;
	for (var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 255) len += 2; else len ++;
	}
	return len;
};

String.prototype.padLeft = function(totalWidth, paddingChar){
	if(!paddingChar)
		paddingChar = " ";
	else
		paddingChar = paddingChar.substr(0,1);
	var str = this;
	while (str.length < totalWidth)
		str = paddingChar + str;
	return str;
};


String.prototype.nl2br = function (){
	return this.replace(/\n/g,'<br />');
};

String.prototype.htmlConvert = function (){
	return this.replace(/>/g,'&gt;').replace(/</g,'&lt;');
};

String.prototype.toSBC = function (){
	var str = this;
	var result = ''; 
	if (str.length <= 0) 
	{
		return false;
	} 
	for(var i=0; i<str.length; ++i) 
	{
		var charCode = str.charCodeAt(i);
		if(charCode < 256)
			result += String.fromCharCode(charCode)
		else if(charCode > 65248)
			result += String.fromCharCode(charCode-65248); 
	} 
	return result; 
};


Number.prototype.padLeft = function(totalWidth, paddingChar){
	return ("" + this).padLeft(totalWidth, paddingChar);
};


Array.prototype.unique = function(){
	var result = new Array();
	for(var elem in this){
 		if(result[this[elem]] == undefined){
			result[this[elem]] = elem;
		}
	}
	result = result.flip();
	return result;
};

Array.prototype.flip = function(){
	var result = new Array();
	for(var elem in this){
		result[this[elem]] = elem;
	}
	return result;
};

Array.prototype.indexOf = function(element, startIndex, bStrict){
	if(element == undefined) return -1;
	var iterStart = startIndex;
	if(iterStart == undefined) iterStart = 0;
	if(iterStart < 0) iterStart = 0;
	if(iterStart >= this.length) iterStart = this.length - 1;
	for(; iterStart<this.length; ++iterStart){
		if(bStrict){
			if(this[iterStart] === element) return iterStart;
		}else{
			if(this[iterStart] == element) return iterStart;
		}
	}
	return -1;
};

Array.prototype.findByElemProp = function(arrProp, arrValue, startIndex){
	if(arrProp == undefined || !arrProp.length || arrValue == undefined || !arrValue.length || arrProp.length != arrValue.length) return -1;
	var iterStart = startIndex;
	if(iterStart == undefined) iterStart = 0;
	if(iterStart < 0) iterStart = 0;
	if(iterStart >= this.length) iterStart = this.length - 1;
	for(; iterStart<this.length; ++iterStart){
		var j = 0;
		for(; j<arrProp.length; ++ j){
			if(!(this[iterStart][arrProp[j]] === arrValue[j])) break;
		}
		if(j == arrProp.length) return iterStart;
	}
	return -1;
};

Array.prototype.remove = function(){
	var nArg = arguments.length;
	for(var i=0; i<nArg; ++i){
		var element = arguments[i];
		var pos;
		while((pos = this.indexOf(element)) >= 0){
			if(pos < this.length)
				this.splice(pos,1);
		}
	}
	return this;
};

Array.prototype.merge = function(){
	var nArg = arguments.length;
	for(var i=0; i<nArg; ++i){
		var element = arguments[i];
		if(element.length){
			for(var j=0; j<element.length; ++j){
				this.push(element[j]);
			}
		}
	}
	return this;
};

if(Date.prototype.__getYear == undefined){
	Date.prototype.__getYear = Date.prototype.getYear;
}
Date.prototype.getYear = function(year){
	var getOs = function(){
	   if(navigator.userAgent.indexOf("MSIE") > 0) return 1;
	   if(isFirefox = navigator.userAgent.indexOf("Firefox") > 0) return 2;
	};
	switch(getOs()){
		case 1:
			return this.__getYear();
		case 2:
			return this.__getYear()+1900;
	}
};