// JavaScript Document
function textCounter(maxlimit,area) {

field = document.getElementById(area);
counter = document.getElementById(area+"_counter");
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
counter.innerHTML=maxlimit-field.value.length;
sz(field);
}

function cnfgdel(gid,type,userid) {
	if ( confirm("Are you sure you want to delete this game?") ) {
		if ( type == 0 ) {
			sendRequest('rmvgame',gid+'|'+userid,'null');
			hide('game_'+gid);
		} else if ( type == 1 ) {
			sendRequest('rmvwgame',gid+'|'+userid,'null');
			hide('wish_'+gid);
		} else if ( type == 2 ) {
			sendRequest('rmvlgame',gid+'|'+userid,'null');
			hide('list_'+gid);
		} else if ( type == 3 ) {
			sendRequest('rmvlgame',gid+'|'+userid,'null');
			var g = gid.split('|');
			window.location = '/games/info.php?id='+g[0];
		}
	}
}

function cnfdel(id,type) {
	if ( confirm("Are you sure you want to delete this "+type+"?") ) {
		if ( type == 'feed' ) {
			sendRequest('rmvfeed',id,'null');
			hide('feed_'+id);
		}

		if ( type == 'comment' ) {
			sendRequest('rmvinlcom',id,'null');
			hide('com_'+id);
		}

		if ( type == 'game request' ) {
			sendRequest('rmvreq',id,'null');
			hide('req_'+id);
		}
		if ( type == 'list' ) {
			urlstr = '/member/code_deletelist.php?id='+id;
			location = urlstr;
		}
	}
}

function SimpleSwap(el){
	if ( el.src=="http://www.vgscore.com/images/cplaying_on.png" ){
		el.src = "/images/cplaying_off.png";
	}  else if ( el.src=="http://www.vgscore.com/images/cplaying_off.png" ) {
		el.src = "/images/cplaying_on.png";
	} else if ( el.src=="http://www.vgscore.com/images/complete_on.png" ){
		el.src = "/images/complete_off.png";
	}  else {
		el.src = "/images/complete_on.png";
	}
}

function hide(id){
	var f = document.getElementById(id);
	f.style.display = "none";
}

function show(id){
	var f = document.getElementById(id);
	f.style.display = "";
	f.visibility = "show";
}

function nl2br(text){
	text = escape(text);
	if(text.indexOf('%0D%0A') > -1){
		re_nlchar = /%0D%0A/g ;
	}else if(text.indexOf('%0A') > -1){
		re_nlchar = /%0A/g ;
	}else if(text.indexOf('%0D') > -1){
		re_nlchar = /%0D/g ;
	}else{
		return text;
	}
	return unescape( text.replace(re_nlchar,'<br />') );
}

function display() {
	var f = document.getElementById('scodes');
	var style = f.style.display;
	if ( style == "none") {
		f.style.display = "";
		f.visibility = "show";
	} else {
		f.style.display = "none";
	}
}

function sz(textArea) {
while (
	textArea.rows > 1 &&
	textArea.scrollHeight < textArea.offsetHeight
){
	textArea.rows--;
}
var h=0;
while (textArea.scrollHeight > textArea.offsetHeight && h!==textArea.offsetHeight)
{
	h=textArea.offsetHeight;
	textArea.rows++;
}
textArea.rows++
}
