function isIE()
{
	//return(document.all);
	return(navigator.appName.indexOf("Microsoft") != -1);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function trim(stringToTrim) 
{
	return new String(stringToTrim).replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return new String(stringToTrim).replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return new String(stringToTrim).replace(/\s+$/,"");
}

function addVote(tableName, id, params)
{
	//alert('a');
	if (!params)
		params = new Object();
	params.id = id;

	var fieldName;
	if (params.fieldName)
		fieldName = params.fieldName;
	else
		fieldName = 'count';
	
	var result = getComponentAjaxValue(tableName, fieldName, params, 'rtValue');
	if (result.replace(/^\s*|\s*$/g,"") != "") // trim
		alert(result);
	else
	{
		//document.cookie = "test=10";
		window.location.href = window.location.href; // reload page
	}
}

function addRating(tableName, id, params)
{
	//alert('a');
	if (!params)
		params = new Object();
	params.id = id;

	var fieldName;
	if (params.fieldName)
		fieldName = params.fieldName;
	else
		fieldName = 'count';
	
	var result = getComponentAjaxValue(tableName, fieldName, params, 'rtValue');
	if (result.replace(/^\s*|\s*$/g,"") != "") // trim
		alert(result);
	else
	{
		//document.cookie = "test=10";
		window.location.href = window.location.href; // reload page
	}
}

// -------------------------------------------- NEW ---------------------------------------- //
var mouseOverAreas = new Object();

function _showMouseOverArea(parentId, areaId, params, e)
{
	var mouseXY = getMouseXY(e); // works on IE6,FF,Moz,Opera7

	var parent = document.getElementById(parentId);
	var area = document.getElementById(areaId);
	var parentNode = parent.parentNode;
	
	var areaParams;
	if (!mouseOverAreas[parentId])
	{
		mouseOverAreas[parentId] = new Object();
		areaParams = mouseOverAreas[parentId];
		
		if (typeof params["followMouse"] == "undefined")
			params["followMouse"] = false;
		if (typeof params["offsetX"] == "undefined")
			params["offsetX"] = 0;
		if (typeof params["offsetY"] == "undefined")
			params["offsetY"] = 0;
		
		areaParams["parentId"] = parentId;	
		areaParams["areaId"] = areaId;	
		areaParams["followMouse"] = params["followMouse"];	
		if (params["hide"] == "")
			params["hide"] = "parent";
		areaParams["hide"] = params["hide"];
		areaParams["link"] = params["link"];
		areaParams["offsetX"] = params["offsetX"];
		areaParams["offsetY"] = params["offsetY"];

		areaParams["position"] = params["position"];	
	
		if (areaParams["followMouse"])
			areaParams["hide"] = "parent";

		// remove area from parent and insert into body
		area.parentNode.removeChild(area);
		document.body.appendChild(area);

		if (parentNode.tagName.toLowerCase() == "a")
		{
			if (parentNode.href.indexOf('javascript') == -1)
				area.onClick = "window.location.href='"+parentNode.href+"'";
		}
		if (areaParams["link"] != "")
		{
			//if (parentNode.href.indexOf('javascript') == -1) // haze chyby na e-vision.cz
			//{
				parent.onclick=new Function("window.location.href='"+areaParams["link"]+"';");
				area.onclick=new Function("window.location.href='"+areaParams["link"]+"';");
				parent.style.cursor='pointer';
				area.style.cursor='pointer';
			//}
		}
	
	}
	else 
		areaParams = mouseOverAreas[parentId];

	if (areaParams["visible"] && !areaParams["followMouse"])
		return;
		
	//alert(1);
	//alert(areaParams["position"]);
	
	//alert(3);
	// check if parent is inside <href and simulate href
	
	var positions = areaParams["position"].split(" ");
	
	//alert(positions);
	var parentPositions = [positions[0], positions[1]];
	var areaPositions = [positions[2], positions[3]];
	
	var parentPosition  = getPosition(parent, document.body);
	var parentLeft = parentPosition[0]; //-(parent.style.marginLeft ? parseInt(parent.style.marginLeft) : 0);
	var parentTop = parentPosition[1]; //-(parent.style.marginTop ? parseInt(parent.style.marginTop) : 0);
	var parentWidth = parent.offsetWidth;
	var parentHeight = parent.offsetHeight;

	// (parentTop);
	//alert (parentLeft);
	//alert (parentTop);
	
	//alert(5);
	if (parentPositions[0] == "top")
	{
		parentY = parentTop;
	}
	if (parentPositions[0] == "center")
	{
		parentY = parentTop+parentHeight/2;
	}
	if (parentPositions[0] == "bottom")
	{
		parentY = parentTop+parentHeight;
	}
	if (parentPositions[1] == "left")
	{
		parentX = parentLeft;
	}
	if (parentPositions[1] == "center")
	{
		parentX = parentLeft+parentWidth/2;
	}
	if (parentPositions[1] == "right")
	{
		parentX = parentLeft+parentWidth;
	}
		
	// to get area width and height, area must be visible
	area.style.zIndex = -1;
	area.style.display = '';
	var areaWidth = area.offsetWidth;
	var areaHeight = area.offsetHeight;
	
	if (areaPositions[0] == "top")
	{
		//areaY = parentY-1;
		areaY = parentY;
	}
	if (areaPositions[0] == "center")
	{
		// fix round
		areaY = parentY-areaHeight/2;
	}
	if (areaPositions[0] == "bottom")
	{
		areaY = parentY-1+parentHeight;
	}
	if (areaPositions[1] == "left")
	{
		//areaX = parentX-1;
		areaX = parentX;
	}
	if (areaPositions[1] == "center")
	{
		areaX = parentX-areaWidth/2;
	}
	if (areaPositions[1] == "right")
	{
		areaX = parentX-1+parentWidth;
	}
	if (areaParams["followMouse"])
	{
		areaX = mouseXY[0];
		areaY = mouseXY[1];
	}

	areaX = areaX+areaParams["offsetX"]*1;
	areaY = areaY+areaParams["offsetY"]*1;
	
	//alert(areaX);
	//alert(areaY);
	
	//alert(parentX);
	//alert(areaX);
	//alert(parentY);
	//alert(areaY);


/*	alert(areaWidth);
	alert(areaHeight);
	alert(areaX);	
	alert(areaY);	
*/
	
	areaParams["parentTop"] = parentTop;
	areaParams["parentLeft"] = parentLeft;
	areaParams["parentWidth"] = parentWidth;
	areaParams["parentHeight"] = parentHeight;
	areaParams["areaTop"] = areaY;
	areaParams["areaLeft"] = areaX;
	areaParams["areaWidth"] = areaWidth;
	areaParams["areaHeight"] = areaHeight;
	
	//(areaX);
	//alert(areaY);
	area.style.position="absolute";
	area.style.top=(areaY)+"px";
	area.style.left=(areaX)+"px";
	area.style.zIndex=1000;
	area.style.display="";
	
	areaParams["visible"] = true;	

	mouseOverAreas[parentId] = areaParams;
	document.onmousemove=_checkMouseOverAreaMouseOver;
	document.onmousewheel=_hideAllMouseOverAreas;
	
	if (cmsMenuHideAll != 'undefined')
	{
		cmsMenuHideAll();
	}
}

function _checkMouseOverAreaMouseOver(e)
{
	var mouseXY = getMouseXY(e); // works on IE6,FF,Moz,Opera7
	
	for (var id in mouseOverAreas)
	{
		var areaParams = mouseOverAreas[id];
		if (areaParams["visible"])
		{
			if (areaParams["hide"] == "parent")
			{
				//document.body.appendChild(document.createElement("h1"));
				if (mouseXY[0] < areaParams["parentLeft"] || mouseXY[0] > areaParams["parentLeft"]+areaParams["parentWidth"] ||
					mouseXY[1] < areaParams["parentTop"] || mouseXY[1] > areaParams["parentTop"]+areaParams["parentHeight"])
				{
					//setTimeout("_hideMouseOverArea('"+areaParams["areaId"]+"');", 10); // due to IE call of showMouseOverArea
					_hideMouseOverArea(areaParams["areaId"]);
				}
			}
			else if (areaParams["hide"] == "area")
			{
				if (mouseXY[0] < areaParams["areaLeft"] || mouseXY[0] > areaParams["areaLeft"]+areaParams["areaWidth"] ||
					mouseXY[1] < areaParams["areaTop"] || mouseXY[1] > areaParams["areaTop"]+areaParams["areaHeight"])
				{
					//setTimeout("hideMouseOverArea('"+areaParams["areaId"]+"');", 10); // due to IE call of showMouseOverArea
					_hideMouseOverArea(areaParams["areaId"]);
				}
			}
			else if (areaParams["hide"] == "both")
			{
				if ((mouseXY[0] < areaParams["parentLeft"] || mouseXY[0] > areaParams["parentLeft"]+areaParams["parentWidth"] ||
					mouseXY[1] < areaParams["parentTop"] || mouseXY[1] > areaParams["parentTop"]+areaParams["parentHeight"]) && 
					(mouseXY[0] < areaParams["areaLeft"] || mouseXY[0] > areaParams["areaLeft"]+areaParams["areaWidth"] ||
					mouseXY[1] < areaParams["areaTop"] || mouseXY[1] > areaParams["areaTop"]+areaParams["areaHeight"]))
				{
					//setTimeout("hideMouseOverArea('"+areaParams["areaId"]+"');", 10); // due to IE call of showMouseOverArea
					_hideMouseOverArea(areaParams["areaId"]);
				}
			}
			
			if (areaParams["followMouse"] && areaParams["visible"])
			{
				//alert(1);
				_showMouseOverArea(areaParams["parentId"], areaParams["areaId"], {}, e);
			}
		}
	}
}

function _hideAllMouseOverAreas(e)
{
	for (var id in mouseOverAreas)
	{
		var areaParams = mouseOverAreas[id];
		if (areaParams["visible"])
		{
			_hideMouseOverArea(areaParams["areaId"]);
		}
	}
}
			
function _hideMouseOverArea(areaId)
{
	//document.onmousemove="";
	
	var area=document.getElementById(areaId);
	area.style.display="none";

	for(var id in mouseOverAreas)
	{
		if (mouseOverAreas[id]["areaId"] == areaId)
			mouseOverAreas[id]["visible"] = false;
	}
	//alert('hide');
}



var	mouseOverAreaTop;
var	mouseOverAreaLeft;
var	mouseOverAreaWidth;
var	mouseOverAreaHeight;
var	mouseOverAreaFollowMouse;
var	mouseOverParentTop;
var	mouseOverParentLeft;
var	mouseOverParentWidth;
var	mouseOverParentHeight;
var mouseOverArea;
var mouseOverAreaIFrame;

var	mouseOverAreaOffsetTop;
var	mouseOverAreaOffsetLeft;

var	mouseOverAreaHideArea;

function showMouseOverArea(parentId, areaId, centerHorizontal, centerVertical, followMouse, hideArea, e)
{
	//alert(1);
	mouseOverAreaHideArea = hideArea;
	if (!mouseOverAreaHideArea)
		mouseOverAreaHideArea = "parent";
	
	if (mouseOverArea)
		hideMouseOverArea();
	
	//alert(1);
	if (centerHorizontal == "")
		centerHorizontal = false;
	if (centerVertical == "")
		centerVertical = false;
	if (followMouse == "")
		followMouse = false;
	
	mouseOverAreaFollowMouse = followMouse;
		
	var parent = document.getElementById(parentId);
	
	// check if parent is inside <href
	mouseOverArea = document.getElementById(areaId);
	
	var parentNode = parent.parentNode;
	if (parentNode.tagName.toLowerCase() == "a")
	{
		//// create link and make it mouseover area		
		//var a = document.createElement("a");
		//a.href = parentNode.href;
		//a.target = parentNode.target;
		//a.className = parentNode.className;
		
		mouseOverArea.onClick = "window.location.href='"+parentNode.href+"'";
	}

	mouseOverAreaIFrame = document.getElementById(areaId+'_iframe');
	//alert(parent);
	
	mouseOverArea.style.position = "absolute";
	mouseOverArea.style.zIndex = "52";
	mouseOverArea.style.left = "0px";
	mouseOverArea.style.top = "0px";
	mouseOverArea.style.display = "";

	//alert(2);
	
	mouseOverAreaWidth = mouseOverArea.offsetWidth;
	mouseOverAreaHeight = mouseOverArea.offsetHeight;

	
	//alert(3);
	var parentPosition = getPosition(parent, document.body);
	mouseOverParentTop = parentPosition[1];
	mouseOverParentLeft = parentPosition[0];
	mouseOverParentWidth = parent.offsetWidth;
	mouseOverParentHeight = parent.offsetHeight;
	
	//alert(mouseOverAreaHeight);
	//alert(mouseOverParentHeight);
	//alert(mouseOverParentTop);
	//alert(mouseOverParentLeft);
	//alert(mouseOverParentWidth);
	//alert(mouseOverParentHeight);
	
	var top;
	var left;
	var bottom;
	var right;
	if (followMouse)
	{
		var mouseXY = getMouseXY(e);
		
		left = mouseXY[0];
		top = mouseXY[1];
		
		if (centerVertical)
			top -= mouseOverAreaHeight/2;
		//alert(top);
		//alert(left);
	}
	else
	{
		//if (mouseOverParentHeight-2 == mouseOverAreaHeight) // obrazek ma stejnou vysku
		//	top = mouseOverParentTop;
		//else
			top = mouseOverParentTop+mouseOverParentHeight/2-mouseOverAreaHeight/2;
			
		//if (mouseOverParentWidth-2 == mouseOverAreaWidth) // obrazek ma stejnou sirku
		//	left = mouseOverParentLeft;
		//else
			left = mouseOverParentLeft+mouseOverParentWidth/2-mouseOverAreaWidth/2;
			
	}

	bottom = top+mouseOverAreaHeight;
	right = left+mouseOverAreaWidth;
	
	var hCenter = document.body.offsetWidth/2;
	var hWidth = document.body.offsetWidth;
	if (centerHorizontal)
	{
		left = hCenter-mouseOverAreaWidth/2;
	}
	
	//alert(left);
	
	if (left < 0)
		left = 20;
	if (top < 0)
		top = 20;
/*
	if (right > hWidth)
	{
		if (followMouse)
			left = left-mouseOverAreaWidth;
		else
			left = hWidth-mouseOverAreaWidth-20;
	}
*/
		
	//alert(top);
	//alert(left);
	//alert(right);
	//alert(bottom);
	
	//alert(left);
	mouseOverArea.style.top=(top)+"px";
	mouseOverArea.style.left=(left)+"px";
	mouseOverAreaTop = top;
	mouseOverAreaLeft = left;

	//mouseOverArea.style.position = "absolute";
	//mouseOverArea.style.display = "";

	//alert(mouseOverArea.style.top);
	//alert(mouseOverArea.style.left);
	//alert(mouseOverArea.offsetWidth);
	//alert(mouseOverArea.offsetHeight);
	//return;
	// IE bug fix - we must place <IFRAME> under the area to hide <SELECT> elements
	//return;
	
	/* - zpusobuje problemy ve FF
	mouseOverAreaIFrame.style.top = (top+4)+"px";
	mouseOverAreaIFrame.style.left = (left+4)+"px";
	mouseOverAreaIFrame.style.width = (mouseOverAreaWidth-16)+"px";
	mouseOverAreaIFrame.style.height = (mouseOverAreaHeight-16)+"px";
	mouseOverAreaIFrame.style.position = "absolute";
	mouseOverAreaIFrame.style.zIndex = "49";
	mouseOverAreaIFrame.style.display = "";
	*/
	
	if (mouseOverArea)
		document.onmousemove=checkMouseOverAreaMouseOver;
		
	//fixIEPNG();
}

function checkMouseOverAreaMouseOver(e)
{
	var mouseXY = getMouseXY(e); // works on IE6,FF,Moz,Opera7
	
	//alert(mouseXY)
	//alert(mouseOverParentLeft+' '+mouseOverParentWidth+ ' | '+mouseOverParentTop+' '+mouseOverParentHeight);
	
	if (mouseOverAreaHideArea == "parent")
	{
		if (mouseXY[0] < mouseOverParentLeft || mouseXY[0] > mouseOverParentLeft+mouseOverParentWidth ||
			mouseXY[1] < mouseOverParentTop || mouseXY[1] > mouseOverParentTop+mouseOverParentHeight)
			setTimeout("hideMouseOverArea();", 10); // due to IE call of showMouseOverArea
	}
	else
	{
		if (mouseXY[0] < mouseOverAreaLeft || mouseXY[0] > mouseOverAreaLeft+mouseOverAreaWidth ||
			mouseXY[1] < mouseOverAreaTop || mouseXY[1] > mouseOverAreaTop+mouseOverAreaHeight)
			setTimeout("hideMouseOverArea();", 10); // due to IE call of showMouseOverArea
	}
}

function hideMouseOverArea()
{
	//alert(1);
	document.onmousemove="";
	mouseOverArea.style.display="none";
	mouseOverAreaIFrame.style.display = "none";
	
	mouseOverArea = null;
	mouseOverAreaIFrame = null;
}


/*
function addToBookmarks() 
{
	if (document.all)
	{
		window.external.AddFavorite(document.location.href, document.title);
	} 
	else 
	{
		var ea = document.createEvent("MouseEvents");
		ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
		var eb = document.getElementsByTagName("head")[0];
		eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
		eb.dispatchEvent(ea);
	}
}

function setAsHomePage(page)
{
	if (!page)
		page = serverUrl+mainUrl;
	
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage(page);
}
*/

function getInlineStyleForEditor(style)
{
	if (style == null)
		style = new String("");
	else
		style = new String(style);
   	style = style.replace(/-moz[^;]*;/g, "");
  	style = replaceAll("; ", ";", style);
  	style = replaceAll(";", "\r\n", style);

	return(style);	
}

function getInlineStyleForTag(style)
{
   	style = replaceAll("\r", "", style);
	style = replaceAll("\n", "; ", style);

	return(style);	
}

function checkInlineStyleForTag(style,tagName,tagType)
{
	if (tagName == "input")
	{
		if (tagType == "text")
		{
			if (style.indexOf("height:") != -1)
				return("Cannot use height style attribute due to IE incompatibility. Use font-size style attribute instead.");
		}
	}
	
	return(null);	
}

function getAjaxValue(url, asyncId)
{
	if (!asyncId)
		asyncId = false;
	
	var xmlhttp =  new XMLHttpRequest();	

    if (debug == 'dbgAjax')
		window.open(url);
    	//alert(url);
	var ret = null;
	if (asyncId)
	{
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				var ret = xmlhttp.responseText;
				if (ret.indexOf('AJAX Error:') == 0)
				{	
					alert(ret);
				}
				else
				{
					ret = trim(ret);
					document.getElementById(asyncId).value = ret;
				}
			}
		};
		xmlhttp.open('GET', url, true);
    	xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open('GET', url, false);
    	xmlhttp.send(null);
		if(xmlhttp.status == 200)
		{
			//var headers = xmlhttp.getAllResponseHeaders();
			//alert(headers);
			var ret = xmlhttp.responseText;
			if (ret.indexOf('AJAX Error:') == 0)
			{
				alert(ret);
				ret = null;
			}
			else
				ret = trim(ret);
		}
		else
		{
			alert('Error in getComponentAjaxValue(): no server response');
		}
	}
	return(ret);
}

