// JavaScript Document
function SelectBox(selectIdIn,optionsHTMLIn){
	this.id=selectIdIn;					//the id of the select box
	this.optionsHTML=optionsHTMLIn;		//all the options in String format
	this.optionElements;				
	
	this.myElementHTML;					//every option in its own array section(<option></option>
	
	
	/*--Object methods--*/
	//inserts a single option
	this.insertNewOption=function(){
		//still empty but can be filled if pleased
	};
	//insert multiple options
	this.insertNewOptions=function(){
		//first split the html string
		this.splitSingleElements();
		
		//temporarily stored option element
		var tempOption;

		//store the elements in a aray
		this.optionElements=new Array();
		//delete the select box childeren
		$(this.id).empty();
		for(var i=0;i<this.myElementHTML.length-1;i++){
			this.optionElements[i]= new Element( 'option', {
			'value': this.getValue(i)
			});
			//set the text for the new option
			this.optionElements[i].setText(this.getText(i));
			//insert the new option into the selectbox
			this.optionElements[i].injectInside(this.id);	
		}
		
	};
	
	//show if the the string with options is passed for testing purposes
	this.getOptionsHTML=function(){
		alert(this.optionsHTML);
	};
	
	//splits every option and places it in its own array adress still a string though
	this.splitSingleElements=function(){

		//splits into array with the following accurance
		var seperator="<option";
		this.myElementHTML = this.optionsHTML.split(seperator);
		//needs to start with one because the first array value sucks ass
		for (var i = 1; i < this.myElementHTML.length; i++) 
		{
			this.myElementHTML[i-1]="<option"+this.myElementHTML[i];
			//alert(this.myElementHTML[i-1]);
		}
	};
	
	/*gets all the values from the options stored in a string more as a private function
	this is used in a loop so the arrayId will equal i*/
	this.getValue=function(arrayId){
		/*seperates where the double quotes are this means 
		*Note the values can not be pass with single quotes so value='1' will not work*/
		var seperator='"';
		//split the option html string into piecies in a temp var
		var tempString=this.myElementHTML[arrayId].split(seperator);
		
		//extract the value in the option tag which is the middle array value 1
		var elementValue=tempString[1];
	
		//alert(elementValue);
		return elementValue;
	};
	
	//gets the text for the option tag this is used in a loop so the arrayId will equal i
	this.getText=function(arrayId){
		//seperates the single option string into pieces... yeah i know again
		var seperator='>';
		var seperator2='<';
		//split the option html string into piecies in a temp var
		var tempString=this.myElementHTML[arrayId].split(seperator);
		//finally filter out the text whats in the option
		tempString=tempString[1].split(seperator2);
		
		//the element text
		var elementText=tempString[0];
		
		//alert(elementText);
		return elementText;
	}
	
}