var timeout = 200;
var closetimer = 0;
var ddmenuitem = 0;
var newsitems;
var curritem=0;
var iPause=0;
var ajaxListener = '/com/ajaxListener.cfc';
;(function($){
	$.coldfusion = {};
	$.coldfusion.eachRow = function( query, callback ){
			$.coldfusion.eachRow.defaultIterator(
				query,
				callback
			); 
		return( this );
	};
	$.coldfusion.eachRow.defaultIterator = function( query, callback ){
		var i = 0;
		for (var i = 0 ; i < query.DATA.length ; i++){ 
			(function( rowIndex ){
				var row = {};
 				$.each(
					query.COLUMNS,
					function( index, column ){
						row[ column ] = query.DATA[ rowIndex ][ index ];
					}
				);
 				callback.call( row, rowIndex, row );
 			})( i );
 		}
	};
})( jQuery );
function removePicResult(r) {
	var thistext = $('#uploads').html();
	var thisval = $('#pics').val();
	thisval = thisval.replace(r.image[0],'');
	var this_div = '#' + r.image[0];
	this_div = this_div.replace(/.jpg/g,'');
	this_div = this_div.replace(/.gif/g,'');
	this_div = this_div.replace(/.png/g,'');
	$(this_div).remove();	
	$('#uploads_pending').html(r.image[0] + ' removed');
	$('#pics').val(thisval);
};
function showInfo(str) {
	$('#err').fadeIn('slow').html('<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span> ' + str).addClass('ui-state-highlight').removeClass('ui-state-error');
	window.setTimeout(function(){
		$('#err').fadeOut('slow');
	},2500);
}
function showErr(str) {
	$('#err').html('<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>' + str);
	$('#err').dialog({ title: 'Error!', resizable: false, autoOpen: true, modal: true, buttons: { Ok: function () { $(this).dialog('close'); } } });
}
function checkAvail() {
	var m_name = $('#new_user_name').val();
	if (m_name == '' || m_name.indexOf(Chr(39)) > -1 || m_name.indexOf(Chr(160)) > -1 || m_name.indexOf(Chr(173)) > -1 || m_name.indexOf('"') > -1) {
		$('#err_username').fadeIn("slow").html('<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> You must choose a valid name. No quotes or single quotes.').removeClass('ui-state-highlight').addClass('ui-state-error');
	}
	else {
		$.ajax({ type: 'POST',
	        url: ajaxListener + '?method=checkUserName&returnFormat=plain',
	        data: 'userName=' + m_name,
	        dataType: 'html',
	        success: function (html) {
	        	var result = $.parseJSON(html);
	        	if (result.my_suc == 'success') {
	        		$('#username_dialog').dialog('close').dialog('destroy').remove();
	        		showInfo('Your name has been updated.');
	        		$('#old_username').val(result.m_name);
	        	}
	        	else {
	        		showErr('That Name is taken.');
	        	}	        	
	        },
	        error: function (e) { alert('Error checking for name.'); }
	    });
	}
};
function fillBandAddy() {
	$('#txtBandAddy').val($('#txtBandName').val().replace(/[^a-zA-Z0-9]+/g,''));
	checkBandAddy();	
}
function fillBandAddyO() {
	$('#txtBandAddy').val($('#txtBandName').val().replace(/[^a-zA-Z0-9]+/g,''));
	$('#band_url').html($('#txtBandName').val().replace(/[^a-zA-Z0-9]+/g,''));
}
function checkBandAddy() {
	var bandaddy = $('#txtBandAddy').val();
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=checkBandAddy&returnFormat=plain',
        data: 'bandaddy=' + bandaddy,
        dataType: 'html',
        success: function (html) {
        	var result = $.parseJSON(html);
        	if (result.my_suc == 0) {
        		$('#err').fadeOut("slow");
        		$('#bandaddy_img').fadeIn('slow').attr('src','../images/green_check_mark.gif');
        		$('#txtBandAddy').val(result.bandaddy);
        		$('#band_url').html(result.bandaddy);
        		$('#txtBandAddy').css('border', 'none');
        		$('#valid').val('1');
        	}
        	else {
        		$('#bandaddy_img').fadeOut('slow').attr('src','../images/ts.gif');	
        		showErr('That band URL is already taken, enter a different one.');
        		$('#txtBandAddy').css('border', '1px solid #a82610');
        		$('#valid').val('0');
        		$('#band_url').html(result.bandaddy);
        	}	        	
        },
        error: function (e) { alert('Error checking for name.'); }
    });
};
function checkUserName() {
	var m_name = $('#username').val();
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=checkUserName_reg&returnFormat=plain',
        data: 'userName=' + m_name,
        dataType: 'html',
        success: function (html) {
        	var result = $.parseJSON(html);
        	if (result.my_suc == 0) {
        		$('#err').fadeOut("slow");
        		$('#username_img').fadeIn('slow').attr('src','../images/green_check_mark.gif');	
        		$('#username').css('border', 'none');
        		$('#valid').val('1');
        	}
        	else {
        		$('#username_img').fadeOut('slow').attr('src','../images/ts.gif');
        		$('#username').css('border', '1px solid #a82610');
        		showErr('That Name is already taken.');
        		$('#valid').val('0');
        	}	        	
        },
        error: function (e) { alert('Error checking for name.'); }
    });
};
function addFriend(ID) {
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=addFriend&returnformat=plain',
        data: 'ID=' + ID,        
        success: function (html) {
			alert('Friend request has been made!');         
        },
        error: function (e) { alert('Error adding friend.'); }
    });
};
function addFriend_profile(ID, userid) {
	if (userid == 0) {	
		showLogin();
	}
	else {
		addFriend(ID);
	}
};
function blockUser(ID) {
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=blockUser&returnformat=plain',
        data: 'ID=' + ID,        
        success: function (html) {
			alert('User has been blocked.');      
        },
        error: function (e) { alert('Error blocking.'); }
    });
};
function removeFriend(ID) {
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=removeFriend&returnformat=plain',
        data: 'ID=' + ID,        
        success: function (html) {
			alert('Friend has been removed.');       
        },
        error: function (e) { alert('Error removing friend.'); }
    });
};
function inviteFriends() {
	var friendlist = $('#inviteFriends').val();
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=inviteFriends&returnformat=plain',
        data: 'friendList=' + friendlist,        
        success: function (html) {
			alert('Your friends have been invited! If they sign up, they will be added to your friends list.');   
			$('#myInvite').dialog('close').dialog('destroy').remove();
		},
        error: function (e) { alert('Error inviting friends.'); }
    });	
};
function remBlock_boards(ID) {
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=remBlockBoards&returnformat=plain',
        data: 'ID=' + ID,        
        success: function (html) {
			$('.post_hidden').removeClass('post_hidden').addClass('post_wrapper');
			$('.block').remove();
			alert('block removed.');   
        },
        error: function (e) { alert('Error removing block.'); }
    });
};
function markUnsafe(ID) {
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=markUnsafe&returnformat=plain',
        data: 'ID=' + ID,        
        success: function (html) {
			alert('Thread marked unsafe.');
        },
        error: function (e) { alert('Error removing block.'); }
    });
};
function checkReg() {
	var err_msg = '';
	if ($('#username').val() == '' || $('#valid').val('1') == 1) {
		err_msg += 'Please Fill in a VALID/Unused username.<br />';
	} 
	if ($('#password').val() == '' || $('#password').val() != $('#password_repeat').val()) {
		err_msg += 'Please enter a password, both passwords must match.<br>';
	}
	if ($('#email').val() == '') { 
		err_msg += 'Please enter a valid email address.<br />';
	}
	if ($('input[@name="gender"]:checked').val() == undefined) { 
		err_msg += 'Gender is required.<br />';
	}
	if ($('#captcha').val() == '') {
		err_msg += 'You must enter the captcha verification code in the bottom left of the form to match the image.<br />';
	}
	if ($('#valid').val() == 0) {
		err_msg +='The Username you picked is taken.<br />';
	}
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=checkCaptcha&returnformat=plain',
        data: 'captcha=' + $('#captcha').val().toUpperCase() + '&captchaHash=' + $('#captchaHash').val(),        
        async: false,
        success: function (html) {
			var result = $.parseJSON(html);
			if (result.my_suc == 0) {
				err_msg += 'Incorrect captcha code.<br />';
			}
		},
        error: function (e) { err_msg += 'Error validation captcha.<br />'; }
    });	
	if (err_msg.length) {
		showErr(err_msg);
		return false;
	}
	else {
		return true;
	}
};
function checkRegBand(thisUsername) {
	var err_msg = '';
	if (thisUsername == 0) {
		if ($('#username').val() == '' || $('#valid').val('1') == 1) {
			err_msg = err_msg + 'Please Fill in a VALID/Unused username.<br />';
		} 
		if ($('#password').val() == '' || $('#password').val() != $('#password_repeat').val()) {
			err_msg  = err_msg + 'Please enter a password, both passwords must match.<br>';
		}
		if ($('#email').val() == '') { 
			err_msg  = err_msg + 'Please enter a valid email address.<br />';
		}
		if ($('input[@name="gender"]:checked').val() == undefined) { 
			err_msg  = err_msg + 'Gender is required.<br />';
		}
	}
	if ($('#txtBandName').val() == '') { 
		err_msg  = err_msg + 'Please enter a band name.<br />';
	}
	if ($('#this_file2').val() != '' && $('#txtmp3name').val() == '') {
		err_msg  = err_msg + 'You must enter a name for the mp3 you are about to upload.<br />';
	}
	if ($('#this_file1').val() != '' && $('#txtalbumname').val() == '') {
		err_msg  = err_msg + 'If you enter an album name if you upload a song Even "Demo" will do.<br />';
	}
	if ($('#captcha').val() == '') {
		err_msg  = err_msg + 'You must enter the captcha verification code in the bottom left of the form to match the image.<br />';
	}
	if ($('#valid').val() == 0) {
		err_msg = err_msg + 'The Username or Band URL you picked is taken.<br />';
	}
	$.ajax({ type: 'POST',
        url: ajaxListener + '?method=checkCaptcha&returnformat=plain',
        data: 'captcha=' + $('#captcha').val().toUpperCase() + '&captchaHash=' + $('#captchaHash').val(),        
        async: false,
        success: function (html) {
			var result = $.parseJSON(html);
			if (result.my_suc == 0) {
				err_msg += 'Incorrect captcha code.<br />';
			}
		},
        error: function (e) { err_msg += 'Error validation captcha.<br />'; }
    });	
	if (err_msg.length) {
		showErr(err_msg);
		return false;
	}
	else {
		return true;
		$('#thiserr').focus();
		$('#btn').prop('disabled',false).val('Uploading...');
		$('#wait').fadeIn('slow');
	}
};
function addShows(ID) {
	var w = $(window).width();
	var h = $(window).height();
	var popW = 420, popH = 700;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../com/views/view_addshow.cfm?bandid=' + ID, 'shows', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function addUpdates(ID) {
	var w = $(window).width();
	var h = $(window).height();
	var popW = 420, popH = 700;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../com/views/view_addupdates.cfm?bandid=' + ID, 'shows', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function changeTab(tab) {
	$('#tabs_cp').tabs('select', tab);	
};
function addReviews() {
	var w = $(window).width();
	var h = $(window).height();
	var popW = 435, popH = 675;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../com/views/view_reviews.cfm', 'shows', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function showPost(ID,ads) {
	if (ads == 0) {
		$('#r_' + ID).fadeIn('slow').removeClass('post_hidden').addClass('post_wrapper');
		$('#block_' + ID).remove();
	}
	else {
		$('#r_' + ID).fadeIn('slow').removeClass('post_hidden').addClass('post_wrapper_ads');
		$('#block_' + ID).remove();
	} 
};
function switchAlbum() {
	var ID = $('#album_listing').val();
	if (ID == '') {
		alert('Please choose an album');
	}
	else {
		$('#photo_album_wrapper').html('').load('../com/views/view_changealbum.cfm?id=' + ID).slideDown('normal');
		$('#insert_pics').show();
	}
};
function switchAlbum_saved() {
		$('#saved_photo_album_wrapper').html('').load('../com/views/view_savedalbum.cfm').slideDown('normal');
		$('#insert_pics_saved').show();
};

