String.prototype.repeat= function(times){
	var ret='';
	for(var i=0; i<times; i++){
		ret+=this;
	}
	return ret;
}

String.prototype.trim = function(){
  return this.replace(/(^\s*|\s*$)/mg,'');
}

function dump(me,recursive,depth,timestamp){
	if(typeof me == 'false') me=this;
	if(typeof depth != 'number') depth=0;
	if(typeof recursive != 'number') recursive=0;
	var ret='';
	for(var i in me){
		if(typeof me[i]!='function'){ // && this[i].hasBeenDumpedAlready==timestamp){
			ret+= '. '.repeat(depth*3) + i + ' = (' + typeof me[i] +') ';
			if(typeof me[i]=='object' && (recursive<0 || depth<recursive)){
				recuret='';
				try{
					recuret=me[i].dump(me[i],recursive,depth+1)
				}
				catch(e){
				}
				ret+='Array {\n' + recuret + '. '.repeat(depth*3) +'}\n';
			}
			else{
				ret+=String(me[i]) + '\n';
			}
		}
	}
	return ret;		
}
// Object.prototype.dump = dump;


 function getChildsByAttribute(name,wert,recursive,d){
	if(typeof d != 'number'){
		d=0;
	}
	if(typeof recursive == 'undefined') recursive=true;
	
	var me=((this) ? this : document); 
	var ret= new Array();
	var msg='';
	var at,hat,cn,hcn,mci;
	
	for(i in me.childNodes){
//		msg+= 'chiNo ' + i + ': ' + me.childNodes[i].tagName + ' (' + me.childNodes[i].nodeType + ') / attrib: ' + me.childNodes[i].attributes + '\n';
		cn=me.childNodes[i];
		at={name:false, value:false};

		if(cn.tagName != undefined){
			
			hat=false;
			try{
				if(cn.attributes){
					at=cn.attributes[0];
					if(cn.attributes[name] != undefined){
						at=cn.attributes[name];
						if(wert){
							if(cn.attributes[name].value == wert){
								hat= true;
							}    
							else{
							  var vs=cn.attributes[name].value.split(' ');
							  for(var vi in vs){
							    if(vs[vi]==wert){
    								hat=true;
							    }
							  }
							}
						}
						else{
							hat= true;
						}
					}
				}
			}
		  catch(e){
		  }
			if(hat){
//				trace('pushit!');
				ret.push(cn);
//				msg=ret.dump(d);
			}
			if(!at) at={name:false, value:false};
//			trace(at.dump());
//			trace(me.tagName + ' hat ' + cn.tagName + ' mit ' + at.name + '=' + at.value + ((hat) ? " - PASST" : " - zwickt") + ': \n' + msg);
			
			hcn=false;
			try{
				if(cn.hasChildNodes()){
					hcn=true;
				}
			}
			catch(e){
			}
		  if(hcn && recursive){
				ret=ret.concat(cn.getChildsByAttribute(name,wert,(typeof recursive=='number' ? (recursive-1) : true),(d+1)));
			}
		}
	}
//	alert(msg);
	return ret;	
}
Object.prototype.getChildsByAttribute=getChildsByAttribute;



function trace(msg,mode,target){
//	return false;
	if(!target){
		var target=document.getElementById('trace');
	}

  
	if(mode=='overwrite'){
		target.innerHTML = msg;
	}
	else if(mode=='asc'){
		target.innerHTML+= msg + '\n';
	}
	else{
		target.innerHTML= msg + '\n' + target.innerHTML;
	}
}
