
// General purpose methods

function getUri()
{
   return window.location.pathname;
}

function open_imagewindow(imagename,w,h)
{
  if (imagename.indexOf("&")!=0)
  {
    imagename+="&width="+w+"&height="+h;
  }

  window.open("showimage.htm?"+imagename,"AISImage","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width="+w+",height="+h);
}

function compose_emailaddress(user,domain,text)
{
  var actText="";
  if (text=="")
    actText=user+"@"+domain;
  else
    actText=text;
  document.write("<a class='NormalLink' name='mailto' href='mailto:" + user+"@"+domain + "'>"+actText + "</a><br>");
}

function generateLinks()
{
  document.write(window.location.pathname);
}

// Specific mail adresses (maybe not very good solution??)

function contactInfo(alias)
{
  var name="";
  var email="";
  var domain="cmr.no"
  var phone="";

  
  if (alias=="stian")
  {
    email="Stian.Anfinsen";
    name="Stian Anfinsen";
    phone="(+47) 55 57 42 59";
  }
  else if (alias=="torchr")
  {
    email="tor.christian.bekkvik";
    name="Tor Christian Bekkvik";
    phone="(+47) 55 57 42 28";
        
  } 
  else if (alias=="perg")
  {
    email="Per.Gunnar.Lunde";
    name="Per Gunnar Lunde";
    phone="(+47) 55 57 42 20";
  } 
  else if (alias=="ingolf")
  {
    email="Ingolf.Magnus";
    name="Ingolf Magnus";
    phone="(+47) 55 57 43 51";
  } 
  else if (alias=="kjell")
  {
    name="Kjell Røang";
    email="kjell";
    phone="(+47) 913 54 664";
  } 
  else if (alias=="kåre")
  {
    name="Kåre P. Villanger";
    email="kpv";
    phone="(+47) 55 57 43 41";
  }
  else if (alias=="vinjar")
  {
    name="Vinjar Wærenskjold";
    email="Vinjar.Werenskjold";
    phone="(+47) 55 57 42 84";
  }

  document.write(name + "<br>Advanced Computing<br>Christian Michelsen Research AS<br>");
  if (email.length>0)
    document.write("Email: <a class='NormalLink' name='mailto' href='mailto:" + email +"@" + domain + "'>" + email +"@" + domain + "</a><br>");
  if (phone.length>0)
    document.write("Phone: " + phone);
}

// Common page layout methods:

var menuArr;
var mainMenuArr;
var thisMenuItemNo=-1;
var thisMainItemNo=-1;
var mainItemText="";

function generateMenuArr()
{
  menuArr=new Array(0);
  mainMenuArr=new Array(0);

// The following code is generated by a spreadsheet:
//-----------------------------

  menuArr.push('AISOnline_home.htm;Home Page;AIS Online Home;;;'.split(';'));mainMenuArr.push('AISOnline_home.htm;AIS Online Home'.split(';'));
  menuArr.push('AISOnline_whatis.htm;What is AIS?;AIS Online Home;What is AIS?;;'.split(';'));
  menuArr.push('AISOnline_WMS.htm;WMS;AIS Online Home;Web Map Service;;'.split(';'));
  menuArr.push('AISOnline_links.htm;Links;AIS Online Home;Links;;'.split(';'));
  menuArr.push('AISOnline_contacts.htm;Contacts;AIS Online Home;Contacts;;'.split(';'));
  menuArr.push('AISOnline_services.htm;Services;Services;;;'.split(';'));mainMenuArr.push('AISOnline_services.htm;Services'.split(';'));
  menuArr.push('AISOnline_products.htm;Product Features;Product Features;;;'.split(';'));mainMenuArr.push('AISOnline_products.htm;Product Features'.split(';'));
  menuArr.push('AISOnline_products_filters.htm;Product Features - Filters;Product Features;Filters;;'.split(';'));
  menuArr.push('AISOnline_products_maps.htm;Product Features - Maps;Product Features;Maps;;'.split(';'));
  menuArr.push('AISOnline_products_lists.htm;Product Features - Lists and Data Export;Product Features;Lists and Data Export;;'.split(';'));
  menuArr.push('AISOnline_products_smartlinks.htm;Product Features - Smart Links;Product Features;Smart Links;;'.split(';'));
  menuArr.push('AISOnline_products_historical.htm;Product Features - Historical Data and Statistics;Product Features;Historical Data and Statistics;;'.split(';'));
  menuArr.push('AISOnline_products_events.htm;Product Features - Events;Product Features;Events;;'.split(';'));
  menuArr.push('AISOnline_products_documentation.htm;Documentation;Product Features;Documentation;;'.split(';'));
  menuArr.push('AISOnline_customers.htm;Customers;Customers;;;'.split(';'));mainMenuArr.push('AISOnline_customers.htm;Customers'.split(';'));
  menuArr.push('AISOnline_partners.htm;Partners;Partners;;;'.split(';'));mainMenuArr.push('AISOnline_partners.htm;Partners'.split(';'));
  menuArr.push('AISOnline_news.htm;News;News;;;'.split(';'));mainMenuArr.push('AISOnline_news.htm;News'.split(';'));

//-----------------------------

}