function getComponentAjaxValue(tableName, fieldName, params, returnType, asyncId, functionName)
{
	if (!params)
		params = new Array;
	if (!returnType)
		returnType = 'rtValue';
	if (!asyncId)
		asyncId = false;
	
	if (!tableName && params['componentType'] == '')
	{
		alert('Error in getComponentAjaxValue(): no tableName or componentType specified');
		return(null);
	}
	if (!fieldName && params['componentType'] == '')
	{
		alert('Error in getComponentAjaxValue(): no fieldName or componentType specified');
		return(null);
	}
	
	//var url = serverUrl+mainUrl+(ADMIN ? "admin/" : "")+"ajax.php?viewType=vtComponent&sid="+sid+"&tableName="+tableName+"&fieldName="+fieldName+"&returnType="+returnType;
	var url = serverUrl+mainUrl+(ADMIN ? "admin/" : "")+"ajax.php";
	var urlParams = "viewType=vtComponent&sid="+sid+"&tableName="+tableName+"&fieldName="+fieldName+"&returnType="+returnType;
	
	//var postParams = params;
	//postParams['viewType'] = 'vtComponent';
	//postParams['sid'] = sid;
	//postParams['tableName'] = tableName;
	//postParams['fieldName'] = fieldName;
	//postParams['returnType'] = returnType;
	
	if (functionName)
	{
		urlParams += "&functionName="+functionName;
		//postParams['functionName'] = functionName;
	}
	
	for (key in params)
	{
		var paramName = key;
		var paramValue = params[key];
		
		urlParams += "&"+paramName+"="+paramValue;
	}
		
	var xmlhttp =  new XMLHttpRequest();	

    if (debug == 'dbgAjax')
		window.open(url+'?'+urlParams);
    	//alert(url);
	var ret = null;
	if (asyncId)
	{
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				var ret = xmlhttp.responseText;
				if (ret.indexOf('AJAX Error:') == 0)
				{	
					alert(ret);
				}
				else
				{
					ret = trim(ret);
					document.getElementById(asyncId).value = ret;
				}
			}
		};
		xmlhttp.open('GET', url+"?"+urlParams, true);
    	xmlhttp.send(null);
	}
	else
	{
		//xmlhttp.open('GET', url+"?"+urlParams, false);
    	//xmlhttp.send(null);
    	xmlhttp.open('POST', url, false);
    	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    	xmlhttp.send(urlParams);
    	
		if(xmlhttp.status == 200)
		{
			//var headers = xmlhttp.getAllResponseHeaders();
			//alert(headers);
			var ret = xmlhttp.responseText;
			if (ret.indexOf('AJAX Error:') == 0)
			{
				alert(ret);
				ret = null;
			}
			else
				ret = trim(ret);
		}
		else
		{
			alert('Error in getComponentAjaxValue(): no server response');
		}
	}
	return(ret);
}

