function getCookie(name){var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg){return getCookieVal(j);}i=document.cookie.indexOf(" ",i)+1;if(i==0){break;}}return-1;};function getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}return unescape(document.cookie.substring(offset,endstr));};function setCookie(NameOfCookie,value,expirehours){var ExpireDate=new Date();ExpireDate.setTime(ExpireDate.getTime()+(expirehours*3600*1000));document.cookie=NameOfCookie+"="+escape(value)+((expirehours==null)?"":"; expires="+ExpireDate.toGMTString())+"; path=/;";};function setCookieMinutes(NameOfCookie,value,expirehours){var ExpireDate=new Date();ExpireDate.setTime(ExpireDate.getTime()+(expirehours*60*1000));document.cookie=NameOfCookie+"="+escape(value)+((expirehours==null)?"":"; expires="+ExpireDate.toGMTString())+"; path=/;";};var context_dictionary=1;document.onkeypress=keyhandler;function findSelection(){if(document.getSelection){txt=document.getSelection();}else if(document.selection){txt=document.selection.createRange().text;}else{return "";}return txt;};function keyhandler(e){if(context_dictionary==0)return 0;if(window.event)Key=window.event.keyCode;else Key=e.which;if(Key==100){var result=findSelection();if(result.length&&result.length<125)var toast=window.open('/dictionary.php?word='+escape(result)+'&pop=1','DictionaryWindow','toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=510,height=510,left=280,top=80');}};var myfontsize=12;var myfontstyle='Verdana';var nn=1;if(parseInt(getCookie('myfontsize'))>0){myfontsize=getCookie('myfontsize');}if(getCookie('myfontstyle').length>0){myfontstyle=getCookie('myfontstyle');}function updateFontSize(direction){if(direction=='u'&&myfontsize<=20){myfontsize++;}else if(myfontsize>=8){myfontsize--;}if(myfontsize<=20&&myfontsize>=8){setCookie('myfontsize',myfontsize,3600);if(nn){document.getElementById('storytext').style.fontSize=myfontsize+'px';}else{document.storytext.style.fontSize=myfontsize+'px';}}};function updateFontStyle(style){setCookie('myfontstyle',style,3600);if(nn)document.getElementById('storytext').style.fontFamily=style;else document.storytext.style.fontFamily=style;};function switchLayer(elementId,bolVisible){if(document.getElementById){var theElement=document.getElementById(elementId);}else{if(document.all){var theElement=document.all[elementId];}else{var theElement=new Object();}}if(!theElement){return;}if(theElement.style){theElement=theElement.style;}if(typeof(theElement.display)=='undefined'&&!(window.ScriptEngine&&ScriptEngine().indexOf('InScript')+1)){return;}if(bolVisible==true){theElement.display='block';}else{theElement.display='none';}};function switchPink(elementId,bolVisible){if(document.getElementById){var theElement=document.getElementById('l_'+elementId);}else{if(document.all){var theElement=document.all['l_'+elementId];}else{var theElement=new Object();}}if(!theElement){alert('bug');return;}if(theElement.style){theElement=theElement.style;}if(bolVisible){theElement.textDecoration='underline';theElement.color='darkgreen';}else{theElement.textDecoration='none';theElement.color='blue';}switchLayer(elementId,bolVisible);};function formatDate(vDate,vFormat){var vDay=vDate.getDate();var vMonth=vDate.getMonth()+1;var vYearLong=vDate.getFullYear();var vYearShort=vDate.getFullYear().toString().substring(2,4);var vYear=(vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort);var vHour=vDate.getHours();var vMinute=vDate.getMinutes();var vSecond=vDate.getSeconds();var vDateString=vFormat.replace(/dd/g,vDay).replace(/MM/g,vMonth).replace(/y{2,4}/g,vYear);vDateString=vDateString.replace(/hh/g,vHour).replace(/mm/g,vMinute).replace(/ss/g,vSecond);return vDateString;}var array_censors=new Array('0','Fiction Rated: K','Fiction Rated: K+','Fiction Rated: T','Fiction Rated: M','Fiction Rated: MA');var array_genres=new Array('None','General','Romance','Humor','Drama','Poetry','Action/Adventure','Mystery','Horror','Parody','Angst','Supernatural','Suspense','Sci-Fi','Fantasy','Spiritual','Tragedy');var array_languages=new Array('0','English','Spanish','French','German','Chinese','Japanese','Dutch','Portuguese','Scandinavian','Russian','Italian','Bulgarian','Polish','Hungarian','Hebrew','Arabic','Swedish','Norwegian','Danish','Finnish','Filipino','Esperanto','Hindi','Punjabi','Farsi','Greek','Romanian','Albanian','Serbian','Turkish','Czech','Indonesian','Croatian','Catalan','Latin');var array_status=new Array('0','In-Progress','Complete');function story(stitle,summary,userid,penname,category,storyid,genreid,subgenreid,datesubmit,dateupdate,ratingtimes,chapters,languageid,censorid,wordcount,statusid,verse){this.stitle=stitle;this.summary=summary;this.userid=userid;this.penname=penname;this.category=category;this.storyid=storyid;this.genreid=genreid;this.subgenreid=subgenreid;this.datesubmit=new Date();this.datesubmit.setTime(datesubmit);this.datesubmittext=formatDate(this.datesubmit,'MM-dd-yy');this.dateupdate=new Date();this.dateupdate.setTime(dateupdate);this.dateupdatetext=formatDate(this.dateupdate,'MM-dd-yy');this.ratingtimes=ratingtimes;this.chapters=chapters;this.languageid=languageid;this.censorid=censorid;this.wordcount=wordcount;this.statusid=statusid;this.verse=verse;}function story_set(myarray,stitle,summary,userid,penname,category,storyid,genreid,subgenreid,datesubmit,dateupdate,ratingtimes,chapters,languageid,censorid,wordcount,statusid,verse){myarray[myarray.length]=new story(stitle,summary,userid,penname,category,storyid,genreid,subgenreid,datesubmit,dateupdate,ratingtimes,chapters,languageid,censorid,wordcount,statusid,verse);}function sortByStatusid(a,b){var x=a.statusid;var y=b.statusid;return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByVerse(a,b){var x=a.verse.toLowerCase();var y=b.verse.toLowerCase();return((x<y)?1:((x>y)?-1:sortByStitle(a,b)));}function sortByStitle(a,b){var x=a.stitle.toLowerCase();var y=b.stitle.toLowerCase();return((x<y)?1:((x>y)?-1:0));}function sortByDateSubmit(a,b){var x=a.datesubmit.getTime();var y=b.datesubmit.getTime();return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByDateUpdate(a,b){var x=a.dateupdate.getTime();var y=b.dateupdate.getTime();return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByChapters(a,b){var x=a.chapters;var y=b.chapters;return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByReviews(a,b){var x=a.reviews;var y=b.reviews;return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByWords(a,b){var x=a.wordcount;var y=b.wordcount;return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function sortByReviews(a,b){var x=a.ratingtimes;var y=b.ratingtimes;return((x<y)?-1:((x>y)?1:sortByStitle(a,b)));}function storylist_render(story_array,startrow,show_cat,show_author){var buffer=new Array();var story;for(i=story_array.length,c=startrow;i>0;i--,c++){story=story_array[i-1];buffer[buffer.length]=c+". <a  href='/s/"+story.storyid+"/1/'>";buffer[buffer.length]=story.stitle+"</a>&nbsp;";if(show_author==1)buffer[buffer.length]="by <a href='/u/"+story.userid+"/'>"+story.penname+"</a> ";if(story.ratingtimes>0)buffer[buffer.length]="<a class=reviews href='/r/"+story.storyid+"/0/1/'>reviews</a>";buffer[buffer.length]="<blockquote>"+story.summary+"<br><span class='gray' style='font-size=11px'>";if(story.statusid==2)buffer[buffer.length]="Complete - ";if(show_cat==1)buffer[buffer.length]=story.category+" - ";buffer[buffer.length]=array_censors[story.censorid]+" - ";buffer[buffer.length]=array_languages[story.languageid]+" - ";if(story.genreid>0){buffer[buffer.length]=array_genres[story.genreid];if(story.subgenreid>0){buffer[buffer.length]="/"+array_genres[story.subgenreid];}}else if(story.subgenreid>0){buffer[buffer.length]=array_genres[story.subgenreid]+" - ";}buffer[buffer.length]=" - Chapters: "+story.chapters+" - Words: "+story.wordcount+" - Reviews: "+story.ratingtimes+" - Updated: "+story.dateupdatetext+" - Published: "+story.datesubmittext+"</span></blockquote>";}return buffer.join("");}function get_html_obj(htmlid){if(document.getElementById){return document.getElementById(htmlid);}else if(document.all){return document.all[htmlid];}else return null;}function storylist_draw(htmlid,story_array,startrow,show_cat,show_author){var result=storylist_render(story_array,startrow,show_cat,show_author);if(result.length<=0)return 0;var htmlobj=get_html_obj(htmlid);htmlobj.innerHTML=result;}var bio=true;function toggleBio(htmlid){var htmlobj=get_html_obj(htmlid);if(bio){switchLayer('bio',false);bio=false;htmlobj.innerHTML="<a href='javascript:toggleBio(\"bio_text\");'>show bio</a>";}else{switchLayer('bio',true);bio=true;htmlobj.innerHTML="<a href='javascript:toggleBio(\"bio_text\");'>hide bio</a>";}}function isenter(myfield,e){var keycode;if(window.event)keycode=window.event.keyCode;else if(e)keycode=e.which;else return false;if(keycode==13){return true;}else{return false;}}function submitenter(myfield,e){var keycode;if(window.event)keycode=window.event.keyCode;else if(e)keycode=e.which;else return true;if(keycode==13){myfield.form.submit();return false;}else{return true;}}
