function InsertElements(tag,choose,myform,elemnamea){
	var f=document.forms[myform].elements[elemnamea];
	var zhosz=tag.length+3;
	//alert(tag.length);
	if(choose=="2"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "[" + tag + "]" + f.value.substring(f.selectionStart,f.selectionEnd) + "[/" + tag + "]" + f.value.substring(f.selectionEnd,f.value.length) ;
			f.focus();
			f.selectionStart-=zhosz;
			f.selectionEnd=f.selectionStart; 
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "[" + tag + "]"  + "[/" + tag + "]" + f.value.substring(doGCP(f),f.value.length) ;
				f.focus();
				sel = document.selection.createRange();
				sel.move('character', - zhosz);
				sel.select();
			}
			else{
				document.selection.createRange().text = "[" + tag + "]" + document.selection.createRange().text + "[/" + tag + "]" ;
				f.focus();
				sel = document.selection.createRange();
				sel.move('character', - zhosz);
				sel.select();
			}	
		}
	}
	else if(choose=="1"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "[" + tag + "]" + f.value.substring(f.selectionStart,f.selectionEnd) + "" + f.value.substring(f.selectionEnd,f.value.length) 
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "[" + tag + "]"  + f.value.substring(doGCP(f),f.value.length) ;
		}
			else{	
				document.selection.createRange().text = "[" + tag + "]" + document.selection.createRange().text + "" ;
			}	
		}	
	}
	else if(choose=="3"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "[" + tag + "]" + f.value.substring(f.selectionStart,f.selectionEnd) + "" + f.value.substring(f.selectionEnd,f.value.length) 
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(document.myform.txtarea)) + "[" + tag + "]"  + f.value.substring(doGCP(document.myform.txtarea),f.value.length) ;
		}
			else{	
				document.selection.createRange().text = "[" + tag + "]" + document.selection.createRange().text + "" ;
			}	
		}	
	}
	else if(choose=="4"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "<" + tag + " align=justify >" + f.value.substring(f.selectionStart,f.selectionEnd) + "</" + tag + ">" + f.value.substring(f.selectionEnd,f.value.length) ;
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "<" + tag + " align=justify>"  + "</" + tag + ">" + f.value.substring(doGCP(f),f.value.length) ;
			}
			else{
				document.selection.createRange().text = "<" + tag + " align=justify>" + document.selection.createRange().text + "</" + tag + ">" ;
			}	
		}
	}
	else if(choose=="5"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "<" + tag + " align=center >" + f.value.substring(f.selectionStart,f.selectionEnd) + "</" + tag + ">" + f.value.substring(f.selectionEnd,f.value.length) ;
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "<" + tag + " align=center>"  + "</" + tag + ">" + f.value.substring(doGCP(f),f.value.length) ;
			}
			else{
				document.selection.createRange().text = "<" + tag + " align=center>" + document.selection.createRange().text + "</" + tag + ">" ;
			}	
		}
	}
	else if(choose=="6"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "<" + tag + " align=left >" + f.value.substring(f.selectionStart,f.selectionEnd) + "</" + tag + ">" + f.value.substring(f.selectionEnd,f.value.length) ;
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "<" + tag + " align=left>"  + "</" + tag + ">" + f.value.substring(doGCP(f),f.value.length) ;
			}
			else{
				document.selection.createRange().text = "<" + tag + " align=left>" + document.selection.createRange().text + "</" + tag + ">" ;
			}	
		}
	}
	else if(choose=="7"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart) + "<" + tag + " align=right >" + f.value.substring(f.selectionStart,f.selectionEnd) + "</" + tag + ">" + f.value.substring(f.selectionEnd,f.value.length) ;
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + "<" + tag + " align=right>"  + "</" + tag + ">" + f.value.substring(doGCP(f),f.value.length) ;
			}
			else{
				document.selection.createRange().text = "<" + tag + " align=right>" + document.selection.createRange().text + "</" + tag + ">" ;
			}	
		}
	}
	else if(choose=="8"){
		if (navigator.appName == "Netscape"){ 
			f.value = f.value.substring(0,f.selectionStart)+ " " + tag +  f.value.substring(f.selectionStart,f.selectionEnd) + " " + f.value.substring(f.selectionEnd,f.value.length) 
		}
		else{ 
			if(document.selection.createRange().text.length == "0"){
				f.value = f.value.substring(0,doGCP(f)) + tag  + f.value.substring(doGCP(f),f.value.length) ;
		}
			else{	
				document.selection.createRange().text = " " + tag + " " + document.selection.createRange().text + "" ;
			}	
		}	
	}
	getpreview();
}

function doGCP (ctrl){
	var CaretPos = 0;
	// IE miatt
	if (document.selection){
		ctrl.focus ();
		var Sel = document.selection.createRange ();
		Sel.moveStart ('character', -ctrl.value.length);
		CaretPos = Sel.text.length;
	}
	// Firefox firefox
	else if (ctrl.selectionStart || ctrl.selectionStart == '0')
		CaretPos = ctrl.selectionStart;
	return (CaretPos);
}


function InsertLink(control,formname){
	window.open('inc/insert_link.php?control='+ control +'&formname='+formname ,'Link','height=200,width=400,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
}

function InsertOutPic(control,formname){
	window.open('inc/insert_outpic.php?control='+ control +'&formname='+formname ,'Link','height=150,width=400,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
}
function ReqPic(control,formname){
	window.open('inc/insert_pic.php?control='+ control +'&formname='+formname ,'Pic','height=700,width=900,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1');
}
