﻿function $(id) {
  return document.getElementById(id);
}

function atualiza(objeto,texto) {
	$(objeto).innerHTML = texto;
}

function createXMLHttpRequest() {
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e){
	}
	try {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
	}
	try {
		return new XMLHttpRequest();
	} catch(e) {
	}
	alert("XMLHttpRequest nao suportado pelo browser");
	return null;
}

function news(arquivo,oObjeto) {
	var xhr = createXMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState==4) { // Request is finished
			if (xhr.status==200) {
				$(oObjeto).innerHTML = xhr.responseText;
			}else{
				$(oObjeto).innerHTML ="";
				//alert("Message returned, but with error status.");
			}
		}
	}
	xhr.open("GET", arquivo, true);
	xhr.send(null);
}

function leia(arquivo,oObjeto) {
	var xhr = createXMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState==4) { // Request is finished
			if (xhr.status==200) {
				$(oObjeto).innerHTML = xhr.responseText;
			}else{
				$(oObjeto).innerHTML ="";
				//alert("Message returned, but with error status.");
			}
		}
	}
	xhr.open("GET", arquivo, true);
	xhr.send(null);
}

function leiaform(arquivo,oObjeto) {
	var xhr = createXMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState==4) { // Request is finished
			if (xhr.status==200) {
				$(oObjeto).innerHTML = xhr.responseText;
			}else{
				$(oObjeto).innerHTML ="";
				//alert("Message returned, but with error status.");
			}
		}
	}
	formvars = '';
	for (i=0;i<document.forms.length;i++) {
		for (j=0;j<document.forms[i].elements.length;j++) {
			if (j==0) {
				if (document.forms[i].elements[j].type=="checkbox") {
					if (document.forms[i].elements[j].checked==true) {
						formvars = formvars + '?' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
					}
				} else if (document.forms[i].elements[j].type=="radio") {
					if (document.forms[i].elements[j].checked==true) {
						formvars = formvars + '?' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
					}
				} else {
					formvars = formvars + '?' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
				}
			} else {
				if (document.forms[i].elements[j].type=="checkbox") {
					if (document.forms[i].elements[j].checked==true) {
						formvars = formvars + '&' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
					}
				} else if (document.forms[i].elements[j].type=="radio") {
					if (document.forms[i].elements[j].checked==true) {
						formvars = formvars + '&' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
					}
				} else {
					formvars = formvars + '&' + document.forms[i].elements[j].name + '=' + document.forms[i].elements[j].value;
				}
			}
		}
	}
  //alert(arquivo+formvars);
	xhr.open("GET", arquivo+formvars, true);
	xhr.send(null);
  setTimeout('highlight()',500);
}

function NovaJanela(url,title) {
	varheight = screen.height - 0;
	varwidth = screen.width - 0;
	mywindow = window.open(url, title, "height="+varheight+", width="+varwidth+", location=no, scrollbars=yes, status=no, toolbar=no, menubar=no");
	mywindow.moveTo(0,0);
}

function AbreJanela(url,title,varwidth,varheight) {
	mywindow = window.open(url, title, "height="+varheight+", width="+varwidth+", location=no, scrollbars=yes, status=no, toolbar=no, menubar=no");
	mywindow.moveTo(50,50);
}
