var PCJSF_Encoding_CharMap =
	new Array(	'0','1','2','3','4','5','6','7','8','9',
				'a','b','c','d','e','f','g','h','i','j',
				'k','l','m','n','o','p','q','r','s','t',
				'u','v','x','y','z','A','B','C','D','E',
				'F','G','H','I','J','K','L','M','N','O',
				'P','Q','R','S','T','U','V','W','X','Y',
				'Z','@','^','~');

var PCJSF_Encoding_ReverseCharMap = new Array();
var PCJSF_Encoding_codea = "a".charCodeAt(0);
var PCJSF_Encoding_codez = "z".charCodeAt(0);
var PCJSF_Encoding_codeA = "A".charCodeAt(0);
var PCJSF_Encoding_codeZ = "Z".charCodeAt(0);
var PCJSF_Encoding_code0 = "0".charCodeAt(0);
var PCJSF_Encoding_code9 = "9".charCodeAt(0);
var PCJSF_Encoding_codeSpace = " ".charCodeAt(0);

function PCJSF_Encoding_BuildReverseCharMap(code)
{
	var i;
	for(i = 0; i < 128; i++)PCJSF_Encoding_ReverseCharMap.push(0);
	for(i = 0; i < PCJSF_Encoding_CharMap.length; i++)PCJSF_Encoding_ReverseCharMap[PCJSF_Encoding_CharMap[i].charCodeAt(0)] = i;
}

PCJSF_Encoding_BuildReverseCharMap();

function PCJSF_Encoding_IsNormal(code)
{
	return 	((code >= PCJSF_Encoding_codea) && (code <= PCJSF_Encoding_codez)) ||
			((code >= PCJSF_Encoding_codeA) && (code <= PCJSF_Encoding_codeZ)) ||
			((code >= PCJSF_Encoding_code0) && (code <= PCJSF_Encoding_code9)) ||
			(code == PCJSF_Encoding_codeSpace);
}

function PCJSF_Encoding_Encode(message)
{
    var encoded = "";
	var state = 0;
	for(var i = 0; i < message.length; i++)
	{
		var emit = state;
	    var code = message.charCodeAt(i) % 131072;
		var nSym = PCJSF_Encoding_IsNormal(code);
		if(state == 0)
		{
			if(!nSym)
			{
				emit = 1;
				if((i + 1 < message.length) && (!PCJSF_Encoding_IsNormal(message.charCodeAt(i + 1))))
				{
					encoded += "*";
					state = 1;
				}
				else
				{
					encoded += "%";
				}
			}
		}
		else
		{
			if(nSym && (i + 1 < message.length) && (PCJSF_Encoding_IsNormal(message.charCodeAt(i + 1))))
			{
				encoded += "!";
				emit = state = 0;
			}
		}
		if(emit)
		{
			if(code < 2048)
			{
				encoded += PCJSF_Encoding_CharMap[code % 64];
				encoded += PCJSF_Encoding_CharMap[PCJSF_SafeParseInt(code / 64)];
			}
			else
			{
				encoded += PCJSF_Encoding_CharMap[code % 64];
				encoded += PCJSF_Encoding_CharMap[32 + (PCJSF_SafeParseInt(code / 64) % 32)];
				encoded += PCJSF_Encoding_CharMap[PCJSF_SafeParseInt(code / 2048)];
			}
		}
		else
		{
			encoded += (code == PCJSF_Encoding_codeSpace) ? "_" : message.charAt(i);
		}
	}
	return encoded;
}

function PCJSF_Encoding_Decode(message)
{
	var decoded = "";
	var state = 0;
	var i = 0;
	while(i < message.length)
	{		
		var read  = state;
		var chr = message.charAt(i);
		if(state == 0)
		{
			if(chr == "*")
			{
				read = state = 1;
				i++;
				continue;
			}
			else if(chr == "%")
			{
				read = 1;
				i++;
			}
		}
		else
		{
			if(chr == "!")
			{
				read = state = 0;
				i++;
				continue;
			}
		}
		if(read)
		{
			if(i + 1 < message.length)
			{
				var d0 = PCJSF_Encoding_ReverseCharMap[message.charCodeAt(i)];
				var d1 = PCJSF_Encoding_ReverseCharMap[message.charCodeAt(i + 1)];
				i += 2;
				if(d1 < 32)
				{
					decoded += String.fromCharCode(d0 + d1 * 64);
				}
				else if(i < message.length)
				{
					var d2 = PCJSF_Encoding_ReverseCharMap[message.charCodeAt(i)];
					i++;
					decoded += String.fromCharCode(d0 + (d1 - 32) * 64 + d2 * 2048);
				}
				else break;
			}
			else break;
		}
		else
		{
			decoded += (chr == "_") ? " " : chr;
			i++;
		}
	}
	return decoded;
}
//URL to the master server
var PCJSF_Processor_IdentifyServerURL = "http://bannerchat.hu/PC21/MasterServer/";
var PCJSF_Processor_ServiceURL = "http://promptchat.com";

//Timeout when connecting to the master server
var PCJSF_Processor_IdentifyServerTimeout = 15000;

//Timeout when connecting to the chat server
var PCJSF_Processor_ServerTimeout = 15000;

//Timeout to reconnect after failed communication
var PCJSF_Processor_ReconnectTimeout = 15000;

//Lifetime in hours of the ServerURL cookie
var PCJSF_Processor_ServerURLCookieLifetime = 2;

//Number fo consequent communication errors that triger reconnect
var PCJSF_Processor_ConsequentErrorsToReconnect = 5;

//Period to automaticly connect to the server
var PCJSF_Tracker_UpdateTimeout = 8000;

//Monitoring cycle period
var PCJSF_Tracker_CyclePeriod = 100;

//Timeout to force window update if changed
var PCJSF_Tracker_WindowsSizeUpdateTime = 500;

//Window change to force update
var PCJSF_Tracker_WindowsSizeUpdateDistance = 200;

//Timeout to force scroll update if changed
var PCJSF_Tracker_ScrollUpdateTime = 500;

//Scroll change to force update
var PCJSF_Tracker_ScrollUpdateDistance = 100;

//Timeout to force mouse position update if changed
var PCJSF_Tracker_MousePositionUpdateTime = 500;

//Mosue position change to force update
var PCJSF_Tracker_MousePositionUpdateDistance = 100;

//Time after which it is considered that a page is abandoned
var PCJSF_Tracker_CookieActionTerminatedTimeout = 5000;

//Monitoring cycle period
PCJSF_Support_CyclePeriod = 100;
PCJSF_Support_CycleIEPeriod = 30;
PCJSF_Support_WFVUpdateTimeout = 8000;
PCJSF_Support_WFOUpdateTimeout = 8000;
PCJSF_Support_SESUpdateTimeout = 2000;
PCJSF_Support_LAMUpdateTimeout = 8000;
PCJSF_Support_OfferAnimPeriod = 30;
PCJSF_Support_OfferAutoMovePeriod = 5000;

PCJSF_Chat_MTStyle = "font-family:Tahoma;font-size:11px;font-weight:bold;color:#000000;";
PCJSF_Chat_MCStyle = "font-family:Tahoma;font-size:12px;font-weight:bool;color:#000000;";
PCJSF_Chat_OTStyle = "font-family:Tahoma;font-size:11px;font-weight:bold;color:#1f5d67;";
PCJSF_Chat_OCStyle = "font-family:Tahoma;font-size:12px;font-weight:bool;color:#000000;";

function PCJSF_SafeParseInt(value)
{
	var result = parseInt(value);
	return isNaN(result) ? 0 : result;
}

function PCJSF_Trim(str)
{
	while(str.length > 0)
	{
		var c = str.charAt(0);
		if((c == "\r") || (c == "\n") || (c == " "))str = str.substr(1);else break;
	}
	while(str.length > 0)
	{
		var c = str.charAt(str.length - 1);
		if((c == "\r") || (c == "\n") || (c == " "))str = str.substr(0, str.length - 1);else break;
	}
	return str;
}

function PCJSF_PadNumber(str, len)
{
	str = String(str);
	while(str.length < len)str = "0" + str;
	return str;
}

function PCJSF_CreateCookie(name,value,hours)
{
	if (hours)
	{
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function PCJSF_ReadCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = PCJSF_Trim(ca[i]);
		if (c.indexOf(nameEQ) == 0)
		{
			return PCJSF_Trim(c.substr(nameEQ.length));
		}
	}
	return null;
}

function PCJSF_ReadCookiesStartingWith(nameStart)
{
	var cookieMap = new Array();
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = PCJSF_Trim(ca[i]);
		if (c.indexOf(nameStart) == 0)
		{
			var equalIndex = c.indexOf("=");
			if(equalIndex >= 0)cookieMap[PCJSF_Trim(c.substr(nameStart.length, equalIndex - nameStart.length))] = PCJSF_Trim(c.substr(equalIndex + 1));
		}
	}
	return cookieMap;
}

function PCJSF_DeleteCookie(name)
{
	PCJSF_CreateCookie(name, "", -1);
}

function PCJSF_GetWindowSize()
{
	var result = {};
	result.width = 0;
	result.height = 0;
	if(typeof(window.innerWidth) == 'number')
	{ 
		result.width = window.innerWidth;
		result.height = window.innerHeight;
	} 
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		result.width = document.documentElement.clientWidth;
		result.height = document.documentElement.clientHeight;
	} 
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		result.width = document.body.clientWidth;
		result.height = document.body.clientHeight;
	}
	return result;
}

function PCJSF_GetScroll()
{
	var result = {};
	result.x = 0;
	result.y = 0;
	if(self.pageYOffset)
	{
		result.x = self.pageXOffset;
		result.y = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop)
	{
		result.x = document.documentElement.scrollLeft;
		result.y = document.documentElement.scrollTop;
	}
	else if(document.body)
	{
		result.x = document.body.scrollLeft;
    	result.y = document.body.scrollTop;
	}
	return result;
}

function PCJSF_ExtractMouseCoordinates(event)
{
	if(event.pageX || event.pageY)return {x:event.pageX, y:event.pageY};
	return {x:event.clientX + document.body.scrollLeft - document.body.clientLeft, y:event.clientY + document.body.scrollTop  - document.body.clientTop};
}

function PCJSF_EscapeParam(param)
{
	var escaped = "";
	for(var i = 0; i < param.length; i++)
	{
		var chr = param.charAt(i);
		if((chr == "\\") || (chr == ",") || (chr == ")") || (chr == ";"))
		{
			if(chr == "\\")escaped += "\\\\";
			else if(chr == ",")escaped += "\\c";
			else if(chr == ";")escaped += "\\d";
			else if(chr == ")")escaped += "\\b";
		}
		else escaped += chr;
	}
	return escaped;
}

function PCJSF_DecodeParam(str)
{
	var result = "";
	var index = 0;
	while(index < str.length)
	{
		var slashIndex = str.indexOf("\\", index);
		if(slashIndex < 0)break;
		result += str.substr(index, slashIndex - index);
		index = slashIndex + 1;
		if(index < str.length)
		{
			var afterSlash = str.charAt(index);
			index++;
			if(afterSlash == "\\")result += "\\";
			else if(afterSlash == "c")result += ",";
			else if(afterSlash == "d")result += ";";
			else if(afterSlash == "b")result += ")";
			else
			{
				result += "\\";
				index--;
			}
		}
		else result += "\\";
	}
	if(index < str.length)result += str.substr(index);
	return result;
}

function PCJSF_EncodeActions(actionList)
{
	if(actionList.length == 0)return "";
	var baseTime = PCJSF_SafeParseInt(actionList[0]);
	var actions = PCJSF_Tracker_PageKey + "," + baseTime + ":";
	for(var i = 0; i < actionList.length; i += 4)
	{
		var time = actionList[i];
		var type = actionList[i + 1];
		var param1 = actionList[i + 2];
		var param2 = actionList[i + 3];
		actions +=	type + (time - baseTime) +
					"(" + ((param1 !== null) ? PCJSF_EscapeParam(String(param1)) : "") +
					((param2 !== null) ? ("," + PCJSF_EscapeParam(String(param2))) : "") + ")";
	}
	return actions;
}

function PCJSF_DisableSelectionById(target, cursor)
{
	PCJSF_DisableSelection(document.getElementById(target), cursor);
}

function PCJSF_DisableSelection(target, cursor)
{
	if(!target)return;
	if (typeof target.onselectstart != "undefined")
	{
		target.onselectstart = function(){return false;}
	}
	else if (typeof target.style.MozUserSelect != "undefined")
	{
		target.style.MozUserSelect="none";
	}
	else
	{
		target.onmousedown=function(){return false;}
	}
	target.style.cursor = cursor;
}

function PCJSF_StopBubbling(event)
{
	if(event && event.stopPropagation)
	{
		event.stopPropagation();
	}
	else
	{
		event.cancelBubble=true;
	}
}

function PCJSF_BuildText(tag, id, font, size, color, weight, style, text, htmlStyle)
{
	return "<" + tag + (id ? (" id=\"" + id + "\" "): "") +" style=\"font-family:'" + font + "';font-size:" + size + ";color:" + color + ";font-weight:" + weight + ";font-style:" + style + ";text-decoration: none;" + htmlStyle + "\">" + text + "</" + tag + ">";
}

var PCJSF_ButtonIndex = 0;
var PCJSF_ButtonToDefinition = new Array();

function PCJSF_BuildButton(width, height, style, img, imgHOver, text, func)
{
	PCJSF_ButtonIndex++;
	var def = {};
	def.width = width;
	def.height = height;
	def.style = style;
	def.img = img;
	def.imgHOver = imgHOver;
	def.text = text;
	def.func = func;
	PCJSF_ButtonToDefinition[PCJSF_ButtonIndex] = def;
	var html = "";
	html += "<div id=\"PCJSF_ButtonDiv" + PCJSF_ButtonIndex + "\"";
	html += " onmouseover=\"PCJSF_BuildOver(" + PCJSF_ButtonIndex + ");\"";
	html += " onmouseout=\"PCJSF_BuildOut(" + PCJSF_ButtonIndex + ");\"";
	html += " onmousedown=\"PCJSF_StopBubbling(event); PCJSF_ButtonOnClick(" + PCJSF_ButtonIndex + ");\" style=\"float:left;\">";
	html += "<table id=\"PCJSF_ButtonTable" + PCJSF_ButtonIndex + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"" + PCJSF_BuildButtonTBLStyle(img, width, height, style) + "\">";
	html += "<tr><td id=\"PCJSF_ButtonText" + PCJSF_ButtonIndex + "\" align=\"center\" style=\"padding:0px;padding-left:5px;padding-right:5px;padding-bottom:3px;vertical-align:middle;\">";
	if(text != null)html += text;else html += "";
	html += "</td></tr></table></div>";
	return html;
}

function PCJSF_BuildButtonTBLStyle(img, width, height, customStyle)
{
	var style = "";
	style += ((width != null) ? ("width:" + width + "px;") : "") + "height:" + height + "px;cursor:hand;cursor:pointer;";
	if(img)
	{
		if(PCJSF_Support_IsIE6)
		{
			style += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "', sizingMethod='crop')";
		}
		else
		{
			style += "background:url(" + img + ") no-repeat;";
		}
	}
	style += customStyle;
	return style;
}

function PCJSF_BuildTextButton(text, func)
{
	return PCJSF_BuildButton(null, 17, "border:" + PCJSF_Support_ButtonBorder + ";background:" + PCJSF_Support_ButtonBackground + ";", null, null,
		PCJSF_BuildText(
			"span", null,
			PCJSF_Support_Font, PCJSF_Support_ButtonTextSize, PCJSF_Support_ButtonColor, "bold", "normal", text),
		func);
}

function PCJSF_BuildOver(index)
{
	var info = PCJSF_ButtonToDefinition[index];
	var img = info.imgHOver;
	if(img == null)img = info.img;
	var table = document.getElementById("PCJSF_ButtonTable" + index);
	table.setAttribute("style", PCJSF_BuildButtonTBLStyle(img, info.width, info.height, info.style));
}

function PCJSF_BuildOut(index)
{
	var info = PCJSF_ButtonToDefinition[index];
	var img = info.img;
	var table = document.getElementById("PCJSF_ButtonTable" + index);
	table.setAttribute("style", PCJSF_BuildButtonTBLStyle(img, info.width, info.height, info.style));
}

function PCJSF_UpdateButton(index, width, height, img, imgHOver, text, textHOver, func)
{
	var info = PCJSF_ButtonToDefinition[index];
	var def = {};
	def.width = width;
	def.height = height;
	def.style = info.style;
	def.img = img;
	def.imgHOver = imgHOver;
	def.text = text;
	def.textHOver = textHOver;
	def.func = func;
	PCJSF_ButtonToDefinition[index] = def;
	var table = document.getElementById("PCJSF_ButtonTable" + index);
	table.setAttribute("style", PCJSF_BuildButtonTBLStyle(img, info.width, info.height, info.style));
	var div = document.getElementById("PCJSF_ButtonText" + index);
	if(text != null)div.innerHTML = PCJSF_FixS(text);else div.innerHTML = "";
}

function PCJSF_ButtonOnClick(index)
{
	var func = PCJSF_ButtonToDefinition[index].func;
	if(func)func();
}

function PCJSF_GetOpacityStyle(alpha)
{
	var style = "";
	if(alpha < 95)
	{
		if(PCJSF_Support_IsIE)
		{
			style += "filter: alpha(opacity=" + PCJSF_SafeParseInt(alpha) + ");";
			style += "filter:progid:DXImageTransform.Microsoft.Alpha(opacity=" + PCJSF_SafeParseInt(alpha) + ");";
		}
		else
		{
			style += "opacity: " + (alpha / 100.0) + ";";
		}
	}
	return style;
}

function PCJSF_SplitParameters(parameters)
{
	var parameterList = parameters.split(",");
	for(var i = 0; i < parameterList.length; i++)
	{
		parameterList[i] = PCJSF_DecodeParam(parameterList[i]);
	}
	return parameterList;
}

