function re() {
var ts = new Date().getTime();
$.get("ajax_refill?t=energy&ts="+ts, function (d){if (d == "1") {$("#energy_i").attr('src','img/bar/100.png');alert('Your energy has been refilled!');}else{alert('Error refilling energy.');}});
}
function rn() {
var ts = new Date().getTime();
$.get("ajax_refill?t=nerve&ts="+ts, function (d){if (d == "1") {$("#nerve_i").attr('src','img/bar/100.png');alert('Your nerve has been refilled!');}else{alert('Error refilling nerve.');}});
}
function ra() {
var ts = new Date().getTime();
$.get("ajax_refill?t=awake&ts="+ts, function (d){if (d != "0") {$("#awake_i").attr('src','img/bar/100.png');alert('Your awake has been refilled for '+d+' points!');}else{alert('Error refilling awake.');}});
}
function showPetList(u) {
$("#petList").html('<img src="img/loading.gif" alt="Loading" />');
$("#petList").load('ajax_pet_list?id='+u);
}
function getRanks() {
$("#ranks").html('<img src="img/loading.gif" alt="Loading" />');
var ts = new Date().getTime();
$("#ranks").load('ajax_get_ranks?ts='+ts);
}
function quotefp(p,t,u) {
$("#reply").focus();
$("#reply").val('Loading Quote . . .');
$.get("ajax_forum?ac=quote&i="+p+"&t="+t, function (d){$("#reply").val("[b][i]Quote by "+u+"[/i]\n"+d+"[/b]\n\n");});
}
function reportfp(p) {
var z = confirm('Are you sure you want to report this post?');
if (z) {
$("#rptBtn"+p).attr('disabled', true);
$("#rptBtn"+p).val('Reported');
$.get("ajax_forum?ac=report&i="+p);
}
}
function updateEditTimerFP() {
var cur = $("#editTime").html();
cur--;
$("#editTime").html(cur);
if (cur < 1) {
}
else {
if (cur <= 30) {
$("#editTime").css('color','#f00');
}
setTimeout("updateEditTimerFP()",1000);
}
}
function copySearchData() {
var data = $('#data').val();
var dataArray = data.split("|");
var theForm = $('#theForm')[0];
if (data == "||||||||||") $('#btn').html('');
else $('#btn').html('[<a href="search?d=' + dataArray[11] + '">delete</a>]');
if ((dataArray[0] != "") && (dataArray[0] != 0)) theForm.uid.value = dataArray[0];
else theForm.uid.value = "";
if ((dataArray[1] != "") && (dataArray[1] != 0)) theForm.user.value = dataArray[1];
else theForm.user.value = "";
if ((dataArray[2] != "") && (dataArray[2] != 0)) theForm.lvl1.value = dataArray[2];
else theForm.lvl1.value = "";
if ((dataArray[3] != "") && (dataArray[3] != 0)) theForm.lvl2.value = dataArray[3];
else theForm.lvl2.value = "";
if ((dataArray[4] != "") && (dataArray[4] != 0)) theForm.money.value = dataArray[4];
else theForm.money.value = "";
if ((dataArray[5] != "") && (dataArray[5] != 0)) theForm.location.value = dataArray[5];
else theForm.location.selectedIndex = 0;
if ((dataArray[6] != "") && (dataArray[6] != -1)) theForm.house.value = dataArray[6];
else theForm.house.value = -1;
if ((dataArray[7] != "") && (dataArray[7] != -1)) theForm.gang.value = dataArray[7];
else theForm.gang.value = -1;
if ((dataArray[8] != "") && (dataArray[8] != 0)) theForm.status.value = dataArray[8];
else theForm.status.selectedIndex = 0;
if ((dataArray[9] != "") && (dataArray[9] != 0)) theForm.gender.value = dataArray[9];
else theForm.gender.selectedIndex = 0;
if ((dataArray[10] != "") && (dataArray[10] != 0)) theForm.attackable.value = dataArray[10];
else theForm.attackable.selectedIndex = 0;
}
function resetSearchForm() {
var theForm = $('#theForm')[0];
theForm.uid.value = "";
theForm.user.value = "";
theForm.lvl1.value = "";
theForm.lvl2.value = "";
theForm.money.value = "";
theForm.location.selectedIndex = 0;
theForm.house.value = -1;
theForm.gang.value = -1;
theForm.status.selectedIndex = 0;
theForm.gender.selectedIndex = 0;
theForm.attackable.selectedIndex = 0;
}
function doSearch() {
$('#seco').html('<br /><br /><center><img src="img/loading.gif" alt="Loading" title="Loading" /></center><br /><br />');
var ts = new Date().getTime();
$.post("ajax_search?ts="+ts, { uid:$("#uid").val(),user:$("#user").val(),level1:$("#lvl1").val(),level2:$("#lvl2").val(),money:$("#money").val(),location:$("#location").val(),gang:$("#gang").val(),house:$("#house").val(),gender:$("#gender").val(),attackable:$("#attackable").val(),status:$("#status").val() }, function(data){ $("#seco").html(data); });
}
function doCrime(i,n) {
if (nerve >= n) {
$("#btn"+i).attr('disabled', true);
$("#rtn").html('<img src="img/loading.gif" alt="Loading . . ." title="Loading" />');
var ts = new Date().getTime();
$.get("ajax_crime?i="+i+"&ts="+ts, function (d){if (d == "2") {document.location='crime';} else if (d == "3") {$("#rtn").html('Can\'t commit crimes while in prison or hospital!');} else if (d != "0") {$("#rtn").html(d);nerve -= n;$("#nerve_i").attr('src','img/bar/'+Math.round(nerve / nerve_max * 100)+'.png');} else {$("#rtn").html('Error commiting crime.');}$("#btn"+i).attr('disabled',false);});
}
else {
$("#rtn").html('You do not have enough nerve for this crime');
}
}
function doPetCrime(i,n,id) {
if (nerve >= n) {
$("#btn"+i).attr('disabled', true);
$("#rtn").html('<img src="img/loading.gif" alt="Loading . . ." title="Loading" />');
var ts = new Date().getTime();
$.get("ajax_pet?id="+id+"&ac=crime&i="+i+"&ts="+ts, 
function (d){
if (d == "2") {location.reload();}
else if (d == "3") {$("#rtn").html('Your pet can\'t commit crimes while in hospital!');}
else if (d != "0") {$("#rtn").html(d);nerve -= n;$("#namt").html(nerve);$("#namt_i").attr('src','img/bar/'+Math.round(nerve / nerve_max * 100)+'.png');}
else {$("#rtn").html('Error commiting crime.');}$("#btn"+i).attr('disabled',false);});
}
else {
$("#rtn").html('Your pet does not have enough nerve for this crime');
}
}
function refillNerve(t) {
if (t==1) {
if (nerve == nerve_max) {
$("#rtn").html('Error refilling nerve.');
$("#nerveBtn").attr('disabled',false);
return 0;
}
}
$("#nerveBtn").attr('disabled',true);
var ts = new Date().getTime();
$.get("ajax_refill?t=nerve&ts="+ts, function (d){
if (d == "1") {
if (t == 1) {nerve=nerve_max;$("#rtn").html('Your nerve has been refilled in exchange for 10 points!');$("#nerveBtn").attr('disabled',false);}
else {$("#nerveBtn").val('Nerve Refilled');}
$("#headpts").html(addCommas(parseInt($("#headpts").html().replace(/,/g, ''))-10));
$("#nerve_i").attr('src','img/bar/100.png');
}
else {
if (t == 2) {$("#nerveBtn").val('Error Refilling Nerve');}
else {$("#rtn").html('Error refilling nerve.');}
$("#nerveBtn").attr('disabled',false);
}
});
}
function refillEnergy() {
if (energy < energy_max) {
disableGymBtns();
var ts = new Date().getTime();
$.get("ajax_refill?t=energy&ts="+ts, function (d){if (d == "1") { $("#rtn").html('Your energy has been refilled in exchange for 10 points!');energy=energy_max;$("#energy_i").attr('src','img/bar/100.png');$("#str").val(energy);$("#def").val(energy);$("#spe").val(energy);$("#eamt").html(energy);$("#headpts").html(addCommas(parseInt($("#headpts").html().replace(/,/g, ''))-10)); } else { $("#rtn").html('Error refilling energy.'); } enableGymBtns(); });
}
}
function refillPetEnergy(i) {
if (energy < energy_max) {
disableGymBtns();
var ts = new Date().getTime();
$.get("ajax_pet?id="+i+"&ac=refillEnergy&ts="+ts, function (d){if (d == "1") { $("#rtn").html('Your pet\'s energy has been refilled in exchange for 5 points!');energy=energy_max;$("#str").val(energy);$("#def").val(energy);$("#spe").val(energy);$("#eamt").html(energy);$("#headpts").html(addCommas(parseInt($("#headpts").html().replace(/,/g, ''))-5)); } else { $("#rtn").html('Error refilling energy.'); } enableGymBtns(); });
}
}
function refillPetNerve(i) {
if (nerve < nerve_max) {
$("#rtn").html('<img src="img/loading.gif" alt="Loading . . ." title="Loading" />');
var ts = new Date().getTime();
$.get("ajax_pet?id="+i+"&ac=refillNerve&ts="+ts, function (d){if (d == "1") { $("#rtn").html('Your pet\'s nerve has been refilled in exchange for 5 points!');nerve=nerve_max;$("#namt").html(nerve);$("#headpts").html(addCommas(parseInt($("#headpts").html().replace(/,/g, ''))-5));$("#namt_i").attr('src','img/bar/100.png'); } else { $("#rtn").html('Error refilling nerve.'); } });
}
}
function refillAwake() {
if (awake < awake_max) {
disableGymBtns();
var ts = new Date().getTime();
$.get("ajax_refill?t=awake&ts="+ts, function (d){if (d != "0") { $("#rtn").html('Your awake has been refilled in exchange for '+d+' points!');awake=awake_max;$("#awake_i").attr('src','img/bar/100.png');$("#headpts").html(addCommas(parseInt($("#headpts").html().replace(/,/g, ''))-parseInt(d))); } else { $("#rtn").html('Error refilling awake.'); } enableGymBtns(); });
}
}
function train(t) {
var a = 0;
var t2 = '';
if (t == 1) {
a = $("#str").val();
t2 = 'str';
}
else if (t == 2) {
a = $("#def").val();
t2 = 'def';
}
else {
a = $("#spe").val();
t2 = 'spe';
}
if ((a >= 1) && (a <= energy)) {
disableGymBtns();
var ts = new Date().getTime();
$.get("ajax_gym_train?t="+t+"&a="+a+"&ts="+ts, function(d){updateGymInfo(t2,d,a,1);});
}
else {
$("#rtn").html("You can't train more energy than you have.");
}
}
function petTrain(t,i) {
var a = 0;
var t2 = '';
if (t == 1) {
a = $("#str").val();
t2 = 'str';
}
else if (t == 2) {
a = $("#def").val();
t2 = 'def';
}
else {
a = $("#spe").val();
t2 = 'spe';
}
if ((a >= 1) && (a <= energy)) {
disableGymBtns();
var ts = new Date().getTime();
$.get("ajax_pet?id="+i+"&ac=train&t="+t+"&a="+a+"&ts="+ts, function(d){updateGymInfo(t2,d,a,2);});
}
else {
$("#rtn").html("You can't train more energy than you have.");
}
}
function updateGymInfo(t,d,a,pet) {
var t2 = '';
enableGymBtns();
d = d.split('|');
if (d[0] == "1") {
if (t == 'str') t2 = 'Strength';
else if (t == 'def') t2 = 'Defense';
else t2 = 'Speed';
$("#"+t+"Amt").html(addCommas(parseInt($("#"+t+"Amt").html().replace(/,/g, ''))+parseInt(d[1])));
if (pet == 2) $("#rtn").html('You trained your pet <b>'+addCommas(a)+'</b> times and gained <b>'+addCommas(d[1])+'</b> '+t2);
else $("#rtn").html('You trained <b>'+addCommas(a)+'</b> times and gained <b>'+addCommas(d[1])+'</b> '+t2);
energy -= a;
awake = d[2];
if (pet != 2) $("#energy_i").attr('src','img/bar/'+Math.round(energy / energy_max * 100)+'.png');
$("#awake_i").attr('src','img/bar/'+Math.round(awake / awake_max * 100)+'.png');
$("#str").val(energy);
$("#def").val(energy);
$("#spe").val(energy);
$("#eamt").html(energy);
}
else if (d[0] == "2") {
if (pet == 2) location.reload();
else document.location='gym';
}
else if (d[0] == "3") {
$("#rtn").html('Can\'t train while in prison or hospital!');
}
else {
$("#rtn").html('Error training!');
}
}
function disableGymBtns() {
$("#rtn").html('<img src="img/loading.gif" alt="Loading . . ." title="Loading" />');
$("#strBtn").attr('disabled', true);
$("#defBtn").attr('disabled', true);
$("#speBtn").attr('disabled', true);
$("#awakeBtn").attr('disabled', true);
$("#energyBtn").attr('disabled', true);
}
function enableGymBtns() {
$("#strBtn").attr('disabled', false);
$("#defBtn").attr('disabled', false);
$("#speBtn").attr('disabled', false);
$("#awakeBtn").attr('disabled', false);
$("#energyBtn").attr('disabled', false);
}
function deleteMail(i) {
closeMail();
$.get("ajax_mail_actions?d="+i, function() { $("#m"+i).fadeOut(500); });
}
function starMail(i) {
$("#starBtn").attr("disabled", true);
$.get("ajax_mail_actions?s="+i, function(data) { $("#starBtn").val(data); });
$("#si"+i).attr("src", "img/star_on.gif");
}
function unstarMail(i) {
$("#starBtn").attr("disabled", true);
$.get("ajax_mail_actions?u="+i, function(data) { $("#starBtn").val(data); });
$("#si"+i).attr("src", "img/star_off.gif");
}
function reportMail(i) {
var z = confirm('Are you sure you want to report this mail?');
if (z) {
$("#reportBtn").attr("disabled", true);
$.get("ajax_mail_actions?r="+i, function() { $("#reportBtn").val('Reported'); });
}
}
function blockUser(i) {
$("#blockBtn").attr("disabled", true);
$.get("ajax_mail_actions?b="+i, function(data) { $("#blockBtn").val(data); });
}
function newMail() {
$("#mcnt").hide();
$("#mreply").show();
scroll(0,0);
$("#uid").val('');
}
function closeMail() {
$("#mreply").hide();
$("#mread").hide();
$("#mlog").hide();
$("#mcnt").show();
scroll(0,0);
}
function replyMail(u,s) {
$("#mreply").show();
$("#uid").val(u);
if (s.substr(0,3) != "Re:") {
s = "Re: "+s;
}
$("#subject").val(s);
$("#reply").focus();
}
function readMail(i,t) {
$("#mcnt").hide();
$("#mread").show();
$("#mlog").show();
$("#mread").html('<img src="img/loading.gif" alt="Loading" title="Loading" /> Loading . . .');
$("#mlog").html('');
$.get('ajax_read_mail?id='+i+'&t='+t,function(d){var dm=d.split('|~|#|~|',2);$("#mread").html(dm[0]);$("#mlog").html(dm[1]);});
scroll(0,0);
if (t != 1) {
$("#b"+i).css("font-weight", "normal");
$("#i"+i).attr("src", "img/msg_old.gif");
$("#i"+i).attr("title", "Read");
}
}
function rateUser(u,r) {
$("#ratingButtons").html('[Rate Up] :: [Rate Down]'); $.get('ajax_rate_user', { u: u, r: r }, function(data) { if (data == '1') { if (r == 'up') { $("#rating")[0].innerHTML++; } else { $("#rating")[0].innerHTML--; } } });
}
function youTube(id) {
	$("#yt"+id).html('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/' + id + '&hl=en&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/' + id + '&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>');
}
function insertBBCode(code1, code2) {
	var txt = $("#reply")[0];
	var bb_start = txt.value.length + code1.length;
	txt.value += code1;
	txt.value += code2;
	txt.selectionStart = bb_start;
	txt.selectionEnd = bb_start;
	$("#reply").focus();
}
function insertSmiley(text) {
        var txt = $("#reply").val();
        txt += ' '+text+' ';
        $("#reply").val(txt);
        $("#reply").focus();
}
var gmailPage = 1;
function showMoreGmails() {
	$("#gmailBtn").hide();
	$("#gmailLoading").show();
	var ts = new Date().getTime();
	$.get("ajax_get_gmails?p="+gmailPage+"&ts="+ts, function (data) { $("#gmailBlock").append(data); $("#gmailBtn").show(); $("#gmailLoading").hide(); });
	gmailPage++;
}
function quote(i) {
        $('#reply').val('use ajax to get this...or parse the page?');
}
function checkForumForm(t) {
	if (t == 1) {
		if ($("#title").val().length < 2) {
			$("#title").focus();
			return false;
		}
	}
	if ($("#reply").val().length < 3) {
		$("#reply").focus();
		return false;
	}
	return true;
}
function parseNotepad() {
	$("#parser").html('<img src="img/loading.gif" alt="Loading . . ." title="Loading" />');
	var ts = new Date().getTime();
	$.post("ajax_parse_notepad?ts="+ts, { msg: $("#reply").val() }, function(data){ $("#parser").html(data); });
}
function saveNotepad() {
	$("#saveBtn").css('border-color', '#f00');
	var ts = new Date().getTime();
	$.post("ajax_save_notepad?ts="+ts, { msg: $("#reply").val() }, function(){$("#saveBtn").css('border-color', '#0f0');setTimeout(function() {$("#saveBtn").css('border-color', '#fff')}, 2000);});
}
function saveContacts() {
	$("#saveBtn").css('border-color', '#f00');
	if (order == "") order = $('#srt').sortable('toArray');
		var aSize = order.length;
		var oID = 0;
		var data = [];
		for (var i=0; i<aSize; ++i) {
			oID = order[i].substr(3);
			data[i] = [$("#id_"+oID).val(), $("#n_"+oID).val(), i];
		}
		var ts = new Date().getTime();
		$.post("ajax_save_contacts?ts="+ts, { 'data[]': data },
		function(){
			$("#saveBtn").css('border-color', '#0f0');
			setTimeout(function() {$("#saveBtn").css('border-color', '#fff')}, 1000);
		});
}
function sendItemShowQty() {
	var val = $("#item").val().split("|")[1];
	if (val > 0 ) {
		$("#cnt").show();
		$("#qty").val(val);
	}
	else {
		$("#cnt").hide();
	}
}
function updateHeader(t,v) {
$("#head"+t).html(v);
}
function toggleAll() {
var inputlist = document.getElementsByTagName("input");
for (i = 0; i < inputlist.length; i++) {
if ( inputlist[i].getAttribute("type") == 'checkbox' ) {
if (inputlist[i].checked) inputlist[i].checked = false
else inputlist[i].checked = true;
}
}
}
function deleteEvent(i) {
$('#i'+i).html('<img src="img/loading.gif" alt="[@]" title="Loading" />');
$.get("ajax_delete_events?id="+i, function(){$('#r'+i).fadeOut(500);$("#total")[0].innerHTML--;});
}
function deleteContact(i, r) {
$('#i'+r).html('<img src="img/loading.gif" alt="[@]" title="Loading" />');
$.get("ajax_delete_contact?id="+i, function(){$('#li_'+r).fadeOut(500);});
}
function checkUser() {
if ($("#user").val() == "") {$("#cumsg").css('color','#f00');$("#cumsg").html('You must enter a username.');}
else { $.get("ajax_check_user?u="+$("#user").val(), function(data){if (data == "1") {$("#cumsg").css('color','#0f0');$("#cumsg").html('Username is available.'); } else {$("#cumsg").css('color','#f00');$("#cumsg").html('Username is already in use.'); } }); }
}
var hex = new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0");
var r=1;
var g=1;
var b=1;
var seq=1;

