function checkForItemCode(location) {
	debugger;
	if(location.indexOf("group-") > -1) {
		return location.substring(location.indexOf("group-") + 6);
	} else if(location.indexOf("item-")) {
		return location.substring(location.indexOf("item-") + 5, location.indexOf("&"));
	}
	
	return 0;
}/* window 'load' attachment */
function addLoadEvent(func,oWin) {
	if(oWin == null)
	{
		oWin = window;
	}
	var oldonload = oWin.onload;
	if (typeof oWin.onload != 'function') {
		oWin.onload = func;
	}
	else {
		oWin.onload = function() {
			oldonload();
			func();
		}
	}
	var R = func.toString();
	var S = oWin.onload.toString();
	var C = oWin.location.href;
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getServerPath() {
	var serverPath = window.location.protocol + "//" + window.location.hostname;
	if (window.location.port != null && window.location.port != '')
	{
		serverPath = serverPath + ":" + window.location.port; 
	}
	
	return serverPath;
}

/* Simple Inheritance Script */
function inheritFrom(/* Object */ aThis, /* Object */ aParent)
{
	var excp;

	for (var property in aParent)
	{
		try
		{
			aThis[property] = aParent[property];
		}
		catch(excp)
		{
		}
	}
}




/* XML Handeling */

function xmlDoc(XML)
{
	// code for IE
	if (window.ActiveXObject)
	{
		oXmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		oXmlDoc.resolveExternals =  false;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		oXmlDoc=document.implementation.createDocument("","",null);
	}
	else
	{
		alert('Your browser cannot handle this script');
		return;
	}
	oXmlDoc.async=false;
	switch(XML.constructor){
		case String:
			switch( XML.substr(XML.length-4,4) )
			{
				// Is the XML_Item a path?
				case ".xsl":
				case "xslt":
				case ".xml":
					oXmlDoc.load( XML );
				break;
				
				// Then it is an XML string
				default:
					oXmlDoc.loadXML( XML );
				break;
			}
		break;
		// Just in case it is already an XML object
		case Object:
			return XML;
		break;
	}
	return oXmlDoc;
}

function getNodeValue(node)
{
	if (window.ActiveXObject)
	{
		return node.text;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation &&  document.implementation.createDocument)
	{
		return node.textContent;
	}
	else
	{
		alert('Your browser cannot handle this script');
		return;
	}
}

if (window.DOMParser &&
	window.XMLSerializer &&
	window.Node && Node.prototype && Node.prototype.__defineGetter__) {

	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
	//XMLDocument.prototype.loadXML =
	Document.prototype.loadXML = function (s) {

		// parse the string to a new doc
		var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

		// remove all initial children
		while (this.hasChildNodes())
			this.removeChild(this.lastChild);

		// insert and import nodes
		for (var i = 0; i < doc2.childNodes.length; i++) {
			this.appendChild(this.importNode(doc2.childNodes[i], true));
		}
	};


	/*
	 * xml getter
	 *
	 * This serializes the DOM tree to an XML String
	 *
	 * Usage: var sXml = oNode.xml
	 *
	 */
	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
	/*
	XMLDocument.prototype.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this);
	});
	*/
	Document.prototype.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this);
	});
}
function getAllStyle(Obj)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(Obj, "");
	}
	else if(Obj.currentStyle){
		strValue = Obj.currentStyle.toString();
	}
	alert(strValue);
	return strValue;
}
function getStyle(Obj,strCssRule)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(Obj, "").getPropertyValue(strCssRule);
	}
	else if(Obj.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = Obj.currentStyle[strCssRule];
	}
	return strValue;
}
/* GUI Element Handeling */
function guiObject()
{
	/* Generic Methods */
	this.getStyle = getStyle;
	this.swapBGs = function( _oldState, _newState )
	{
		this.style.backgroundImage = getStyle(this,"background-image").replace(_oldState,_newState);
	};
	/* Event Handlers */
	this.onmouseover = function ()
	{
		this.swapBGs("_idle","_hover");
	};
	this.onmouseout = function ()
	{
		this.swapBGs("_hover","_idle");
	};
	this.onmousedown = function ()
	{
		this.swapBGs("_hover","_down");
	};
	this.onmouseup = function ()
	{
		this.swapBGs("_down","_hover");
	};
	
	/* Methods */
	this.disable = function()
	{
		this.disabled = true;
		
	};
	this.enable = function()
	{
		this.disabled = false;
		
	};
}

