// update this when you make edits!
var version_scripts_story = 5

var isAutoSave = false;
var autosaveCounterId = 0;
var timeToSaveId = 0;
var autosavetime = 3000*60;
var saveAlertTime = 1000*60;
var critcountstarted = false;
var saving = false;
var issaved = true;


function hoverStory(e, id, isit)
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	if (!isit) {
		ttHideTimer = setTimeout('HideGlobalTooltip()', 1000);
		clearTimeout(hoverTimer);
		hoverTimer = 0;
	} else {
		SetTooltipPosition(e);
		hoverWhat = e;
		clearTimeout(ttHideTimer);
		ttHideTimer = 0;

		if (e != null) {
			hoverUrl = 'worker_queue.asp?action=info&id='+id;
			hoverTimer = setTimeout("DoFetchStory()", 1000);
		}
	}
}

function DoFetchStory()
{
	var t = document.getElementById('g_tt');
	if (t == null) return;
	//alert(hoverUrl);
	pollServer(hoverUrl, 'StoryInfoResponse');
}

function StoryInfoResponse()
{
	//alert(servResponse);
	if (hoverTimer == 0)
		return;
	if (servResponse == '-1') {
		alert("Unable to get a sane response from server...");
		return;
	} else {
		var t = document.getElementById('g_tt');
		t.style.display = "block";
		t.style.width = "400px";
		t.innerHTML = unescape(servResponse);
	}
}
	
function ToggleAutoSave()
{
	var v = document.getElementById('autosaveicon');
	critcountstarted = false;
	if (isAutoSave) {
		v.src = 'images/autosave_up.gif';
		clearTimeout(autosaveCounterId);
		timeToSaveId = setTimeout("TimeToSave()", saveAlertTime);
		setMultipleCookie("flags", "autosaveoff", "1");
		document.getElementById('saved').innerHTML = '<b><font color=red>Autosaving is disabled&nbsp;&nbsp;</font></b>';
	} else {
		v.src = 'images/autosave_down.gif';
		clearTimeout(timeToSaveId);
		StartAutoSaveCounter();
		setMultipleCookie("flags", "autosaveoff", "");
		alertAutoSave();
	}
	isAutoSave = !isAutoSave;
}


/* inline crits */

function ChangeCritType(url)
{
	if (document.themessage == null)
		document.location.href = url;
	else {
		if (document.themessage.critID.value > 0) {
			alert(schemeChangeTextNo);
		} else {
			var agree = confirm(schemeChangeText);
			if (agree)
				document.location.href = url;
		}
	}
}

function ToggleInlineComments(doit)
{
	for (var i = 0; i < 100; i++) {
		var v = document.getElementById('c_'+i);
		if (v == null) continue;
		if (doit)
			v.style.display = "block";
		else
			v.style.display = "none";			
	}
	var fl = "1";
	if (doit) fl = "";
	setMultipleCookie("flags", "inlineclosed", fl);
}
function ToggleInlineUncommented(doit)
{
	var tags = document.getElementsByTagName("P");
	var fl = "";
	for (i = 0; i < tags.length; i++) {
		if (tags[i].className == 'sti') {
			if (tags[i].style.display == "none") {
				tags[i].style.display = "block";
				fl = ""
			} else {
				tags[i].style.display = "none";
				fl = "1"
			}
		}
	}
	setMultipleCookie("flags", "inlineuncommented", fl);
}

function ToggleComment(id)
{
	var v = document.getElementById('c_'+id);
	if (v.style.display == 'block')
		v.style.display = 'none'
	else
		v.style.display = 'block'
}

var count = 0;

function SubmitCrit()
{
 	dontbugme = true;
	SubmitText();
	var storyFld = document.getElementById('storyText');
	document.themessage.submit();
}

var currentParagraph = null;

function im(what, doit)
{
	if (currentParagraph != null) return;
	if (what == currentParagraph || what.style.backgroundColor == '#ccffff' || what.style.backgroundColor == 'rgb(204, 255, 255)')
		return;
	if (doit) {
		what.style.backgroundColor = '#FFFFCC';
	} else {
		what.style.backgroundColor = '';
	}
}

