// =============================
// MM_swapImgRestore()
// This function replaces one image with another.
function MM_swapImgRestore() 
{
  var i,x,a=document.MM_sr; 
  for(i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++) x.src=x.oSrc;
}

// =============================
// MM_findObj(n, d)
// This function is a helper to replace one image with another.
function MM_findObj(n, d) 
{
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0 && parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  if(!(x=d[n]) && d.all) x=d.all[n]; 
  for (i=0; !x && i<d.forms.length; i++) x=d.forms[i][n];
  for(i=0; !x && d.layers && i<d.layers.length; i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 
  return x;
}

// =============================
// MM_swapImage()
// This function replaces one image with another.
function MM_swapImage() 
{
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0; i<(a.length-2); i+=3)
  if ((x=MM_findObj(a[i]))!=null)
  {
    document.MM_sr[j++]=x; 
    if(!x.oSrc) x.oSrc=x.src; 
    x.src=a[i+2];
  }
}

// =============================
// openNewWindow(mypage, myname, w, h, scroll, resize)
// This function pops up a new window with the supplied properties.
function openNewWindow(mypage, myname, w, h, scroll, resize)
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize+''
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) 
  {
    win.window.focus();
	}
}
// =============================
// replaceAll(oldStr, findStr, repStr)
// This function replaces all instances of findStr in oldStr with repStr.

function replaceAll(oldStr, findStr, repStr) 
{
  var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                    // of oldStr are we searching.
  var newStr = "";  // newStr will hold the altered version of oldStr.
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
                    // As long as there are strings to replace, this loop
                    // will run. 
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
                    // Put it all the unaltered text from one findStr to
                    // the next findStr into newStr.
    newStr += repStr;
                    // Instead of putting the old string, put in the
                    // new string instead. 
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
                    // Now jump to the next chunk of text till the next findStr.           
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
                    // Put whatever's left into newStr.             
  return newStr;
}
// =============================
// getPageElement(eleID)
function getPageElement(eleID)
{
  var ie = document.all ? 1 : 0;
  var ns4 = document.layers ? 1 : 0;
  var dom = document.getElementById ? 1 : 0;

  if (ie || ns4 || dom) 
  {
    var d = document;
    var pageElement = dom ? d.getElementById(eleID) : ie ? d.all[eleID] : d.layers[eleID];
    return pageElement;
  }
}

// =============================
// img_rollover(event, image_id, imageFile)
//
function img_rollover(e, descriptor, image)
{

  e = e ? e : window.event;

  // can do nothing
  if ( !e )
  {
    return;
  }

  // only mouseover and out
  if ( (e.type != 'mouseover') && (e.type != 'mouseout') )
  {
    return;
  }

  var image_to_use = getPageElement(descriptor);

  //if no image provided, do nothing
  if ( image == '' )
  {
    return;
  }
  else
  {
    image_to_use.src = image;
  }
}

// =============================
// clearField(field)
//
function clearField(field)
{
  field.value = "";
}

// =============================
// setParentLocation(url)
//
function setParentLocation(url)
{
  parent.location = url;
}

// =============================
// submitMailForm()
//
function submitMailForm() 
{
  var errorExists = "N";
  var errorMessage = "The following fields must be filled out before the form can be submitted: \n\n";	
  var i = 1;
  var j = 0;
  for ( i = 1; i <= document.mailForm.elements.length; i++ )
  {
    //Ensure that field exists
    if ( document.mailForm.elements["formFieldIsRequired" + i] && 
	 document.mailForm.elements["formFieldName" + i] && 
	 document.mailForm.elements["formFieldValue" + i] )
    {
      if ( document.mailForm.elements["formFieldIsRequired" + i].value == "Y" )
      {
        //check if field has options
        if ( document.mailForm.elements["formFieldValue" + i].type == "select-one" ||
             document.mailForm.elements["formFieldValue" + i].type == "select-multiple" ) 
        {
          j = 0;
          j = document.mailForm.elements["formFieldValue" + i].selectedIndex;
          if ( document.mailForm.elements["formFieldValue" + i].options[j].value == "" )
          {
            errorMessage += document.mailForm.elements["formFieldName" + i].value + "\n";
            errorExists = "Y";
          } 
        }
        else 
        {
          if ( document.mailForm.elements["formFieldValue" + i].value == "" )
          {
            errorMessage += document.mailForm.elements["formFieldName" + i].value + "\n";
            errorExists = "Y";
          }
        }
      }
    }
  }

  if ( errorExists == "Y" )
  {
    window.alert(errorMessage);
  }
  else
  {
    window.alert("Thank you for submitting your information.");
    document.mailForm.submit();
  }
}

// =============================
// jemail(user, domain, suffix, linktext, subject)
//
function jemail(user, domain, suffix, linktext, subject)
{
  var user;
  var domain;
  var suffix;
  var linktext;
  var subject;
  if ( linktext==undefined ) {
    linktext = "";
  }
  if ( subject==undefined ) {
    subject = "";
  }
  if ( subject!="" ) {
    subject = "?subject=" + subject;
  }
  if ( linktext=="" ) {
    document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + subject + '">' + user + '@' + domain + '.' + suffix + '</a>');
  } else {
    document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + subject + '">' + linktext + '</a>');
  }
}
