//Esta funo simula a funo trim para o javascript
//uma funo trim elimina os espaos em branco de uma variavel
String.prototype.trim = function() {
	var x = this;
	x = x.replace(/^/s*(.*)/, "$1");
	x = x.replace(/(.*?)/s*$/, "$1");
	return x;
}


/* FUNO PARA ABRIR POPUP DE EDITOR PARA BANNER */
function openEditor(bnn_id){
	gravaClick(bnn_id);
	wn = window.open('../popup/editor.php?bnn_id='+bnn_id, 'editor', 'width=800, height=650, top=50, left=50, scrollbars=yes');
	wn.focus();
}

function openInfo(prod){
	wn = window.open('../produtos/produtos_popup.php?prod='+prod, 'popupProd'+prod, 'width=800, height=650, top=50, left=50, scrollbars=yes');
	wn.focus();
}

/* FUNCAO PARA ABAS - download */
function gravaClick(bnn_id, funcaoRedirecionamento){
	var xmlhttp = createHttp();
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4){
			//resposta da query ok
			if (funcaoRedirecionamento) {
				funcaoRedirecionamento.call();
			}
			delete xmlhttp;
		}
	}
	xmlhttp.open("POST", "grava_click.php", true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("bnn_id="+bnn_id);
}


function createHttp(){
	//cria objeto de conexo AJAX
	try {var xmlhttp = new XMLHttpRequest();
	} catch(ee) {
		try {var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {var xmlhttp = false;}
		}
	}
	return xmlhttp;
}