function FocusInlineEditBox()
{
	var v = document.getElementById('comm')
	v.focus();
}

function OpenTextWindow(what)
{
	currentParagraph = what;
	var v = document.getElementById('comm');
	var vpar = document.getElementById('commParent');
	StopSpellCheck();
	spellAreaName = v.id;
	
	// populate window with current text
	var c = document.themessage.crit.value;
	var mrk = '--BEGIN_'+what.id;
	var idx = c.indexOf(mrk);
	if (idx >= 0) {
		idx += mrk.length + 1;
		var idx2 = c.indexOf('--END', idx);
		var txt = c.substr(idx, idx2-idx);
		v.value = txt;
	} else
		v.value = "";
	
	if (what.nextSibling) {
		nextSib = what.nextSibling;
		var par = what.parentNode;
		while (par.tagName != "DIV" && par != null)
			par = par.parentNode;
		if (par == null) par = what.parentNode;
		// don't know why this sometimes doesn't work :-|
		try {
			par.insertBefore(vpar, what.nextSibling);
		} catch (a) {
			what.appendChild(vpar);
		}
		if (nextSib.className == "comment") {
			what.parentNode.removeChild(nextSib)
		}
	}
	v = document.getElementById('txtwnd');
	v.style.display = "block";
	setTimeout('FocusInlineEditBox()', 100);
}

function RemoveSection(id)
{
	var c = document.themessage.crit.value;
	var mrk = '--BEGIN_'+id;
	var idx = c.indexOf(mrk);
	if (idx >= 0) {
		var idx2 = c.indexOf('--END', idx) + 5;
		c = c.substr(0, idx) + c.substr(idx2, c.length-idx2);
		document.themessage.crit.value = c;
	}
}

function icc(what)
{
	if (isSpellChecking) {
		StopSpellCheck();
		return;
	}
	if (currentParagraph != null) {
		if (currentParagraph.id == what.id)
			return;
		SubmitText();
	}
	OpenTextWindow(what);
	what.style.backgroundColor = '#CCFFFF';
}

function SubmitText()
{
	if (currentParagraph == null) {
		return;
	}
	var v = document.getElementById('comm');
	RemoveSection(currentParagraph.id);
	if (v.value == '') {
		currentParagraph.style.backgroundColor = '';
		currentParagraph = null;
	} else {
		var c = document.themessage.crit.value;
		var val = v.value;
		c = c + '--BEGIN_'+currentParagraph.id+':'+val+'--END';
		document.themessage.crit.value = c;
		v.value = '';

		AddInProgressComment(currentParagraph, val);

	}
	v = document.getElementById('txtwnd');
	v.style.display = "none";
	currentParagraph = null;
}

function ToggleShowInProgressComments()
{
	v = getCookie('showprogressinlinecomments');
	if (v == '1')
		v = '';
	else
		v = '1';
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie('showprogressinlinecomments', v, now);
	ColorParagraphs();
}

function AddInProgressComment(para, val)
{
	if (getCookie('showprogressinlinecomments') != '1')
		return;
	// put the text underneath the paragraph
	var td = document.createElement("DIV");
	td.className = "comment";
	//td.onClick = function(what) {icc(what.previousSibling);};

	td.colSpan = 5
	td.innerHTML = '<div style="color:gray; cursor:pointer;" onClick="icc(this.parentNode.previousSibling);">' + val.replace(new RegExp("\n", "g"), "<br>")  + '</div>';
	para.parentNode.insertBefore(td, para.nextSibling);
}

var theTop = 100;
var old = theTop;
function moveTextWindow() {
	var v = document.getElementById('txtwnd');
	var py;
	var px = 0;
	var w = 200;
	if (window.innerHeight) {
		py = window.pageYOffset
		w = window.innerWidth;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		py = document.documentElement.scrollTop
		w = document.documentElement.clientWidth;
	} else if (document.body) {
		py = document.body.scrollTop
		w = document.body.clientWidth;
	}
	py += 100;
	if (py < theTop) py = theTop;
	else py += theTop;
	if (py == old && v != null) {
		v.style.top = py;
		px = (w / 2)-180;
		px += 65;
		if (px < 132) px = 132;
		v.style.left = px;
		//alert(py);
	}
	old = py;
	setTimeout('moveTextWindow()', 200);
}

