// dwr zmodyfikowany dla opinii
if (ForumDWR == null) {
var ForumDWR = {};
ForumDWR.setErrorHandler = function(handler) {
ForumDWR._errorHandler = handler;
};
ForumDWR.setWarningHandler = function(handler) {
ForumDWR._warningHandler = handler;
};

ForumDWR.setTimeout = function(timeout) {
ForumDWR._timeout = timeout;
};

ForumDWR.setPreHook = function(handler) {
ForumDWR._preHook = handler;
};

ForumDWR.setPostHook = function(handler) {
ForumDWR._postHook = handler;
};

ForumDWR.XMLHttpRequest = 1;
ForumDWR.IFrame = 2;

ForumDWR.setMethod = function(newMethod) {
if (newMethod != ForumDWR.XMLHttpRequest && newMethod != ForumDWR.IFrame) {
ForumDWR._handleError("Remoting method must be one of ForumDWR.XMLHttpRequest or ForumDWR.IFrame");
return;
}
ForumDWR._method = newMethod;
};

ForumDWR.setVerb = function(verb) {
if (verb != "GET" && verb != "POST") {
ForumDWR._handleError("Remoting verb must be one of GET or POST");
return;
}
ForumDWR._verb = verb;
};

ForumDWR.setOrdered = function(ordered) {
ForumDWR._ordered = ordered;
};
ForumDWR.setAsync = function(async) {
ForumDWR._async = async;
};

ForumDWR.setTextHtmlHandler = function(handler) {
ForumDWR._textHtmlHandler = handler;
}
ForumDWR.defaultMessageHandler = function(message) {
if (typeof message == "object" && message.name == "Error" && message.description) {
alert("Error: " + message.description);
}
else {

if (message.toString().indexOf("0x80040111") == -1) {
alert(message);
}
}
};

ForumDWR.beginBatch = function() {
if (ForumDWR._batch) {
ForumDWR._handleError("Batch already started.");
return;
}

ForumDWR._batch = {
map:{ callCount:0 },
paramCount:0,
ids:[],
preHooks:[],
postHooks:[]
};
};

ForumDWR.endBatch = function(options) {
var batch = ForumDWR._batch;
if (batch == null) {
ForumDWR._handleError("No batch in progress.");
return;
}
if (options && options.preHook) batch.preHooks.unshift(options.preHook);
if (options && options.postHook) batch.postHooks.push(options.postHook);
if (ForumDWR._preHook) batch.preHooks.unshift(ForumDWR._preHook);
if (ForumDWR._postHook) batch.postHooks.push(ForumDWR._postHook);
if (batch.method == null) batch.method = ForumDWR._method;
if (batch.verb == null) batch.verb = ForumDWR._verb;
if (batch.async == null) batch.async = ForumDWR._async;
if (batch.timeout == null) batch.timeout = ForumDWR._timeout;
batch.completed = false;
ForumDWR._batch = null;
if (!ForumDWR._ordered) {
ForumDWR._sendData(batch);
ForumDWR._batches[ForumDWR._batches.length] = batch;
}
else {
if (ForumDWR._batches.length == 0) {

ForumDWR._sendData(batch);
ForumDWR._batches[ForumDWR._batches.length] = batch;
}
else {

ForumDWR._batchQueue[ForumDWR._batchQueue.length] = batch;
}
}
};

ForumDWR._errorHandler = ForumDWR.defaultMessageHandler;
ForumDWR._warningHandler = ForumDWR.defaultMessageHandler;
ForumDWR._preHook = null;
ForumDWR._postHook = null;
ForumDWR._batches = [];
ForumDWR._batchQueue = [];
ForumDWR._handlersMap = {};
ForumDWR._method = ForumDWR.XMLHttpRequest;
ForumDWR._verb = "POST";
ForumDWR._ordered = false;
ForumDWR._async = true;
ForumDWR._batch = null;
ForumDWR._timeout = 0;
ForumDWR._DOMDocument = ["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"];
ForumDWR._XMLHTTP = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];

