// include this to use  <script src="/js/routines.js"></script> 

// steen was here

/* Ensure html page enters https
<head>
   <script src="/js/routines.js"></script> 
   gotoHttps();
 <head>
*/
 function gotoHttps(){
    loc = document.location.toString();
    if ('localhost' != loc.substring(7, 16)) {	
      index = loc.indexOf(":");
      if ('4'==index) {
        url = loc.substring(index,loc.length);
        secureUrl = "https" + url;
        location.replace(secureUrl);
        location.href = secureUrl;
      }
    } 
  }  
  
/* Find the value of a radio button, via NAME not id 
   var radioValue=getRadioValue('radioName');   // This will check all forms on a page
   
   var radioValue=getRadioValue('radioName', 'formName');  // This will only check one form
*/

  function getRadioValue(radioName, formName){
    if (1==arguments.length){
      var foundRadio=false;
      for (var formCount=document.forms.length-1; -1<formCount; formCount--){
        if ('undefined'!=typeof(document.forms[formCount].elements[radioName])){	
          var radioObject=document.forms[formCount].elements[radioName];          // var radioValue=getRadioValue('radioName'); 
          foundRadio=true;
          break;
        }
      }
      if (!foundRadio){
        alert('getRadioValue(' + radioName + ') did not find a matching radiobutton');
        return -1;
      }
    }
    else{
      var radioObject=document.forms[formName].elements[radioName];    //  var radioValue=getRadioValue('radioName', 'formName'); 
    }
    
    for (var i=radioObject.length-1; -1<i; i--){
      if (radioObject[i].checked){
        return radioObject[i].value;
      }
    }
    return 0;
  }

  function setRadioValue(radioName, onValue, formName){
    if (2==arguments.length){
      var foundRadio=false;
      for (var formCount=document.forms.length-1; -1<formCount; formCount--){
        if ('undefined'!=typeof(document.forms[formCount].elements[radioName])){
          var radioObject=document.forms[formCount].elements[radioName];          // var radioValue=getRadioValue('radioName', 1);
          foundRadio=true;
          break;
        }
      }
      if (!foundRadio){
        alert('setRadioValue(' + radioName + ') did not find a matching radiobutton');
        return -1;
      }
    }
    else{
      var radioObject=document.forms[formName].elements[radioName];    //  var radioValue=getRadioValue('radioName', 1,'formName');
    }

    for (var i=radioObject.length-1; -1<i; i--){
      if (radioObject[i].value==onValue){
        radioObject[i].checked=true;
        return 0;
      }
    }
    alert('setRadioValue(' + radioName + ') did not find a matching radiobutton value');
    return -1;
  }


/* 
  
// Include the below <noscript> in every web page, after the <body> tag that uses javascript so the user has a chance to turn it on
  <body>
  
  <noscript>
<div align="center">
  <p><br><font color="#FF0000">Your browser does not support Javascript, this page will not display properly. </font></p>
  <p align="left">To turn on Javascript follow the steps below:</p>
  <div align="left">
    <ol>
      <li>Click on 'Tools' on the Internet Explorer's menu, and select 'Internet Options'</li>
      <li>In the new dialog choose the 'Security' tab</li>
      <li>Select the Internet, the first icon, displayed as Earth</li>
      <li>In the lower middle section click on the 'Custon Level...' button</li>
      <li>Enable the 'Scripting, Active scripting' setting near the end of the list</li>
    <li>Save change with 'OK', 'Yes' and a final 'Ok'</li>
      <li><a href="index.htm">Restart application again by clicking here</a></li>
    </ol>
  </div>
</div>
</noscript>
      



*/


// onKeyUp=" this.value=intMaxVal(99, this.value) "  // in javascript
// Do not forget to set MAXLENGTH="2" inside the <INPUT element>
function intMaxVal(maxValue, theValue){
  regExp=/^\d*$/;
  while (!regExp.test(theValue) && 0<theValue.length){  // Check a number
    theValue=theValue.slice(0, -1);
  }

  if (!isNaN( parseInt(theValue, 10))){
    theValue=parseInt(theValue, 10);                        // Change 09 to 9
    if ( maxValue<theValue){  // Check max
      theValue=maxValue;
    }  
  }  
  return theValue;
}



function startLogOutCountDown(logOutPage, secondsToLogout, theForm){
  if (2==arguments.length){
    var funcLogOut= function(){
                      location.replace(logOutPage);
                    };
  }
  else{
    var funcLogOut= function(){
                      document.forms[theForm].action=logOutPage;
                      document.forms[theForm].submit();
                    };   
  }
  return setTimeout(funcLogOut, secondsToLogout*1000);  // Return the function so clearTimeout() can be used by caller
}

// This function is for IE to change a password input box into a text box
function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}


function includeJavaScript(jsFile){
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>');
}