function loadScript(strPath) {
	var oScript = document.createElement("SCRIPT");
	var ScriptID = "Script_"+strPath.replace(/\/()/g,"_");
	oScript.id = ScriptID;
	oScript.type = "text/javascript";
	oScript.src = strPath;
	document.getElementsByTagName("HEAD")[0].appendChild(oScript);
}

function loadCss(strPath) {
	var oCss = document.createElement("LINK");
	var cssId = "Css_"+strPath.replace(/\/()/g,"_");
	//oCss.id = cssId;
	oCss.rel = "stylesheet";
	oCss.type = "text/css";
	oCss.href = strPath;
	document.getElementsByTagName("HEAD")[0].appendChild(oCss);
}

/* *** */
function loadScripts()
{
	this.scriptPath = "";
	this.loadScript = function(strPath)
	{
		oScript = document.createElement("SCRIPT");
		oScript.id = ScriptID;
		oScript.type = "text/javascript";
		oScript.src = this.scriptPath + strPath;
		document.getElementsByTagName("HEAD")[0].appendChild(oScript);
	}
	Scriptlist = 
	{
		"Button3Parts"		: "gui/buttons/buttons.js",
		"ImgBtn"			: "gui/buttons/buttons.js",
		"Tab"				: "gui/tabCtrl/tabCtrl.js"
	};
	for(className in Scriptlist){
		if(getElementsByClass(className).length > 0)
		{
			var ScriptID = "Script_"+Scriptlist[className].replace(/\/()/g,"_");
			if( !document.getElementById(ScriptID) )
			{
				this.loadScript(Scriptlist[className]);
			}
		}
	}
}

function createStatementEmailHtml(statementObject)
{

	var server = getServerPath();
	var html = "";
	var mailHeader = "You got a zlango message";
	var mailFooter = "/resource/images/zlangoMailBottom.gif";
	html += "<div>";
	html += "	<table style=\"width:480px;\">";
	html += "		<tr>";
	html += "			<td style=\"font-family:arial;font-size:12px;color:black;padding-bottom:40px;padding-left:12px;\">";
	html += "				" + mailHeader + " @@FROMUSERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:50px;padding-bottom:50px;\">";
	html += "				<div style=\width:380px;\>";
	html += "					<A href='" + server + "/?LinkInID=1901080100001000' style='color:white'><IMG border='0' src='" + server + "/zmess.view?id=" + statementObject.id + "'/></A>";
	html += "				</div>";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"text-align:right;paddingleft:12px;font-family:arial;font-size:12px;font-weight:bold;color:#016392;\">";
	html += "				@@USERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:12px;\">";
	html += "				<A href='" + server + "/shortcodes?LinkInID=1901080100001000' style='font-family:arial;font-size:12px;color:black;'>Send Zlango icon messages from your mobile</A>";
	html += "			</td>";
	html += "		</tr>";
	html += "	</table>";
	html += "</div>";
		
	return html;
}

function createWidgetStatementEmailHtml(data, linkInID, header, footer) {
	return createWidgetStatementEmailHtml(data, linkInID, header, footer, '');
}

function createWidgetStatementEmailHtml(data, linkInID, header, footer, lang) {
	
	var server = getServerPath();
	var html = "";
	var mailHeader = "You got a zlango message";
	var mailFooter = "/resource/images/zlangoMailBottom.gif";
	if(header && header != "") {
		mailHeader = header;
	}
	if(footer && footer != "") {
		mailFooter = footer;
	}
	

	html += "<div>";
	html += "	<table style=\"width:480px;\">";
	html += "		<tr>";
	html += "			<td style=\"font-family:arial;font-size:12px;color:black;padding-bottom:40px;padding-left:12px;\">";
	html += "				" + mailHeader + " @@FROMUSERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:50px;padding-bottom:50px;\">";
	html += "				<div style=\width:380px;\>";
	html += "					<A href='" + server + "/?LinkInID=" + linkInID + "' style='color:white'><IMG border='0' src='" + server + "/zmess.view?data=" + data + "&type=mail&LinkInID=" + linkInID + "&langId="+lang+"'/></A>";
	html += "				</div>";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"text-align:right;paddingleft:12px;font-family:arial;font-size:12px;font-weight:bold;color:#016392;\">";
	html += "				@@USERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:12px;\">";
	html += "				<A href='" + server + "/shortcodes?LinkInID=1901080100001000' style='font-family:arial;font-size:12px;color:black;'>Send Zlango icon messages from your mobile</A>";
	html += "			</td>";
	html += "		</tr>";
	html += "	</table>";
	html += "</div>";
		
	return html;
}

