function options() {
	this.destName;
	this.selectName;
	this.stack = new Array; //set to json, returned by php
	this._load = function()
	{
		var select = document.getElementById(this.selectName);
		var no = select.options[select.selectedIndex].value; 
		var append = "";
		if(this.stack.length < no) {
			for(var x=this.stack.length; x<no; x++) {
				this._push("", "");
			}
		} else {
			var length = this.stack.length;
			for(var x=no; x<length; x++) {
				this._pop();
			}
		}
		
		var x = 1;
		for(var i in this.stack){
		append += '<br />' +
    '<label for="friends_email" class="label required">Friend ' + x + ' Email</label>' +
    '<input id="friends_email" name="friends_email[]" value="' + this.stack[i]['email'] + '" />' +
	'<br />' +
    '<label for="friends_name" class="label required">Friend ' + x + ' Name</label>' +
    '<input id="friends_name" name="friends_name[]" value="' + this.stack[i]['name'] + '" />';
		x++;
			
		}
		document.getElementById(this.destName).innerHTML = append;
	}
	
	this.load = function() {
		this.stack = new Array;
		friends_email = document.getElementsByName('friends_email[]');
		friends_name = document.getElementsByName('friends_name[]')
		for(var i=0; i < friends_email.length; i++) {
			this._push(friends_email[i].value, friends_name[i].value);
		}
		this._load();
	}
	
	this.preload = function() {
		var select = document.getElementById(this.selectName);
		var index = 0;
		if(this.stack.length > 0) {
			index = this.stack.length-1;
		}
		select.options[index].selected = "selected";
		this._load();
	}
	
	this._push = function(email, name)
	{
		var tmp = new Array;
		tmp['email'] = email;
		tmp['name'] = name;
		this.stack.push(tmp); 
	}
	
	this._pop = function()
	{
		this.stack.pop();
	}
}

