function editname() {
	document.getElementById('preview').getElementsByTagName('h3')[0].firstChild.nodeValue=document.tellafriend.tellmail_name.value+" "+invitedata;
}

function editcomment() {
	document.getElementById('preview').getElementsByTagName('p')[0].firstChild.nodeValue=document.tellafriend.tellmail_comment.value;
}

function getBrowserHeight(){
	if (window.innerHeight){
		return window.innerHeight;}	
	else if (document.documentElement && document.documentElement.clientHeight != 0){
		return document.documentElement.clientHeight;	}
	else if (document.body){return document.body.clientHeight;}		
		return 0;
}

function addfriend () {
	
	if(i==0) {
	ccinput=document.createElement('input');	 				
	ccinput.setAttribute("type","hidden");
	ccinput.setAttribute("name","tellmail_friendcounter");
	ccinput.setAttribute("value",i);
	document.getElementById('friend').appendChild(ccinput);	
	} else {
	document.tellafriend.tellmail_friendcounter.value=i+1;
	}
	this["newp"+i]=document.createElement('p');
	newtext=document.createTextNode("Friend's e-mail");
	this["newp"+i].newlabel=document.createElement('label');
	this["newp"+i].newlabel.setAttribute("for","tellmail_friend"+i);
	this["newp"+i].newinput=document.createElement('input');	 				
	this["newp"+i].newinput.setAttribute("type","text");
	this["newp"+i].newinput.setAttribute("name","tellmail_friend"+i);
	this["newp"+i].newinput.setAttribute("id","tellmail_friend"+i);
	this["newp"+i].i=i;
	this["newp"+i].newlabel.appendChild(newtext);
	this["newp"+i].appendChild(this["newp"+i].newlabel);
	this["newp"+i].appendChild(this["newp"+i].newinput);
	document.getElementById('friend').appendChild(this['newp'+i]);
	i++;
	
}

function delfriend () {
	this["newp"+i].removeChild(this["newp"+i].newinput);
	this["newp"+i].removeChild(this["newp"+i].newlabel);
	i--;
}

function tellafriend() {
	document.tellafriend.tellmail_name.onkeyup=editname;
	document.tellafriend.tellmail_name.onblur=editname;
	document.tellafriend.tellmail_comment.onkeyup=editcomment;
	document.getElementById('addfriend').onclick=addfriend;
	document.getElementById('delfriend').onclick=delfriend;
}
window.onload=function () {
	if(document.getElementById('preview')) {
		if(! document.tellafriend.tellmail_friendcounter) {
			i=0;
		} else {
			i=document.tellafriend.tellmail_friendcounter.value;
		}
		invitedata=document.getElementById('preview').getElementsByTagName('h3')[0].firstChild.data;
		document.getElementById('preview').getElementsByTagName('h3')[0].firstChild.nodeValue=document.tellafriend.tellmail_name.value+" "+invitedata;
		document.getElementById('preview').getElementsByTagName('p')[0].firstChild.nodeValue=document.tellafriend.tellmail_comment.value;
		tellafriend(); 
	}	
}