function PCJSF_FixStyle(style)
{
	var tbl = new Array();
	var cond = 0;
	var n = "";
	var v = "";
	var i = 0;
	while(i < style.length)
	{
		var ch = style.charAt(i);
		var code = style.charCodeAt(i);
		i++;
		switch(cond)
		{
			case 0:
				if(ch == ";")
				{
					if(n.length > 0)tbl[n] = "";
					n = "";
				}
				else if(ch == ":")cond = 1;
				else if(code > 32)n += ch;
				break;
			case 1:
				if(ch == ";")
				{
					if(n.length > 0)tbl[n] = v;
					n = "";
					v = "";
					cond = 0;
				}
				else v += ch;
				break;
		}
	}
	if(n.length > 0)tbl[n] = v;
	var res = "";
	if(tbl["margin"] == undefined)res += "margin:0px;";
	if(tbl["padding"] == undefined)res += "padding:0px;";
	if(tbl["border"] == undefined)res += "border:0px solid;";
	if(tbl["line-height"] == undefined)res += "line-height:100%;";
	if(tbl["text-align"] == undefined)res += "text-align:left;";
	return res;
}

function PCJSF_FixS(html)
{	
	var res = "";
	var cond = 0;
	var	i = 0;
	var tag = "";
	var attr = "";
	var vl = "";
	while(i < html.length)
	{
		var fix = false;
		var ch = html.charAt(i);
		var code = html.charCodeAt(i);
		i++;
		switch(cond)
		{
			case 0:
				if(ch == "<")cond = 10;
				break;
			case 10:
				if(code <= 32)cond = 11;
				else if(ch == ">"){ fix = true; cond = 0; }
				else tag += ch;
				break;
			case 11:			
				if(ch == ">"){ fix = true; cond = 0; }
				else if((code <= 32) || (ch == "="))
				{
					if(attr.length > 0)cond = (ch == "=") ? 13 : 12;
				}
				else attr += ch;
				break;
			case 12:
				if(ch == "=")cond=13;
				break;
			case 13:
				if(ch == "\"")cond=14;
				break;
			case 14:
				if(ch == "\"")
				{
					if(attr == "style")res += ";" + PCJSF_FixStyle(vl);
					cond = 11;
					attr = "";
					vl = "";
				}
				else
				{
					vl += ch;
					if(ch == "\\")cond = 15;
				}
				break;
			case 15:
				vl += ch;
				cond = 14;
				break;
		}
		if(fix)
		{
			res += " style=\"" + PCJSF_FixStyle("") + "\" ";
			cond = 0;
			tag = "";
		}
		res += ch;
	}
	return res;
}

function PCJSF_IsScalar(mixed_var)
{
    return (/boolean|number|string/).test(typeof mixed_var);
}

 function PCJSF_IsArray(input)
 {
    return typeof(input)=='object'&&(input instanceof Array);
 }

function PCJSF_DeserializePacket(data)
{
	var result = new Array();
	if(data.length == 0)return result;
	var list = data.split(",");
	if((list.length % 2) != 0)return null;
	var pairsCount = PCJSF_SafeParseInt(list.length / 2);	
	for(var i = 0; i < pairsCount; i++)
	{
		result[PCJSF_Encoding_Decode(list[i * 2])] = PCJSF_Encoding_Decode(list[i * 2 + 1]);
	}
	return result;
}

function PCJSF_DeserializeData(data)
{
	var result = new Array();
	var offset = 0;
	var dotPos = data.indexOf(":", exPos);
	if(dotPos < 0)return result;
	var id = PCJSF_Encoding_Decode(data.substr(offset, dotPos - offset));
	result["_id"] = id;
	offset = dotPos + 1;
	while(true)
	{
		var exPos = data.indexOf(":", offset);
		if(exPos < 0)break;
		var key = PCJSF_Encoding_Decode(data.substr(offset, exPos - offset));
		var dotPos = data.indexOf(".", exPos);
		if(dotPos < 0)break;
		value = PCJSF_DeserializePacket(data.substr(exPos + 1, dotPos - exPos - 1));
		if(value === null)break;
		result[key] = value;
		offset = dotPos + 1;
	}
	return result;
}

function PCJSF_SerializePacket(data)
{
	var result = "";
	for(var key in data)
	{
		if(!PCJSF_IsScalar(data[key]))continue;
		if(result !== "")result += ",";
		result += PCJSF_Encoding_Encode(String(key)) + "," + PCJSF_Encoding_Encode(String(data[key]));
	}
	return result;
}

function PCJSF_SerializeData(data)
{
	var result = data["_id"] + ":";
	for(var key in data)
	{
		if(!PCJSF_IsArray(data[key]))continue;
		if(key != "_id")
		{
			result += PCJSF_Encoding_Encode(String(key)) + ":" + PCJSF_SerializePacket(data[key]) + ".";
		}
	}
	return result;
}

var PCJSF_SendRequest_CurrentPacketId = -1;
var PCJSF_SendRequest_CurrentCallback = null;
var PCJSF_SendRequest_LastPacketId = 0;
var PCJSF_SendRequest_Timeout = null;

function PCJSF_SendRequest(url, data, callback, timeout)
{
	if(PCJSF_SendRequest_Timeout)clearTimout(PCJSF_SendRequest_Timeout);
	PCJSF_SendRequest_Timeout = setTimeout("PCJSF_SendRequestTimeout()", timeout);
	PCJSF_SendRequest_CurrentPacketId = PCJSF_SendRequest_LastPacketId;
	PCJSF_SendRequest_CurrentCallback = callback;
	PCJSF_SendRequest_LastPacketId++;
	data["_id"] = String(PCJSF_SendRequest_CurrentPacketId);
	var serialized = PCJSF_SerializeData(data);
	var scriptContainer = document.getElementById("PCJSF_ScriptContainer");
    var scriptChildElement = document.createElement("script");
    scriptChildElement.setAttribute("src", url + "?packets=" + serialized);
    scriptChildElement.setAttribute("type", 'text/javascript');
	scriptChildElement.setAttribute("id", "PCJSF_CommScriptId");
	var oldScriptChildElement = document.getElementById("PCJSF_CommScriptId"); 
	if(oldScriptChildElement)scriptContainer.removeChild(oldScriptChildElement); 
	scriptContainer.appendChild(scriptChildElement); 
}

function PCJSF_SendRequestFinished(data)
{
	if(PCJSF_SendRequest_Timeout)clearTimeout(PCJSF_SendRequest_Timeout);
	PCJSF_SendRequest_Timeout = null;
	PCJSF_SendRequest_CurrentPacketId = -1;
	var callback = PCJSF_SendRequest_CurrentCallback;
	PCJSF_SendRequest_CurrentCallback = null;
	if(callback)callback(data);
}

function PCJSF_SendRequestTimeout()
{
	PCJSF_SendRequestFinished(null);
}

function PCJSF_CommRes(serialized)
{
	data = PCJSF_DeserializeData(String(serialized));
	if(data["_id"] !== String(PCJSF_SendRequest_CurrentPacketId))return;
	PCJSF_SendRequestFinished(data);
}
var PCJSF_Tracker_VisitorKey = "";
var PCJSF_Tracker_PageKey = "";
var PCJSF_Tracker_ActionsCode = "";
var PCJSF_Tracker_Actions = new Array();
var PCJSF_Tracker_SentActions = null;
var PCJSF_Tracker_LastLocation = "";
var PCJSF_Tracker_LastMousePosition = null;
var PCJSF_Tracker_LastMousePositionTime = 0;
var PCJSF_Tracker_LastWindowSize = null;
var PCJSF_Tracker_LastWindowSizeTime = 0;
var PCJSF_Tracker_LastScroll = null;
var PCJSF_Tracker_LastScrollXTime = 0;
var PCJSF_Tracker_LastScrollYTime = 0;
var PCJSF_Tracker_CurrentMousePosition = null;
var PCJSF_Tracker_SentOldActions = new Array();
var PCJSF_Tracker_LastMouseTime = 0;
var PCJSF_Tracker_LastKeyboardTime = 0;
var PCJSF_Tracker_LastWindowTime = 0;
var PCJSF_Tracker_RealLastWindowSize = null;
var PCJSF_Tracker_RealLastScroll = null;
var PCJSF_Tracker_Mode = -1;

function PCJSF_Tracker_StoreActions(useZeroTime)
{
	if(PCJSF_Tracker_Mode != 2)return;
	var currentTime = (new Date).getTime();
	if(PCJSF_Tracker_PageKey == "")return;
	var actions = PCJSF_Tracker_Actions;
	if(PCJSF_Tracker_SentActions !== null)actions = PCJSF_Tracker_SentActions.concat(PCJSF_Tracker_Actions);
	if(actions.length > 0)
	{
		PCJSF_CreateCookie("PCJSF_Actions" + PCJSF_Tracker_PageKey, (useZeroTime ? 0 : currentTime) + "_" + PCJSF_EncodeActions(actions), 1);
	}
	else
	{
		PCJSF_DeleteCookie("PCJSF_Actions" + PCJSF_Tracker_PageKey);
	}
}

function PCJSF_Tracker_AppendAction(type, param1, param2)
{
	if((PCJSF_Tracker_Mode == 2) || (PCJSF_Tracker_Mode == -1))
	{
		PCJSF_Tracker_Actions.push((new Date).getTime(), type, param1, param2);
		PCJSF_Tracker_StoreActions(0);
	}
}

function PCJSF_Tracker_CollectRequestData(connecting, data)
{
	var currentTime = (new Date).getTime();
	var requiresTime = false;
	if(PCJSF_Tracker_VisitorKey === "")
	{
		var key = PCJSF_ReadCookie("PCJSF_Tracker_Key");
		if(key != null)PCJSF_Tracker_VisitorKey = key;
	}
	var d = data["tracker"] = new Array();
	if(PCJSF_Tracker_VisitorKey !== "")d["key"] = PCJSF_Tracker_VisitorKey;
	if(connecting)
	{
		if(PCJSF_Tracker_PageKey == "")d["get_page_key"] = "1";
		d["location"] = String(document.location);
		var token = PCJSF_ReadCookie("PCJSF_Tracker_Token");
		if(token !== null)d["token"] = token;
		d["referer"] = String(document.referrer);
		d["getmode"] = "1";
	}
	d["act"] =
		PCJSF_SafeParseInt(PCJSF_Tracker_LastMouseTime / 1000) + "," +
		PCJSF_SafeParseInt(PCJSF_Tracker_LastKeyboardTime / 1000) + "," +
		PCJSF_SafeParseInt(PCJSF_Tracker_LastWindowTime / 1000);
	if((PCJSF_Tracker_Mode == 2) && (PCJSF_Tracker_PageKey != ""))
	{
		if(PCJSF_Tracker_SentActions !== null)
		{
			PCJSF_Tracker_SentActions = PCJSF_Tracker_SentActions.concat(PCJSF_Tracker_Actions);
		}
		else if(PCJSF_Tracker_Actions.length > 0)
		{
			PCJSF_Tracker_SentActions = PCJSF_Tracker_Actions;
		}
		PCJSF_Tracker_Actions = new Array();
		if(PCJSF_Tracker_SentActions !== null)
		{
			d["actions"] = PCJSF_EncodeActions(PCJSF_Tracker_SentActions);
			requiresTime = true;
		}
		PCJSF_Tracker_SentOldActions = new Array();
		var actionCookieMap = PCJSF_ReadCookiesStartingWith("PCJSF_Actions");
		var oldActions = "";
		for(var cookieName in actionCookieMap)
		{
			if(!PCJSF_IsScalar(actionCookieMap[cookieName]))continue;
			if(PCJSF_Tracker_PageKey != cookieName)
			{
				var currentActions = actionCookieMap[cookieName];
				var underscoreIndex = currentActions.indexOf("_");
				if(underscoreIndex >= 0)
				{
					var time = PCJSF_SafeParseInt(currentActions.substr(0, underscoreIndex));
					if(currentTime - time > PCJSF_Tracker_CookieActionTerminatedTimeout)
					{
						if(oldActions.length > 0)oldActions += ";";
						oldActions += currentActions.substr(underscoreIndex + 1);
						PCJSF_Tracker_SentOldActions.push(cookieName + "_" + time);
					}
				}
			}
		}
		if(oldActions.length > 0)
		{
			if(PCJSF_Tracker_Mode == 2)
			{
				d["oldactions"] = oldActions;
				requiresTime = true;
			}
		}
	}
	d["time"] = String(currentTime);
}

function PCJSF_Tracker_OnValidResponse()
{
	for(var i = 0; i < PCJSF_Tracker_SentOldActions.length; i++)
	{
		var id = PCJSF_Tracker_SentOldActions[i];
		var underscoreIndex = id.indexOf("_");
		var cookieName = "PCJSF_Actions" + id.substr(0, underscoreIndex);
		var time = id.substr(underscoreIndex + 1);
		var value = PCJSF_ReadCookie(cookieName);
		if((value !== null) && (value.indexOf(time + "_") == 0))
		{
			PCJSF_DeleteCookie(cookieName);
		}
	}	
	PCJSF_Tracker_SentOldActions = new Array();
	PCJSF_Tracker_SentActions = null;
	if(PCJSF_Tracker_Mode == 2)
	{
		PCJSF_Tracker_StoreActions(0);
	}
	else if(PCJSF_Tracker_Mode != -1)
	{
		if(PCJSF_Tracker_PageKey != "")PCJSF_DeleteCookie("PCJSF_Actions" + PCJSF_Tracker_PageKey);
	}
	if(PCJSF_Tracker_Mode != 0)
	{
		PCJSF_Processor_RegisterRequest(PCJSF_Tracker_UpdateTimeout);
	}
}

function PCJSF_Tracker_HandleResponseData(connecting, data)
{
	if(connecting)
	{
		if(data["tracker"] !== undefined)
		{
			var trackerInfo = data["tracker"];
			if(trackerInfo["mode"] !== undefined)PCJSF_Tracker_Mode = PCJSF_SafeParseInt(trackerInfo["mode"]);
			if(trackerInfo["result"] !== undefined)
			{
				if(trackerInfo["page_key"] !== undefined)PCJSF_Tracker_PageKey = trackerInfo["page_key"];
				var result = trackerInfo["result"];
				if(result == "found")
				{
					PCJSF_Tracker_OnValidResponse();
					return 1;
				}
				if(result == "created")
				{
					if(trackerInfo["key"] !== undefined)
					{
						PCJSF_Tracker_VisitorKey = trackerInfo["key"];
						PCJSF_CreateCookie("PCJSF_Tracker_Key", PCJSF_Tracker_VisitorKey, 1);
						if(trackerInfo["token"] !== undefined)PCJSF_CreateCookie("PCJSF_Tracker_Token", trackerInfo["token"], 8760);
						PCJSF_Tracker_OnValidResponse();
						return 1;						
					}
					else return 0;
				}
			}
		}
		return 0;
	}
	else
	{
		if(data["tracker"] !== undefined)
		{
			var trackerInfo = data["tracker"];
			if(trackerInfo["mode"] !== undefined)PCJSF_Tracker_Mode = PCJSF_SafeParseInt(trackerInfo["mode"]);
			if(trackerInfo["result"] !== undefined)
			{
				var result = trackerInfo["result"];
				if(result == "found")
				{
					PCJSF_Tracker_OnValidResponse();
					return 1;
				}
			}
		}
		return 0;
	}
}

function PCJSF_Tracker_Cycle()
{
	var currentTime = (new Date).getTime();
	
	var currentLocation = String(document.location);
	if(currentLocation != PCJSF_Tracker_LastLocation)
	{
		PCJSF_Tracker_AppendAction("u", currentLocation, null);
		PCJSF_Tracker_LastLocation = currentLocation;
	}
	
	var windowSize = PCJSF_GetWindowSize();
	if((windowSize.width != PCJSF_Tracker_LastWindowSize.width) || (windowSize.height != PCJSF_Tracker_LastWindowSize.height))
	{
		var dx = (windowSize.width - PCJSF_Tracker_LastWindowSize.width);
		var dy = (windowSize.height - PCJSF_Tracker_LastWindowSize.height);
		var d = Math.sqrt(dx * dx + dy * dy);
		if(	((currentTime - PCJSF_Tracker_LastWindowSizeTime) > PCJSF_Tracker_WindowsSizeUpdateTime) ||
			(d > PCJSF_Tracker_WindowsSizeUpdateDistance))
		{
			PCJSF_Tracker_LastWindowSizeTime = currentTime;
			PCJSF_Tracker_LastWindowSize = windowSize;
			PCJSF_Tracker_AppendAction("w", PCJSF_Tracker_LastWindowSize.width, PCJSF_Tracker_LastWindowSize.height);
		}
	}

	var scroll = PCJSF_GetScroll();
	if(scroll.x != PCJSF_Tracker_LastScroll.x)
	{
		if(	((currentTime - PCJSF_Tracker_LastScrollXTime) > PCJSF_Tracker_ScrollUpdateTime) ||
			(Math.abs(scroll.x - PCJSF_Tracker_LastScroll.x) > PCJSF_Tracker_ScrollUpdateDistance))
		{
			PCJSF_Tracker_LastScroll.x = scroll.x;
			PCJSF_Tracker_LastScrollXTime = currentTime;
			PCJSF_Tracker_AppendAction("x", PCJSF_Tracker_LastScroll.x, null);
		}
		
	}
	if(scroll.y != PCJSF_Tracker_LastScroll.y)
	{
		if(	((currentTime - PCJSF_Tracker_LastScrollYTime) > PCJSF_Tracker_ScrollUpdateTime) ||
			(Math.abs(scroll.y - PCJSF_Tracker_LastScroll.y) > PCJSF_Tracker_ScrollUpdateDistance))
		{
			PCJSF_Tracker_LastScroll.y = scroll.y;
			PCJSF_Tracker_LastScrollYTime = currentTime;
			PCJSF_Tracker_AppendAction("y", PCJSF_Tracker_LastScroll.y, null);
		}
		
	}
	if((windowSize.width != PCJSF_Tracker_RealLastWindowSize.width) || (windowSize.height != PCJSF_Tracker_RealLastWindowSize.height) ||
		(scroll.x != PCJSF_Tracker_RealLastScroll.x) || (scroll.y != PCJSF_Tracker_RealLastScroll.y))
	{
		PCJSF_Tracker_LastWindowTime = currentTime;
		PCJSF_Tracker_RealLastWindowSize = windowSize;
		PCJSF_Tracker_RealLastScroll = scroll;
	}
	if(PCJSF_Tracker_CurrentMousePosition !== null)
	{
		if(PCJSF_Tracker_LastMousePosition === null)
		{
			PCJSF_Tracker_LastMousePosition = PCJSF_Tracker_CurrentMousePosition;
			PCJSF_Tracker_AppendAction("p", PCJSF_Tracker_LastMousePosition.x, PCJSF_Tracker_LastMousePosition.y);
		}
		else if((PCJSF_Tracker_LastMousePosition.x != PCJSF_Tracker_CurrentMousePosition.x) ||
				(PCJSF_Tracker_LastMousePosition.y != PCJSF_Tracker_CurrentMousePosition.y))
		{
			var dx = (PCJSF_Tracker_LastMousePosition.x - PCJSF_Tracker_CurrentMousePosition.x);
			var dy = (PCJSF_Tracker_LastMousePosition.y - PCJSF_Tracker_CurrentMousePosition.y);
			var d = Math.sqrt(dx * dx + dy * dy);
			if(	((currentTime - PCJSF_Tracker_LastMousePositionTime) > PCJSF_Tracker_MousePositionUpdateTime) ||
				(d > PCJSF_Tracker_MousePositionUpdateDistance))
			{
				PCJSF_Tracker_LastMousePositionTime = currentTime;
				PCJSF_Tracker_LastMousePosition = PCJSF_Tracker_CurrentMousePosition;
				PCJSF_Tracker_AppendAction("p", PCJSF_Tracker_LastMousePosition.x, PCJSF_Tracker_LastMousePosition.y);
			}
		}
	}
}