function createSpanishStatementEmailHtml(data, linkInID, header, footer, lang) {
	
	var server = getServerPath();
	var html = "";
	var mailHeader = "Recibiste un mensaje de Zlango";
	var mailFooter = "/resource/images/zlangoMailBottom.gif";
	if(header && header != "") {
		mailHeader = header;
	}
	if(footer && footer != "") {
		mailFooter = footer;
	}
	

	html += "<div>";
	html += "	<table style=\"width:480px;\">";
	html += "		<tr>";
	html += "			<td style=\"font-family:arial;font-size:12px;color:black;padding-bottom:40px;padding-left:12px;\">";
	html += "				" + mailHeader + " @@FROMUSERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:50px;padding-bottom:50px;\">";
	html += "				<div style=\width:380px;\>";
	html += "					<A href='" + server + "/?LinkInID=" + linkInID + "' style='color:white'><IMG border='0' src='" + server + "/zmess.view?data=" + data + "&type=mail&LinkInID=" + linkInID + "&langId="+lang+"'/></A>";
	html += "				</div>";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"text-align:right;paddingleft:12px;font-family:arial;font-size:12px;font-weight:bold;color:#016392;\">";
	html += "				@@USERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:12px;\">";
	html += "				<A href='" + server + "/shortcodes?LinkInID=1901080100001000' style='font-family:arial;font-size:12px;color:black;'>Manda mensajes con iconos de zlango desde tu celular</A>";
	html += "			</td>";
	html += "		</tr>";
	html += "	</table>";
	html += "</div>";
		
	return html;
}

function createItalianStatementEmailHtml(data, linkInID, header, footer, lang, msisdn) {
	
	var server = getServerPath();
	var html = "";
	var mailHeader = "Hai un messaggio Zlango";
	var mailFooter = "/resource/images/zlangoMailBottom.gif";
	if(header && header != "") {
		mailHeader = header;
	}
	if(footer && footer != "") {
		mailFooter = footer;
	}
	

	html += "<div>";
	html += "	<table style=\"width:480px;\">";
	html += "		<tr>";
	html += "			<td style=\"font-family:arial;font-size:12px;color:black;padding-left:12px;\">";
	html += "				" + mailHeader + " da " + msisdn;
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:50px;padding-bottom:50px;\">";
	html += "				<div style=\width:380px;\>";
	html += "					<A href='http://timtribu.tim.it/zlango' style='color:white'><IMG border='0' src='" + server + "/zmess.view?data=" + data + "&type=mail&LinkInID=" + linkInID + "&langId=en-us'/></A>";
	html += "				</div>";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"text-align:right;paddingleft:12px;font-family:arial;font-size:12px;font-weight:bold;color:#016392;\">";
	html += "				@@USERNAME@@";
	html += "			</td>";
	html += "		</tr>";
	html += "		<tr>";
	html += "			<td style=\"width:480px;padding-left:12px;\">";
	html += "				<div style=\"border-top:1px solid #114986;border-bottom:1px solid #114986;\">";
	html += "					<table>";
	html += "						<tr>";
	html += "							<td>";
	html += "								<img src=\"" + server + "/resource/images/mobileApp.gif\"/>";
	html += "							</td>";
	html += "							<td style=\"vertical-align:top;\">";
	html += "								<table>";
	html += "									<tr>";
	html += "										<td style=\"font-family:arial;font-size:11px;font-weight:bold;color:#181818;padding-right:3px;border-right:1px solid #ee2e24;white-space:nowrap;\">";
	html += "											Zlango per cellulare";
	html += "										</td>";
	html += "										<td style=\"font-family:arial;font-size:11px;color:#181818;padding-right:3px;padding-left:2px;border-right:1px solid #ee2e24;white-space:nowrap;\">";
	html += "											Scarica Zlango sul cellulare e manda SMS con icone!";
	html += "										</td>";
	html += "										<td style=\"padding-left:2px;white-space:nowrap;\">";
	html += "											<a href=\"http://timtribu.tim.it/zlango\" style=\"font-family:arial;font-size:11px;font-weight:bold;color:#114986;\">";
	html += "												Download gratuito";
	html += "											</a>";
	html += "										</td>";
	html += "									</tr>";
	html += "								</table>";
	html += "							</td>";
	html += "						</tr>";
	html += "					</table>";
	html += "				</div>";
	html += "				<table>";
	html += "					<tr>";
	html += "						<td style=\"vertical-align:top;padding-top:3px;padding-right:5px;\">";
	html += "							<span style=\"font-family:arial;font-size:9px;color:#181818;\">il servizio ZLANGO è offerto in esclusiva da TIM</span>";
	html += "						</td>";
	html += "						<td style=\"padding-right:5px;padding-top:2px;\">";
	html += "							<a href=\"http://www.zlango.com/\"><img border=\"0\" src=\"" + server + "/resource/images/zlangoSmallLogo.gif\"/></a>";
	html += "						</td>";
	html += "						<td style=\"vertical-align:top;padding-top:1px;\">";
	html += "							<a href=\"http://timtribu.tim.it/ \"><img border=\"0\" src=\"" + server + "/resource/images/timSmallLogo.gif\"/></a>";
	html += "						</td>";
	html += "					</tr>";
	html += "				</table>";
	html += "			</td>";
	html += "		</tr>";
	html += "	</table>";
	html += "</div>";
	
						
					
				
	
		
	return html;
}