// story bookmarks
function moveBookIcon() {
	var v = document.getElementById('bookselalt');
	if (v == null) return;
	var py;
	var px = 0;
	var w = 200;
	if (window.innerHeight) {
		py = window.pageYOffset
		w = window.innerWidth;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		py = document.documentElement.scrollTop
		w = document.documentElement.clientWidth;
	} else if (document.body) {
		py = document.body.scrollTop
		w = document.body.clientWidth;
	}
	py += 100;
	if (py < theTop) py = theTop;
	else py += theTop;
	if (py == old && v != null) {
		v.style.top = py;
		px = 140;
		v.style.left = px;
		var vpreview = document.getElementById('senda');
		if (isIexplore && vpreview != null) {
			d = vpreview.getBoundingClientRect().top;
			if (d < 200)
				v.style.display = "none";
			else
				v.style.display = "inline";
		}
	}
	old = py;
	setTimeout('moveBookIcon()', 500);
}

function ColorParagraphs()
{
	var c = document.themessage.crit.value;
	for (var i = 1; i < 1000; i++) {
		var it = i;
		if (i >= 100) 
			it = ''+i;
		else if (i >= 10)
			it = '0'+i;
		else
			it = '00'+i;
		var v = document.getElementById('p_'+it);
		if (v == null) {
			return;
		}
		var mrk = '--BEGIN_p_'+it;
		var idx = c.indexOf(mrk);
		
		nextSib = v.nextSibling;
		if (nextSib != null && nextSib.className == "comment") {
			v.parentNode.removeChild(nextSib)
		}
		if (idx >= 0) {
			v.style.backgroundColor = '#CCFFFF';
			
			idx += mrk.length + 1;
			var idx2 = c.indexOf('--END', idx);
			var txt = c.substr(idx, idx2-idx);
			AddInProgressComment(v, txt);
		}		
	}
}

/* */
function CloseDisclaimerTable()
{
	var now = new Date();
	now.setTime(now.getTime() + 4 * 24 * 60 * 60 * 1000);
	var element = document.getElementById('disclaimer');
	element.style.display = "none";
	setMultipleCookie("flags", "discClose", "1", now);
}
				
function OpenThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "";
}

function CloseThisLayer(name)
{
	var element = document.getElementById(name)
	element.style.display = "none";
}

function ToggleStory()
{
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (element.style.display != "")
		  OpenThisLayer(name);
	  else
	      CloseThisLayer(name);
	}
}
var colchange = false
function ToggleStoryColor()
{
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (colchange)
		  element.style.color = "#888888";
	  else
	      element.style.color = "#009900";
	}
	colchange = !colchange;
}
var size = ""
if (document.getElementById("t1") != null) {
	size = element.style.fontSize
}
function ToggleStorySize()
{
	var num = 50
	for (i=1; i<num+1; i+=1) {
	  var name = "t"+i
	  var element = document.getElementById(name)
	  if (element == null)
	  	break;
	  if (element.style.fontSize == size)
		  element.style.fontSize = "9px";
	  else
	      element.style.fontSize = size;
	}
}

function TimeToSave()
{
	timeToSaveId = 0;
//	var v = document.getElementById('Vista');
//	v.src = "images/skilabod_vistud_red.gif";

	SaveCritique('Saving...', true);
}

function StartCounter()
{
	issaved = false;
	isCritTextAdded = true;
	if (timeToSaveId == 0 && isAutoSave)
		timeToSaveId = setTimeout("TimeToSave()", saveAlertTime);
}

function StartAutoSaveCounter()
{
	if (!critcountstarted) {
		// the first save is 10 seconds from now, then every 60
		setTimeout("SaveCritique('', true)", 5000);
		autosaveCounterId = setTimeout("AutoSaveCritique()", 10000);
		document.themessage.timeoutid.value = autosaveCounterId;
		critcountstarted = true;
	}
}