function getTableAjaxValue(tableName, functionName, params, asyncId)
{
	if (!params)
		params = new Array;
	returnType = 'rtValue';
	if (!asyncId)
		asyncId = false;
	
	if (!tableName)
	{
		alert('Error in getTableAjaxValue(): no tableName specified');
		return(null);
	}
	
	var url = serverUrl+mainUrl+(ADMIN ? "admin/" : "")+"ajax.php?viewType=vtTable&sid="+sid+"&tableName="+tableName+"&functionName="+functionName+"&returnType="+returnType;
	if (functionName)
		url += "&functionName="+functionName;
	
	for (key in params)
	{
		var paramName = key;
		var paramValue = params[key];
		
		url += "&"+paramName+"="+paramValue;
	}
		
	var xmlhttp =  new XMLHttpRequest();	
    if (debug == 'dbgAjax')
		window.open(url);

	var ret = null;
	if (asyncId)
	{
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				var ret = xmlhttp.responseText;
				if (ret.indexOf('Error') != -1)
				{	
					alert(ret);
				}
				else
				{
					document.getElementById(asyncId).innerHTML = ret;
				}
			}
		};
		xmlhttp.open('GET', url, true);
    	xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open('GET', url, false);
    	xmlhttp.send(null);
		if(xmlhttp.status == 200)
		{
			//var headers = xmlhttp.getAllResponseHeaders();
			//alert(headers);
			var ret = xmlhttp.responseText;
			if (ret.indexOf('AJAX Error:') == 0)
			{
				alert(ret);
				ret = null;
			}
		}
		else
		{
			alert('Error in getComponentAjaxValue(): no server response');
		}
	}
	
	return(ret);
}