function createPictureEmailHtml(pictureUrl)
{
	var server = getServerPath();
	var pictueHtml = "<IMG width='450px' src='" + server + "/" + pictureUrl + "&LinkInID=1901080100004000'/> ";
	
	
	
	
	return createMailHtmlEnvelope(pictueHtml, "picture"); 
}

function createVideoEmailHtml(groupId, itemId)
{
	var server = getServerPath();
	var videoUrl = server + "/item-" + itemId + "&groupId=" + groupId + "&LinkInID=1901080100004000";
	var html = "<HTML><BODY><A href='" + videoUrl + "'>You have recieved a zlango video, click here to see it.</A></BODY></HTML>";
	return html;
}

function createStoryEmailHtml(groupId, itemId) {
	var server = getServerPath();
	var videoUrl = server + "/item-" + itemId + "&groupId=" + groupId + "&LinkInID=1901080100004000";
	var html = "<HTML><BODY><A href='" + videoUrl + "'>You have recieved a zlango story, click here to see it.</A></BODY></HTML>";
	return html;
}

function createMailHtmlEnvelope(contentHtml, scope)
{

	var mailBottomPic = "";
	if(scope == "statement") {
		mailBottomPic = "mailBottom.gif";
	} else {
		mailBottomPic = "mailBottom2.gif";
	}

	var server = getServerPath();
	var html = 	"<DIV>" +
				"<TABLE cellpadding='0' cellspacing='0'> " +
				"	<TR> " +
				"		<TD style='width:547;height:98px;background-repeat:no-repeat;background-image:url(" + server + "/resource/images/mailBackgroundTop.gif)'> " +
				"		</TD> " +
				"	</TR> " +
				"	<TR> " +
				"		<TD style='text-align:right;background-repeat:repeat-y;background-image:url(" + server + "/resource/images/mailBackgroundMiddle.gif)'> " +
				"			<TABLE style='width:507px;' align='center' cellpadding='0' cellspacing='0'> " +
				"				<TR> " +
				"					<TD style='width:507px;height:27px;background-repeat:no-repeat;background-image:url(" + server + "/resource/images/mailTop.gif)'> " +
				"					</TD> " +
				"				</TR> " +
				"				<TR> " +
				"					<TD style='padding:20px;background-repeat:repeat-y;background-image:url(" + server + "/resource/images/mailMiddle.gif)'> " +
				"						<DIV> " +
											contentHtml +
				"						</DIV> " +
				"					</TD> " +
				"				</TR> " +
				"				<TR> " +
				"					<TD style='width:507px;height:67px;background-repeat:no-repeat;background-image:url(" + server + "/resource/images/" + mailBottomPic + ")'> " +
				"						<A href='" + server + "/'><div style='height:67px'></div></A> " +
				"					</TD> " +
				"				</TR> " +
				"			</TABLE> " +
				"			<A href='" + server + "/'><SPAN style='border:0px;text-decoration:underline;cursor:pointer;color:#80c34d;font-size:10pt;padding-right:20px;padding-bottom:5px;font-weight:bold'>Learn more about Zlango</SPAN></A> " +
				"		</TD> " +
				"	</TR> " +
				"	<TR> " +
				"		<TD style='width:547;height:18px;background-repeat:no-repeat;background-image:url(" + server + "/resource/images/mailBackgroundBottom.gif)'> " +
				"		</TD> " +
				"	</TR> " +
				"</TABLE> " +
				"</DIV><br><br><span style='font-family:Arial'>@@userMsg@@</span>";
	return html;
}

