function tag(tagadd,tagclose) {

        var post = document.form1.pm_body;
		var iStart = document.form1.pm_body.selectionStart;
		var iStop= document.form1.pm_body.selectionEnd;
		var courses = document.form1.pm_body.value.length;
		var theAppetizer= document.form1.pm_body.value.substring(0, iStart);
		var theDessert=document.form1.pm_body.value.substring(iStop, courses);
		var theEntree= document.form1.pm_body.value.substring(iStart, iStop);
		if(tagadd == "[img]"){
			var theIMG=prompt("Please enter the image URL",""); 
			if(theEntree.length == 0){
				var img = new Image();
				img.src = theIMG;
				if (img.width > 220){
					pct=Math.round(220/img.width * 100);
					//msg = "The selected image dimensions are not valid. The image cannot be wider than 150 pixels.\n\n";
					//msg = msg + "Your selected image dimensions are " + img.width + " x " + img.height + "\n\n";
					//msg = msg + "It would fit if it was scaled to " + pct + "%";
					//alert(msg);
					theWrap = "[img scale=" + pct + "]" + theIMG + "[/img]";
				}else{
					theWrap = "[img]" + theIMG + "[/img]";
				}
			}
			var stuff = theAppetizer + theWrap + theDessert;
		}else if(tagadd == "[url]"){
			var theURL=prompt("Please enter URL to link to","");
			if(theEntree.length == 0){
				theEntree = theURL;
			}
			var stuff = theAppetizer + "[url=" + theURL + "]" + theEntree + "[/url]" + theDessert;
		}else if(tagadd == "[youtube="){
			var clip=prompt("Please enter the youtube file id","");
			if(theEntree.length == 0){
				theEntree = clip;	
			}
			var stuff = theAppetizer + "[youtube=" + clip + "]" + theDessert;
		}else{
			var stuff = theAppetizer + tagadd + theEntree + tagclose + theDessert;
		}
        post.value = stuff;
        post.focus();
		if(tagclose.length == 0){
			hide_emos();	
		}	
		return false;
}
function tag2(tagadd,tagclose) {
        var post = document.form1.pbody;
		var iStart = document.form1.pbody.selectionStart;
		var iStop= document.form1.pbody.selectionEnd;
		var courses = document.form1.pbody.value.length;
		var theAppetizer= document.form1.pbody.value.substring(0, iStart);
		var theDessert=document.form1.pbody.value.substring(iStop, courses);
		var theEntree= document.form1.pbody.value.substring(iStart, iStop);
		if(tagadd == "[img]"){
			var theIMG=prompt("Please enter the image URL",""); 
			if(theEntree.length == 0){
				var img = new Image();
				img.src = theIMG;
				theWrap = "[img]" + theIMG + "[/img]";
			}
			var stuff = theAppetizer + theWrap + theDessert;
		}else if(tagadd == "[url]"){
			var theURL=prompt("Please enter URL to link to","");
			if(theEntree.length == 0){
				theEntree = theURL;
			}
			var stuff = theAppetizer + "[url=" + theURL + "]" + theEntree + "[/url]" + theDessert;
		}else if(tagadd == "[youtube="){
			var clip=prompt("Please enter the youtube file id","");
			if(theEntree.length == 0){
				theEntree = clip;	
			}
			var stuff = theAppetizer + "[youtube=" + clip + "]" + theDessert;
		}else{
			var stuff = theAppetizer + tagadd + theEntree + tagclose + theDessert;
		}
        post.value = stuff;
        post.focus();
		if(tagclose.length == 0){
			hide_emos();	
		}
		return false;
}
//Function for adding smilies

function smilie (smilie) {
        var post = document.form1.pm_body;
		var iStart = document.form1.pm_body.selectionStart;
		var iStop= document.form1.pm_body.selectionEnd;
		var courses = document.form1.pm_body.value.length;
		var theAppetizer= document.form1.pm_body.value.substring(0, iStart);
		var theDessert=document.form1.pm_body.value.substring(iStop, courses);
		var theEntree= document.form1.pm_body.value.substring(iStart, iStop);
		var stuff = theAppetizer + smilie + theDessert;
        post.value = stuff;
        post.focus();
        return;
}
//Function to confirm reset
function colorCheck () {
	if(document.editform.fc.value.length > 0){
		tag("[color=" + document.editform.fc.value + "]","[/color]");
		document.editform.fc.value="";
	}
}

function checkForm() {
	var subject = document.form1.pm_subject;
	var post = document.form1.pm_body;
	var recipient = document.form1.pm_recipient;
	if (subject.value.length > 0 && post.value.length > 0 && recipient.value.length > 0) {
		return true;
	}else{
		return false;
	}
}
function checkPost() {
	var subject = document.form1.psubject;
	var post = document.form1.pbody;
	if (subject.value.length > 0 && post.value.length > 0) {
		return true;
	}else{
		return false;
	}
}