ForumDWR._execute = function(path, scriptName, methodName, vararg_params) {
var singleShot = false;
if (ForumDWR._batch == null) {
ForumDWR.beginBatch();
singleShot = true;
}

var args = [];
for (var i = 0; i < arguments.length - 3; i++) {
args[i] = arguments[i + 3];
}

if (ForumDWR._batch.path == null) {
ForumDWR._batch.path = path;
}
else {
if (ForumDWR._batch.path != path) {
ForumDWR._handleError("Can't batch requests to multiple DWR Servlets.");
return;
}
}

var params;
var callData;
var firstArg = args[0];
var lastArg = args[args.length - 1];

if (typeof firstArg == "function") {
callData = { callback:args.shift() };
params = args;
}
else if (typeof lastArg == "function") {
callData = { callback:args.pop() };
params = args;
}
else if (lastArg != null && typeof lastArg == "object" && lastArg.callback != null && typeof lastArg.callback == "function") {
callData = args.pop();
params = args;
}
else if (firstArg == null) {

if (lastArg == null && args.length > 2) {
ForumDWR._handleError("Ambiguous nulls at start and end of parameter list. Which is the callback function?");
}
callData = { callback:args.shift() };
params = args;
}
else if (lastArg == null) {
callData = { callback:args.pop() };
params = args;
}
else {
ForumDWR._handleError("Missing callback function or metadata object.");
return;
}

var random = Math.floor(Math.random() * 10001);
var id = (random + "_" + new Date().getTime()).toString();
var prefix = "c" + ForumDWR._batch.map.callCount + "-";
ForumDWR._batch.ids.push(id);

if (callData.method != null) {
ForumDWR._batch.method = callData.method;
delete callData.method;
}
if (callData.verb != null) {
ForumDWR._batch.verb = callData.verb;
delete callData.verb;
}
if (callData.async != null) {
ForumDWR._batch.async = callData.async;
delete callData.async;
}
if (callData.timeout != null) {
ForumDWR._batch.timeout = callData.timeout;
delete callData.timeout;
}


if (callData.preHook != null) {
ForumDWR._batch.preHooks.unshift(callData.preHook);
delete callData.preHook;
}
if (callData.postHook != null) {
ForumDWR._batch.postHooks.push(callData.postHook);
delete callData.postHook;
}


if (callData.errorHandler == null) callData.errorHandler = ForumDWR._errorHandler;
if (callData.warningHandler == null) callData.warningHandler = ForumDWR._warningHandler;

ForumDWR._handlersMap[id] = callData;
ForumDWR._batch.map[prefix + "scriptName"] = scriptName;
ForumDWR._batch.map[prefix + "methodName"] = methodName;
ForumDWR._batch.map[prefix + "id"] = id;
for (i = 0; i < params.length; i++) {
ForumDWR._serializeAll(ForumDWR._batch, [], params[i], prefix + "param" + i);
}
ForumDWR._batch.map.callCount++;
if (singleShot) {
ForumDWR.endBatch();
}
};

