/* SESSION EXPIRATION INFO */

function SessionExpiration()
{
	alert("Your session has expired. Please log in again.");
	window.location = mainurl;
}

if (session_expiration)
{
	window.setTimeout("SessionExpiration()", session_expiration * 1000);
}

/* DEBUG */
function DebugOpen()
{
	dbg = document.getElementById('Debug');
	dbg.style.height = '100px';
	dbg.style.width = '100%';
}

function DebugClose()
{
	dbg = document.getElementById('Debug');
	dbg.style.height = '20px';
	dbg.style.width = '20px';
}

function window_open(url, width, height)
{
	win = window.open(url, '', 'toolbar=0, width=' + width + ',height=' + height + ',left=10,top=10,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1');
}


function SelectAllCheckboxes(v)
{

    var f = document.getElementById('multiaction');
    var c = f.getElementsByTagName('input');
	var chk   = ( v == null ? true : v );

	for (i = 0; i < c.length; i++)
	{
		if( c[i].type == 'checkbox' )
		{
			c[i].checked = chk;
		}
	}

}

/* MUTLIACTION CONTROL */
function CheckMultiAction()
{

    var f = document.getElementById('multiaction');
    var c = f.getElementsByTagName('input');
    var checkbox_counter = 0;

	for (i = 0; i < c.length; i++)
	{
		if( c[i].type == 'checkbox' && c[i].checked == true )
        {
			  checkbox_counter++;
		}
	}

    if ( checkbox_counter > 0 && f.MultiActionType.value != 'none')
    {
        return true;
    }
    else
    {
        alert('Select tickets by checking checkboxes and choose action for them.');
        return false;
    }

}

/* IE HACK */
function HideMultiActionType()
{

        document.getElementById("MultiActionType").style.visibility="hidden";

}

function ShowMultiActionType()
{

        document.getElementById("MultiActionType").style.visibility="visible";

}

/* JS PAUSE - source: http://ourworld.cs.com/tcmits1/javascript/papers/pause/pause.html */

   /** constructor 
   
       @param duration integer seconds
       @param <optional> function to run while waiting.
       
    */
   function Pause(duration, busy){
      this.duration= duration * 1000;
      this.busywork = null; // function to call while waiting.
      this.runner = 0;

      if (arguments.length == 2) {
         this.busywork = busy;
      }

      this.pause(this.duration);

   } // Pause class

   /** pause method 
   
       @param duration: integer in seconds
       
    */
   Pause.prototype.pause = function(duration){
      if ( (duration == null) || (duration < 0)) {return;}

      var later = (new Date()).getTime() + duration;

      while(true){
         if ((new Date()).getTime() > later) {
            break;
         }

         this.runner++;

         if (this.busywork != null) {
            this.busywork(this.runner);
         }

      } // while

   } // pause method

/* http://www.quirksmode.org/js/mailcheck.html - checkMail function */

function checkMail(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (filter.test(email))
	{
        return true;
	}
	else
	{
        return false;
	} 
}
