var seePriceTypeWidget = {
	init: function (options) {
      	console.log("Initiate widget");
		
		var requestUrl = "//" + options.hostName + "/widget/pricetypes?hostname=" + options.hostName + "&eventid=" + options.eventId;
		if (options.affiliate != null) {
			requestUrl += "&aff=" + options.affiliate;
		}
      
        if (options.culture != null) {
			requestUrl += "&culture=" + options.culture;
		}

		var errorMsg = '<p class="see-error">There was an error. Please visit <a href="http://' + options.hostName + '/redirect/byshowcode/' + options.eventId + '">See Tickets</a> to book.</p>'
		var el = document.querySelector('#' + options.resultContainerId);
		if(window.XDomainRequest)
		{
			var xhr = new XDomainRequest();
			xhr.onload = function()
			{
				el.innerHTML = xhr.responseText;
			}
			xhr.error = function()
			{
				el.innerHTML = errorMsg;
			}
			xhr.timeout = function()
			{
				el.innerHTML = errorMsg;
			}
		}
		else
		{
			var xhr = new XMLHttpRequest();			
			xhr.onreadystatechange = function()
			{
				if(xhr.readyState === 4)
				{
					if(xhr.status == 200)
					{
						el.innerHTML = xhr.responseText;
					}
					else
					{
						el.innerHTML = errorMsg;
					}
				}
			}
		}
		
		xhr.open("GET", requestUrl);
		xhr.send();

		if (options.useDefaultStyle) {
			this.loadStyleSheet("//www.seetickets.com/Content/price-type-widget-css");
		}
	},	

	loadStyleSheet: function (url) {
		var styleSheetLink = document.createElement("link");

		styleSheetLink.rel = "stylesheet";
		styleSheetLink.type = "text/css";
		styleSheetLink.href = url;

		(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(styleSheetLink);
	}
}