function preloadImages(words) {
	for(var j in words) {
		element = document.createElement("IMG");
		element.src = "show.img?id=" + words[j].iconId;
	}
}

function createStatementPostHtml(statementId, numberOfIcons, desiredWidth, words) {
	createStatementPostHtml(statementId, numberOfIcons, desiredWidth, words, '');
}

function createStatementPostHtml(statementId, numberOfIcons, desiredWidth, words, lang) {
	var postHtml = "";
	var minIconsInRow = 5;
	var iconSize = 48;
	var server = getServerPath();
	var flashWidth;
	var flashHeight;
	var actualIconWidth
	var actualIconHeight;

	var rowsCount = 1;
	var rowWidth = 0;
	var element;
	var iconWidth;
	var iconsArray = [];
	for(var i = 0; i < words.length; i++) {
		iconsArray[i] = words[i].iconId;
	}
	var iconsSizes;
	iconsSizes = jsonrpc.imageInfoService.getSize(iconsArray,getServerPath(), 48);
	iconsSizes = iconsSizes.list;
	for(var i in words) {
		if(words[i].iconId != "-1") {
			iconWidth = iconsSizes[i].width + 19;
		} else {
			var text = words[i].word;
			iconWidth = text.length * 10;
		}
		rowWidth += iconWidth
		if(words[i].word == "$nl") {
			rowsCount += 1;
			rowWidth = 0;
		} else {
			if(rowWidth > (desiredWidth - 79)) {
				rowsCount += 1;
				rowWidth = iconWidth;
			}
		}
	}
		
	if(iconSize == 48) {
		actualIconHeight = 77;
	}

	flashWidth = desiredWidth;
	flashHeight = (rowsCount * actualIconHeight) + 38 + actualIconHeight;
	
	postHtml += "<object width='" + (flashWidth) + "' height='" + flashHeight + "' align='middle'> " +
				"	<param name='movie' value='" + server + "/gui/flash/EmbeddedViewer/EmbeddedViewer.swf?flashWidth=" + (flashWidth) + "&flashHeight=" + flashHeight + "&iconSize=" + iconSize + "&serverPath=" + server + "/&statementId=" + statementId + "&langId=" + lang + "'/> " +
				"	<param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /> " +
				"	<embed src='" + server + "/gui/flash/EmbeddedViewer/EmbeddedViewer.swf?flashWidth=" + flashWidth + "&flashHeight=" + flashHeight + "&iconSize=" + iconSize + "&serverPath=" + server + "/&statementId=" + statementId + "&langId=" + lang + "' " +
				"		   quality='high' bgcolor='#ffffff' " +
				"		   width='" + (flashWidth) + "' " +
				"	 	   height='" + flashHeight + "' " +
				"		   name='EmbeddedViewer.swf' " +
				"		   align='middle' " +
				"		   allowScriptAccess='never' " +
				"		   allowFullScreen='false' " +
				"		   type='application/x-shockwave-flash' " +
				"		   pluginspage='http://www.macromedia.com/go/getflashplayer' /> " +
				"</object>";
				
	var envelope = "";
	envelope += "<TABLE> ";
	envelope += "	<TR> ";
	envelope += "		<TD> ";
	envelope += 			postHtml;
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "	<TR> ";
	envelope += "		<TD align='right' style='padding-right:20px'> ";
	envelope += "			<a href='" + server + "/?LinkInID=1901080100003000'><SPAN style='border:0px;text-decoration:underline;cursor:pointer;color:#80c34d;font-size:10pt;font-weight:bold'>Learn more about Zlango</SPAN></a> ";
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "</TABLE> ";
		
	return postHtml;
}

function createDataStatementPostHtml(data, desiredWidth, linkInID) {
	var server = getServerPath();
	postHtml += "<IMG border='0' src='" + server + "/zmess.view?data=" + data + "&type=mail&LinkInID=" + linkInID + "&langId=en-us&width=" + desiredWidth + "'/>";
				
	var envelope = "";
	envelope += "<TABLE> ";
	envelope += "	<TR> ";
	envelope += "		<TD> ";
	envelope += "			<a href='" + server + "/?LinkInID=1901080100003000'>" + postHtml + "</a> ";
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "	<TR> ";
	envelope += "		<TD align='right' style='padding-right:20px'> ";
	envelope += "			<a href='" + server + "/?LinkInID=1901080100003000'><SPAN style='border:0px;text-decoration:underline;cursor:pointer;color:#80c34d;font-size:10pt;font-weight:bold'>Learn more about Zlango</SPAN></a> ";
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "</TABLE> ";
		
	return postHtml;
}

