/* Library */

String.prototype.trim = function()
{
  return this.replace(/^\s*|\s*$/g, '');
};

function Email()
{
  this.domain = '';
  this.name = '';

  this.check = function(address)
  {
    var validcharacters = 'abcdefghijklmnopqrstuvwxyz0123456789-_.@';
    var domain, i, position, success;
    success = false;
    if (address != null)
    {
      address = address.toLowerCase();
      position = address.indexOf('@');
      if (position != -1)
      {
        if (address.indexOf('@', position + 1) == -1)
        {
          if (address.substr(position + 1).indexOf('.') != -1)
          {
            for (i = 0; i < address.length; i++)
            {
              if (validcharacters.match(address.charAt(i)) == null)
                break;
            }
            if (i == address.length)
            {
              domain = address.substr(position + 1);
              if ((address.substring(0, position).length > 1) && (domain.length > 4))
              {
                if (domain.length > (domain.indexOf('.') + 2))
                {
                  this.domain = domain;
                  this.name = address.substring(0, position);
                  success = true;
                }
              }
            }
          }
        }
      }
    }
    return success;
  };
}

function changeImage(imageobj, image)
{
  imageobj.src = image;
  return true;
}

function preloadImage(image)
{
  var imageobj = new Image();
  imageobj.src = image;
}

function showPopup(html, left, top, width, height, resizable, scrollbars)
{
  var windowobj;
  if ((html.substr(html.length - 4, 4).toLowerCase() == '.htm') || (html.substr(html.length - 5, 5).toLowerCase() == '.html'))
    windowobj = window.open(html, '', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',resizable=' + ((resizable == true) ? 'yes' : 'no') + ',scrollbars=' + ((scrollbars == true) ? 'yes' : 'no'));
  else
  {
    windowobj = window.open('', '', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',resizable=' + ((resizable == true) ? 'yes' : 'no') + ',scrollbars=' + ((scrollbars == true) ? 'yes' : 'no'));
    windowobj.document.open();
    windowobj.document.write(html);
    windowobj.document.close();
  }
  windowobj.focus();
}

function showPicture(title, css, picture, width, height)
{
  var html;
  html = '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n';
  html += '<html>\n';
  html += '  <head>\n';
  html += '    <title>' + title + '</title>\n';
  html += '    <link rel=\"stylesheet\" href=\"' + css + '\" type=\"text/css\">\n';
  html += '  </head>\n';
  html += '  <body style=\"margin: 0px\">\n';
  html += '    <img src=\"' + picture + '\" alt=\"\" border=\"0\" width=\"' + width + '\" height=\"' + height + '\">\n';
  html += '  </body>\n';
  html += '</html>\n';
  if ((width > (screen.availWidth - 12)) || (height > (screen.availHeight - 31)))
    showPopup(html, 0, 0, width, height, true, true);
  else
    showPopup(html, (screen.availWidth - width) / 2, (screen.availHeight - height) / 2, width, height, false, false);
}

/* Routines */

var languages = new Array(Array('nl', 'Nederlands', 'be.gif', 'nl.gif'),
                          Array('en', 'English', 'us.gif', 'uk.gif'));

var freewaremenus = new Array(Array(Array('Code', 'code.html'),
                                    Array('Extra', 'tools.html'),
                                    Array('Scripts', 'scripts.html'),
                                    Array('Toepassingen', 'applications.html')),
                              Array(Array('Code', 'code.html'),
                                    Array('Tools', 'tools.html'),
                                    Array('Scripts', 'scripts.html'),
                                    Array('Applications', 'applications.html')));

var linksmenus = new Array(Array(Array('Dieren', 'animals.html'),
                                 Array('Films', 'movies.html'),
                                 Array('Geschiedenis', 'history.html'),
                                 Array('Muziek', 'music.html'),
                                 Array('Programmeren', 'programming.html'),
                                 Array('Wetenschap', 'science.html')),
                           Array(Array('Animals', 'animals.html'),
                                 Array('Movies', 'movies.html'),
                                 Array('History', 'history.html'),
                                 Array('Music', 'music.html'),
                                 Array('Programming', 'programming.html'),
                                 Array('Science', 'science.html')));

