// Fun�es que manipulam elementos de uma p�ina XML
// Desenvolvido por Assinaweb - SOLU�ES
// Programador respons�el: Erlimar P. Silva Campos

function DOM_getId(preobj,id)
{//Fun�o que retorna um OBJETO atrav� do ID fornecido
	if(preobj!=false)
	{
		return preobj.getElementById(id);
	}
	else
	{
		return document.getElementById(id);
	}
}

function DOM_getName(preobj,name,index)
{//Fun�o que retorna um OBJETO atrav� do nome fornecido
//O 'index' �para escolha de um elemento caso o resultado seja muitos
//Use '0' no index caso s�haja um elemento com o nome informado
//O 'preobj' �para informar se o objeto procurado se encontra dentro de outro objeto (uma div por exemplo)
//Caso haja passe o par�etro 'preobj' como um OBJ v�ido
	if(preobj!=false)
	{
		return preobj.getElementsByTagName(name)[index];
	}
	else
	{
		return document.getElementsByTagName(name)[index];
	}
}

function DOM_getText(obj)
{//Fun�o que retorna o texto de um objeto
//Este objeto deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==3)
	{//Se o objeto �do tipo 'texto'
		return obj.data
	}
	else
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		return obj.firstChild.data;
	}
	else
	{//Se n� �do tipo 'texto' ou 'n�
		return false;
	}
}

function DOM_setText(obj,txt)
{//Fun�o que atribui o valor de texto a um objeto
//Este objeto tamb� deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==3)
	{//Se o objeto �do tipo 'texto'
		obj.data=txt;
	}
	else
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		obj.firstChild.data=txt;
	}
	else
	{//Se n� �do tipo 'texto' ou 'n�
		alert('O objeto "'+obj.nodeName+'" n� suporta a atribui�o de texto.');
	}
}

function DOM_getAtributo(obj,atributo)
{//Fun�o que retorna o valor do atributo de um objeto
//Este objeto deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		return obj.getAttribute(atributo);
	}
	else
	{//Se n� �do tipo 'n�
		return false;
	}
}

function DOM_setAtributo(obj,atributo,valor)
{//Fun�o que altera o valor do atributo de um objeto
//Este objeto deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		obj.setAttribute(atributo,valor);
		return true;
	}
	else
	{//Se n� �do tipo 'n�
		return false;
	}
}

