function getCode () {
	if (!document.getElementById) return;
	
	hs="<!-- Insert this part into HEAD section (between <head>...</head> tags) of the HTML -->";
	he="<!-- End of the HEAD section -->\n\n";
	bs="<!-- Insert this part into BODY section (between <body>...</body> tags) of the HTML, where you want to show news feed -->";
	be="<!-- End of the BODY section -->\n\n";

	m=document.getElementById('imedia').options[document.getElementById('imedia').selectedIndex].value;
	h=document.getElementById('iheadings').options[document.getElementById('iheadings').selectedIndex].value;
	s=document.getElementById('istyle').options[document.getElementById('istyle').selectedIndex].value;
	t=document.getElementById('itype').options[document.getElementById('itype').selectedIndex].value;

	a=document.getElementById('iannotation').checked?'full':'compact'
	l = m.substring(m.indexOf('_')+1, m.length);
	m = m.substring(0, m.indexOf('_'));

	ret = '';
//get style string
	ret += hs + getStyle() + he;

//http://www.armtown.com/jsf/en/a1p/most/compact/15
	src = "<script language=\"javascript\" src=\"http://www.armtown.com/jsf/" + l + '/' + (m?m + '/':'') + (t?t + '/':'') + a + '/' + (h?h + '/':'') + "\"><"+"/script>"
	ret += bs + "\n" + src + "\n" + be;

//	alert(ret);
	return (ret);
}

function setStyle() {
	if (!document.getElementById) return;
	getStyle();
	tdiv = document.getElementById('armtown_newsbox');
	tdiv.style.cssText = document.getElementById('idiv').value;
	tul = tdiv.getElementsByTagName('UL')[0];
	tul.style.cssText = document.getElementById('iul').value;

	tli = tul.getElementsByTagName('LI')
	for (i=0;i<tli.length;i++ ) {
		tli[i].style.cssText = document.getElementById('ili').value;
		tlia = tli[i].getElementsByTagName('A')[0].style.cssText = document.getElementById('ilia').value;
	}
	tdiv.getElementsByTagName('P')[0].getElementsByTagName('A')[0].style.cssText = document.getElementById('ipa').value;
}

function getStyle() {
	if (!document.getElementById) return;
	cbox = document.getElementById('cfields');
	sty = document.getElementById('istyle');

	tdiv=document.getElementById('idiv');
	tul=document.getElementById('iul');
	tli=document.getElementById('ili');
	tlia=document.getElementById('ilia');
	tpa=document.getElementById('ipa');

	if (sty.options[sty.selectedIndex].value == 10) {
		if(cbox.style.display != "block") {
			tdiv.value = '';
			tul.value = '';
			tli.value = '';
			tlia.value = '';
			tpa.value = '';
		}
		cbox.style.display = "block";
	} else {
		cbox.style.display = "none";
		switch(sty.options[sty.selectedIndex].value) {
			case "1":
				tdiv.value = 'font-size: 90%; padding:0.5em';
				tul.value = 'list-style:circle; margin:3';
				tli.value = 'color:gray; padding:5px 0';
				tlia.value = 'color:black';
				tpa.value = 'font-size: 80%';
			break;
			case "2":
				tdiv.value = 'font-size: 90%; padding:0.5em';
				tul.value = 'list-style:square; margin:3';
				tli.value = 'padding:5px 0';
				tlia.value = 'font-weight:bold; font-style:italic';
				tpa.value = 'font-size: 80%';
			break;
			case "3":
				tdiv.value = 'font-size: 90%; padding:0.5em; border:1px solid blue';
				tul.value = 'list-style:none; padding:0';
				tli.value = 'padding:5px;';
				tlia.value = 'text-decoration:none';
				tpa.value = 'font-size: 80%';
			break;
			case "4":
				tdiv.value = 'font-size: 90%; padding:0.5em; border:1px solid green';
				tul.value = 'list-style:none; padding:0';
				tli.value = 'border-bottom:1px dotted gray; padding:5px';
				tlia.value = 'color:green; text-decoration:none';
				tpa.value = 'font-size: 80%';
			break;
			case "10":break;
			default:
				tdiv.value = '';
				tul.value = '';
				tli.value = '';
				tlia.value = '';
				tpa.value = '';
		}
	}

	return "\n<style>\ndiv.armtown_newsbox {" + tdiv.value + "}\ndiv.armtown_newsbox ul {" + tul.value + "}\ndiv.armtown_newsbox ul li {" + tli.value + "}\ndiv.armtown_newsbox ul li a {" + tlia.value + "}\ndiv.armtown_newsbox p a {" + tpa.value + "}\n</style>\n";
}