function PCJSF_Tracker_OnMouseMove(ev)
{
	PCJSF_Tracker_LastMouseTime = (new Date).getTime();
	PCJSF_Tracker_CurrentMousePosition = PCJSF_ExtractMouseCoordinates(ev || window.event);
}

function PCJSF_Tracker_OnClick(ev)
{
	PCJSF_Tracker_LastMouseTime = (new Date).getTime();
	PCJSF_Tracker_AppendAction("c", PCJSF_Tracker_CurrentMousePosition.x, PCJSF_Tracker_CurrentMousePosition.y);
}

function PCJSF_Tracker_OnDblClick(ev)
{
	PCJSF_Tracker_LastMouseTime = (new Date).getTime();
	PCJSF_Tracker_AppendAction("d", PCJSF_Tracker_CurrentMousePosition.x, PCJSF_Tracker_CurrentMousePosition.y);
}

function PCJSF_Tracker_OnKey(ev)
{
	PCJSF_Tracker_LastKeyboardTime = (new Date).getTime();
}

function PCJSF_Tracker_OnUnload(ev)
{
	PCJSF_Tracker_AppendAction("x", null, null);
	PCJSF_Tracker_StoreActions(1);
}

var PCJSF_Tracker_CurrentTime = (new Date).getTime();

PCJSF_Tracker_LastLocation = String(document.location);
PCJSF_Tracker_LastWindowSize = PCJSF_GetWindowSize();
PCJSF_Tracker_LastScroll = PCJSF_GetScroll();
PCJSF_Tracker_RealLastWindowSize = PCJSF_GetWindowSize();
PCJSF_Tracker_RealLastScroll = PCJSF_GetScroll();
PCJSF_Tracker_AppendAction("a", document.location, document.referrer);
PCJSF_Tracker_AppendAction("w", PCJSF_Tracker_LastWindowSize.width, PCJSF_Tracker_LastWindowSize.height);
if(PCJSF_Tracker_LastScroll.x != 0)PCJSF_Tracker_AppendAction("x", PCJSF_Tracker_LastScroll.x, null);
if(PCJSF_Tracker_LastScroll.y != 0)PCJSF_Tracker_AppendAction("y", PCJSF_Tracker_LastScroll.y, null);
PCJSF_Tracker_LastWindowSizeTime = PCJSF_Tracker_CurrentTime;
PCJSF_Tracker_LastScrollXTime = PCJSF_Tracker_CurrentTime;
PCJSF_Tracker_LastScrollYTime = PCJSF_Tracker_CurrentTime;
PCJSF_Tracker_CurrentMousePosition = {};
PCJSF_Tracker_CurrentMousePosition.x = 0;
PCJSF_Tracker_CurrentMousePosition.y = 0;
setInterval("PCJSF_Tracker_Cycle()", PCJSF_Tracker_CyclePeriod);

if (document.addEventListener)
{
	document.addEventListener('mousemove', PCJSF_Tracker_OnMouseMove, false); 
	document.addEventListener('click', PCJSF_Tracker_OnClick, false); 
	document.addEventListener('dblclick', PCJSF_Tracker_OnDblClick, false); 
	document.addEventListener('keydown', PCJSF_Tracker_OnKey, false); 
	document.addEventListener('keyup', PCJSF_Tracker_OnKey, false); 
}
else if (document.attachEvent)
{
	document.attachEvent('onmousemove', PCJSF_Tracker_OnMouseMove);
	document.attachEvent('onclick', PCJSF_Tracker_OnClick);
	document.attachEvent('ondblclick', PCJSF_Tracker_OnDblClick);
	document.attachEvent('onkeydown', PCJSF_Tracker_OnKey);
	document.attachEvent('onkeyup', PCJSF_Tracker_OnKey);
}

if (window.addEventListener)
{
	window.addEventListener('unload', PCJSF_Tracker_OnUnload, false); 
}
else if (window.attachEvent)
{
	window.attachEvent('onunload', PCJSF_Tracker_OnUnload);
}

var PCJSF_Chat_Cache = [];
var PCJSF_Chat_Areas = [];
var PCJSF_Chat_ShiftDown = 0;
var PCJSF_Chat_LastMessageId = 0;

