	function gE(el)
	{ return document.getElementById(el); }
	
	function gN(el)
	{ return document.getElementsByName(el); }
	
	/* function Trim(str)
	{ str = str.replace(/\s+$/, ''); str = str.replace(/^\s+/, ''); return str; } */
	
	function IsEmail(str)
	{
		var re_1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/i;
		return (Trim(str).length && Trim(str).match(re_1))?true:false;
	}
	
	function ValidateEmail(str)
	{
		var re_1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/i;
		return (Trim(str).length && Trim(str).match(re_1))?true:false;
	}
	
	/* function ValidateLogin(str)
	{return (str.match(/^[0-9_a-z-]+$/i) && str.length>2)?true:false;} */

	function IsInt(v)
	{ return parseInt(v).toString()===v.toString(); }
	
	function ToInt(v)
	{ return (v*1); }
	
	function AddLoadEvent(func)
	{
		var oldonload = window.onload;
		if (typeof window.onload != 'function')
			window.onload = func;
		else
		{
			window.onload = function()
			{
				oldonload();
				func();
			}
		}
	}
	
	//@todo delete in old scripts and use function upper
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		}
		else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
	
	//@todo delete in old scripts
	function isset(varname)  {
	  if(typeof(varname)=="undefined") 
		return false;
	  else 
		return true;
	}

	function InnerToFromAjax(_url, oInsertTo)
	{
		var oAjax;

		if (window.XMLHttpRequest)
		{
			oAjax = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			try 
			{
				oAjax = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e){}
			try 
			{
				oAjax = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e){}
		}

		if (oAjax)
		{
			oAjax.onreadystatechange = function()
			{
				if (oAjax.readyState == 4 && oAjax.status == 200) 
				{
					var sContent = oAjax.responseText;
					oInsertTo.innerHTML = sContent;
				}
			};
			oAjax.open("POST", _url, true);
			oAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oAjax.send('is_ajax=1');
		}
		else
		{
			alert("AJAX not init!");
		}
	}

	function AlertFromAjax(_url)
	{
		var oAjax;

		if (window.XMLHttpRequest)
		{
			oAjax = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			try 
			{
				oAjax = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e){}
			try 
			{
				oAjax = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e){}
		}

		if (oAjax)
		{
			oAjax.onreadystatechange = function()
			{
				if (oAjax.readyState == 4 && oAjax.status == 200) 
				{
					alert( oAjax.responseText );
				}
			};
			oAjax.open("POST", _url, true);
			oAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oAjax.send('is_ajax=1');
		}
		else
		{
			alert("AJAX not init!");
		}
	}
	
	function SetValueFromAjax(_url, obj)
	{
		var oAjax;

		if (window.XMLHttpRequest)
		{
			oAjax = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			try 
			{
				oAjax = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e){}
			try 
			{
				oAjax = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e){}
		}

		if (oAjax)
		{
			oAjax.onreadystatechange = function()
			{
				if (oAjax.readyState == 4 && oAjax.status == 200) 
				{
					obj.value 		= oAjax.responseText;
				}
			};
			oAjax.open("POST", _url, true);
			oAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oAjax.send('is_ajax=1');
		}
		else
		{
			alert("AJAX not init!");
		}
	}

	function getElementsByClass(searchClass, node, tag) //@todo from small becouse use in old scripts
	{
		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 StrLen(string) 
	{
		var str = string+'';
		var i = 0, chr = '', lgth = 0;
	 
		var getWholeChar = function (str, i) 
		{
			var code = str.charCodeAt(i);
			var next = '', prev = '';
			if (0xD800 <= code && code <= 0xDBFF) 
			{
				if (str.length <= (i+1))  
				{
					throw 'High surrogate without following low surrogate';
				}
				next = str.charCodeAt(i+1);
				if (0xDC00 > next || next > 0xDFFF) 
				{
					throw 'High surrogate without following low surrogate';
				}
				return str[i]+str[i+1];
			}
			else if (0xDC00 <= code && code <= 0xDFFF) {
				if (i === 0) 
				{
					throw 'Low surrogate without preceding high surrogate';
				}
				prev = str.charCodeAt(i-1);
				if (0xD800 > prev || prev > 0xDBFF) 
				{
					throw 'Low surrogate without preceding high surrogate';
				}
				return false;
			}
			return str[i];
		};
	 
		for (i=0, lgth=0; i < str.length; i++) 
		{
			if ((chr = getWholeChar(str, i)) === false) 
			{
				continue;
			}
			lgth++;
		}
		return lgth;
	}
	
	// old form
	function strlen(string) {return StrLen(string);}

	define = 
	(
		function()
		{
			function toString(name, value)
			{
				return  "const " + name + "=" + (/^(null|true|false|(\+|\-)?\d+(\.\d+)?)$/.test(value = String(value)) ? value : '"' + replace(value) + '"')
			};
			
			var define, replace;
			try
			{
				eval("const e=1");
				replace = function(value)
				{
					var replace = {"\x08":"b","\x0A":"\\n","\x0B":"v","\x0C":"f","\x0D":"\\r",'"':'"',"\\":"\\"};
					return  value.replace(/\x08|[\x0A-\x0D]|"|\\/g, function(value){return  "\\"+replace[value]})
				};
				
				define = function(name, value)
				{
					var script = document.createElement("script");
					script.type = "text/javascript";
					script.appendChild(document.createTextNode(toString(name, value)));
					document.documentElement.appendChild(script);
					document.documentElement.removeChild(script);
				}
			}
			catch(e)
			{
				replace = function(value)
				{
					var replace = {"\x0A":"\\n", "\x0D":"\\r"};
					return  value.replace(/"/g, '""').replace(/\n|\r/g, function(value){return replace[value]})
				};
				
				define = this.execScript ?	function(name, value){execScript(toString(name, value), "VBScript");} :	function(name, value){eval(toString(name, value).substring(6));}
			};
			return  define;
		}
	)();
	
	function defined(constantName )  
	{
		return (typeof window[constantName] !== 'undefined');
	}
	
	function File(url) 
	{
		var req = null;
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch(e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			catch(e) 
			{
				try { req = new XMLHttpRequest(); } catch(e) {}
			}
		}
		if (req == null)
			throw new Error('XMLHttpRequest not supported');
	 
		req.open("GET", url, false);
		req.send(null);
	 
		return req.responseText.split('\n');
	}
	
	function FileGetContents(url)
	{
		var req = null;
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (e)
		{
			try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
				try { req = new XMLHttpRequest(); } catch(e) {}
			}
		}
		if (req == null) throw new Error('XMLHttpRequest not supported');
	 
		req.open("GET", url, false);
		req.send(null);
	 
		return req.responseText;
	}
	
	function GetX(el)
	{
		var left = 0;
		do
		{
			left += el.offsetLeft || 0;																	
			el 	 =  el.offsetParent;
		} while (el);
		return left+(window.ie6||window.ie7?1:0);
	}
	
	function GetY(el)
	{
		var top = 0;
		do
		{
			top += el.offsetTop || 0;
			el 	=  el.offsetParent;
		} while (el);
		return top+(window.ie6||window.ie7?1:0);
	}
	
	
	/**
	 *	OLD FUNCTION
	 */
	function Appear(str)
	{
		var content  = gE(str);
		var _Content = new AppearObj(1,0,content);
		_Content.Appear();
	}
	
	function ChangeLanguage(lang_id)
	{
		var str = document.location.href;
		str = str.replace(/lang=[\w&]+/gi, '');
		str = str.replace(/&$/gi, '');
		if (str.indexOf("?") > -1 || str.indexOf("action") != -1)
		{
			window.location=str+'&lang='+lang_id;
		}
		else
		{
			window.location='?lang='+lang_id;
		}
		
		return false;
	}
	
	function ChangeLimitNews(count)
	{
		var str = document.location.href;
		str = str.replace(/limit=[\w&]+/gi, '');
		str = str.replace(/&$/gi, '');
		if (str.indexOf("?") > -1)
		{
			window.location=str+'&limit='+count;
		}
		else
		{
			window.location='?limit='+count;
		}
		
		return false;
	}
	
	function GotoOpenLiveAccount(server)
	{
		if(server.indexOf("instafxmalaysia.com") !== -1 || server.indexOf("instafxgroup.com") !== -1)
		{
			location.href="http://www.instaforex.com/open_live_account.php?x=IS";
		}
		else
		{
			location.href="open_live_account.php";
		}
		return;
	}
	
	function	is_int(v) 
	{
		return	parseInt(v).toString()===v.toString();
	}
	
	function	pagelist(npage,cntrows,perpage,range)
	{
		if (!range) range = 9;

		var totalpage	=	Math.ceil(cntrows/perpage);
		var crange		=	Math.ceil(range/2);

		if(totalpage>1) {

			if(npage>totalpage)	npage	=	totalpage;

			if(npage<crange) {

				var fromurl	=	1;
				var tourl		=	fromurl+(range-1);

				if(tourl>totalpage)	tourl	=	totalpage;

			} else if(npage>(totalpage-crange)) {


				var fromurl	=	totalpage-(range-1);
				var tourl	=	totalpage;

				if(fromurl<1)	fromurl	=	1;

			} else {
				fromurl	=	npage-(crange-1);
				tourl	=	npage+(crange-1);
			}

			var llpoint	=	npage-range;
			var lpoint		=	npage-1;
			var rpoint		=	npage+1;
			var rrpoint	=	npage+range;

			if(llpoint<1)
				llpoint	=	1;
			if(lpoint<1)
				lpoint		=	1;
			if(rpoint>totalpage)
				rpoint		=	totalpage;
			if(rrpoint>totalpage)
				rrpoint	=	totalpage;
		}

		return	{"npage":npage,"total":totalpage,"ll":llpoint,"l":lpoint,"from":fromurl,"to":tourl,"r":rpoint,"rr":rrpoint};
	}
	
	function htmlspecialchars(str,typ) 
	{
		if(typeof str=="undefined") str="";
		if(typeof typ!="number") typ=2;
		typ=Math.max(0,Math.min(3,parseInt(typ)));
		var from=new Array(/</g,/>/g);
		var to=new Array("&lt;","&gt;");
		if(typ==1 || typ==3) {from.push(/'/g); to.push("&#039;");}
		if(typ==2 || typ==3) {from.push(/"/g); to.push("&quot;");}
		for(var i in from) str=str.replace(from[i],to[i]);
		return str;
	}
	
	function addEvent(elm, evType, fn, useCapture) 
	{
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}
	
	function toggle(obj) 
	{
		var el = document.getElementById(obj);
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}
		else {
			el.style.display = '';
		}
	}

	function insertAfter(parent, node, referenceNode) 
	{
		parent.insertBefore(node, referenceNode.nextSibling);
	}
	
	function PreLoadImages()
	{		
		var clientWidth 	= document.documentElement.clientWidth;
		var Images			= (_browser.isIE6)?document.getElementsByTagName('img'):document.getElementById("content").getElementsByTagName("img");
		var max800			= 250;
		var max1024			= 485;
		var max1280			= 750;
		var max1440			= 940;
		var max1680			= 1160;
		var k				= 1;
		//if (_browser.isIE6)
		//{
			for (var i=0; i<Images.length;i++)
			{
				outHeight 	= GetImageHeight(Images[i]);
				outWidth 	= GetImageWidth(Images[i]);
				if(clientWidth<800 && outWidth>max800)				// >150 -> 75				
					k = outWidth/max800;
				
				else if(clientWidth<=1024 && outWidth>max1024)		// >150 -> 75 ???
					k = outWidth/max1024;
				
				else if (clientWidth<=1280 && outWidth>max1280)		// >510 -> 483
					k = outWidth/max1280;
				
				else if (clientWidth<=1440 && outWidth>max1440)		// >510 -> 483
					k = outWidth/max1440;
				
				else if (clientWidth<=1680 && outWidth>max1680)		// >510 -> 483
					k = outWidth/max1680;
				
				if(k!=1)
				{
					Images[i].width 	= outWidth/k;
					Images[i].height 	= outHeight/k;
				}
			}
		//}	
		return true;
	};
	
	function ChangeLanguageCountry(lang_id,country)
	{
		var str = document.location.href;
		str = str.replace(/lang=[\w]+/gi, '');
		str = str.replace(/&country=(\d)*/gi, '');
		str = str.replace(/&$/gi, '');
		str = str.replace(/\?$/gi, '');
		if (str.indexOf("?") > -1 || str.indexOf("action") != -1)
		{
			window.location=str+'&lang='+lang_id+'&country='+country;
		}
		else
		{
			window.location='?lang='+lang_id+'&country='+country;
		}
		
		return false;
	}