ForumDWR._sendData = function(batch) {
if (batch.map.callCount == 0) return;
for (var i = 0; i < batch.preHooks.length; i++) {
batch.preHooks[i]();
}
batch.preHooks = null;
if (batch.timeout && batch.timeout != 0) {
batch.interval = setInterval(function() { ForumDWR._abortRequest(batch); }, batch.timeout);
}
var urlPostfix;
if (batch.map.callCount == 1) {
urlPostfix = batch.map["c0-scriptName"] + "." + batch.map["c0-methodName"] + ".dwr";
}
else {
urlPostfix = "Multiple." + batch.map.callCount + ".dwr";
}
if (batch.method == ForumDWR.XMLHttpRequest) {
if (window.XMLHttpRequest) {
batch.req = new XMLHttpRequest();
}
else if (window.ActiveXObject && !(navigator.userAgent.indexOf("Mac") >= 0 && navigator.userAgent.indexOf("MSIE") >= 0)) {
batch.req = ForumDWR._newActiveXObject(ForumDWR._XMLHTTP);
}
}

var query = "";
var prop;
if (batch.req) {
batch.map.xml = "true";
if (batch.async) {
batch.req.onreadystatechange = function() { ForumDWR._stateChange(batch); };
}
var indexSafari = navigator.userAgent.indexOf("Safari/");
if (indexSafari >= 0) {
var version = navigator.userAgent.substring(indexSafari + 7);
if (parseInt(version, 10) < 400) batch.verb == "GET";
}
if (batch.verb == "GET") {
batch.map.callCount = "" + batch.map.callCount;
for (prop in batch.map) {
var qkey = encodeURIComponent(prop);
var qval = encodeURIComponent(batch.map[prop]);
if (qval == "") ForumDWR._handleError("Found empty qval for qkey=" + qkey);
query += qkey + "=" + qval + "&";
}
try {
batch.req.open("GET", batch.path + "/exec/" + urlPostfix + "?" + query, batch.async);
batch.req.send(null);
if (!batch.async) ForumDWR._stateChange(batch);
}
catch (ex) {
ForumDWR._handleMetaDataError(null, ex);
}
}
else {
for (prop in batch.map) {
if (typeof batch.map[prop] != "function") {
query += prop + "=" + batch.map[prop] + "\n";
}
}

try {
batch.req.open("POST", batch.path + "/exec/" + urlPostfix, batch.async);
batch.req.setRequestHeader('Content-Type', 'text/plain');
batch.req.send(query);
if (!batch.async) ForumDWR._stateChange(batch);
}
catch (ex) {
ForumDWR._handleMetaDataError(null, ex);
}
}
}
else {
batch.map.xml = "false";
var idname = "dwr-if-" + batch.map["c0-id"];

batch.div = document.createElement("div");
batch.div.innerHTML = "<iframe src='javascript:void(0)' frameborder='0' width='0' height='0' id='" + idname + "' name='" + idname + "'></iframe>";
document.body.appendChild(batch.div);
batch.iframe = document.getElementById(idname);
batch.iframe.setAttribute("style", "width:0px; height:0px; border:0px;");

if (batch.verb == "GET") {
for (prop in batch.map) {
if (typeof batch.map[prop] != "function") {
query += encodeURIComponent(prop) + "=" + encodeURIComponent(batch.map[prop]) + "&";
}
}
query = query.substring(0, query.length - 1);

batch.iframe.setAttribute("src", batch.path + "/exec/" + urlPostfix + "?" + query);
document.body.appendChild(batch.iframe);
}
else {
batch.form = document.createElement("form");
batch.form.setAttribute("id", "dwr-form");
batch.form.setAttribute("action", batch.path + "/exec" + urlPostfix);
batch.form.setAttribute("target", idname);
batch.form.target = idname;
batch.form.setAttribute("method", "POST");
for (prop in batch.map) {
var formInput = document.createElement("input");
formInput.setAttribute("type", "hidden");
formInput.setAttribute("name", prop);
formInput.setAttribute("value", batch.map[prop]);
batch.form.appendChild(formInput);
}
document.body.appendChild(batch.form);
batch.form.submit();
}
}
};


ForumDWR._stateChange = function(batch) {
if (!batch.completed && batch.req.readyState == 4) {
try {
var reply = batch.req.responseText;

if (reply == null || reply == "") {
ForumDWR._handleMetaDataWarning(null, "No data received from server");
}
else {
var contentType = batch.req.getResponseHeader("Content-Type");
if (!contentType.match(/^text\/plain/) && !contentType.match(/^text\/javascript/)) {
if (ForumDWR._textHtmlHandler && contentType.match(/^text\/html/)) {
ForumDWR._textHtmlHandler();
}
else {
ForumDWR._handleMetaDataWarning(null, "Invalid content type from server: '" + contentType + "'");
}
}
else {

if (reply.search("DWREngine._handle") == -1) {
	ForumDWR._handleMetaDataWarning(null, "Invalid reply from server");
}
else {
	reply = reply.replace(/DWREngine/,"ForumDWR");
	eval(reply);
}
}
}
ForumDWR._clearUp(batch);
}
catch (ex) {
if (ex == null) ex = "Unknown error occured";
ForumDWR._handleMetaDataWarning(null, ex);
}
finally {
if (ForumDWR._batchQueue.length != 0) {
var sendbatch = ForumDWR._batchQueue.shift();
ForumDWR._sendData(sendbatch);
ForumDWR._batches[ForumDWR._batches.length] = sendbatch;
}
}
}
};

ForumDWR._handleResponse = function(id, reply) {

var handlers = ForumDWR._handlersMap[id];
ForumDWR._handlersMap[id] = null;

if (handlers) {
try {
if (handlers.callback) handlers.callback(reply);
}
catch (ex) {
ForumDWR._handleMetaDataError(handlers, ex);
}
}


if (ForumDWR._method == ForumDWR.IFrame) {
var responseBatch = ForumDWR._batches[ForumDWR._batches.length-1];

if (responseBatch.map["c"+(responseBatch.map.callCount-1)+"-id"] == id) {
ForumDWR._clearUp(responseBatch);
}
}
};


