function getTimeDiff (t1, t2)
 {
   var d1 = new Date(t1);
   var d2 = new Date(t2);
   var t = d2.getTime() - d1.getTime();
   t = t / (1000 * 60);
   return t;
 }  <!--// Begin
// Take user here after session timed out
timedouturl = "index.php?logout=1";

function Minutes(data) {
  for (var i = 0; i < data.length; i++)
   if (data.substring(i, i + 1) == ":")
   break;
   return (data.substring(0, i));
}
function Seconds(data) {
  for (var i = 0; i < data.length; i++)
  if (data.substring(i, i + 1) == ":")
  break;
  return (data.substring(i + 1, data.length));
}
function Display(min, sec) {
  var disp;
  if (min <= 9) disp = " 0";
  else disp = " ";
  disp += min + ":";
  if (sec <= 9) disp += "0" + sec;
  else disp += sec; 
  return (disp);
}

function Down() { 
  sec--;      
  if (sec == -1) { sec = 59; min--; }
  document.forms[0].clock.value = Display(min, sec);
  window.status = "Session will time out in: " + Display(min, sec);
  if (min == 0 && sec == 0) {
  alert("Your session has been logged out for security reasons");
  window.location.href = timedouturl;
}
  else down = setTimeout("Down()", 1000);
}

function timeIt() {
  min = 1 * Minutes(document.forms[0].clock.value);
  sec = 0 + Seconds(document.forms[0].clock.value);
  Down();
}
//  End -->
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// -------------------------------------------------------------------
// TabNext()
// Function to auto-tab phone field
// Arguments:
//   obj :  The input object (this)
//   event: Either 'up' or 'down' depending on the keypress event
//   len  : Max length of field - tab when input reaches this length
//   next_field: input object to get focus after this one
// -------------------------------------------------------------------
var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
				}
			}
		}
	}


 
//Function by Andre

function checkAll(field)
{
    
   for ( i = 0; i < document.forms[0].elements.length; i++ )

   {

      if (document.forms[0].elements[i].type == 'checkbox')

      {
        
        if (document.forms[0].elements[i].name.indexOf(field) != -1)

        {

          if (document.forms[0].elements[i].checked == true)
          {
            document.forms[0].elements[i].checked = false;
          }
             else
          {
            document.forms[0].elements[i].checked = true;
          }

        }
      

      }

   }

}
function open_window (sname)
{
  open(sname, "content", "toolbar=yes, scrollbars=yes, resizable=yes, width=1024, height=600, top=0, left=0");
}
function roundit(num, places)
{
   times = 10;
   places = places-1;
   for (var i = 0; i < places; i++) times = times * 10; 
   return Math.round(num * times)/times;
}//Function to check values
var FormVerify = Array();

FormVerify['default'] = "Please check that your input is valid!";

function sw_check_values () 
{ 
  var AText; 
  var AForm = document.forms[0];
  for (var i = 0; i < AForm.length; i ++) 
  {  
     if (AForm.elements[i].type == "text" || AForm.elements[i].type == "textarea" || AForm.elements[i].type == "password") 
     { 
       AText = AForm.elements[i]; 
	    
       if (FormVerify[AText.name] != null && AText.name.substring(0, 3) == "edt") 
       {
	   if (AText.name == "edtEMAIL") 
	   { 
		
		if (AText.value.search(/^.+@.+..+$/)) 
		{ 
		  if (FormVerify[AText.name] == null) { window.alert (FormVerify['default']); } else { window.alert (FormVerify[AText.name]); }                   
                  AText.select(); 
                  return false; 
                  break; 
		}
            }	
              else
            {
       	      if (AText.value == "") 
              { 
	        if (FormVerify[AText.name] == null) { window.alert (FormVerify['default']); } else { window.alert (FormVerify[AText.name]); }                   
                AText.select(); 
                return false; 
                break; 
	      }
           }  
				
       }
       
     }   
   } 
   return true;
} 
//function to select first element in a form
function sw_select_first()
{
  var AText;

  var AForm = document.forms[0];
  
  for (var i = 0; i < AForm.length; i ++)
  {
    if (AForm.elements[i].type == "text")
    {
      AText = AForm.elements[i];
      AText.select();
      return true;
      break;
    }
  }
  return false;
}function fireEvent(element,event){
    if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}