function createECardPostHtml(flashUrl) {
	
	var postHtml = "";
	var server = getServerPath();
	
	postHtml += "<a href='" + server + "/?LinkInID=1901080100003000'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='442' height='296' align='middle'> " +
			    "	<param name='allowScriptAccess' value='never' /> " +
				"	<param name='allowFullScreen' value='false' /> " +
				"	<param name='movie' value='" + server + "/" + flashUrl + "' /> " +
				"	<param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /> " +
				"	<embed src='" + server + "/" + flashUrl + "' " +
				"		   quality='high' bgcolor='#ffffff' " +
				"		   width='442' " +
				"	 	   height='296' " +
				"		   name='ZlangoComposer_hovav' " +
				"		   align='middle' " +
				"		   allowScriptAccess='never' " +
				"		   allowFullScreen='false' " +
				"		   type='application/x-shockwave-flash' " +
				"		   pluginspage='http://www.macromedia.com/go/getflashplayer' /> " +
				"</object></a> ";
				
	var envelope = "";
	envelope += "<TABLE> ";
	envelope += "	<TR> ";
	envelope += "		<TD> ";
	envelope += 			postHtml;
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "	<TR> ";
	envelope += "		<TD align='right' style='padding-right:20px'> ";
	envelope += "			<a href='" + server + "/?LinkInID=1901080100003000'><SPAN style='border:0px;text-decoration:underline;cursor:pointer;color:#80c34d;font-size:10pt;font-weight:bold'>Learn more about Zlango</SPAN></a> ";
	envelope += "		</TD> ";
	envelope += "	</TR> ";
	envelope += "</TABLE> ";
		
	return postHtml;
}

addLoadEvent(loadScripts);

function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}

function setMainSize()
{
	var CH	= document.body.clientHeight;
	var DOH	= document.body.offsetHeight;
	var DSH	= document.body.scrollHeight
	var M = document.getElementById("MainContentPane");
	var MOH = M.offsetHeight;
	var DBS = document.body.style;
	var PF = document.getElementById("PageFrame");
	
	if(typeof(ddd) != "undefined"){
		ddd.innerHTML =	"CH: " + CH + "<br/>"
						+ "DOH:" + DOH + "<br/>";
	}
	if(DOH > CH)
	{
		PF.style.height = "auto";
		var tt = window.setTimeout(function(){
			PF.style.height = "99%";
		},500)
	}
}

function processPlaxo(toObject) {
	var toStr = toObject.value;
	var adresses = toStr.split(",");
	var newAdresses = "";
	
	for(r in adresses) {
		if(adresses[r].indexOf("<") != -1) {
			newAdresses += adresses[r].slice(adresses[r].indexOf("<") + 1, adresses[r].length -1) + "; ";
		}
	}
	toObject.value = newAdresses;
}

function getStatementXml(statement) {
	var cap = statement.caption == true ? "true" : "false";
		
	var xmlString = "<contentObject>";	
	xmlString += "<id>" + statement.id + "</id>";
	xmlString += "<type><![CDATA[message]]></type>";
	xmlString += "<captions>" + cap + "</captions>";
	xmlString += "<version>1.0</version>";
	xmlString += "<data>";
	
	
	for(var word in statement.zlWords) {
		xmlString += "<word>";
		xmlString += "<text><![CDATA[" + statement.zlWords[word].word + "]]></text>";
		xmlString += "<iconId>" + statement.zlWords[word].iconId + "</iconId>";
		xmlString += "<iconURL><![CDATA[show.img?id=" + statement.zlWords[word].iconId + "&size=60]]></iconURL>";
		xmlString += "</word>";
	}
	
	xmlString += "</data>";
	xmlString += "</contentObject>";
	
	return xmlString;
}

function translateStatement(st) {
	var statement = new Object();
	statement.id = st.id;
	statement.caption = st.caption;
	statement.editorPick = st.editorPick;
	statement.ownerId = st.ownerId;
	statement.ownerName = st.ownerName;
	statement.zlWords = translateWords(st.content);
	
	return statement;
}

