function borra(selectObj)
{
	var temp = selectObj.options.length;
	for (var x=0;x <= temp ;x++)
	{
		selectObj.options[temp-x]=null;
	};
}

function seleccionaItem(opt,items)
{
       for (var intLoop = 0; intLoop < opt.length; intLoop++)
	    {
               if ((opt[intLoop].value)==items) 
					{
						opt.selectedIndex=intLoop;
						break;
					}
		}
}

function seleccionaItemW(opt,items)
{
       for (var intLoop = 0; intLoop < opt.length; intLoop++)
	    {
               if ((opt[intLoop].value)==items) 
					{
						opt[intLoop].checked=true;
						break;
					}
		}
}

function seleccionaItemCB(opt,items)
{
       for (var intLoop = 0; intLoop < opt.length; intLoop++)
	    {
               if ((opt[intLoop].value)==items) 
					{
						opt[intLoop].checked=true;
						break;
					}
		}
}

function getSelected(opt)
{
	    var selected = new Array();

            for (var intLoop = 0; intLoop < opt.length; intLoop++)
	    {
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked))
		{
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               	}
            }
            return selected;
}

function outputSelected(opt)
{
            var sel = getSelected(opt);
            var strSel = "";
	    for (var item in sel)
		strSel += sel[item].value;
	    return strSel;
 }

function addNew(sthis,text, value,i,j)
{
	var el = new Option(text,value);

	if (j == 1 )
           sthis.options[i] = el;
}

function mensaje(sthis,opt1,opt2)
{
	var Lista_Nombres=new Array();
	var Lista_Codigos=new Array();

	var seleccion = outputSelected(opt1.options);
	//----------------------------------
	borra(opt2);
	//----------------------------------
	Lista_Nombres = eval("Lista_Comuna_Nom_" + seleccion);
	Lista_Codigos = eval("Lista_Comuna_Cod_" + seleccion);

	for (var x=0 ; x< Lista_Nombres.length ; x++)
			addNew(opt2,Lista_Nombres[x],Lista_Codigos[x],x,1);


}