function MakeCritWndBigger()
{
	var c = document.getElementById('critwndcontainer');
	if (c != null) 
		c.style.width = "300";
	document.themessage.Text.style.width = "";
	
	var cols = document.themessage.Text.cols;
	var rows = document.themessage.Text.rows;
	if (cols < 130)
	document.themessage.Text.cols = cols + 10;
	if (rows < 40)
	document.themessage.Text.rows = rows + 5;
	SetSizeCookie('sz_c', document.themessage.Text.cols, document.themessage.Text.rows);
}

function MakeCritWndSmaller()
{
	var c = document.getElementById('critwndcontainer');
	if (c != null) 
		c.style.width = "300";
	document.themessage.Text.style.width = "";
	
	var cols = document.themessage.Text.cols;
	var rows = document.themessage.Text.rows;
	if (cols > 90)
		document.themessage.Text.cols = cols - 10;
	if (rows > 20)
		document.themessage.Text.rows = rows - 5;
	SetSizeCookie('sz_c', document.themessage.Text.cols, document.themessage.Text.rows);
}

function MakeCritWndReallyBig()
{
	var c = document.getElementById('critwndcontainer');
	c.style.width = "90%";
	document.themessage.Text.style.width = "100%";
	SetSizeCookie('sz_c', "BIG", "BIG");
}

function MoveToolbar(what, smallrows, largerows) {
	if (smallrows == null) {
		smallrows = 5;
	}
	if (largerows == null) {
		largerows = 16;
	}
	if (lostForm != null) {
		lostForm.rows = smallrows;
		lostForm.style.backgroundColor = "#F3F3F3";

	}
	what.rows = largerows;
	what.style.backgroundColor = "#FFFFFF";
	StopSpellCheck();
	spellAreaName = what.id;

	return
	
	var element = document.getElementById("toolbar");
	//formName.insertAdjacentElement( "afterEnd" , element );
	if (what.nextSibling)
		what.parentNode.insertBefore(element, what.nextSibling);
	else
		what.parentNode.appendChild(element);
	
	element.style.display = "block";
}

var b = false;
function MoveToolbarNoSize(what, smallrows, largerows) {
	var element = document.getElementById("toolbar");
	if (what.nextSibling)
		what.parentNode.insertBefore(element, what.nextSibling);
	else
		what.parentNode.appendChild(element);
	StopSpellCheck();
	spellAreaName = what.id;
	element.style.display = "block";
}

var novelLast = null;
function ToggleNovelSynopsis(id, chapter, isprev)
{
	var inf = document.getElementById('novelinfo');
	if (novelLast == 'synopsis'+isprev) {
		inf.innerHTML = '';
		inf.style.display = 'none';
		novelLast = null;
	} else {
		inf.innerHTML = 'Retrieving information...';
		novelLast = 'synopsis'+isprev;
		inf.style.display = 'block';
		window.frames["worker"].location.href = 'worker_queue.asp?action=novelsynopsis&id='+id+'&num='+chapter+'&prev='+isprev;
	}
}

function ToggleNovelDesc(id)
{
	var inf = document.getElementById('novelinfo');
	if (novelLast == 'desc') {
		inf.innerHTML = '';
		inf.style.display = 'none';
		novelLast = null;
	} else {
		inf.innerHTML = 'Retrieving information...';
		novelLast = 'desc'
		inf.style.display = 'block';
		window.frames["worker"].location.href = 'worker_queue.asp?action=noveldesc&id='+id;
	}
}

function ToggleNovelCharacters(id, chapter)
{
	var inf = document.getElementById('novelinfo');
	if (novelLast == 'char') {
		inf.innerHTML = '';
		inf.style.display = 'none';
		novelLast = null;
	} else {
		inf.innerHTML = 'Retrieving information...';
		novelLast = 'char';
		inf.style.display = 'block';
		window.frames["worker"].location.href = 'worker_queue.asp?action=novelcharacters&id='+id+'&num='+chapter;
	}
}