function generateHead()
{

  generateMenuArr();

// Find parameters about current page
  
  thisMenuItemNo=-1;
  thisMainItemNo=-1;
  
  for (i=0;i<menuArr.length && thisMenuItemNo<0; i++)
    if (fileName==menuArr[i][0])
      thisMenuItemNo=i;
  /* 
  alert(fileName);
  alert(thisMenuItemNo);
  alert(menuArr[thisMenuItemNo-1][0]);
  alert(menuArr[thisMenuItemNo][0]);
  alert(menuArr[thisMenuItemNo+1][0]);
  */
  if (thisMenuItemNo>=0)
  {
    pageTitle=menuArr[thisMenuItemNo][1];
    if (pageTitle.length>0)
      document.title="AISOnline - "+pageTitle;
    mainItemText=menuArr[thisMenuItemNo][2]

    for (i=0;i<mainMenuArr.length && thisMainItemNo<0; i++)
      if (mainItemText==mainMenuArr[i][1])
        thisMainItemNo=i;
  }

// Determine font sizes depending on navigator type
  
  if (navigator.appName == "Netscape")
	  pathfontstyle="font-size: small";
	else
	  pathfontstyle="font-size: x-small";

// Check if Print or normal page
	  
  var normal = (window.location.search!="?print");

// Achor top of page (nice to have)
  
	document.write("<a name='pageTop'></a>");

  // Here comes the real stuff.
	
  // Outer table, wrapping the whole page, table terminated in "generateTail"
  if (normal)
    document.write(  "<table border='0' width='840' cellspacing='0' cellpadding='0'>");
  else
  {
    document.write(  "<table border='0' width='700' cellspacing='0' cellpadding='0'>");
    document.title="Print: "+ document.title;
  	window.print();
  }
  
  // Table containing logo and top image
  document.write(  "<table border='0' cellspacing='0' cellpadding='0'>");
  document.write(    "<tr>");
  document.write(      "<td valign='middle' align='left' width='142'>");
  document.write(        "<a href='AISOnline_home.htm'><img border='0' src='images/hdr_logo-blue.png' width='140' height='114' alt='HOME'></a>");
  document.write(      "</td>");
  if (normal)
  {
    document.write(      "<td valign='middle' align='left' width='552'>");
    document.write(        "<a href='AISOnline_home.htm'><img border='0' src='images/hdr_boatmap-bluish.png' width='550' height='114' alt='HOME'></a>");
    document.write(      "</td>");
  }
  else
  {
    document.write(      "<td valign='middle' align='left' width='410'>");
    document.write(      "</td>");
  }
  
  document.write(      "<td valign='middle' align='center' width='140' style='background-color: #FFFFFF'>");
  document.write(        "<a href='http://www.cmr.no'><img border='0' src='images/cmr_logo.png' alt='CMR HOME'></a>");
  document.write(      "</td>");
  document.write(    "</tr>");
  document.write(  "</table>");

  if (normal)
  {
    // Table containing main menu
    document.write(  "<table width='840' border='0' cellspacing='3' cellpadding='8' bordercolor='#FFFFFF'>");
    document.write(    "<tr height='40' >");

    generateMainMenu();

    document.write(    "</tr>");
    document.write(  "</table>");
  }

  // Table wrapping submenu and page content, table terminated in "generateTail"
  if (normal)
    document.write(  "<table width='840' border='0' cellspacing='3' cellpadding='0' bordercolor='#FFFFFF'>");
  else
    document.write(  "<table width='700' border='0' cellspacing='3' cellpadding='0' bordercolor='#FFFFFF'>");
  
  document.write(    "<tr valign='top'>");  // Tablerow terminated in "generateTail"

  if (normal)
  {
    // Left coloumn: Submenu
    document.write(    	"<td>");
    // Submenu in separate table 
    document.write(       "<table  width='140' cellpadding='5'>");

	  generateSubMenu();

    document.write(       "</table>");
    document.write(		  "</td>");
  }

  // Right coloumn: Page path and content
  document.write(     "<td valign='top' align='left' width='700'>");  // Tablecell terminated in "generateTail"

  // PagePath and print icon in separate table 
  document.write(      "<table width='680' style='"+pathfontstyle+"'>");
  document.write(    	  "<tr valign='top'>");
  document.write(    	   "<td class='AISOnlinePath'>");

  generatePath("AISOnlinePath");

  document.write(       "</td>");
  document.write(       "<td width='50' align='right'>");
  if (normal)
    document.write(          "<a class='AISOnlinePrint' href='"+window.location.pathname+"?print'><img border='0' src='images/print.png' alt='Print this Article' width='27' height='27'></a>");
  else
    document.write(          "<a class='AISOnlinePrint' href='"+window.location.pathname+"'>Back to article</a>");
  document.write(       "</td>");
  document.write(      "</tr>");
  document.write(    	"</table>");
}