ForumDWR._handleServerError = function(id, error) {

var handlers = ForumDWR._handlersMap[id];
ForumDWR._handlersMap[id] = null;

if (error.message) ForumDWR._handleMetaDataError(handlers, error.message, error);
else ForumDWR._handleMetaDataError(handlers, error);
};


ForumDWR._eval = function(script) {
return eval(script);
}


ForumDWR._abortRequest = function(batch) {
if (batch && !batch.completed) {
clearInterval(batch.interval);
ForumDWR._clearUp(batch);
if (batch.req) batch.req.abort();

var handlers;
for (var i = 0; i < batch.ids.length; i++) {
handlers = ForumDWR._handlersMap[batch.ids[i]];
ForumDWR._handleMetaDataError(handlers, "Timeout");
}
}
};


ForumDWR._clearUp = function(batch) {
if (batch.completed) {
ForumDWR._handleError("Double complete");
return;
}


if (batch.div) batch.div.parentNode.removeChild(batch.div);
if (batch.iframe) batch.iframe.parentNode.removeChild(batch.iframe);
if (batch.form) batch.form.parentNode.removeChild(batch.form);


if (batch.req) delete batch.req;

for (var i = 0; i < batch.postHooks.length; i++) {
batch.postHooks[i]();
}
batch.postHooks = null;


for (var i = 0; i < ForumDWR._batches.length; i++) {
if (ForumDWR._batches[i] == batch) {
ForumDWR._batches.splice(i, 1);
break;
}
}

batch.completed = true;
};


ForumDWR._handleError = function(reason, ex) {
if (ForumDWR._errorHandler) ForumDWR._errorHandler(reason, ex);
};


ForumDWR._handleWarning = function(reason, ex) {
if (ForumDWR._warningHandler) ForumDWR._warningHandler(reason, ex);
};


ForumDWR._handleMetaDataError = function(handlers, reason, ex) {
if (handlers && typeof handlers.errorHandler == "function") handlers.errorHandler(reason, ex);
else ForumDWR._handleError(reason, ex);
};


ForumDWR._handleMetaDataWarning = function(handlers, reason, ex) {
if (handlers && typeof handlers.warningHandler == "function") handlers.warningHandler(reason, ex);
else ForumDWR._handleWarning(reason, ex);
};


ForumDWR._serializeAll = function(batch, referto, data, name) {
if (data == null) {
batch.map[name] = "null:null";
return;
}

switch (typeof data) {
case "boolean":
batch.map[name] = "boolean:" + data;
break;
case "number":
batch.map[name] = "number:" + data;
break;
case "string":
batch.map[name] = "string:" + encodeURIComponent(data);
break;
case "object":
if (data instanceof String) batch.map[name] = "String:" + encodeURIComponent(data);
else if (data instanceof Boolean) batch.map[name] = "Boolean:" + data;
else if (data instanceof Number) batch.map[name] = "Number:" + data;
else if (data instanceof Date) batch.map[name] = "Date:" + data.getTime();
else if (data instanceof Array) batch.map[name] = ForumDWR._serializeArray(batch, referto, data, name);
else batch.map[name] = ForumDWR._serializeObject(batch, referto, data, name);
break;
case "function":

break;
default:
ForumDWR._handleWarning("Unexpected type: " + typeof data + ", attempting default converter.");
batch.map[name] = "default:" + data;
break;
}
};


ForumDWR._lookup = function(referto, data, name) {
var lookup;

for (var i = 0; i < referto.length; i++) {
if (referto[i].data == data) {
lookup = referto[i];
break;
}
}
if (lookup) return "reference:" + lookup.name;
referto.push({ data:data, name:name });
return null;
};


ForumDWR._serializeObject = function(batch, referto, data, name) {
var ref = ForumDWR._lookup(referto, data, name);
if (ref) return ref;



if (data.nodeName && data.nodeType) {
return ForumDWR._serializeXml(batch, referto, data, name);
}


var reply = "Object:{";
var element;
for (element in data) {
batch.paramCount++;
var childName = "c" + ForumDWR._batch.map.callCount + "-e" + batch.paramCount;
ForumDWR._serializeAll(batch, referto, data[element], childName);

reply += encodeURIComponent(element) + ":reference:" + childName + ", ";
}

if (reply.substring(reply.length - 2) == ", ") {
reply = reply.substring(0, reply.length - 2);
}
reply += "}";

return reply;
};