// moves the "save" button so that it's always visible
var theTop = 100;
var old = theTop;
var savefailed = false;
var hidesavebuttonmoretimer = null;
// highlights the given element
function OverSaveIcon(what, doit)
{
	d = document.getElementById('saveicon_more');
	d2 = document.getElementById('saveicon2');
    if (doit) {
		d2.className = 'colbdr hdr_sel link'
		d.style.display = 'inline';
	} else {
		d2.className = 'colbdr or link'
		if (!savefailed)
			HideSaveButtonMore();
	}

}

function MoveSaveIcon() {
    // this assumes IE
    var v = document.getElementById('saveicon');
    if (v == null) return;
    var py;
    var px = 0;
    var w = 200;
    if (document.documentElement && document.documentElement.scrollTop) {
		py = document.documentElement.scrollTop
		w = document.documentElement.clientWidth;
    } else if (document.body) {
		py = document.body.scrollTop
		w = document.body.clientWidth;
    }

    py -= 100;
    if (py < theTop)
    	py = theTop;
    else
    	py += theTop;
    if (py == old && v != null) {
		v.style.top = py;
		px = 132;
		v.style.left = px;
		/*var vpreview = document.getElementById('saved');
		if (vpreview != null) {
		    d = vpreview.getBoundingClientRect().top;
		    if (d < 0)
				v.style.display = "inline";
		    else
				v.style.display = "none";
		}
		*/
		if (py > 500)
			v.style.display = "inline";
		else
			v.style.display = "none";
    }
    old = py;
    setTimeout('MoveSaveIcon()', 10);
}
function SaveCritique(txt, auto)
{
	try {
		if (saving) {
			txt = "<font color=red><b>SAVE FAILED! PLEASE TRY AGAIN!</b></font>"
			savefailed = true;
		}
		t = '<b>'+txt+'</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		document.getElementById('saved').innerHTML = t
		mr = document.getElementById('saveicon_more');
		if (mr != null) {
			mr.innerHTML = "<nobr><b>"+txt+"</b></nobr>"
			mr.style.display = 'inline';
		}
		saving = true;
		var oldAction = document.themessage.action;
		act = 'worker_savecrit.asp?'+document.themessage.qry.value+'&timeoutid='+document.themessage.timeoutid.value;
		if (auto)
			act += "&auto=1";
		document.themessage.action = act;
		document.themessage.target = 'worker';
		// for inline crits
		if (currentParagraph != null) {
			var v = document.getElementById('comm');
			if (v != null) {
				RemoveSection(currentParagraph.id);
				if (v.value == '') {
				} else {
					var c = document.themessage.crit.value;
					c = c + '--BEGIN_'+currentParagraph.id+':'+v.value+'--END';
					document.themessage.crit.value = c;
				}
			}
		}


		document.themessage.submit();

		document.themessage.action = oldAction;
		document.themessage.target = "_self";
	} catch (e) {
		alert('There was an unspecified error saving your critique. Please try again.\nThe error said: '+e);
	}
}

function HideSaveButtonMore()
{
	if (hidesavebuttonmoretimer == null)
		hidesavebuttonmoretimer = setTimeout('DoHideSaveButtonMore()', 3000);
}
function DoHideSaveButtonMore()
{
	mr = document.getElementById('saveicon_more')
	if (mr != null)
		mr.style.display = 'none';
	hidesavebuttonmoretimer = null;
}


function ToggleStoryBookmark(what, id, r)
{
	if (what.innerHTML.indexOf("<!--1-->") >= 0) {
		url = 'worker_queue.asp?action=deletebookmark&id='+id+'&isreminder='+r;
		//alert('1 '+url);
		window.frames["worker"].location.href = url;
		txt = langStrings[4]
		if (r)
			txt = langStrings[5]
		what.innerHTML = '<!--0--><nobr><img src="images/bookmark_16.png" align=absmiddle> '+txt+'</nobr>';

	} else {
		url = 'worker_queue.asp?action=addbookmark&id='+id+'&location=0&isreminder='+r;
		//alert('2 '+url);
		window.frames["worker"].location.href = url;
		txt = langStrings[3]
		if (r)
			txt = langStrings[6]
		what.innerHTML = '<!--1--><nobr><img src="images/bookmark_16.png" align=absmiddle> '+txt+'</nobr>';
	}
}