function generateTail()
{
  document.write(      "</td>");
  document.write(    "</tr>");
  document.write(  "</table>");
  document.write("</table>");
}
  

// Generate path text: "p1 >> p2 >> p3 >> etc"...

function generatePath(classname)
{
  var printText="";
  var delimiter="&nbsp;>>&nbsp;"
  var path="";
  var itemLevel=0;
  var currLevel;

// Initilize search text if this is a "print"-page
  if (window.location.search=="?print")
    printText="?print";

// Determine the nested levels of items in the path
  for (j = 0; j+2 < menuArr[thisMenuItemNo].length;j++)
    if (menuArr[thisMenuItemNo][j+2].length>0)
      itemLevel=j;

// Generate the path text
  currLevel=-1;
  var firstItem=true;
  
  for (i = 0; i <= thisMenuItemNo; i++) // Parse up to and including this item
  {
    var newLevel=-1;

// Compare possible menu items with the current
    for (j=currLevel+1;j<=itemLevel && j+2< menuArr[i].length;j++)
      if (menuArr[i][j+2]==menuArr[thisMenuItemNo][j+2])
        newLevel=j;

    if (newLevel>=0)
    {
      currLevel=newLevel;
      if (currLevel==0 && i > 0)
      {
        document.write("<a class='"+classname+"' href='"+menuArr[0][0]+printText+"'>"+menuArr[0][newLevel+2]+"</a>");
        firstItem=false;
      }
      if (!firstItem)
        document.write(delimiter);
      if (i < thisMenuItemNo)
        document.write("<a class='"+classname+"' href='"+menuArr[i][0]+printText+"'>"+menuArr[i][newLevel+2]+"</a>");
      else
        document.write(menuArr[i][newLevel+2]);
      firstItem=false;
    }
  }
}

