
function selectObj(host, firstId, secondId, thirdId)
{
	this.areasArray = new Array();
	this.areasArray2 = new Array();
	this.brotherArray = new Array();
	this.host = host;
	this.firstId = firstId;
	this.secondId = secondId;
	this.thirdId = thirdId;
	this.initHTML = '<div style="padding-top:5px"><select id="thirdAreaBox" name="thirdAreaBox" class="textbox" style="height:18px; width:145px" onChange="select.postBox = this;"><option class="textbox" value="0">Make selection...</option></select></div>';
		
	this.addFourthBox = function(fourthId, extId)
	{
		this.fourthId = fourthId;
		
		this.initHTML = '<div style="padding-top:5px"><select id="thirdAreaBox" name="thirdAreaBox" class="textbox" style="height:18px; width:145px" onChange="select.execThirdSelect()"><option class="textbox" value="0">Make selection...</option></select></div><div style="padding-top:15px"><select id="fourthAreaBox" name="fourthAreaBox" class="textbox" style="height:18px; width:145px" onChange="select.execFourthSelect()"><option class="textbox" value="0">Make selection...</option></select>';
		if(extId)
		{
			this.extId = extId;
			this.initHTML += '<span style="padding-left:40px" class="darkGreyLarge"><select id="extension" name="extension" class="textbox" style="height:18px; width:55px"><option class="textbox" value="">Ext.</option></select></span>';
		}
		this.initHTML += '</div>';
	}
	
	this.init = function(pane)
	{
		this.pane = pane;
		this.firstBox = document.getElementById(this.firstId);
		this.secondBox = document.getElementById(this.secondId);
		this.ext = document.getElementById(this.extId);
		if(this.secondBox.length > 1)	
			this.secondBox.style.visibility = 'visible';
	}
	
	this.execThirdSelect = function()
	{
		select.populateBox(false)
	}
	
	this.execFourthSelect = function()
	{
		// stub
	}
		
	this.getMoreAreas = function()
	{
		var thirdBox = document.getElementById(this.thirdId);
		var firstBoxSelected = document.getElementById(this.firstId).value;
		var extension = document.getElementById(this.extId);
		if(!(this.fourthId) &&!(firstBoxSelected == 3) && !(firstBoxSelected == 4) && !(firstBoxSelected == 10))
        {
        	this.postBox = this.secondBox;
            return;
		}
		else if(this.secondBox.selectedIndex == 0)
		{
			hideSelectBox(thirdBox);
			hideSelectBox(this.fourthBox);
		}
		else
   		{
   			this.pane.ajax.setVar('parent', this.secondBox.value);
   			if(extension)
   				this.pane.ajax.setVar('ext', '');
        	getAjaxFile(this.pane, "http://"+this.host+"/phpScripts/areaPopulator.php", this.initArrays);
        	this.pane.ajax.removeVar('parent');
        	if(extension)
        		this.pane.ajax.removeVar('ext');
		}
	}
	
	this.populateBox = function(isFirst)
	{
		var srcBox = document.getElementById(this.thirdId);
		var targetBox = document.getElementById(this.fourthId);
		this.ext = document.getElementById(this.extId);
		var array = this.areasArray2;
		if(isFirst)
		{
			this.postBox = null;
			srcBox = this.firstBox;
			targetBox = this.secondBox;	
			array = this.areasArray;			
		}
		fillSelectFromArray(targetBox, ((srcBox.selectedIndex == -1) ? null : array[srcBox.selectedIndex-1]));
		if(targetBox.length > 1)
		{
			targetBox.style.visibility = 'visible';
			if(isFirst)
			{
				hideSelectBox(this.thirdBox);
				hideSelectBox(this.fourthBox);
				if(this.extId)	
				{
					 this.ext.style.visibility = 'hidden';
	                 this.ext.selectedIndex = 0;
				}
			}	
			else
			{ 
				this.postBox = this.fourthBox;
				if(this.extId)	
				{
					 this.ext.style.visibility = 'visible';
	                 this.ext.selectedIndex = 0;
				}
			}
		}
		else
		{
			hideSelectBox(targetBox);
			if(isFirst)
			{
				hideSelectBox(this.thirdBox);
				hideSelectBox(this.fourthBox);
			}
			else
				this.postBox = this.thirdBox;
			if(this.ext)	
			{
				 this.ext.style.visibility = 'hidden';
                 this.ext.selectedIndex = 0;
			}
		}
	}
	
	this.initArrays = function()
	{
		select.pane.screen.innerHTML = select.initHTML;
		select.thirdBox = document.getElementById(select.thirdId);
		
		select.fourthBox = document.getElementById(select.fourthId);
		select.thirdBox.style.visibility = 'visible';
		eval(select.pane.ajax.response);
	}	
}

function hideSelectBox(selectBox)
{
	if(selectBox)
    {
	    for (i = selectBox.options.length; i >= 0; i--) 
	    	selectBox.options[i] = null;
		selectBox.style.visibility = 'hidden';
		selectBox.selectedIndex = 0;
    }
}

