/**
 * Bumworld JavaScript Ext
 */

var MyProtoExt = {
	Version: '0.01'
};

/**
 * Trim 함수 구현
 * use
 * trim	: '   s      s e tststset       '.trim()
 * ltrim	: '   s      s e tststset       '.ltrim()
 * rtrim	: '   s      s e tststset       '.rtrim()
 */
String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, '$1');
};
String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, '$1');
};
String.prototype.trim = function() {
	return this.ltrim().rtrim();
};

/**
 * 알파벳과 숫자만 포함인지 체크
 * 주로 아이디 검사시 사용
 */
String.prototype.isAlphaNumeric = function() {
	var sAlphabet	= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

	for ( i=0; i<this.length; i++ ) {
		if ( sAlphabet.indexOf(this.substring(i, i+1)) < 0 ) {
			return false;
		}
	}
	return true;
};

/**********************************
 * 숫자인지 체크
 * 주로 아이디 검사시 사용
 **********************************/
String.prototype.isNumber = function() {
	var numberChar	= '0123456789';

	for ( i=0; i<this.length; i++ ) {
		if ( numberChar.indexOf(this.substring(i, i+1)) < 0 ) {
			return false;
		}
	}
	return true;
};

/**
 * URL이 맞는지 확인
 */
String.prototype.isValidURL = function() {

	var returnValue = true;

	var chkExp = /http:\/\/([\w\-]+\.)+/g;

	if( chkExp.test(this) == false) {
		returnValue = false;
	}

	return returnValue;
};

/**********************************
 * 배열 remove 함수 구현
 * index 값으로 제거
 **********************************/
Array.prototype.remove = function(idx) {
	var temp = new Array();
	var i = this.length;

	while( i > idx ) {
		var kk = this.pop();
		temp.push(kk);

		i--;
	}

	for(var i=temp.length - 2; i>=0; i--) {
		this.push(temp[i]);
	}
};

/**********************************
 * 배열 remove 함수 구현
 * Value 값으로 제거
 **********************************/
Array.prototype.removeValue = function(val) {

	var chkIdx = -1;
	for(var i=0; i<this.length; i++) {
		var tempVal = this[i];
		if( tempVal == val ) {
			chkIdx = i;
			break;
		}
	}
	if( chkIdx != -1 ) {
		this.remove(chkIdx);
	}
};


/**********************************
 * HashMap 함수 구현
 **********************************/
function HashMap() {
	HashMap.prototype.keys = new Array();
	HashMap.prototype.values = new Array();
};
/* HashMap get function */
HashMap.prototype.get = function(key) {
	for (var index=0; index < this.keys.length; index++) {
		if (key==this.keys[index]) {
			return(this.values[index]);
		}
	}
	return(null);
};

/* HashMap put function */
HashMap.prototype.put = function(key, value) {
	this.keys[this.keys.length] = key;
	this.values[this.values.length] = value;
};
/* HashMap containsKey function */
HashMap.prototype.containsKey= function(key) {
	for (var index=0; index < this.keys.length; index++){
		if (key==this.keys[index]){
			return(true);
		}
	}
	return(false);
};
/* HashMap debug function */
HashMap.prototype.debug = function() {
	var debug = "";
	for (var index=0; index < this.keys.length; index++) {
		var key = this.keys[index];
		var value = this.values[index];
		debug += key + "->" + value + "\n";
	}
	return(debug);
};
/* HashMap size function */
HashMap.prototype.size = function() {
	return(this.keys.length);
};
/* HashMap containsKey function */
HashMap.prototype.containsValue= function(values) {
	for (var index=0; index < this.values.length; index++) {
		if ( values == this.values[index] ) {
			return (true);
		}
	}
	return (false);
};