var productsmenus = new Array(Array(Array('Componenten', 'components.html'),
                                    Array('Portfolio', 'portfolio.html')),
                              Array(Array('Components', 'components.html'),
                                    Array('Portfolio', 'portfolio.html')));

var formats = new Array(Array('Windows Bitmap', 'BMP', 'X', 'X'),
                        Array('Autodesk Animator Graphic', 'CEL', 'X', 'X'),
                        Array('Kodak Cineon', 'CIN', 'X', 'X'),
                        Array('Windows Clipboard', 'CLP', 'X', 'X'),
                        Array('DICOM', 'DCM', 'X', '&nbsp;'),
                        Array('Direct Draw Surface', 'DDS', 'X', '&nbsp;'),
                        Array('Digital Moving Picture Exchange', 'DPX', 'X', 'X'),
                        Array('Windows Enhanced Metafile', 'EMF', 'X', 'X'),
                        Array('Kodak FlashPix', 'FPX', 'X', '&nbsp;'),
                        Array('FaceSaver', 'FS', 'X', 'X'),
                        Array('EA Sports Format *', 'FSH', 'X', 'X'),
                        Array('Flexible Image Transport System', 'FTS', 'X', 'X'),
                        Array('Compuserve Graphics Interchange Format', 'GIF', 'X', 'X'),
                        Array('Amiga Interchange File Format', 'IFF/LBM', 'X', 'X'),
                        Array('GEM Raster', 'IMG', 'X', '&nbsp;'),
                        Array('Intergraph Raster', 'ITG', 'X', '&nbsp;'),
                        Array('JBIG', 'JBG/JBIG', 'X', '&nbsp;'),
                        Array('JPEG/JFIF', 'JPG/JPEG', 'X', 'X'),
                        Array('MacPaint', 'MAC', 'X', '&nbsp;'),
                        Array('Psion Series 5 Bitmap', 'MBM', 'X', 'X'),
                        Array('Magick Image File Format', 'MIF/MIFF', 'X', 'X'),
                        Array('Microsoft Paint', 'MSP', 'X', '&nbsp;'),
                        Array('Gimp Pattern', 'PAT', 'X', 'X'),
                        Array('Kodak Photo CD', 'PCD', 'X', '&nbsp;'),
                        Array('Macinthosh PICT', 'PCT', 'X', 'X'),
                        Array('ZSoft Paintbrush', 'PCX/DCX/SCR', 'X', 'X'),
                        Array('Palm Pilot', 'PDB', 'X', '&nbsp;'),
                        Array('Portable Network Graphics', 'PNG', 'X', 'X'),
                        Array('Portable Anymap', 'PBM/PGM/PPM', 'X', 'X'),
                        Array('Polychrome Recursive Format', 'PRF', 'X', 'X'),
                        Array('Adobe Photoshop', 'PSD', 'X', 'X'),
                        Array('Paint Shop Pro Image', 'PSP', 'X', 'X'),
                        Array('PIXAR Picture File', 'PXR/PIC', 'X', 'X'),
                        Array('Radiance', 'RAD', 'X', 'X'),
                        Array('Sun Raster', 'RAS', 'X', 'X'),
                        Array('ColorRIX', 'RIX/SCX', 'X', 'X'),
                        Array('Wavefront Raster File', 'RLA', 'X', 'X'),
                        Array('Utah RLE', 'RLE', 'X', 'X'),
                        Array('SciTex Continuous Tone', 'SCT/CT', 'X', 'X'),
                        Array('Silicon Graphics', 'SGI', 'X', 'X'),
                        Array('Astronomical Photos', 'STX/SBIG', 'X', 'X'),
                        Array('Truevision Targa', 'TGA', 'X', 'X'),
                        Array('Tagged Image File Format', 'TIF/TIFF', 'X', 'X'),
                        Array('Vicar', 'VIC/VICAR', 'X', 'X'),
                        Array('Khoros Visualization Image File', 'VIF/VIFF', 'X', 'X'),
                        Array('Windows Metafile', 'WMF', 'X', 'X'),
                        Array('Word Perfect Graphics', 'WPG', 'X', 'X'),
                        Array('X Bitmap', 'XBM', 'X', '&nbsp;'),
                        Array('X Windows Dump', 'XWD', 'X', 'X'));

