
function logout(){
  if(confirm('Are You Sure You Want To Log Out?')){
    top.location = 'logout.asp';
  }
}

function cancelEdit(returnURL){
  if(confirm('Are you sure you want to leave this page?\nYou will lose any changes you haven\'t saved.')){
    top.location = returnURL;
  }
}

function confirmDelete(strConf,returnPage,returnQuery){
  if(confirm('Are you sure want to delete this item?\nThis CANNOT be undone!')){
    top.location=returnPage+'?action=delete&id='+strConf+'&QReturn='+returnQuery;
  }
}

if(document.all && !document.getElementById) {
  document.getElementById = function(id) {
    return document.all[id];
  }
}

function sendMsg(a,b){
  message = window.open('messagepopup.asp?to='+a+'&n='+b,'message','width=400,height=300,toolbar=no,menubar=no,statusbar=no');
}

function reportError(a,b){

  if(document.getElementById('content')){
    pageText = document.getElementById('content').innerHTML;
    stringPos = pageText.length-300;
    stringPos = pageText.indexOf('<font face="Arial" size="2">');
    if(stringPos > -1){
      rx = /<\S[^><]*>/g;
      c = pageText.substring(stringPos,pageText.length);
      c = c.replace(rx, " ");
    }
  }

  message = window.open('errorreport.asp?url='+a+'&bug='+b+'&errMsg='+c,'message','width=400,height=400,toolbar=no,menubar=no,statusbar=no');
}

function checkStrength(what){
  var iStrength = 0;
  strPassword = what;
  var regexp = new RegExp("[a-z]");

  if (regexp.test(strPassword)){
    iStrength++;
  }

  var regexp = new RegExp("[0-9]");

  if (regexp.test(strPassword)){
    iStrength++;
  }

  var regexp = new RegExp("[\.\!\?\@\'\"\#\*\<\>\,\$\£\%\^\&\(\)\~\_\-]");

  if (regexp.test(strPassword)){
    iStrength++;
  }

  if(strPassword.length > 4 && iStrength> 0)
  {
    iStrength++;
  }

  if(strPassword.length > 7 && iStrength> 0)
  {
    iStrength++;
  }
  if(iStrength > 5){iStrength = 5;};
  imgBar = document.getElementById("bar")
  imgBar.src = 'images/rating' + iStrength + '.gif'

}


function tickAllDays(item){
  if(item.checked){
    for(i=0;i<document.forms[0].Available.length;i++){
      document.forms[0].Available[i].checked=true;
     };
   }else{
    for(i=0;i<document.forms[0].Available.length;i++){
      document.forms[0].Available[i].checked=false;
    };
  };
}



if (document.getElementsByTagName) {
  var inputElements = document.getElementsByTagName("input");
  for (i=0; inputElements[i]; i++) {
    if (inputElements[i].className && (inputElements[i].className.indexOf("disableAutoComplete") != -1)) {
      inputElements[i].setAttribute("autocomplete","off");
    }//if current input element has the disableAutoComplete class set.
  }//loop thru input elements
}//basic DOM-happiness-check



var reqXML;

function LoadXMLDoc(url){
  if (window.XMLHttpRequest){ //Mozilla, Firefox, Opera 8.01, Safari
    reqXML = new XMLHttpRequest();
    reqXML.onreadystatechange = BuildXMLResults;
    reqXML.open("GET", url, true);
    reqXML.send(null);
  }
  else if(window.ActiveXObject){ //IE
    reqXML = new ActiveXObject("Microsoft.XMLHTTP");
    if (reqXML) {
      reqXML.onreadystatechange = BuildXMLResults;
      reqXML.open("GET", url, true);
      reqXML.send();
    }
  }
  else{ //Older Browsers
    alert("Your Browser does not support Ajax!");
  }
}

function BuildXMLResults(){
  if(reqXML.readyState == 4){ //completed state
    if(reqXML.status == 200){ //We got a sucess page back

      //Check to verify the message from the server
      if(reqXML.responseText.indexOf("Session Updated - Server Time:") == 0){
        window.status = reqXML.responseText; //display the message in the status bar
        keepAlive(); //restart timer
      }
      else{
        //display that that session expired
        alert("UH-OH!\nYour session appears to have already expired. You may lose your current data if you try to save any changes.\n\nIt might be useful to copy any information into another program and re-log in.");
      }
    }
    else{
      //display server code not be accessed
      alert("There was a problem retrieving the XML data:\n" + reqXML.statusText + "\n\nWe recommend saving your changes before continuing.");
    }
  }
}

function ConfirmUpdate(){
  //Ask them to extend
  if(confirm("WARNING!\nYour PIMS session is about to expire. You may lose information if you submit information after it has expired.\nIf you are still working on a document you can keep your session active by pressing 'OK'.")){
    //load server side page if ok
    LoadXMLDoc('keepalive.asp');
  }
}
