/*
 *
 * GoldenSelect - Pais / Estado / Município
 * Desenvolvedor: Fernando Arroyo
 * GoldenLight [ fernando.arroyo@goldenlight.biz ]
 * 21.09.2009
 *
 */

 var GoldenSelect = function(GSParametros){
 	
	/*
	 * Alvo: Objeto Input
	 * Itens: Valores
	 * 
	 */
	
	if(!GSParametros.Modelo){
		GSParametros.Modelo = 1;
	}
	
	this.NovoSelect=function(){
		document.onmouseup=function(){
			AcaoElemento("#GoldenSelect_"+GSParametros.Alvo.id,"Sumir");
		}
		
		/*_-_-_- + Elemento Texto - Filho Select + -_-_-_*/
			GSElementoTextoFS=document.createElement("span");
			GSElementoTextoFS.innerHTML="Selecione o Formato... &nbsp;";
			GSElementoTextoFS.style.display="inline-block";
			GSElementoTextoFS.style.cssFloat="left";
			GSElementoTextoFS.style.width=(GSParametros.Alvo.parentNode.offsetWidth-43)+"px";
			GSElementoTextoFS.style.paddingLeft="10px";
			if (GSParametros.Modelo == 2) {
				GSElementoTextoFS.style.paddingTop="2px";
				GSElementoTextoFS.style.paddingBottom = "7px";
				GSElementoTextoFS.style.backgroundColor = "#c7c7c7";
				GSElementoTextoFS.style.color = "#9200d8";
				GSElementoTextoFS.style.border = "1px solid #008db8";
			}
			GSElementoTextoFS.style.fontWeight="bolder";
			GSElementoTextoFS.style.zIndex="999999999";
		/*_-_-_- - Elemento Texto - Filho Select - -_-_-_*/
		
		/*_-_-_- + Elemento Imagem - Filho Select + -_-_-_*/
			GSElementoImagemFS=document.createElement("img");
			GSElementoImagemFS.setAttribute("alt","");
			if (GSParametros.Modelo == 1) {
				GSElementoImagemFS.setAttribute("src", window["CaminhoRaiz"] + "/images/GoldenSelect_baixo.jpg");
			}else if (GSParametros.Modelo == 2){
				GSElementoImagemFS.setAttribute("src", window["CaminhoRaiz"] + "/images/GoldenSelect_baixo2.jpg");
				GSElementoImagemFS.style.height="22px";
				GSElementoImagemFS.style.width="20px";
			}
			GSElementoImagemFS.style.border="none";
		/*_-_-_- - Elemento Imagem - Filho Select - -_-_-_*/
		
		/*_-_-_- + Elemento Link - Filho Select + -_-_-_*/
			GSElementoLinkFS=document.createElement("a");
			GSElementoLinkFS.setAttribute("href","javascript:void(0);");
			
			if (GSParametros.Modelo == 1) {
				GSElementoLinkFS.style.color = "#000000";
			}
			else if (GSParametros.Modelo == 2) {
				GSElementoLinkFS.style.color="#ffffff";
			}
			GSElementoLinkFS.style.display="block";
			GSElementoLinkFS.onclick=function(){
				AcaoElemento("#GoldenSelect_"+GSParametros.Alvo.id,"SurgirSumir");
			}
		/*_-_-_- - Elemento Link - Filho Select - -_-_-_*/
		
		/*_-_-_- + Elemento Pai Select + -_-_-_*/
			GSElementoSelect=document.createElement("div");
			GSElementoSelect.style.fontFamily="Verdana";
			GSElementoSelect.style.fontSize="11px";
			GSElementoSelect.style.display="block";
			GSElementoSelect.style.cssFloat="left";
			GSElementoSelect.style.width=(GSParametros.Alvo.parentNode.offsetWidth-10)+"px";
			GSElementoSelect.style.height="20px";
			GSElementoSelect.style.paddingTop="2.5px";
			GSElementoSelect.style.paddingBottom="0px";
			if (GSParametros.Modelo == 1) {
				GSElementoSelect.style.border="solid 1px #c5c5c5";
			}
			else if (GSParametros.Modelo == 2) {
				//GSElementoSelect.style.border="solid 1px #727272";
				//GSElementoSelect.style.backgroundColor="#c7c7c7";
			}
			
			GSElementoSelect.style.zIndex="999999999";
		/*_-_-_- - Elemento Pai Select - -_-_-_*/
	
		/*_-_-_- + Elemento Pai Options + -_-_-_*/
			GSElementoOptions=document.createElement("span");
			GSElementoOptions.style.display="none";
			GSElementoOptions.style.cssFloat="left";
			GSElementoOptions.style.width="100%";
			GSElementoOptions.style.fontFamily="Verdana";
			GSElementoOptions.style.fontSize="11px";
			GSElementoOptions.style.border="solid 1px #c5c5c5";
			if (GSParametros.Modelo == 1) {
				GSElementoOptions.style.height="150px";
				GSElementoOptions.style.overflow="auto";
			}
			else if (GSParametros.Modelo == 2) {
				
			}
			
			GSElementoOptions.style.zIndex="999999999";
			GSElementoOptions.setAttribute("id","GoldenSelect_"+GSParametros.Alvo.id);
		/*_-_-_- - Elemento Pai Options - -_-_-_*/
		
		iChecked=0;
		
		for (iOptions = 0; iOptions < GSParametros.Itens.length; iOptions++) {
			/*_-_-_- + Elemento Texto - Filho Options + -_-_-_*/
			GSElementoTextoFO = document.createElement("div");
			GSElementoTextoFO.style.display = "block";
			GSElementoTextoFO.style.padding = "2.5px";
			GSElementoTextoFO.style.paddingLeft = "10px";
			
			if (GSParametros.Modelo == 1){ 
				if (iOptions % 2) {
					GSElementoTextoFO.style.backgroundColor = "#f1f1f1";
				}
				else {
					GSElementoTextoFO.style.backgroundColor = "#f9f9f9";
				}
			}else if(GSParametros.Modelo == 2){
				GSElementoTextoFO.style.backgroundColor = "#c7c7c7";
				GSElementoTextoFO.setAttribute("class","GSelemento"+iOptions);
			}
				
				GSElementoTextoFO.innerHTML=GSParametros.Itens[iOptions][0];
			/*_-_-_- - Elemento Texto - Filho Options - -_-_-_*/
			
			/*_-_-_- + Elemento Link - Filho Options + -_-_-_*/
				
				GSElementoLinkFO=document.createElement("a");
				GSElementoLinkFO.display="block";
				GSElementoLinkFO.style.color="#000000";
				GSElementoLinkFO.setAttribute("href","javascript:void(0);");
				GSElementoLinkFO.setAttribute("rel",iOptions);
				if (GSParametros.Modelo == 1) {
					GSElementoLinkFO.onclick = function(){
						GoldenSelect_SelecionarOpcao(this.rel, GSParametros.Alvo, GSParametros.Itens);
					}
				}
				if (GSParametros.Modelo == 2) {
					
					GSElementoLinkFO.onmouseover = GSParametros.Over;
					GSElementoLinkFO.onmouseout = GSParametros.Out;
					GSElementoLinkFO.onclick = GSParametros.LinkForm;
				}
			/*_-_-_- - Elemento Link - Filho Options - -_-_-_*/
			
			GSElementoLinkFO.appendChild(GSElementoTextoFO);
			GSElementoOptions.appendChild(GSElementoLinkFO);
			
			if((GSParametros.Itens[iOptions][1]==parseInt(GSParametros.Alvo.value))){
				iChecked=iOptions;
			}
		}
		
		/*_-_-_- + Hierarquia de Elementos + -_-_-_*/
			GSElementoLinkFS.appendChild(GSElementoTextoFS);
			GSElementoLinkFS.appendChild(GSElementoImagemFS);
			GSElementoSelect.appendChild(GSElementoLinkFS);
			GSParametros.Alvo.parentNode.appendChild(GSElementoSelect);
			GSParametros.Alvo.parentNode.appendChild(GSElementoOptions);
		/*_-_-_- - Hierarquia de Elementos - -_-_-_*/
		
		GoldenSelect_SelecionarOpcao(iChecked,GSParametros.Alvo,GSParametros.Itens);
	}
	
	GoldenSelect_SelecionarOpcao=function(iOpcao,Alvo,Itens){
		Alvo.value=Itens[iOpcao][1];
		Alvo.parentNode.childNodes[(Alvo.parentNode.childNodes.length-2)].childNodes[0].childNodes[0].innerHTML=Itens[iOpcao][0]
		for(iCor=0;iCor<Alvo.parentNode.lastChild.childNodes.length;iCor++){
			Alvo.parentNode.lastChild.childNodes[iCor].style.color="#000000";
			Alvo.parentNode.lastChild.childNodes[iCor].style.fontWeight="normal";
		}
		Alvo.parentNode.lastChild.childNodes[iOpcao].style.color="#0B89BD";
		Alvo.parentNode.lastChild.childNodes[iOpcao].style.fontWeight="bolder";
	}
	
	this.NovoSelect();
 }
	