ForumDWR._serializeXml = function(batch, referto, data, name) {
var ref = ForumDWR._lookup(referto, data, name);
if (ref) return ref;

var output;
if (window.XMLSerializer) output = new XMLSerializer().serializeToString(data);
else output = data.toXml;

return "XML:" + encodeURIComponent(output);
};


ForumDWR._serializeArray = function(batch, referto, data, name) {
var ref = ForumDWR._lookup(referto, data, name);
if (ref) return ref;

var reply = "Array:[";
for (var i = 0; i < data.length; i++) {
if (i != 0) reply += ",";
batch.paramCount++;
var childName = "c" + ForumDWR._batch.map.callCount + "-e" + batch.paramCount;
ForumDWR._serializeAll(batch, referto, data[i], childName);
reply += "reference:";
reply += childName;
}
reply += "]";

return reply;
};


ForumDWR._unserializeDocument = function(xml) {
var dom;
if (window.DOMParser) {
var parser = new DOMParser();
dom = parser.parseFromString(xml, "text/xml");
if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
var message = dom.documentElement.firstChild.data;
message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
throw message;
}
return dom;
}
else if (window.ActiveXObject) {
dom = ForumDWR._newActiveXObject(ForumDWR._DOMDocument);
dom.loadXML(xml);
return dom;
}
else {
var div = document.createElement("div");
div.innerHTML = xml;
return div;
}
};





ForumDWR._newActiveXObject = function(axarray) {
var returnValue;
for (var i = 0; i < axarray.length; i++) {
try {
returnValue = new ActiveXObject(axarray[i]);
break;
}
catch (ex) {   }
}
return returnValue;
};


if (typeof window.encodeURIComponent === 'undefined') {
ForumDWR._utf8 = function(wide) {
wide = "" + wide;
var c;
var s;
var enc = "";
var i = 0;
while (i < wide.length) {
c = wide.charCodeAt(i++);

if (c >= 0xDC00 && c < 0xE000) continue;
if (c >= 0xD800 && c < 0xDC00) {
if (i >= wide.length) continue;
s = wide.charCodeAt(i++);
if (s < 0xDC00 || c >= 0xDE00) continue;
c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
}

if (c < 0x80) {
enc += String.fromCharCode(c);
}
else if (c < 0x800) {
enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
}
else if (c < 0x10000) {
enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
else {
enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
}
return enc;
}

ForumDWR._hexchars = "0123456789ABCDEF";

ForumDWR._toHex = function(n) {
return ForumDWR._hexchars.charAt(n >> 4) + ForumDWR._hexchars.charAt(n & 0xF);
}

ForumDWR._okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

window.encodeURIComponent = function(s)  {
s = ForumDWR._utf8(s);
var c;
var enc = "";
for (var i= 0; i<s.length; i++) {
if (ForumDWR._okURIchars.indexOf(s.charAt(i)) == -1) {
enc += "%" + ForumDWR._toHex(s.charCodeAt(i));
}
else {
enc += s.charAt(i);
}
}
return enc;
}
}

if (typeof Array.prototype.splice === 'undefined') {
Array.prototype.splice = function(ind, cnt)
{
if (arguments.length == 0) return ind;
if (typeof ind != "number") ind = 0;
if (ind < 0) ind = Math.max(0,this.length + ind);
if (ind > this.length) {
if (arguments.length > 2) ind = this.length;
else return [];
}
if (arguments.length < 2) cnt = this.length-ind;

cnt = (typeof cnt == "number") ? Math.max(0, cnt) : 0;
removeArray = this.slice(ind, ind + cnt);
endArray = this.slice(ind + cnt);
this.length = ind;

for (var i = 2; i < arguments.length; i++) this[this.length] = arguments[i];
for (i = 0; i < endArray.length; i++) this[this.length] = endArray[i];

return removeArray;
}
}

if (typeof Array.prototype.shift === 'undefined') {
Array.prototype.shift = function(str) {
var val = this[0];
for (var i = 1; i < this.length; ++i) this[i - 1] = this[i];
this.length--;
return val;
}
}

if (typeof Array.prototype.unshift === 'undefined') {
Array.prototype.unshift = function() {
var i = unshift.arguments.length;
for (var j = this.length - 1; j >= 0; --j) this[j + i] = this[j];
for (j = 0; j < i; ++j) this[j] = unshift.arguments[j];
}
}
if (typeof Array.prototype.push === 'undefined') {
Array.prototype.push = function() {
var sub = this.length;
for (var i = 0; i < push.arguments.length; ++i) {
this[sub] = push.arguments[i];
sub++;
}
}
}
if (typeof Array.prototype.pop === 'undefined') {
Array.prototype.pop = function() {
var lastElement = this[this.length - 1];
this.length--;
return lastElement;
}
}
}

function AjaxForum() { }
AjaxForum._path = '/forum/dwr';
AjaxForum.login = function(p0, p1, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'login', p0, p1, false, false, callback);
}
AjaxForum.logout = function(callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'logout', false, false, callback);
}
AjaxForum.getThread = function(p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'getThread', false, false, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, callback);
}
AjaxForum.getOpinionThread = function(p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'getOpinionThread', false, false, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, callback);
}
AjaxForum.getSendModel = function(p2, p3, p4, p5, p6, p7, p8, p9, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'getSendModel', false, false, p2, p3, p4, p5, p6, p7, p8, p9, callback);
}
AjaxForum.ajaxSendPost = function(p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'ajaxSendPost', false, false, false, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, callback);
}
AjaxForum.getPreview = function(p1, p2, p3, p4, callback) {
    ForumDWR._execute(AjaxForum._path, 'AjaxForum', 'getPreview', false, p1, p2, p3, p4, callback);
}

