function checkPass()
{
    if ($('#pw').val() == '')
    {
        alert('You must enter your password to make any changes!');
        $('#pw').focus();
        return false;
    }
    return true;
}


function change(what,val,update)
{
    switch(what)
    {
    case 'size':
        $('#main').css('font-size',  val);
        options = {size: val};
        if (update)
    		$.post('/account/options/?action=fontsize',options);
        break;
    case 'font':
        $('#main').css('font-family',  val);
		options = {font: val};
        if (update)
		    $.post('/account/options/?action=fontface',options);
        break;
    case 'width':
        $('#main').css('width',  val);
        break;
    }
}


function startResize()
{
    $('#m').html('');
    $('#m').hide();
}

function updateResize(resizable, event)
{
    var newWidth = event.size.width;
    $.cookie('fw', newWidth, { expires: 10, path: '/', domain: 'fanficauthors.net'});
    $.ajax(
        {
        type: "POST",
        url: '/account/options/',
        data: "width="+newWidth,
        success:resizeSaved,
        error: resizeError
        }
    );
    return false;

}
function resizeSaved()
{ 
    $('#m').html('Position saved');
    $('#m').show();
}

function resizeError()
{
    $('#m').html('Sorry, there was an error, please try again later');
    $('#m').show();
}

function resizeDiv()
{
    $("#main").resizable({minWidth:400,stop: updateResize, start: function () {$('#main').addClass('aCenter')}});
}

// review functions
var review = false;
function actionReview(url,type)
{
    var text = $('#review').val();
    if (type === 'newsreview')
    {
        if (review)
            return false;
        responseFunc = returnReview;
    }
    else if (type === 'review')
    {
        if (review)
            return false;
        responseFunc = returnStory;
    }
    else if (type === 'ragn')
    {
        if (review)
            return false;
        responseFunc = returnRagn;
    }
    else
    {
        responseFunc = returnPreview;
    }
    

    $.ajax(
        {
        type: "POST",
        url: url,
        data: {review: text, action : type},
        success:responseFunc,
        error: returnPreview
        }
    );
    return false;
}
// let's make a comment

// and some new lines
function returnPreview(XMLHttpRequest, textStatus)
{
    review = false;
    if ((typeof(XMLHttpRequest)) == 'string')
        var t = XMLHttpRequest;
    else
        var t = XMLHttpRequest.responseText;

    $('#reviewmsg').html("<p>"+t+'</p>');
}
function returnStory(transport)
{
    review = true;
    $('#reviewform').html('<div class="notes">Thank you, your review has been accepted.</div>');
}
function returnRagn(transport)
{
    review = true;
    document.location = $('#ragn').html();
}
function returnReview(transport,status)
{
    review = true;
    // set the review form to be emtpy
    $('#reviewform').html('');

    // add the new review
    $('#newreview').html(transport);

    // get the int of the pager total, increment it, and set it back
    var y = parseInt($('#pagerTotal').html());
    y++;
    $('#pagerTotal').html(y);

    // same again for the to value
    var t = parseInt($('#pagerTo').html());
    t++;
    $('#pagerTo').html(t);

    // move the window to the comments tag
    window.location.hash='comments';

    // return false to stop the form submitting
    return false;
}

function checkPasswordsMatch()
{
    if ($('#new_pass').val() == '' || $('#new_pass').val() !== $('#new_pass_dup').val())
    {
        $('#psubmit')[0].disabled = true;
        $('#p1').html("Passwords do not match");
        $('#p').show();
        $('#p1').show();
    }
    else
    {
        $('#psubmit')[0].disabled = false;
        $('#p1').innerHTML = "";
        $('#p').hide();
        $('#p1').hide();
    }
}

function checkUsername(url,fieldId)
{
    var username = $('#'+fieldId).val();
    if (username == '')
        return false;

    $.ajax(
        {
        type: "POST",
        url: url,
        data: "name="+username+"&type=check",
        success:usernameNotExists,
        error: usernameExists
        }
    );
    return false;
}

function usernameExists()
{

    $('#e').show();
    $('#e1').show();
    $('#e1').html("Username is already in use");
    $('#psubmit')[0].disabled = true;
}

function usernameNotExists()
{
    $('#psubmit')[0].disabled = false;
    $('#e1').html("");
    $('#e').hide();
    $('#e1').hide();
}
function checkEmail(url,fieldId)
{
    var email = $('#'+fieldId).val();

    if (email == '')
        return false;

    $.ajax(
        {
        type: "POST",
        url: url,
        data: "email_address="+email+"&type=check",
        success:emailNotExists,
        error: emailExists
        }
    );
    return false;
}
function emailNotExists()
{
    $('#psubmit')[0].disabled = false;
    $('#f1').html("");
    $('#f').hide();
    $('#f1').hide();
}
function emailExists()
{
    $('#f').show();
    $('#f1').show();
    $('#f1').html("An account with this email address already exists!  Use the <a href=\"/account/#lost\">lost password</a> form to continue");
    $('#psubmit')[0].disabled=true;
}
mySettings = {
	previewParserPath:	'/news/preview/', // path to your BBCode parser
	markupSet: [
		{name:'Bold', key:'B', openWith:'[b]', closeWith:'[/b]'},
		{name:'Italic', key:'I', openWith:'[i]', closeWith:'[/i]'},
		{name:'Underline', key:'U', openWith:'[u]', closeWith:'[/u]'},
		{separator:'---------------' },
		{name:'Picture', key:'P', replaceWith:'[img][![Url]!][/img]'},
		{name:'Link', key:'L', openWith:'[url=[![Url]!]]', closeWith:'[/url]', placeHolder:'Your text to link here...'},
		{separator:'---------------' },
		{name:'Quotes', openWith:'[quote]', closeWith:'[/quote]'}
	]
}



$(document).ready( function() {
$('ul.sf-menu').supersubs({ 
            minWidth:    12,    
            maxWidth:    27,    
            extraWidth:  1      
            }).superfish();

var fs = $.cookie('fs');
if (fs !== null && fs !== '')
    change('size',fs,false);
var ff = $.cookie('ff');
if (ff !== null && ff !== '')
    change('font',ff,false);
var fw = $.cookie('fw');
if (fw !== null && fw !== '' && $('#is').html() === '1')
{
    change('width',fw+'px',false);
    $('#main').addClass('aCenter'); 
}

$('#photos').galleryView({
    panel_width: 800,
    panel_height: 500,
    frame_width: 100,
    frame_height: 100,
    nav_theme: 'light'
});

} );
/**
 *
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
