var blocks = new Array();
var loadimg = '<img src="images/loading.gif" alt="Loading.." style="margin:auto;display:block;" />';
var loadimg2 = '<img src="images/loading3.gif" alt="Loading.." align="absmiddle" /> ';
var loadimg3 = '<img src="images/loading4.gif" width="43" height="11" alt="" align="absmiddle" /> ';
var loadimg4 = '<img src="images/loading5.gif" align="absmiddle" /> ';
var loadimg5 = '<img src="images/loading6.gif" align="absmiddle" width="64" height="43" /> ';
var successimg = '<img src="images/greentick.png" align="absmiddle" /> ';
var fcheck = 0;

function shoutboxClose(block) {
$('#block_shoutbox').animate({height:0,opacity:0}, 500);
		$.ajax({
			type: "GET",
			url: "js/ajax/shoutbox_close.php",
			async: false,
			error:function(ajaxrequest){
				return false;
			},
			success:function(content){
				return true;
			}
		});
}
function sendpm() {
	
	$('#pmsubmit').attr('disabled', true);
	$('#sentpmstatus').fadeIn();
	$('#sentpmstatus').html(loadimg2 + ' Sending message..');
	var id = $('#pmusername').val();
	var subject = $('#pmsubject').val();
	// var message = $('#pmmessage').val();
	var message = tinyMCE.activeEditor.getContent();
		$.ajax({
			type: "POST",
			url: "js/ajax/sendpm.php",
			data: "username=" + id + "&subject="+subject+"&message="+message,
			async: false,
			error:function(ajaxrequest){
				$('#sentpmstatus').html('<div id="error">Failed</div>');
				return false;
			},
			success:function(content){
				if(content == "Message Sent!") {
					$('#sentpmstatus').html(successimg + content);
					setTimeout(function () {$('#newmessage').hide('normal')}, 4000);
					setTimeout(function () {$('#pmsubject').attr('value','')}, 4500);
					//setTimeout(function () {$('#pmmessage').attr('value','')}, 4500);
					setTimeout(function () {tinyMCE.activeEditor.setContent('')}, 4500);
					setTimeout(function () {$('#pmusername').attr('value','')}, 4500);
				} else {
					$('#sentpmstatus').html(loadimg2 + content);
				}
				setTimeout(function () {$('#pmsubmit').attr('disabled', false)}, 5000);
				setTimeout(function () {$('#pmsubmit').show('normal')}, 5000);
				setTimeout(function () {$('#sentpmstatus').fadeOut()}, 4500);
				setTimeout(function () {$('#sentpmstatus').html('')}, 5000);
				return true;
			}
		});
}
function addthanks(to,from,forr) {
	$('#addthanks').html('Sending thanks..');
		$.ajax({
			type: "POST",
			url: "js/ajax/addthanks.php",
			data: "to="+to+"&from="+from+"&for="+forr,
			async: false,
			error:function(ajaxrequest){
				$('#addthanks').html('Failed');
				return false;
			},
			success:function(content){
				$('#addthanks').html(content);
				setTimeout(function() {
						$('#addthanks').animate({
												opacity:0,
												height:0,
												width:0
												}, 500)
										  }, 1000);
				return true;
			}
		});
}
function addfriend(username,id) {
	$('#addfriendb').attr('disabled', true);
	$('#addfriendb').addClass('addfriend_send');
	$('#addfriendb').attr('value', 'Sending Invitation...');
		$.ajax({
			type: "POST",
			url: "js/ajax/addfriend.php",
			data: "id=" + id,
			async: false,
			error:function(ajaxrequest){
				$('#addfriend').html('<div id="error">Failed</div>');
				return false;
			},
			success:function(content){
				$('#addfriendb').attr('value', content);
				$('#addfriendb').addClass('addfriend_success');
				setTimeout(function() {
										  $('#addfriendb').animate({
																  opacity:0,
																  height:0,
																  width:0
																  }, 500)
										  }, 1000);
				return true;
			}
		});
}
function removefriend(username,id) {
	$('#addfriendb').attr('disabled', true);
	$('#addfriendb').addClass('addfriend_send');
	$('#addfriendb').attr('value', 'Removing...');
		$.ajax({
			type: "POST",
			url: "js/ajax/removefriend.php",
			data: "id=" + id,
			async: false,
			error:function(ajaxrequest){
				$('#addfriend').html('<div id="error">Failed</div>');
				return false;
			},
			success:function(content){
				$('#addfriendb').attr('value', content);
				setTimeout(function() {
										  $('#addfriendb').animate({
																  opacity:0,
																  height:0,
																  width:0
																  }, 500)
										  }, 1000);
				return true;
			}
		});
}
function toggleCheck(fn) {
	aryChk=document.fn;
	for(cptChk=0;cptChk<aryChk.length;cptChk++){
	  elem=aryChk[cptChk]
	  if( (elem.type.lower()=='checkbox') && (elem.checked==false) ){
		elem.checked=true;
	  }
	}
}
function toggleBlock(blockname) {
if(blocks[blockname] == 1) {
$('#'+blockname).slideDown('slow');
blocks[blockname] = 0;
} else {
$('#'+blockname).slideUp('slow');
blocks[blockname] = 1;
}
}
function out(message, channel) {
		document.getElementById('message').value = '';
		$.ajax({
			type: "POST",
			url: "js/ajax/shoutbox.php",
			data: "message=" + encodeURIComponent(message) + "&channel="+channel,
			async: true,
			error:function(ajaxrequest){
				return false;
			},
			success:function(content){
				$('#shoutbox').load('js/ajax/shoutbox.php', {'channel':channel});
				return true;
			}
		});
}
function sponsor_click(lid) {
		$.ajax({
			type: "GET",
			url: "js/ajax/sponsor_click.php?id=" + lid,
			async: false,
			error:function(ajaxrequest){
				return false;
			},
			success:function(content){
				return true;
			}
		});
}
function sponsorClose(block) {
$('#block_sponsor1').animate({height:0,opacity:0}, 500);
		$.ajax({
			type: "GET",
			url: "js/ajax/sponsor_close.php",
			async: false,
			error:function(ajaxrequest){
				return false;
			},
			success:function(content){
				return true;
			}
		});
}






// Misc

function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE 
		var str = document.selection.createRange().text;
		document.forms['submission'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['submission'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['submission'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}


function changeRow(tableRow, highLight) {
if (highLight) {
tableRow.classSave = tableRow.className;
tableRow.className='hover';
} else {
tableRow.className= tableRow.classSave;
}
}
function jumpTo(theUrl) {
document.location.href = theUrl;
}

function firstClear(obj)
{
if(obj.clearThis == undefined)
  {
    obj.value = '';
    obj.clearThis = true;
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}