/* String */
String.prototype.getElementType=function() {
	var out=null;
	var element=this.substring(0,1);
	if (element.isCharacter()) {
		element=element.toUpperCase();
		for (var i=0; i<Elements.length; i++) {
			if (Elements[i][0]==element) {
				out=element;
				break;
			}
		}
	}
	return(out);
	
	out=null;
	element=null;
};
String.prototype.isNull=function(alt) {
	return((this==null) ? alt : this);
}
String.prototype.isNumeric=function() {
	return (this.search(/^\d+$/) != -1);
	//return (this.match(/\d/g)!=null);
};
String.prototype.getNumbersOnly=function() {
	var out=this.match(/[\d\.]+/g);
//	alert(this);
//	alert(out.length);
	out=out.join('');
//	alert(out);
	return(out);
	
	out=null;
};
String.prototype.isCharacter=function() {
	return (this.search(/^[a-zA-Z]+$/) != -1);
};
String.prototype.trim = function() {
	return(this.replace(/^\s+|\s+$/g, ''));
};
String.prototype.isDrygood = function() {
	return(this=='3');
};
String.prototype.isFish = function() {
	return(this=='1');
};
String.prototype.isInvert = function() {
	return(this=='2');
};
String.prototype.asMsgLoading=function() {
	return(['<div id="MsgLoading">',this,'<div>'].join(' '));
};
String.prototype.asMsgLoadingAsDiv=function() {
	var div=document.createElement('div');
	div.id='MsgLoading';
	div.innerHTML=this;
	return(div);
	
	div=null;
};
String.prototype.asMsgLoadingAsDocFrag=function() {
	var doc=document.createDocumentFragment();
	doc.appendChild(this.asMsgLoadingAsDiv());
	return(doc);

	doc=null;
};
String.prototype.withFixedDigits=function(digitCount) {
	alert([this,this.length,digitCount,digitCount-this.length].join('\n'))
	var additionalDigits=Math.max(0,digitCount-this.length);
	var out=(additionalDigits>0) ? ['0'.repeat(additionalDigits),this].join('') : this;
	return(out);
	
	additionalDigits=null;
	out=null;
};
String.prototype.repeat=function(count) {
	var array=[];
	for (var i=1; i<=count; i++) {
		array.push(this);
	}
	return(array.join(''));
	
	array=null;
};
String.prototype.isNull=function() {
	return( (this==null) ? '' : this );
};

/* Array */
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(elt /*, from*/) {
		var len = this.length;
		var from = Number(arguments[1]) || 0;

		from = (from < 0) ? Math.ceil(from) : Math.floor(from);
		if (from < 0) from += len;

		for (; from < len; from++) {
			if (from in this && this[from] === elt) return from;
		}
		return -1;
		
		len=null;
		from=null;
	};
}
if (!Array.prototype.size) {
	Array.prototype.size = function () {
		var l=0;
		for (var k in this) { l++; }
		return l;
		
		l=null;
	};
}
if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") throw new TypeError();
		var thisp = arguments[1];
//		for (var i = 0; i < len; i++) {
//			if (i in this) fun.call(thisp, this[i], i, this);
//		}
		for (var i in this) {
			fun.call(thisp, this[i], i, this);
		}
		
		len=null;
		thisp=null;
	};
}
if (!Array.prototype.add) {
	Array.prototype.add = function(obj) {
		this[this.length]=obj;
	};
}

/* Function */
Function.prototype.extendsFrom = function(Super) {
   var Self = this;
   var Func = function() {
      Super.apply(this, arguments);
      Self.apply(this, arguments);
   };
   Func.prototype = new Super();
   return Func;
   
   Self=null;
   Func=null;
};
/*Function.prototype.log = function(details) {
	if (!details) {
		details=[];
		for (var i in arguments) {
			details.push([i,arguments[i]].join('='));
		}
		details=details.join('; ');
	}	
	System.Log.push(new LogEntry(arguments.caller,arguments.callee,details));
};*/
if (!Function.prototype.length) {
	Function.prototype.length = function () {
		var l=0;
		for (var k in this) { l++; }
		return l;
		
		l=null;
	};
}
/*Function.prototype.getChildElementById=function(id) {
	var out=null;
	var nodes=this.childNodes;
	for (var i in nodes) {
		if (nodes[i].id==id) {
			out=nodes[i];
			break;
		}
		if (out==null) {
			out=getChildElementById(nodes[i],id);
		}
	}
	return(out);
}*/
function hasParentWithClassName(obj,className) {
	var out=false;
	try {
		var node=obj.parentNode;
		if (node) {
			if (node.className==className) { out=true; }
			else { out=hasParentWithClassName(node,className); }
		}

		node=null;
	} catch(e) { alert(['hasParentWithClassName',e].join('\n')); }
	return(out);
	
	out=null;
};
function hasParentWithID(obj,id) {
	var out=false;
	try {
		var node=obj.parentNode;
		if (node) {
			if (node.id==id) { out=true; }
			else { out=hasParentWithID(node,className); }
		}

		node=null;
	} catch(e) { alert(['hasParentWithID',e].join('\n')); }
	return(out);
	
	out=null;
}
function getParentWithTagName(obj,tagName) {
	var out=null;
	try {
		var node=obj.parentNode;
//		alert([node.nodeName,node.id,node.innerHTML].join('\n'))
		if (node) {
			if (node.nodeName==tagName) { out=node; }
			else { out=getParentWithTagName(node,tagName); }
		}
	} catch(e) { alert(['getParentWithTagName',e].join('\n')); }
	return(out);
	
	node=null;
	out=null;
}
function getChildElementByClassName(obj,className) {
	var out=null;
	try {
		var nodes=obj.childNodes;
		for (var i in nodes) {
			if (nodes[i].className==className) {
				out=nodes[i];
				break;
			}
			if (out==null) {
				out=getChildElementById(nodes[i],className);
			}
		}
		
		nodes=null;
	} catch(e) { ; }
	return(out);

	out=null;
}
function getChildElementById(obj,id) {
	var out=null;
	try {
		var nodes=obj.childNodes;
		for (var i in nodes) {
			if (nodes[i].id==id) {
				out=nodes[i];
				break;
			}
			if (out==null) {
				out=getChildElementById(nodes[i],id);
			}
		}
		
		nodes=null;
	} catch(e) { ; }
	return(out);

	out=null;
}
function getElementsByClassName(className, startElement, elements) {
	if (!elements) elements=[];
	if (!startElement) startElement=document.body;
	var nodes=startElement.childNodes;
	for (var i in nodes) {
		var node=nodes[i];
		if (node.className) {
			if (node.className==className) {
				elements.push(node);
			}
		}
		if (node.hasChildNodes()) {
			elements=getElementsByClassName(className, node, elements);
		}
	}
	nodes=null;
	return(elements);
}
function $$(id) {
	return(document.getElementById(id));
}
