	
	function onLoadFunction()
	{
		//	if old browser case...
		if (!document.getElementById) {
			location.href = "browser.php";
		}
		//	While Firefox does not reset on reload...
		document.getElementById('option').value=0;
		resetAll();
	}
	
	function changeSelector()
	{
		//	load content selector
		switch (document.getElementById('option').value)
		{
			case '1':
				document.getElementById('selector').innerHTML = 'Učitavanje...&nbsp;<img src="/global/img/loader.gif">';
				updateElement('selector', 'topicSelector.php', true);
				break;
			case '2':
				document.getElementById('selector').innerHTML = 'Učitavanje...&nbsp;<img src="/global/img/loader.gif">';
				updateElement('selector', 'customSelector.php', true);
				break;
			default:
				document.getElementById('selector').innerHTML = '';
		}
		//	clear content
		document.getElementById('content').innerHTML = '';
	}
	
	function changeContent()
	{
		//	if topic is undefined...
		if (document.getElementById('topic') && document.getElementById('topic').value === 0) {
			document.getElementById('content').innerHTML = '';
			return;
		}
		//	loads previews
		switch (document.getElementById('option').value)
		{
			case '1':
				URL = 'topicContent.php?id=' + document.getElementById('topic').value + setQuery();
				break;
			case '2':
				URL = 'customContent.php?query=' + encodeURI(document.getElementById('query').value) + setQuery();
				break;
			default:
				return;
		}
		document.getElementById('content').innerHTML = 'Učitavanje...&nbsp;<img src="/global/img/loader.gif">';
		updateElement('content', URL, true);
	}
	
	function setQuery()
	{
		//	set fields selection
		newsFields = '&fields='+
					 document.getElementById('summaryShow').value+
					 document.getElementById('titlesShow' ).value+
					 document.getElementById('sourcesShow').value;
		
		//	set http query extension
		HttpQuery  = '&limit='  + document.getElementById('limit' ).value+
					 '&image='  + document.getElementById('image' ).value+
					 '&target=' + document.getElementById('target').value+
					 newsFields;
					 
		//	return HTTP query string
		return HttpQuery;
	}
	
	function changeLayout()
	{
		//	set empty rules array
		var theRules = [];
		
		//	set styleSheet rules
		if (document.styleSheets[0].cssRules) {
			theRules = document.styleSheets[0].cssRules;
		} else if (document.styleSheets[0].rules) {
			theRules = document.styleSheets[0].rules;
		} else {
			return;
		}
		//	set rules
		theRules[0].style.fontFamily = document.getElementById('font' ).value;
		theRules[0].style.textAlign  = document.getElementById('text' ).value;
		theRules[0].style.paddingTop = document.getElementById('space').value + 'px';
		theRules[0].style.backgroundColor = document.getElementById('bgColor').value;

		//	set font size rules
		theRules[ 1].style.fontSize = document.getElementById('titleSize'  ).value + 'px';
		theRules[ 5].style.fontSize = document.getElementById('sourceSize' ).value + 'px';
		theRules[ 6].style.fontSize = document.getElementById('timeSize'   ).value + 'px';
		theRules[ 7].style.fontSize = document.getElementById('summarySize').value + 'px';
		theRules[ 8].style.fontSize = document.getElementById('titlesSize' ).value + 'px';
		theRules[12].style.fontSize = document.getElementById('sourcesSize').value + 'px';
		theRules[16].style.fontSize = document.getElementById('relatedSize').value + 'px';
		theRules[20].style.fontSize = document.getElementById('captionSize').value + 'px';
		
		//	set font weight options
		fontWeights = [];
		fontWeights[false] = 'normal';
		fontWeights[true ] = 'bold';
		
		//	set font weight rules
		theRules[ 1].style.fontWeight = fontWeights[document.getElementById('titleBold'  ).checked];
		theRules[ 5].style.fontWeight = fontWeights[document.getElementById('sourceBold' ).checked];
		theRules[ 6].style.fontWeight = fontWeights[document.getElementById('timeBold'   ).checked];
		theRules[ 7].style.fontWeight = fontWeights[document.getElementById('summaryBold').checked];
		theRules[ 8].style.fontWeight = fontWeights[document.getElementById('titlesBold' ).checked];
		theRules[12].style.fontWeight = fontWeights[document.getElementById('sourcesBold').checked];
		theRules[16].style.fontWeight = fontWeights[document.getElementById('relatedBold').checked];
		theRules[20].style.fontWeight = fontWeights[document.getElementById('captionBold').checked];
		
		//	set font style options
		fontStyles  = [];
		fontStyles[false] = 'normal';
		fontStyles[true ] = 'italic';
		
		//	set font style rules
		theRules[ 1].style.fontStyle = fontStyles[document.getElementById('titleItalic'  ).checked];
		theRules[ 5].style.fontStyle = fontStyles[document.getElementById('sourceItalic' ).checked];
		theRules[ 6].style.fontStyle = fontStyles[document.getElementById('timeItalic'   ).checked];
		theRules[ 7].style.fontStyle = fontStyles[document.getElementById('summaryItalic').checked];
		theRules[ 8].style.fontStyle = fontStyles[document.getElementById('titlesItalic' ).checked];
		theRules[12].style.fontStyle = fontStyles[document.getElementById('sourcesItalic').checked];
		theRules[16].style.fontStyle = fontStyles[document.getElementById('relatedItalic').checked];
		theRules[20].style.fontStyle = fontStyles[document.getElementById('captionItalic').checked];
	
		//	set font color rules
		theRules[ 2].style.color = document.getElementById('titleColor'  ).value;
		theRules[ 3].style.color = document.getElementById('titleColor'  ).value;
		theRules[ 4].style.color = document.getElementById('titleColor'  ).value;
		theRules[ 5].style.color = document.getElementById('sourceColor' ).value;
		theRules[ 6].style.color = document.getElementById('timeColor'   ).value;
		theRules[ 7].style.color = document.getElementById('summaryColor').value;
		theRules[ 8].style.color = document.getElementById('sourceColor' ).value;
		theRules[ 9].style.color = document.getElementById('titlesColor' ).value;
		theRules[10].style.color = document.getElementById('titlesColor' ).value;
		theRules[11].style.color = document.getElementById('titlesColor' ).value;
		theRules[12].style.color = document.getElementById('summaryColor').value;
		theRules[13].style.color = document.getElementById('sourcesColor').value;
		theRules[14].style.color = document.getElementById('sourcesColor').value;
		theRules[15].style.color = document.getElementById('sourcesColor').value;
		theRules[17].style.color = document.getElementById('relatedColor').value;
		theRules[18].style.color = document.getElementById('relatedColor').value;
		theRules[19].style.color = document.getElementById('relatedColor').value;
		theRules[21].style.color = document.getElementById('captionColor').value;
		theRules[22].style.color = document.getElementById('captionColor').value;
		theRules[23].style.color = document.getElementById('captionColor').value;
	
		//	set color buttons
		document.getElementById('bgButton'     ).style.backgroundColor = document.getElementById('bgColor'     ).value;
		document.getElementById('titleButton'  ).style.backgroundColor = document.getElementById('titleColor'  ).value;
		document.getElementById('sourceButton' ).style.backgroundColor = document.getElementById('sourceColor' ).value;
		document.getElementById('timeButton'   ).style.backgroundColor = document.getElementById('timeColor'   ).value;
		document.getElementById('summaryButton').style.backgroundColor = document.getElementById('summaryColor').value;
		document.getElementById('sourceButton' ).style.backgroundColor = document.getElementById('sourceColor' ).value;
		document.getElementById('titlesButton' ).style.backgroundColor = document.getElementById('titlesColor' ).value;
		document.getElementById('summaryButton').style.backgroundColor = document.getElementById('summaryColor').value;
		document.getElementById('sourcesButton').style.backgroundColor = document.getElementById('sourcesColor').value;
		document.getElementById('relatedButton').style.backgroundColor = document.getElementById('relatedColor').value;
		document.getElementById('captionButton').style.backgroundColor = document.getElementById('captionColor').value;
		
		//	hide code form
		if (document.getElementById('codeForm')) {
			hideCode();
		}
	}
	
	function showCode()
	{
		//	set empty rules array
		theRules = [];
		
		//	set styleSheet rules
		if (document.styleSheets[0].cssRules) {
			theRules = document.styleSheets[0].cssRules;
		} else if (document.styleSheets[0].rules) {
			theRules = document.styleSheets[0].rules;
		} else {
			return;
		}
		//	set empty style strings
		summaryStyle = '';
		titlesStyle  = '';
		sourcesStyle = '';
		
		if (document.getElementById('summaryShow').value == 1) {
			summaryStyle =	".mondopressSummary {"+
								"font-size: "+theRules[7].style.fontSize+"; "+
								"color: "+theRules[7].style.color+"; "+
								"font-weight: "+theRules[7].style.fontWeight+"; "+
								"font-style: "+theRules[7].style.fontStyle+";}\n";
		}
		if (document.getElementById('titlesShow' ).value == 1) {
			titlesStyle =	".mondopressTitles {"+
								"font-size: "+theRules[8].style.fontSize+"; "+
								"color: "+theRules[8].style.color+"; "+
								"font-weight: "+theRules[8].style.fontWeight+"; "+
								"font-style: "+theRules[8].style.fontStyle+";}\n"+
							"a.mondopressTitles:link {color: "+theRules[9].style.color+"; text-decoration: underline;}\n"+
							"a.mondopressTitles:active {color: "+theRules[10].style.color+"; text-decoration: underline;}\n"+
							"a.mondopressTitles:visited {color: "+theRules[11].style.color+"; text-decoration: underline;}\n";
		}
		if (document.getElementById('sourcesShow').value == 1) {
			sourcesStyle =	".mondopressSources {"+
								"font-size: "+theRules[12].style.fontSize+"; "+
								"color: "+theRules[12].style.color+"; "+
								"font-weight: "+theRules[12].style.fontWeight+"; "+
								"font-style: "+theRules[12].style.fontStyle+";}\n"+
							"a.mondopressSources:link {color: "+theRules[13].style.color+"; text-decoration: underline;}\n"+
							"a.mondopressSources:active {color: "+theRules[14].style.color+"; text-decoration: underline;}\n"+
							"a.mondopressSources:visited {color: "+theRules[15].style.color+"; text-decoration: underline;}\n";
		}
		
		userStyle =	"<style type=\"text/css\"><!--\n"+
					"div.mondopressStory {"+
						"font-family: "+theRules[0].style.fontFamily+"; "+
						"text-align: "+theRules[0].style.textAlign+"; "+
						"padding-top: "+theRules[0].style.paddingTop+"; "+
						"background-color: "+theRules[0].style.backgroundColor+"; "+
						"text-decoration: none;}\n"+
					".mondopressTitle {"+
						"font-size: "+theRules[1].style.fontSize+"; "+
						"font-weight: "+theRules[1].style.fontWeight+"; "+
						"font-style: "+theRules[1].style.fontStyle+";}\n"+
					"a.mondopressTitle:link {color: "+theRules[2].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressTitle:active {color: "+theRules[3].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressTitle:visited {color: "+theRules[4].style.color+"; text-decoration: underline;}\n"+
					".mondopressSource {"+
						"font-size: "+theRules[5].style.fontSize+"; "+
						"color: "+theRules[5].style.color+"; "+
						"font-weight: "+theRules[5].style.fontWeight+"; "+
						"font-style: "+theRules[5].style.fontStyle+";}\n"+
					".mondopressTime {"+
						"font-size: "+theRules[6].style.fontSize+"; "+
						"color: "+theRules[6].style.color+"; "+
						"font-weight: "+theRules[6].style.fontWeight+"; "+
						"font-style: "+theRules[6].style.fontStyle+";}\n"+
					summaryStyle+
					titlesStyle+
					sourcesStyle+
					".mondopressRelated {"+
						"font-size: "+theRules[16].style.fontSize+"; "+
						"font-weight: "+theRules[16].style.fontWeight+"; "+
						"font-style: "+theRules[16].style.fontStyle+";}\n"+
					"a.mondopressRelated:link {color: "+theRules[17].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressRelated:active {color: "+theRules[18].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressRelated:visited {color: "+theRules[19].style.color+"; text-decoration: underline;}\n"+
					".mondopressCaption {"+
						"font-size: "+theRules[20].style.fontSize+"; "+
						"font-weight: "+theRules[20].style.fontWeight+"; "+
						"font-style: "+theRules[20].style.fontStyle+";}\n"+
					"a.mondopressCaption:link {color: "+theRules[21].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressCaption:active {color: "+theRules[22].style.color+"; text-decoration: underline;}\n"+
					"a.mondopressCaption:visited {color: "+theRules[23].style.color+"; text-decoration: underline;}"+
					"\n--></style>\n";
					
		//	set URL
		switch(document.getElementById('option').value)
		{
			case '1':
				widgetURL = 'http://www.mondopress.com/widgets/topic.php?id=' + document.getElementById('topic').value + setQuery();
				htmlURL = 'http://www.mondopress.com/category.php?id=' + document.getElementById('topic').value;
				break;
			case '2':
				widgetURL = 'http://www.mondopress.com/widgets/custom.php?query=' + encodeURI(document.getElementById('query').value) + setQuery();
				htmlURL = 'http://www.mondopress.com/search.php?query=' + encodeURI(document.getElementById('query').value);
				break;
			default:
				alert('Invalid filter option selection.');
		}
		//	set user code
		userCode =	"<!-- START OF MONDOPRESS.COM WIDGET -->\n"+
					userStyle+
					'<script language="javascript" type="text/javascript" src="'+widgetURL+'"></script>'+"\n"+
					"<noscript>"+
					'<div style="padding:10px;text-align:center;">'+
						'<a href="'+htmlURL+'">'+
							'NAJNOVIJE VIJESTI<br><img src="http://www.mondopress.com/global/img/byMondopress.gif" alt="MondoPress" border="no">'+
						'</a>'+
					"</div>"+
					"</noscript>\n"+
					"<!-- END OF MONDOPRESS.COM WIDGET -->\n";
					
		//	set code display
		document.getElementById('codeForm').style.height = '258px';
		document.getElementById('codeForm').innerHTML = '<div id="codeDiv"><div style="padding-bottom:5px;color:green"><b>Umetnite ovaj JavaScript kod u HTML kod vaše web stranice:</b></div><textarea id="codeArea"></textarea></div>';
		document.getElementById('codeArea').value = userCode;
		
		//	change caption + onClick function of code button
		codeButton = document.getElementById('codeButton');
		codeButton.value = 'Sakrij kod za moju web stranicu';
		codeButton.onclick = function() { hideCode(); };
	}
	
	function hideCode()
	{
		//	change caption + onClick function of code button
		document.getElementById('codeForm').innerHTML = '';
		document.getElementById('codeForm').style.height = '0px';
		codeButton = document.getElementById('codeButton');
		codeButton.value = 'Pokaži kod za moju web stranicu';
		codeButton.onclick = function() { showCode(); };
	}
	
	function resetAll()
	{
		//	reset basics
		document.getElementById('font'   ).value = 'Arial, Helvetica, sans-serif';
		document.getElementById('limit'  ).value = 10;
		document.getElementById('text'   ).value = 'left';
		document.getElementById('image'  ).value = 'left';
		document.getElementById('space'  ).value = 10;
		document.getElementById('target' ).value = 'blank';
		document.getElementById('bgColor').value = '#FFFFFF';
		document.getElementById('summaryShow').value = 1;
		document.getElementById('titlesShow' ).value = 1;
		document.getElementById('sourcesShow').value = 1;
		
		//reset fonts
		document.getElementById('titleSize'  ).value = 16;
		document.getElementById('sourceSize' ).value = 12;
		document.getElementById('timeSize'   ).value = 12;
		document.getElementById('summarySize').value = 12;
		document.getElementById('titlesSize' ).value = 12;
		document.getElementById('sourcesSize').value = 12;
		document.getElementById('relatedSize').value = 12;
		document.getElementById('captionSize').value = 10;
		
		document.getElementById('titleColor'  ).value = '#003366';
		document.getElementById('sourceColor' ).value = '#696969';
		document.getElementById('timeColor'   ).value = '#333333';
		document.getElementById('summaryColor').value = '#333333';
		document.getElementById('titlesColor' ).value = '#003366';
		document.getElementById('sourcesColor').value = '#CC0000';
		document.getElementById('relatedColor').value = '#CC0000';
		document.getElementById('captionColor').value = '#003366';
		
		document.getElementById('titleBold'  ).checked = true;
		document.getElementById('sourceBold' ).checked = true;
		document.getElementById('timeBold'   ).checked = true;
		document.getElementById('summaryBold').checked = false;
		document.getElementById('titlesBold' ).checked = false;
		document.getElementById('sourcesBold').checked = false;
		document.getElementById('relatedBold').checked = true;
		document.getElementById('captionBold').checked = false;
		
		document.getElementById('titleItalic'  ).checked = false;
		document.getElementById('sourceItalic' ).checked = false;
		document.getElementById('timeItalic'   ).checked = false;
		document.getElementById('summaryItalic').checked = false;
		document.getElementById('titlesItalic' ).checked = false;
		document.getElementById('sourcesItalic').checked = false;
		document.getElementById('relatedItalic').checked = false;
		document.getElementById('captionItalic').checked = false;

		changeLayout();
		changeContent();
	}
	
	function updateElement(elementId, URL, option)
	{
		//	URL not defined case
		if (URL === '') {
			document.getElementById(elementId).innerHTML = '';
			return;
		}
		//	Firefox, Opera 8.0+, Safari
		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch(e)
		{
			//	Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					alert("Your browser does not support AJAX!");
					return;
				}
			}
		}
		
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4) {
				document.getElementById(elementId).innerHTML = xmlHttp.responseText;
			}
		};
		xmlHttp.open("GET", URL, true);
		xmlHttp.send(null);
	}
