/* public web pages functions :- all javascript in one file
   main.js
   print.js
   menu.js
   cookies.js
   dropdowns.js
   tree.js
*/



/* main.js start */

/************************** START GLOBAL JS FUNCTIONS **************************/
function divStyle(theDiv)
{
if (document.getElementById) return document.getElementById(theDiv).style;
return eval("document."+((document.all)?"all."+theDiv+".style":theDiv));
}
function clipDiv(thisDiv,cT,cR,cB,cL)
{
if (document.all || document.getElementById) divStyle(thisDiv).clip = "rect("+cT+" "+cR+" "+cB+" "+cL+")";
else
{
divStyle(thisDiv).clip.top = cT;
divStyle(thisDiv).clip.bottom = cB;
divStyle(thisDiv).clip.left = cL;
divStyle(thisDiv).clip.right = cR;
}
}
function showDiv(thisDiv)
{
if (document.getElementById) node=document.getElementById(thisDiv).style.visibility='visible';
else divStyle(thisDiv).visibility = "visible"
}
function hideDiv(thisDiv)
{
if (document.getElementById) node = document.getElementById(thisDiv).style.visibility='hidden';
else divStyle(thisDiv).visibility=(document.all)?"hidden":"hide";
}
function _go(fName,sName,div) {
if (document.layers && div){
if (eval("document." + div + ".document." + fName + "." + sName + ".options[document." + div + ".document." + fName + "." + sName + ".selectedIndex].value"))
location.href=eval("document." + div + ".document." + fName + "." + sName + ".options[document." + div + ".document." + fName + "." + sName + ".selectedIndex].value");
} else {
if (eval("document." + fName + "." + sName + ".options[document." + fName + "." + sName + ".selectedIndex].value"))
location.href=eval("document." + fName + "." + sName + ".options[document." + fName + "." + sName + ".selectedIndex].value");
}
}
/*************************************************/
var mfBannerIndex = 2;
function mfBannerChange2() {
var nxtBan, prevBan;
var vis;
vis = mfBannerIndex - 1;
if (vis == 0) vis = 6;
nxtBan = "ban" + mfBannerIndex;
prevBan = "ban" + vis;
if (document.all){
eval ("document.all." + nxtBan + ".style.visibility = 'visible'");
eval ("document.all." + prevBan + ".style.visibility = 'hidden'");
} else {
eval ("document." + nxtBan + ".visibility = 'visible'");
eval ("document." + prevBan + ".visibility = 'hidden'");
}
mfBannerIndex++;
if(mfBannerIndex > 6)
mfBannerIndex = 1;
}
function startBan(){
if (document.all){
document.all.ban1.style.visibility = 'visible';
} else {
document.ban1.visibility = 'visible';
}
setInterval("mfBannerChange2()", 3000);
}
/****************************************** NS Resize Script */
if (document.layers)
{
origWidth = innerWidth;
origHeight = innerHeight;
}
function resizeDetected()
{
if (document.layers)
{
if (innerWidth != origWidth || innerHeight != origHeight)
{
// location.reload();
location.href = location.href;
}
}
}

    function expandCollapseLayers(name, collapseOthers) {
	targetId = "div_" + name;
        targetElement = document.all(targetId);
        if (targetElement.style.display == "none")
          targetElement.style.display = "";
        else
          targetElement.style.display = "none";

	//collapse other layers starting 'div_'

        if (targetElement.style.display == "none" || !collapseOthers)
          return;

	var objLayers = document.getElementsByTagName('DIV');
	for (var i=0;i<objLayers.length; i++)
	  if (objLayers[i].id.substring(0,4)=='div_' && objLayers[i].id != 'div_'+name)
	    objLayers[i].style.display = "none";
    }


    //insert into textarea. IE support only
    function insertAtCursor(oTA, val) {
	if (document.selection) {
		oTA.focus();
		sel = document.selection.createRange();
		sel.text = val;
	}
    }

    //insert link into texterea. IE support only
    function insertLinkIntoTextArea(oTA, url1) {
	if (document.selection) {
	  oTA.focus();
	  sel = document.selection.createRange();

	  var fullurl;
	  if (url1.indexOf('www.')==0)
	    fullurl = 'http://' + url1;
	  else
	    fullurl = '/' + url1;	// doesnt work on XP

	  if (sel.text != '')
	    sel.text = '<a href="' + fullurl + '">' + trimString(sel.text) + '</a> ';
	  else
	    sel.text = '<a href="' + fullurl + '">' + url1 + '</a> ';
	}
    }

    function trimString (str) {
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
    }



