//vfnm prototype extension
//add your custom methods here

if (typeof Prototype == 'undefined')
	alert("Prototype needed!");
if (Prototype.Version < "1.6")
	alert("Minimum Prototype version is 1.6.0 you are using " + Prototype.Version+" please upgrade");
	

	
//this method will return the element as a string with all its atributes
//init as usual $($('objectname')).DomElementToString(); return string
Element.addMethods({  
  DomElementToString: function(element) {
	element = $(element);
	$clone = element.cloneNode(true);

	$container = document.createElement("div");
	$container.insert($clone);	

	$string = $container.innerHTML;		
	return $string;

	}
	
});




/* example  +++++++++++++++++++++++++++++++++++++++++++++
$test = new Array('a1', 'a2','a3','a4','a5','a6', 'a2');

alert($test.ArrayMultieKeySearch('a2'));
alert($test.ArrayKeySearch('a2'));
alert($test);
alert($test.ArrayReverseKeySearch('a2'));
alert($test);
alert($test.ArrayMultieKeySearch('a2'));
alert($test);

*/


Object.extend(Array.prototype, {
	ArrayKeySearch: function($p_needle, $p_strict) {
		
		if(!Object.isArray(this))
			return false;
			
		for($key in this) {
			if(($p_strict && this[$key] === $p_needle) || (!$p_strict && this[$key] == $p_needle)) {
				return $key;
			}		
		}		
		return false;		
	},	
	
	ArrayReverseKeySearch: function($p_needle, $p_strict) {
		
		if(!Object.isArray(this))
			return false;
			
		$ar_reverse = this;
		$ar_reverse.reverse();
			
		for($key in this) {
			if(($p_strict && $ar_reverse[$key] === $p_needle) || (!$p_strict && $ar_reverse[$key] == $p_needle)) {
				$key_pos = -$key-1+$ar_reverse.length;
				$ar_reverse.reverse();
				return $key_pos;
			}		
		}
		$ar_reverse.reverse();
		return false;		
	},
	
	ArrayMultieKeySearch: function($p_needle, $p_strict) {
		
		if(!Object.isArray(this))
			return false;
		
		$ar_temp = new Array();
		for($key in this) {
			if(($p_strict && this[$key] === $p_needle) || (!$p_strict && this[$key] == $p_needle)) {
				$ar_temp.push($key);
			}		
		}

		if($ar_temp.length > 0)
			return $ar_temp;
			
		return false;		
	}

});
Object.extend(String.prototype,{
	strReplace: function(search, replace) {
		return this.split(search).join(replace);
	}
});