function GetStoryListEntry(arrID, arrTitleRaw, arrStatus, arrWhoCanCrit, arrIsHidden, arrIsAdult, arrDontWantCrits, arrNovelChapterNumber, arrNovelChapterPart, arrAuthor, status, hasCrit, userID, userLevel)
{
	HasCritStyle = ' style="text-decoration: line-through;" title="You have critiqued this story"'
	StoryNotVisibleStyle = ' title="Story is not visible to you for some reason"'
	StoryHiddenStyle = ' title="Story has been hidden by the author"'
	StoryInQueueStyle = ' title="Story is still in the Queue and cannot be viewed until it comes up for review"'
	StoryArcStyle = ' title="Story has been archived. It may still be visible but you cannot crit it"'
	OnlyCrittersStyle = ' title="The writer only allows active participants to view his story"'
	OnlyCritsInMonthStyle = ' title="The writer only allows active participants to view his story"'
	OnlyExperiencedStyle = ' title="The writer only allows active participants to view his story"'
	OnlyActiveStyle = ' title="The writer only allows active participants to view his story"'

	var markers = getCookie('queuemarkers');
	markAdult = (markers.indexOf("adult") < 0);
	markProtect = (markers.indexOf("protect") < 0);
	markBookmarks = (markers.indexOf("bookmark") < 0);
	markNovels = (markers.indexOf("novels") < 0);

	storyIsHidden = true
	if ((arrStatus > 1 && !arrIsHidden) || (userLevel >= 8) || arrAuthor == userID)
		storyIsHidden = false

	bn = ""//MultipleCookieValue("StoryBookmark", ""&arrID)
	titleIcon = ''
	if (arrTitleRaw == "")
		arrTitleRaw = "(unnamed)"

	if (markProtect) {
		tt = "";
		switch (arrWhoCanCrit)
		{
		case 6:
			ic = "shield_green";
			tt = "Only members who have critiqued before can view this story"
			break;
		case 4:
			ic = "shield";
			tt = "Only members who have critiqued in the last month can view this story"
			break;
		case 8:
			ic = "shield_yellow";
			tt = "Only experienced members (who have critiqued at least 10 stories) can view this story"
			break;
		case 2:
			ic = "shield_red";
			tt = "Only very active members (who have critiqued 10 stories and in the last month) can view this story"
			break;
		}
		if (tt != "")
			titleIcon = '<img src="images/'+ic+'.png" hspace=1 height=12 align=absmiddle title="'+tt+'">'
	}

	if (arrStatus == 7 || arrStatus == 8)
		titleIcon += '<img src="images/data.png"" height=14 align=absmiddle title="Story has been archived">'

	extrastyle = ""

	theStyle = ""
	if (arrStatus == 2 && status != 2)
		theStyle = 'style="color:#0055AA; font-weight: bold;"'
	overStyle = ""
	if (hasCrit)
		overStyle = HasCritStyle

	storyWantsCrits = true
	myAge = 20

	//If me_nocrits AND Int(arrWhoCanCrit) = STORY_ACCESS_CRITTERS Then storyWantsCrits = False
	//If me_nocritsinmonth AND (Int(arrWhoCanCrit) = STORY_ACCESS_MONTHCRITTERS OR Int(arrWhoCanCrit) = STORY_ACCESS_ACTIVE) Then storyWantsCrits = False
	//If NOT me_overTenCrits AND (Int(arrWhoCanCrit) = STORY_ACCESS_ACTIVE OR Int(arrWhoCanCrit) = STORY_ACCESS_EXPERIENCED) Then storyWantsCrits = False
	//If GetUserLevel >= USR_SUPER Then storyWantsCrits = True
	//Dim txt : txt = ""
	txt = ''
	title = arrTitleRaw//GetStoryTitle(arrTitleRaw, arrNovelChapterNumber, arrNovelChapterPart, STORY_TITLE_LENGTH, False)

	ovr = ' onMouseOver="hoverStory(this, '+arrID+', true);" onMouseOut="hoverStory(this, '+arrID+', false);"'

	if (arrIsAdult > 1 && arrAuthor != userID) {
		txt += '<span title="Story contains adult content and is not visible to members below 18 years of age">' + title + '</span>'
		titleIcon += '<img hspace=1 height=12 src="images/forbidden_13.png" height=13 width=13 align=absmiddle>'
	} else if (!storyIsHidden) {
		if (arrIsAdult && markAdult)
			titleIcon += '<img src="images/sml_dvl_faint.gif" align=absmiddle title="Story contains material which might offend readers">'

		if (arrStatus == 7 || arrStatus == 8) {// archived
			txt += '<span'+StoryArcStyle+'>'+title+'</span>'
			txt = '<a '+StoryArcStyle+' style="color:#666688;" href="queue.asp?action=lookup&index='+arrID+'"> <span>'+title+'</span> </a>'
		} else if (storyWantsCrits)
			txt += '<a class=hoverlink '+theStyle+' href="queue.asp?action=lookup&index='+arrID+'"> <span'+ovr+' '+overStyle+'>'+title+'</span></a> '
		else
			txt += '"<span'+OnlyCrittersStyle+'>'+title+' </span>'
	} else if (arrIsHidden) {
		txt += '<span'+StoryHiddenStyle+'>'+title+' </span>'
	} else if (arrStatus == 1) { // in queue
		txt += '<span'+StoryInQueueStyle+'>'+title+' </span>'
	} else {
		txt += '<span'+StoryNotVisibleStyle+'>'+title+' </span>'
	}
	if (arrStatus == 0) { // rejects
		txt = '<del>' + txt + '<del>'
		titleIcon += '<img hspace=1 height=12 src="images/delstory.png" align=absmiddle title="This story is rejected">'
	}
	if (arrIsHidden) {
		if (arrStatus == 5) // deleted
			titleIcon += '<img hspace=1 height=12  src="images/delstory.png" align=absmiddle title="This story has been deleted by the author">'
		else if (arrStatus != 7 && arrStatus != 8) // archived
			titleIcon += '<img hspace=1 height=12  src="images/ghost_14.png" align=absmiddle title="This story has been hidden by the author">'
	}
	if (arrDontWantCrits)
		titleIcon += '<img hspace=1 height=12 src="images/lock2.png" align=absmiddle title="The author does not want any more critiques on this story">'
	if (arrNovelChapterNumber != '0' && markNovels)
		titleIcon += '<img hspace=1 height=12  src="images/novelicon.png" align=absmiddle title="This is a part of a novel">'

	c = getCookie('storybookmarks');
	if (markBookmarks && c.indexOf(';'+arrID+';') >= 0)
		txt = '<img class=link OnClick="RemoveBookmarkInQueue(this, '+arrID+');" hspace=1 height=12  src="images/bookmark_16.png" align=absmiddle title="'+langStrings[1]+'">' + txt
	if (titleIcon == "")
		titleIcon = '<img src="images/spc.gif" align=absmiddle width=1>'
	//txt += titleIcon
	//txt = '<table cellpadding=0 cellspacing=0 width="100%"><tr><td>' + txt + '</td><td align=right>' + titleIcon + '</td></tr></table>'
	txt += ' ' + titleIcon

	return txt
}

