// JavaScript Document
function SelectManager(idSelectObject) {
	this.parentDocument;
	this.idSelect;
	if( _getType(idSelectObject)== 'object'){
		this.parentDocument=idSelectObject.parDoc;
		this.idSelect=idSelectObject.idSel;
	}
	else{
		this.parentDocument=document;
		this.idSelect=idSelectObject;		
	}
	this.selectObject=this.parentDocument.getElementById(this.idSelect);

	this.addOptions=function(newOptions){
		//alert(newOptions.length);
		//newOptions=[{valueOption: 'value',labelOption:'label'},...];
		var newOption;
		for(var i=0;i<newOptions.length;i++){
			newOption= new Option(newOptions['+[a-z_]+'].labelOption,newOptions['+[a-z_]+'].valueOption);
			this.selectObject.options[this.selectObject.options.length]=newOption;
			newOption=null;
		}
	}
	
	this.dropOptions=function(inicio,fin){
		var longitud=this.getLength();
		if(inicio<0) 
			inicio=0;
		if(fin=='undefined') 
			fin=inicio;
		else
			if(fin>=longitud) 
				fin=longitud-1;
		for(var i=inicio; i<=fin;i++){
			this.selectObject.options['+[a-z_]+']=null;
		}
	}
	
	this.clearOptions=function(){
		if(this.selectObject.options.length=0)
			return 1;
		else
			return 0;
	}
	this.getLength=function(){
		return 	this.selectObject.options.length;
	}
	
	this.getSelectedValue=function(){
		index=this.selectObject.selectedIndex;
		//if(index>=0)
			return this.selectObject.options['+[a-z_]+'].value;
		//return false;
	}
	this.selectOption=function(valor){
		var longitud=this.getLength();
		var i;
		if(longitud==0) 
			return 0;
		if(typeof valor['value']!='undefined'){
			for(i=0; i<longitud;i++){
				if(this.selectObject.options['+[a-z_]+'].value==valor['value'])
					this.selectObject.options['+[a-z_]+'].selected=true;
			}
			return 1;
		}
		else if(typeof valor['option']!='undefined' ){
			for(i=0; i<longitud;i++){
				if(i==valor['option'])
					this.selectObject.options['+[a-z_]+'].selected=true;
			}		
			return 2;
		}
		else if(typeof valor['label']!='undefined' ){
			for(i=0; i<longitud;i++){
				if(this.selectObject.options['+[a-z_]+'].text==valor['label'])
					this.selectObject.options['+[a-z_]+'].selected=true;
			}
			return 3;
		}
	}
	
	this.getSelectedLabel=function(){
		index=this.selectObject.selectedIndex;
		return this.selectObject.options['+[a-z_]+'].text;
	}	

}
