/*
Variables globales:
createselect: para crear el tag "select".
createlink: para crear el tag "a".
*/	
var createselect = document.createElement('select'); //select
var createlink = document.createElement('a'); //a

 /**
 * CambiarURL: Cambia los valores de botón asociado al "select" según los valores de este.
 * @param 
 * @see
 * @return 
 */
 function cambiarURL(){
 	createlink.setAttribute('href',aURL[document.getElementById('cbo').selectedIndex]);
  createlink.setAttribute('target',aTARGET[document.getElementById('cbo').selectedIndex]);
 	}

/**
 * CrearCBO: Inserta un select en un div con id="selector" y borra un elemento de lista con id="linkgral"
 * @param tituloCBO: titulo del CBO
 * @param tituloBOTON: texto del botón
 * @param aTITULO: array con los titulos de las opciones del select.
 * @param aURL: array con las url de las opciones del select.
 * @param aTARGET: array con los target de las urls de las opciones del select.
 * @see
 * @return 
 */
function crearCBO(tituloCBO,tituloBOTON,aTITULO,aURL,aTARGET){
	
  if (!document.getElementById('selector') || !document.getElementById('linkgral')){return false;}

	var formplace = document.getElementById('selector'); //formplace: id del contenedor
	var subtitulo = document.createElement('h2'); //encabezado
			formplace.appendChild(subtitulo); //encabezado
			subtitulo.appendChild(document.createTextNode(tituloCBO)); //texto del encabezado

      formplace.appendChild(createselect);
			createselect.setAttribute('class','select1'); //CLASS del select
			createselect.setAttribute('id','cbo'); //ID del select
			document.getElementById('cbo').onchange=cambiarURL;	//Funcion para cambiar los valores.
			
  var aTITULOlength = aTITULO.length;
	for (var s=0;s<aTITULOlength;s++){
			var createopc=document.createElement('option');
   	 	createselect.appendChild(createopc);
    	createopc.appendChild(document.createTextNode(aTITULO[s]));
    	createopc.setAttribute('value',aURL[s]);
  }
	//Link (botón)
	var creaspan = document.createElement('span');
    	formplace.appendChild(createlink); //link (botón)
    	creaspan.appendChild(document.createTextNode(tituloBOTON)); //span dentro del link (botón)
			//Atributos del link (botón)
			createlink.setAttribute('href',aURL[0]);
			createlink.setAttribute('target',aTARGET[0]);
    	createlink.setAttribute("title",'');
    	createlink.setAttribute("onclick",'');
			createlink.appendChild(creaspan);
			//Atributos del span (botón)
			createlink.setAttribute('class','button1');
	
		
	  //Elimina el primer elemento (<li id="linkgral">) de la lista (<ul id="ul_1">)
    if (document.getElementById('ul_1') && document.getElementById('linkgral'))
    {
        var contentul = document.getElementById('ul_1');
        var li_noscript = document.getElementById('linkgral');
        var lideleted = contentul.removeChild(li_noscript);
    }
    return false;
 }

