var citylink = {
		
		jsPath:		'http://vip.karelia.pro/check.js',
		cookieName: 'citylink',
		cookieExp: 	60,
		cookiePath: '/',
		useCookie: false,
		setCookie: 	function(CookieName, CookieVal, CookieExp, CookiePath, CookieDomain, CookieSecure)
					{
						var CookieText = escape(CookieName) + '=' + escape(CookieVal);
						
						if (CookieExp)
						{
							var date = new Date();
							
							date.setTime(date.getTime() + CookieExp * 1000); 
							CookieExp = date.toGMTString();
						}

						CookieText += (CookieExp ? '; EXPIRES=' + CookieExp : '');
						CookieText += (CookiePath ? '; PATH=' + CookiePath : '');
						CookieText += (CookieDomain ? '; DOMAIN=' + CookieDomain : '');
						CookieText += (CookieSecure ? '; SECURE' : '');

						document.cookie = CookieText;
					}, 
		getCookie: 	function(CookieName)
					{
						var CookieVal = null;

						if (document.cookie)
						{
							var CookieParts = document.cookie.split((escape(CookieName) + '=')); 

							if (CookieParts.length >= 2)
							{
								var CookieValues = CookieParts[1].split(';');

								CookieVal  = unescape(CookieValues[0]);
							}
						}

						return CookieVal;
					},						
	    createJS:   function()
	    			{
						if (document.createElement)
						{
							var span = document.createElement('span');
							
							span.style.display = 'none';

					        var script = document.createElement('script');

					        script.type = 'text/javascript';
					        script.src  = this.jsPath + '?nrnd=' + (100000 + Math.floor(Math.random() * 899999));
					        span.appendChild(script);
					        
					        var body = document.body;

					        body.insertBefore(span, body.firstChild);
					        
						}
	    			},
		init:       function()
					{
	    				var checkCookie = null;
	    				
	    				if (this.useCookie)
	    					checkCookie = this.getCookie(this.cookieName);
	    				
	    				if (checkCookie == null)
	    				{	
	    					this.createJS();
	    					
	    					if (this.useCookie)
	    						this.setCookie(this.cookieName, 1, this.cookieExp, this.cookiePath);
	    				}
					}
};

citylink.init();