function replyComment(id) {
	var thisid = '#respond_div_' + id;
	$(thisid).fadeIn("slow");
};
$.fn.insertAtCaret = function (myValue) { return this.each(function(){ if (document.selection) { this.focus(); sel = document.selection.createRange(); sel.text = myValue; this.focus(); } else if (this.selectionStart || this.selectionStart == '0') { var startPos = this.selectionStart; var endPos = this.selectionEnd; var scrollTop = this.scrollTop;
                this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos,this.value.length);
                this.focus();
                this.selectionStart = startPos + myValue.length;
                this.selectionEnd = startPos + myValue.length;
                this.scrollTop = scrollTop;
        } else {
                this.value += myValue;
                this.focus();
        }
	});
};
function DoSmilie(addSmilie) {$('#message').insertAtCaret(addSmilie);return;}
function DoPrompt(action) {	
	if (action == "bold") {	var thisBold = prompt("Enter the text that you wish to make bold.", "");var boldUBBCode = "[B]"+thisBold+"[/B]";$('#message').insertAtCaret(boldUBBCode);return;}	
	if (action == "italics") {var thisItal = prompt("Enter the text that you wish to italicize.", "");var italUBBCode = "[I]"+thisItal+"[/I]";$('#message').insertAtCaret(italUBBCode).focus();	return;}
	if (action == 'lt') {$('#message').insertAtCaret('&lt;').focus();}
	if (action == 'gt') {$('#message').insertAtCaret('&gt;').focus();}
};
function x () {return;};
function ajax_paging_albums(id,album,startrow, maxrows, ceiling, fun) {
	var Floor = 1, maxpages = 20, currentpage = Math.ceil(startrow / maxrows),lastpage = Math.ceil(ceiling / maxrows),FromLoop = Floor,toLoop = lastpage;
	if ((FromLoop + toLoop - 1) > maxpages) {if (currentpage > Math.ceil(maxpages/2)) {	FromLoop = Math.ceil((startrow/maxrows) - maxpages/2);}	toLoop = FromLoop + maxpages - 1;}if (lastpage < toLoop) {toLoop = lastpage;}
	var paging = '';	
	if (startrow > 1) {	paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + album + ',1,' + maxrows + ',' + ceiling + ');">&lt;&lt;</a>&nbsp;';}
	if (eval(startrow - maxrows) > Floor) {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + album + ',' + Math.ceil(eval(startrow - maxrows)) + ',' + maxrows + ',' + ceiling + ');">&lt;</a>&nbsp;';}
	for (pointer = FromLoop; pointer <= toLoop; pointer++) {if (currentpage == pointer) {paging = paging + '<span class="pointer">[' + pointer + ']</span>&nbsp;';}	else {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + album + ',' + Math.ceil(eval((pointer - 1) * (maxrows  - 1))  + pointer) + ',' + maxrows + ',' + ceiling + ');">' + pointer + '</a>&nbsp;';	}	} 
	if (eval(startrow + maxrows) < ceiling) {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + album + ',' + Math.ceil(eval(startrow + maxrows)) + ',' + maxrows + ',' + ceiling + ');">&gt;</a>&nbsp;';	}
	if (currentpage != lastpage) {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + album + ',' + Math.ceil(eval((lastpage - 1) * maxrows + 1)) + ',' + maxrows + ',' + ceiling + ');">&gt;&gt;</a>&nbsp;';}	
	return paging;
};
function ajax_paging(id, startrow, maxrows, ceiling, fun) {
	var Floor = 1,maxpages = 10,currentpage = Math.ceil(startrow / maxrows),lastpage = Math.ceil(ceiling / maxrows),FromLoop = Floor,toLoop = lastpage;
	if ((FromLoop + toLoop - 1) > maxpages) {if (currentpage > Math.ceil(maxpages/2)) {	FromLoop = Math.ceil((startrow/maxrows) - maxpages/2);}	toLoop = FromLoop + maxpages - 1;}
	if (lastpage < toLoop) {toLoop = lastpage;}
	var paging = '';
	if (startrow > 1) { paging = paging + '<a href="javascript:get' + fun + '(' + id + ',1,' + maxrows + ',' + ceiling + ');">&lt;&lt;</a>&nbsp;';}
	if (eval(startrow - maxrows) > Floor) {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + Math.ceil(eval(startrow - maxrows)) + ',' + maxrows + ',' + ceiling + ');">&lt;</a>&nbsp;';}
	for (pointer = FromLoop; pointer <= toLoop; pointer++) {if (currentpage == pointer) {paging = paging + '<span class="pointer">[' + pointer + ']</span>&nbsp;';}else {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + Math.ceil(eval((pointer - 1) * (maxrows  - 1))  + pointer) + ',' + maxrows + ',' + ceiling + ');">' + pointer + '</a>&nbsp;';	}} 
	if (eval(startrow + maxrows) < ceiling) {paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + Math.ceil(eval(startrow + maxrows)) + ',' + maxrows + ',' + ceiling + ');">&gt;</a>&nbsp;';}
	if (currentpage != lastpage) {	paging = paging + '<a href="javascript:get' + fun + '(' + id + ',' + Math.ceil(eval((lastpage - 1) * maxrows + 1)) + ',' + maxrows + ',' + ceiling + ');">&gt;&gt;</a>&nbsp;';	}	
	return paging;
};
function Mod(X, Y) { return X - Math.floor(X / Y) * Y;};
function openWindow(url) {
	var w = $(window).width(),h = $(window).height(),popW = 620, popH = 400,leftPos = (w-popW)/2, topPos = (h-popH)/2;
	if (url == 'friendlist.cfm') {pagename = 'friendlist';}
	else if (url == 'viewcurrent.cfm') {pagename = 'currentusers';}
	else {pagename = 'currentusers'}
	popupWin = window.open(url, pagename, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function openPic(url,popW,popH) {
	var w = $(window).width(),h = $(window).height(),leftPos = (w-(popW+10))/2, topPos = (h-(popH+10))/2;
	popupWin = window.open(url, 'picture', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function messageWindow() {
	var w = $(window).width(),h = $(window).height(),popW = 555, popH = 475, leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../boards/mailbox.cfm', 'messages', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function composeWindow(id, subject) {
	var w = $(window).width(), h = $(window).height(), popW = 555, popH = 300, leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../boards/private.cfm?id=' + id, 'new_page', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function composeWindowNew() {
	var w = $(window).width(), h = $(window).height(), popW = 555, popH = 300, leftPos = (w-popW)/2, topPos = (h-popH)/2;
	popupWin = window.open('../boards/private.cfm?new=true', 'new_page', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
	popupWin.focus();
};
function insertPicComments() {
	$('.insertPic').slideToggle('slow');
};
function insertLinkComments() {
	$('.insertURL').slideToggle('slow');		
};
function insertPicCommentsAction() {
	var currentMessage = $('#This_Message').val().replace('Yell @ Friends','');
	var thisURL = $('#image_url').val();
	if (thisURL != null && thisURL != '' && thisURL != 'http://') {
		var urlUBBCode = "[img]"+thisURL+"[/img]";		
		revisedMessage = currentMessage+urlUBBCode;
		$('#This_Message').val(revisedMessage);
		$('.insertPic').val('http://').fadeOut('slow');
	}
	else {
		alert("You Must Enter a URL");
	}
};
function insertPicCommentsAction() {
	var currentMessage = $('#This_Message').val().replace('Yell @ Friends','');
	var thisURL = $('#image_url').val();
	if (thisURL != null && thisURL != '' && thisURL != 'http://') {
		var urlUBBCode = "[img]"+thisURL+"[/img]";		
		revisedMessage = currentMessage+urlUBBCode;
		$('#This_Message').val(revisedMessage);
		$('#image_url').val('http://').fadeOut('slow');
	}
	else {
		alert("You Must Enter a URL");
	}
};
function insertGoogleImage(thisURL) {
	var currentMessage = $('#message').val();
	if (thisURL != null && thisURL != '' && thisURL != 'http://') {
		var urlUBBCode = "\n[img]"+thisURL+"[/img]";		
		revisedMessage = currentMessage+urlUBBCode;
		$('#message').val(revisedMessage).focus();
	}
	else {
		alert("You Must Enter a URL");
	}
};
function insertLinkCommentsAction() {
	var currentMessage = $('#This_Message').val().replace('Yell @ Friends','');
	var thisURL = $('#url').val();
	if (thisURL != null && thisURL != '' && thisURL != 'http://') {
		var urlUBBCode = "[a]"+thisURL+"[/a]";		
		revisedMessage = currentMessage+urlUBBCode;
		$('#This_Message').val(revisedMessage);
		$('#url').val('http://').slideToggle('slow');	
	}
	else {
		alert("You Must Enter a URL");
	}		
};
function doQuote_js(id,by,r_id) {
	var revisedMessage;
	var currentText = $('#message').val();
	var this_id = '#reply' + r_id;
	var currentMessage = $(this_id).html();
	currentMessage = currentMessage.cleanTopic();
	var quoteUBBCode = '[quote][b]Originally posted by: <a href=view_profile.cfm?id=' + id + '>' + by + '</a>[/b]' + '\n' + '\n';
	if (currentText != ''){
		revisedMessage =  currentText + '\n' + '\n' + quoteUBBCode + currentMessage + '[/quote]';
	} else {
		revisedMessage =  currentText + quoteUBBCode + currentMessage + '[/quote]';	
	}
	$('#message').val(revisedMessage.trim()).focus();
	return;
};
String.prototype.cleanTopic = function() {
	var currentMessage = this;
	currentMessage = currentMessage.replace(/<br>/g, '\n');
	currentMessage = currentMessage.replace(/ class="topic_img"/g, '');
	currentMessage = currentMessage.replace(/ style="(.+)"\s/gi, ' ');
	currentMessage = currentMessage.replace(/" border="0/gi, '').trim();
	currentMessage = currentMessage.replace(/" width="15" align="absmiddle" height="15/gi,'');
	currentMessage = currentMessage.replace(/&nbsp;&nbsp;&nbsp;&nbsp;/g, '\t');
	return currentMessage;	
};
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.count = function(substr) {
	var thisReg = new RegExp(substr,'gi');
	try {
		var matches = this.match(thisReg);
		var count = matches.length;
	}
	catch(e) {
		var count = 0;
	}
	return count;
};
function Chr(AsciiNum) {
	return String.fromCharCode(AsciiNum);
};
function doTopicQuote_js(id,by,r_id) {
	var revisedMessage;
	var currentText = $('#message').val();
	var this_id = '#topic' + r_id;
	var currentMessage = $(this_id).html();
	currentMessage = currentMessage.cleanTopic();
	var quoteUBBCode = '[quote][b]Originally posted by: <a href=view_profile.cfm?id=' + id + '>' + by + '</a>[/b]' + '\n' + '\n';
	if (currentText != ''){
		revisedMessage =  currentText + '\n' + '\n' + quoteUBBCode + currentMessage + '[/quote]';
	} else {
		revisedMessage =  currentText + quoteUBBCode + currentMessage + '[/quote]';	
	}
	$('#message').val(revisedMessage.trim()).focus();
	return;
};
function doEdit_reply(id) {	
	document.PostTopic.methodtypeurl.value = 'edit';
	var this_id = '#reply' + id;
	var currentMessage = $(this_id).html().trim().replace('  ',' ');
	$('#reply_id').val(id);
	currentMessage = currentMessage.cleanTopic();
	$('#message').val(currentMessage.trim()).focus();
	document.PostTopic.Submit.value = 'Edit Reply';
	$('#message').css('background','#e7adad url(../../images/innerShadowAlpha.png) no-repeat top left');
	$('#qRep').html('EDIT REPLY');
	$('#subject_div').hide();
};
function doEdit_topic(id) {	
	document.PostTopic.methodtypeurl.value = 'editTopic';
	var this_id = '#topic' + id;
	var currentMessage = $(this_id).html();
	$('#topic_id').val(id);
	currentMessage = currentMessage.cleanTopic();
	$('#message').val(currentMessage.trim());
	document.PostTopic.Submit.value = 'Edit Topic';
	document.PostTopic.Message.focus();
	$('#message').css('background','#e7adad url(../../images/innerShadowAlpha.png) no-repeat top left');
	$('#qRep').html('EDIT TOPIC');
	$('#subject_div').show();
};
function validateTopic() {
	var currentMessage = $('#message').val();
	if (currentMessage.count('<') != currentMessage.count('>')) {
		alert('Invalid HTML. Please close all tags.');
		return false;
	}
	else if (currentMessage.count('<marquee') != currentMessage.count('</marquee')) {
		alert('Unclosed marquee tag');
		return false;
	}
	else if (currentMessage.indexOf('[b]') > -1 && currentMessage.indexOf('[/b]') < 0) {
		currentMessage = currentMessage + '[/b]';
		$('#message').val(currentMessage);
		return true;
	}
	else if (currentMessage.indexOf('[i]') > -1 && currentMessage.indexOf('[/i]') < 0) {
		currentMessage = currentMessage + '[/i]';
		$('#message').val(currentMessage);
		return true;
	}
	else if (currentMessage.indexOf('<b>') > -1 && currentMessage.indexOf('</b>') < 0) {
		currentMessage = currentMessage + '</b>';
		$('#message').val(currentMessage);
		return true;
	}
	else if (currentMessage.indexOf('<marquee') > -1 && currentMessage.indexOf('</marquee') < 0) {
		currentMessage = currentMessage + '</marquee>';
		$('#message').val(currentMessage);
		return true;
	}
	else if (currentMessage.indexOf('<i>') > -1 && currentMessage.indexOf('</i>') < 0) {
		currentMessage = currentMessage + '</i>';
		$('#message').val(currentMessage);
		return true;
	}
	else if (currentMessage.length == 0 && num_uploads > 0) {
		alert('When uploading images, you still must enter a message.');
		return false;
	}
};
function growComment(obj) {
		$(obj).val('');
		$(obj).css('color','#000');
};
function jsddm_open() {  
	jsddm_canceltimer();
  	jsddm_close();
  	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
};
function jsddm_close() {  
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
	}
};
function hover_highlight() {  
	$(this).css('background', '#fff');
};
function hover_highlight_off() {  
	$(this).css('background', '#efefef');
};
function showThis(obj) {
	var this_obj = '#' + obj;
	$(obj).slideToggle('slow');	
};
function toggleUser(id) {
	var this_user = '#user_div' + id;
	$(this_user).slideToggle('fast');
};
function insertQuote() {
	var thisQuote = $('#quoteBox').val();
	if (thisQuote != null && thisQuote != '' && thisQuote != 'http://') {
		var urlUBBCode = '\n'+ '[quote]' + thisQuote + '[/quote]';		
		$('#message').insertAtCaret(urlUBBCode);
	}
	else {
		alert("You Must Enter a quote");
	}
};
function cleanPost(str) {
	currentMessage = currentMessage.replace(/<br>/g, '\n');
	currentMessage = currentMessage.replace(/ class="topic_img"/g, '');
	currentMessage = currentMessage.replace(/ style=""/g, '');
	currentMessage = currentMessage.replace(/<br>/gi, '\n');
	currentMessage = currentMessage.replace(/<img(.+)src="?(.+)">/gi, '[img]$2[/img]');
};
function insertLink() {	
	var thisQuote = $('#linkBox').val();
	if (thisQuote != null && thisQuote != '' && thisQuote != 'http://') {
		var urlUBBCode = '\n'+ '[a]' + thisQuote + '[/a]';		
		$('#message').insertAtCaret(urlUBBCode);
	}
	else {
		alert("You Must Enter a link");
	}
};
function insertPicture() {
	var thisQuote = $('#imageBox').val();
	if (thisQuote != null && thisQuote != '' && thisQuote != 'http://') {
		var urlUBBCode = '\n'+ '[img]' + thisQuote + '[/img]';		
		$('#message').insertAtCaret(urlUBBCode);
	}
	else {
		alert("You Must Enter a image");
	}
};
function insertPictureAlbum(thisQuote) {
	var urlUBBCode = '\n' + '[img]' + thisQuote + '[/img]';		
	$('#message').insertAtCaret(urlUBBCode);
};
function jsddm_timer(){  closetimer = window.setTimeout(jsddm_close, timeout);};
function jsddm_canceltimer(){  if(closetimer) {  window.clearTimeout(closetimer); closetimer = null;}};
function left(str, n) {if (n <= 0) {return "";}else if (n > String(str).length) {return str;}else { return String(str).substring(0,n);}};
function resizeImg(max_width, selector) { 	
	$(selector).each(function(){var width = $(this).width();var height = $(this).height();if (width > max_width) {var ratio = (height / width );var new_width = max_width;var new_height = (new_width * ratio);$(this).height(new_height).width(new_width);}});
};
function showTopicPost(forum_id, forum_title) {
	$(document.body).append('<div id="topic_dialog" title="Post New Topic"></div>');
	if (forum_id > 0) {
		$('#topic_dialog').html('').load('/com/dialogs/dialog_topic.cfm?forum_id=' + forum_id).dialog({ autoOpen: true, modal: true, width:1000, height: 600 });
	}
	else {
		$('#topic_dialog').html('').load('/com/dialogs/dialog_topic.cfm').dialog({ autoOpen: true, modal: true, width:1000, height: 600 });
	}	
	if (typeof myTimeout != 'undefined') {
		window.clearTimeout(myTimeout);
	}
};
function showGoogleImages() {
	$(document.body).append('<div id="google_image_dialog" title="Insert Google Image"></div>');
	$('#google_image_dialog').load('/com/dialogs/dialog_googleimage.cfm').dialog({ autoOpen: true, modal: true, width:600, height: 510, buttons: { Done: function () { $(this).dialog('close'); } } });
};
function showEmoticons() {
	$(document.body).append('<div id="emoticon_dialog" title="Insert Emoticon"></div>');
	$('#emoticon_dialog').load('/com/dialogs/dialog_emoticons.cfm').dialog({ autoOpen: true, modal: true, width:700, height: 510, buttons: { Done: function () { $(this).dialog('close'); } } });
};
function showAlbumImages() {
	$(document.body).append('<div id="photo_album_dialog" title="Insert Photo Album Image"></div>');
	$('#photo_album_dialog').load('/com/dialogs/dialog_photoalbum.cfm').dialog({ autoOpen: true, modal: true, width:300, height:540, buttons: { Done: function () { $(this).dialog('close'); } } });
};
function showAlbumImages_saved() {
	$(document.body).append('<div id="saved_photo_dialog" title="Insert Saved Image"></div>');
	$('#saved_photo_dialog').load('/com/dialogs/dialog_savedimage.cfm').dialog({ autoOpen: true, modal: true, width:300, height:540, buttons: { Done: function () { $(this).dialog('close'); } } });
};
function showInvite() {
	var this_str = 'Enter email addresses of people to invite (separated by commas). If they join, <strong>they will automatically be added to your friendlist</strong>.<br />';
	this_str += '<textarea style="width:300px;height:175px;" id="inviteFriends" class="this_input"></textarea><br /><input class="comment_btn" value="Invite Friends!" type="button" id="inviteButton">';
	$(document.body).append('<div id="myInvite" title="Invite your friends!"></div>').css('text-align','center');
    $('#myInvite').html(this_str).dialog({ width: 460, height: 300, autoOpen: true, modal: true });
    $('#inviteButton').bind('click', inviteFriends);
};
function goPrivate(id) {
	opener.location.href = 'view_profile.cfm?id=' + id;
};
function changeTab(tab) {
	$('#tabs').tabs('select', tab);
};
function changeCPTab(tab) {
	$('#tabs_cp').tabs('select', tab);
};
var jGoogleImage = function() { 
  $('#this_image .search_control').jGoogle({
    searchString: $("#google_search_text").val(),
    callbackKeep: doSomethingWithImage
  });
};  
var doSomethingWithImage = function(url) {        
 		insertGoogleImage(url);
};
function rem(id) {
	var this_id = '#top_friends #' + id;
	$(this_id).remove();
};
function showLogin() {
	$('#loginDiv').fadeIn('slow');
	window.setTimeout(hideLogin, 10000);
};
function hideLogin() {
	$('#loginDiv').hide('slow');
};
function openPlaylist() {
	var url='/music/playlist.cfm';
	var w = $(window).width();
	var h = $(window).height();
	var popW =688, popH = 235;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	pagename = 'playlist';
	popupWin = window.open(url, pagename, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,alwaysRaised=yes,titlebar=no,copyhistory=no,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
    popupWin.focus();
};
function removeAccents(str){
    return str;
}
document.onclick = jsddm_close;
$(document).ready(function(){  
	$('#jsddm > li').hoverIntent(jsddm_open,  jsddm_timer);
	$("#topic_dialog").dialog({ autoOpen: false, modal: true, width:940 });
	$("#song_dialog").dialog({ autoOpen: false, modal: true, width:400 });
	$('.hover').bind('mouseover', hover_highlight);
	$('.hover').bind('mouseout', hover_highlight_off);
	$('#posting_toolbar div').bind('mouseover', function(e){$(this).css('background','#efefef')});
	$('#posting_toolbar div').bind('mouseout', function(e){$(this).css('background','#ffffff')});
	$('#loginDiv').bind('click', function(){document.location.href="register.cfm";});		
	$('#linkBox').bind('click', function(){$(this).val('');});
	$('#imageBox').bind('click', function(){$(this).val('');});	
	$('.post_right_lower img').jScale({w:'600px'});
	$('.post_right_lower_ad img').jScale({w:'400px'});
	$('.margin img').jScale({w:'300px'});
	$('.margin_sub img').jScale({w:'250px'});
	$('#tabs').tabs({ cache: false,spinner: '<img border="0" src="/images/icon_loading.gif" style="vertical-align:text-top;">Loading' });
	$('#tabs_cp').tabs({ selected: -1, cache: false,spinner: '<img border="0" src="/images/icon_loading.gif" style="vertical-align:text-top;">Loading' });
	$('#inviteButton').bind('click', inviteFriends);
	$('.featband').hover(function() {$(this).animate({"opacity": ".7"}, "normal");}, function() {$(this).animate({"opacity": "1"}, "normal");});
	$('#word_stats').click(function(){
		w = 350;
		h = 280;
		$('#phrase').remove();
		$(document.body).append('<div style="height:' + h + ';width:' + w + '" id="phrase" title="Calculate Word Saturdation"></div>');
		$('#phrase').load('/com/dialogs/dialog_wordsaturation.cfm').dialog({autoOpen:true,zIndex:3999, modal:true, width:w, height:h,  buttons: { Cancel: function () { $(this).dialog('close');$('#phrase').remove(); }} });
		$('#phrase').dialog('open');			
	});
});