function setJsfSource() {
	m=document.getElementById('imedia').options[document.getElementById('imedia').selectedIndex].value;
	h=document.getElementById('iheadings').options[document.getElementById('iheadings').selectedIndex].value;
	t=document.getElementById('itype').options[document.getElementById('itype').selectedIndex].value;
	a=document.getElementById('iannotation').checked?'full':'compact';
	s=document.getElementById('istyle').options[document.getElementById('istyle').selectedIndex].value;

	setCookie("cmedia", m, 180,"/");
	setCookie("cheadings", h, 180,"/");
	setCookie("ctype", t, 180,"/");
	setCookie("cannotation", a, 180,"/");
	setCookie("cstyle", s, 180,"/");
	window.location.reload();
}


function getJsfSource() {
	med=document.getElementById('imedia');
	hed=document.getElementById('iheadings');
	typ=document.getElementById('itype');
	ant=document.getElementById('iannotation');
	sty=document.getElementById('istyle');

	setSelect('imedia', getCookie('cmedia'));
	setSelect('iheadings', getCookie('cheadings'));
	setSelect('itype', getCookie('ctype'));
	setSelect('istyle', '0');
	setCheck('iannotation', getCookie('cannotation'));

	m=med.options[med.selectedIndex].value;
	h=hed.options[hed.selectedIndex].value;
	t=typ.options[typ.selectedIndex].value;
	a=ant.checked?'full':'compact';
	s=sty.options[sty.selectedIndex].value;

	l = m.substring(m.indexOf('_')+1, m.length);
	m = m.substring(0, m.indexOf('_'));
	if (getCookie("cmedia")) {
		//alert('<script language="javascript" src="http://www.armtown.com/jsf/' + l + '/' + (m?m + '/':'') + (t?t + '/':'') + a + '/' + (h?h + '/':'') + '"><'+'/script>');
		return '<script language="javascript" src="http://www.armtown.com/jsf/' + l + '/' + (m?m + '/':'') + (t?t + '/':'') + a + '/' + (h?h + '/':'') + '"><'+'/script>';
	} else {
		return 'Please complete <b><i>Step 1</i></b> and click<br/>"Refresh Example"<ul><li><b>Source</b>: media name, which will be the source of JavaScript Feed.</li><li><b>Type</b>: "Regular news" is the list of latest news from our database. "Most read news" is the list of most read news for last 7 days.</li><li><b>Headlines</b>: number of headline in the feed. If it is "All" then all news for selected properties, which cant be more than 30 headlines.</li><li><b>Annotation</b>: check this option, if you like to provide a little description for each headline.</li></ul>In the <b><i>Step 2</i></b> you can choose the presentation style of JavaScript Feed. You can choose from several predefined styles or you can use your own style, when you choose "Custom" option.<ul><li><b>Style</b>: list of predefined styles.</li></ul>This options are available, if you choose "Custom" option in style menu.<ul><li><b>DIV</b>: container of JavaScript Feed. All changes here will be inherited in other levels.</li><li><b>UL</b>: list container. All changes here will be inherited in other levels except DIV.</li><li><b>LI</b>: list items (blocks of news headings). All changes here will be inherited in other levels except DIV and UL.</li><li><b>LI A</b>: links of news headlines. All changes here will affect only that links.</li><li><b>P A</b>: link of news source on the bottom of the feed. All changes here will affected only that link.</li></ul>In these fields you can use CSS style parameters only. For example you can put "list-style:none" in the UL field to suppress list bullets or put "color:red; text-decoration:none" in the LI A field to make headline links red, not underlined. You can do the same thing whit CSS selectors in the result code (code between &lt;style&gt;...&lt;/style&gt; tags).<br/><br/>After changing custom fields, click "Refresh Example" to see changes.<br/><br/>In <b><i>Step 3</i></b> click "Generate Code" and copy selected code from text field.';
	}

}

function setSelect(selid, val) {
	sel=document.getElementById(selid);

//walk trough options of select object and select option with val value
	for (i=0; i<sel.options.length; i++) {
		if (sel.options[i].value == val) {
			sel.selectedIndex = i
		}
	}
}

function setCheck(chkid, val) {
	chk=document.getElementById(chkid);

//check checkbox if val is 'full'
		if (val == 'full') {
			chk.checked = true
		} else {
			chk.checked = false
		}
}

function getHelp() {

	deleteCookie("cmedia", "/");
	deleteCookie("cheadings", "/");
	deleteCookie("ctype", "/");
	deleteCookie("cannotation", "/");
	deleteCookie("cstyle", "/");

	window.location.reload();
}