function DOM_getStyle(obj,estilo)
{//Fun�o que retorna o valor do estilo de um objeto
//Este objeto deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		var estilominusculo = estilo.toLowerCase();
		
		switch (estilominusculo)
		{
			case 'azimuth':
				return obj.style.azimuth;
				break;
			case 'background':
				return obj.style.background;
				break;
			case 'backgroundattachment':
				return obj.style.backgroundAttachment;
				break;
			case 'backgroundcolor':
				return obj.style.backgroundColor;
				break;
			case 'backgroundimage':
				return obj.style.backgroundImage;
				break;
			case 'backgroundposition':
				return obj.style.backgroundPosition;
				break;
			case 'backgroundrepeat':
				return obj.style.backgroundRepeat;
				break;
			case 'border':
				return obj.style.border;
				break;
			case 'borderbottom':
				return obj.style.borderBottom;
				break;
			case 'borderbottomcolor':
				return obj.style.borderBottomColor;
				break;
			case 'borderbottomstyle':
				return obj.style.borderBottomStyle;
				break;
			case 'borderbottomwidth':
				return obj.style.borderBottomWidth;
				break;
			case 'bordercollapse':
				return obj.style.borderCollapse;
				break;
			case 'bordercolor':
				return obj.style.borderColor;
				break;
			case 'borderleft':
				return obj.style.borderLeft;
				break;
			case 'borderleftcolor':
				return obj.style.borderLeftColorh;
				break;
			case 'borderleftstyle':
				return obj.style.borderLeftStyle;
				break;
			case 'borderleftwidth':
				return obj.style.borderLeftWidth;
				break;
			case 'borderright':
				return obj.style.borderRight;
				break;
			case 'borderrightcolor':
				return obj.style.borderRightColor;
				break;
			case 'borderrightstyle':
				return obj.style.borderRightStyle;
				break;
			case 'borderrightwidth':
				return obj.style.borderRightWidth;
				break;
			case 'borderspacing':
				return obj.style.borderSpacing;
				break;
			case 'borderstyle':
				return obj.style.borderStyle;
				break;
			case 'bordertop':
				return obj.style.borderTop;
				break;
			case 'bordertopcolor':
				return obj.style.borderTopColor;
				break;
			case 'bordertopstyle':
				return obj.style.borderTopStyle;
				break;
			case 'bordertopwidth':
				return obj.style.borderTopWidth;
				break;
			case 'borderwidth':
				return obj.style.borderWidth;
				break;
			case 'bottom':
				return obj.style.bottom;
				break;
			case 'captionside':
				return obj.style.captionSide;
				break;
			case 'clear':
				return obj.style.clear;
				break;
			case 'clip':
				return obj.style.clip;
				break;
			case 'color':
				return obj.style.color;
				break;
			case 'content':
				return obj.style.content;
				break;
			case 'counterincrement':
				return obj.style.counterIncrement;
				break;
			case 'counterreset':
				return obj.style.counterReset;
				break;
			case 'cssfloat':
				return obj.style.cssFloat;
				break;
			case 'csstext':
				return obj.style.cssText;
				break;
			case 'cue':
				return obj.style.cue;
				break;
			case 'cueafter':
				return obj.style.cueAfter;
				break;
			case 'onbefore':
				return obj.style.onBefore;
				break;
			case 'cursor':
				return obj.style.cursor;
				break;
			case 'direction':
				return obj.style.direction;
				break;
			case 'display':
				return obj.style.display;
				break;
			case 'elevation':
				return obj.style.elevation;
				break;
			case 'emptycells':
				return obj.style.emptyCells;
				break;
			case 'filter':
				return obj.style.filter;
				break;
			case 'font':
				return obj.style.font;
				break;
			case 'fontfamily':
				return obj.style.fontFamily;
				break;
			case 'fontsize':
				return obj.style.fontSize;
				break;
			case 'fontsizeadjust':
				return obj.style.fontSizeAdjust;
				break;
			case 'fontstretch':
				return obj.style.fontStretch;
				break;
			case 'fontstyle':
				return obj.style.fontStyle;
				break;
			case 'fontvariant':
				return obj.style.fontVariant;
				break;
			case 'fontweight':
				return obj.style.fontWeight;
				break;
			case 'height':
				return obj.style.height;
				break;
			case 'left':
				return obj.style.left;
				break;
			case 'length':
				return obj.style.length;
				break;
			case 'letterspacing':
				return obj.style.letterSpacing;
				break;
			case 'lineheight':
				return obj.style.lineHeight;
				break;
			case 'liststyle':
				return obj.style.listStyle;
				break;
			case 'liststyleimage':
				return obj.style.listStyleImage;
				break;
			case 'liststyleposition':
				return obj.style.listStylePosition;
				break;
			case 'liststyletype':
				return obj.style.listStyleType;
				break;
			case 'margin':
				return obj.style.margin;
				break;
			case 'marginbottom':
				return obj.style.marginBottom;
				break;
			case 'marginleft':
				return obj.style.marginLeft;
				break;
			case 'marginright':
				return obj.style.marginRight;
				break;
			case 'margintop':
				return obj.style.marginTop;
				break;
			case 'markeroffset':
				return obj.style.markerOffset;
				break;
			case 'marks':
				return obj.style.marks;
				break;
			case 'maxheight':
				return obj.style.maxHeight;
				break;
			case 'maxwidth':
				return obj.style.maxWidth;
				break;
			case 'minheight':
				return obj.style.minHeight;
				break;
			case 'minwidth':
				return obj.style.minWidth;
				break;
			case 'mozbinding':
				return obj.style.MozBinding;
				break;
			case 'mozopacity':
				return obj.style.MozOpacity;
				break;
			case 'opacity':
				return obj.style.opacity;
				break;
			case 'orphans':
				return obj.style.orphans;
				break;
			case 'outline':
				return obj.style.outline;
				break;
			case 'outlinecolor':
				return obj.style.outlineColor;
				break;
			case 'outlinestyle':
				return obj.style.outlineStyle;
				break;
			case 'outlinewidth':
				return obj.style.outlineWidth;
				break;
			case 'overflow':
				return obj.style.overflow;
				break;
			case 'padding':
				return obj.style.padding;
				break;
			case 'paddingbottom':
				return obj.style.paddingBottom;
				break;
			case 'paddingleft':
				return obj.style.paddingLeft;
				break;
			case 'paddingright':
				return obj.style.paddingRight;
				break;
			case 'paddingtop':
				return obj.style.paddingTop;
				break;
			case 'page':
				return obj.style.page;
				break;
			case 'pagebreakafter':
				return obj.style.pageBreakAfter;
				break;
			case 'pagebreakbefore':
				return obj.style.pageBreakBefore;
				break;
			case 'pagebreakinside':
				return obj.style.pageBreakInside;
				break;
			case 'parentrule':
				return obj.style.parentRule;
				break;
			case 'pause':
				return obj.style.pause;
				break;
			case 'pauseafter':
				return obj.style.pauseAfter;
				break;
			case 'pausebefore':
				return obj.style.pauseBefore;
				break;
			case 'pitch':
				return obj.style.pitch;
				break;
			case 'pitchrange':
				return obj.style.pitchRange;
				break;
			case 'playduring':
				return obj.style.playDuring;
				break;
			case 'position':
				return obj.style.position;
				break;
			case 'quotes':
				return obj.style.quotes;
				break;
			case 'richness':
				return obj.style.richness;
				break;
			case 'right':
				return obj.style.right;
				break;
			case 'size':
				return obj.style.size;
				break;
			case 'speak':
				return obj.style.speak;
				break;
			case 'speakheader':
				return obj.style.speakHeader;
				break;
			case 'speaknumeral':
				return obj.style.speakNumeral;
				break;
			case 'speakpunctuation':
				return obj.style.speakPunctuation;
				break;
			case 'speechrate':
				return obj.style.speechRate;
				break;
			case 'stress':
				return obj.style.stress;
				break;
			case 'tablelayout':
				return obj.style.tableLayout;
				break;
			case 'textalign':
				return obj.style.textAlign;
				break;
			case 'textdecoration':
				return obj.style.textDecoration;
				break;
			case 'textindent':
				return obj.style.textIndent;
				break;
			case 'textshadow':
				return obj.style.textShadow;
				break;
			case 'texttransform':
				return obj.style.textTransform;
				break;
			case 'top':
				return obj.style.top;
				break;
			case 'unicodeBidi':
				return obj.style.unicodeBidi;
				break;
			case 'verticalalign':
				return obj.style.verticalAlign;
				break;
			case 'visibility':
				return obj.style.visibility;
				break;
			case 'voicefamily':
				return obj.style.voiceFamily;
				break;
			case 'volume':
				return obj.style.volume;
				break;
			case 'whitespace':
				return obj.style.whiteSpace;
				break;
			case 'widows':
				return obj.style.widows;
				break;
			case 'width':
				return obj.style.width;
				break;
			case 'wordspacing':
				return obj.style.wordSpacing;
				break;
			case 'zindex':
				return obj.style.zIndex;
				break;
		}
	}
	else
	{//Se n� �do tipo 'n�
		return false;
	}
}


