
//form field names:
//fileURL - text field where URL appears
//Delay - form field for delay number
//Action - radio buttons: radioURL is Go To another document
//                        radioThisDoc is stay at current document

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

var helpDoc = MM.HELP_inspRefresh;

// ******************** API ****************************
function canInspectSelection(){

  var metaObj = getSelectedObj();
  if (!metaObj || !metaObj.getAttribute) return false;

  return (metaObj.tagName && metaObj.tagName=="META" &&
          metaObj.getTranslatedAttribute("http-equiv") && 
          metaObj.getTranslatedAttribute("http-equiv").toLowerCase()=="refresh");
   
}

function inspectSelection(){
  var refreshObj = getSelectedObj();

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

  var tagContent = refreshObj.getAttribute("content"); 
  var Delay = findObject("Delay");
  var radioURL = findObject("radioURL");var radioThisDoc = findObject("radioThisDoc");
  var contentArray;
  
  
  //fill in PI form fields
  //check to see if the refresh applies to the current document by doing
  // an integer check - URL will have a ; 
  if (tagContent == parseInt(tagContent)){ 
    //fill in the Delay value and check the correct radio button:
    Delay.value = tagContent; 
    radioThisDoc.checked = true;     radioURL.checked = false;
  } else {               // else refresh is used to go to another document
     contentArray = getTokens(tagContent,";"); //create 2-member array
	 //fill in the Delay value
     Delay.value = (parseInt(contentArray[0])==contentArray[0])?contentArray[0]:""; 
	 //check correct radio button:
	 radioURL.checked = true;     radioThisDoc.checked = false;
	 //strip "URL=" before placing into PI
     if (contentArray[1] && contentArray[1].indexOf("URL=")==0) 
	   contentArray[1] = contentArray[1].substring(4);  
	 //fill in correct URL value  
	 if (contentArray[1])
	   findObject("fileURL").value = contentArray[1];
	 else
	   findObject("fileURL").value="";  
  }

  showHideTranslated();
}


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

function clearField(){
  findObject("fileURL").value="";

}

function setMetaTag(whichButton){
  //if whichButton is 0, go to URL just checked. If 1, refresh this doc just checked
  //if 2, this function called from a form field other than a checkbox
  var fileName="",refreshContent="";
  var radioURL = findObject("radioURL");
  var radioThisDoc = findObject("radioThisDoc");
  var fileURL = findObject("fileURL");
  var Delay = findObject("Delay");
  var refreshDelay = (parseInt(Delay.value) == Delay.value)?Delay.value:"";
  
  if (whichButton == 0 || (whichButton == 2 && radioURL.checked && !radioThisDoc.checked)){
  //if going to another doc
    fileName=(fileURL.value)?fileURL.value:"";
	refreshContent=refreshDelay + ";URL=" + fileName;
	//set checkboxes correctly
	radioThisDoc.checked = false;
	radioURL.checked=true;
  }
  else { //refresh current doc
    refreshContent=refreshDelay;
	//set checkboxes correctly
	radioURL.checked = false;
	radioThisDoc=true;
  }
  
  getSelectedObj().setAttribute("content",refreshContent);
  
}


function browseForFile(){
  var File = browseForFileURL(); 
  if (File)
    findObject("fileURL").value = File;
}

