//proccessDcInformer();

function dcInformer() {
	
	this.getIncHost = function() {
		return "www.dc-market.ru";
	}
	
	this.getHost = function() {
		var host = window.location.hostname;
		if(host) {
			host = host.toLowerCase();
			if(host.indexOf("www.") == 0)
				host = host.substring(4);
			if(host.indexOf(".sasta") == host.length - 6) {
				host = host.substring(0,host.indexOf(".sasta")) + ".ru";
			}
		}
		return escape(host);	
	}
	
	this.getURL = function() {
		var url = window.location.href;
		return escape(url);
	}
	
	this.getParametr = function( param ) {
		var result = "";
		var currScript = this.getCurrentScript();
		if(currScript) {
			try {
				var src = currScript.src;
				var pos = src.indexOf(param + "=");
				if(pos > 0) {
					result = src.substring(pos + param.length + 1);
				
					pos = result.indexOf("&");
					if(pos > 0)
						result = result.substring(0,pos);
				}
			}
			catch(e){}
		}
		
		return result;
	}
	
	this.getArticle = function() {
		return escape(this.getParametr("article"));
	}
	
	this.getCity = function() {
		return escape(this.getParametr("city"));
	}
	
	this.getCurrentScript = function() {
		return document.getElementById("dcInformer");
	}
	
	
	
 	this.addStyleScript = function() {
		var script = document.createElement('SCRIPT');

		script.setAttribute("language","JavaScript");
		script.setAttribute("type","text/javascript");
		script.setAttribute("src","http://" + this.getIncHost() + "/informer/style.js");
		document.getElementsByTagName('HEAD')[0].appendChild(script);
	}
	
	var cssLoadTrys = 0;
	this.loadCSS = function() {
		if(typeof(getStyleFactoryInstance) != "undefined") {
			var factory = getStyleFactoryInstance(document);
			factory.loadStyleSheet("http://" + this.getIncHost() + "/informer/dcstyle.css");
		}
		else {
			if(cssLoadTrys++ < 50)
				setTimeout("dcInformerImpl.loadCSS()",100);
		}
	}
	
	this.proccess = function() {
		this.addStyleScript();
		this.loadCSS();
		var host = this.getHost();
		var url = this.getURL();
		var article = this.getArticle();
		var city = this.getCity();
		if(host == "" || url == "" || article == "")
			return;
	
		var scriptLanguage = "JavaScript";
		var scriptType = "text/javascript";
		var scriptSrc = "http://" + this.getIncHost() + "/informer/get-instance-action.do?host=" + host + "&url=" + url + "&article=" + article +
				(city != "" ? ("&city=" + city) : "");
		document.write("<script language=\"" + scriptLanguage + "\" src=\"" + scriptSrc + "\" type=\"" + scriptType + "\"></script>");
	}
	
}

var dcInformerImpl = new dcInformer();
dcInformerImpl.proccess();