var language;
var menu;

function getCurrentFile()
{
  return window.location.href.substring(window.location.href.lastIndexOf('/') + 1, window.location.href.length);
}

function preloadImages()
{
  if (document.images != null)
  {
    preloadImage('../images/be.gif');
    preloadImage('../images/nl.gif');
    preloadImage('../images/uk.gif');
    preloadImage('../images/us.gif');
    preloadImage('images/introduction.gif');
    preloadImage('images/introductiond.gif');
    preloadImage('images/introductions.gif');
    preloadImage('images/news.gif');
    preloadImage('images/newsd.gif');
    preloadImage('images/newss.gif');
    preloadImage('images/freeware.gif');
    preloadImage('images/freewared.gif');
    preloadImage('images/freewares.gif');
    preloadImage('images/products.gif');
    preloadImage('images/productsd.gif');
    preloadImage('images/productss.gif');
    preloadImage('images/links.gif');
    preloadImage('images/linksd.gif');
    preloadImage('images/linkss.gif');
    preloadImage('images/sitemap.gif');
    preloadImage('images/sitemapd.gif');
    preloadImage('images/sitemaps.gif');
    preloadImage('images/contact.gif');
    preloadImage('images/contactd.gif');
    preloadImage('images/contacts.gif');
  }
}

function setInputColor(inputobj, focus)
{
  if (focus == true)
    inputobj.style.background = '#666666';
  else
    inputobj.style.background = '#444444';
}

function showLanguagesMenu(language, root, menus, menu)
{
  var html, i;
  var link, relativepath;
  html = '';
  this.language = language;
  this.menu = menu;
  for (i = 0; i < languages.length; i++)
  {
    if (i != language)
    {
      if (root == true)
      {
        relativepath = '';
        link = relativepath + languages[i][0] + '/home.html';
      }
      else if (getCurrentFile() == 'home.html')
      {
        relativepath = '../';
        link = relativepath + 'index.html';
      }
      else
      {
        if (menus != undefined)
          relativepath = '../../';
        else
          relativepath = '../';
        if (menus != undefined)
          link = relativepath + languages[i][0] + '/' + menus + '/' + getCurrentFile();
        else
          link = relativepath + languages[i][0] + '/' + getCurrentFile();
      }
      html = '<a class=\"menulink\" href=\"' + link + '\">\n';
      html += '  <img class=\"flagframe\" src=\"' + relativepath + 'images/' + languages[i][2] + '\" alt=\"\" border=\"0\" width=\"16\" height=\"11\">\n';
      html += '  <img class=\"flagframe\" src=\"' + relativepath + 'images/' + languages[i][3] + '\" alt=\"\" border=\"0\" width=\"16\" height=\"11\">\n';
      html += '  <span class=\"language\">' + languages[i][1] + '</span></a>';
    }
  }
  document.write(html);
}

function showFreewareMenu()
{
  var html, i;
  var link;
  html = '';
  for (i = 0; i < freewaremenus[language].length; i++)
  {
    if (i == menu)
      html += '<a class=\"selectedmenulink\" href=\"' + freewaremenus[language][i][1] + '\">' + freewaremenus[language][i][0] + '</a>';
    else
      html += '<a class=\"menulink\" href=\"' + freewaremenus[language][i][1] + '\">' + freewaremenus[language][i][0] + '</a>';
    if (i < (freewaremenus[language].length - 1))
      html += '&nbsp;<span class=\"separator\">|</span>&nbsp;';
  }
  document.write(html);
}