function DOM_setStyle(obj,estilo,valor)
{//Fun�o que altera o valor do estilo de um objeto
//Este objeto deve ser obtido antes, atrav� da fun�o 'DOM_getID()' ou 'DOM_getName()'
	if(obj.nodeType==1)
	{//Se o objeto �do tipo 'n�
		var estilominusculo = estilo.toLowerCase();
		
		switch (estilominusculo)
		{
			case 'azimuth':
				obj.style.azimuth=valor;
				break;
			case 'background':
				obj.style.background=valor;
				break;
			case 'backgroundattachment':
				obj.style.backgroundAttachment=valor;
				break;
			case 'backgroundcolor':
				obj.style.backgroundColor=valor;
				break;
			case 'backgroundimage':
				obj.style.backgroundImage=valor;
				break;
			case 'backgroundposition':
				obj.style.backgroundPosition=valor;
				break;
			case 'backgroundrepeat':
				obj.style.backgroundRepeat=valor;
				break;
			case 'border':
				obj.style.border=valor;
				break;
			case 'borderbottom':
				obj.style.borderBottom=valor;
				break;
			case 'borderbottomcolor':
				obj.style.borderBottomColor=valor;
				break;
			case 'borderbottomstyle':
				obj.style.borderBottomStyle=valor;
				break;
			case 'borderbottomwidth':
				obj.style.borderBottomWidth=valor;
				break;
			case 'bordercollapse':
				obj.style.borderCollapse=valor;
				break;
			case 'bordercolor':
				obj.style.borderColor=valor;
				break;
			case 'borderleft':
				obj.style.borderLeft=valor;
				break;
			case 'borderleftcolor':
				obj.style.borderLeftColorh=valor;
				break;
			case 'borderleftstyle':
				obj.style.borderLeftStyle=valor;
				break;
			case 'borderleftwidth':
				obj.style.borderLeftWidth=valor;
				break;
			case 'borderright':
				obj.style.borderRight=valor;
				break;
			case 'borderrightcolor':
				obj.style.borderRightColor=valor;
				break;
			case 'borderrightstyle':
				obj.style.borderRightStyle=valor;
				break;
			case 'borderrightwidth':
				obj.style.borderRightWidth=valor;
				break;
			case 'borderspacing':
				obj.style.borderSpacing=valor;
				break;
			case 'borderstyle':
				obj.style.borderStyle=valor;
				break;
			case 'bordertop':
				obj.style.borderTop=valor;
				break;
			case 'bordertopcolor':
				obj.style.borderTopColor=valor;
				break;
			case 'bordertopstyle':
				obj.style.borderTopStyle=valor;
				break;
			case 'bordertopwidth':
				obj.style.borderTopWidth=valor;
				break;
			case 'borderwidth':
				obj.style.borderWidth=valor;
				break;
			case 'bottom':
				obj.style.bottom=valor;
				break;
			case 'captionside':
				obj.style.captionSide=valor;
				break;
			case 'clear':
				obj.style.clear=valor;
				break;
			case 'clip':
				obj.style.clip=valor;
				break;
			case 'color':
				obj.style.color=valor;
				break;
			case 'content':
				obj.style.content=valor;
				break;
			case 'counterincrement':
				obj.style.counterIncrement=valor;
				break;
			case 'counterreset':
				obj.style.counterReset=valor;
				break;
			case 'cssfloat':
				obj.style.cssFloat=valor;
				break;
			case 'csstext':
				obj.style.cssText=valor;
				break;
			case 'cue':
				obj.style.cue=valor;
				break;
			case 'cueafter':
				obj.style.cueAfter=valor;
				break;
			case 'onbefore':
				obj.style.onBefore=valor;
				break;
			case 'cursor':
				obj.style.cursor=valor;
				break;
			case 'direction':
				obj.style.direction=valor;
				break;
			case 'display':
				obj.style.display=valor;
				break;
			case 'elevation':
				obj.style.elevation=valor;
				break;
			case 'emptycells':
				obj.style.emptyCells=valor;
				break;
			case 'filter':
				obj.style.filter=valor;
				break;
			case 'font':
				obj.style.font=valor;
				break;
			case 'fontfamily':
				obj.style.fontFamily=valor;
				break;
			case 'fontsize':
				obj.style.fontSize=valor;
				break;
			case 'fontsizeadjust':
				obj.style.fontSizeAdjust=valor;
				break;
			case 'fontstretch':
				obj.style.fontStretch=valor;
				break;
			case 'fontstyle':
				obj.style.fontStyle=valor;
				break;
			case 'fontvariant':
				obj.style.fontVariant=valor;
				break;
			case 'fontweight':
				obj.style.fontWeight=valor;
				break;
			case 'height':
				obj.style.height=valor;
				break;
			case 'left':
				obj.style.left=valor;
				break;
			case 'length':
				obj.style.length=valor;
				break;
			case 'letterspacing':
				obj.style.letterSpacing=valor;
				break;
			case 'lineheight':
				obj.style.lineHeight=valor;
				break;
			case 'liststyle':
				obj.style.listStyle=valor;
				break;
			case 'liststyleimage':
				obj.style.listStyleImage=valor;
				break;
			case 'liststyleposition':
				obj.style.listStylePosition=valor;
				break;
			case 'liststyletype':
				obj.style.listStyleType=valor;
				break;
			case 'margin':
				obj.style.margin=valor;
				break;
			case 'marginbottom':
				obj.style.marginBottom=valor;
				break;
			case 'marginleft':
				obj.style.marginLeft=valor;
				break;
			case 'marginright':
				obj.style.marginRight=valor;
				break;
			case 'margintop':
				obj.style.marginTop=valor;
				break;
			case 'markeroffset':
				obj.style.markerOffset=valor;
				break;
			case 'marks':
				obj.style.marks=valor;
				break;
			case 'maxheight':
				obj.style.maxHeight=valor;
				break;
			case 'maxwidth':
				obj.style.maxWidth=valor;
				break;
			case 'minheight':
				obj.style.minHeight=valor;
				break;
			case 'minwidth':
				obj.style.minWidth=valor;
				break;
			case 'mozbinding':
				obj.style.MozBinding=valor;
				break;
			case 'mozopacity':
				obj.style.MozOpacity=valor;
				break;
			case 'opacity':
				obj.style.opacity=valor;
				break;
			case 'orphans':
				obj.style.orphans=valor;
				break;
			case 'outline':
				obj.style.outline=valor;
				break;
			case 'outlinecolor':
				obj.style.outlineColor=valor;
				break;
			case 'outlinestyle':
				obj.style.outlineStyle=valor;
				break;
			case 'outlinewidth':
				obj.style.outlineWidth=valor;
				break;
			case 'overflow':
				obj.style.overflow=valor;
				break;
			case 'padding':
				obj.style.padding=valor;
				break;
			case 'paddingbottom':
				obj.style.paddingBottom=valor;
				break;
			case 'paddingleft':
				obj.style.paddingLeft=valor;
				break;
			case 'paddingright':
				obj.style.paddingRight=valor;
				break;
			case 'paddingtop':
				obj.style.paddingTop=valor;
				break;
			case 'page':
				obj.style.page=valor;
				break;
			case 'pagebreakafter':
				obj.style.pageBreakAfter=valor;
				break;
			case 'pagebreakbefore':
				obj.style.pageBreakBefore=valor;
				break;
			case 'pagebreakinside':
				obj.style.pageBreakInside=valor;
				break;
			case 'parentrule':
				obj.style.parentRule=valor;
				break;
			case 'pause':
				obj.style.pause=valor;
				break;
			case 'pauseafter':
				obj.style.pauseAfter=valor;
				break;
			case 'pausebefore':
				obj.style.pauseBefore=valor;
				break;
			case 'pitch':
				obj.style.pitch=valor;
				break;
			case 'pitchrange':
				obj.style.pitchRange=valor;
				break;
			case 'playduring':
				obj.style.playDuring=valor;
				break;
			case 'position':
				obj.style.position=valor;
				break;
			case 'quotes':
				obj.style.quotes=valor;
				break;
			case 'richness':
				obj.style.richness=valor;
				break;
			case 'right':
				obj.style.right=valor;
				break;
			case 'size':
				obj.style.size=valor;
				break;
			case 'speak':
				obj.style.speak=valor;
				break;
			case 'speakheader':
				obj.style.speakHeader=valor;
				break;
			case 'speaknumeral':
				obj.style.speakNumeral=valor;
				break;
			case 'speakpunctuation':
				obj.style.speakPunctuation=valor;
				break;
			case 'speechrate':
				obj.style.speechRate=valor;
				break;
			case 'stress':
				obj.style.stress=valor;
				break;
			case 'tablelayout':
				obj.style.tableLayout=valor;
				break;
			case 'textalign':
				obj.style.textAlign=valor;
				break;
			case 'textdecoration':
				obj.style.textDecoration=valor;
				break;
			case 'textindent':
				obj.style.textIndent=valor;
				break;
			case 'textshadow':
				obj.style.textShadow=valor;
				break;
			case 'texttransform':
				obj.style.textTransform=valor;
				break;
			case 'top':
				obj.style.top=valor;
				break;
			case 'unicodeBidi':
				obj.style.unicodeBidi=valor;
				break;
			case 'verticalalign':
				obj.style.verticalAlign=valor;
				break;
			case 'visibility':
				obj.style.visibility=valor;
				break;
			case 'voicefamily':
				obj.style.voiceFamily=valor;
				break;
			case 'volume':
				obj.style.volume=valor;
				break;
			case 'whitespace':
				obj.style.whiteSpace=valor;
				break;
			case 'widows':
				obj.style.widows=valor;
				break;
			case 'width':
				obj.style.width=valor;
				break;
			case 'wordspacing':
				obj.style.wordSpacing=valor;
				break;
			case 'zindex':
				obj.style.zIndex=valor;
				break;
		}
	}
	else
	{//Se n� �do tipo 'n�
		return false;
	}
}

