function modPreview() {

	var f = document.forms.moduleForm;

	if(!checkReg()) { return false; }
	if(!checkTOU(f)) { return false; }

	// general form values
	var layout;
	if(f.elements['layout'][0].checked) { layout='v'; } else { layout='h'; }
	var ccm_hs = f.elements['ccm_hs'].options[f.elements['ccm_hs'].selectedIndex].value;
	var ccm_lj = f.elements['ccm_lj'].checked?1:0;
	var ccm_myspace = f.elements['ccm_myspace'].checked?1:0;

	//
	// make code
	//
	var c_start = '';
	var c_end = '';
	if(!ccm_myspace) {
		c_start = '<!-- // Begin Current Moon Phase HTML (c) MoonConnection.com // -->';
		c_end = '<!-- // end moon phase HTML // -->';
	}
	
	var str = '';
	if(layout=='v') {
		if(ccm_lj) {
			str = '<table cellpadding="0" cellspacing="0" border="0" width="130"><tr><td align="center"><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="196" border="0" alt="" /></td><td background="http://www.moonmodule.com/cs/dm/v'+ccm_hs+'.gif" valign="bottom" align="center"><a href="http://www.moonconnection.com/current_moon_phase.phtml" target="mc_moon_ph"><img src="http://www.moonmodule.com/cs/dm/s.gif" width="128" height="150" border="0" alt="" /></a><table cellpadding="0" cellspacing="0" border="0" width="120" height="20"><tr><td align="center" bgcolor="#000000"><a href="'+cc_base_url+link_page+'" target="mc_moon_ph"><font color="#7F7F7F" size="1" face="arial,helvetica,sans-serif"><span style="color:#7F7F7F;font-family:arial,helvetica,sans-serif;font-size:10px;">'+link_text+'</span></font></a></td></tr></table><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="4" border="0" alt="" /></td><td><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="196" border="0" alt="" /></td></tr></table>';
		} else {
			str = '<table cellpadding="0" cellspacing="0" border="0" width="128"><tr><td align="center"><a href="http://www.moonconnection.com/current_moon_phase.phtml" target="mc_moon_ph"><img src="http://www.moonmodule.com/cs/dm/v'+ccm_hs+'.gif" width="128" height="196" border="0" alt="" /></a><div style="position:relative;width:128px;"><div style="position:absolute;top:-20px;left:6px;background:#000000;width:116px;text-align:center;"><a href="'+cc_base_url+link_page+'" target="mc_moon_ph"><font color="#7F7F7F" size="1" face="arial,helvetica,sans-serif"><span style="color:#7F7F7F;font-family:arial,helvetica,sans-serif;font-size:10px;">'+link_text+'</span></font></a></div></div></td></tr></table>';
		}
	} else if(layout=='h') {
		if(ccm_lj) {
			str = '<table cellpadding="0" cellspacing="0" border="0" width="214"><tr><td align="center"><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="136" border="0" alt="" /></td><td background="http://www.moonmodule.com/cs/dm/h'+ccm_hs+'.gif" valign="bottom" align="center"><a href="http://www.moonconnection.com/current_moon_phase.phtml" target="mc_moon_ph"><img src="http://www.moonmodule.com/cs/dm/s.gif" width="212" height="90" border="0" alt="" /></a><table cellpadding="0" cellspacing="0" border="0" width="204" height="20"><tr><td align="center" bgcolor="#000000"><a href="'+cc_base_url+link_page+'" target="mc_moon_ph"><font color="#7F7F7F" size="1" face="arial,helvetica,sans-serif"><span style="color:#7F7F7F;font-family:arial,helvetica,sans-serif;font-size:10px;">'+link_text+'</span></font></a></td></tr></table><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="4" border="0" alt="" /></td><td><img src="http://www.moonmodule.com/cs/dm/s.gif" width="1" height="136" border="0" alt="" /></td></tr></table>';
		} else {
			str = '<table cellpadding="0" cellspacing="0" border="0" width="212"><tr><td align="center"><a href="http://www.moonconnection.com/current_moon_phase.phtml" target="mc_moon_ph"><img src="http://www.moonmodule.com/cs/dm/h'+ccm_hs+'.gif" width="212" height="136" border="0" alt="" /></a><div style="position:relative;width:128px;"><div style="position:absolute;top:-20px;left:6px;background:#000000;width:116px;text-align:center;"><a href="'+cc_base_url+link_page+'" target="mc_moon_ph"><font color="#7F7F7F" size="1" face="arial,helvetica,sans-serif"><span style="color:#7F7F7F;font-family:arial,helvetica,sans-serif;font-size:10px;">'+link_text+'</span></a></font></div></div></td></tr></table>';
		}
	} else { alert('Error: no layout chosen. Contact us if you continue to get this message.'); }

	document.getElementById('module_preview').innerHTML = str;
	f.elements['module_html'].value = (ccm_myspace?str:c_start+str+c_end);

	return;
}

function textarea_ready(s) {
	s = s.replace('&','&amp;');
	s = s.replace('<','&lt;');
	s = s.replace('>','&gt;');
	return s;
}
function checkTOU(f) {
	if(!f.tou.checked) {
		alert( "Before using this module, you must read and agree to the Copyright/Terms of Use.\nPlease check the \"I have read and agree...\" checkbox.\n" );
		return false;
	}
	return true;
}
function checkReg() {
	if(rok) { return true; }
	var rC = new Cookie(document,"MoonConnection");
	rC.load();
	if(rC.registered_module_user) { return true; }
	var x = confirm("Please register first. The registration form is back on the original moon module page. If you have already registered, you can also sign in on that page. Would you like to go there now? If so, click OK.");
	if(x) {
		location.href = 'moon_module.phtml#register';
	}
	return false;
}