
function addField(tForm, tName, tValue){
	var tField = document.createElement("input");
	with(tField){
		setAttribute("type", "hidden");
		setAttribute("name", tName);
		setAttribute("id", tName);
		setAttribute("value", tValue);
	};
	tForm.appendChild(tField);
}

function addForm(){
	var tForm = document.createElement("form");
	tForm.name = "TELLAFRIEND";
	tForm.id = "tempform";
	addField(tForm, 'SMSubject', 'Empfehlung...');
	addField(tForm, 'SMFromName', '');
	addField(tForm, 'SMFromMail', '');
	addField(tForm, 'SMToName', '');
	addField(tForm, 'SMToMail', '');
	addField(tForm, 'SMMessage', '');
	document.body.appendChild(tForm);
	document.getElementById('message').innerHTML = '<br><a href="' 
		+ opener.location.href + '"><strong>' 
		+ opener.document.title + '</strong></a><br><br>'
}

function buildMessage(oForm){
	sMessage = document.getElementById('salutation').innerHTML
		+ oForm.toname.value + ",<br>"
		+ document.getElementById('intro').innerHTML + '<br>'
		+ document.getElementById('message').innerHTML + '<br>'
		+ document.getElementById('regards').innerHTML + '<br>'
		+ oForm.fromname.value;
	return(sMessage);
};

function checkForm(oForm){
	if(oForm.frommail.value == 'Bitte geben Sie Ihre Email-Adresse ein!'){
		alert('!');
		oForm.frommail.focus();
		return(false);
	};
	if(oForm.tomail.value == ''){
		alert('Bitte geben Sie Ihre Email-Adresse des Empfängers ein!');
		oForm.tomail.focus();
		return(false);
	};

	document.getElementById('SMSubject').value = (document.getElementById('subject').innerHTML);
	document.getElementById('SMFromName').value = (oForm.fromname.value);
	document.getElementById('SMFromMail').value = (oForm.frommail.value);
	document.getElementById('SMToName').value = (oForm.toname.value);
	document.getElementById('SMToMail').value = (oForm.tomail.value);
	document.getElementById('SMMessage').value = (buildMessage(oForm));

	window.setTimeout("submitForm()", 100);

	return(false);
};

function submitForm(){
	var oForm = document.getElementById("tempform");
	if(oForm!=null) oForm.parentNode.removeChild(oForm);

	var tForm = document.createElement("form");
	with(tForm){
		setAttribute("target", "RED_TELLAFRIEND");
		setAttribute("method", "post");
		setAttribute("action", opener.SMBrokerURL);
	};

	var tBase = location.href.substring(0, location.href.lastIndexOf('\/'));
	addField(tForm, 'SMDatastring', opener.SX_esc(opener.Form2XML.encode(oForm).sys_xml(true)));
	addField(tForm, 'SMSuccessPage', opener.SX_esc(tBase + '/tellafriend_success.html'));
	addField(tForm, 'SMErrorPage', opener.SX_esc(tBase + '/tellafriend_error.html'));
	addField(tForm, 'SMCfgItems', opener.SMCfgItems);
	addField(tForm, 'SMColors', opener.SX_esc(opener.SMColors.documentElement.sys_xml(true)));
	addField(tForm, 'SMFonts', opener.SX_esc(opener.SMFonts.documentElement.sys_xml(true)));
	document.body.appendChild(tForm);
	tForm.submit();
};