function showLinksMenu()
{
  var html, i;
  var link;
  html = '';
  for (i = 0; i < linksmenus[language].length; i++)
  {
    if (i == menu)
      html += '<a class=\"selectedmenulink\" href=\"' + linksmenus[language][i][1] + '\">' + linksmenus[language][i][0] + '</a>';
    else
      html += '<a class=\"menulink\" href=\"' + linksmenus[language][i][1] + '\">' + linksmenus[language][i][0] + '</a>';
    if (i < (linksmenus[language].length - 1))
      html += '&nbsp;<span class=\"separator\">|</span>&nbsp;';
  }
  document.write(html);
}

function showProductsMenu()
{
  var html, i;
  var link;
  html = '';
  for (i = 0; i < productsmenus[language].length; i++)
  {
    if (i == menu)
      html += '<a class=\"selectedmenulink\" href=\"' + productsmenus[language][i][1] + '\">' + productsmenus[language][i][0] + '</a>';
    else
      html += '<a class=\"menulink\" href=\"' + productsmenus[language][i][1] + '\">' + productsmenus[language][i][0] + '</a>';
    if (i < (productsmenus[language].length - 1))
      html += '&nbsp;<span class=\"separator\">|</span>&nbsp;';
  }
  document.write(html);
}

function showFormats(title, width, height, name, extension, read, write, fsh)
{
  var html, i;
  html = '<html>\n';
  html += '  <head>\n';
  html += '    <title>' + title + '</title>\n';
  html += '    <link rel=\"stylesheet\" href=\"../../quicksystems.css\" type=\"text/css\">\n';
  html += '  </head>\n';
  html += '  <body class=\"formatspopup\">\n';
  html += '    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"520\">\n';
  html += '      <tr>\n';
  html += '        <td>\n';
  html += '          <div class="entryframe">\n';
  html += '            <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"516\">\n';
  html += '              <tr>\n';
  html += '                <td class=\"entrytitle\">' + name + '</td>\n';
  html += '                <td class=\"entrytitle\">' + extension + '</td>\n';
  html += '                <td class=\"entrytitle\">' + read + '</td>\n';
  html += '                <td class=\"entrytitle\">' + write + '</td>\n';
  html += '              </tr>\n';
  for (i = 0; i < formats.length; i++)
  {
    html += '              <tr>\n';
    html += '                <td class=\"entrytext\">' + formats[i][0] + '</td>\n';
    html += '                <td class=\"entrytext\">' + formats[i][1] + '</td>\n';
    html += '                <td class=\"entrytext\" align=\"center\">' + formats[i][2] + '</td>\n';
    html += '                <td class=\"entrytext\" align=\"center\">' + formats[i][3] + '</td>\n';
    html += '              </td>\n';
  }
  html += '            </table>\n';
  html += '          </div>\n';
  html += '        </td>\n';
  html += '      </tr>\n';
  html += '      <tr>\n';
  html += '        <td height="6"></td>\n';
  html += '      </tr>\n';
  html += '      <tr>\n';
  html += '        <td class=\"smalltext\">' + fsh + '</td>\n';
  html += '      </tr>\n';
  html += '      <tr>\n';
  html += '        <td height="6"></td>\n';
  html += '      </tr>\n';
  html += '    </table>\n';
  html += '  </body>\n';
  html += '</html>\n';
  showPopup(html, (screen.availWidth - width) / 2, (screen.availHeight - height) / 2, width, height, false, true);
}

function showHTML(html, width, height)
{
  showPopup(html, (screen.availWidth - width) / 2, (screen.availHeight - height) / 2, width, height, false, false);
}

function showNumberFormats()
{
  document.write(formats.length);
}

function isValidComments(formobj, emailwarning, messagewarning)
{
  var emailobj = new Email();
  var str;
  str = '';
  if (emailobj.check(formobj.email.value) == false)
  {
    formobj.email.focus();
    str = emailwarning;
  }
  else if (formobj.message.value.trim().length == 0)
  {
    formobj.message.focus();
    str = messagewarning;
  }
  if (str.length > 0)
  {
    window.alert(str);
    return false;
  }
  else
    return true;
}
