
//form field names (all text fields):
//Href
//ID
//Title
//Rel
//Rev

// *********** GLOBAL VARS *****************************

var helpDoc = MM.HELP_inspLink;

// ******************** API ****************************
function canInspectSelection(){
  return true;
}

function inspectSelection(){
  var Href = findObject("Href");
  var Title = findObject("Title");
  var ID = findObject("ID");
  var Rel = findObject("Rel");
  var Rev = findObject("Rev");
  var linkObj = getSelectedObj();

  if (!linkObj || !linkObj.getAttribute) return;

  if (linkObj.getAttribute("href"))
    Href.value=linkObj.getAttribute("href");
  else
    Href.value = "";	
  if (linkObj.getAttribute("id"))
    ID.value=linkObj.getAttribute("id");
  else
    ID.value = "";	
  if (linkObj.getAttribute("title"))  
    Title.value=linkObj.getAttribute("title");
  else
    Title.value="";	
  if (linkObj.getAttribute("rel"))
    Rel.value=linkObj.getAttribute("rel");
  else
    Rel.value = "";	
  if (linkObj.getAttribute("rev"))
    Rev.value=linkObj.getAttribute("rev");
  else
    Rev.value ="";	
  showHideTranslated();;
  //showHideTranslated( getSelectedObj(), 'tButtonSpan' );	
}



// ******************** LOCAL FUNCTIONS ****************************

function setLinkTag(){
  var linkObj = getSelectedObj();
  var relValue = findObject("Rel").value;
  var bRelEqualsStylesheet = relValue &&
                             relValue.toLowerCase().indexOf("stylesheet")!=-1;
  if (findObject("Href").value)
    linkObj.setAttribute("href",findObject("Href").value);
  else
    linkObj.removeAttribute("href");
  if (findObject("ID").value)
    linkObj.setAttribute("id",findObject("ID").value);
  else
    linkObj.removeAttribute("id");
  if (findObject("Title").value)
    linkObj.setAttribute("title",findObject("Title").value);
  else
    linkObj.removeAttribute("title");
  if (findObject("Rel").value)
    linkObj.setAttribute("rel",findObject("Rel").value);
  else
    linkObj.removeAttribute("rel");
  if (findObject("Rev").value)
    linkObj.setAttribute("rev",findObject("Rev").value);
  else
    linkObj.removeAttribute("rev");
  setTypeAttr(bRelEqualsStylesheet);//set type attribute based on rel value	
}

function browseForFile(){
  var fileName=browseForFileURL();
  if (fileName) 
    findObject("Href").value=fileName;
}

function setTypeAttr(bStyle){
  var linkObj = getSelectedObj();
  var typeAttr = linkObj.getAttribute("type");
  if (bStyle) //set type to text/css if applicable
    linkObj.setAttribute("type","text/css");
  //otherwise, remove it	
  else if (typeAttr && typeAttr.toLowerCase() == "text/css")
    linkObj.removeAttribute("type");
}