function RemoveBookmarkInQueue(what, id)
{
	if (confirm(langStrings[2])) {
		window.frames["worker"].location.href = 'worker_queue.asp?action=deletebookmarkall&id='+id;
		what.style.display = 'none';
	}
}

function AddQueueDividerRow(qID, slotnum, numCrits)
{
	var tbl = document.getElementById('queue_'+qID);
	var tbody = tbl.getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR");
	row.className = "er"
	if (tbl.childNodes[tbl.childNodes.length-1].className == "er")
		row.className = "or"

	//row.innerHTML = '<td colspan=5 height=10 style="border-bottom:1 px solid #000000;"><hr size=1></td><td colspan=1 class=tinytext align=center><a href="queue.asp?action=whocrit&slot='+slotnum+'"&queue='+qID+'"><b>'+numCrits+'</b></a></td>';
	var td = document.createElement("TD");
	td.className = "tdlst";
	td.colSpan = 5
	td.innerHTML = "<hr size=1>";
	row.appendChild(td);
	var td = document.createElement("TD");
	td.innerHTML = '<center><a href="queue.asp?action=whocrit&slot='+slotnum+'&queue='+qID+'"><b>'+numCrits+'</b></a></center>'
	row.appendChild(td);
	tbody.appendChild(row);
}

