/*
http://www.w3schools.com/tags/att_input_type.asp
Attribute Values
Value 		Description
-----------------------------------
button 		Defines a clickable button (mostly used with a JavaScript to activate a script)
checkbox 	Defines a checkbox
file 		Defines an input field and a "Browse..." button, for file uploads
hidden 		Defines a hidden input field
image 		Defines an image as a submit button
password 	Defines a password field. The characters in this field are masked
radio 		Defines a radio button
reset 		Defines a reset button. A reset button resets all form fields to their initial values
submit 		Defines a submit button. A submit button sends form data to a server
text 		Defines a one-line input field that a user can enter text into. Default width is 20 characters

http://www.w3schools.com/tags/tag_input.asp
Attribute 	Value 	Description 	DTD
----------------------------------------------
accept 		MIME_type 	Specifies the types of files that can be submitted through a file upload (only for type="file") 	STF
align 	left
		right
		top
		middle
		bottom 		Deprecated. Use styles instead.
					Specifies the alignment of an image input (only for type="image") 	TF
alt 		text 		Specifies an alternate text for an image input (only for type="image") 	STF
checked 	checked  	Specifies that an input element should be preselected when the page loads (for type="checkbox" or type="radio") 	STF
disabled 	disabled 	Specifies that an input element should be disabled when the page loads 	STF
maxlength 	number 		Specifies the maximum length (in characters) of an input field (for type="text" or type="password") 	STF
name 		name 		Specifies a name for an input element 	STF
readonly 	readonly 	Specifies that an input field should be read-only (for type="text" or type="password") 	STF
size 		number 		Specifies the width of an input field 	STF
src 		URL 		Specifies the URL to an image to display as a submit button (only for type="image") 	STF
type 	button
		checkbox
		file
		hidden
		image
		password
		radio
		reset
		submit
		text 		Specifies the type of an input element 	STF
value 	value 		Specifies the value of an input element 	STF

typical application :

	var inputPreselectSlowTraffic = new spcInput('radioButtonSlowTraffic',
												  { type: 		'radio'
												  , name:		'Name of group radio buttons'
												  , onClick:	self.onRadioSlowTrafficSelect 
												  , name:		'Text next to radio button'
												  , value:		true
												  }
												 );

*/


function spcInput(id,attributes)
{
	var self = this;
	this.id = id;
	
	this.attributes = attributes;
	this.html = '';
	this.verification = 'propperClass';
	
	//console.log("Called spcInput(): ");
	
} 

spcInput.prototype.onClick = function(object,event)
{
	
	var self = this;
	var X = 0;
	var Y = 0;
	
	object = document.getElementById(self.id);
	
	if (object) {
		if (object.type) {
			object.checked = (object.type == 'radio');
		}
	}
	
	if (!object) object = self;

	//console.log("Called spcInput.prototype.onClick("+object+", X:"+X+", Y:"+Y+") and I am: " + self.verification );
	
	if (self.attributes.onClick) {
		self.attributes.onClick(event);
	}

}

spcInput.prototype.htmlContent = function()
{
	var self = this;
	
	this.html = '';
	sName = '';
	if (this.attributes.name) {
		sName = ' name="' + this.attributes.name + '"';
	}
	
	sChecked = '';
	if (this.attributes.checked) {
		 sChecked = ' checked="checked"';
	}
	
	sLabel = '';
	if ((this.attributes.type=='radio') || (this.attributes.type=='checkbox')) {
		sLabel = this.attributes.value ;
	}
	
	console.log('spcInput.prototype.htmlContent onClick() '+this.attributes.onClick);
	// 
	 
	this.html += '<input '
				+' id="'+this.id + '"'
				+' type="'+this.attributes.type + '"'
				+' onclick="eventDispatch(this,event,\'onClick\')"' 
				+' value="'+ this.attributes.value + '"' 
				+' name="' + this.attributes.name + '"'
				+ sChecked
				+' />'
				+ sLabel
				+ '<br />';
	
	
	if (this.attributes.type) {
		if (this.attributes.type=='radio') {
			//this.html += '<caption>'+this.attributes.name+'</caption>';
			
		}
	}
	
	
	
	return this.html;
}

