/*
 *
 * GoldenCompleta
 * Desenvolvedor: Fernando Arroyo
 * GoldenLight [ fernando.arroyo@goldenlight.biz ]
 * 04.11.2009
 *
 */

 var GoldenCompleta=function(Parametros){
	/*
	 * Parâmetros
	 * 
	 * Alvo = Objeto Referência
	 * Campo = Objeto Input
	 * Modelo = Modelo de Busca  
	 * 
	 */
	 
	 Parametros.ObjPai=this;
	 this.Parametros=Parametros;
	 
	 /*_-_-_- + Criando Objeto + -_-_-_*/
		 this.Criar=function(){
			 if((this.Parametros.Campo.value.toString().charAt(this.Parametros.Campo.value.toString().length-1))==" "){
				 if(document.getElementById("__GoldenCompleta__")!=null){
					 this.Destruir();
				 };
				/*_-_-_- + Objeto Pai + -_-_-_*/
					this.GoldenCompletaObjPai=document.createElement("div");
					this.GoldenCompletaObjPai.style.backgroundColor="#EAEAEA";
					this.GoldenCompletaObjPai.id="__GoldenCompleta__";
					this.GoldenCompletaObjPai.style.position="absolute";
					this.GoldenCompletaObjPai.style.top=(RemoveMedida(this.Parametros.Alvo.style.height)+RemoveMedida(this.Parametros.Alvo.style.paddingTop)+RemoveMedida(this.Parametros.Alvo.style.paddingBottom)+RemoveMedida(this.Parametros.Alvo.style.marginTop)+RemoveMedida(this.Parametros.Alvo.style.marginBottom))+"px";
					this.GoldenCompletaObjPai.style.left=this.Parametros.Alvo.style.marginLeft;
					this.GoldenCompletaObjPai.style.width=(RemoveMedida(this.Parametros.Campo.style.width)+RemoveMedida(this.Parametros.Campo.style.paddingLeft)+RemoveMedida(this.Parametros.Campo.style.paddingRight)+RemoveMedida(this.Parametros.Campo.style.marginLeft)+RemoveMedida(this.Parametros.Campo.style.marginRight))+"px";
					this.GoldenCompletaObjPai.style.backgroundColor="#FFFFFF";
					this.GoldenCompletaObjPai.style.border="solid 1px #aeaeae";
					this.GoldenCompletaObjPai.style.zIndex=999999;
					this.GoldenCompletaObjPai.style.innerHTML=window["MensagemCarregando"];
					$.ajax({
		                 type:"POST"
		                ,url:window["CaminhoRaiz"]+"/inc2/popups.php"
		                ,dataType:"script"
		                ,data:"pagina=GoldenCompleta&b="+this.Parametros.Modelo+"&p="+this.Parametros.Campo.value.toString()
		                ,ObjAlvo:this.GoldenCompletaObjPai
		                ,Campo:this.Parametros.Campo
		                ,success:function(resultado){
							if(requiResul){
			                	for(IndResul=0;IndResul<requiResul.length;IndResul++){
			                		GCLinkValor=this.Campo.value;
			                		GCLinkCampo=this.Campo;
			                		GoldenCompletaLink=document.createElement("a");
			                		GoldenCompletaLink.setAttribute("href","javascript:void(0);");
			                		GoldenCompletaLink.setAttribute("rel",requiResul[IndResul]);
			                		GoldenCompletaLink.onmouseout=function(){
			                			GCLinkCampo.value=GCLinkValor;
			                		};
			                		GoldenCompletaLink.onmouseover=function(){
			                			GCLinkCampo.value=this.rel;
			                		};
									GoldenCompletaLink.innerHTML=requiResul[IndResul];
									GoldenCompletaTexto=document.createElement("span");
									GoldenCompletaTexto.style.display="inline-block";
									GoldenCompletaTexto.style.position="relative";
									GoldenCompletaTexto.style.cssFloat="left";
									GoldenCompletaTexto.style.paddingTop="5px";
									GoldenCompletaTexto.style.paddingBottom="5px";
									if(IndResul%2){
										GoldenCompletaTexto.style.backgroundColor="#CACACA";
									}
									else{
										GoldenCompletaTexto.style.backgroundColor="#EAEAEA";
									}
									GoldenCompletaTexto.style.width="100%";
									GoldenCompletaTexto.appendChild(GoldenCompletaLink);
									this.ObjAlvo.appendChild(GoldenCompletaTexto);
			                	}
							}
		                }
		            });
				/*_-_-_- - Objeto Pai - -_-_-_*/

/*				$.ajax({
	                 type:"POST"
	                ,url:window["CaminhoRaiz"]+"/inc2/popups.php"
	                ,data:"pagina=GoldenCompleta&b=0&p="+this.Parametros.Campo.value.toString()
	                ,dataType:"script"
	                ,ObjAlvo:this.GoldenCompletaObjPai
	                ,ObjPai:this
	                ,success:function(r){
					alert(r);
/*						for(IndResul=0;IndResul<requiResul.length;IndResul++){
							this.ObjPai.GoldenCompletaTexto=document.createElement("span");
							this.ObjPai.GoldenCompletaTexto.style.display="inline-block";
							this.ObjPai.GoldenCompletaTexto.style.position="relative";
							this.ObjPai.GoldenCompletaTexto.style.cssFloat="left";
							this.ObjPai.GoldenCompletaTexto.style.padding="5px";
							if(IndResul%2){
								this.ObjPai.GoldenCompletaTexto.style.backgroundColor="#CACACA";
							}
							else{
								this.ObjPai.GoldenCompletaTexto.style.backgroundColor="#EAEAEA";
							}
							this.ObjPai.GoldenCompletaTexto.style.width=(ObjPai.RemoveMedida(this.ObjAlvo.style.width)-(ObjPai.RemoveMedida(this.ObjPai.GoldenCompletaTexto.style.padding)*2));
							this.ObjPai.GoldenCompletaTexto.innerHTML=requiResul[IndResul];
							this.ObjAlvo.appendChild(this.ObjPai.GoldenCompletaTexto);
						}
	                }
	            });*/

				/*_-_-_- + Hierarquia de Elementos + -_-_-_*/
					this.Parametros.Alvo.parentNode.appendChild(this.GoldenCompletaObjPai);
				/*_-_-_- - Hierarquia de Elementos - -_-_-_*/
			 };
		 };
	 /*_-_-_- - Criando Objeto - -_-_-_*/
	 
	 /*_-_-_- + Destruindo Objeto + -_-_-_*/
		 this.Destruir=function(){
			 if(document.getElementById("__GoldenCompleta__")!=null){
				 this.Parametros.Alvo.parentNode.removeChild(this.Parametros.ObjPai.GoldenCompletaObjPai);
			 };
		 };
	 /*_-_-_- - Destruindo Objeto - -_-_-_*/
};

/*_-_-_- + Removendo Medida + -_-_-_*/
	RemoveMedida=function(Valor){
		 if(Valor){
			 return parseInt(Valor.substr(0,(Valor.length-2)));
		 }
		 else{
			 return 0;
		 }
	};
/*_-_-_- - Removendo Medida - -_-_-_*/