/************************** END GLOBAL JS FUNCTIONS **************************/

/* main.js end */

/* print.js start */

var gAutoPrint = true; // Flag for whether or not to automatically call the print function


// printSpecial
// first, try to find the IFRAME and print contents
// otherwise, find the print DIV Tags and print contents
// otherwise, print the complete window

function printSpecial() {
	if (document.getElementById != null) {
	  if (document.IFRAME || window.frames['IFRAME']) {
		window.status = 'print iframe';
	  	printiframe();
	  } else {
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null) {
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}

		html += '\n</HE' + 'AD>\n<BODY>\n';

		var printReadyElem = document.getElementById("printReady");

		if (printReadyElem != null) {
				html += printReadyElem.innerHTML;
		} else {
			window.status = 'print complete window';
			window.print();
			return;
		}
		window.status = 'print div area';
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';

		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	  }
	} else {
		alert('Sorry, the print feature is only available in modern browsers');
	}
}


function CheckIsIE() {
  return (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER');
}


function printiframe() {
  if (CheckIsIE()) {
	document.IFRAME.focus();
	document.IFRAME.print();
  } else {
	window.frames['IFRAME'].focus();
	window.frames['IFRAME'].print();
  }
}

/* print.js end */


/* menu.js start */

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

/* [MODIFIED] This code commented out, not needed for activate/deactivate
   on mouseover.

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element that was clicked on.

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  // If the active button was clicked on, exit.

  if (el == activeButton)
    return;

  // If the element is not part of a menu, reset and clear the active
  // button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

[END MODIFIED] */

function buttonClick(event, menuId) {
  var button;

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.

  button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;

  // Exit if this button is the currently active one.

  if (button == activeButton)
    return false;

  // [END MODIFIED]

  // Reset the currently active button, if any.

  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {
  var button;

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Activates this button's menu if no other is currently active.

  if (activeButton == null) {
    buttonClick(event, menuId);
    return;
  }

  // [END MODIFIED]

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

  button.className += " menuOptionActive";

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  // For IE, adjust position.

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuOptionActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {

  var item, menu, x, y;

  // Find the target item element and its parent menu element.

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  // Close any active sub menu and mark this one as active.

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  // Highlight the item element.

  item.className += " menuItemHighlight";

  // Initialize the sub menu, if not already done.

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the sub menu, if not already done.

  if (item.subMenu.onmouseout == null)
    item.subMenu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Get position for submenu based on the menu item.

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE) {
    maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
      (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
      (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  // Position and show the sub menu.

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";

  // Stop the event from bubbling.

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

// [MODIFIED] Added for activate/deactivate on mouseover. Handler for mouseout
// event on buttons and menus.

function buttonOrMenuMouseout(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element the mouse is moving to.
  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
      el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // If the element is not part of a menu, reset the active button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

// [END MODIFIED]

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  // For items with arrows, add padding to item text to make the
  // arrows flush right.

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // Mark menu as initialized.

  menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

/* menu.js end */



/* cookies.js start */

  // Set a cookie given a name, value and expiration date.

  function setCookie (name, value, expires) {
    var cookie = escape(name) + "=" + escape(value);
    cookie += "; expires=" + expires.toGMTString();
    cookie +=  "; path=/";

    document.cookie = cookie;
  }


  // Returns the value of the named cookie.

  function getCookieValue(name) {

    var search, cookieValue;

    cookieValue = "";

    search = name + "=";
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
        end = document.cookie.length;
        cookieValue = unescape(document.cookie.substring(offset, end));
    }
    return cookieValue;
  }


  // Delete the named cookie.

  function deleteCookie(name) {

    var expdate = new Date();
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    setCookie(name, "", expdate);
  }

/* cookies.js end */



/* dropdowns.js start */

  // removes items from a select box. removes all unless a range is supplied
  function removeItems(fromCtrl, idxFrom, idxTo) {
    var from;
    var to;
    var l = fromCtrl.options.length;
    if (!idxFrom) from = 0; else from = idxFrom;
    if (!idxTo) to = l; else to = idxTo;

    for (i = from; i < to; i++)
      fromCtrl.options[fromCtrl.options.length - 1] = null;
  }


  // removes Item(s) from a select box by locating its value
  function removeItemByValue(ctrl, val, newIdx) {
    for (var i = 0; i < ctrl.options.length; i++)
      if (ctrl.options[i].value == val)
        ctrl.options[i] = null;
    if (newIdx) ctrl.selectedIndex = newIdx;
  }


  // adds an item to a select box at end
  function addItem(toCtrl, value, name) {
    var nextitem = toCtrl.options.length;
    toCtrl.options[nextitem] = new Option(name);
    toCtrl.options[nextitem].value = value;
  }

  // transfers items from one select box to another (uses spacer-node)
  function moveItems(FromItem, ToItem) {
    var spacerName, aNode, v, n;
    var fromCount = FromItem.options.length;

    for (var i=0; i<fromCount; i++) {
      v = FromItem.options[i].value;
      n = FromItem.options[i].text;

      if (v != '') {
        if (FromItem.options[i].selected) {

	  //remove spacer option from To-dropdown
	  spacerName = ToItem.options[ToItem.options.length-1].text;
	  removeItemByValue(ToItem, '');

	  //remove option from from-box
	  removeItemByValue(FromItem, v);

	  //and add to to to-box
	  addItem(ToItem, v, n);

	  //put spacer option back
	  addItem(ToItem, '', spacerName);

	  fromCount = FromItem.options.length;
	  i--;
	}
      }
    }
  }

/* dropdowns.js end */




/* tree.js start */

    function clickHandler() {

      var targetID, srcElement, theLayer, theImage;
      srcElement = window.event.srcElement;

      if (srcElement.className == "tree")
        targetID = srcElement.id;
      else if (srcElement.className == "treeLabel")
        targetID = srcElement.id.replace('Label','');
      else
      	return;

      for (var i=0;i<document.images.length;i++)
	if (document.images[i].id == targetID) {
	  theLayer = document.all(targetID + 'V');
	  theImage = document.images[i];
	}

      if (theLayer.style.display == "none") {
           theLayer.style.display = "";
           theImage.src = theImage.src.replace('open.gif','close.gif');
      } else {
           theLayer.style.display = "none";
           theImage.src = theImage.src.replace('close.gif','open.gif');
      }
    }

    document.onclick = clickHandler;

/* tree.js end */


/* functions.js start */

/* general javascript functions */

    //openWin
    //open a window of specified size and position.
    //prevent multiple opens

    var theWin;
    function openWin (file, w, h, x, y, params) {
      if (theWin && theWin.open && !theWin.closed) {
      	//window is open
      } else {
	//open window
        if (!x) x=screen.width/2 - w/2;
        if (!y) y=screen.height/2 - h/2;
        if (!params)
          params = 'scrollbars=no,toolbar=no,menubar=no,location=no,left=' + x + ',top=' + y + ',height=' + h + ',width=' + w;
        else
          params = params + ',left=' + x + ',top=' + y + ',height=' + h + ',width=' + w;
        theWin = window.open(file, '', params)
      }
    }

    //openModelessWin
    //open a modeless window of specified size
    function openModelessWin(url,w,h) {
      if (document.all && window.print) //ie5
        eval('window.showModelessDialog(url,"","help:0;resizable:1;dialogWidth:'+w+'px;dialogHeight:'+h+'px")')
      else
        eval('window.open(url,"","width='+w+'px,height='+h+'px,resizable=1,scrollbars=1")')
    }


  // add an element to an array at the specified index

  function addElement(arr, idx, val) {
    var size = arr.length;
    for (var i=arr.length+1;i>idx; i--)
      arr[i] = arr[i-1];
    arr[idx] = val;
    arr.length = arr.length-1;
  }


  // delete the specified index from an array

  function deleteElement(arr, idx) {
    var size = arr.length;
    for (var j=idx;j<size-1;j++)
      if (j != size) arr[j] = arr[j+1];
    arr.length = size - 1;
  }


   // delete the specified range of indices from an array

  function deleteElementRange(arr, idx1, idx2) {
    var range;
    var size = arr.length;

    if (idx2>=size) idx2=size-1;
    range = idx2-idx1+1;

    var d = 0;
    for (var j=idx2;j<size-1;j++) {
      if (idx2+d<size) arr[idx1+d] = arr[idx2+d+1];
      d++;
    }
    arr.length = size - range;
  }


  function isvalidtime(timStr) {
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
    var matchArray = timStr.match(timePat);
    if (matchArray == null) {
      return "time format must be '00:00'";
    }
    hour = matchArray[1];
    minute = matchArray[2];

    if (hour < 0  || hour > 23) {
      return "hours must be between 0 and 23";
    }
    if (minute<0 || minute > 59) {
      return "minutes must be between 0 and 59.";
    }
    return "";
  }


  function isEmail (str) {
    // are regular expressions supported?
    var supported = 0;
    if (window.RegExp) {
      var tempStr = "a";
      var tempReg = new RegExp(tempStr);
      if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported)
      return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
  }


  function isDNS (strDNS) {
    //var DNSpattern=/^(\w{1,30})\.(\w{1,30})\.(\w{1,3})?$/;
    //return (patternMatches(strDNS, DNSpattern));
    return (strDNS.length > 6);
  }


  function isIP (strIP) {
    var IPpattern=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})?$/;
    return (patternMatches(strIP, IPpattern));
  }

  function isYear (val) {
    var ch;
    var digits = '0123456789';
    for (var i=0;i<val.length;i++) {
      ch = val.substring(i,i+1);
      if (digits.indexOf(ch)==-1)
        return false;
    }
    return (val.length == 4);
  }

  function isNumber (val) {
    var ch;
    var digits = '0123456789. ';
    for (var i=0;i<val.length;i++) {
      ch = val.substring(i,i+1);
      if (digits.indexOf(ch)==-1)
        return false;
    }
    return true;
  }


  function isSMS (val) {
    var ch;
    var digits = '0123456789+ ';
    for (var i=0;i<val.length;i++) {
      ch = val.substring(i,i+1);
      if (digits.indexOf(ch)==-1)
        return false;
    }
    return true;
  }

  function isBlank(val) {
    var ch;
    for (var i=0;i<val.length;i++) {
      ch = val.substring(i,i+1);
      if (ch != ' ')
        return false;
    }
    return true;
  }


  // isValidDate
  // returns true when date has format dd/mm/yyyy
  function isValidDate(strDate) {
    var DatePattern=/^(\d{1,2})\/(\d{1,2})\/(\d{4})?$/;
    return (patternMatches(strDate, DatePattern));
  }


  // match a string to a pattern
  // examples
  // /^(\d{1,6})?(.(\d{1,2}))?$/;	// 9, 9.9, 9.99, 99.99 - 999999.99
  // /[a-z]{3}\d{2}/i;			// XXX99, ABC01

  function patternMatches (str, pattern) {
    var res = str.match(pattern);
    return (res != null);
  }



  function findObjectByName(obj, name, tagType) {
	    var objList = obj.getElementsByTagName(tagType);
	    for (var i = 0; i < objList.length; i++)
	      if (objList[i].id == name) {
		alert(objList[i].id);
	        //return objList[i];
	      }
  }


  // startSessionMonitor
  // starts a timer that warns after x minutes if the page has not been submitted
  function startSessionMonitor(numMinutes) {
    setTimeout('warnSession(' + numMinutes + ')', numMinutes*1000*60);
  }

  // warnSession
  // pops up the session expire warning page
  function warnSession(numMinutes) {
    openWin('sessionexpire.asp?m='+numMinutes, 300, 100)
  }

  function saveWinPosition(cookieName) {
    var date = new Date();
    date.setTime (date.getTime() + (86400 * 1000 * 60));  // 60 days

    var xadjustment = -3;
    var yadjustment = -22;
    var winx = self.window.screenLeft + xadjustment;
    var winy = self.window.screenTop + yadjustment;

    setCookie(cookieName + '_x', winx, date);
    setCookie(cookieName + '_y', winy, date);
  }

  function confirmnavigate(msg, urlpath) {
    if (confirm(msg))
      document.location.href = urlpath;
  }

/* functions.js end */