function glosuj(x,fx)
{
  if( confirm('Jeste¶ pewien, że ten komentarz powinien być skasowany ?') ){
	window.open('http://forum.gazeta.pl/forum/info/forum/zgloszenie.jsp?f='+fx+'&glos=0&a='+x,'_blank','toolbar=no, directories=no, location=no,status=yes, menubar=no, resizable=no, scrollbars=no, width=300, height=200, top=200,left=200');
  }
}


function loadOpinion(){
	if( urlctx  && ! oType ){
	 oType = 'V_'+urlctx.toUpperCase();
	}
	addPostForm();
}

function addPostForm()
{
	progressInfo('opinions','Ładowanie opinii ');

	AjaxForum.getSendModel(fId,
		caId,
		wId,
		pId,
		oId,
		a_xx,
		oType,
		rep, addPostFView
	);
}

function addPostFView(data)
{
  progressInfoOff(true);
  if( data.newPost == null ){
	  getElement('opinions').innerHTML = '<span style="color:#aaa;">Opinie nie podł±czone !</span>';
	  return;
  }
  showElement('addPost');
  if( rep == 2)	{
   getElement('postBody').value=data.newPost.body;
  }
  if( data.newPost.replySubject != null)
    getElement('pSubject').value=data.newPost.replySubject;
  else if( data.opinion != null && data.opinion.title != null)
    getElement('pSubject').value=data.opinion.title;

  if( data.newPost.author != null ){
	getElement('pAuthor').value=data.newPost.author;
  }

  if( data.login_required  != null ){
	 getElement('logHas').innerHTML='Login: ';
	 getElement('komInf').innerHTML='Zaloguj się ';
  }

  if( data.opinion != null ){
	fId = data.opinion.forumId;
	wId = data.opinion.threadId;
	oId = data.opinion.id;
	if( wId>0){
		loadForumThread();
	}
  }
  
}

function addPostPreview()
{
	var f = getElement('addPostForm');
	AjaxForum.getPreview(fId,
		f.body.value,
		f.author.value,
		f.subject.value,
		addPostPreviewView
	);
}

function addPostPreviewView(data)
{
  getElement('pvMsg').innerHTML = data.preview.body+'<div><a href="javascript:previewOff()">Powrót</a></div>';
  showElement('pvMsg');
  hideElement('pvHide');
}

function previewOff()
{
  hideElement('pvMsg');
  showElement('pvHide');
  getElement('pvMsg').innerHTML ='';
}

function addPost(f)
{

	if(  getElement("pUsername")!=null && !isEmpty(getElement("pUsername").value) &&
			getElement("pPassword")!=null && !isEmpty(getElement("pPassword").value) ) {
		addPostLogin(getElement("pUsername").value, getElement("pPassword").value);
		return;
	}else if( isEmpty(f.author.value) && getElement("pUsername")!=null ){
		f.author.value = getElement("pUsername").value;
	}

	addPostContinue(f);
}

