// JavaScript Document
function fnOpenFlash(swf, id){
	var width = ob(id).style.width.substr(0, ob(id).style.width.length-2);
	var height = ob(id).style.height.substr(0, ob(id).style.height.length-2);
	var so = new SWFObject("swfs/"+swf+".swf", "lightbox", width, height, "8", "#FFF", "transparent");
	so.addParam("WMODE", "transparent");
	//so.addVariable("variavel", valor);
	so.write(id);
}

function ob(id){
	return document.getElementById(id);
}

function fnConexao(args, file, retorno, tipo){
	var req = null;
	
	if (window.XMLHttpRequest){
	
		req = new XMLHttpRequest();
		if (req.overrideMimeType){
			req.overrideMimeType('text/xml');
		}
	} 
	
	else if (window.ActiveXObject){
	
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
		
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	req.onreadystatechange = function() { 
	
		if(req.readyState == 4)	{
			if(req.status == 200) {
				
				if(tipo){
					tipo=tipo.toLowerCase();
					var doc = null;
					if("text"==tipo){
						doc = req.responseText;
					} else if("xml"==tipo){
						doc = req.responseXML;
						//doc2 = req.responseText;
						//alert(doc2);
						//alert(doc.childNodes[0].firstChild.data);
					}
					//alert(retorno);
					if(retorno){
						retorno = retorno + "(doc)";
						eval(retorno);
					}
				}				
			}
		}
	};
	
	req.open("POST", file, true);
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	req.send(args);
}

//Objecto-Ferramenta para os ComboBoxs do filtro do acervo de artigos
var ListUtil = new Object();

//Função para adicionar options aos combos
ListUtil.add = function (oListbox, sName, sValue) {
	
	var oOption = document.createElement("option");
	oOption.appendChild(document.createTextNode(sName));
	if (arguments.length == 3) {
		oOption.setAttribute("value", sValue);
	}
	oListbox.appendChild(oOption);
};

//Remove um Item do ComboBox
ListUtil.remove = function (oListbox, iIndex){
	oListbox.remove(iIndex);
};

//Limpa o ComboBox deixando só um primeiro item, que é uma linha em branco.
ListUtil.clear = function (oListbox) {
	for (var i=oListbox.options.length-1; i >= 0; i--) {
		if (i != 0){
			ListUtil.remove(oListbox, i);
		}
	}
};



//Validando Emails
function fnValidaEmail(emailad){
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return false;
	}
	else {
		return true;
	}
}

//elimina espaços em branco no inicio e no final da string
function trimAll(sString){
	
	var sString = new String(sString);
	
	while (sString.substring(0,1) == " "){
		sString = sString.substring(1, sString.length);
	}
	
	while (sString.substring(sString.length-1, sString.length) == " "){
		sString = sString.substring(0,sString.length-1);
	}
	
	return sString;
	
}