// Copyright 2003 U de Lima. Adolfo Quevedo Toro Lira. All rights reserved.
//------------------------ CLASES COMBO -------------------------

function selectDataObj(valor,nombre){
	this.nombre=nombre;
	this.valor=valor;
}

function selectDataArrayObj(valor,nombre,index,indexRelative,encontrado){ //extends selectDataObj
	this.nombre=nombre;
	this.valor=valor;
	this.index=index;
	this.indexRelative=indexRelative;
	this.encontrado=encontrado;
}

//-------------------------------------------- UTILITARIOS COMBOBOX --------------------------------------------


function impSelect(nombre,funcion,initStr,arreglo,sIndex,eIndex){
	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;
	
	if(funcion==null)
		document.write('<SELECT class=inputs name=' + nombre + '>');	
	else
		document.write('<SELECT class=inputs name=' + nombre+ ' onchange=' + funcion + '>');

	document.write('<OPTION selected value="initStr">' + initStr + '</OPTION>');
	
	for(i=sIndex; i<eIndex; i++){
		document.write('<OPTION value="' + arreglo[i].valor + '">' + arreglo[i].nombre + '</OPTION>');
	}
	
	document.write('</SELECT>');
}
//28/01/2005
function impSelectDis(nombre,funcion,initStr,arreglo,sIndex,eIndex,sDis){
	var aux= sDis;
 if (sDis=='DISABLED') {
	document.write('<input type=hidden name='+nombre+' value='+initStr+'>');	
	
 } else 
{	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;
	
	if(funcion==null)
		document.write('<SELECT ' + aux + ' class=inputs name=',nombre,'>');	
	else
		document.write('<SELECT ' + aux + ' class=inputs name=',nombre,' onchange=',funcion,'>');

	document.write('<OPTION selected value="initStr">',initStr,'</OPTION>');
	
	for(i=sIndex; i<eIndex; i++){
		document.write('<OPTION value="',arreglo[i].valor,'">',arreglo[i].nombre,'</OPTION>');
	}
	
	document.write('</SELECT>');}
 }



// 04-10-2004

function impSelectOption(nombre,funcion,initStr,arreglo,sIndex,eIndex,sValor){
	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;
	
	if(funcion==null)
		document.write('<SELECT class=inputs name=',nombre,'>');	
	else
		document.write('<SELECT class=inputs name=',nombre,' onchange=',funcion,'>');

	if(sValor=='')
		document.write('<OPTION selected value="initStr">',initStr,'</OPTION>');
	else
		document.write('<OPTION value="initStr">',initStr,'</OPTION>');
	
	for(i=sIndex; i<eIndex; i++){
		if(arreglo[i].tipoPostulante==parseInt(sValor))
			document.write('<OPTION value="',arreglo[i].valor,' SELECTED">',arreglo[i].nombre,'</OPTION>');
		else
			document.write('<OPTION value="',arreglo[i].valor,'">',arreglo[i].nombre,'</OPTION>');
	}
	
	document.write('</SELECT>');
	if(arreglo.length<1) {
		alert( 'El servicio de preinscripción en línea elegido aún no está abierto. Disculpe la molestia.' );
		window.close();
	}
}

function impSelectMultiple(nombre,selectSize,funcion,arreglo,sIndex,eIndex){
	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;
	
	if(funcion==null)
		document.write('<SELECT class=inputs name=',nombre,' size=',selectSize,' multiple>');
	else
		document.write('<SELECT class=inputs name=',nombre,' onchange=',funcion,' size=',selectSize,' multiple>');

	for(i=sIndex; i<eIndex; i++){
		document.write('<OPTION value="',arreglo[i].valor,'">',arreglo[i].nombre,'</OPTION>');
	}
	
	document.write('</SELECT>');
}

function actualizarSelect(nombre,initStr,arreglo,sIndex,eIndex){

	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;

	document.formInsL.elements[nombre].options[0].text=initStr;
	document.formInsL.elements[nombre].options[0].value="initStr";

	for(i=sIndex; i<eIndex; i++){
		document.formInsL.elements[nombre].options[i-sIndex+1]=new Option();
		document.formInsL.elements[nombre].options[i-sIndex+1].text=arreglo[i].nombre;
		document.formInsL.elements[nombre].options[i-sIndex+1].value=arreglo[i].valor;
	}
	document.formInsL.elements[nombre].length=eIndex-sIndex+1;
}

function actualizarSelectMultiple(nombre,arreglo,sIndex,eIndex){

	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;

	for(i=sIndex; i<eIndex; i++){
		document.formInsL.elements[nombre].options[i-sIndex]=new Option();
		document.formInsL.elements[nombre].options[i-sIndex].text=arreglo[i].nombre;
		document.formInsL.elements[nombre].options[i-sIndex].value=arreglo[i].valor;
	}
	document.formInsL.elements[nombre].length=eIndex-sIndex;
}

function getItemXvalor(arreglo,valor,sIndex,eIndex){
	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;
	
	if(isNaN(valor))
		valor=valor.replace(/ /g,'');

	for(m=sIndex; m<eIndex; m++){
		if(arreglo[m].valor==valor)
			return new selectDataArrayObj(arreglo[m].valor,arreglo[m].nombre,m,m-sIndex,true);
	}
	return new selectDataArrayObj("","",-1,false);
}

function getItemXnombre(arreglo,nombre,sIndex,eIndex){
	if(sIndex==null)
		sIndex=0;
	if(eIndex==null)
		eIndex=arreglo.length;

	for(m=sIndex; m<eIndex; m++){
		if(arreglo[m].nombre==nombre)
			return new selectDataArrayObj(arreglo[m].valor,arreglo[m].nombre,m,m-sIndex,true);
	}
	return new selectDataArrayObj("","",-1,false);
}