function DOM_criaElemento(local,tag,identificacao,propriedades)
{//Funcao que cria um elemento HTML
/*
local - Objeto que recebera o novo elemento
tag - Nome da tag do novo elemento
identificacao - Usado para o nome e o ID do novo elemento
propriedades - Atributos incluidos no novo elemento
	ex: "href|http://www.google.com.br@style|color:#ff0000;background-color:#ff0"

	propriedades especiais:
	--> html = inclui um conteudo do tipo innerHTML
	--> data = inclui um elemento do tipo Text ou data de um documento XML
*/

	objlocal=DOM_getId(false,local);// document.getElementById(local);
	objnovo=document.createElement(tag);

	if((identificacao)&& (identificacao!=false))
	{
		objnovo.id=identificacao;
		objnovo.name=identificacao;
	}

	if(propriedades)
	{
		propriedades_p=propriedades.split('@');
		propriedades_nl=propriedades_p.length;
	
		for(i=0;i<propriedades_nl;i++)
		{
			propriedade=propriedades_p[i];
			propriedade_p=propriedade.split('|');
			propriedade_nome=propriedade_p[0];
			propriedade_valor=propriedade_p[1];
	
			if(propriedade_nome=='html')
			{
				objnovo.innerHTML=propriedade_valor;
			}
			else
			if(propriedade_nome=='data')
			{
				objnovo.data=propriedade_valor;
			}
			else
			{
				objnovo.setAttribute(propriedade_nome,propriedade_valor);
			}
		}
	}
	objlocal.appendChild(objnovo);

	delete objnovo;
	delete objlocal;
}

function DOM_excluiElemento(idobj)
{
	obj=DOM_getId(false,idobj); //document.getElementById(idobj);
	objpai=obj.parentNode;

	objpai.removeChild(obj);
}