function getTableAjaxRecordValues(tableName, params, asyncId)
{
	if (!params)
		params = new Array;

	if (typeof ADMIN == 'undefined')
		ADMIN = false;
	if (typeof sid == 'undefined')
		sid = '';
	if (typeof debug == 'undefined')
		debug = '';

	returnType = 'rtValue';
	functionName = 'getAjaxHidden';
	
	if (!asyncId)
		asyncId = false;
	
	if (!tableName)
	{
		alert('Error in getTableAjaxValue(): no tableName specified');
		return(null);
	}
	
	var url = serverUrl+mainUrl+(ADMIN ? "admin/" : "")+"ajax.php?viewType=vtTable&sid="+sid+"&tableName="+tableName+"&functionName="+functionName+"&returnType="+returnType;
	if (functionName)
		url += "&functionName="+functionName;
	
	for (key in params)
	{
		var paramName = key;
		var paramValue = params[key];
		
		url += "&"+paramName+"="+escape(paramValue);
	}
		
	//if (tableName == "forms")
	//	window.location.href=url;
		
	var xmlhttp =  new XMLHttpRequest();	
    if (debug == 'dbgAjax')
		window.open(url);

	var ret = null;
	if (false && asyncId)
	{
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				var ret = xmlhttp.responseText;
				if (ret.indexOf('Error') != -1)
				{	
					alert(ret);
				}
				else
				{
					document.getElementById(asyncId).innerHTML = ret;
				}
			}
		};
		xmlhttp.open('GET', url, true);
    	xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open('GET', url, false);
    	xmlhttp.send(null);
		if(xmlhttp.status == 200)
		{
			//var headers = xmlhttp.getAllResponseHeaders();
			//alert(headers);
			var ret = xmlhttp.responseText;
			//alert(url);
			//alert(ret);
			if (ret.indexOf('AJAX Error:') == 0)
			{
				alert(ret);
				ret = null;
			}
			else
			{
				//alert(ret);
				var records = new Object;
				eval("records = "+ret+";");
				
				return(records);
			}
		}
		else
		{
			alert('Error in getComponentAjaxValue(): no server response');
		}
	}

	return(ret);
}

