//Common Function
function parseJSON(jsonString){
	return (new Function('return ' + jsonString))();
}

function createHideImage(params){
	try{
		var src = params.getValue('src');
		var container = document.getElementById('fox_img_container');
		if (container){
			var elementID = 'fox_img_' + (new Date()).getTime();
			var element = document.createElement('img');
			element.id = elementID;
			element.src = src;
			element.style.display = 'none';
			container.appendChild(element);
			return elementID;
		}
	}catch(e){
		WriteLog('createHideImg', e.message);
	}
	return '';
}
function removeHideImage(params){
	try{
		var id = params.getValue('id');
		var element = document.getElementById(id);
		$(element).remove();
	}catch(e){
		WriteLog('removeHideImage', e.message);
	}
}

//var editor_elements_list = ["TEXTAREA", "INPUT"];
function checkIsFocusInEditor(){
	var obj = document.activeElement;
	if (obj){
		var tagName = obj.tagName;
		if (tagName === 'TEXTAREA'){
			return true;
		}else if (tagName === 'INPUT'){
			return true;
		}
	}
	return false;
}

function getPointFromString(ptString){
	//string: "x:123,y:345"
	var px = 0;
	var py = 0;
	try{
	var xIndex = ptString.indexOf('x:');
	var yIndex = ptString.lastIndexOf('y:');
	if (xIndex != -1 && yIndex != -1){
		var splitIndex = ptString.indexOf(',');
		px = parseInt(ptString.substring(xIndex+2, splitIndex));
		py = parseInt(ptString.substring(yIndex+2));
	}
	}catch(e){ WriteLog('getPointFromString', e.message); }
	return {x: px, y: py};
}

function WriteLog(name, msg){
	var logTime = new Date();
	invokeAppFunction('FoxWriteLog', {name: name, msg: msg, time: logTime.getTime()});
}

function safeRun(func, erCallback){
	try{
		func();
	}catch(err){
		if(erCallback){
			erCallback(err.name, err.message);
		}
	}
}

var g_debugMsgCount = 0;
function doInitDebugMsg(){
	$('#debug_msg').removeClass();
}
function doClearDebugMsg(){
	var debug = document.getElementById('debug_msg');
	debug.innerHTML = '';
}
function doAddDebugMsg(msg){
	var debug = document.getElementById('debug_msg');
	if ($(debug).hasClass('hide_ifzero_0')) return;
	g_debugMsgCount++;
	if (g_debugMsgCount >= 50){
		doClearDebugMsg();
		g_debugMsgCount = 0;
	}
	debug.innerHTML = debug.innerHTML + msg + '<br/>';
}