function AddQueueRow(qID, arrID, arrTitleRaw, arrStatus, arrWhoCanCrit, arrIsHidden, arrIsAdult, arrDontWantCrits, arrNovelChapterNumber, arrNovelChapterPart, arrAuthor, status, arrUserName, arrNumCrits, dt, arrNumWords, arrGenre, hasCrit, userID, userLevel, isStar, isOwe, isPeriod, arrAccess)
{
	var tbl = document.getElementById('queue_'+qID);
	var tbody = tbl.getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR");
	// Story link
	var tit = GetStoryListEntry(arrID, arrTitleRaw, arrStatus, arrWhoCanCrit, arrIsHidden, arrIsAdult, arrDontWantCrits, arrNovelChapterNumber, arrNovelChapterPart, arrAuthor, status, hasCrit, userID, 12);

	// User link
	mr = ''
	if (parseInt(arrAccess) == 6)
		mr = ' class=usr_prem '
	else if (parseInt(arrAccess) == 7)
		mr = ' class=usr_gold '
	//alert(parseInt(arrAccess))
	var usr = '<a class=hoverlink OnMouseOver="HoverInfo(this, '+arrAuthor+', 1);" OnMouseOut="StopInfo(this);" href="members.asp?lookup='+arrAuthor+'"><span'+mr+'>'+arrUserName+'</span></a>'
	
	var markers = getCookie('queuemarkers');
	markBuddy = (markers.indexOf("buddy") < 0);
	markOwe = (markers.indexOf("owe") < 0);
	markStr = (markers.indexOf("starcritters") < 0);
	
	if (markOwe && isOwe)
		usr += ' <img src="images/handshake.png" title="Care to return the favor?" align=absmiddle>'
	if (markStr && isStar)
		usr += ' <img src="images/star.gif" title="This member is an outstanding critter" align=absmiddle>'
	c = getCookie('buddies');
	if (markBuddy && c.indexOf(';'+arrAuthor+';') >= 0)
		usr = usr + ' <img src="images/usr_buddy.gif" title="This member is your buddy" align=absmiddle>'

	var numCrits = arrNumCrits;
	if (numCrits == 0)
		numCrits = "<font color=red><b>0</b></font>"
	numCrits = "<center>" + numCrits + "</center>"
	if (status == 1 && isPeriod)
		var lst = [tit, usr, dt, arrNumWords, arrGenre]
	else if (status == 2 && isPeriod)
		var lst = [tit, usr, arrNumWords, arrGenre, numCrits]
	else
		var lst = [tit, usr, dt, arrNumWords, arrGenre, numCrits]

	row.className = "er"
	if (tbody.childNodes[tbody.childNodes.length-1].className == "er")
		row.className = "or"
	for (i = 0 ; i < lst.length; i++) {
		var td = document.createElement("TD");
		td.className = "tdlst";
		td.innerHTML = "<nobr>" + lst[i] + "</nobr>";
		row.appendChild(td);
	}
	tbody.appendChild(row);
}

function CancelQueueSub(queueID, isPriv)
{
	if (confirm(langStrings[isPriv ? 8 : 7])) {
		Goto('customqueue.asp?action=cancelsubscription&id='+queueID);
	}
}