//script.js
var fullView = false;

function selectcat(id, str, arr) {
	for(var i = 0; i < arr.length; i++) {
		e = document.getElementById('catid' + arr[i]);
		if (e != null) {
			e.className = '';
		}
	}
	e = document.getElementById('catid' + id);
	e.className = 'acSelectedItem';
	
	el = document.getElementById('upload_region');
	el.innerHTML = '&nbsp;' + str;
	
	$('#submitter').show();
	document.getElementById('sidcat').value = id;
	$('#writer_n').hide();

	if (id == 23 || id == 24 || id == 25) {
		$('#submitter').hide();
		$('#writer_n').show();
	}
	$('#cats').hide(500);
}

function deleteJournal(id) {
	var answer = confirm("Delete this journal?")
	if (answer){
		window.location = "/journals/d/"+String(id);
	}
}

function resizeArt(id, tit, ext, xtype, xwidth, xheight, xloc) {
	var artContainer = document.getElementById('artwork');
	if (xtype == 'img')  {
		if (!fullView) {
			artContainer.src = '/images/'+String(id)+'/full/'+tit+'.'+ext;
			fullView = true;
		} else {
			artContainer.src = '/images/'+String(id)+'/thumb/'+tit+'.'+ext;
			fullView = false;
		}
	} else if (xtype == 'fla') {
		if (!fullView) {
			artContainer.innerHTML = '<object width="'+xwidth+'" height="'+xheight+'">\
				<param name="movie" value="/images/'+String(id)+'/full/'+tit+'.'+ext+'">\
				<embed src="/images/'+String(id)+'/full/'+tit+'.'+ext+'" width="'+xwidth+'" height="'+xheight+'">\
				</embed>\
				</object>\
			';
			fullView = true;
		}
	} else if (xtype == 'mus') {
		if (!fullView) {
			artContainer.innerHTML = '<object width="400" height="200">\
				<param name="movie" value="'+xloc+'">\
				<param name="file" value="/images/'+String(id)+'/full/'+tit+'.'+ext+'">\
				<embed src="'+xloc+'?file=/images/'+String(id)+'/full/'+tit+'.'+ext+'" width="400" height="200">\
				</embed>\
				</object>\
			';
			fullView = true;
		}
	}
}


function selectArtType(artID) {
	for (x = 1; x <= 4; x++) {
		elem = document.getElementById('art_type_'+String(x));
		elem.style.display = 'none';
	}
	
	elem = document.getElementById('art_type_' + artID);
	elem.style.display = 'block';
}

function showFavs(id) {
	window.open ("/favs/"+id + '/', "mywindow","location=1,status=1,scrollbars=1,width=250,height=300"); 
}

function selectInformation(iID) {
	for (x = 1; x <= 3; x++) {
		elem = document.getElementById('info_type_'+String(x));
		elem.style.display = 'none';
		elem2 = document.getElementById('info_nav_'+String(x));
		elem2.style.color = '#000';
	}
	
	elem = document.getElementById('info_type_' + iID);
	elem.style.display = 'block';
	elem2 = document.getElementById('info_nav_'+ iID);
	elem2.style.color = '#fff';
}

function changePrefs(iID) {
	for (x = 1; x <= 4; x++) {
		elem = document.getElementById('prefs_page_'+String(x));
		elem.style.display = 'none';
		elem2 = document.getElementById('prefs_nav_'+String(x));
		elem2.style.color = '#000';
	}
	
	elem = document.getElementById('prefs_page_' + iID);
	elem.style.display = 'block';
	elem2 = document.getElementById('prefs_nav_'+ iID);
	elem2.style.color = '#fff';
}


function deleteMsg(msgId) {
	if (confirm("Do you want to delete this message?")) {
		document.location.href="/inbox/d/" + msgId; 
	}
}