function getDialogAjaxValue(params)
{
	if (!params)
		params = new Array;
	returnType = 'rtDialog';
	asyncId = false;
	
	var url = serverUrl+mainUrl+(ADMIN ? "admin/" : "")+"ajax.php?viewType=vtTable&sid="+sid+"&returnType="+returnType;
	
	for (key in params)
	{
		var paramName = key;
		var paramValue = params[key];
		
		url += "&"+paramName+"="+paramValue;
	}
		
	var xmlhttp =  new XMLHttpRequest();	
    if (debug == 'dbgAjax')
		window.open(url);

	var ret = null;
	if (asyncId)
	{
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				var ret = xmlhttp.responseText;
				if (ret.indexOf('Error') != -1)
				{	
					alert(ret);
				}
				else
				{
					document.getElementById(asyncId).innerHTML = ret;
				}
			}
		};
		xmlhttp.open('GET', url, true);
    	xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open('GET', url, false);
    	xmlhttp.send(null);
		if(xmlhttp.status == 200)
		{
			//var headers = xmlhttp.getAllResponseHeaders();
			//alert(headers);
			var ret = xmlhttp.responseText;
			if (ret.indexOf('AJAX Error:') == 0)
			{
				alert(ret);
				ret = null;
			}
		}
		else
		{
			alert('Error in getComponentAjaxValue(): no server response');
		}
	}
	
	return(ret);
}



