/*
 This file is part of HiNii.

 Copyright (C) 2008 Carnino Claudio (jollyr0ger) <jollyr0g3r@gmail.com>
 */

/**
 * Collection of Dom Utils
 * @author jollyr0ger
 *
 * Attention need:
 * -Prototype
 */
var DomUtils = Class.create({ });
Object.extend(DomUtils, {	
	
	
	/**
	 * Strip spaces, html tags, all kind of scripts and slashes
	 * @param 	string|DomElement	element		Element where strip
	 */
	stripAll: function(element){
	
		element = $(element);
		
		if(element != null){
			element.value = element.value.strip().stripTags().stripScripts();
			//element.value = element.value.gsub('/', '');
			
			// If there's nothing into the string
			if(element == ''){
				return null;
			}
			
			// Else the value stripped
			return element.value;
		}
		
		// If nothing is done
		return null;
	},
	
	
	
	/**
	 * Remove all, but the digit chars
	 * @param 	string|DomElement	element		Element to filter
	 */
	filterDigits: function(element){
		
		element = $(element);
		
		if(element != null){

			var elementValue = new String(element.value);
			var stringArray = elementValue.toArray();
			var stringClean = "";

			// Check each character
			for(var i = 0; i < stringArray.size(); i++){
				
				if(	stringArray[i] == '0' || 
					stringArray[i] == '1' || 
					stringArray[i] == '2' || 
					stringArray[i] == '3' || 
					stringArray[i] == '4' || 
					stringArray[i] == '5' || 
					stringArray[i] == '6' || 
					stringArray[i] == '7' || 
					stringArray[i] == '8' || 
					stringArray[i] == '9' 		){
					
					// Add character
					stringClean += stringArray[i];
					
				}
				
				if(	stringArray[i] == '+' ){
					
					stringClean += '00';
				}
			}
			
		}
		
		// Set the result
		element.value = stringClean;
	},

	
	
	/**
	 * Create a rollover image
	 * @param	string		elementName		Image element, name
	 * @param	string		imgSource		Image souce path
	 */
	rolloverImage: function(imgElem, imgAlt){
		
		imgElem = $(imgElem);
		imgDef = imgElem.src;
		actionDef = "$('" + imgElem.id + "').src = '" + imgDef + "'";
		actionAlt = "$('" + imgElem.id + "').src = '" + imgAlt + "'";

		imgElem.writeAttribute("onmouseover", actionAlt);
		imgElem.writeAttribute("onmouseout", actionDef);
	}
	

});