function addPostContinue(f)
{

	if( isEmpty(f.author.value) ){
		getElement("addPMsg").innerHTML = 'Wypełnij pole autor!';
		return;
	}

	if( isEmpty(f.body.value) ){
		getElement("addPMsg").innerHTML = 'Wypełnij tre¶ć komentarza !';
		return;
	}

	progressInfo('addPMsg','Trwa wysyłanie ');
		
	AjaxForum.ajaxSendPost(
		fId,
		caId,
		wId,
		pId,
		oId,
		a_xx,
		oType,
		'',
		rep,
		f.author.value,
		f.subject.value,
		f.body.value,
		wId,
		formId,
		null, //f.author.value
		'false',
		addPostView);

	return;
}

function addPostView(data){

  progressInfoOff(true);
  if( data.msg != null ){
	if( data.msg.match(/^Nie masz upra.*/) ){
		data.msg = "Komentarze mog± publikować tylko zalogowani użytkownicy. Zaloguj się żeby komentować.";
	}
	getElement("addPMsg").innerHTML = data.msg;
  }else{
	getElement("addPMsg").innerHTML = '';
  }

  if( data.post_created != null && data.post_created == true ){
	formId-=1;
	getElement("addPost").innerHTML = 'Komentarz dodany <a href="javascript:commentLink()">skomentuj ponownie</a>';
	if ( typeof( data.threadSize ) != "undefined" && tOrder == 0 ) {
	   tPage = Math.floor( (data.threadSize+1)/pSize );
	}
	loadForumThread();
  }else{
 	 getElement('pvMsg').innerHTML = '';
  }
}

function commentLink(){
	window.location.href = window.location.href+'#comments' ;
	window.location.reload();
}

function addPostLogin(username,password) {
	progressInfo('addPMsg','Trwa wysyłanie ');
        AjaxForum.login(username, password, showAddPostLogin);
}

function doLogout(f) {
        AjaxForum.logout(showLogout);
}


function showAddPostLogin(data) {
	progressInfoOff(true);
	if (data.msg == "OK") {
			getElement("loginMsg").innerHTML = '';
		getElement('addPostForm').author.value = data.username;
		cUser = data.username;
		addPostContinue(getElement('addPostForm'));
	} else {
		if( data.msg == 'Hasło jest nieprawidłowe.'){
			getElement("loginMsg").innerHTML = data.msg+' Spróbuj innego. Możesz je też <a href="http://konto.gazeta.pl/konto/3481802,2,,,,,,3.html">odzyskać</a>.';
		}else{
		   alert('inny błąd logowania');
		   getElement("loginMsg").innerHTML = data.msg;
		}
	}
}

function showLogout(data) {

	var ihtml = '<div class="pseuL titA">Autor:</div>';
	ihtml+= '<div class="pseuR">';
	ihtml+=	'<span id="loginForm">';
	ihtml+=	'<span id="loginMsg"></span>';
	ihtml+=	'<form name="loginForm">';
	ihtml+=	'<span style="margin-right:100px;">Login / Pseudonim: </span> <span class="">Hasło: </span>';
	ihtml+=	'<div>';
	ihtml+=	'<input class="itxt" id="pUsername" name="username" type="text"> ';
	ihtml+=	'<input class="itxt" id="pPassword" name="password" type="password"> ';
	ihtml+=	'</div>';
	ihtml+=	'<div>Komentuj pod pseudonimem jako Go¶ć lub zaloguj się | ';
	ihtml+=	'  <a href="http://konto.gazeta.pl/konto/3481801,2,,,,,,1.html?back='+encodeURIComponent(document.location.href)+'" class="loginLink" title="">Załóż konto</a>';

	ihtml += '</div>';
	getElement('author').innerHTML = ihtml;
	getElement("loginMsg").innerHTML = '';
	getElement('addPostForm').author.value = '';
	cUser = '';
}


