var _cauti_logo = {
	domain : 'cauti.ro',
	protocol : 'http',
	ref : '',
	merchant_id : -1,
	merchant_slug: '',
	type : 1,
	keywork: '',
	init : function (settings) {
		this.protocol = document.location.protocol == 'https:' ? 'https' : 'http';
		this.url = document.URL;
		
		if (document.referrer) {
			var m = document.referrer.match('^(http|https):\\/\\/([a-z0-9\\-\\.]+)(.*)$');
			
			if (m && m.length > 2) {
				this.ref = m[2];
			}
		}
		
		if (settings) {
			if (settings.merchant_id) {
				this.merchant_id = settings.merchant_id;
			}/* else {
				this.merchant_id = typeof cauti_client != 'undefined' ? cauti_client : -1;
			}*/
			if (settings.type) {
				this.type = settings.type;
			} else {
				this.type = typeof cauti_logo != 'undefined' ? 1 : 1;
			}
			if (settings.merchant_slug) {
				this.merchant_slug = settings.merchant_slug;
			}
			if (settings.keyword) {
				this.keyword = settings.keyword;
			}
		}
	},
	output : function () {
		var keyword_filter = '';
		if (this.keyword) {
			keyword_filter = '/keyword~~' + this.keyword;
		}
		var merchant_filter = '';
		if (this.merchant_slug) {
			merchant_filter = '/merchant~~' + this.merchant_slug;
		}
		var a = document.createElement('a');
		a.href = this.protocol + '://www.' + this.domain + '/produse/compara-preturi' + merchant_filter + keyword_filter + '.html';
		a.target = '_blank';
		a.title = 'Cauti.ro - comparatii preturi produse';
		
		switch (this.type) {
			case 1:
			case 2:
			default: {
				var img = document.createElement('img');
				img.src = this.protocol + '://logo.' + this.domain + '/img/logo_' + this.type + '.png?'
					+ 'merchant_id=' + this.merchant_id
					+ '&url=' + encodeURIComponent(this.url)
					+ '&ref=' + encodeURIComponent(this.ref);
				img.alt = 'cauti.ro';
				a.appendChild(img);
				break;
			}
			case 3: {
				var span = document.createElement('span');
				span.innerHTML = 'Partener Cauti.ro';
				
				var img = document.createElement('img');
				img.src = this.protocol + '://logo.' + this.domain + '/img/logo_' + this.type + '.png?'
					+ 'merchant_id=' + this.merchant_id
					+ '&url=' + encodeURIComponent(this.url)
					+ '&ref=' + encodeURIComponent(this.ref);
				
				a.appendChild(span);
				a.appendChild(img);
				break;
			}
		}
		
		var parent = document.getElementById('cautiro-logo-container');
		if (!parent) {
			document.write('<div id="cautiro-logo-container"></div>');
			parent = document.getElementById('cautiro-logo-container');
		}
		parent.appendChild(a);
	}
};
var _cauti_logo_settings = _cauti_logo_settings || {};
_cauti_logo.init(_cauti_logo_settings);
_cauti_logo.output();

