var editFunction = false;

function getSel(tag,theClass,style){
	var txt = '';
    var extra = '';
	if(editFunction==true){
if (window.getSelection){
		txt = window.getSelection();
	} else if (document.getSelection){
		txt = document.getSelection();
	} else if (document.selection){
		txt = document.selection.createRange().text;
	} else { alert('Our formatting tools do not yet work in your browser. Use Internet Explorer 6 or later for this function.'); return null;}
	
	if (theClass !=null){
	  extra = ' class="'+theClass+'"';
	}
	if(tag=='hr' || tag=='col' || tag=='input'){
	   string = '<'+tag+extra+'/>'+txt;
	} else {
	
	  if(tag=='a' || tag=='img'){
	   
	   var linkPass=false;
	     address = document.getElementById("weburl").value;
		 address = stripCharacter(address,' ');
		 
	     if(address != ''){
		 if(address.match('http://') || address.match('https://')){
		   linkPass = true;
		 }
		 if (linkPass==false){
		   address = 'http://'+address;
		 }
		   if(tag=='a'){
		     if(txt==''){txt=document.getElementById("linkname").value;}
		     string = '<a href="'+address+'">'+txt+'</a>';
		   }
		   if(tag=='img'){
		     if(txt==''){txt='Image';}
		     string = '<img src="'+address+'" alt="'+txt+'"/>';
		   }
		 } else {alert('You must enter a web address in order to make a link or image.');}
	    
	  } else {string = '<'+tag+extra+'>'+txt+'</'+tag+'>';}
	  
	}

	if (window.getSelection){
		alert('Our formatting tools do not yet work in your browser. Use Internet Explorer 6 or later for this function.'); return false;
	}
	else if (document.getSelection){
		//document.getSelection() = string ;
		alert('Our formatting tools do not yet work in your browser. Use Internet Explorer 6 or later for this function.'); return false;
	}
	else if (document.selection){
		document.selection.createRange().text=string;
	}
   } else {alert('This button only works when the main text field is selected.');}

}

function changeState(direction){
  editFunction = direction;

}


