﻿function addressValid(field){
  var character;
  var counter1;
  var counter2;
  var fieldvalid;
  var invalidcharacters;
  var regexp1;
  var regexp2;
  fieldvalid = true;
  invalidcharacters = '!\"#$%&()*\'+,/:;<=>?[\\]^{|}~£¬';
  regexp1 = new RegExp('(@.*@)|(\\.\\.)|(@\\.)|(^\\.)');
  regexp2 = new RegExp('^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$');
  for (counter1 = 0; counter1 < field.length; ++ counter1){
    character = field.charCodeAt(counter1);
    for (counter2 = 0; counter2 < invalidcharacters.length; ++ counter2){
      if (invalidcharacters.charCodeAt(counter2) == character){
        fieldvalid = false;
        break;
      }
    }
    if (fieldvalid == false){
      break;
    }
  }
  if (fieldvalid == false){
    return fieldvalid;
  }
  fieldvalid = regexp1.test(field) == false && regexp2.test(field) == true;
  return fieldvalid;
}
function charactersValid(mode, field){
  var character;
  var counter1;
  var counter2;
  var fieldvalid;
  var validcharacters;
  fieldvalid = true;
  if (mode == 'h'){
    validcharacters = '0123456789ABCDEF';
  }
  else if (mode == 'nl'){
    validcharacters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  }
  else if (mode == 'spphn'){
    validcharacters = ' ()+-0123456789';
  }
  for (counter1 = 0; counter1 < field.length; ++ counter1){
    character = field.charCodeAt(counter1);
    for (counter2 = 0; counter2 < validcharacters.length; ++ counter2){
      if (validcharacters.charCodeAt(counter2) == character){
        break;
      }
    }
    if (counter2 == validcharacters.length){
      fieldvalid = false;
      break;
    }
  }
  return fieldvalid;
}
function encodeQuotes(field){
  field = field.replace(/\"/g, '{').replace(/\'/g, '}');
  return field;
}
function expandMenu(mode, elementid){
  var counter;
  var element;
  var tdleft;
  var tdtop;
  tdleft = 0;
  tdtop = 0;
  if (mode == 1){
    for (counter = 0; counter < document.forms[0].elements.length; ++ counter){
      document.forms[0].elements[counter].blur();
    }
    if (document.getElementById('tdmenu' + elementid.toString()).offsetParent){
      element = document.getElementById('tdmenu' + elementid.toString());
      while (element.offsetParent != null){
        tdleft += element.offsetLeft;
        tdtop += element.offsetTop;
        element = element.offsetParent;
      }
      document.getElementById('divmenu' + elementid.toString()).style.left = (tdleft - 1).toString() + 'px';
      document.getElementById('divmenu' + elementid.toString()).style.top = (tdtop + 16).toString() + 'px';
    }
    document.getElementById('divmenu' + elementid.toString()).style.visibility = 'visible';
  }
  else{
    document.getElementById('divmenu' + elementid.toString()).style.visibility = 'hidden';
  }
}
function getTimeStamp(){
  var currentdate;
  var currenthour;
  var currentmillisecond;
  var currentminute;
  var currentsecond;
  var timestamp;
  currentdate = new Date();
  currenthour = currentdate.getHours().toString();
  if (currenthour.length == 1){
    currenthour = '0' + currenthour;
  }
  currentminute = currentdate.getMinutes().toString();
  if (currentminute.length == 1){
    currentminute = '0' + currentminute;
  }
  currentsecond = currentdate.getSeconds().toString();
  if (currentsecond.length == 1){
    currentsecond = '0' + currentsecond;
  }
  currentmillisecond = currentdate.getMilliseconds().toString();
  if (currentmillisecond.length == 1){
    currentmillisecond = '00' + currentmillisecond;
  }
  else if (currentmillisecond.length == 2){
    currentmillisecond = '0' + currentmillisecond;
  }
  timestamp = currenthour + currentminute + currentsecond + currentmillisecond;
  return timestamp;
}
function highlightImage(mode, element){
  if (mode == 1){
    element.style.filter = 'alpha(opacity = 70)';
    element.style.opacity = '0.70';
    element.style.MozOpacity = '0.70';
  }
  else{
    element.style.filter = 'alpha(opacity = 100)';
    element.style.opacity = '0.99999';
    element.style.MozOpacity = '0.99999';
  }
}
function highlightLink(mode, element){
  if (mode == 1){
    element.style.color = linkhighlightcolor;
  }
  else{
    element.style.color = linkcolor;
  }
}
function highlightMenu(mode, element){
  if (mode == 1){
    element.style.color = menuhighlightcolor;
  }
  else{
    element.style.color = menucolor;
  }
}
function highlightPanelLink(mode, element){
  if (mode == 1){
    element.style.color = panellinkhighlightcolor;
  }
  else{
    element.style.color = panellinkcolor;
  }
}
function openEnlargementWindow(type, caption, enlargementname, enlargementwidth, enlargementheight){
  var firefoxindex;
  var firefoxname;
  var htmltext;
  var newwindow;
  var notice;
  var windowheight;
  var windowsettings;
  var windowwidth;
  firefoxname = 'Firefox/';
  firefoxindex = navigator.userAgent.indexOf(firefoxname);
  notice = 'This window closes automatically 30 seconds after opening.';
  if (type == 'I'){
    if (screen.width < 1024 || screen.height < 768){
      if (enlargementwidth >= enlargementheight){
        enlargementheight = Math.floor(enlargementheight * 450 / enlargementwidth);
        enlargementwidth = 450;
      }
      else{
        enlargementwidth = Math.floor(enlargementwidth * 450 / enlargementheight);
        enlargementheight = 450;
      }
    }
    document.getElementById('tablemeasure1').width = enlargementwidth + 4;
    document.getElementById('tablemeasure2').width = enlargementwidth + 4;
    document.getElementById('spanmeasure1').innerHTML = caption;
    document.getElementById('spanmeasure2').innerHTML = notice;
  }
  else{
    document.getElementById('spanmeasure3').innerHTML = caption;
    document.getElementById('spanmeasure4').innerHTML = notice;
  }
  windowwidth = enlargementwidth + 20;
  if (type == 'I'){
    windowheight = enlargementheight + document.getElementById('tdmeasure1').offsetHeight + document.getElementById('tdmeasure2').offsetHeight + 32;
  }
  else{
    windowheight = enlargementheight + document.getElementById('tdmeasure3').offsetHeight + document.getElementById('tdmeasure4').offsetHeight + 32;
  }
  if (firefoxindex != -1){
    windowheight += 2;
  }
  windowsettings = 'left=10, top=10, width=' + windowwidth + ', height=' + windowheight + ', alwaysRaised=1, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0';
  htmltext = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n';
  htmltext += '<html>\n';
  htmltext += '<head>\n';
  if (type == 'I'){
    htmltext += '<title>' + longname + ' - Image enlargement</title>\n';
  }
  else{
    htmltext += '<title>' + longname + ' - Detail enlargement</title>\n';
  }
  htmltext += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n';
  htmltext += '<meta http-equiv="Content-Language" content="en-us">\n';
  htmltext += '<meta http-equiv="ImageToolBar" content="no">\n';
  htmltext += '<style type="text/css">\n';
  htmltext += 'body.window1 {background-color: ' + pagebgcolor + '; color:' + textcolor + '; font-family: Verdana, Arial, Helvetica, sans-serif; margin: 0; padding: 0;}\n';
  htmltext += 'img.window1 {border: 1px solid ' + imageinnerbordercolor + ';}\n';
  htmltext += 'p.window1 {border: 1px solid ' + imageouterbordercolor + '; margin-left: 8px; margin-right: 8px; margin-top: 8px; margin-bottom: 0;}\n';
  htmltext += 'p.window2 {font-size: 12px; margin-left: 8px; margin-right: 8px; margin-top: 8px; margin-bottom: 0;}\n';
  htmltext += 'p.window3 {font-size: 9px; margin-left: 8px; margin-right: 8px; margin-top: 6px; margin-bottom: 6px;}\n';
  htmltext += '.center {text-align: center;}\n';
  htmltext += '</style>\n';
  htmltext += '</head>\n';
  htmltext += '<body class="window1 center" onload="setTimeout(function(){window.close();}, 30000);">\n';
  htmltext += '<table cellpadding="0" cellspacing="0" width="' + windowwidth + '">\n';
  htmltext += '<tr>\n';
  htmltext += '<td class="center">\n';
  htmltext += '<p class="window1"><img class="window1" alt="" src="imagebank/' + enlargementname + '" width="' + enlargementwidth.toString() + '" height="' + enlargementheight.toString() + '"></p>\n';
  htmltext += '<p class="window2">' + caption + '</p>\n';
  htmltext += '<p class="window3">' + notice + '</p>\n';
  htmltext += '</td>\n';
  htmltext += '</tr>\n';
  htmltext += '</table>\n';
  htmltext += '</body>\n';
  htmltext += '</html>';
  newwindow = window.open('', '', windowsettings);
  newwindow.document.open();
  newwindow.document.write(htmltext);
  newwindow.document.close();
  newwindow.focus();
}
function openWebSiteWindow(url){
  var newwindow;
  var windowsettings;
  if (screen.width >= 1024 && screen.height >= 768){
    windowsettings = 'left=10, top=10, width=800, height=600, alwaysRaised=1, location=0, menubar=0, resizable=1, scrollbars=1, status=0, toolbar=1';
  }
  else{
    windowsettings = 'left=10, top=10, width=700, height=500, alwaysRaised=1, location=0, menubar=0, resizable=1, scrollbars=1, status=0, toolbar=1';
  }
  newwindow = window.open(url, 'WebSite', windowsettings);
  newwindow.focus();
}
function postToURL(url){
  document.forms[0].action = url;
  document.forms[0].submit();
}
function preloadImages(){
  var counter;
  for (counter = 0; counter < preloadname.length; ++ counter){
    preloadimage[counter] = new Image();
    if (preloadname[counter] != ''){
      preloadimage[counter].src = 'imagebank/' + preloadname[counter];
    }
    else{
      preloadimage[counter].src = '';
    }
  }
}
function redirect(url){
  window.location.href = url;
}
function setClientDate(){
  var clientdate;
  var currentdate;
  var currentday;
  var currentmonth;
  var currentweekday;
  var currentyear;
  var monthname;
  var weekdayname;
  monthname = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  weekdayname = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  currentdate = new Date();
  currentday = currentdate.getDate();
  currentmonth = monthname[currentdate.getMonth()];
  currentweekday = weekdayname[currentdate.getDay()];
  currentyear = currentdate.getFullYear();
  clientdate = currentweekday + ', ' + currentmonth + '&nbsp;' + currentday + ',&nbsp;' + currentyear;
  document.getElementById('pheader1').innerHTML = clientdate;
}
function setFocus(elementid){
  document.forms[0].elements[elementid - 1].focus();
}
function setOpacity(element, opacity){
  if (opacity == 100){
    document.getElementById(element).style.filter = 'alpha(opacity = 100)';
    document.getElementById(element).style.opacity = '0.99999';
    document.getElementById(element).style.MozOpacity = '0.99999';
  }
  else{
    document.getElementById(element).style.filter = 'alpha(opacity = ' + opacity.toString() + ')';
    document.getElementById(element).style.opacity = (opacity / 100).toString();
    document.getElementById(element).style.MozOpacity = (opacity / 100).toString();
  }
}
function shortenField(field, maxlength){
  var shortenedfield;
  if (field.length <= maxlength){
    shortenedfield = field;
  }
  else{
    shortenedfield = field.substr(0, maxlength - 3);
    if (shortenedfield.charAt(shortenedfield.length - 1) == ' '){
      shortenedfield = shortenedfield.substr(0, shortenedfield.length - 1);
    }
    shortenedfield += '...';
  }
  return shortenedfield;
}
function showMessage(mode, message){
  if (mode == 1){
    document.getElementById('divmessage1').style.visibility = 'visible';
    document.getElementById('spanmessage1').innerHTML = message;
  }
  else{
    document.getElementById('divmessage1').style.visibility = 'hidden';
  }
}
function trim(field){
  var character;
  character = field.charCodeAt(0);
  while (character == 10 || character == 13 || character == 32){
    field = field.substring(1, field.length);
    character = field.charCodeAt(0);
  }
  character = field.charCodeAt(field.length - 1);
  while (character == 10 || character == 13 || character == 32){
    field = field.substring(0, field.length - 1);
    character = field.charCodeAt(field.length - 1);
  }
  field = field.replace(/&/g, '').replace(/</g, '').replace(/>/g, '').replace(/\\/g, '').replace(/{/g, '').replace(/}/g, '');
  return field;
}