function selPage(p) {
	if( tPage != p-1 ){
		tPage = p-1;
		loadForumThread();
	}
	window.location.href = window.location.href.replace(/(.*)#.*/,"$1")+'#opinions';
}

function loadForumThread() {
   try{
	if( tV.length == 0 ){
		tV = '2';
	}
	progressInfo('opinionStatus','Ładowanie opinii ');
	AjaxForum.getOpinionThread(
		fId,
		caId,
		wId,
		pId,
		oId,
		a_xx,
		oType,
		tV,
		tOrder,
		tPage,pSize,
		threadView );
    }catch(e){
	    alert("Error: "+e);
	    return 0;
    }
    return 0;
}

function threadView(data)
{
    var i;
    var ihtml='';
    var pages = 0;
    var author_pat=/^G/;
    try{
    	var e = data.exit;
	if( e != null && e == true){
	  return 0;
	}

    	var l = data.posts.length;
	var p;
	var j;
	if( l>0){
		ihtml = '<div class="clr"></div><h6 style="">Komentarze: </h6>';
	}
    	for( i=0, j=1 ; i<l; i++, j=i%2+1 ){
		p = data.posts[i];
		if( p.body.indexOf('Wiadomo')==18 ){ continue; }
		ihtml +='<div class="koment'+j+'_top"></div>\n';
		ihtml +='<div class="koment'+j+'">\n';
		ihtml +='	<div class="koment'+j+'_l">\n';
		ihtml +='	<div class="komentarz">\n';
		ihtml +='		<span class="data">'+p.date+'</span><br>\n';
		if( author_pat.test(p.author) ){
			ihtml +='        <span class="autor">'+p.author+'</span>\n';
		}else{	
			ihtml +='        <span class="autor zalog">'+p.author+'</span>\n';
		}
		ihtml +=' <div class="data"><a href="javascript:glosuj('+p.id+','+data.forum.id+');"  alt="Skasujcie"'+
			' title="Skasujcie ten post - zgłoszenie do moderacji" class="del"><span></span></a></div>\n';
		ihtml +='	</div>\n';
		ihtml +='	</div>\n';
		ihtml +='	<div style="" class="koment'+j+'_r">'+p.body+'</div>\n';
		ihtml +='</div>\n';
		ihtml +='<div class="koment'+j+'_bottom"></div>\n';
	}

	if( data.thread.size>pSize){
		ihtml += '<div id="opPages">';
		pages = Math.ceil(data.thread.size/pSize);
		if( tPage>0 ){
			ihtml += '<span class="prev"><a href="javascript:selPage('+tPage+')">&laquo; poprzednie</a></span>';
		}
		ihtml += '<span class="all">';
		for( i=1; i<= pages; i++){
			if( i == tPage+1){
				ihtml += '<span class="sel">'+i+'</span>';
			}else{
				ihtml += '<a href="javascript:selPage('+i+')">'+i+'</a>';
			}
		}
		ihtml += '</span>';
		if( tPage+1<pages ){
			ihtml += '<span class="next"><a href="javascript:selPage('+(tPage+2)+')">następne &raquo;</a></span>';
		}
		ihtml += '</div>';
	}

	getElement('opinions').innerHTML = ihtml;
    }catch(e){
		progressInfoOff(true);
		alert('Error '+e);
		return 0;
    }
    progressInfoOff(true);
    return 0;
}

var tMlynek = ['-','\\','|','/','-','\\','|','/'];
var progressPos=-1;
var progressMsg='Ładowanie opinii';
var progressEId='';

function progressInfo(pEId,msg)
{
  progressMsg = msg;
  progressEId = pEId;
  progressPos = 0;
  var elem = getElement(progressEId);
  if( elem != null ){
  	elem.innerHTML = '<span style="color:#F00;">'+progressMsg+tMlynek[progressPos]+'</span>';
  }
  setTimeout('setProgressInfo()',250);
  return true;
}

function setProgressInfo(){
  if( progressPos >= 0 ){
  	if( progressPos >7 ){
		progressPos = 0;
	}
	var elem = getElement(progressEId);
	if( elem != null ){
		elem.innerHTML = '<span style="color:#F00;">'+progressMsg+tMlynek[progressPos]+'</span>';
	}
  	progressPos = progressPos+1;
  	setTimeout('setProgressInfo()',250);
  }
}

function progressInfoOff(clr)
{
  progressPos = -1;	
  if( clr != null && clr == true){
  	  var elem = getElement(progressEId);
  	  if( elem != null ){
	  	getElement(progressEId).innerHTML = '';
	  }
  }
  return true;
}