var jsOnLoad = [];

// calling form.submit() does not fire onsubmit event (only using submit button)! needed this function
function submitForm(formId)
{
	var form = document.getElementById(formId);
	
	if (form)
	{
		if (form.onsubmit)
			form.onsubmit();
		
		form.submit();
	}
}

function getElementById(id)
{
	return(document.getElementById(id));
}

function playSound(soundName) 
{
	soundName = String(soundName.charAt(0)).toUpperCase()+String(soundName).substr(1, soundName.length-1);
	var embed = document.getElementById("sound"+soundName);
	embed.Play();
}

var highlightFnc = null;
function switchHighlight(element, highlight, origBorderStyle, borderStyle)
{  
	//if (highlight)
	//	element.style.border = borderStyle;
	//else
	//	element.style.border = origBorderStyle;

	if (highlight)
		element.style.border = "2px solid #FF9900";
	else
		element.style.border = "2px solid #0072A8";

	//alert(highlight+" "+origBorderStyle+" "+borderStyle);
	
	if(highlightFnc != null)
		highlightFnc = setTimeout(function(){switchHighlight(element, !highlight, origBorderStyle, borderStyle);}, 1000);
} 

function startElementHighlight(id, borderStyle)
{
	var element = document.getElementById(id);
	
	if (element)
	{
		highlightFnc = setTimeout(function(){switchHighlight(element, true, element.style.border, borderStyle);}, 1000);
	}
}

function stopElementHighlight()
{
	highlightFnc = null;
}

function addOnLoad(evalCode)
{
	jsOnLoad.push(evalCode);	
}

function showToolTip(message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20)
{
	var ret = overlib(message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20);
	
	//alert(ret);
	return(ret);
}

function hideToolTip()
{
	return nd();
}

function showBubbleMessage(title, text, timeout)
{
	var bubbleMessageContainer = document.getElementById('bubbleMessageContainer');
	var bubbleMessageTitle = document.getElementById('bubbleMessageTitle');
	var bubbleMessageText = document.getElementById('bubbleMessageText');

	bubbleMessageTitle.innerHTML = title;	
	bubbleMessageText.innerHTML = text;	
	
	bubbleMessageContainer.style.display = "";
	
	// move to bottom right corner
	var width = bubbleMessageContainer.offsetWidth;
	var height = bubbleMessageContainer.offsetHeight;
	
	//alert(width);
	//alert(height);
	
	
	bubbleMessageContainer.style.left = (document.body.offsetWidth-width-30)+'px';
	bubbleMessageContainer.style.top = (document.body.offsetHeight-height-30)+'px';
	
	//alert(bubbleMessageContainer.style.left);
	//alert(bubbleMessageContainer.style.top);
	
	setTimeout(function() { bubbleMessageContainer.style.display = "none";}, 5000);

/*	

	var width = 260;
	var height = 400;
	var top = window.top.document.body.offsetHeight-height-50;
	var left = window.top.document.body.offsetWidth-width-50;
	//alert(left + "x" + top + " - " + width + "x" + height );
	
	//showToolTip(text, BUBBLE, BUBBLETYPE, 'roundcorners', ADJBUBBLE);	
	if (timeout == "undefined")
		timeout = 4000;
	else if (timeout == 0)
		timeout = 20000;
	else
		timeout = timeout*1000;
		
	//alert("showToolTip(\"<div style='overflow: hidden;'>"+text+"</div>"+","+BUBBLE+","+BUBBLETYPE+","+'roundcorners'+","+ADJBUBBLE+","+CAPTION+","+"<span style='color: #000000;'>"+title+"</span>"+","+FIXX+","+left+","+FIXY+","+top+","+WIDTH+","+width+","+HEIGHT+","+height+","+TIMEOUT+","+timeout+");");
	showToolTip("<div style='overflow: hidden;'>"+text+"</div>", BUBBLE, BUBBLETYPE, 'roundcorners', ADJBUBBLE, CAPTION, "<span style='color: #000000;'>"+title+"</span>", FIXX, left, FIXY, top, WIDTH, width, HEIGHT, height, TIMEOUT, timeout);	
*/
}

var progressBarVisible = false;
function showProgressBar(percent,message)
{
	if (!progressBarVisible)
	{
		showMessage('','','');
	}
	
	var progressBarContainer = document.getElementById('messageBoxProgressContainer');
	var progressBar = document.getElementById('messageBoxProgressBar');
	var progressBarR = document.getElementById('messageBoxProgressBarR');
	var progressBarText = document.getElementById('messageBoxProgressBarText');
	//progressBarContainer.style.border = '1px solid #666666';
	var progressBarMessage = document.getElementById('messageBoxMessage');
	
	if (message != "")
		progressBarMessage.innerHTML = message;

	// reposition progressBarText
	var pos = getPosition(progressBarContainer);
	progressBarText.style.top = (pos[1]+progressBarContainer.offsetHeight/4-2)+"px";
	progressBarText.style.left = (pos[0]+progressBarContainer.offsetWidth/2-10)+"px";
	
	if (percent == 0)
	{
		progressBar.style.background = '#EEEEEE';
		progressBar.style.border = '1px solid #EEEEEE';
		progressBar.innerHTML = '';
	}
	else
	{
		progressBar.style.background = '#2222FF';
		progressBar.style.border = '1px solid #2222FF';
		progressBar.innerHTML = '&nbsp;';
	}

	if (percent == 100)
	{
		progressBarR.style.background = '#2222FF';
		progressBarR.style.border = '1px solid #2222FF';
		progressBarR.innerHTML = '';
	}
	else
	{
		progressBarR.style.background = '#EEEEEE';
		progressBarR.style.border = '1px solid #EEEEEE';
		progressBarR.innerHTML = '&nbsp;';
	}

	if (percent < 48)
		progressBarText.style.color = '#000000';		
	if (percent >= 48 && percent <= 54)
		progressBarText.style.color = '#888888';		
	if (percent > 54)
		progressBarText.style.color = '#FFFFFF';		

	progressBar.style.width = percent+'%';
	progressBarR.style.width = (100-percent)+'%';
	
	progressBarText.innerHTML = percent+'%';
}

