//-------------------------------------------------------------------------
var topFrame = 0;
var leftFrame = 1;
var centerFrame = 2;

var boxId = "";
var globalPage = "Home.html"
var globalMethod="Frame"
function DEBUG(loc,v)
{
  var p = document.getElementById(loc);
  p.innerHTML = v;
}

function ShowStatus1(s)
{
   var p = window.top.frames[topFrame].document.getElementById("status");
  p.innerHTML = s;
}

function CheckRemove()
{
  var page = GetLastPage();
  if(page != "") {
    ShowRemoveButton("y");
    ShowCurrentPage(page);
  }
}

function ShowRemoveButton(s)
{

  var win = window.top;
  var doc = win.frames[leftFrame].document;
  var location = doc.getElementById("Remover");
  if(s == "y") {
    //    doc.getElementById("FrameRemover").style.visibility="visible";
   location.style.visibility="visible";
  }
  else {
    //    location.style.visibility="hidden";
  }
}


function newSelectBox() 
{ 
  if (xmlHttp.readyState==4)
    { 
      var selectBox = xmlHttp.responseText;
      var location;
      if(boxId == "LinksOfInterest") {
	var win = window.top;
	var doc = win.frames[leftFrame].document;
	location = doc.getElementById(boxId);
	if(selectBox)
	  location.innerHTML = selectBox;
      }
      else {
	location = document.getElementById(boxId);
          location.innerHTML = selectBox;
      }
    }
}



function IsLink(page)
{
  var islink = 0;
  if( page.indexOf("http://") != -1) islink = 1;
  else 
    if( page.indexOf(".asp") != -1) islink = 1;
    else 
      if( page.indexOf(".htm") != -1) islink = 1;
  return islink;
}

function ShowLink2(link,target,aspFile)
{  
  var page = link.options[link.selectedIndex].value;
  ShowStatus1(page);
  if(page == "") return;
  if(IsLink(page) == 0) {
    getSelectOptions(page,target,aspFile); 
  }
  else {
    OpenThisPage(page,'yes');
    //    var win = window.parent;
    //    var doc = win.frames["center"];
    //    doc.location.href = page;
    //    window.open(page,"_top");
  }
}

function Warn(s)
{
  return;
  document.getElementById("Warning").innerHTML = s;
}

function OpenPage()
{
  if(globalPage == "") return;
  var win = window.top;
  //  var doc = win.frames[centerFrame];
  if(globalMethod == "Frame") {
    win.open(globalPage,"center");
    //    doc.location.href = globalPage;
    Warn("");
  }
  else if(globalMethod == "Top") {
    window.open(globalPage,"_top");
    Warn("");
  }
  else if(globalMethod == "Single") {
    window.open(globalPage,"NewWindow");
    Warn("Remember to check Tabs");
  }
  else if(globalMethod == "Multiple") {
    window.open(globalPage,"_blank");
    Warn("Remember to check Tabs");
  }
}
function ChangeFrame(f)
{
  var method = f.options[f.selectedIndex].value;
  globalMethod = method;
  OpenPage();
}


function ShowLink(link)
{  
  var page = link.options[link.selectedIndex].value;
  if(page == "") return;
  window.open(page,"_top");
}

function SetLastPage(page)
{
  document.cookie="LastPage="+page + ";";
}

function GetLastPage()
{
  var page = "";
  var c_start = document.cookie.indexOf("LastPage=");
  if(c_start != -1) {
    c_start += 9;
    var c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    page = document.cookie.substring(c_start,c_end);
  }
  return page;
}

function RemoveFrame()
{
  var top = window.top;
  page = GetLastPage();
  if(page != "") {
    top.open(page,"_self");
  }
  else {
    alert("Sorry could not find page to move");
  }
}
function ShowCurrentPage(s)
{
  var p = window.top.frames[topFrame].document.getElementById("CurrentPage");
  p.innerHTML = s;
}

function ShowInfo(s)
{
  var p = window.top.frames[topFrame].document.getElementById("status");
  p.innerHTML = s;
}

function OpenThisPage(page,yesno)
{
  globalPage = page;
  SetLastPage(page);
  ShowCurrentPage(globalPage);
  ShowRemoveButton("y");
  if(yesno == "yes") {
    var win = window.top;
    win.open(globalPage,"center");
  }
}
function ShowLinkInFrame(link)
{
  var page = link.options[link.selectedIndex].value;
  OpenThisPage(page);
}

function ShowPageInFrame(page)
{
  if(page == "") return;
  var win = window.parent
  var doc = win.frames[centerFrame];
  doc.location.href = page;
  return;
}






function getSelectOptions(id,target,aspFile)
{ 
  boxId = target;
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    } 
  var url = aspFile+"?group=";
  url += escape(id);
  //  var url="FillPulldown.asp?group=" + escape(id);
  //    DEBUG("p1",boxId);
  //    DEBUG("p2",url);
  //    DEBUG("p3","");

  xmlHttp.onreadystatechange=newSelectBox;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}






function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
	{
	    // Firefox, Opera 8.0+, Safari
	    xmlHttp=new XMLHttpRequest();
	}
    catch (e)
	{
	    // Internet Explorer
	    try
		{
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	    catch (e)
		{
		    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
    return xmlHttp;
}
