function change_width(mywidth)
{
	document.getElementById('my_wrapper').style.width = mywidth;
	setCookie("res", mywidth, (30*24));
		mywidth = mywidth.replace(/[^0-9]*/g,"");
		if ( mywidth == "95" )
		{
			mywidth = "100%";
			window.onerror = no_error;
			document.getElementById('fil').style.width = mywidth;
			mywidth = "-2px";
		}
		else
		{
			mywidth =  parseInt(mywidth) - 2 ;
			mywidth = mywidth + "px";
		}
		window.onerror = no_error;
		document.getElementById('fil').style.width = mywidth;
}
function no_error()
{
	return true;
}
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=/; domain=.buffynfaith.net;";
}
function multi_page_jump( url_bit, total_posts, per_page )
{
	pages = 1; cur_st = parseInt(""); cur_page  = 1;
	if ( total_posts % per_page == 0 )
	{
		pages = total_posts / per_page;
	}
	else
	{
		pages = Math.ceil( total_posts / per_page );
	}
	msg = "Please enter a page number to jump to between 1 and" + " " + pages;
	if ( cur_st > 0 )
	{
		cur_page = cur_st / per_page; cur_page = cur_page -1;
	}
	show_page = 1;
	if ( cur_page < pages )
	{
		show_page = cur_page + 1;
	}
	if ( cur_page >= pages )
	{
		show_page = cur_page - 1;
	}
	else
	{
		show_page = cur_page + 1;
	}
	userPage = prompt( msg, show_page );
	if ( userPage > 0  )
	{
		if ( userPage < 1 )     {    userPage = 1;  }
		if ( userPage > pages ) { userPage = pages; }
		if ( userPage == 1 )    {     start = 0;    }
		else { start = (userPage - 1) * per_page; }
		window.location = url_bit + start;
	}
}

var nn = 1;
function updateFontSize(direction) {
	myfontsize = document.getElementById('fanfiction').style.fontSize;
	myfontsize = myfontsize.replace(/px/, "");
	if( direction == 'u' && myfontsize <= 20 )
	{
		myfontsize++;
	}
	else if( myfontsize >= 8 )
	{
		myfontsize--;
	}

	if( myfontsize <= 20 && myfontsize >= 8 )
	{
		setCookie("myfontsize",myfontsize,3600);
		if( nn )
		{
			document.getElementById('fanfiction').style.fontSize = myfontsize + 'px';
		}
		else
		{
			document.storytext.style.fontSize = myfontsize + 'px';
		}
	}
}
function updateFontStyle(style) {
	var key = 5;
	var fontarray= new Array(5);
	fontarray[0]="Verdana";
	fontarray[1]="Sans";
	fontarray[2]="Arial";
	fontarray[3]="Helvetica";
	fontarray[4]="Tahoma";
	for ( i=0; i<5; i++ )
	{
		if ( fontarray[i] == document.getElementById('fanfiction').style.fontFamily )
		{
			key = i;
		}
	}
	if ( (key+1)<5 )
	{
		key = key + 1;
	}
	else
	{
		key = 0;
	}
	style = fontarray[key];
	setCookie('myfontstyle',style,3600);
	if( nn )
	{
		document.getElementById('fanfiction').style.fontFamily = style;
		document.getElementById('changefont').innerHTML = style;
	}
	else
	{
		document.storytext.style.fontFamily = style;
	}
}
function bg_changer()
{
	var formObject = document.getElementById('bg_changer');
	var ffobj = document.getElementById('fanfiction');
	formObject.style.backgroundColor = formObject.value;
	ffobj.style.backgroundColor = formObject.value;
	setCookie("mybgcolor",formObject.value,3600);
}
function text_changer()
{
	var formObject = document.getElementById('text_changer');
	var ffobj = document.getElementById('fanfiction');
	formObject.style.color = formObject.value;
	ffobj.style.color = formObject.value;
	setCookie("mytextcolor",formObject.value,3600);
}
function openwindow(act,rep,fid,cid)
{
	if ( act == "fav" )
	{
		var location = "./index.php?act=" + act + "&fid=" + fid + "&aid=" + cid + "&js=on";
	}
	else if ( act == "rep" )
	{
		var location = "./index.php?act=" + act + "&rep=" + rep + "&fid=" + fid + "&cid=" + cid + "&js=on";
	}
	else if ( act == "rea" )
	{
			var location = "./index.php?act=" + act + "&fid=" + fid + "&js=on";
	}
	else if ( act == "crd" )
	{
			var location = "./index.php?act=" + act + "&fid=" + fid + "&uid=" + cid + "&js=on";
	}
	else if ( act == "faq" )
	{
			if ( rep != "" ) rep = "&fei=" + rep;
			if ( fid != "" ) fid = "&par=" + fid;
			var location = "./index.php?act=" + act + rep + fid + "&js=on";
	}
	else
	{
		var location = "./index.php?act=" + act + "&fid=" + fid + "&cid=" + cid + "&js=on";
	}
	window.open(location, "phpmyfiction" + fid, "left="+ ((screen.width / 2)-300) + ",top=" + ((screen.height / 2)-200) + "), scrollbars=yes,resizable,height=400,width=600,top=0,left=0");
	return false;
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
function show_search()
{
	if ( document.getElementById('mna').value == "" )
	{
		alert("You can't leave this field empty!");
	}
	else
	{
		var title = trim(document.getElementById('mna').value);
	 	var location = "./index.php?act=msr&mna=" + title;
	 	window.open(location, "newwindow", "left="+ ((screen.width / 2)-150) + ",top=" + ((screen.height / 2)-50) + "),scrollbars=yes,height=100,width=300");
	}

}