function rb(id) {
rainbow="#"+hex[r]+hex[g]+hex[b];
$("#rb"+id)[0].style.color = rainbow;
if (seq==6){
b--
if (b==0)
seq=1
}
if (seq==5){
r++
if (r==12)
seq=6
}
if (seq==4){
g--
if (g==0)
seq=5
}
if (seq==3){
b++
if (b==12)
seq=4
}
if (seq==2){
r--
if (r==0)
seq=3
}
if (seq==1){
g++
if (g==12)
seq=2
}
}
function startrb(id) {
setInterval("rb('"+id+"')",80);
}

var buTxt = new Array();
var buDelay = 0;
function bu(id) {
	buDelay++;
	if (buDelay >= 1) {
		buTxt[3] = buTxt[1].substring(0, buDelay - 1) + buTxt[2].substring(buDelay - 1,buDelay) + buTxt[1].substring(buTxt[1].length,buDelay);
		$("#bu"+id).html(buTxt[3]);
	}
	if (buDelay > buTxt[1].length) {
		$("#bu"+id).html(buTxt[1]);
		buDelay = -1;
	}
}
function startbu(id) {
	$("#bu"+id).html($("#bu"+id).html().toLowerCase());
	buTxt[1] = $("#bu"+id).html();
	buTxt[2] = $("#bu"+id).html().toUpperCase();
	setInterval("bu('"+id+"')",200);
}

var hiTxt = new Array();
var hiDelay = new Array();
function hi(id) {
	hiDelay[id]++;
	if (hiDelay[id] >= 1) {
		
		$("#hi"+id).html(hiTxt[id].substring(0,hiDelay[id]-1)+'<span style="color:red">'+hiTxt[id].substring(hiDelay[id]-1,hiDelay[id])+'</span>'+hiTxt[id].substring(hiTxt[id].length,hiDelay[id]));
	}
	if (hiDelay[id] > hiTxt[id].length) {
		hiDelay[id] = -1;
	}
}
function starthi(id) {
	$("#hi"+id).css('color','#fff');
	hiTxt[id] = $("#hi"+id).html();
	hiDelay[id] = 0;
	setInterval("hi('"+id+"')",150);
}


function validateEmail(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1){
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false;
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false;
}
if (str.indexOf(at,(lat+1))!=-1){
return false;
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false;
}
if (str.indexOf(dot,(lat+2))==-1){
return false;
}
if (str.indexOf(" ")!=-1){
return false;
}
return true;
}
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
