function showhide(id){
    if (document.getElementById){
    obj = document.getElementById(id);
		if (obj.style.display == "none"){
		obj.style.display = "";
		} else {
		obj.style.display = "none";
		}
	}
}
bookmark=[];
fila=[];
ifila=0;
isActive = false;
function loadmenu() {
ajax('menu_engine.php','menu','');
}
var ajax = function(url, id,qtd) {
	if(qtd != 'ajaxback' && id != 'sidebar') {
	bookmark[bookmark.length] = url;
	//mypos = bookmarkpos;
	//bookmarkpos++;
	}
	// Usando o id, você pode colocar um carregando
	//document.getElementById('Layer1').style.visibility="visible";
	// Enfileirando a requisição
    fila[fila.length]=[id,url]
	// se a fila atingir o tamanho indicado por qtd, dispara a execucao das requisicoes
    if((ifila+1)==fila.length)
		ajax2();
}
function set_positive_gif(id) {
img = document.getElementById(id)
img.src = 'positivo-green.gif'
}
function set_positive_jpg(id) {
img = document.getElementById(id)
img.src = 'positivo-green.jpg'
}
function show_input(element_index) {
	element_array = new Array(3)
	element_array[0] = new Array('cash','cOK','show_cashbox')
	element_array[1] = new Array('zeny','zOK','show_zenybox')
	element_array[2] = new Array('yggdrasil','yOK','show_yggbox')
	box = document.getElementById(element_array[element_index][0])
	box.style.display = "";
	button = document.getElementById(element_array[element_index][1])
	button.style.display = "";
	button = document.getElementById(element_array[element_index][2])
	button.style.display = "none";
}
function get_yggdrasil() {
var cashvalue = document.getElementById('yggdrasil').value
document.getElementById('yggdrasil').disabled = true
document.getElementById('yOK').disabled = true
ajax('trade_action.php?action=get_yggdrasil&amount='+cashvalue,'corpo','sidebar')
ajax('trade_action.php','corpo','sidebar')
}
function cashedit() {
var cashvalue = document.getElementById('cash').value
document.getElementById('cash').disabled = true
document.getElementById('cOK').disabled = true
ajax('trade_action.php?action=add_cash&value='+cashvalue,'cashcell','sidebar')
ajax('trade_action.php','corpo','sidebar')
}
function zenyedit() {
var cashvalue = document.getElementById('zeny').value
document.getElementById('zeny').disabled = true
document.getElementById('zOK').disabled = true
ajax('trade_action.php?action=add_zeny&value='+cashvalue,'zenycell','sidebar')
ajax('trade_action.php','corpo','sidebar')
}
function itemedit() {
var cashvalue = document.getElementById('item').value
var item_amount = document.getElementById('amount').value
	if(!item_amount) {
	alert('Selecione o item e depois a quantidade para continuar!');
	return false
	}
document.getElementById('item').disabled = true
document.getElementById('iOK').disabled = true
ajax('trade_action.php?action=add_item&item_id='+cashvalue+'&item_amount='+item_amount,'itemcell','sidebar')
ajax('trade_action.php','corpo','sidebar')
}
function getitemamount() {
var cashvalue = document.getElementById('item').value
document.getElementById('item').disabled = true
document.getElementById('iOK').disabled = true
ajax('trade_action.php?action=get_item_amount&item_id='+cashvalue,'itemamount','')
document.getElementById('iOK').disabled = false
}

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 ajax2() {
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",fila[ifila][1],true);
xmlHttp.send('null');
}
function stateChanged() {
	if (xmlHttp.readyState==4) {
	//document.getElementById('botao').disabled = false;
	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;
		eval(xmlHttp.responseText.substr(x, y));
		}
	document.getElementById(fila[ifila][0]).innerHTML=xmlHttp.responseText;
		if(fila[ifila][0] == 'menu') {
		loadtab();
		}
    ifila++
        if(ifila<fila.length)setTimeout("ajax2()",20)
	}
}
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 + "=" + frm.elements[i].value;
	}
	if(frm_name != 'ajaxback') {
		if(http.indexOf('?') > -1) {
		bookmark[bookmark.length] = http+'&'+url+'&xyzpost=0';
		} else {
		bookmark[bookmark.length] = http+'?'+url+'&xyzpost=0';
		}
//	mypos = bookmarkpos;
//	bookmarkpos++;
	}

	POST_xmlhttp.open("POST", http, true);

	POST_xmlhttp.onreadystatechange = function() {
		if (POST_xmlhttp.readyState == 4) {
		document.getElementById('Layer1').style.visibility="hidden";
	//	document.getElementById('botao').disabled = false;
			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 + ' ';
				
		}
	}
	//url = escape(url);
	POST_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	POST_xmlhttp.setRequestHeader("Content-length", url.length);
	POST_xmlhttp.setRequestHeader("Accept-Charset","UTF-8");
	POST_xmlhttp.setRequestHeader("Connection", "close");
	POST_xmlhttp.send(url);  

	return false;
}
function ajaxreturn() {
	if(isActive != true) {
		if(window.confirm('A função "Voltar" do LiveCP ainda está em fase de testes, e pode retornar resultados inesperados. Deseja tentar utilizar esta opção?')) {
		isActive = true;
		} else {
		return false;
		}
	}
	if(bookmark.length >= 2) {
		if(bookmark[bookmark.length-2].indexOf('xyzpost') > -1) {
			if(!confirm('Para voltar para esta pagina será preciso reenviar os dados enviados anteriormente, você deseja continuar?')) {
			return false;
			}
		}
	ajax(bookmark[bookmark.length-2],'corpo','ajaxback');
	bookmark.pop();
	//document.title = bookmark.length;
	} else {
	//document.getElementById('botao').disabled = true;
	}
}

function ajaxupdate() {
ajax(bookmark[bookmark.length-1],'corpo','ajaxback');
}
function loginajax(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').innerHTML='Por favor, aguarde...';
	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) {

			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;
				novo = document.createElement("script")
novo.text = xmlHttp.responseText.substr(x, y);
document.body.appendChild(novo);
			}

			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 + ' ';
				ajax('menu_engine.php','sidebar','null');
				
		}
	}
	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 isNumeric(val)
	{
		if (val.match(/^[0-9]+$/))
		{
			return true;
		}
		else
		{
			alert('Utilize apenas numeros no campo correspondente ao valor!');
			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;
}