function flagMsg(msgId, subj) {
	if (confirm("Do you want to notify the administrators about this message?")) {
		alert("You agree")
	} else {
		alert ("You do not agree")
	};
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function closeReply(elem) {
	var el = document.getElementById('msgreply');
	el.style.display='none';
	el.innerHTML = '';
}


function switch_updates(uid) {
	if (document.getElementById('update_type_1') == undefined) {
		return true;
	}
	
	for (x = 1; x <= 6; x++) {
		elem = document.getElementById('update_type_'+String(x));
		elem.style.display = 'none';
	}
	
	elem = document.getElementById('update_type_' + uid);
	elem.style.display = 'block';
	
	return true;
}

function closeCommentReply(commentId) {
	elem = document.getElementById('reply' + commentId);
	elem.style.display = 'none';
}

function openCommentReply(commentId) {
	elem = document.getElementById('reply' + commentId);
	elem.style.display = 'block';
}

function showLogin() {
	elem = document.getElementById('loginform');
	elem.style.display = 'block';
	elem = document.getElementById('fpwdform');
	elem.style.display = 'none';
}

function showForgotPwd() {
	elem = document.getElementById('fpwdform');
	elem.style.display = 'block';
	elem = document.getElementById('loginform');
	elem.style.display = 'none';
}

function deleteArtwork(artId) {
	if (confirm('Really remove this artwork?')) {
		document.location.href="/art/"+String(artId)+"/delete/";
	} else {
		return;
	}
}

function addname() {
	elem = document.getElementById('descript');
	var txt = elem.value;
	var usr = prompt('Add Art alleys username');
	elem.value = txt + ' [[user:' + usr + ']] ';
}


function addlink() {
	elem = document.getElementById('descript');
	var txt = elem.value;
	var lnk = prompt('Add link');
	elem.value = txt + ' [[link:' + lnk + ']] ';
}

function addart() {
	elem = document.getElementById('descript');
	var txt = elem.value;
	var lnk = prompt('Add art number');
	elem.value = txt + ' [[art:' + lnk + ']] ';
}

function drawSketcher(dta) {
	dta = decode64(dta);
	arr = new Array();
	arr = dta.split("\0\0");
	
	uri = decode64('aHR0cDovL3NrZXRjaGVyLmFydGdyb3VuZHMuY29tL2FwcGxldC5waHA/dXJsPWFydGFsbGV5cyZ0b2tlbj0=') + arr[1] + '&nick=' + arr[0];
	
	document.write('\
		<FRAMESET cols="100%">\
		<frame src='+uri+' />\
		</FRAMESET>\
	');
}


//updates removal :3
function removeUpdateComment(id) {
	if (confirm("This is permanately removing watched comment!")) {
		window.location.href="/updates/delete/comments/"+ String(id);
	}
}
function removeUpdateReplies(id) {
	if (confirm("This is permanately removing watched comment!")) {
		window.location.href="/updates/delete/replies/"+ String(id);
	}
}
function removeUpdateWatch(id) {
	if (confirm("This is permanately removing watched watch!")) {
		window.location.href="/updates/delete/watch/"+ String(id);
	}
}
function removeUpdateFav(id) {
	if (confirm("This is permanately removing watched fav!")) {
		window.location.href="/updates/delete/favs/"+ String(id);
	}
}
function removeUpdateJournal(id) {
	if (confirm("This is permanately removing watched journal!")) {
		window.location.href="/updates/delete/journal/"+ String(id);
	}
}
function removeUpdateArt(id) {
	if (confirm("This is permanately removing watched art!")) {
		window.location.href="/updates/delete/art/"+ String(id);
	}
}

//nuke section
function nukeUpdateComment() {
	if (confirm("You're about to remove all comments!")) {
		window.location.href="/updates/delete/comments/all";
	}
}
function nukeUpdateReplies() {
	if (confirm("You're about to remove all replies")) {
		window.location.href="/updates/delete/replies/all";
	}
}
function nukeUpdateWatch() {
	if (confirm("You're about to remove all watched watches!")) {
		window.location.href="/updates/delete/watch/all";
	}
}
function nukeUpdateFav() {
	if (confirm("You're about to remove all watched favorites!")) {
		window.location.href="/updates/delete/favs/all";
	}
}
function nukeUpdateJournal() {
	if (confirm("You're about to remove all watched journals!")) {
		window.location.href="/updates/delete/journal/all";
	}
}
function nukeUpdateArt() {
	if (confirm("You're about to remove all watched art!")) {
		window.location.href="/updates/delete/art/all";
	}
}


//search
function closeSearch() {
	var curelem = document.getElementById('searchbox');
	curelem.style.display='none';
}

function openSearch() {
	var curelem = document.getElementById('searchbox');
	curelem.style.display='block';
	var curelem = document.getElementById('searchelem');
	curelem.focus();
}

function doSearch(e) {
	var curelem = document.getElementById('searchelem');
	var keycode;
	if (window.event) { 
		keycode = curelem.event.keyCode;
	} else if (e) {
		keycode = e.which;
	}
	
	if (keycode == 27) {
		closeSearch();
	} else if (keycode == 13) {
		window.location.href='/search/' + urlencode(curelem.value);
	}
}

function social_rolover(obj, imgsrc) {
	var o = document.getElementById(obj);
	o.src = imgsrc;
}

function showFriends() {
	var o = document.getElementById('friendsOnline');
	o.style.display = 'block';
}

function hideFriends() {
	var o = document.getElementById('friendsOnline');
	o.style.display = 'none';
}