function translateWords(wordsString) {
	var pos = 0;
	var wordIndex = 0;
	var words = [];
	var iconDataLength;
	var iconData;
	var textDataLength;
	var textData;
	while(pos < wordsString.length) {
		var word = new Object;
		iconDataLength = Number(wordsString.substring(pos + 1, pos + 3));
		pos += 3;
		if(iconDataLength != 0) {
			iconData = wordsString.substring(pos, pos + iconDataLength);
			pos += iconDataLength;
			word.iconId = iconData;
		} else {
			word.iconId = -1;
			iconData = -1;
		}
		
		textDataLength = Number(wordsString.substring(pos + 1, pos + 3));
		pos += 3;
		textData = wordsString.substring(pos, pos + textDataLength);
		pos += textDataLength;
		
		word.id = 0;
		
		word.word = textData;
		
		words[wordIndex] = word;
		wordIndex++;
	}
	return words;
}

function trimStatementNewLine(words) {
	var trimedWords = [];
	var wordIndex = 0;
	
	for(var word in words) {
		if(words[word].word != "$nl") {
			trimedWords[wordIndex] = words[word];
			wordIndex ++;
		}
	}
	
	return trimedWords;
}

function cropRecipientsString(recippients) {
	var map = {};
	var newString = ""
	
	var adresses = recippients.split(";");
	for(i in adresses) {
		if(adresses[i].replace(" ", "") != "") {
			map[adresses[i]] = 1;
		}
	}
	
	for(j in map) {
		newString += j + ";"
	}
	
	return newString;
}

function converXmlToData(xml) {
	var msgDoc = xml;
	var captionStatus = msgDoc.getElementsByTagName("captions")[0].childNodes[0].nodeValue;
	var wordNodes = msgDoc.getElementsByTagName("word");
	var messageContent = "";
	var startFlag = true;
	for(var index=0;index < wordNodes.length;index++){
		var inChild = wordNodes[index].childNodes;
		var tNodeValue = wordNodes[index].getElementsByTagName("text")[0].childNodes[0].nodeValue;
		var iconText = tNodeValue;
		var iconId = wordNodes[index].getElementsByTagName("iconId")[0].childNodes[0].nodeValue;
		if(captionStatus == 'false' && !(Number(iconId) < 0)){
			iconText = "";
		}
		if(!(Number(iconId) < 0 && iconText.length == 0)){
			messageContent += "I"+ (Number(iconId) < 0 ? '00' : padZero(String(iconId.length))) + (Number(iconId) < 0 ? '' : iconId) +"T"+ padZero(String(iconText.length))  +iconText
		}
	}
	
	return messageContent;
}

function padZero(originalValue){
	var paddingCount = 2 - originalValue.length;
	var currentValue = originalValue;
	for(var i=0;i<paddingCount;i++){
		currentValue = "0"+currentValue;
	}
	return currentValue;
}