function generateMainMenu()
// Generate main menu across page almost on top
{
  var text="";
  var href="";
  var title="";

  var name = navigator.appName;
  if (name == "Netscape")
	  fontstyle="font-size: small";
	else
	  fontstyle="font-size: x-small";

  switch (mainMenuArr.length)
  {
    case 1: colWidth="100%";break;
    case 2: colWidth="50%";break;
    case 3: colWidth="33%";break;
    case 4: colWidth="25%";break;
    case 5: colWidth="20%";break;
    case 6: colWidth="16%";break;
    case 7: colWidth="14%";break;
    case 8: colWidth="12%";break;
  }


  for (i = 0; i < mainMenuArr.length; i++)
  {
    href=mainMenuArr[i][0];
    text=mainMenuArr[i][1];
    title="";

    ptext="<p>"+text+"</p>";
    
    if (i==thisMainItemNo)
      generateTableCellHlink("mainMenuCurrent","mainMenuCurrent",fontstyle,"center",colWidth,ptext,href,title)
    else
      generateTableCellHlink("mainMenu","mainMenuHover",fontstyle,"center",colWidth,ptext,href,title)
  }
}

function generateSubMenu()
// Generate submenu on left side
{

  var text="";
  var href="";
  var title="";

  var name = navigator.appName;
  if (name == "Netscape")
	  fontstyle="font-size: small";
	else
	  fontstyle="font-size: x-small";

  for (i = 0; i < menuArr.length; i++)
  {
    if (menuArr[i][2]==mainItemText)
    // Item belongs to this submenu
    {
      text=menuArr[i][3];
      href=menuArr[i][0];
      title="";
         
      if (text !="")
      {
        document.write("<tr>");
        if (i==thisMenuItemNo)
          generateTableCellOwnHlink("subMenuCurrent",fontstyle,"left","",text,"",title);
        else
          generateTableCellHlink("subMenu","subMenuHover",fontstyle,"left","",text,href,title);
        document.write("</tr>");
      }
      if (i==thisMenuItemNo && pageSections.length>0)
        generateSectionMenu();
    }
  }
}

function generateSectionMenu()
{
  var sections=pageSections.split(";");

  while (sections.length >1)
  {
    nextLink=sections.shift();
    nextItem=sections.shift();
    nextTitle="Move to section \"" + nextItem + "\" on this page";

    document.write("<tr>");
    generateTableCellHlink("sectionMenu","sectionMenuHover",fontstyle,"left","","<p>"+nextItem+"</p>",nextLink,nextTitle);
    document.write("</tr>");
  }
}

function generateTableCellHlink(baseClass,hoverClass,fontstyle,align,width,text,href,title)
{
  document.write(
    "<td class='"+baseClass+"'"+
    " style='"+fontstyle+"'");
  if (align.length>0)
    document.write(" align='"+align+"'");
  if (width.length>0)
    document.write(" width='"+width+"'");
  if (title.length>0)
    document.write(" title='"+title+"'");
  document.write(
    " onclick='change_Location(\""+href+"\")'"+ 
    " onmouseover=\"this.className='"+hoverClass+"';style.cursor='Pointer'\""+
    " onmouseout=\"this.className='"+baseClass+"'\">"+
    text+"</td>");
}

function generateTableCellOwnHlink(cellClass,fontstyle,align,width,text,href,title)
{
  document.write(
    "<td class='"+cellClass+"'"+
    " style='"+fontstyle+"'"+
    " style='"+fontstyle+"'");
  if (align.length>0)
    document.write(" align='"+align+"'");
  if (width.length>0)
    document.write(" width='"+width+"'");
  if (title.length>0)
    document.write(" title='"+title+"'");
  if (href.length>0)
    document.write(" onclick='change_Location(\""+href+"\")'");
  document.write(
    " onmouseover=\"style.cursor='Default'\">"+
    text+"</td>");
}

function change_Location(loc)
{
  window.location=loc;
}

function underConstruction()
{
  document.write("<p align='right'>Under construction<img border='0' src='images/bangdesk.gif' width='45' height='45'></p>");
}
