/********************************************************************************************************
Projeto                     =   API Ajax - ShopTour
Arquivo                     =   DOM.js
Descricao                   =   Objeto de gerenciamento e tratamento de funcoes em DOM.
Dependencias                =   nenhum
Criador                     =   LabST (Laboratorio Shop Tour)
Data de criacao             =   05/11/2007
Data de altima alteracao    =   21/11/2007
********************************************************************************************************/
function DOM() {

    //Loader
    this.arrInputLoader = new Array();
    this.defaultBoxLoader = "boxCarregandoID";
    //Loader
    
    
    
    
         
    /*
        Funcao          :   GetMediaPlayer;
	    Descricao       :   Cria um objeto Media Player do tamanho _width X _height e inputa na página no local informado pelo parâmetro _idDestination;
        Entrada         :   _idDestination = id do local onde o objeto será inserido;
                            _width = largura do objeto;
                            _height = altura do objeto;
        Saida           :   false = caso haja problemas;
    */    
    this.GetMediaPlayer = function( _idDestination, _width, _height )
    {
        try
        {
            var myPlayer = null; //Objeto player
            var myPlayerParamAutoStart = null; //Objeto parametro de Auto Start
            var myPlayerParamUiMode = null; //Objeto parametro de uiMode
            
            //Validando os Browsers
            if(Browser.isIE)
            {
                //Internet Explorer
                myPlayer = document.createElement("object");
                myPlayer.setAttribute("id", "PLAYERID");
                myPlayer.setAttribute("name", "PLAYERID");
                myPlayer.setAttribute("width", _width);
                myPlayer.setAttribute("height", _height);            
                myPlayer.setAttribute("classid", "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6");            
                myPlayer.setAttribute("type", "application/x-oleobject");
                myPlayer.setAttribute("windowLessVideo", "-1");
                
                myPlayerParamAutoStart = document.createElement("param");
                myPlayerParamAutoStart.setAttribute("name", "autoStart");
                myPlayerParamAutoStart.setAttribute("value", "true");
                
                myPlayerParamUiMode = document.createElement("param");
                myPlayerParamUiMode.setAttribute("name", "uiMode");
                myPlayerParamUiMode.setAttribute("value", "full");
            }
            else
            {
                //Firefox e Opera
                myPlayer = document.createElement("object");
                myPlayer.setAttribute("id", "PLAYERID");
                myPlayer.setAttribute("name", "PLAYERID");
                myPlayer.setAttribute("width", _width);
                myPlayer.setAttribute("height", _height);            
                myPlayer.setAttribute("type", "Video/x-ms-asf");
                myPlayer.setAttribute("windowLessVideo", "-1");
                
                myPlayerParamAutoStart = document.createElement("param");
                myPlayerParamAutoStart.setAttribute("name", "autoStart");
                myPlayerParamAutoStart.setAttribute("value", "true");
                
                myPlayerParamUiMode = document.createElement("param");
                myPlayerParamUiMode.setAttribute("name", "uiMode");
                myPlayerParamUiMode.setAttribute("value", "full");
                
                myPlayer.appendChild(myPlayerParamAutoStart);
                myPlayer.appendChild(myPlayerParamUiMode);
            }
            DOM.GID(_idDestination).appendChild(myPlayer);            
        }
        catch(e)
        {
            //throw(e);
            return false;
        }
    }

	/*
        Funcao          :   GID;
	    Descricao       :   getElementById melhorado;
        Entrada         :   id = id do objeto a ser recuperado;
        Saida           :   obj = objeto recuperado;
	*/
    this.GID = function (id) {
        try {
            var obj = null
            if(document.layers) {
                obj = document.layers[id];
            } else if(document.all && !this.GID) {
                obj = document.all[id];
            } else {
                obj = document.getElementById(id);
            }
            return obj;
        } catch(e) {
            //alert("DOM: GID(id);");
            return false;
        }
    }
    
    
	/*
        Funcao          :   Loading;
	    Descricao       :   Funcao que insere o carregando (texto ou flash);
        Entrada         :   id = id onde sera inserido o carregando;
                        :   tipo = carregando ou carregado;
        Saida           :   true = caso insira o texto de carregando;
                            false = caso haja erro de processamento;
	*/
    this.Loading = function ( id, tipo ) {
        try {
            var i = 0;
            var totalInputLoader;
            var nextIndex = null;
            var imgCarregando = null;
            var boxCarregando = null;
            
            if(tipo == "carregando")
            {   
                this.arrInputLoader.push(id);
                imgCarregando = this.GetImage( "imgCarregando_" + id, "img/loading.gif", 0, "", "Aguarde, carregando...", "" );
                boxCarregando = this.GetDiv( "boxCarregando_" + id, "msgCarregando", imgCarregando, "", "" );
                this.GID(this.defaultBoxLoader).appendChild(boxCarregando);
            }
            else if(tipo == "carregado")
            {
                totalInputLoader = this.arrInputLoader.length;
                
                for ( i = 0; i < totalInputLoader; i++ )
                {
                    if ( id == this.arrInputLoader[i] ) 
                    {
                        this.arrInputLoader.splice(i,1);
                        this.RemoveObject("boxCarregando_" + id);
                    }
                }
                
                totalInputLoader = this.arrInputLoader.length;
                
                if ( totalInputLoader == 0 )
                {
                    this.GID("boxCarregandoID").innerHTML = "";
                }
            }
           
        } catch(e) {
            alert("DOM: Loading(id);" + e.message);
            return false;
        }
    }

	/*
        Funcao          :   Loaded;
	    Descricao       :   Funcao que exclui o carregando (texto ou flash);
        Entrada         :   Nenhuma;
        Saida           :   true = caso insira o texto de carregando;
                            false = caso haja erro de processamento;
	*/
    this.Loaded = function () {
        try {
            //this.GID("boxCarregandoID").innerHTML = "";

        } catch(e) {
            //alert("DOM: Loading(id);");
            return false;
        }
    }    
    
	/*
        Funcao          :   ClearObject;
	    Descricao       :   Elimina todos os nos abaixo do objeto identificado por id;
        Entrada         :   id = id do objeto a ser limpo;
        Saida           :   nada;
                            false = caso haja erro de processamento;
	*/
    this.ClearObject = function ( id ) {
        try {
            var e = DOM.GID(id);
            if(!e.hasChildNodes()) {
                return;
            }
            
            var c = e.childNodes;
            while(c.length > 0) {
                var no = c[c.length-1];
                e.removeChild(no);
            }
        } catch(e) {
            //alert("DOM: ClearObject(id);");
            return false;
        }
    }
    
	/*
        Funcao          :   RemoveObject;
	    Descricao       :   Elimina o no identificado por id;
        Entrada         :   id = id do objeto a ser eliminado;
        Saida           :   true = caso consiga remover o no;
                            false = caso haja erro de processamento;
	*/
    this.RemoveObject = function ( id ) {
        try {
            var objeto = null;
            var pai = null;
            if (id != "") {
                objeto = this.GID(id)
                pai = objeto.parentNode;
                pai.removeChild(objeto);
            }
            return true;
        } catch(e) {
            //alert("DOM: RemoveObject(id);");
            return false;
        }
    }
    
	/*
        Funcao          :   ChangeCss;
	    Descricao       :   Altera a classe css do objeto referenciado por id para className;
        Entrada         :   id = id do objeto a ser alterado a classe;
                            className = classe css do objeto;
        Saida           :   false = caso haja erro de processamento;
	*/
    this.ChangeCss = function( classeCss, className ) {
        try {
            if ( className != "" ) {
                classeCss.setAttribute("class", className);
                classeCss.setAttribute("className", className);
            }
        } catch(e) {
            //alert("DOM: ChangeCss(classeCss, className);");
            return false;
        }
    }
    
    
	/*
        Funcao          :   ShowHiddenElement;
	    Descricao       :   Altera o style 'display' do objeto referenciado por id para block ou none;
        Entrada         :   objeto = id do objeto base para a posicao;
                        :   idElement = id do Elemento a ser alterado o style;
        Saida           :   false = caso haja erro de processamento;
	*/    
    this.ShowHiddenElement = function( objeto, idElement ) {
        try {

            var e = this.GID(idElement).style.display;
		    
			if ( e == 'block')	{
				this.GID(idElement).style.display = "none";
			} else {
				this.GID(idElement).style.display = "block";
                DOM.PositionElement( objeto , idElement );
			}
        } catch(e) {
            //alert("DOM: ShowHiddenElement( idElement );");
            return false;
        }
    }
    
    
	/*
        Funcao          :   PositionElement;
	    Descricao       :   Posiciona x e y do elemento;
        Entrada         :   objeto = id do objeto base para a posicao;
                        :   idElement = id do elemento a ser alterado a posicao;
        Saida           :   false = caso haja erro de processamento;
	*/    
    this.PositionElement = function( objeto , idElement ) {
        try {

            var r = "";
            var oT = 0;
		    var oL = 0;
            var el = idElement.substring(0, 2);

            if(el == "Oq")
            {
	            oT = this.GID(objeto).offsetTop + 20;
	            oL = this.GID(objeto).offsetLeft;
            } else {
                oT = 0;
	            oL = 0;
            }
			r = this.GID(idElement).style.top = oT + "px";
			r += this.GID(idElement).style.left = oL + "px";
			
			return r;
			
        } catch(e) {
            //alert("DOM: PositionElement( idElement );");
            return false;
        }
    }
    
    
	/*
        Funcao          :   SetTextValue;
	    Descricao       :   Seta valor a um campo do tipo text especificado por textId;
        Entrada         :   textId = id do campo a ser inserido/alterado o valor;
                            textValue = valor a ser inserido;
        Saida           :   false = caso haja erro de processamento;
	*/
    this.SetTextValue = function( textId, textValue ) {
        try {
            var text = this.GID(textId);
            text.value = "";
            text.value = textValue;
            return false;
        } catch(e) {
            //alert("DOM: SetTextValue(textId, textValue);");
            return false;
        }
    
    }
    
	/*
        Funcao          :   SelectElement;
	    Descricao       :   Seta valor a um campo do tipo text especificado por textId;
        Entrada         :   textId = id do campo a ser inserido/alterado o valor;
                            textValue = valor a ser inserido;
        Saida           :   false = caso haja erro de processamento;
	*/
    this.SelectElement = function( idElement ) {
        try {
            this.GID(idElement).select();
        } catch(e) {
            //alert("DOM: SelectElement( idElement );");
            return false;
        }
    
    }    
    
	/*
        Funcao          :   SetAttribute;
	    Descricao       :   Seta valor a um atributo;
        Entrada         :   Id = id do campo a ser inserido/alterado o valor;
							Attribute = qual o atributo será alterado
                            textValue = valor a ser inserido neste atributo;
        Saida           :   false;
	*/
	
	this.SetAttribute = function( id, attribute, value  )	{
		try	{
			eval("document.getElementById(\"" + id + "\").style." + attribute + " = \"" + value + "\";");
		} catch(e)	{
			//alert("DOM: SetAttribute(id, attribute, value);");
            return false;
		}
		
	}

	/*
        Funcao          :   ResizeLay;
	    Descricao       :   Seta width proporcional ao div Pai;
        Entrada         :   idPai = id do Div pai;
							idDif = id do Div onde ele pega a diferença;
							idDiv = id do campo a ser alterado o valor;
                            Marg = diferenca de espacamento entre os campos;
        Saida           :   false = caso haja erro de processamento;
	*/
	
	this.ResizeLay = function( idPai, idDif, idDiv, Marg )	{
		try	{
			var dp = null;
			var dd = null;
			var v = null;
			var divPai = idPai;
			var divDif = idDif;
			var divId = idDiv;
			var m = Marg;
			
			dp = document.getElementById(divPai).offsetWidth;
			dd = m + document.getElementById(divDif).offsetWidth;
			
			v = Math.floor(dp - dd);

			eval("document.getElementById(\"" + divId + "\").style.width = \"" + v + "px\";");
			
			// verifica se é o div do mapa
			if (idDif == "divNav")
			{
				DOM.ResizaLayHeight();
			}

	 	} catch(e)	{
			//alert(e);
       		return false;
		}
	
	}
	
	
	this.ResizaLayHeight = function()
	{
		var v = (document.getElementById("divContainerMap").offsetHeight - 1);
		document.getElementById("divBoxBarra").style.height = v +"px";
		document.getElementById("divBoxSeta").style.top = parseInt(v/2)+"px";
	}
	
	/*
        Funcao          :   ResizePercentPai;
	    Descricao       :   Seta width proporcional ao div Pai enviando a porcentagem do campo alterado ;
        Entrada         :   idPai = id do Div pai;
							idDiv = id do campo a ser alterado o valor;
                            divRes = valor em porcentagem do div;
        Saida           :   false = caso haja erro de processamento;
	*/
	
	this.ResizePercentPai = function( idPai, idDiv, divRes )	{
		try	{	
	
			var dp = null;
			var res = divRes;
			var v = null;
			var divPai = idPai;
			var divId = idDiv;	
	
			dp = document.getElementById(divPai).offsetWidth;
			
			v = Math.floor((res / 100) * dp);
			
			if(dp < "550"){
				v = 110;
			}
			eval("document.getElementById(\"" + divId + "\").style.width = \"" + v + "px\";");
		} catch(e)	{
			//alert("ResizePercentPai()");
        	return false;
		}	
	}
	
	/*
        Funcao          :   ResizePercent;
	    Descricao       :   Seta width e height proporcional ao tamanho do browser;
        Entrada         :   Id = id do campo a ser inserido/alterado o valor;
							divRes = valor em porcentagem do div;
							Attribute = qual o atributo será alterado width ou height;
                            divResMin = valor a minimo do div;
        Saida           :   false = caso haja erro de processamento;
	*/

	this.ResizePercent = function( divId, divRes, Attribute, divResMin)	{
		try	{
			var res = divRes;
			var p = "100";
			var resMin = divResMin;
			var v = null;
			var offsetW = null;
			var offsetH = null;
			var attr = null;
			var offset = null;
			
			
			if(Browser.isIE)
			{
				offsetW = document.body.offsetWidth;
				offsetH = document.body.parentNode.offsetHeight;
			} else {
				offsetW = window.innerWidth;
				offsetH = window.innerHeight;
			}
			
			
			switch(Attribute)
			{
			case "w":
				attr = "width";
				offset = offsetW;
				break;
			case "h":
				attr =  "height"
				offset = offsetH;
				break;
			default:
				attr = "width";
				offset = offsetW;
			}
			
			v = Math.floor((res / p) * offset);
			
			if(resMin > v)	{
				v = Math.floor(resMin);
			}
			
			//alert(divId + " - " +  v);
			eval("document.getElementById(\"" + divId + "\").style." + attr +" = \"" + v + "px\";");
			
		} catch(e)	{
			//alert(e);
        	return false;
		}
	}

 
	/*
        Funcao          :   GetImage;
	    Descricao       :   Cria um objeto Image e retorna o mesmo;
        Entrada         :   id = identificador da imagem a ser criada;
                            src = path da imagem a ser criada;
                            width = largura da imagem a ser criada;
                            height = altura da imagem a ser criada;
                            alt = texto explicativo da imagem a ser criada;
                            className = valor da classe css a ser aplicada a imagem;
        Saida           :   img = objeto Image com todas as opcoes informadas;
                            false = caso haja erro de processamento;
	*/
    this.GetImage = function( id, src, width, height, alt, className ) {
        try {
            var img = document.createElement("img");
            img.setAttribute("name", id);
            img.setAttribute("id", id);
            img.setAttribute("src", src);
            
            if ( parseInt(width) > 0 ) {
                img.setAttribute("width", width);
            }
            
            if ( parseInt(height) > 0 ) {
                img.setAttribute("height", height);
            }

            img.setAttribute("border", 0);
            img.setAttribute("alt", alt);
            img.setAttribute("title", alt);
            
            if ( className != "" ) {
                DOM.ChangeCss(img, className)
            }
            
            return img;
        } catch(e) {
            //alert("DOM: GetImage(id, src, width, height, alt, className);");
            return false;
        }
    }
    
	/*
        Funcao          :   GetHref;
	    Descricao       :   Cria um objeto A e retorna o mesmo;
        Entrada         :   id = identificador do link a ser criado;
                            value = objeto de exibicao no link;
                            url = endereco de destino do link;
                            target = target do link;
                            className = valor da classe css a ser aplicada ao link;
                            title = valor do title do obj;
        Saida           :   href = objeto A com todas as opcoes informadas;
                            false = caso haja erro de processamento;
	*/
    this.GetHref = function ( id, value, url, target, className, title ) {
        try {
            var href = null;
            href = document.createElement("a");
            href.setAttribute("name", id);
            href.setAttribute("id", id);
            href.setAttribute("href", url);
            href.setAttribute("title", title);
            target = ( target == "" ) ? "_self" : target ;
            href.setAttribute("target", target);
            
            if ( className != "" ) {
                DOM.ChangeCss(href, className);
            }
            
            switch(typeof(value)) {
                case "string":
                    href.appendChild(DOM.GetTextNode(value, ""));
                    break;
                case "object":
                    href.appendChild(value);
                    break;
            }            
            return href;
        } catch(e) {
            //alert("DOM: GetHref(id, url, target, className, title);");
            return false;
        }
    }
    
	/*
        Funcao          :   GetSelect;
	    Descricao       :   Cria e retorna um select(combo) com seu options;
        Entrada         :   id = id do objeto a ser criado;
                            className = classe css do objeto;
                            len = limite do quantidade de option a ser inserida;
                            values = valores a serem inseridos na lista;
                            eventMethod = evento a ser inserido;
        Saida           :   sel = select criado;
                            false = caso haja erro de processamento;
	*/
    this.GetSelect = function (id, className, len, values, eventMethod) {
        try {
            var sel = null;
            var selOption = null;
            var i, totArray = 0;
            
            sel = document.createElement("select");
            sel.setAttribute("name", id);
            sel.setAttribute("id", id);
            sel.setAttribute("size", len);
            
            if ( className != "" ) {
                this.ChangeCss(sel, className)
            }
            
            totArray = values.length;
            
            if ( eventMethod != "" ) {
                sel = this.CreateEventListener(sel, "onchange", "change", eventMethod);
            }
            
            for( i=0; i<totArray; i++ ) {
                selOption = document.createElement("option");
                selOptionText = this.GetTextNode(values[i], "");
                selOption.setAttribute("value", values[i]);
                selOption.appendChild(selOptionText);
                sel.appendChild(selOption);
            }
            return sel;
        } catch(e) {
            //alert("DOM: GetSelect();");
            return false;
        }
    }
    
	/*
        Funcao          :   GetList;
	    Descricao       :   Cria e retorna uma lista com seu valores;
        Entrada         :   id = id do objeto a ser criado;
                            className = classe css do objeto;
                            values = valores a serem inseridos na lista;
                            eventMethod = evento a ser inserido;
        Saida           :   list = lista criada;
                            false = caso haja erro de processamento;
	*/
    this.GetList = function( id, className, values, eventMethod ) {
        try {
            var listValue = null;
            var listText = null;
            var list = null;
            var i = 0;
            var listHref = null;
        
            list = document.createElement("ul");        
            list.setAttribute("name", id);
            list.setAttribute("id", id);
            
            if ( className != "" ) {
                this.ChangeCss(list, className)
            }
            totArray = values.length;
            for( i=0; i<totArray; i++ ) {
                listValue = document.createElement("li");
                listValue.setAttribute("id", "li_" + id + "_" + i);
                if ( eventMethod != "" ) {
                    listHref = this.GetHref("href" + i, values[i], "javascript:void(\"" + values[i] + "\");", "_self","","");
                    listHref = this.CreateEventListener(listHref, "onclick", "click", eventMethod);
                    listValue.appendChild(listHref);
                } else {
                    listText = this.GetTextNode(values[i], "");
                    listValue.appendChild(listText);
                }
                list.appendChild(listValue);
            }
            return list;
        } catch(e) {
            //alert("DOM: GetList(id, className, values);");
            return false;
        }
    }
    
	/*
        Funcao          :   GetTextNode;
	    Descricao       :   Cria um objeto TextNode e retorna aplicado a uma classe css informada;
        Entrada         :   value = valor do texto;
                            className = valor da classe css a ser aplicada ao value;
        Saida           :   txt = objeto TextNode com todas as opcoes informadas;
                            false = caso haja erro de processamento;
	*/
    this.GetTextNode = function( value, className ) {
        try {
            var txt = document.createTextNode(value);
            if ( className != "" ) {
                DOM.ChangeCss(txt, className)
            }
            
            return txt;
        } catch(e) {
            //alert("DOM: GetTextNode(value, className);");
            return false;
        }
    }
    
	/*
        Funcao          :   GetDiv;
	    Descricao       :   Recebe uma lista de parametros de retorna um objeto div;
        Entrada         :   id = id/name do objeto a ser criado;
                            divClassName = nome da classe a ser aplicada ao div criado;
                            value = valor do div;
                            valueClassName = valor da classe css a ser aplicada ao value (caso valueType seja "TEXTNODE");
                            valueType = tipo de insercao do no div (INNERHTML, TEXTNODE);
        Saida           :   div = objeto div com todas as opcoes informadas;
                            false = caso haja erro de processamento;
	*/
    this.GetDiv = function ( id, divClassName, value, valueClassName, valueType ) {
        try {
            var div = null;
            
            div = document.createElement("div");
            div.setAttribute("name", id);
            div.setAttribute("id", id);
            
            if ( divClassName != "" ) {
                DOM.ChangeCss(div, divClassName)
            }
            
            if ( typeof(value) == "object" ) {
                div.appendChild(value);
            } else {
                switch( valueType ) {
                    case "INNERHTML":
                        div.innerHTML = value;
                        break;                    
                    case "TEXTNODE":
                        div.appendChild(DOM.GetTextNode(value, valueClassName));
                        break;
                }
            }
            
            if ( value != "" ) {
            }
            
            return div;
        } catch(e) {
            //alert("DOM: GetDiv(id, divClassName, value, valueClassName, valueType);");
            return false;
        }
    }
    
	/*
        Funcao          :   CreateEventListener;
	    Descricao       :   Recebe um objeto e retorna o mesmo com o evento informado;
        Entrada         :   obj = objeto a ser criado um evento;
                            eventIE = nome do evento a ser criado para o Browser IE;
                            eventOthers = nome do evento a ser criado para o outros Browsers;
                            metodo = funcao a ser inserida no evento;
        Saida           :   obj = objeto recebido e com o evento;
                            false = caso haja erro de processamento;
	*/
    this.CreateEventListener = function( obj, eventIE, eventOthers, metodo ) {
        try {
            if (obj.addEventListener){
                //Outros
                eval("obj.addEventListener(\"" + eventOthers + "\", " + metodo + ", false);");
            } else if (obj.attachEvent){
                //Internet Explorer
                eval("obj.attachEvent(\"" + eventIE + "\", " + metodo + ");");
            }
            
            return obj;
        } catch(e) {
            //alert("DOM: CreateEventListener(obj, eventIE, eventFirefox, metodo);");
            return false;
        }
    }
    
	/*
        Funcao          :   GetEventListenerValue;
	    Descricao       :   Retorna o valor desejado dentro de um evento. Para que seja possivel o retorno, o href do link clicado deve ser javascript:void("valordesejado");;
        Entrada         :   e = evento ocorrido;
                            valueToReturn = propriedade de retorno (TagName ou TagValue);
        Saida           :   valueReturned = string tratada a partir do padrao;
                            false = caso haja erro de processamento;
	*/
    this.GetEventListenerValue = function(e, valueToReturn) {
        try {
            var valueReturned = "";
            var targ = null;
            
            if ( !e ) {
                e = window.event;
            }

            if (e.target) {
                targ = e.target;
            } else if (e.srcElement) {
                targ = e.srcElement;
            }
            
            if (targ.tagName.toLowerCase() != 'a') {
                targ = targ.parentNode;
            }
            
            if (targ.nodeType == 3) {// defeat Safari bug
                targ = targ.parentNode;
            }
            if ( valueToReturn == "TagName" ) {
                valueReturned = targ.tagName;
            } else {
                if ( valueToReturn == "TagValue" ) {
                    targ = String(targ);
                    first = targ.indexOf("\"") + 1;
                    last = targ.lastIndexOf("\"");
                    lenght = last - first;
                    valueReturned = targ.substr( first, lenght );
                }
            }
           
            return valueReturned;
        } catch(e) {
            //alert("DOM: GetEventListenerValue(e, valueToReturn);");
            return false;
        }
    }
    
    
	/*
        Funcao          :   ClearElementValue;
	    Descricao       :   Limpa o value do elemento caso tenha texto padrão quando esta em focus;
        Entrada         :   idElement = id do elemento que sera alterado;
        Saida           :   false = caso haja erro de processamento;
	*/    
    
		this.ClearElementValue = function(idElement, text)    {
            try {
                var v = this.GID(idElement).value;

                if	(v == text) {
	                this.GID(idElement).value = '';
                } else {
	                this.GID(idElement).select();
                }
            } catch(e) {
                //alert("DOM: ClearElementValue(idElement);");
                return false;
            }            
		}		


	/*
        Funcao          :   SetElementValue;
	    Descricao       :   Seta o value do elemento;
        Entrada         :   idElement = id do elemento que sera alterado;
                        :   text = texto que será incluido no value;
        Saida           :   false = caso haja erro de processamento;
	*/ 

		this.SetElementValue = function(idElement, text)
		{
		    try {
			    
    			var v = this.Trim(this.GID(idElement).value);
    			
			    if (v != "")   {
				    this.GID(idElement).value;
			    } else {
				    this.GID(idElement).value = text;
			    }
			} catch(e) {
                alert("DOM: SetElementValue(idElement);");
                return false;
            }            
			
		}    

	/*
        Funcao          :   SetElementValue;
	    Descricao       :   Limpa caracteres em branco;
        Entrada         :   str = string que sera alterado;
        Saida           :   string alterada;
                        :   false = caso haja erro de processamento;
	*/ 

		this.Trim = function( str)
		{
		    try {

		    return str.replace(/^\s+|\s+$/g,""); 
    			
			} catch(e) {
                alert("DOM: Trim( str );");
                return false;
            }            
			
		} 
		
	/*
        Funcao          :   AlterneteIcoMinimizar;
	    Descricao       :   Altera imagem e link da seta Minimizar / Maximizar;
        Entrada         :   idElement = Elemento que sera alterado;
        Saida           :   false = caso haja erro de processamento;
	*/ 

		this.AlterneteIcoMinimizar = function( idElement )
		{
		    try {
                
                
                var str = DOM.GID(idElement).src;
		        
		        var start = str.lastIndexOf("/")+1;
		        var lenght = str.lastIndexOf(".");
                
                var strId = idElement;
                var startId = strId.lastIndexOf("_")+1;
                
                var divId = strId.substring(startId);
                var seta = str.substring(start , lenght);

		        if(seta == "ico_box_tit_setaCima")
		        {
		            DOM.GID(idElement).src = "img/ico_box_tit_setaBaixo.gif";
		            DOM.GID(idElement).title = "Maximizar";
		            ShopTour.GetTipoMaterias(divId , 0, 0);
		        } else {
		            DOM.GID(idElement).src = "img/ico_box_tit_setaCima.gif";
		            DOM.GID(idElement).title = "Minimizar";
		            ShopTour.GetTipoMaterias(divId , 0, 6);
		        }
    			
			} catch(e) {
                alert("DOM: AlterneteIcoMinimizar( idElement );");
                return false;
            }           
			
		}
		
    /*
        Funcao          :   EnterKeyPress; 
	    Descricao       :   Quando teclar enter ele aciona a funcao click do botao (keyCode/which = 13 'tecla enter' );
        Entrada         :   event = evento acionado;
                        :   idElement = elemento que pegara o valor;
        Saida           :   false = caso haja erro de processamento;
	*/ 
	
	    this.elementBusca = "";

		this.EnterKeyPress = function(event, idElement)
		{
            if(event.which || event.keyCode)
            {            
                if ((event.which == 13) || (event.keyCode == 13))
                {
                    DOM.elementBusca = idElement;
                    /*
                    var frm1;
                    frm1 = DOM.GID("aspnetForm");
                    frm1 = DOM.CreateEventListener(frm1, "onsubmit", "onsubmit", "ShopTour.SubmitClickBusca");
                    */
                    
                    ShopTour.ClickBusca(idElement);
                }                
                
            } else {
                //alert("DOM: EnterKeyPress( event, idElement );");
            }
            //return false;
       }
       
       
    /*
        Funcao          :   CopyToClipboard; 
	    Descricao       :   Quando clicar no botao ele copia para a area de transferencia o valor do elemento;
        Entrada         :   idElement = id do Elemento;
        Saida           :   false = caso haja erro de processamento;
	*/ 
       
    this.CopyToClipboard = function( idElement )
    {
       try
       {
           var v = DOM.GID(idElement).value;

           if( window.clipboardData && clipboardData.setData )
           {
            clipboardData.setData("Text", v);
            DOM.GID(idElement).select();
           }
           else
           {
               //alert("Firefox");   
           }
       } catch(e) {
           
           //alert("DOM: CopyToClipboard( idElement );");
           return false;
       }
    }
     
    /*
        Funcao          :   AddItensToSelect; 
	    Descricao       :   Adiciona um item novo a um Select
        Entrada         :   valorOrigen = Valor para Adicionar ao Select;
                            idSelectDestino = Id do Objecto SELECT
                            regExpValidar = Expressao regular para Validar o "valorOrigem"
                            txtAlerta = Mensagem para ser utilziado no Alerta quando nao tiver sucesso na validacao
        Saida           :   false = caso haja erro de processamento;
	*/ 
    this.AddItensToSelect = function (valorOrigen, idSelectDestino, regExpValidar, txtAlerta)
    {
        try
        {
            var e = document.getElementById(idSelectDestino);
            var o = document.createElement("option");
            var t = document.createTextNode(valorOrigen);

            if (regExpValidar.test(valorOrigen) != true){
                alert(txtAlerta);
                return false;
            } else {
                var podeIncluir = true;
                for (var i = 0; i < e.length; i++){
                    if (e[i].value == valorOrigen){
                        podeIncluir = false;
                    }
                }
                if(podeIncluir == true){
                    o.appendChild(t);
                    o.value = valorOrigen;	    
                    o.setAttribute("selected", true)
                    e.appendChild(o);
                }
            }
        } catch(e)
        {
            //alert("DOM: SelectAddItens(valorOrigen, idSelectDestino);");
            return false;
        }
    }
    
    /*
        Funcao          :   RemoveSelectItemFromSelect; 
	    Descricao       :   Remove o item selecionado do Select
        Entrada         :   idSelectDestino = Id do Objecto SELECT
        Saida           :   false = caso haja erro de processamento;
	*/
    this.RemoveSelectItemFromSelect = function (idSelectDestino)
    {
        try
        {
            var objetoSelect = document.getElementById(idSelectDestino);
            objetoSelect.options[objetoSelect.selectedIndex] = null;
        }catch(e){
            //alert("DOM: RemoveSelectItemFromSelect(idSelectDestino);");
            return false;
        }
        
    }
    
    /*
        Funcao          :   AddEmailToSelect; 
	    Descricao       :   Adiciona um valor tipo Email a um Select
        Entrada         :   idTextBoxOrigem = Id do Text Box com o email 
                            idSelectDestino = Id do Objecto SELECT
                            regExpValidar = Expressao regular para Validar o "valorOrigem"
                            txtAlerta = Mensagem para ser utilziado no Alerta quando nao tiver sucesso na validacao
        Saida           :   false = caso haja erro de processamento;
	*/ 
    this.AddEmailToSelect = function (idTextBoxOrigem, idSelectDestino)
    {
        var emailRegxp = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        var objetoOrigem = document.getElementById(idTextBoxOrigem);
        this.AddItensToSelect(objetoOrigem.value, idSelectDestino, emailRegxp, 'O email digitado não é válido');
        objetoOrigem.value = "";
    }
    
    this.VerificaAncora = function ()
    {
        var verificaAncora = new String();
        var ancora  = new String();
        
        verificaAncora = location.href;
        
        var ancStart = verificaAncora.lastIndexOf("#");
        var ancLength = verificaAncora.length;
        
        ancora = verificaAncora.substr(ancStart, ancLength);

        if (ancStart != -1)
        {
             this.location = ancora;
        }
    }
	
	this.AbrirPopup = function(__destino, __width, __height, __left, __top)
	{
		var width = __width;
		var height = __height;
		var left =__left;
		var top = __top;
		window.open(__destino,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
	}
    
    
}