  function fMax(lang, theElement, maxLength) {
    if (theElement.value.length > maxLength) {
      var message = "You cannot enter more than " + maxLength + " characters."
      if (lang == "FR") message = "Vous ne pouvez pas entrer plus de " + maxLength + " caractères.";
      if (lang == "ES") message = "Usted no puede entrar más de " + maxLength + " caracteres.";
      alert(message);
      theElement.value = (theElement.value.substr(0, maxLength));
      return false;
    } 
    return true;
  }	

  function fMin(lang, theElement, minLength) {
    if (theElement.value.length < minLength) {
      var message = "You must enter at least " + minLength + " characters."
      if (lang == "FR") message = "Vous devez entrer au moinse " + minLength + " caractères.";
      if (lang == "ES") message = "Debe introducir al menos " + minLength + " caracteres.";
      alert(message);
      theElement.focus;
      return false;
    } 
    return true;
  }	

  // if you enter anything then it must be at least minLength characters
  function fMinO(lang, theElement, minLength) {
    if (theElement.value.length < minLength && theElement.value.length > 0) {
      var message = "You must enter at least " + minLength + " characters."
      if (lang == "FR") message = "Vous devez entrer au moinse " + minLength + " caractères.";
      if (lang == "ES") message = "Debe introducir al menos " + minLength + " caracteres.";
      alert(message);
      theElement.focus;
      return false;
    } 
    return true;
  }

  function fCap(theElement) {
    theElement.value = theElement.value.toUpperCase()
    return true;
  }	


  function jconfirm(url,msg) {
    if (confirm (msg)) {
      location=url
    }
  }


  function toggle(theDiv) {
		var divStyle = document.getElementById(theDiv).style;
  	if (divStyle.display != 'block' ) {
  		divStyle.display = 'block';
  	}
  	else {
  		divStyle.display = 'none';
  	}
	}

 
  function divOn(theDiv) {
    var theElement = document.getElementById(theDiv);
    if (theElement != null) theElement.style.display = "block";
  }


  function divOff(theDiv) {
    var theElement = document.getElementById(theDiv);
    if (theElement != null) theElement.style.display = "none";
  }


  function disable(theElement) {
		document.getElementById(theElement).disabled=true;
  }  


  function enable(theElement) {
		document.getElementById(theElement).disabled=false;
  }  

  
  function jPrint() {      
    // hide any buttons
    var theButtons = document.getElementsByTagName("input");
    for (var i=0; i < theButtons.length; i++) {
      if (theButtons[i].type=="button" || theButtons[i].type=="submit" ) {
        theButtons[i].style.visibility='hidden'; 
      }
    }
    // enable any disabled fields so they will print better
    document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/disabled/g,"pooh-disabled");
    // convert any textareas to a div so the entire text will be displayed (IE converts all tags to upper case, FF is lower)
    document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/textarea/g,"pooh:div");
    document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/TEXTAREA/g,"pooh:div");
    // print the page
    parent.main.print();   
    // return the div to the original textarea
    document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/pooh:div/g,"textarea");
    // re-disable any disabled fields so they will print better
    document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/pooh-disabled/g,"disabled");
    // return any buttons
    var theButtons = document.getElementsByTagName("input");
    for (var i=0; i < theButtons.length; i++) {
      if (theButtons[i].type=="button" || theButtons[i].type=="submit" ) {
        theButtons[i].style.visibility='visible'; 
      }
    }
  }        

  

  function hideElement (theElementId) {
    var theElement = document.getElementById(theElementId);
    if (theElement != null) theElement.style.visibility='hidden';
  }


  function showElement (theElementId) {
    var theElement = document.getElementById(theElementId);
    if (theElement != null) theElement.style.visibility='visible';
  }

  
  function emptyField(theElement) {
    document.getElementById(theElement).value = "";
  }    


  function fillField(theElement, theValue) {
    document.getElementById(theElement).value = theValue;
  }    

  
  function refillField(theElement, theValue) {
    if (document.getElementById(theElement).value == "") {
      fillField(theElement, theValue)
    }
  }
  

  function WebService(vUrl, vMsg) {
    var agt    = navigator.userAgent.toLowerCase(); 
    var ie     = (agt.indexOf("msie") != -1); 
    if (ie)
      oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else
      oXmlHttp = new XMLHttpRequest();
    try {
      oXmlHttp.open("POST", vUrl, false);
      oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      oXmlHttp.send(vMsg);    
      return oXmlHttp.responseText;
    }
    catch (err) {
      alert(err);
      return "error using web service";
    }  
  }
  
  
  function jsonWebService(vUrl, vMsg) {
    var agt    = navigator.userAgent.toLowerCase(); 
    var ie     = (agt.indexOf("msie") != -1); 
    if (ie)
      oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else
      oXmlHttp = new XMLHttpRequest();
    try {
      oXmlHttp.open("POST", vUrl, false);
      oXmlHttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      oXmlHttp.send(vMsg);    
      return oXmlHttp.responseText;
    }
    catch (err) {
      alert(err);
      return "error using json web service";
    }  
  }  
  
  //   this is used to render an info item, it displays the appropriate div near the info (exclamation) mark  
  function renderInfo(theElementNo) {

    // this defines the DIV that contains the message
    document.getElementById('div_' + theElementNo).style.padding          = "5px"; 
    document.getElementById('div_' + theElementNo).style.color            = "#008000"; 
    document.getElementById('div_' + theElementNo).style.borderStyle      = "solid"; 
    document.getElementById('div_' + theElementNo).style.borderWidth      = "1px"; 
    document.getElementById('div_' + theElementNo).style.borderColor      = "#008000"; 
    document.getElementById('div_' + theElementNo).style.position         = "absolute";
    document.getElementById('div_' + theElementNo).style.width            = "150px";
    document.getElementById('div_' + theElementNo).style.backgroundColor  = "#D7FFD7";
    document.getElementById('div_' + theElementNo).style.textAlign        = "left";


    // display the div so we can get the size
    toggle('div_' + theElementNo); 

    // determine if we need to position the DIV to the left or right of the info mark (ie the mouse)
    var xPlus = 10; 
    if ((document.body.scrollWidth - window.event.clientX) < 200) { 
      xPlus = - 150 - 10;
    } 

    // determine if we need to position the DIV to the left or right of the info mark (ie the mouse)
    var yPlus = 10;
//  if ((document.body.scrollHeight - window.event.clientY) < document.getElementById('div_' + theElementNo).clientHeight) { 
//    yPlus = - document.getElementById('div_' + theElementNo).clientHeight - 10;
//  }

//  alert('Screen Height: ' + document.body.scrollHeight + '\n Mouse Height: ' + window.event.clientY);

    // rendered the DIV
    document.getElementById('div_' + theElementNo).style.left             = window.event.clientX + xPlus;    
    document.getElementById('div_' + theElementNo).style.top              = window.event.clientY + yPlus;    

  }  
  
  //  this is used on landing pages or anywhere that we want to ensure that the ID/Password is valid
  function idOk (vId) {
    var charsOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_@.";
    var allValid = true;
    for (i = 0;  i < vId.length;  i++) {
      ch = vId.charAt(i);
      for (j = 0;  j < charsOk.length;  j++) {
        if (ch == charsOk.charAt(j)) break;
      }
      if (j == charsOk.length) {
        allValid = false;
        break;
      }
    }
    return allValid;
  }  
  
  
  //  this returns a querystring value and strips off any "+" representing spaces  
  function getParameter(name) {
    var pair=location.search.substring(1).split("&");
    for (var i = 0; i < pair.length; i++) {
      var a = pair[i].split("=");
      var i, n="", v="";
      if (a.length > 0) {
        n=a[0];
        if (n==name) {
          if (a.length > 1) {
            v=unescape(a[1]);
            for (i = 0;  i < v.length; i++) {
              v = v.replace('+', ' ');
            }  
            return v;               
          }  
        }
      }
    }
  }
  
 