function setCookie(name, value, expires)
{
    var secure = false;
    document.cookie= info_cookie_id + name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        "; path=" + info_cookie_path +
        "; domain=" + info_cookie_domain +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    name = info_cookie_id + name;
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return '';
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//deleteCookie('quotedposts')
var quotedPosts = getCookie('quotedposts');
quotedPosts=typeof(quotedPosts)=='null'?'':quotedPosts;
quotedPosts = new String(quotedPosts);
var lastQuoteTopicId = getCookie('lastquotetopic');
function toggleQuote( id )
{
    var quoteRegexp=new RegExp(current_topic_id+':'+id+',','g');
    if(quotedPosts.match(quoteRegexp))
    {
        quotedPosts=quotedPosts.replace(quoteRegexp,'');
        imagePath=macro_quote_add_img;
    }
    else
    {
        if(lastQuoteTopicId!=''&&lastQuoteTopicId!=current_topic_id)
        {
            if(confirm(lang_qa_clear_all_quotes))
            //var quoteRegexp=new RegExp('^|;'+current_topic_id+':'+id+',','g');
            quotedPosts='';
        }
        quotedPosts+=current_topic_id+':'+id+',';
        imagePath=macro_quote_add_on_img;
    }
    setCookie('quotedposts',quotedPosts);
    setCookie('lastquotetopic',current_topic_id)
    lastQuoteTopicId=current_topic_id;
    return imagePath;
}

function quoteImage( id )
{
    var quoteImg = macro_quote_add;
    var quoteRegexp=new RegExp(current_topic_id+':'+id+',','g');
    if(quotedPosts.match(quoteRegexp))
    {
        quoteImg = macro_quote_add_on;
    }
    quoteImg=quoteImg.replace('{ONCLICK}','this.src=toggleQuote('+id+')');
    return quoteImg;
}