function PCJSF_Chat_InitChatArea(chatDiv, containerDiv, messageInput, index)
{
	var area = {};
	area.div = chatDiv;
	area.containerDiv = containerDiv;
	area.input = messageInput;
	area.index = index;	
	area.cache = (PCJSF_Chat_Cache[index] !== undefined) ? (PCJSF_Chat_Cache[index]) : ("");
	area.messages = [];
	area.lastMessageId = 0;
	area.typeStarted = false;
	area.inputHandler = function(ev){ PCJSF_Chat_MessageKeyUp(ev, index); };
	area.focusHandler = function(ev){ PCJSF_Chat_OnFocus(ev, index); };
	if (messageInput.addEventListener)
	{
		messageInput.addEventListener('keyup', area.inputHandler, false); 
		messageInput.addEventListener('focus', area.focusHandler, false); 
	}
	else if (messageInput.attachEvent)
	{
		messageInput.attachEvent('onkeyup', area.inputHandler);
		messageInput.attachEvent('onfocus', area.focusHandler);
	}
	PCJSF_Chat_Areas.push(area);
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Chat_DestroyChatArea(index)
{
	for(var i = 0; i < PCJSF_Chat_Areas.length; i++)
	{
		var area = PCJSF_Chat_Areas[i];
		if(area.index == index)
		{
			PCJSF_Chat_Cache[index] = area.cache;
			if (area.input.removeEventListener)
			{
				area.input.removeEventListener('keyup', area.inputHandler, false); 
			}
			else if (area.input.detachEvent)
			{
				area.input.attachEvent('onkeyup', area.inputHandler);
			}
			PCJSF_Chat_Areas.splice(i, 1);
			break;
		}
	}
}

function PCJSF_Chat_GetArea(index)
{
	for(var i = 0; i < PCJSF_Chat_Areas.length; i++)
	{
		if(PCJSF_Chat_Areas[i].index == index)return PCJSF_Chat_Areas[i];
	}
	return null;
}

function PCJSF_Chat_CollectRequestData(connecting, data)
{
	for(var i = 0; i < PCJSF_Chat_Areas.length; i++)
	{
		var area = PCJSF_Chat_Areas[i];
		var g = "chat" + area.index;
		var d = data[g] = new Array();
		if(area.lastMessageId > 0)d["last_message"] = String(area.lastMessageId);
		if(area.messages.length > 0)
		{
			var messageList = "";
			for(var j = 0; j < area.messages.length; j++)
			{
				messageList += PCJSF_EscapeParam(area.messages[j]) + ";";
			}
			d["send"] = messageList;
		}
	}
}

function PCJSF_Chat_HandleResponseData(connecting, data)
{
	var currentTime = (new Date).getTime();
	for(var i = 0; i < PCJSF_Chat_Areas.length; i++)
	{
		var area = PCJSF_Chat_Areas[i];
		var g = "chat" + area.index;
		if(data[g] !== undefined)
		{
			var chatInfo = data[g];
			if(area.lastMessageId == 0)area.div.innerHTML = "";
			if(chatInfo["received"] !== undefined)
			{
				var received = PCJSF_SafeParseInt(chatInfo["received"]);
				if(received > area.messages.length)received = area.messages.length;
				if(received > 0)area.messages.splice(0, received);
			}
			if(chatInfo["messages"] !== undefined)
			{
				var messages = chatInfo["messages"];
				var commaIndex = messages.indexOf(",");
				if(commaIndex >= 0)
				{
					var serverTime = parseFloat(messages.substr(0, commaIndex));
					var colIndex = messages.indexOf(":", commaIndex);
					if(colIndex >= 0)
					{
						var lastMessageId = parseFloat(messages.substr(commaIndex + 1, colIndex - commaIndex - 1));
						var messageList = messages.substr(colIndex + 1).split(";");
						var messageAppended = false;
						var messageHTML = "";
						for(var j = 0; j < messageList.length; j++)
						{
							var message = messageList[j];
							if(message.length > 0)
							{
								var parts = message.split(",");
								if(parts.length != 4)
								{
									return 0;
								}
								var date = new Date();
								date.setTime(parseFloat(parts[0]) * 1000 - serverTime + currentTime);
								messageHTML += "<span style=\"" + (parseInt(parts[3]) ? PCJSF_Chat_OTStyle : PCJSF_Chat_MTStyle) + "\">";
								messageHTML += "[" + PCJSF_PadNumber(date.getHours(), 2) + ":"  + PCJSF_PadNumber(date.getMinutes(), 2) + ":"  + PCJSF_PadNumber(date.getSeconds(), 2) + "] " + PCJSF_DecodeParam(parts[1]) + ": ";
								messageHTML += "</span>";
								messageHTML += "<span style=\"" + (parseInt(parts[3]) ? PCJSF_Chat_OCStyle : PCJSF_Chat_MCStyle) + "\">";
								messageHTML += PCJSF_DecodeParam(parts[2]);
								messageHTML += "</span><br />";
								
								messageAppended = true;
							}
						}
						if(messageAppended)
						{
							area.cache += PCJSF_FixS(messageHTML);
							area.div.innerHTML = area.cache;
							area.containerDiv.scrollTop = 100000;
						}
						area.lastMessageId = lastMessageId;
						return 1;
					}
					else return 0;
				}
				else return 0;
			}
		}
	}
	return 1;
}

function PCJSF_Chat_MessageKeyUp(ev, index)
{
	ev = ev || window.event;
	if((ev.keyCode == 13) && (PCJSF_Chat_ShiftDown == 0))
	{
		PCJSF_Chat_SendMessage(index);
	}
}

function PCJSF_Chat_SendMessage(index)
{
	var area = PCJSF_Chat_GetArea(index);
	var message = PCJSF_Trim(area.input.value);
	if(message.length > 0)
	{
		area.messages.push(message);
		PCJSF_Processor_RegisterRequest(0);
	}
	area.input.value = "";
}

function PCJSF_Chat_OnFocus(ev, index)
{
	var area = PCJSF_Chat_GetArea(index);
	if(!area.typeStarted)
	{
		area.input.value = "";
		area.typeStarted = true;
	}
}

function PCJSF_Chat_KeyDown(ev)
{
    ev = ev || window.event;
    if(ev.keyCode == 16)PCJSF_Chat_ShiftDown = 1;
}

function PCJSF_Chat_KeyUp(ev)
{
    ev = ev || window.event;
    if(ev.keyCode == 16)PCJSF_Chat_ShiftDown = 0;
}

if (document.addEventListener)
{
	document.addEventListener('keydown', PCJSF_Chat_KeyDown, false); 
	document.addEventListener('keyup', PCJSF_Chat_KeyUp, false); 
}
else if (document.attachEvent)
{
	document.attachEvent('onkeydown', PCJSF_Chat_KeyDown); 
	document.attachEvent('onkeyup', PCJSF_Chat_KeyUp); 
}

function PCJSF_Support_GetTitleHTML(allowHide, title, imageId, separatorHeight, imageWidth, imageHeight, imageMIME, showBottomBorder)
{
	var stateURL = PCJSF_Support_SkinURL;
	var titleStyle = "";
	if(PCJSF_Support_TitleVisible || !allowHide)
	{
		stateURL += "CollapseTitle.png";
	}
	else
	{
		stateURL += "ExpandTitle.png";
		titleStyle = "height:1px;overflow:hidden;";
	}
	var header = "";
	if(allowHide)
	{
		var stateURL = PCJSF_Support_SkinURL + (PCJSF_Support_TitleVisible ? "CollapseTitle.png" : "ExpandTitle.png");
		header += "<div id=\"PCJSF_Support_TitleSwitch\" style=\"width:100%;height:18px;background:" + PCJSF_Support_SwitchBackground + " url(" + stateURL + ") no-repeat;border:0px;border-bottom:" + PCJSF_Support_SwitchBorder + ";cursor:hand;cursor:pointer;\" ";
		header += "onclick=\"PCJSF_Support_SwitchTitleVisible();\"";
		header += "></div>";
	}
	header += "<div id=\"PCJSF_Support_Title\" style = \"width:100%;" + titleStyle + "; background:" + PCJSF_Support_TitleBackground + ";\"><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	if(title.length > 0)
	{
		header += "<tr><td height=\"" + PCJSF_Support_ImagePadding + "\" colspan=\"5\"></td></tr>";
		header += "<tr><td width=\"" + PCJSF_Support_ImagePadding + "\"></td>";
		header +=
			"<td id=\"PCJSF_Support_Title_Text\" colspan=\"3\">" +
				PCJSF_BuildText(
					"span", null,
					PCJSF_Support_Font, PCJSF_Support_TitleTextSize, PCJSF_Support_TitleColor, PCJSF_Support_TitleWeight, "normal", title) +
			"</td><td width=\"" + PCJSF_Support_ImagePadding + "\"></td></tr></table><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	}
	if(imageMIME.length > 0)
	{
		header += "<tr><td height=\"" + PCJSF_Support_ImagePadding + "\" colspan=\"5\"></td></tr>";
		header +=
			"<tr><td></td><td height=\"" + PCJSF_Support_ImageBorderWidth + "\" colspan=\"3\" style=\"background:" + PCJSF_Support_InnerBorderColor + ";font-size:2px;\"></td><td></td></tr>" +
			"<tr><td>&nbsp;</td>" +
			"	<td width=\"" + PCJSF_Support_ImageBorderWidth + "\" style=\"background:" + PCJSF_Support_InnerBorderColor + ";\"></td>" +
			"	<td width=\"" + imageWidth + "px\" height=\"" + imageHeight + "px\">" +
			"		<img src=\"" + PCJSF_Processor_ServerURL + "Public/Support_Image.php?" + imageId + "=" + PCJSF_Support_ConfigurationCode + "\" width=\"" + imageWidth + "px\" height=\"" + imageHeight + "px\" />" +
			"	</td>" +
			"	<td width=\"" + PCJSF_Support_ImageBorderWidth + "\" style=\"background:" + PCJSF_Support_InnerBorderColor + ";\">" +
			"</td><td>&nbsp;</td></tr>" +
			"<tr><td></td><td height=\"" + PCJSF_Support_ImageBorderWidth + "\" colspan=\"3\" style=\"background:" + PCJSF_Support_InnerBorderColor + ";\"></td><td></td></tr>";
	}
	header += "<tr><td height=\"" + PCJSF_Support_ImageBorderWidth + "\" colspan=\"5\"></td></tr>";
	if(showBottomBorder)header += "<tr><td height=\"" + separatorHeight + "px\" colspan=\"5\" style=\"background:" + PCJSF_Support_InnerBorderColor + "\"></td></tr>";
	header += "</table></div>";
	return header;
}

function PCJSF_Support_SwitchTitleVisible()
{
	var sw = document.getElementById("PCJSF_Support_TitleSwitch");
	var title = document.getElementById("PCJSF_Support_Title");
	PCJSF_Support_TitleVisible = PCJSF_Support_TitleVisible ? 0 : 1;
	var stateURL = PCJSF_Support_SkinURL;
	if(PCJSF_Support_TitleVisible)
	{
		stateURL += "CollapseTitle.png";
	}
	else
	{
		stateURL += "ExpandTitle.png";
	}
	sw.style.background = "" + PCJSF_Support_SwitchBackground + " url(" + stateURL + ") no-repeat";
	title.style.height = PCJSF_Support_TitleVisible ? "" : "1px";
	title.style.overflow = PCJSF_Support_TitleVisible ? "auto" : "hidden";
	PCJSF_Support_OnSizeOrStructureChanged();
}

function PCJSF_Support_GetChatHTML()
{
	var add = "";
	if(PCJSF_Support_IsIE && (document.compatMode == "CSS1Compat"))
	{
		add = " style=\"height:100px;\"";
	}
	var html = "";
	html += "<table id=\"PCJSF_chtt\" width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td height=\"" + PCJSF_Support_ChatSeparatorHeight + "px\">";
	html += "	<div style=\"width:100%;height:" + PCJSF_Support_ChatSeparatorHeight + ";background:url(" + PCJSF_Support_SkinURL + "SeparatorBackground.png);\"></div>";
	html += "</td></tr><tr><td id=\"PCJSF_Support_ChatCell\"" + add + " valing=\"top\">";
	if(PCJSF_Support_IsChrome)
	{
		html += "	<div id=\"PCJSF_Support_ChatContainer\" style=\"padding:0px;padding-left:4px;background:" + PCJSF_Support_ChatBackground + ";width:100%;height:100%;overflow:auto;\"><div id=\"PCJSF_Support_ChatDiv\"></div></div>";
	}
	else
	{
		html += "	<div id=\"PCJSF_Support_ChatContainer\" style=\"width:5px;height:5px;background:" + PCJSF_Support_ChatBackground + ";padding:0px;padding-left:4px;overflow:auto;\"><div id=\"PCJSF_Support_ChatDiv\" style=\"width:100%;\"></div></div>";
	}
	html += "</td></tr><tr><td height=\"" + PCJSF_Support_InnerBorderWidth + "\"  style=\"font-size:4px;\">";
	html += "	<div style=\"width:100%;height:" + PCJSF_Support_InnerBorderWidth + ";background:" + PCJSF_Support_InnerBorderColor + ";\"></div>";
	html += "</td></tr><tr><td height=\"59px\">";
	html += "	<table width=\"100%\" height=\"59px\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	html += "	<tr><td height=\"50px\">";
	html +=	"		<div style=\"width:100%;height:59px;overflow:hidden;\"><textarea id=\"PCJSF_Support_ChatInput\" style=\"width:100%;height:59px;border:0px solid;background:" + PCJSF_Support_TypeBackground + ";font-family:" + PCJSF_Support_Font + ";font-size:" + PCJSF_Support_TypeSize + ";color:" + PCJSF_Support_TypeColor + ";font-weight:" + PCJSF_Support_TypeWeight + ";\">" + PCJSF_Support_TypeHereText + "</textarea></div>";
	html += "	</td><td width=\"13px\" height=\"59px\"><div style=\"width:13px;height59px;overflow:hidden;\">";
	html += PCJSF_BuildButton(13, 59, "display:block;float:left;", PCJSF_Support_SkinURL + "SendButton.png", null, null, PCJSF_Support_OnSendClicked);
	html += "	</div></td></tr></table>";
	html += "</td></tr></table>";
	return html;
}

function PCJSF_Support_ElementHeight(id)
{
	return PCJSF_SafeParseInt(document.getElementById(id).offsetHeight);
}

function PCJSF_Support_UpdateChatHTML(h)
{	
	if(h > 90)h -= 90;
	document.getElementById("PCJSF_Support_ChatCell").style.height = h + "px";
}

function PCJSF_Support_OnSendClicked()
{
	PCJSF_Chat_SendMessage(0);
}

function PCJSF_Support_UpdateChatDiv()
{
	if(PCJSF_Support_IsChrome)return;
	var container = document.getElementById("PCJSF_Support_ChatContainer");
	var cell = document.getElementById("PCJSF_Support_ChatCell");
	if(cell && container)
	{
		var scrollTop = container.scrollTop;
		container.style.display = "none";
		var newWidth = "";
		var newHeight = "";
		if(window.getComputedStyle && (!PCJSF_Support_IsSafari))
		{
			var style = window.getComputedStyle(cell, null);
			newWidth = (PCJSF_SafeParseInt(style.width) - 4) + "px";
			newHeight = PCJSF_SafeParseInt(style.height) + "px";
		}
		else
		{
			newWidth = (PCJSF_SafeParseInt(cell.offsetWidth) - 4) + "px";
			newHeight = PCJSF_SafeParseInt(cell.offsetHeight) + "px";
		}
		if(PCJSF_SafeParseInt(container.style.width) != PCJSF_SafeParseInt(newWidth))container.style.width = newWidth;
		if(PCJSF_SafeParseInt(container.style.height) != PCJSF_SafeParseInt(newHeight))container.style.height = newHeight;
		container.style.display = "block";
		container.scrollTop = scrollTop;
	}
}

function getInternetExplorerVersion()
{
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

var PCJSF_Support_OffersActive = false;
var PCJSF_Support_OffersId = "";
var PCJSF_Support_OffersLoading = new Array();
var PCJSF_Support_OffersMap = new Array();
var PCJSF_Support_OffersList = new Array();
var PCJSF_Support_OfferIndex = 0;
var PCJSF_Support_OfferOffset = 0;
var PCJSF_Support_LastOfferScript = 0;
var PCJSF__OfferLen;
var PCJSF__OfferSpace;
var PCJSF__OfferVisible;
var PCJSF__OfferIndent;
var PCJSF__OfferBefore;
var PCJSF__OfferAfter;
var PCJSF__LastMove = 0;

function PCJSF_Support_InitOffers(id)
{
	var box = document.getElementById("PCJSF_Support_OffersBox");
	var html = "";
	html += "<div id=\"PCJSF_Support_OfferTable\" width=\"100%\" height=\"70px\" style=\"background:" + PCJSF_Support_OffersBackground + ";\">";
	html += "<div style=\"width:12px;height:70px;margin:11px 0px 0px 6px;float:left;aling:left;\">";
	html += PCJSF_BuildButton(12, 47, "display:block;", PCJSF_Support_SkinURL + "OffersLeft.png", null, null, PCJSF_Support_GotoPrevious);
	html += "</div>";
	html += "<div style=\"width:12px;height:70px;margin:11px 6px 0px 0px;float:right;align:right;\">";
	html += PCJSF_BuildButton(12, 47, "display:block;", PCJSF_Support_SkinURL + "OffersRight.png", null, null, PCJSF_Support_GotoNext);
	html += "</div>";
	html += "<div id=\"PCJSF_Support_OfferContainer\" style=\"margin-left:18px;margine-right:18px;position:relative;height:70px;overflow:hidden;\"></div>";
	html += "</div>";
	html += "<table id=\"PCJSF_Support_OfferTable\" width=\"100%\" height=\"70px\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:" + PCJSF_Support_OffersBackground + ";\"><tr><td width = \"6px\"></td><td width = \"12px\" valign=\"center\">";	
	box.innerHTML = PCJSF_FixS(html);
	
	PCJSF_Support_OffersId = id;
	if(PCJSF_Support_OffersLoading[id] == undefined)
	{
		PCJSF_Support_OffersLoading[id] = true;
		var url = PCJSF_Processor_ServerURL + "Public/GetOffers.php";
		var scriptContainer = document.getElementById("PCJSF_ScriptContainer");
		var scriptChildElement = document.createElement("script");
		scriptChildElement.setAttribute("src", url + "?id=" + id);
		scriptChildElement.setAttribute("type", 'text/javascript');
		if(PCJSF_Support_LastOfferScript)scriptContainer.removeChild(PCJSF_Support_LastOfferScript); 
		scriptContainer.appendChild(scriptChildElement);
		PCJSF_Support_LastOfferScript = scriptChildElement;
	}
	PCJSF_Support_StartOffers();
	PCJSF_Support_OffersActive = true;
}

function PCJSF_Support_DestroyOffers()
{
	PCJSF_Support_OffersActive = false;
	var box = document.getElementById("PCJSF_Support_OffersBox");
	if(box)
	{
		box.innerHTML = "";
	}
}


function PCJSF_Support_GotoPrevious()
{
	if(PCJSF__OfferLen < 2)return;
	PCJSF__LastMove = (new Date()).getTime();
	PCJSF_Support_CalculateLayout();
	PCJSF_Support_OfferIndex = PCJSF_SafeParseInt((PCJSF_Support_OfferIndex + PCJSF__OfferLen - 1) % PCJSF__OfferLen);
	PCJSF_Support_OfferOffset -= 180 + PCJSF__OfferIndent;
	PCJSF_Support_UpdateOfferPositions();
}

function PCJSF_Support_GotoNext()
{
	if(PCJSF__OfferLen < 2)return;
	PCJSF__LastMove = (new Date()).getTime();
	PCJSF_Support_CalculateLayout();
	PCJSF_Support_OfferIndex = PCJSF_SafeParseInt((PCJSF_Support_OfferIndex + 1) % PCJSF__OfferLen);
	PCJSF_Support_OfferOffset += 180 + PCJSF__OfferIndent;
	PCJSF_Support_UpdateOfferPositions();
}

function Promptchat_Support_OffersReceived(id, offers)
{
	offers = PCJSF_Encoding_Decode(offers);
	var offerList = new Array();
	var op = PCJSF_SplitParameters(offers);
	for(var i = 0; i < op.length - 4; i += 5)
	{
		var offer = {};
		offer.title = op[i];
		offer.text = op[i + 1];
		offer.footer = op[i + 2];
		offer.url = op[i + 3];
		offer.img = op[i + 4];
		offerList.push(offer);
	}
	PCJSF_Support_OffersMap[id] = offerList;
	if(id == PCJSF_Support_OffersId)PCJSF_Support_StartOffers();
}

function PCJSF_Support_RandomizeArray(array)
{
	for(var i = 0; i < array.length; i++)
	{
		var ind = Math.floor(array.length * Math.random());
		if(ind >= array.length)ind = array.length - 1;
		if(ind != i)
		{
			var buf = array[ind];
			array[ind] = array[i];
			array[i] = buf;
		}
	}
}

function PCJSF_Support_StartOffers()
{
	PCJSF_Support_OffersList = new Array();
	if(PCJSF_Support_OffersMap[PCJSF_Support_OffersId] == undefined)return;
	var offerList = PCJSF_Support_OffersMap[PCJSF_Support_OffersId];
	var html = "";
	var vis = (PCJSF_Support_PopupState == "opened") ? "visible" : "hidden";
	for(var i = 0; i < offerList.length; i++)
	{
		var offer = offerList[i];
		html += "<div id=\"PCJSF_Support_Offer" + i + "\" style=\"visibility:" + vis + ";position:absolute;top:5px;left:0px;width:180px; height:60px;overflow:hidden;\">";
		html += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>";
		if(offer.img.length > 0)
		{
			html += "<td width=\"52px\" height=\"52px\">";
			html += "<a href=\"" + offer.url + "\" target=\"_blank\"><img src=\"" + PCJSF_Processor_ServerURL + "Public/OfferImage.php?id=" + offer.img + "\" width=\"50\" height=\"50\" style=\"border:" + PCJSF_Support_OfferBorder + ";\" /></a>";
			html += "</td><td width=\"4px\"></td>";
		}
		html += "<td><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>";
		html += "<a href=\"" + offer.url + "\" target=\"_blank\" style=\"text-decoration:" + PCJSF_Support_OfferTitleDecoration + ";\">" + PCJSF_BuildText("span", null, PCJSF_Support_OfferFont, PCJSF_Support_OfferTitleSize, PCJSF_Support_OfferTitleColor, PCJSF_Support_OfferTitleWeight, "normal", offer.title) + "</a>";
		html += "</td></tr><tr><td>";
		html += "<a href=\"" + offer.url + "\" target=\"_blank\" style=\"text-decoration:" + PCJSF_Support_OfferTextDecoration + ";\">" + PCJSF_BuildText("span", null, PCJSF_Support_OfferFont, PCJSF_Support_OfferTextSize, PCJSF_Support_OfferTextColor, PCJSF_Support_OfferTextWeight, "normal", offer.text) + "</a>";
		html += "</td></tr><tr><td>";
		html += "<a href=\"" + offer.url + "\" target=\"_blank\" style=\"text-decoration:" + PCJSF_Support_OfferFooterDecoration + ";\">" + PCJSF_BuildText("span", null, PCJSF_Support_OfferFont, PCJSF_Support_OfferFooterSize, PCJSF_Support_OfferFooterColor, PCJSF_Support_OfferFooterWeight, "normal", offer.footer) + "</a>";
		html += "</td></tr></table></td></tr></table></a></div>";
		PCJSF_Support_OffersList.push(i);
	}
	document.getElementById("PCJSF_Support_OfferContainer").innerHTML = PCJSF_FixS(html);
	PCJSF_Support_RandomizeArray(PCJSF_Support_OffersList);
	PCJSF_Support_OfferIndex = 0;
	PCJSF_Support_OfferOffset = 0;
	PCJSF__LastMove = (new Date()).getTime();
	PCJSF_Support_UpdateOfferPositions();
}

function PCJSF_Support_CalculateLayout()
{
	var len = PCJSF_Support_OffersList.length;
	if(len == 0)return;
	var space = PCJSF_SafeParseInt(document.getElementById("PCJSF_Support_OfferTable").scrollWidth) - 36;
	var visibleItems = PCJSF_SafeParseInt(space / 200);
	if(visibleItems < 1)visibleItems = 1;
	var indent = PCJSF_SafeParseInt((space - visibleItems * 178) / (visibleItems + 1));
	var before = 0;
	var after = 0;
	if(len > visibleItems)
	{
		before = PCJSF_SafeParseInt((PCJSF_Support_OfferOffset <= 0) ? ((len - visibleItems) / 2) : ((len - visibleItems + 1) / 2));
		after = PCJSF_SafeParseInt((PCJSF_Support_OfferOffset <= 0) ? ((len - visibleItems + 1) / 2) : ((len - visibleItems) / 2));
	}
	PCJSF__OfferLen = len;
	PCJSF__OfferSpace = space;
	PCJSF__OfferVisible = visibleItems;
	PCJSF__OfferIndent = indent;
	PCJSF__OfferBefore = before;
	PCJSF__OfferAfter = after;
}

function PCJSF_Support_UpdateOfferPositions()
{
	if(!PCJSF_Support_OffersActive)return;
	PCJSF_Support_CalculateLayout();
	var i;
	var l = PCJSF__OfferVisible + PCJSF__OfferAfter;
	if(l + PCJSF__OfferBefore > PCJSF__OfferLen)l = PCJSF__OfferLen - PCJSF__OfferBefore;
	for(i = -PCJSF__OfferBefore; i < l; i++)
	{
		var index = (PCJSF_Support_OfferIndex + PCJSF__OfferLen + i) % PCJSF__OfferLen;
		var divObj = document.getElementById("PCJSF_Support_Offer" + PCJSF_Support_OffersList[index]);
		divObj.style.left = ((PCJSF__OfferIndent * (i + 1) + i * 180) + PCJSF_Support_OfferOffset) + "px";
	}
}

function PCJSF_Support_SetVisible(visible)
{
	if(!PCJSF_Support_OffersActive)return;
	for(var i = 0;i < PCJSF_Support_OffersList.length; i++)
	{
		document.getElementById("PCJSF_Support_Offer" + i).style.visibility = visible ? "visible" : "hidden";
	}
}

function PCJSF_Support_MoveOffers()
{
	if(!PCJSF_Support_OffersActive)return;
	var currentTime = (new Date()).getTime();
	if(currentTime - PCJSF__LastMove > PCJSF_Support_OfferAutoMovePeriod)
	{
		PCJSF_Support_GotoNext();
	}
	if(PCJSF_Support_OfferOffset == 0)return;
	if(Math.abs(PCJSF_Support_OfferOffset) < 2)
	{
		PCJSF_Support_OfferOffset = 0;
	}
	else
	{
		PCJSF_Support_OfferOffset = PCJSF_SafeParseInt(PCJSF_Support_OfferOffset * 0.7);
	}
	PCJSF_Support_UpdateOfferPositions();
}

setInterval("PCJSF_Support_MoveOffers()", PCJSF_Support_OfferAnimPeriod);

var PCJSF_Support_Loading_DotCount = 0;
var PCJSF_Support_Loading_Timeout;

function PCJSF_Support_Loading_Activate()
{
	PCJSF_Support_ContainerDiv.innerHTML = PCJSF_FixS(
		"<table width=\"100%\" height=\"100%\"><tr><td align=\"center\" valign=\"middle\">" +
		PCJSF_BuildText(
			"span", "PCJSF_Support_Loading_P",
			PCJSF_Support_Font, PCJSF_Support_LargeTextSize, PCJSF_Support_LoadingColor, "bold", "normal",
			"") +
		 "</td></tr></table>");
	PCJSF_Support_Loading_Timeout = setInterval("PCJSF_Support_Loading_Update();", 300);
	PCJSF_Support_Loading_Update();
	PCJSF_DisableSelectionById("PCJSF_Support_Loading_P", "default");
}

function PCJSF_Support_Loading_Deactivate()
{
	clearInterval(PCJSF_Support_Loading_Timeout);
	PCJSF_Support_ContainerDiv.innerHTML = "&nbsp;";
}

function PCJSF_Support_Loading_Update()
{
	PCJSF_Support_Loading_DotCount = (PCJSF_Support_Loading_DotCount + 1) % 10;
	var txt = PCJSF_Support_TxtLoading + "<br />";
	for(var i = 0; i <= PCJSF_Support_Loading_DotCount; i++)txt += ".";
	document.getElementById("PCJSF_Support_Loading_P").innerHTML = txt;
}
var PCJSF_Support_WFV_HasChat = false;

function PCJSF_Support_WFV_Activate()
{
	PCJSF_Support_WFV_HasChat = false;
	var text = PCJSF_Support_OperatorAvailable ? PCJSF_Support_WFV_InviteTextHTML : PCJSF_Support_WFV_NATextHTML;
	var hasText = (text.length > 0);
	var hasStartChat = (PCJSF_Support_OperatorAvailable && !PCJSF_Support_AllowChatInWFV);
	var hasLeaveAMessage = (PCJSF_Support_AllowLeaveAMessage && (!PCJSF_Support_OperatorAvailable || PCJSF_Support_AllowLeaveAMessageOpAv));
	var hasTextPanel = (hasText || hasStartChat || hasLeaveAMessage);
	var html = "";
	html += "<div id=\"PCJSF_wfvt\" style=\"width:100%;height:100%;overflow:hidden\">";
	html += "<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:" + PCJSF_Support_TitleBackground + ";\"><tr><td id=\"PCJSF_wfvh\" height=\"10px\" valign=\"top\">";
	html += PCJSF_Support_GetTitleHTML(PCJSF_Support_WFV_AllowHideTitle, PCJSF_Support_WFV_TitleHTML, "picture_wfv", PCJSF_Support_InnerBorderWidth, PCJSF_Support_WFV_ImageWidth, PCJSF_Support_WFV_ImageHeight, PCJSF_Support_WFV_ImageMIME, hasTextPanel);
	if(hasTextPanel)
	{
		html += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td colspan=\"2\" height=\"7px\"></td></tr><tr><td width=\"12px\"></td><td>";
		if(hasText)
		{
			html += PCJSF_BuildText("span", null, PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", text);
			if(hasStartChat || hasLeaveAMessage)html += "<br /><br />";
		}
		if(hasStartChat)
		{
			html += PCJSF_BuildTextButton(PCJSF_Support_WFV_StartChatButtonText, PCJSF_Support_WFV_StartChat) + "<div style=\"width:10px;height:20px;float:left;\"></div>";
		}
		if(hasLeaveAMessage)
		{
			html += PCJSF_BuildTextButton(PCJSF_Support_WFV_LeaveAMessageButtonText, PCJSF_Support_WFV_LeaveAMessage);
		}
		html += "</td><td width=\"12px\"></td></tr><tr><td colspan=\"2\" height=\"7px\"></td></tr></table>";
	}
	var add = "";
	if(PCJSF_Support_ManualSizeUpdate)
	{
		add = " id=\"PCJSF_wfvm\" style=\"height:100px;\"";
	}
	if(PCJSF_Support_AllowChatInWFV && PCJSF_Support_OperatorAvailable)
	{
		html += "</td></tr><tr><td" + add + ">";
		html += PCJSF_Support_GetChatHTML();
	}
	else html += "</td></tr><tr><td" + add + ">&nbsp;";
	if(PCJSF_Support_WFV_ShowOffers)
	{
		html += "</td></tr><tr><td height=\"" + PCJSF_Support_InnerBorderWidth + "\" style=\"font-size:4px;\">";
		html += "	<div style=\"width:100%;height:" + PCJSF_Support_InnerBorderWidth + ";background:" + PCJSF_Support_InnerBorderColor + ";\"></div>";
		html += "</td></tr><tr><td height=\"70px\"><div id=\"PCJSF_Support_OffersBox\" style=\"width:100%;height:70px;\"></div>";
	}
	html += "</td></tr></table></div>";
	PCJSF_Support_ContainerDiv.innerHTML = PCJSF_FixS(html);
	PCJSF_DisableSelectionById("PCJSF_Support_Title_Text", "default");
	if(PCJSF_Support_AllowChatInWFV && PCJSF_Support_OperatorAvailable)
	{
		PCJSF_Chat_InitChatArea(document.getElementById("PCJSF_Support_ChatDiv"), document.getElementById("PCJSF_Support_ChatContainer"), document.getElementById("PCJSF_Support_ChatInput"), 0);
		PCJSF_Support_WFV_HasChat = true;
	}
	if(PCJSF_Support_WFV_ShowOffers)PCJSF_Support_InitOffers(PCJSF_Support_OffersId);
	if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_WFVUpdateSize();
}

function PCJSF_Support_WFVUpdateSize()
{
	var h = (PCJSF_Support_ElementHeight("PCJSF_wfvt") -  PCJSF_Support_ElementHeight("PCJSF_wfvh") - (PCJSF_Support_WFV_ShowOffers ? 77 : 0));
	if(h < 0)h = 0;
	document.getElementById("PCJSF_wfvm").style.height = h + "px";
	if(PCJSF_Support_AllowChatInWFV && PCJSF_Support_OperatorAvailable)PCJSF_Support_UpdateChatHTML(h);
}

function PCJSF_Support_WFV_StartChat()
{
	PCJSF_Support_Commands.push("wfv_start_chat");
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Support_WFV_LeaveAMessage()
{
	PCJSF_Support_Commands.push("wfv_leave_a_message");
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Support_WFV_Deactivate()
{
	PCJSF_Support_DestroyOffers();
	if(PCJSF_Support_WFV_HasChat)
	{
		PCJSF_Chat_DestroyChatArea(0);
	}
	PCJSF_Support_ContainerDiv.innerHTML = "&nbsp;";
}

var PCJSF_Support_WFO_HasChat = false;

function PCJSF_Support_WFO_Activate()
{
	PCJSF_Support_WFO_HasChat = false;
	
	var text = PCJSF_Support_OperatorAvailable ? PCJSF_Support_WFO_WaitTextHTML : PCJSF_Support_WFO_NATextHTML;
	var hasText = (text.length > 0);
	var hasLeaveAMessage = (PCJSF_Support_AllowLeaveAMessage && (!PCJSF_Support_OperatorAvailable || PCJSF_Support_AllowLeaveAMessageOpAv));
	var hasTextPanel = (hasText || hasLeaveAMessage);
	
	var html = "";
	html += "<div id=\"PCJSF_wfot\" style=\"width:100%;height:100%;overflow:hidden\">";
	html += "<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:" + PCJSF_Support_TitleBackground + ";\"><tr><td id=\"PCJSF_wfoh\" height=\"10px\" valign=\"top\">";
	html += PCJSF_Support_GetTitleHTML(PCJSF_Support_WFO_AllowHideTitle, PCJSF_Support_WFO_TitleHTML, "picture_wfo", PCJSF_Support_InnerBorderWidth, PCJSF_Support_WFO_ImageWidth, PCJSF_Support_WFO_ImageHeight, PCJSF_Support_WFO_ImageMIME, hasTextPanel);
	if(hasTextPanel)
	{
		html += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td colspan=\"2\" height=\"7px\"></td></tr><tr><td width=\"12px\"></td><td>";
		if(hasText)
		{
			html += PCJSF_BuildText("span", null, PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", text);
			if(hasLeaveAMessage)html += "<br /><br />";
		}
		if(hasLeaveAMessage)
		{
			html += PCJSF_BuildTextButton(PCJSF_Support_WFO_LeaveAMessageButtonText, PCJSF_Support_WFO_LeaveAMessage);
		}
		html += "</td><td width=\"12px\"></td></tr><tr><td colspan=\"2\" height=\"7px\"></td></tr></table>";
	}
	var add = "";
	if(PCJSF_Support_ManualSizeUpdate)
	{
		add = " id=\"PCJSF_wfom\" style=\"height:100px;\"";
	}
	if(PCJSF_Support_AllowChatInWFO && PCJSF_Support_OperatorAvailable)
	{
		html += "</td></tr><tr><td" + add + ">";
		html += PCJSF_Support_GetChatHTML();
	}
	else html += "</td></tr><tr><td" + add + ">&nbsp;";
	if(PCJSF_Support_WFO_ShowOffers)
	{
		html += "</td></tr><tr><td height=\"" + PCJSF_Support_InnerBorderWidth + "x\" style=\"font-size:4px;\">";
		html += "	<div style=\"width:100%;height:" + PCJSF_Support_InnerBorderWidth + ";background:" + PCJSF_Support_InnerBorderColor + ";\"></div>";
		html += "</td></tr><tr><td height=\"70px\"><div id=\"PCJSF_Support_OffersBox\" style=\"width:100%;height:70px;\"></div>";
	}
	html += "</td></tr></table></div>";
	PCJSF_Support_ContainerDiv.innerHTML = PCJSF_FixS(html);
	PCJSF_DisableSelectionById("PCJSF_Support_Title_Text", "default");
	if(PCJSF_Support_AllowChatInWFO && PCJSF_Support_OperatorAvailable)
	{
		PCJSF_Chat_InitChatArea(document.getElementById("PCJSF_Support_ChatDiv"), document.getElementById("PCJSF_Support_ChatContainer"), document.getElementById("PCJSF_Support_ChatInput"), 0);
		PCJSF_Support_WFO_HasChat = true;
	}
	if(PCJSF_Support_WFO_ShowOffers)PCJSF_Support_InitOffers(PCJSF_Support_OffersId);
	if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_WFOUpdateSize();
}

function PCJSF_Support_WFOUpdateSize()
{
	var h = (PCJSF_Support_ElementHeight("PCJSF_wfot") -  PCJSF_Support_ElementHeight("PCJSF_wfoh") - (PCJSF_Support_WFO_ShowOffers ? 77 : 0)) + 1;	
	if(h < 0)h = 0;
	document.getElementById("PCJSF_wfom").style.height = h + "px";
	if(PCJSF_Support_AllowChatInWFO && PCJSF_Support_OperatorAvailable)PCJSF_Support_UpdateChatHTML(h);
}

function PCJSF_Support_WFO_LeaveAMessage()
{
	PCJSF_Support_Commands.push("wfo_leave_a_message");
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Support_WFO_Deactivate()
{
	PCJSF_Support_DestroyOffers();
	if(PCJSF_Support_WFO_HasChat)
	{
		PCJSF_Chat_DestroyChatArea(0);
	}
	PCJSF_Support_ContainerDiv.innerHTML = "&nbsp;";
}

function PCJSF_Support_SES_Activate()
{
	PCJSF_Support_WFO_HasChat = false;
	var html = "";
	html += "<div id=\"PCJSF_sest\" style=\"width:100%;height:100%;overflow:hidden\">";
	html += "<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:" + PCJSF_Support_TitleBackground + ";\"><tr><td id=\"PCJSF_sesh\" height=\"10px\" valign=\"top\">";
	html += PCJSF_Support_GetTitleHTML(PCJSF_Support_SES_AllowHideTitle, PCJSF_Support_SES_TitleHTML, "picture_ses", 0, PCJSF_Support_SES_ImageWidth, PCJSF_Support_SES_ImageHeight, PCJSF_Support_SES_ImageMIME, true);
	var add = "";
	if(PCJSF_Support_ManualSizeUpdate)
	{
		add = " id=\"PCJSF_sesm\" style=\"height:100px;\"";
	}
	html += "</td></tr><tr><td" + add + ">";
	html += PCJSF_Support_GetChatHTML();
	if(PCJSF_Support_SES_ShowOffers)
	{
		html += "</td></tr><tr><td height=\"" + PCJSF_Support_InnerBorderWidth + "\" style=\"font-size:4px;\">";
		html += "	<div style=\"width:100%;height:" + PCJSF_Support_InnerBorderWidth + ";background:" + PCJSF_Support_InnerBorderColor + ";\"></div>";
		html += "</td></tr><tr><td height=\"70px\"><div id=\"PCJSF_Support_OffersBox\" style=\"width:100%;height:70px;\"></div>";
	}
	html += "</td></tr></table></div>";
	PCJSF_Support_ContainerDiv.innerHTML = PCJSF_FixS(html);
	PCJSF_DisableSelectionById("PCJSF_Support_Title_Text", "default");
	PCJSF_Chat_InitChatArea(document.getElementById("PCJSF_Support_ChatDiv"), document.getElementById("PCJSF_Support_ChatContainer"), document.getElementById("PCJSF_Support_ChatInput"), 0);
	if(PCJSF_Support_SES_ShowOffers)PCJSF_Support_InitOffers(PCJSF_Support_OffersId);
	if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_SESUpdateSize();
}

function PCJSF_Support_SESUpdateSize()
{
	var h = (PCJSF_Support_ElementHeight("PCJSF_sest") -  PCJSF_Support_ElementHeight("PCJSF_sesh") - (PCJSF_Support_SES_ShowOffers ? 77 : 0));
	if(h < 0)h = 0;
	document.getElementById("PCJSF_sesm").style.height = h + "px";
	PCJSF_Support_UpdateChatHTML(h);
}

function PCJSF_Support_SES_Deactivate()
{
	PCJSF_Support_DestroyOffers();
	PCJSF_Chat_DestroyChatArea(0);
	PCJSF_Support_ContainerDiv.innerHTML = "&nbsp;";
}

function PCJSF_Support_LAMInputStyle()
{
	return 	"border:" + PCJSF_Support_InputBorder +
			";background:" + PCJSF_Support_TypeBackground +
			";font-family:" + PCJSF_Support_Font +
			";font-size:" + PCJSF_Support_TypeSize +
			";color:" + PCJSF_Support_TypeColor +
			";font-weight:" + PCJSF_Support_TypeWeight + ";";
}

function PCJSF_Support_LAM_Activate()
{
	var html = "";
	html += "<div id=\"PCJSF_lamt\" style=\"width:100%;height:100%;overflow:hidden\">";
	html += "<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:" + PCJSF_Support_TitleBackground + ";\"><tr><td id=\"PCJSF_lamh\" height=\"10px\" valign=\"top\">";
	html += PCJSF_Support_GetTitleHTML(PCJSF_Support_LAM_AllowHideTitle, PCJSF_Support_LAM_TitleHTML, "picture_lam", PCJSF_Support_InnerBorderWidth, PCJSF_Support_LAM_ImageWidth, PCJSF_Support_LAM_ImageHeight, PCJSF_Support_LAM_ImageMIME, true);
	html +=
		"<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td colspan=\"2\" height=\"7px\"></td></tr><tr><td width=\"12px\"></td><td colspan=\"2\">" +
		PCJSF_BuildText(
			"span", null,
			PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", PCJSF_Support_LAM_TextHTML) +
		"<br /><br />";
	html += PCJSF_BuildTextButton(PCJSF_Support_LAM_BackButtonText, PCJSF_Support_LAM_GoBack) + "&nbsp;";
	html += "</td><td width=\"12px\"></td></tr>";
	html += "<tr><td colspan=\"4\" height=\"7px\"></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan=\"2\">";
	html += PCJSF_BuildText("span", null, PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", PCJSF_Support_LAM_EMailLabelText);
	html += "<td width=\"12px\"></td></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan=\"2\"><input id=\"PCJSF_Support_LAM_EMail\" type=\"text\" style = \"width:100%;height:" + PCJSF_Support_InputHeight + ";" + PCJSF_Support_LAMInputStyle() + "\"/></td><td width=\"12px\"></td></tr>";
	html += "<tr><td colspan=\"4\" height=\"7px\"></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan=\"2\">";
	html += PCJSF_BuildText("span", null, PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", PCJSF_Support_LAM_NameLabelText);
	html += "<td width=\"12px\"></td></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan=\"2\"><input id=\"PCJSF_Support_LAM_Name\" type=\"text\" style = \"width:100%;height:" + PCJSF_Support_InputHeight + ";" + PCJSF_Support_LAMInputStyle() + "\"/></td><td width=\"12px\"></td></tr>";
	html += "<tr><td colspan=\"4\" height=\"7px\"></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan = \"2\">";
	html += PCJSF_BuildText("span", null, PCJSF_Support_Font, PCJSF_Support_MainTextSize, PCJSF_Support_MainTextColor, "bold", "normal", PCJSF_Support_LAM_MessageLabelText);
	html += "</td><td width=\"12px\"></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan = \"2\"><textarea id=\"PCJSF_Support_LAM_Message\" style=\"width:100%;height:50px;" + PCJSF_Support_LAMInputStyle() + "\"></textarea><td width=\"12px\"></td></tr>";
	html += "<tr><td colspan=\"4\" height=\"7px\"></td></tr>";
	html += "<tr><td width=\"12px\"></td><td colspan = \"2\">";
	html += PCJSF_BuildTextButton(PCJSF_Support_LAM_SendButtonText, PCJSF_Support_LAM_Send) + "&nbsp;";
	html += "</td><td width=\"12px\"></td></tr>";
	html += "</table>";
	var add = "";
	if(PCJSF_Support_ManualSizeUpdate)
	{
		add = " id=\"PCJSF_lamm\" style=\"height:100px;\"";
	}
	html += "</td></tr><tr><td" + add + ">&nbsp;";
	if(PCJSF_Support_LAM_ShowOffers)
	{
		html += "</td></tr><tr><td height=\"7px\" style=\"font-size:4px;\">";
		html += "	<div style=\"width:100%;height:7px;background:" + PCJSF_Support_InnerBorderColor + ";\"></div>";
		html += "</td></tr><tr><td height=\"70px\"><div id=\"PCJSF_Support_OffersBox\" style=\"width:100%;height:70px;\"></div>";
	}
	html += "</td></tr></table>";
	PCJSF_Support_ContainerDiv.innerHTML = PCJSF_FixS(html);
	PCJSF_DisableSelectionById("PCJSF_Support_Title_Text", "default");
	if(PCJSF_Support_LAM_ShowOffers)PCJSF_Support_InitOffers(PCJSF_Support_OffersId);
	if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_LAMUpdateSize();
}

function PCJSF_Support_LAMUpdateSize()
{
	var h = (PCJSF_Support_ElementHeight("PCJSF_lamt") -  PCJSF_Support_ElementHeight("PCJSF_lamh") - (PCJSF_Support_LAM_ShowOffers ? 77 : 0));
	if(h < 0)h = 0;
	document.getElementById("PCJSF_lamm").style.height = h + "px";
}

function PCJSF_Support_LAM_GoBack()
{
	PCJSF_Support_Commands.push("lam_go_back");
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Support_LAM_Send()
{
	PCJSF_Support_LAM_EMail = document.getElementById("PCJSF_Support_LAM_EMail").value;
	PCJSF_Support_LAM_Name = document.getElementById("PCJSF_Support_LAM_Name").value;
	PCJSF_Support_LAM_Message = document.getElementById("PCJSF_Support_LAM_Message").value;
	PCJSF_Support_Commands.push("lam_leave_a_message");
	PCJSF_Processor_RegisterRequest(0);
}

function PCJSF_Support_LAM_Deactivate()
{
	PCJSF_Support_DestroyOffers();
	PCJSF_Support_ContainerDiv.innerHTML = "&nbsp;";
}

var PCJSF_Support_PopupState = "closed";
var PCJSF_Support_PopupStateAltered = false;
var PCJSF_Support_State = "unk";
var PCJSF_Support_VisibleState = "";
var PCJSF_Support_ContainerDiv = null;
var PCJSF_Support_MasterDiv = null;
var PCJSF_Support_Temp = navigator.userAgent.toLowerCase();
var PCJSF_Support_IsIE = ((PCJSF_Support_Temp.indexOf("msie") != -1) && (PCJSF_Support_Temp.indexOf("opera") == -1));
var PCJSF_Support_IsIE8 = PCJSF_Support_IsIE ? (getInternetExplorerVersion() >= 8.0) : false;
var PCJSF_Support_IsIE6 = PCJSF_Support_IsIE ? (getInternetExplorerVersion() < 7.0) : false;
var PCJSF_Support_IsChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var PCJSF_Support_IsSafari = (PCJSF_Support_Temp.indexOf("safari") >= 0);
var PCJSF_Support_ManualSizeUpdate = false;
var PCJSF_Support_MinimizeButtonIndex;
var PCJSF_Support_LoadedSets = new Array();
var PCJSF_Support_SkinURL;
var PCJSF_Support_TitleVisible = 1;
var PCJSF_Support_SentCommands = new Array();
var PCJSF_Support_Commands = new Array();
var PCJSF_Support_SetStateDone = false;
var PCJSF_Support_TempUpdateChatDiv = 0;

//Skin
var PCJSF_Support_Font = "Arial";

var PCJSF_Support_LargeTextSize = "20px";
var PCJSF_Support_TitleTextSize = "14px";
var PCJSF_Support_ButtonTextSize = "11px";
var PCJSF_Support_MainTextSize = "12px";
var PCJSF_Support_PoweredByTextSize = "10px";

var PCJSF_Support_LoadingColor = "brown";
var PCJSF_Support_HeaderColor = "#e0e0e0";
var PCJSF_Support_BorderColor = "#000000";
var PCJSF_Support_BorderAlpha = 55;
var PCJSF_Support_InnerBorderColor = "#666666";
var PCJSF_Support_BaseColor = "#ffffff";
var PCJSF_Support_TitleColor = "#000000";
var PCJSF_Support_TitleWeight = "bold";
var PCJSF_Support_ButtonColor = "#d0d0d0";
var PCJSF_Support_ButtonHOverColor = "#f0f0f0";
var PCJSF_Support_MainTextColor = "#000000";
var PCJSF_Support_PoweredByHeight = "12px";
var PCJSF_Support_PoweredByTextColor = "#ffffff";

var PCJSF_Support_SwitchBackground = "#cccccc";
var PCJSF_Support_SwitchBorder = "#999999";
var PCJSF_Support_TitleBackground = "#ffffff";
var PCJSF_Support_ChatBackground = "#ffffff";
var PCJSF_Support_TypeSize = "12px";
var PCJSF_Support_TypeColor = "#000000";
var PCJSF_Support_TypeWeight = "normal";
var PCJSF_Support_TypeBackground = "#ffffff";
var PCJSF_Support_OffersBackground = "#ffffff";
var PCJSF_Support_OfferBorder = "1px solid #cccccc";
var PCJSF_Support_ButtonBorder = "1px solid black";
var PCJSF_Support_ButtonBackground = "#2d2d2d";
var PCJSF_Support_InputBorder = "1px solid black";
var PCJSF_Support_InputHeight = "20px";

var PCJSF_Support_OfferFont = "Tahoma";
var PCJSF_Support_OfferTitleDecoration = "none";
var PCJSF_Support_OfferTitleSize = "11px";
var PCJSF_Support_OfferTitleColor = "#000000";
var PCJSF_Support_OfferTitleWeight = "bold";
var PCJSF_Support_OfferTextDecoration = "none";
var PCJSF_Support_OfferTextSize = "11px";
var PCJSF_Support_OfferTextColor = "#000000";
var PCJSF_Support_OfferTextWeight = "normal";
var PCJSF_Support_OfferFooterDecoration = "none";
var PCJSF_Support_OfferFooterSize = "11px";
var PCJSF_Support_OfferFooterColor = "#000000";
var PCJSF_Support_OfferFooterWeight = "bold";

var PCJSF_Support_ChatSeparatorHeight = "24px";
var PCJSF_Support_BorderWidth = "6px";
var PCJSF_Support_InnerBorderWidth = "7px";
var PCJSF_Support_ImageBorderWidth = "4px";
var PCJSF_Support_ImagePadding = "7px";


//Messages
var PCJSF_Support_TxtLoading = "Loading";

//Global configuration
var PCJSF_Support_GlobalConf = 0;
var PCJSF_Support_ConfigurationCode = "";
var PCJSF_Support_TitleType = 0; //0-Default, 1-Image, 2-Text
var PCJSF_Support_TitleText = "";
var PCJSF_Support_Skin = "default";
var PCJSF_Support_Width = 0;
var PCJSF_Support_Height = 0;
var PCJSF_Support_MinWidth =300;
var PCJSF_Support_MinHeight = 300;
var PCJSF_Support_MaxWidth = 800;
var PCJSF_Support_MaxHeight = 800;
var PCJSF_Support_AlignmentX = 2;
var PCJSF_Support_AlignmentY = 2;
var PCJSF_Support_OffsetX = 30;
var PCJSF_Support_OffsetY = 30;
var PCJSF_Support_AllowMove = 1;
var PCJSF_Support_AllowResize = 1;
var PCJSF_Support_AllowChatInWFO = 1;
var PCJSF_Support_AllowChatInWFV = 1;
var PCJSF_Support_AllowLeaveAMessage = 1;
var PCJSF_Support_AllowLeaveAMessageInSES = 1;
var PCJSF_Support_AllowLeaveAMessageOpAv = 1;
var PCJSF_Support_ShowLiveChat = 1;
var PCJSF_Support_LivechatURL = "";
var PCJSF_Support_LivechatScript = "";
var PCJSF_Support_LivechatImageURL = "";
var PCJSF_Support_LivechatImageWidth = "";
var PCJSF_Support_LivechatImageHeight = "";
var PCJSF_Support_TypeHereText = "";
var PCJSF_Support_OffersId = "";
var PCJSF_Support_FB_Show = 0;
var PCJSF_Support_FB_ShowWhenOffline = 0;
var PCJSF_Support_FB_AlignmentX = 2;
var PCJSF_Support_FB_AlignmentY = 2;
var PCJSF_Support_FB_OffsetX = 30;
var PCJSF_Support_FB_OffsetY = 30;

var PCJSF_Support_OperatorAvailable = 0;

//WFV
var PCJSF_Support_WFV_TitleHTML = "";
var PCJSF_Support_WFV_ImageMIME = "";
var PCJSF_Support_WFV_ImageWidth = 0;
var PCJSF_Support_WFV_ImageHeight = 0;
var PCJSF_Support_WFV_InviteTextHTML = "";
var PCJSF_Support_WFV_NATextHTML = "";
var PCJSF_Support_WFV_LeaveAMessageButtonText = "";
var PCJSF_Support_WFV_StartChatButtonText = "";
var PCJSF_Support_WFV_AllowHideTitle = 1;
var PCJSF_Support_WFV_ShowOffers = 1;

//WFO
var PCJSF_Support_WFO_TitleHTML = "";
var PCJSF_Support_WFO_ImageMIME = "";
var PCJSF_Support_WFO_ImageWidth = 0;
var PCJSF_Support_WFO_ImageHeight = 0;
var PCJSF_Support_WFO_WaitTextHTML = "";
var PCJSF_Support_WFO_NATextHTML = "";
var PCJSF_Support_WFO_LeaveAMessageButtonText = "";
var PCJSF_Support_WFO_AllowHideTitle = 1;
var PCJSF_Support_WFO_ShowOffers = 1;

//LAM
var PCJSF_Support_LAM_TitleHTML = "";
var PCJSF_Support_LAM_ImageMIME = "";
var PCJSF_Support_LAM_ImageWidth = 0;
var PCJSF_Support_LAM_ImageHeight = 0;
var PCJSF_Support_LAM_TextHTML = "";
var PCJSF_Support_LAM_EMailLabelText = "";
var PCJSF_Support_LAM_NameLabelText = "";
var PCJSF_Support_LAM_MessageLabelText = "";
var PCJSF_Support_LAM_SendButtonText = "";
var PCJSF_Support_LAM_BackButtonText = "";
var PCJSF_Support_LAM_AllowHideTitle = 1;
var PCJSF_Support_LAM_ShowOffers = 1;

//SES
var PCJSF_Support_SES_TitleHTML = "";
var PCJSF_Support_SES_ImageMIME = "";
var PCJSF_Support_SES_ImageWidth = 0;
var PCJSF_Support_SES_ImageHeight = 0;
var PCJSF_Support_SES_NickButtonText = "";
var PCJSF_Support_SES_MailButtonText = "";
var PCJSF_Support_SES_AllowHideTitle = 1;
var PCJSF_Support_SES_ShowOffers = 1;
var PCJSF_Support_SES_NIK_TitleText = "";
var PCJSF_Support_SES_NIK_TextHTML = "";
var PCJSF_Support_SES_NIK_NickLabelText = "";
var PCJSF_Support_SES_NIK_SetButtonText = "";
var PCJSF_Support_SES_MAIL_TitleText = "";
var PCJSF_Support_SES_MAIL_TextHTML = "";
var PCJSF_Support_SES_MAIL_EMailLabelText = "";
var PCJSF_Support_SES_MAIL_SetButtonText = "";

var PCJSF_Support_LAM_EMail = "";
var PCJSF_Support_LAM_Name = "";
var PCJSF_Support_LAM_Message = "";

//Communication
function PCJSF_Support_CollectRequestData(connecting, data)
{
	var d = data["support"] = new Array();
	d["state"] = PCJSF_Support_PopupState + ";" + PCJSF_Support_State;
	var load = "";
	if(!PCJSF_Support_GlobalConf)load += "global;";
	if(!PCJSF_Support_LoadedSets[PCJSF_Support_State])load += PCJSF_Support_State + ";";
	if(load.length > 0)d["load"] = load;
	PCJSF_Support_SentCommands = PCJSF_Support_SentCommands.concat(PCJSF_Support_Commands);
	PCJSF_Support_Commands = new Array();
	var commands = "";
	for(var i = 0; i < PCJSF_Support_SentCommands.length; i++)
	{
		if(commands != "")commands += ";";
		var command = PCJSF_Support_SentCommands[i];
		commands += command;
		if(command == "lam_leave_a_message")
		{
			d["mail"] = PCJSF_Support_LAM_EMail;
			d["name"] = PCJSF_Support_LAM_Name;
			d["message"] = PCJSF_Support_LAM_Message;
		}
	}
	if(commands != "")d["commands"] = commands;
	if(connecting)
	{
		d["connecting"] = "1";
		var loc = String(document.location);
		var qIndex = loc.indexOf("?");
		if(qIndex >= 0)
		{
			var pri = loc.indexOf("prcc=", qIndex);
			if(pri >= 0)
			{
				if((pri == qIndex + 1) || (loc.charAt(pri - 1) == "&"))
				{
					var end = loc.indexOf("&", pri);
					if(end < 0)end = loc.length;
					d["campaign"] = loc.substr(pri + 5, end - pri - 5);
				}
			}
		}
	}
}

function PCJSF_Support_CollectState()
{
	if((PCJSF_Support_Width == 0) || (PCJSF_Support_Height == 0))return "";
	return	PCJSF_Support_OffsetX + "," + PCJSF_Support_OffsetY + "," + PCJSF_Support_Width + "," + PCJSF_Support_Height + "," +
			PCJSF_Support_PopupState + "," + PCJSF_Support_TitleVisible;
}

function PCJSF_Support_JSSChanged()
{
	if(PCJSF_Tracker_VisitorKey == "")return;
	var state = PCJSF_Support_CollectState();
	if(state != "")PCJSF_CreateCookie("PCJSF_JSS" + PCJSF_Tracker_VisitorKey, state, 1);
}

function PCJSF_Support_SetState(state)
{
	if(!state)return;
	var parts = state.split(",");	
	if(parts.length == 6)
	{
		PCJSF_Support_OffsetX = parseInt(parts[0]);
		PCJSF_Support_OffsetY = parseInt(parts[1]);
		PCJSF_Support_Width = parseInt(parts[2]);
		PCJSF_Support_Height = parseInt(parts[3]);
		if(PCJSF_Support_Width < PCJSF_Support_MinWidth)PCJSF_Support_Width = PCJSF_Support_MinWidth;
		if(PCJSF_Support_Width > PCJSF_Support_MaxWidth)PCJSF_Support_Width = PCJSF_Support_MaxWidth;
		if(PCJSF_Support_Height < PCJSF_Support_MinHeight)PCJSF_Support_Height = PCJSF_Support_MinHeight;
		if(PCJSF_Support_Height > PCJSF_Support_MaxHeight)PCJSF_Support_Height = PCJSF_Support_MaxHeight;
		if((PCJSF_Support_PopupState != "embedded") && (parts[4] != "embedded"))PCJSF_Support_PopupState = parts[4];
		PCJSF_Support_TitleVisible = parseInt(parts[5]);
	}
}

function PCJSF_Support_SkinLoaded()
{
	PCJSF_Support_GlobalConf = 1;
	if(PCJSF_Support_PopupState != "embedded")
	{
		if(PCJSF_Support_GlobalConf && !PCJSF_Support_MasterDiv)PCJSF_Support_CreatePopup();
	}
	PCJSF_Support_UpdateState();
}

function PCJSF_Support_HandleResponseData(connecting, data)
{
	if(data["support"] !== undefined)
	{
		var d = data["support"];
		if(d["global"] != undefined)
		{
			var gp = PCJSF_SplitParameters(d["global"]);
			PCJSF_Support_ConfigurationCode = gp[0];
			PCJSF_Support_TitleType = gp[1];
			PCJSF_Support_TitleText = gp[2];
			PCJSF_Support_Skin = gp[3];
			PCJSF_Support_AllowMove = parseInt(gp[4]);
			PCJSF_Support_AllowResize = parseInt(gp[5]);
			PCJSF_Support_AlignmentX = parseInt(gp[6]);
			PCJSF_Support_AlignmentY = parseInt(gp[7]);
			PCJSF_Support_OffsetX = parseInt(gp[8]);
			PCJSF_Support_OffsetY = parseInt(gp[9]);
			PCJSF_Support_MinWidth = parseInt(gp[10]);
			PCJSF_Support_MaxWidth = parseInt(gp[11]);
			PCJSF_Support_Width = parseInt(gp[12]);
			PCJSF_Support_MinHeight = parseInt(gp[13]);
			PCJSF_Support_MaxHeight = parseInt(gp[14]);
			PCJSF_Support_Height = parseInt(gp[15]);
			PCJSF_Support_AllowChatInWFO = parseInt(gp[16]);
			PCJSF_Support_AllowChatInWFV = parseInt(gp[17]);
			PCJSF_Support_AllowLeaveAMessage = parseInt(gp[18]);
			PCJSF_Support_AllowLeaveAMessageInSES = parseInt(gp[19]);
			PCJSF_Support_AllowLeaveAMessageOpAv = parseInt(gp[20]);
			PCJSF_Support_ShowLiveChat = parseInt(gp[21]);
			PCJSF_Support_LivechatURL = gp[22];
			PCJSF_Support_LivechatScript = gp[23];
			PCJSF_Support_LivechatImageURL = gp[24];
			PCJSF_Support_LivechatImageWidth = gp[25];
			PCJSF_Support_LivechatImageHeight = gp[26];
			PCJSF_Support_TypeHereText = gp[27];
			PCJSF_Support_OffersId = gp[28];
			PCJSF_Support_FB_Show = parseInt(gp[29]);
			PCJSF_Support_FB_ShowWhenOffline = parseInt(gp[30]);
			PCJSF_Support_FB_AlignmentX = parseInt(gp[31]);
			PCJSF_Support_FB_AlignmentY = parseInt(gp[32]);
			PCJSF_Support_FB_OffsetX = parseInt(gp[33]);
			PCJSF_Support_FB_OffsetY = parseInt(gp[34]);
			
			PCJSF_Support_SkinURL = PCJSF_Processor_ServerURL + "Public/Skins/" + PCJSF_Support_Skin + "/";
			if((PCJSF_Tracker_VisitorKey != "") && (!PCJSF_Support_SetStateDone))
			{
				PCJSF_Support_SetStateDone = true;
				PCJSF_Support_SetState(PCJSF_ReadCookie("PCJSF_JSS" + PCJSF_Tracker_VisitorKey));
			}
			if(PCJSF_Support_GlobalConf == 0)
			{
				var scriptContainer = document.getElementById("PCJSF_ScriptContainer");
				var scriptChildElement = document.createElement("script");
				scriptChildElement.setAttribute("src", PCJSF_Processor_ServerURL + "Public/LoadSkin.php?skin=" + PCJSF_Support_Skin + "&prefix=PCJSF_");
				scriptChildElement.setAttribute("type", 'text/javascript');
				scriptContainer.appendChild(scriptChildElement); 
			}
		}
		if(d["wfv"] != undefined)
		{
			var vp = PCJSF_SplitParameters(d["wfv"]);
			PCJSF_Support_WFV_TitleHTML = vp[0];
			PCJSF_Support_WFV_ImageMIME = vp[1];
			PCJSF_Support_WFV_ImageWidth = parseInt(vp[2]);
			PCJSF_Support_WFV_ImageHeight = parseInt(vp[3]);
			PCJSF_Support_WFV_InviteTextHTML = vp[4];
			PCJSF_Support_WFV_NATextHTML = vp[5];
			PCJSF_Support_WFV_LeaveAMessageButtonText = vp[6];
			PCJSF_Support_WFV_StartChatButtonText = vp[7];
			PCJSF_Support_WFV_AllowHideTitle = parseInt(vp[8]);
			PCJSF_Support_WFV_ShowOffers = parseInt(vp[9]);
			PCJSF_Support_LoadedSets["wfv"] = true;
		}
		if(d["wfo"] != undefined)
		{
			var vp = PCJSF_SplitParameters(d["wfo"]);
			PCJSF_Support_WFO_TitleHTML = vp[0];
			PCJSF_Support_WFO_ImageMIME = vp[1];
			PCJSF_Support_WFO_ImageWidth = parseInt(vp[2]);
			PCJSF_Support_WFO_ImageHeight = parseInt(vp[3]);
			PCJSF_Support_WFO_WaitTextHTML = vp[4];
			PCJSF_Support_WFO_NATextHTML = vp[5];
			PCJSF_Support_WFO_LeaveAMessageButtonText = vp[6];
			PCJSF_Support_WFO_AllowHideTitle = parseInt(vp[7]);
			PCJSF_Support_WFO_ShowOffers = parseInt(vp[8]);
			PCJSF_Support_LoadedSets["wfo"] = true;
		}
		if(d["lam"] != undefined)
		{
			var vp = PCJSF_SplitParameters(d["lam"]);
			PCJSF_Support_LAM_TitleHTML = vp[0];
			PCJSF_Support_LAM_ImageMIME = vp[1];
			PCJSF_Support_LAM_ImageWidth = parseInt(vp[2]);
			PCJSF_Support_LAM_ImageHeight = parseInt(vp[3]);
			PCJSF_Support_LAM_TextHTML = vp[4];
			PCJSF_Support_LAM_EMailLabelText = vp[5];
			PCJSF_Support_LAM_NameLabelText = vp[6];
			PCJSF_Support_LAM_MessageLabelText = vp[7];
			PCJSF_Support_LAM_SendButtonText = vp[8];
			PCJSF_Support_LAM_BackButtonText = vp[9];
			PCJSF_Support_LAM_AllowHideTitle = parseInt(vp[10]);
			PCJSF_Support_LAM_ShowOffers = parseInt(vp[11]);
			PCJSF_Support_LoadedSets["lam"] = true;
		}
		if(d["ses"] != undefined)
		{
			var vp = PCJSF_SplitParameters(d["ses"]);
			PCJSF_Support_SES_TitleHTML = vp[0];
			PCJSF_Support_SES_ImageMIME = vp[1];
			PCJSF_Support_SES_ImageWidth = parseInt(vp[2]);
			PCJSF_Support_SES_ImageHeight = parseInt(vp[3]);
			PCJSF_Support_SES_NickButtonText = vp[4];
			PCJSF_Support_SES_MailButtonText = vp[5];
			PCJSF_Support_SES_AllowHideTitle = parseInt(vp[6]);
			PCJSF_Support_SES_ShowOffers = parseInt(vp[7]);
			PCJSF_Support_SES_NIK_TitleText = vp[8];
			PCJSF_Support_SES_NIK_TextHTML = vp[9];
			PCJSF_Support_SES_NIK_NickLabelText = vp[10];
			PCJSF_Support_SES_NIK_SetButtonText = vp[11];
			PCJSF_Support_SES_MAIL_TitleText = vp[12];
			PCJSF_Support_SES_MAIL_TextHTML = vp[13];
			PCJSF_Support_SES_MAIL_EMailLabelText = vp[14];
			PCJSF_Support_SES_MAIL_SetButtonText = vp[15];
			PCJSF_Support_LoadedSets["ses"] = true;
		}
		if(PCJSF_Support_PopupState != "embedded")
		{
			if(PCJSF_Support_GlobalConf && !PCJSF_Support_MasterDiv)PCJSF_Support_CreatePopup();
		}
		if(d["state"] != undefined)
		{
			PCJSF_Support_State = d["state"];
		}
		if((PCJSF_Support_PopupState != "embedded") && (d["pstate"] != undefined))
		{
			if(!PCJSF_Support_PopupStateAltered)PCJSF_Support_PopupState = d["pstate"];
		}
		if(d["opav"] != undefined)
		{
			PCJSF_Support_OperatorAvailable = (d["opav"] == "1") ? 1 : 0;
		}
		PCJSF_Support_UpdateState();
		PCJSF_Support_SentCommands = new Array();
		var timeout;
		if(PCJSF_Support_State == "ses")timeout = PCJSF_Support_SESUpdateTimeout;
		else if(PCJSF_Support_State == "lam")timeout = PCJSF_Support_LAMUpdateTimeout;
		else if(PCJSF_Support_State == "wfo")timeout = PCJSF_Support_WFOUpdateTimeout;
		else timeout = PCJSF_Support_WFVUpdateTimeout;
		if(PCJSF_Tracker_Mode != 0)
		{
			PCJSF_Processor_RegisterRequest(timeout);
		}
		return 1;
	}
	return 0;
}

function PCJSF_Support_OnSizeOrStructureChanged()
{
	PCJSF_Support_UpdatePosition();
	PCJSF_Support_UpdateChatDiv();
	PCJSF_Support_UpdateOfferPositions();
	PCJSF_Support_TempUpdateChatDiv = 2;
}

function PCJSF_Support_GetEmbeddedContainerHTML(addFrame, width, height, noFrameBorderColor)
{
	return PCJSF_FixS("<div id = \"PCJSF_Support_ContainerDiv\" align=\"center\" style = \"width:" + width + "px;height:" + height + "px;border:solid 1px " + noFrameBorderColor + ";overflow:hidden;padding:0px;margin:0px;\"></div>");
}

function PCJSF_Support_CreatePopup()
{
	var skinURL = PCJSF_Support_SkinURL;
	var sz = {};
	sz.width = PCJSF_Support_Width;
	sz.height = PCJSF_Support_Height;
	var position = PCJSF_Support_CalculatePosition(sz, sz, true);
	PCJSF_Support_MasterDiv = document.createElement("div");
	PCJSF_Support_MasterDiv.setAttribute("id", "PCJSF_Support_MasterDiv");
	var style = "";
	style += "position:" + (PCJSF_Support_IsIE ? "absolute" : "fixed") + ";";
	style += "left:" + position.x + "px;top:" + position.y + "px;width:" + PCJSF_Support_Width + "px;height:" + PCJSF_Support_Height + "px;overflow:hidden;";
	style += "background:transparent none;z-index:2147483647;visibility:hidden;";
	PCJSF_Support_MasterDiv.setAttribute("style", style);
	PCJSF_Support_MasterDiv.style.cssText = style;
	var html = "";
	var border = "<div style=\"width:100%;height:100%;background:" + PCJSF_Support_BorderColor + ";" + PCJSF_GetOpacityStyle(PCJSF_Support_BorderAlpha) + "\"></div>";
	html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" height=\"100%\">";
	html += "<tr><td colspan=\"3\" style = \"height:28px;background:" + PCJSF_Support_BaseColor + " url(" + skinURL + "HeaderBackground.png) repeat-x;cursor:move;\" onmousedown=\"PCJSF_Support_MouseDownInHeader(event); return false;\">";
	html += "	<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" height=\"100%\"><tr><td height=\"0px\" colspan=\"2\"></td></tr><tr><td valign=\"top\">";
	if(PCJSF_Support_TitleType == 0)
	{
		html += "			<div style=\"width:100%;height:28px;";
		if(PCJSF_Support_IsIE6)
		{
			html+= "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + skinURL + "DefaultTitle.png', sizingMethod='crop')";
		}
		else
		{
			html += "background:url(" + skinURL + "DefaultTitle.png) no-repeat;";
		}
		html += "\">&nbsp;</div>";
	}
	else if(PCJSF_Support_TitleType == 1)
	{
		html += "			<div style=\"width:100%;height:28px;";
		if(PCJSF_Support_IsIE6)
		{
			html+= "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + PCJSF_Processor_ServerURL + "Public/Support_Image.php?title=" + PCJSF_Support_ConfigurationCode + "', sizingMethod='crop')";
		}
		else
		{
			html += "background:url(" + PCJSF_Processor_ServerURL + "Public/Support_Image.php?title=" + PCJSF_Support_ConfigurationCode + ") no-repeat;";
		}
		html += "\">&nbsp;</div>";
	}
	else if(PCJSF_Support_TitleType == 2)
	{
		html += "			<div style=\"width:100%;height:28px;overflow:hidden;\"><div style=\"padding:0px;padding-top:4px;\">";
		html += PCJSF_BuildText("span", "PCJSF_Support_HeaderText", PCJSF_Support_Font, PCJSF_Support_LargeTextSize, PCJSF_Support_HeaderColor, "bold", "normal", "&nbsp;" + PCJSF_Support_TitleText);
		html += "			</div></div>";
	}
	html += "		</td>";
	html += "		<td width=\"51px\" valign=\"top\">";
	html += PCJSF_BuildButton(25, 28, "display:block;float:left;", skinURL + "Minimize.png", skinURL + "MinimizeHOver.png", null, function(){PCJSF_Support_Minimize();});
	PCJSF_Support_MinimizeButtonIndex = PCJSF_ButtonIndex;
	html += PCJSF_BuildButton(26, 28, "display:block;float:left;", skinURL + "Close.png", skinURL + "CloseHOver.png", null, function(){PCJSF_Support_Close();});
	html += "	</td></tr></table>";
	html +=	"</td></tr>";
	var ch = "100%";
	if(PCJSF_Support_IsIE)
	{
		if(document.compatMode == "CSS1Compat")
		{
			ch = "100px";
			PCJSF_Support_ManualSizeUpdate = true;
		}
	}
	html += "<tr><td id=\"PCJSF_mc1\" width = \"" + PCJSF_Support_BorderWidth + "\" style=\"height:" + ch + ";cursor:w-resize;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 1); return false;\">" + border + "</td>";
	html += "	<td id=\"PCJSF_mc2\" style=\"height:" + ch + ";background:" + PCJSF_Support_BaseColor + ";\"><div id=\"PCJSF_Support_ContainerDiv\" style=\"width:100%;height:100%;overflow:hidden;\">&nbsp;</div></td>";
	html += "	<td id=\"PCJSF_mc3\" width = \"" + PCJSF_Support_BorderWidth + "\" style=\"height:" + ch + ";cursor:e-resize;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 2); return false;\">" + border + "</td></tr>";
	html += "<tr><td width = \"" + PCJSF_Support_BorderWidth + "\" style=\"height:" + PCJSF_Support_PoweredByHeight + ";cursor:w-resize;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 1); return false;\">" + border + "</td>";
	html += "	<td style=\"height:" + PCJSF_Support_PoweredByHeight + ";background:" + PCJSF_Support_BorderColor + ";text-align:right;\">";
	html += PCJSF_BuildText("div", null, PCJSF_Support_Font, PCJSF_Support_PoweredByTextSize, PCJSF_Support_PoweredByTextColor, "bold", "normal", "&nbsp;<a target=\"_blank\" href=\"" + PCJSF_Processor_ServiceURL + "\" style=\"color:" + PCJSF_Support_PoweredByTextColor + ";\"> Powered by Promptchat</a>&nbsp;", "text-align:right;");
	html += "	</td>";
	html += "	<td width = \"" + PCJSF_Support_BorderWidth + "\" style=\"height:" + PCJSF_Support_PoweredByHeight + ";cursor:e-resize;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 2); return false;\">" + border + "</td></tr>";
	html += "<tr><td width = \"" + PCJSF_Support_BorderWidth + "\" height=\"" + PCJSF_Support_BorderWidth + "\" style=\"cursor:sw-resize;font-size:2px;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 5); return false;\">" + border + "</td>";
	html += "	<td height=\"" + PCJSF_Support_BorderWidth + "\" style=\"cursor:s-resize;font-size:2px;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 4); return false;\">" + border + "</td>";
	html += "	<td width = \"" + PCJSF_Support_BorderWidth + "\" height=\"" + PCJSF_Support_BorderWidth + "\" style=\"cursor:se-resize;font-size:2px;\" onmousedown=\"PCJSF_Support_MouseDownForResize(event, 6); return false;\">" + border + "</td></tr>";
	html += "</table>";
	PCJSF_Support_MasterDiv.innerHTML = PCJSF_FixS(html);
	document.body.appendChild(PCJSF_Support_MasterDiv);	
	if(PCJSF_Support_TitleType == 2)PCJSF_DisableSelectionById("PCJSF_Support_HeaderText", "move");
	PCJSF_Support_ContainerDiv = document.getElementById("PCJSF_Support_ContainerDiv");
	if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_UpdateSize(false);
}

var PCJSF_Support_FloatingImg = null;
var PCJSF_Support_FloatingPic = null;

function PCJSF_ShowFloatingButton()
{
	if(!PCJSF_Support_FB_Show || (!PCJSF_Support_FB_ShowWhenOffline && !PCJSF_Support_OperatorAvailable))
	{
		PCJSF_HideFloatingButton();
		return;
	}
	if(PCJSF_Support_FloatingImg == null)
	{
		PCJSF_Support_FloatingImg = document.createElement("img");
		PCJSF_Support_FloatingImg.setAttribute("id", "PCJSF_Support_FloatingImg");
		var style = "";
		style += "position:" + (PCJSF_Support_IsIE ? "absolute" : "fixed") + ";";
		style += "left:" + 0 + "px;top:" + 0+ "px;";
		style += "background:transparent none;z-index:2147483647;visibility:hidden;cursor:hand;cursor:pointer;";
		PCJSF_Support_FloatingImg.setAttribute("style", style);
		PCJSF_Support_FloatingImg.style.cssText = style;
 		PCJSF_Support_FloatingImg.src = PCJSF_Processor_ServerURL + "Public/Support_Image.php?floating=" + PCJSF_Support_ConfigurationCode + "&available=" + PCJSF_Support_OperatorAvailable;
		PCJSF_Support_FloatingImg.onclick = PCJSF_FloatingButton_Click;
		document.body.appendChild(PCJSF_Support_FloatingImg);	
		PCJSF_Support_FloatingPic = new Image();
		PCJSF_Support_FloatingPic.src = PCJSF_Support_FloatingImg.src;
	}
	PCJSF_Support_UpdatePosition();
	PCJSF_Support_FloatingImg.style.visibility = "visible";
}

function PCJSF_FloatingButton_Click()
{
	PCJSF_Support_Open();
}

function PCJSF_HideFloatingButton()
{
	if(PCJSF_Support_FloatingImg != null)
	{
		PCJSF_Support_FloatingImg.style.visibility = "hidden";
	}
}

var PCJSF_Support_LastHeight = 0;

function PCJSF_Support_UpdateSize(force)
{
	var h = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.height) - 28 - PCJSF_SafeParseInt(PCJSF_Support_PoweredByHeight) - PCJSF_SafeParseInt(PCJSF_Support_BorderWidth);
	if(h < 0)h = 0;
	if((!force) && (h == PCJSF_Support_LastHeight))return;
	PCJSF_Support_LastHeight = h;
	var height = h + "px";
	document.getElementById("PCJSF_mc1").style.height = height;
	document.getElementById("PCJSF_mc2").style.height = height;
	document.getElementById("PCJSF_mc3").style.height = height;
	if(PCJSF_Support_VisibleState == "wfv")PCJSF_Support_WFVUpdateSize();
	if(PCJSF_Support_VisibleState == "wfo")PCJSF_Support_WFOUpdateSize();
	if(PCJSF_Support_VisibleState == "lam")PCJSF_Support_LAMUpdateSize();
	if(PCJSF_Support_VisibleState == "ses")PCJSF_Support_SESUpdateSize();
}

var PCJSF_Support_Moving = false;
var PCJSF_Support_Resizing = false;
var PCJSF_Support_ResizeDirections = false;
var PCJSF_Support_MoveStartPos;
var PCJSF_Support_MoveInitalPos;

function PCJSF_Support_MouseDownInHeader(event)
{
	if((!PCJSF_Support_Moving) && (!PCJSF_Support_Resizing))
	{
		PCJSF_Support_Moving = true;
		PCJSF_Support_OnStartMoveResize(event);
	}
}

function PCJSF_Support_MouseDownForResize(event, directions)
{
	if((!PCJSF_Support_Moving) && (!PCJSF_Support_Resizing))
	{
		PCJSF_Support_ResizeDirections = directions;
		PCJSF_Support_Resizing = true;
		PCJSF_Support_OnStartMoveResize(event);
	}
}

function PCJSF_Support_OnStartMoveResize(event)
{	
	PCJSF_Support_MoveStartPos = {};
	PCJSF_Support_MoveStartPos.x = event.clientX;
	PCJSF_Support_MoveStartPos.y = event.clientY;
	PCJSF_Support_MoveInitalPos = {};
	PCJSF_Support_MoveInitalPos.x = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.left);
	PCJSF_Support_MoveInitalPos.y = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.top);
	if (document.addEventListener)
	{
		document.addEventListener('mousemove', PCJSF_Support_MouseMove, false); 
		document.addEventListener('mouseup', PCJSF_Support_MouseUp, false); 
	}
	else if (document.attachEvent)
	{
		document.attachEvent('onmousemove', PCJSF_Support_MouseMove); 
		document.attachEvent('onmouseup', PCJSF_Support_MouseUp); 
	}
}

function PCJSF_Support_OnStopMoveResize()
{
	if (document.removeEventListener)
	{
		document.removeEventListener('mousemove', PCJSF_Support_MouseMove, false); 
		document.removeEventListener('mouseup', PCJSF_Support_MouseUp, false); 
	}
	else if (document.detachEvent)
	{
		document.detachEvent('onmousemove', PCJSF_Support_MouseMove); 
		document.detachEvent('onmouseup', PCJSF_Support_MouseUp); 
	}
	PCJSF_Support_UpdatePosition();
}

function PCJSF_Support_MouseMove(event)
{
	if(PCJSF_Support_Moving)
	{
		PCJSF_Support_MasterDiv.style.left = (PCJSF_Support_MoveInitalPos.x + event.clientX - PCJSF_Support_MoveStartPos.x) + "px";
		PCJSF_Support_MasterDiv.style.top = (PCJSF_Support_MoveInitalPos.y + event.clientY - PCJSF_Support_MoveStartPos.y) + "px";
		return false;
	}
	else if(PCJSF_Support_Resizing)
	{
		var newWidth = parseInt(PCJSF_Support_Width);
		var newHeight = parseInt(PCJSF_Support_Height);
		if((PCJSF_Support_ResizeDirections & 1) != 0)
		{
			newWidth -= event.clientX - PCJSF_Support_MoveStartPos.x;
		}
		if((PCJSF_Support_ResizeDirections & 2) != 0)
		{
			newWidth += event.clientX - PCJSF_Support_MoveStartPos.x;
		}
		if((PCJSF_Support_ResizeDirections & 4) != 0)
		{
			newHeight += event.clientY - PCJSF_Support_MoveStartPos.y;
		}
		if(newWidth < PCJSF_Support_MinWidth)newWidth = PCJSF_Support_MinWidth;
		if(newWidth > PCJSF_Support_MaxWidth)newWidth = PCJSF_Support_MaxWidth;
		if(newHeight < PCJSF_Support_MinHeight)newHeight = PCJSF_Support_MinHeight;
		if(newHeight > PCJSF_Support_MaxHeight)newHeight = PCJSF_Support_MaxHeight;
		PCJSF_Support_MasterDiv.style.width = newWidth + "px";
		PCJSF_Support_MasterDiv.style.height = newHeight + "px";
		if((PCJSF_Support_ResizeDirections & 1) != 0)
		{
			PCJSF_Support_MasterDiv.style.left = PCJSF_Support_MoveInitalPos.x - (newWidth - PCJSF_Support_Width);
		}
		PCJSF_Support_OnSizeOrStructureChanged();
		if(PCJSF_Support_ManualSizeUpdate)PCJSF_Support_UpdateSize(false);
		return false;
	}
}

function PCJSF_Support_CalcOffset(content, container, align, pos)
{
	var offset = 0;
	if(align == 0)offset = pos;
	else if(align == 1)offset = pos + PCJSF_SafeParseInt((content - container) / 2);
	else if(align == 2)offset = container - pos - content;
	return offset;
}

function PCJSF_Support_MouseUp(event)
{
	var scroll = PCJSF_GetScroll();
	var windowSize = PCJSF_GetWindowSize();
	if(PCJSF_Support_Moving)
	{
		PCJSF_Support_Moving = false;
		PCJSF_Support_OffsetX = PCJSF_Support_CalcOffset(PCJSF_Support_Width, windowSize.width, PCJSF_Support_AlignmentX, PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.left));
		PCJSF_Support_OffsetY = PCJSF_Support_CalcOffset(PCJSF_Support_Height, windowSize.height, PCJSF_Support_AlignmentY, PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.top));
		if(PCJSF_Support_IsIE)
		{
			PCJSF_Support_OffsetX += scroll.x;
			PCJSF_Support_OffsetY += scroll.y;
		}
		PCJSF_Support_OnStopMoveResize();
		PCJSF_Support_JSSChanged();
	}
	else if(PCJSF_Support_Resizing)
	{
		PCJSF_Support_Resizing = false;
		PCJSF_Support_Width = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.width);
		PCJSF_Support_Height = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.height);
		PCJSF_Support_OffsetX = PCJSF_Support_CalcOffset(PCJSF_Support_Width, windowSize.width, PCJSF_Support_AlignmentX, PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.left));
		PCJSF_Support_OffsetY = PCJSF_Support_CalcOffset(PCJSF_Support_Height, windowSize.height, PCJSF_Support_AlignmentY, PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.top));
		if(PCJSF_Support_IsIE)
		{
			PCJSF_Support_OffsetX += scroll.x;
			PCJSF_Support_OffsetY += scroll.y;
		}
		PCJSF_Support_OnStopMoveResize();
		PCJSF_Support_OnSizeOrStructureChanged();
		PCJSF_Support_JSSChanged();
	}
}

//Position management
function PCJSF_Support_CalcAlign(content, container, visualContent, align, offset, fix)
{
	var c = 0;
	if(align == 0)c += offset;
	else if(align == 1)c += PCJSF_SafeParseInt((container - content) / 2) + offset;
	else if(align == 2)c += container - content - offset;
	if(fix)
	{
		if(c + visualContent > container)c = container - visualContent;
		if(c < 0)c = 0;
	}
	return c;
}

function PCJSF_Support_CalculatePosition(size, visualSize, fix)
{
	var windowSize = PCJSF_GetWindowSize();
	var x = PCJSF_Support_CalcAlign(size.width, windowSize.width, visualSize.width, PCJSF_Support_AlignmentX, PCJSF_Support_OffsetX, fix);
	var y = PCJSF_Support_CalcAlign(size.height, windowSize.height, visualSize.height, PCJSF_Support_AlignmentY, PCJSF_Support_OffsetY, fix);
	var scroll = PCJSF_GetScroll();
	if(PCJSF_Support_IsIE)
	{
		x += scroll.x;
		y += scroll.y;
	}
	var res = {};
	res.x = x;
	res.y = y;
	return res;
}

function PCJSF_Support_CalculateFloatingPosition(size, visualSize, fix)
{
	var windowSize = PCJSF_GetWindowSize();
	var x = PCJSF_Support_CalcAlign(size.width, windowSize.width, visualSize.width, PCJSF_Support_FB_AlignmentX, PCJSF_Support_FB_OffsetX, fix);
	var y = PCJSF_Support_CalcAlign(size.height, windowSize.height, visualSize.height, PCJSF_Support_FB_AlignmentY, PCJSF_Support_FB_OffsetY, fix);
	var scroll = PCJSF_GetScroll();
	if(PCJSF_Support_IsIE)
	{
		x += scroll.x;
		y += scroll.y;
	}
	var res = {};
	res.x = x;
	res.y = y;
	return res;
}

function PCJSF_Support_UpdatePosition()
{
	if(PCJSF_Support_MasterDiv != null)
	{
		var sz = {};
		var vsz = {};
		sz.width = PCJSF_Support_Width;
		sz.height = PCJSF_Support_Height;
		vsz.width = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.width);
		vsz.height = PCJSF_SafeParseInt(PCJSF_Support_MasterDiv.style.height);
		var position = PCJSF_Support_CalculatePosition(sz, vsz, true);
		PCJSF_Support_MasterDiv.style.left = position.x + "px";
		PCJSF_Support_MasterDiv.style.top = position.y + "px";
	}
	if(PCJSF_Support_FloatingImg != null)
	{
		var sz = {};
		sz.width = PCJSF_Support_FloatingPic.width;
		sz.height = PCJSF_Support_FloatingPic.height;
		var position = PCJSF_Support_CalculateFloatingPosition(sz, sz, 0);
		PCJSF_Support_FloatingImg.style.left = position.x + "px";
		PCJSF_Support_FloatingImg.style.top = position.y + "px";
	}
}

//Commands
function PCJSF_Support_UpdateState()
{
	var skinURL = PCJSF_Support_SkinURL;
	if(PCJSF_Support_PopupState == "closed")
	{
		if(PCJSF_Support_MasterDiv)PCJSF_Support_MasterDiv.style.visibility = "hidden";
		PCJSF_Support_SetVisible(false);
		PCJSF_ShowFloatingButton();
	}
	else
	{
		PCJSF_HideFloatingButton();
	}
	if(PCJSF_Support_PopupState == "opened")
	{
		if(PCJSF_Support_MasterDiv)
		{
			PCJSF_Support_MasterDiv.style.visibility = "visible";			
			if((!PCJSF_Support_Moving) && (!PCJSF_Support_Resizing))
			{
				PCJSF_Support_MasterDiv.style.height = PCJSF_Support_Height + "px";
			}
			PCJSF_UpdateButton(PCJSF_Support_MinimizeButtonIndex, 25, 28, skinURL + "Minimize.png", skinURL + "MinimizeHOver.png", null, null, function(){PCJSF_Support_Minimize();});
			PCJSF_Support_SetVisible(true);
		}
	}
	else if(PCJSF_Support_PopupState == "minimized")
	{
		if(PCJSF_Support_MasterDiv)
		{
			PCJSF_Support_MasterDiv.style.visibility = "visible";
			PCJSF_Support_MasterDiv.style.height = "28px";
			PCJSF_UpdateButton(PCJSF_Support_MinimizeButtonIndex, 25, 28, skinURL + "Minimize.png", skinURL + "MinimizeHOver.png", null, null, function(){PCJSF_Support_Maximize();});
		}
	}
	if(PCJSF_Support_MasterDiv)PCJSF_Support_UpdatePosition();
	if(PCJSF_Support_ContainerDiv)
	{
		var targetState = PCJSF_Support_State;
		if(!PCJSF_Support_GlobalConf)targetState = "loading";
		if(PCJSF_Support_VisibleState != PCJSF_Support_State)
		{			
			if(PCJSF_Support_VisibleState == "loading")PCJSF_Support_Loading_Deactivate();
			else if(PCJSF_Support_VisibleState == "wfv")PCJSF_Support_WFV_Deactivate();
			else if(PCJSF_Support_VisibleState == "wfo")PCJSF_Support_WFO_Deactivate();
			else if(PCJSF_Support_VisibleState == "lam")PCJSF_Support_LAM_Deactivate();
			else if(PCJSF_Support_VisibleState == "ses")PCJSF_Support_SES_Deactivate();
			var state = "loading";
			if(PCJSF_Support_LoadedSets[targetState])state = targetState;
			if(state == "loading")PCJSF_Support_Loading_Activate();
			else if(state == "wfv")PCJSF_Support_WFV_Activate();
			else if(state == "wfo")PCJSF_Support_WFO_Activate();
			else if(state == "lam")PCJSF_Support_LAM_Activate();
			else if(state == "ses")PCJSF_Support_SES_Activate();
			PCJSF_Support_VisibleState = state;
			PCJSF_Support_OnSizeOrStructureChanged();
		}
	}
	PCJSF_Support_JSSChanged();
}

function PCJSF_Support_Minimize()
{
	if(PCJSF_Support_PopupState != "opened")return;
	PCJSF_Support_PopupState = "minimized";
	PCJSF_Support_PopupStateAltered = true;
	PCJSF_Support_UpdateState();
}

function PCJSF_Support_Maximize()
{
	if(PCJSF_Support_PopupState != "minimized")return;
	PCJSF_Support_PopupState = "opened";
	PCJSF_Support_PopupStateAltered = true;
	PCJSF_Support_UpdateState();
}

function PCJSF_Support_Close()
{
	if((PCJSF_Support_PopupState == "closed") || (PCJSF_Support_PopupState == "embedded"))return;
	PCJSF_Support_PopupState = "closed";
	PCJSF_Support_PopupStateAltered = true;
	PCJSF_Support_UpdateState();
}

function PCJSF_Support_Open()
{
	if(PCJSF_Support_PopupState == "minimized")PCJSF_Support_Maximize();
	if(PCJSF_Support_PopupState == "opened")return;
	if(PCJSF_Support_PopupState == "embedded")return;
	PCJSF_Support_PopupState = "opened";
	PCJSF_Support_UpdateState();
}

function Promptchat_Open()
{
	PCJSF_Support_Open();
}

function ISL_ISF_UserOpenNormal()
{
	Promptchat_Open();
}

function PCJSF_Support_Cycle()
{
	if(PCJSF_Support_ManualSizeUpdate)
	{
		if(PCJSF_Support_TempUpdateChatDiv > 0)
		{
			PCJSF_Support_UpdateChatDiv();
			PCJSF_Support_TempUpdateChatDiv--;
			PCJSF_Support_UpdateOfferPositions();
			PCJSF_Support_UpdateSize(true);
		}
		else
		{
			PCJSF_Support_UpdateOfferPositions();
			PCJSF_Support_UpdateSize(false);
		}
	}
	if(PCJSF_Support_MasterDiv && (!PCJSF_Support_Moving) && (!PCJSF_Support_Resizing))
	{
		PCJSF_Support_UpdatePosition();
	}
}

if(window.Promptchat_Embedded)
{
	var PCJSF_Support_Width = 400;
	var PCJSF_Support_Height = 400;
	var PCJSF_Support_BorderColor = "#000000";
	if(window.Promptchat_Width)PCJSF_Support_Width = PCJSF_SafeParseInt(window.Promptchat_Width);
	if(window.Promptchat_Height)PCJSF_Support_Height = PCJSF_SafeParseInt(window.Promptchat_Height);
	if(isNaN(PCJSF_Support_Width))PCJSF_Support_Width = 400;
	if(isNaN(PCJSF_Support_Height))PCJSF_Support_Height = 400;
	if((PCJSF_Support_Width < 100) || (PCJSF_Support_Width > 2000))PCJSF_Support_Width = 400;
	if((PCJSF_Support_Height < 100) || (PCJSF_Support_Height > 2000))PCJSF_Support_Height = 400;
	if(window.Promptchat_BorderColor)PCJSF_Support_BorderColor = String(window.Promptchat_BorderColor);
	PCJSF_Support_PopupState = "embedded";
	document.write(PCJSF_Support_GetEmbeddedContainerHTML	(false, PCJSF_Support_Width, PCJSF_Support_Height, PCJSF_Support_BorderColor));
	PCJSF_Support_ContainerDiv = document.getElementById("PCJSF_Support_ContainerDiv");
}

setInterval("PCJSF_Support_Cycle()", PCJSF_Support_IsIE ? PCJSF_Support_CycleIEPeriod : PCJSF_Support_CyclePeriod);

var PCJSF_Processor_CommunicationState = "not_started";
var PCJSF_Processor_ServerURL = "";
var PCJSF_Processor_ConsequentErrors = 0;
var PCJSF_Processor_NextRequestTime = 0;
var PCJSF_Processor_NextRequestTimeout = null;
var PCJSF_Processor_SuspendNextRequestTimeoutChanges = 0;
var PCJSF_Processor_Handling = 0;
var PCJSF_Processor_Handling_Id = 0;

function PCJSF_Processor_Process()
{
	PCJSF_Processor_Handling++;
	PCJSF_Processor_Handling_Id = "Process" + PCJSF_Processor_CommunicationState;
	switch(PCJSF_Processor_CommunicationState)
	{
		case "not_started":
			var serverURL = PCJSF_ReadCookie("PCJSF_Processor_SURL");
			if(serverURL !== null)
			{
				PCJSF_Processor_ServerURL = serverURL;
				PCJSF_Processor_CommunicationState = "connect";
				PCJSF_Processor_Process();
				PCJSF_Processor_Handling--;
				return;
			}
			PCJSF_Processor_CommunicationState = "server_url";
			PCJSF_Processor_Process();
			break;
		
		case "server_url":
			var data = new Array();
			data["indentify"] = new Array();
			data["indentify"]["location"] = String(document.location);
			PCJSF_Processor_CommunicationState = "wait_server_url";
			PCJSF_SendRequest(PCJSF_Processor_IdentifyServerURL + "Public/Identify.php", data, function(response){PCJSF_Processor_HandleServerURLResponse(response);}, PCJSF_Processor_IdentifyServerTimeout);
			break;
			
		case "wait_server_url":
			break;
			
		case "connect":
			var data = new Array();
			PCJSF_Processor_SuspendNextRequestTimeoutChanges = 1;
			PCJSF_Processor_CollectRequestData(true, data);
			PCJSF_Processor_SuspendNextRequestTimeoutChanges = 0;
			PCJSF_Processor_CommunicationState = "wait_connect";
			PCJSF_SendRequest(PCJSF_Processor_ServerURL + "Public/Processor.php", data, function(response){PCJSF_Processor_HandleResponse(true, response);}, PCJSF_Processor_ServerTimeout);
			break;
			
		case "wait_connect":
			break;
			
		case "cycle":
			if(PCJSF_Processor_NextRequestTimeout)clearTimeout(PCJSF_Processor_NextRequestTimeout);
			PCJSF_Processor_NextRequestTimeout = null;
			if(PCJSF_Processor_NextRequestTime == 0)
			{
				PCJSF_Processor_Handling--;
				return;
			}
			var currentTime = (new Date()).getTime();
			if(PCJSF_Processor_NextRequestTime <= currentTime)
			{
				PCJSF_Processor_CommunicationState = "cycle_send";
				PCJSF_Processor_Process();
				PCJSF_Processor_Handling--;
				return;
			}
			else
			{
				setTimeout("PCJSF_Processor_Process()", PCJSF_Processor_NextRequestTime - currentTime);
				PCJSF_Processor_Handling--;
				return;
			}
			break;
			
		case "cycle_send":
			var data = new Array();
			PCJSF_Processor_SuspendNextRequestTimeoutChanges = 1;
			PCJSF_Processor_CollectRequestData(false, data);
			PCJSF_Processor_SuspendNextRequestTimeoutChanges = 0;
			if(PCJSF_Processor_NextRequestTimeout)clearTimeout(PCJSF_Processor_NextRequestTimeout);
			PCJSF_Processor_NextRequestTimeout = null;
			PCJSF_Processor_NextRequestTime = 0;
			PCJSF_Processor_CommunicationState = "cycle_send_wait";
			PCJSF_SendRequest(PCJSF_Processor_ServerURL + "Public/Processor.php", data, function(response){PCJSF_Processor_HandleResponse(false, response);}, PCJSF_Processor_ServerTimeout);
			break;
			
		case "cycle_send_wait":
			break;
		
		case "wait_for_reconnect":
			setTimeout("PCJSF_Processor_CommunicationState = \"server_url\"; PCJSF_Processor_Process();", PCJSF_Processor_ReconnectTimeout);
			break;
	}
	PCJSF_Processor_Handling--;
}

function PCJSF_Processor_HandleServerURLResponse(response)
{
	PCJSF_Processor_Handling++;
	PCJSF_Processor_Handling_Id = "URLResponse";
	if(response != null)
	{
		var identifyInfo = (response["indentify"] !== undefined) ? response["indentify"] : null;
		if(identifyInfo)
		{
			var result = (identifyInfo["result"] !== undefined) ? identifyInfo["result"] : "";
			if(result === "not_found")
			{
				PCJSF_Processor_CommunicationState = "idle";
				PCJSF_Processor_Handling--;
				return;
			}
			else if(result === "found")
			{
				if(identifyInfo["location"] !== undefined)
				{
					PCJSF_Processor_ConsequentErrors = 0;
					PCJSF_Processor_ServerURL = identifyInfo["location"];
					PCJSF_CreateCookie("PCJSF_Processor_SURL", PCJSF_Processor_ServerURL, PCJSF_Processor_ServerURLCookieLifetime);
					PCJSF_Processor_CommunicationState = "connect";
					PCJSF_Processor_Process();
					PCJSF_Processor_Handling--;
					return;
				}
			}
		}
	}
	PCJSF_Processor_CommunicationState = "server_url";
	PCJSF_Processor_Process();
	PCJSF_Processor_Handling--;
}

function PCJSF_Processor_HandleResponse(connecting, response)
{
	PCJSF_Processor_Handling++;
	PCJSF_Processor_Handling_Id = "Response";
	if(response != null)
	{
		PCJSF_Processor_SuspendNextRequestTimeoutChanges = 1;
		var handlingResult = PCJSF_Processor_HandleResponseData(connecting, response);
		PCJSF_Processor_SuspendNextRequestTimeoutChanges = 0;
		if(handlingResult == 1)
		{
			PCJSF_Processor_ConsequentErrors = 0;
			PCJSF_Processor_CommunicationState = "cycle";
			PCJSF_Processor_Process();
			PCJSF_Processor_Handling--;
			return;
		}
	}
	PCJSF_Processor_ConsequentErrors++;
	if(PCJSF_Processor_ConsequentErrorsToReconnect == PCJSF_Processor_ConsequentErrors)
	{
		PCJSF_Processor_ServerURL = "";
		PCJSF_Processor_CommunicationState = "wait_for_reconnect";
		PCJSF_Processor_Process();
		PCJSF_Processor_Handling--;
		return;
	}
	PCJSF_Processor_CommunicationState = "wait_for_reconnect";
	PCJSF_Processor_Process();
	PCJSF_Processor_Handling--;
}

function PCJSF_Processor_RegisterRequest(delay)
{
	var currentTime = (new Date()).getTime();
	var nextRequestTime = currentTime + delay;
	var changed = 0;
	if((PCJSF_Processor_NextRequestTime == 0) || (nextRequestTime < PCJSF_Processor_NextRequestTime))
	{
		PCJSF_Processor_NextRequestTime = nextRequestTime;
		changed = 1;
	}
	if((changed) && (PCJSF_Processor_CommunicationState == "cycle") && (PCJSF_Processor_SuspendNextRequestTimeoutChanges == 0))PCJSF_Processor_Process();
}

function PCJSF_Processor_CollectRequestData(connecting, data)
{
	PCJSF_Tracker_CollectRequestData(connecting, data);
	PCJSF_Support_CollectRequestData(connecting, data);
	PCJSF_Chat_CollectRequestData(connecting, data);
}

function PCJSF_Processor_HandleResponseData(connecting, response)
{
	var result = 1;
	if(PCJSF_Tracker_HandleResponseData(connecting, data) == 0)result = 0;
	if(PCJSF_Support_HandleResponseData(connecting, data) == 0)result = 0;
	if(PCJSF_Chat_HandleResponseData(connecting, data) == 0)result = 0;
	return result;
}

function PCJSF_Processor_Guard()
{
	if(PCJSF_Processor_Handling > 0)
	{
		PCJSF_Processor_Handling = 0;
		PCJSF_Processor_CommunicationState = "not_started";
		PCJSF_Processor_Process();
	}
}

document.write("<div id=\"PCJSF_ScriptContainer\" style=\"display:none\"></div>");

PCJSF_Processor_Process();

setInterval("PCJSF_Processor_Guard();", 5000);
