jQuery.fn.fadeToggle = function(s, fn){
  return (this.is(":visible"))
  ? this.fadeOut(s, fn)
  : this.fadeIn(s, fn);
}

function toggle_extra(div_id) {
  $('.extra_'+div_id).fadeToggle();
}

function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}

function voteScript(siteID,siteName) {
	var voteInfo = document.getElementById('show_vinfo');

	voteInfo.innerHTML  = '<form action="./vote.php" method="post" target="_blank">'
		 + '['+siteName+'] Your Account Name: <input type="text" name="vote_account" /> '
		 + ' <input type="hidden" name="vote_id" value="'+siteID+'">'
		 + ' <input type="submit" name="Vote!" value="Vote!">'
		 + '</form>';
}

function convert(id,rate,max,current,points,currency) {
	var current;
	var result_input = document.getElementById('result_'+id);
	var exchange_input = document.getElementById('exchange_'+id);

	if(isNaN(exchange_input.value)) {
		exchange_input.value = 0;
	}

	if(exchange_input.value < 0) {
		exchange_input.value = 0;
	}

	if(exchange_input.value > points) {
		exchange_input.value = points;
	}

	money = Math.floor(rate*exchange_input.value);

	if(money > max) {
		money = Math.floor(max);
		max_value = Math.floor(money/rate);
		exchange_input.value = Math.floor(max_value);
		money = Math.floor(rate*exchange_input.value);
	}
	
	total = Comma(Math.floor(current + money));
	money = Comma(Math.floor(money));

	result_input.innerHTML = 'Exchange: ' + money + ' ' + currency + '<br/>Total: ' + total;
}
