// border and selection
var currentSGEditSelection = null;
var currentSGEditHilite = null
function doborder(theid)
{
   var thediv = theid ? document.getElementById(theid) : null;
   
   if(currentSGEditSelection)
   {
     removeClass(currentSGEditSelection, 'sg_cms_selected');
   }
   if(thediv)
   { 
     removeClass(thediv, 'sg_cms_hilite'); 
     addClass(thediv, 'sg_cms_selected'); 
   }
   currentSGEditSelection = thediv;
}

function dohilite(theid)
{
   var thediv = theid ? document.getElementById(theid) : null;
   
   if(currentSGEditHilite)
   {
     removeClass(currentSGEditHilite, 'sg_cms_hilite');
   }
   if(thediv && thediv != currentSGEditSelection){ addClass(thediv, 'sg_cms_hilite'); }
   currentSGEditHilite = thediv;
}

function addClass(target, classValue)
{
   var pattern = new RegExp("(^| )" + classValue + "( |$)");
   if(!pattern.test(target.className))
   {
   	if(target.className == "")
   	{
   		target.className = classValue;
   	}
   	else
   	{
   		target.className += " " + classValue;
   	}
   }
}

function removeClass(target, classValue)
{
 var removedClass = target.className;
 var pattern = new RegExp("(^| )" + classValue + "( |$)");
 removedClass = removedClass.replace(pattern, "$1");
 removedClass = removedClass.replace(/ $/, "");
 
 target.className = removedClass;
}
