function showhide(id){
    if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none"){
      obj.style.display = "";
    } else {
      obj.style.display = "none";
    }
  }
}
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

var xmlHttp;
function ajax(str,str1,str3) {
str2 = str1;
str4 = str3;
document.getElementById('Layer1').style.visibility="visible";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Seu navegador não suporta AJAX!");
return;
}
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",str,true);
xmlHttp.send(str);
}
function stateChanged() {
if (xmlHttp.readyState==4) {
document.getElementById('Layer1').style.visibility="hidden";
	if (xmlHttp.responseText.indexOf("<script type=\"text/javascript\">") > -1) {
				var x = xmlHttp.responseText.indexOf("<script type=\"text/javascript\">") + "<script type=\"text/javascript\">".length;
				var y = xmlHttp.responseText.indexOf("</script>") - x;
novo = document.createElement("script")
novo.text = xmlHttp.responseText.substr(x, y);
document.body.appendChild(novo);
			}
document.getElementById(str2).innerHTML=xmlHttp.responseText;
}

}
function seraph_status() {
ajax('servercheck.php?server=seraph','status_seraph','GET');
}
function thrones_status() {
ajax('servercheck.php','status_thrones','GET');
setTimeout("thrones_status()",400000);
}

//JSPost
function postajax(http, div_name, frm_name) { //função para posts

	var POST_xmlhttp = false;
	var frm = false;
	var url = "";


	try { POST_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { POST_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { POST_xmlhttp = new XMLHttpRequest(); }
	catch (e) { POST_xmlhttp = false; }}}
	if (!POST_xmlhttp) return null;
document.getElementById('Layer1').style.visibility="visible";
	frm = document.getElementById(frm_name);
	url = "frm_name=" + frm_name;
	for (i = 0; i < frm.elements.length; i++) {
		frm.elements[i].disabled = true;
		if (frm.elements[i].type == "checkbox") {
			if (frm.elements[i].checked)
				frm.elements[i].value = 1;
			else
				frm.elements[i].value = 0;
		}
		url = url + "&" + frm.elements[i].name + "=" + escape(frm.elements[i].value);
	}


	POST_xmlhttp.open("POST", http, true);

	POST_xmlhttp.onreadystatechange = function() {
		if (POST_xmlhttp.readyState == 4) {
		document.getElementById('Layer1').style.visibility="hidden";

			for (i = 0; i < frm.elements.length; i++) {
				if (frm.elements[i].type == "checkbox")
					frm.elements[i].checked = false;
				if (frm.elements[i].type == "password")
					frm.elements[i].value = "";
				frm.elements[i].disabled = false;
			}

			if (POST_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">") > -1) {
				var x = POST_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">") + "<script type=\"text/javascript\">".length;
				var y = POST_xmlhttp.responseText.indexOf("</script>") - x;
				eval(POST_xmlhttp.responseText.substr(x, y));
			}

			if (POST_xmlhttp.responseText.indexOf('ALERT|') > -1) {
				var x = POST_xmlhttp.responseText.indexOf('ALERT|') + "ALERT|".length;
				var y = POST_xmlhttp.responseText.indexOf('|ENDALERT') - x;
				window.alert(POST_xmlhttp.responseText.substr(x , y));
			} else
				document.getElementById(div_name).innerHTML = POST_xmlhttp.responseText + ' ';
				
		}
	}
	POST_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	POST_xmlhttp.setRequestHeader("Content-length", url.length);
	POST_xmlhttp.setRequestHeader("Connection", "close");
	POST_xmlhttp.send(url);  

	return false;
}
function checkdata () {
	// Validation functions obtained from:
	// http://www.devshed.com/c/a/JavaScript/Form-Validation-with-JavaScript/7/
	
	// check to see if input is numeric
	function isNumeric(val)
	{
		if (val.match(/^[0-9]+$/))
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
	// check to see if input is alphanumeric
	function isAlphaNumeric(val)
	{
		if (val.match(/^[a-zA-Z0-9]+$/))
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
	// check to see if input is a valid email address
	function isEmailAddress(val)
	{
		if (val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	user = document.formvip.login.value;
	email = document.formvip.email.value;
	nome = document.formvip.nome.value;
	deposito = document.formvip.deposito.value;
	dinheiro = document.formvip.dinheiro.value;
	server = document.formvip.server.value;
	tipo = document.formvip.tipo.value;
	if (!user || user.length < 4 || user.length > 24) {
		alert("Login Invalido.");
		return false;
	}
	if (!nome || nome == "") {
		alert("Digite seu Nome!");
		return false;
	}
	if (!server || server == 0) {
		alert("Escolha o Servidor!");
		return false;
	}
	if (!tipo || tipo == 0) {
		alert("Escolha o Tipo da doação!");
		return false;
	}
	if (!dinheiro || dinheiro == "") {
		alert("Digite o valor da doação!");
		return false;
	}
	if (!email || email.length < 6 || email.length > 60) {
		alert("O email precisa ter entre 6 e 60 caracteres.");
		return false;
	}
	if (!deposito || deposito.length < 2 || deposito.length > 500) {
		alert("Digite corretamente o comprovante da doação!.");
		return false;
	}
	if (!isEmailAddress(email)) {
		alert("Email Invalido");
		return false;
	}
	return true;
}