function showMessage(title, message, icon)
{
	var container = document.getElementById('messageBoxContainer');
	var containerTD = document.getElementById('messageBoxContainerTD');
	var iconIMG = document.getElementById('messageBoxIcon');
	var titleTD = document.getElementById('messageBoxTitle');
	var messageTD = document.getElementById('messageBoxMessage');
	container.style.display = "block";
	containerTD.style.height = (container.offsetHeight-10)+'px';
	containerTD.style.width = (container.offsetWidth-10)+'px';
	
	if (icon != "")
	{
		iconIMG.src = serverCoreUrl+coreUrl+"images/core/64/"+icon+".png";
		iconIMG.style.display = "inline";
	}
	
	titleTD.innerHTML = title;
	messageTD.innerHTML = message;
	
	progressBarVisible = true;
}

function hideProgressBar()
{
	var container = document.getElementById('messageBoxContainer');
	container.style.display = "none";

	progressBarVisible = false;
}

function urlEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return (encoded);
}

function urlDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2)
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return(plaintext);
}

function roundDown(n)
{
	return (Math.floor(n));
}

function roundUp(n)
{
	return (Math.ceil(n));
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{
  var mousex, mousey;
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  {
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      //algor = '[e.pageX]';
      //if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      // Note: I am adding together both the "body" and "documentElement" scroll positions
      //       this lets me cover for the quirks that happen based on the "doctype" of the html page.
      //         (example: IE6 in compatibility mode or strict)
      //       Based on the different ways that IE,FF,Moz,Opera use these ScrollValues for body and documentElement
      //       it looks like they will fill EITHER ONE SCROLL VALUE OR THE OTHER, NOT BOTH
      //         (from info at http://www.quirksmode.org/js/doctypes.html)
      mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      //algor = '[e.clientX]';
      //if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }
  }
  return([mousex,mousey]);
}

function swapNode(node1, node2)
{
  	var nextSibling = node1.nextSibling;
  	var parentNode = node1.parentNode;
  	node2.parentNode.replaceChild(node1, node2);
  	parentNode.insertBefore(node2, nextSibling);
}

function moveNodeBefore(node1,node2)
{
  	var parentNode = node1.parentNode;
  	parentNode.removeChild(node1);
  	parentNode.insertBefore(node1, node2);
}

function moveNodeAfter(node1,node2)
{
  	var parentNode = node1.parentNode;
  	parentNode.removeChild(node1);
  	parentNode.insertBefore(node1, node2.nextSibling);
}

function moveNodeInto(node1,node2,first)
{
  	var parentNode = node1.parentNode;
  	parentNode.removeChild(node1);
  	
  	if (first === true)
  		node2.insertBefore(node1, node2.childNodes[0]);
  	else
  		node2.appendChild(node1);
}

/*
Node.prototype.swapNode = function(node)
{
  	var nextSibling = this.nextSibling;
  	var parentNode = this.parentNode;
  	node.parentNode.replaceChild(this, node);
  	parentNode.insertBefore(node, nextSibling);
}

Node.prototype.moveBefore = function(node)
{
  	var parentNode = this.parentNode;
  	parentNode.removeChild(this);
  	parentNode.insertBefore(this, node);
}

Node.prototype.moveAfter = function(node)
{
  	var parentNode = this.parentNode;
  	parentNode.removeChild(this);
  	parentNode.insertBefore(this, node.nextSibling);
}
*/

function popupImage(imageUrl, width, height, event)
{
	if (width > 0 && height > 0)
		wnd = window.open("", "popupImage", "width="+(width)+",height="+(height)+",resizable=0,scrollbars=0,status=0,titlebar=0,top="+(event.screenY-height/2)+",left="+(event.screenX-width/2));
	else
		wnd = window.open("", "popupImage", "");
    wnd.document.writeln("<html><body style='width:100%;height:100%;margin: 0px 0px 0px 0px;'><table style='width:100%;height:100%;'><tr><td style='text-align:center; vertical-align: middle;'>");
    wnd.document.writeln("<a href='#' onclick='window.close();'>");
	    
	if (width > 0 && height > 0)
	    wnd.document.writeln("<img src='"+imageUrl+"' width='"+width+"' height='"+height+"' alt='' border='0' />");
	else
    	wnd.document.writeln("<img src='"+imageUrl+"' alt='' border='0' />");
    wnd.document.writeln("</a>");
    wnd.document.writeln("</td></tr></table></body></html>");
    wnd.document.close();
    wnd.focus();

    return false;
}

function hoverFindObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=hoverFindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function hoverSwapImage() { //v3.0
  var i,j=0,x,a=hoverSwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=hoverFindObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function hoverSwapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function hoverPreloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=hoverPreloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


String.prototype.isArgument=function()
{
	return /^([a-zA-Z]){1,}=([0-9]){1,}$/.test(this);
}


/*
call this function just work like window.open(url,name,feature);
however, for IE5.0+, it will open a showModelessDialog window;
and For Gecko(Mozilla or Netscape), the child window will stay on top focus untill user close it.
*/


function dialog(url,name,feature,isModal)
{
 if(url==null){return false;}
 url = url
 if(name==null){name=""}
 if(feature==null){feature=""};
 if(window.showModelessDialog)
 {
  	var WindowFeature = new Object();
	WindowFeature["width"] = 400;
	WindowFeature["height"]  =400;
	WindowFeature["left"]  = "";
	WindowFeature["top"]  =  "";
	WindowFeature["resizable"]  = "";

	if(feature !=null && feature!="")
	{
      feature = ( feature.toLowerCase()).split(",");

      for(var i=0;i< feature.length;i++)
		{
          if( feature[i].isArgument())
			{
               var featureName = feature[i].split("=")[0];
			   var featureValue = feature[i].split("=")[1];

			   if(WindowFeature[featureName]!=null){WindowFeature[featureName] = featureValue; }
			}
		}
	}

  if(WindowFeature["resizable"]==1 || WindowFeature["resizable"]=="1" || WindowFeature["resizable"].toString().toLowerCase()=="yes"){WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;"}
  if(WindowFeature["left"]!=""){WindowFeature["left"] ="dialogLeft:" +  WindowFeature["left"] +"px;";}
  if(WindowFeature["top"]!=""){WindowFeature["top"] ="dialogTop:" +  WindowFeature["Top"] +"px;"; }
  if(window.ModelessDialog ==null){window.ModelessDialog = new Object() ; };
  if(name!="")
  {
   if(window.ModelessDialog[name]!=null && !window.ModelessDialog[name].closed )
   {
     window.ModelessDialog[name].focus();
	 return window.ModelessDialog[name];
   }
  }
	var F = WindowFeature["left"] +WindowFeature["top"] +  "dialogWidth:"+WindowFeature["width"] +" px;dialogHeight:"+WindowFeature["height"]+"px;center:1;help:0;" + WindowFeature["resizable"] +"status:0;unadorned:0;edge: raised; ;border:thick;"
	if(isModal)
	{
		window.showModalDialog(url,self,F);
		return false;
	}
	else
	{
		window.ModelessDialog[name] = window.showModelessDialog(url,self,F);
		return window.ModelessDialog[name];
	}
 }
 else
 {
   if(document.getBoxObjectFor)
   {


	 if(isModal)
	 {
		 var Modal = window.open(url,name,"modal=1," + feature);
		 var ModalFocus = function()
		 {
			if(!Modal.closed){Modal.focus();}
			else{Modal =null;window.removeEventListener(ModalFocus,"focus");ModalFocus = null; };
		 }
		 window.addEventListener( "focus",ModalFocus, false );
		 return false;
	 }
	 else
	 {
		return window.open(url,name,"modal=1," + feature);
	 }
   }
   else
   {
     return window.open(url,name,feature);
   }
   //
 }
 return null;
}




function modal(url,feature)
{
	dialog(url,"",feature,true);
	return false;
}

function getPosition(object, relativeToObject, relativeToClassName)
{
	if (relativeToClassName == "")
		relativeToClassName = "undefinedClassName";
		
	if (object.offsetParent)
  	{
    	for (var posX = 0, posY = 0; object.offsetParent; object = object.offsetParent)
    	{
            if (object == relativeToObject || object.className == relativeToClassName)
            	break;

      		posX += object.offsetLeft;
      		posY += object.offsetTop;
    	}
    	return [ posX, posY ];
  	}
    else
    {
    	return [ object.x, object.y ];
  	}
}

// TEXTAREA <TAB> simulation
function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}

function replaceSelection (input, replaceString) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);

		if (selectionStart != selectionEnd){
			setSelectionRange(input, selectionStart, selectionStart + 	replaceString.length);
		}else{
			setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
		}

	}else if (document.selection) {
		var range = document.selection.createRange();

		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;

			 if (!isCollapsed)  {
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}


// We are going to catch the TAB key so that we can use it, Hooray!
function catchTab(item,e){
	if(navigator.userAgent.match("Gecko")){
		c=e.which;
	}else{
		c=e.keyCode;
	}
	if(c==9){
		//replaceSelection(item,String.fromCharCode(9));  // inserts [TAB]
		replaceSelection(item,"    ");    				  // inserts "    "
		setTimeout("document.getElementById('"+item.id+"').focus();",0);
		return false;
	}

}
// end TEXTAREA <TAB> simulation

function cleanLink(link)
{
	link = link.replace("//", "/");
	link = link.replace("//", "/");
	link = link.replace("//", "/");
	link = link.replace("http:/", "http://");

    return(link);
}

function uncryptMail(s)
{
	var n=0;
	var r="";
	var shift=3; // same value as the mail was coded with
	for(var i=0; i < s.length; i++)
    {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift));
	}
	return r;
}

function antiSpamMailTo(s)
{
	location.href=uncryptMail(s);
}

function charsTotalRemaining(id, max)
{
	var elem = document.getElementById(id);
    var elem_text_total = document.getElementById(id+'_counterTotal');
    var elem_text_remaining = document.getElementById(id+'_counterRemaining');
	if (elem != null && elem_text_total != null && elem_text_remaining != null)
    {
        elem_text_total.innerHTML = elem.value.length;
		elem_text_remaining.innerHTML = max-elem.value.length;
    }
};

function replaceAll( str, from, to )
{
    //alert(str);
	var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    //alert(str);
    return str;
};

function str_replace( from, to, str )
{
    //alert(str);
	var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    //alert(str);
    return str;
};
