SSD = function(c){
	return {
	
		//TODO: cache these
		el : function(e){
			if(typeof(e) === 'string'){
			  return document.getElementById(e);
			}else{
			  return e;
			}
		},
	  
		hide : function(){
			for(var i = 0; i < arguments.length; i++){
				SSD.el(arguments[i]).style.display = 'none';
			}
		},

		show : function(){
			for(var i = 0; i < arguments.length; i++){
				SSD.el(arguments[i]).style.display = '';
			}
		},

		//a text input is assumed
		empty : function(){
			for(var i = 0; i < arguments.length; i++){
				SSD.el(arguments[i]).value = '';
			}
		},
	  
		//a radio button is assumbed
		uncheck : function(){
			for(var i = 0; i < arguments.length; i++){
				SSD.el(arguments[i]).checked = false;
			}
		},
	  
		removeChildren : function(e){
			while (e.childNodes[0]){
				e.removeChild(e.childNodes[0]);
			}
		},
		
		
		
		node : function(){
			//encode a string to html encoding
			// we don't want to allow code injection when using the innerHTML property
			var encode = function(s){
				var r = [], i, l = s.length, ch;
				for(i = 0; i < l; i++){
					ch = s.charCodeAt(i);
					if(ch === 32){
						r.push('&nbsp;');
					}else{
						r.push('&#');
						r.push(s.charCodeAt(i));
						r.push(';');
					}
				}
				return r.join('');
			};
			//create a dom element and return it
			// where type is the html dom element type eg input
			//		conf is the configuration of the element
			//EG : create('td', { innerHTML: 'hi world', width:'12px' } )
			return {
				create : function(type, conf){
					var t = document.createElement(type);
					for(prop in conf){
						if(prop === 'innerHTML' || prop === 'innerText' || prop === 'text'){
							//deny code injection
							t['innerHTML'] = encode(conf[prop]);
						}
						if(prop === 'style'){
							var style = conf.style;
							for(s in style){
								t.style[s] = style[s];
							}
						}else{
							t[prop] = conf[prop];
						}
					}
					return t;
				},
				append : function(parent, conf){
					if(typeof(parent) === 'string'){
						parent = SSD.el(parent);
					}
					if(typeof(conf.el) === 'string'){
						var t = SSD.node.create(conf.el, conf);
						parent.appendChild(t);
						if(conf.append){
							if(conf.append.constructor === Array){
								var i, l = conf.append.length;
								for(i = 0; i < l; i++){
									SSD.node.append(t, conf.append[i]);
								}
							}else{
								SSD.node.append(t, conf.append);
							}
						}
					}else{
						//TODO: check that this is a valid html element
						parent.appendChild(conf.el);
					}
				},
				clear : function(){
					for(var i = 0; i < arguments.length; i++){
						var a = arguments[i];
						if(typeof(a) === 'string'){
							a = SSD.el(a);
						}
						while (a.childNodes[0]){
							a.removeChild(a.childNodes[0]);
						}
					}
				}
			}
		}(),
		//end node
	  
	  
		validAddress : function(email) {
			return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email); 
		}
	};
}();