function createStatementHTML(statementId, CDNPath, maxIcons) {
	var statement = jsonrpc.daoStatement.getStatement(statementId);
	var words = statement.zlWords.list;
	
	var iconsArray = [];
	for(var i in words) {
		iconsArray[i] = words[i].iconId;
	}
	var iconsSizes = jsonrpc.imageInfoService.getSize(iconsArray,getServerPath(), 32);
	iconsSizes = iconsSizes.list;
	var max;

	if(maxIcons) {
		max = Number(maxIcons);
	} else {
		max = words.length;
	}

	var html = "";
	var index = 0;
	for (var i = 0; i < words.length && i < max; i++) {
		var word = words[i];
		var spanStyle = "padding-right:5px";

		if (word.iconId == -1) {
			if (word.word == " " || word.word == "$nl") {
				iconImg = "<SPAN style='color:#84bf36; vertical-align:center'></SPAN>";
			} else {
				iconImg = "<SPAN style='color:#84bf36; vertical-align:center'>"	+ word.word + "</SPAN>";
			}
			iconText = "&nbsp;";
			spanStyle = "";
		} else {
			if(CDNPath != "") {
				iconImg = "<img class='zlStatementIcon' style='float: left;height:" + iconsSizes[i].height + "px;width:" + iconsSizes[i].width + "px;' src='" + CDNPath + "/show.img?id=" + word.iconId + "&size=32'/> ";
			} else {
				iconImg = "<img class='zlStatementIcon' style='float: left;height:" + iconsSizes[i].height + "px;width:" + iconsSizes[i].width + "px;' src='/show.img?id=" + word.iconId + "&size=32'/> ";
			}
			if (statement.caption) {
				iconText = word.word;
			} else {
				iconText = "&nbsp;";
			}
		}

		html += "<SPAN style='" + spanStyle
				+ "' class='Centered'><TABLE style='display:inline'> " + "	<TR> "
				+ "		<TD style='text-align: -moz-center!important;_text-align: center!important;'>" + iconImg + "		</TD> "
				+ "	</TR> " + "	<TR> " + "		<TD class='Centered' style='font-family:Arial;color:#666666;font-size:8pt;width:100%;text-align: -moz-center!important;_text-align: center!important;'> "
				+ iconText
				+ "		</TD> " + "	</TR> "
				+ "</TABLE></SPAN>";
			
		index += 1;
	} 
	
	if(max < words.length) {
		html += "<SPAN style='" + spanStyle
				+ "' class='Centered'><TABLE style='display:inline'> " + "	<TR> "
				+ "		<TD style='text-align: -moz-center!important;_text-align: center!important;'><SPAN style='color:#84bf36; vertical-align:center;font-size:32px;'>...</SPAN></TD> "
				+ "	</TR> " + "	<TR> " + "		<TD class='Centered' style='font-family:Arial;color:#666666;font-size:8pt;width:100%;text-align: -moz-center!important;_text-align: center!important;'> "
				+ "&nbsp;"
				+ "		</TD> " + "	</TR> "
				+ "</TABLE></SPAN>";
	}

	return html;
	
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a negative version for firefox, otherwiswe 0
// (indicating the use of another browser).
{
  var rv = 0; // Return value assumes failure.
  //alert(navigator.appName);
  //alert(navigator.userAgent);
  
  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 );
    }
  }
  else if (navigator.appName == 'Netscape')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("Firefox/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
    {
      rv = -parseFloat( RegExp.$1 );
    }
  }
  //alert(rv);
  return rv;
}

function checkVersion()
{
	var ver = getInternetExplorerVersion();
	return ver;	  
}

function checkForItemCode(location) {
	if(location.indexOf("group-") > -1) {
		return location.substring(location.indexOf("group-") + 6);
	} else if(location.indexOf("item-") > -1) {
		return location.substring(location.indexOf("item-") + 5, location.indexOf("&"));
	}
	
	return 0;
}

function padLeft(value, charNum, paddingChar) {
	var tempValue = value + "";
	var newValue= ""; 
	var charsToPad = charNum - tempValue.length;
	
	for(var i = 0; i < charsToPad; i++) {
		newValue += paddingChar;
	}
	
	newValue += tempValue;
	return newValue;
}

function changeGenericButtonState(buttonId, buttonType, state) {
	var disabled = document.getElementById(buttonId + "Disabled").value;

	if(disabled != "true") {
		var left = document.getElementById(buttonId + "Left");
		var center = document.getElementById(buttonId + "Center");
		var right = document.getElementById(buttonId + "Right");
	
		left.className = buttonType + "Left" + state;
		center.className = buttonType + "Center" + state + " Centered";
		right.className = buttonType + "Right" + state;
	}
}

function changegenericButtonText(buttonId, newText) {
	var text = document.getElementById(buttonId + "Text");
	text.innerHTML = newText;
}

function enableGenericButton(buttonId) {
	document.getElementById(buttonId + "Disabled").value = "false";
	
	var left = document.getElementById(buttonId + "Left");
	var center = document.getElementById(buttonId + "Center");
	var right = document.getElementById(buttonId + "Right");
	var buttonType = document.getElementById(buttonId + "CurrentButtonType").value
	var cursor = document.getElementById(buttonId);
	
	left.className = buttonType + "Left";
	center.className = buttonType + "Center Centered";
	right.className = buttonType + "Right";
	cursor.className = "GenericButtonEnabled";
}

function disableGenericButton(buttonId) {
	document.getElementById(buttonId + "Disabled").value = "true";
	
	var left = document.getElementById(buttonId + "Left");
	var center = document.getElementById(buttonId + "Center");
	var right = document.getElementById(buttonId + "Right");
	var buttonType = document.getElementById(buttonId + "CurrentButtonType").value
	var cursor = document.getElementById(buttonId);
	
	left.className = buttonType + "LeftDisabled";
	center.className = buttonType + "CenterDisabled Centered";
	right.className = buttonType + "RightDisabled";
	cursor.className = "GenericButtonDisabled";	
}