/*
'======================================================================
' AUTHOR: Tim Sewell
' OVERVIEW: 
' Javascript functions
'
' MODIFICATION DETAILS (LAST 2)
' LAST EDITED: Tim Sewell - 28/04/2004
' COMMENTS:
' 
'======================================================================
*/

/*======================================================================
								OPEN POPUP WINDOWS
======================================================================*/

var wHeight = screen.height
var wWidth = screen.width

function goNextPage(page,firstPage,lastPage)
{
	var currPage = nextPage.page.value;
	nextPage.page.value = Number(page);
	nextPage.firstPage.value = Number(firstPage);
	nextPage.lastPage.value = Number(lastPage);
	nextPage.submit();
}


function reorderResults(frmName,frmField,orderBy)
{
	
	var frm = document.forms[frmName];
	var elem = document.forms[frmName].elements[frmField];
	elem.value = orderBy;
	frm.submit();
	
}

function showFormProcessing()
{	

	if (document.getElementById('formSubmitButtons'))
	{
		
		document.getElementById('formSubmitButtons').style.display = 'none';

		if (document.getElementById('formSubmitProcessing'))
		{
		document.getElementById('formSubmitProcessing').style.display = 'inline';
		}
	}
}


function reloadOpenerAndClose()
{
	if ( window.opener && !window.opener.closed )
	{
		if (window.opener.nextPage)
			window.opener.nextPage.submit();
		else
			window.opener.location.reload();
			
		window.opener.focus();
	}
	
	window.close();
}


function closeAndFocusOpener()
{
	
	if ( window.opener && !window.opener.closed )
	{
		window.opener.focus();
	}
	window.close();
}


function popupMainWindow(url,height,width) 
{
	var isHeight=Number(height);
	var isWidth=Number(width);
	var wTop = (wHeight - isHeight) / 2
	var wLeft = (wWidth - isWidth) / 2
	mainWindow  =   window.open(url,"mainWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+'px,height='+isHeight+'px,top='+wTop+',left='+wLeft);
	mainWindow.focus();
}

function popupMainWindow1(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  mainWindow1  =   window.open(url,"mainWindow1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  mainWindow1.focus();
}

function popupMainWindow2(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  mainWindow2  =   window.open(url,"mainWindow2",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  mainWindow2.focus();
}

function popupMainWindow3(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  mainWindow3  =   window.open(url,"mainWindow3",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  mainWindow3.focus();
}

function popupPrintWindow(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  printWindow1  =   window.open(url+"&popup=1","printWindow1",'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  printWindow1.focus();
  printWindow1.print();
}

function centerScreen(xWidth,xHeight)
{
	var uAgent = navigator.userAgent
	if(uAgent.indexOf("Windows NT 5.1")!=-1)
	{
		xHeight = xHeight+30;
	}
	window.resizeTo(xWidth,xHeight);
	var wHeight = screen.height-xHeight;
	var wWidth = screen.width-xWidth;
	window.moveTo(wWidth/2,wHeight/2);
}

/*======================================================================
								CHECK FOR DIGITS
======================================================================*/

function isDigits(str) {
	var i
	for (i = 0; i < str.length; i++) {
		mychar = str.charAt(i)
		if ((mychar < "0" || mychar > "9") && mychar !=".")
			return false;
	}
	return true;
}

function IsNumeric(strString)
  //  check for valid numeric strings	
  {
  var strValidChars = "0123456789.-";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;
  }

/*======================================================================
								CHECK FOR VALID EMAIL
======================================================================*/

function checkemail(s)
{
    var str = s;
    var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (filter.test(str))
        testresults=true
    else
    {
        testresults=false
    }
    return (testresults)
}

function checkPassword(txtField) 
    {
	
	var error = 0;
	var errorChar = 1;
	var errorNum = 1;
	var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWQYZ1234567890";
	var reNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWQYZ"
	var reAlph = "1234567890"

	var password = txtField.value;

	// iterate through string and check against allowed character list
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (validChars.indexOf(c) == -1)
		{
			error = 1;
			break;
		}
	}
	
	// check to make sure contains numbers and characters
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (reNum.indexOf(c) != -1)
		{
			errorChar = 0;
			break;
		}
	}
	// check to make sure contains numbers and characters
	for (x=0; x<password.length; x++)
	{
		c = password.charAt(x);
		if (reAlph.indexOf(c) != -1)
		{
			errorNum = 0;
			break;
		}
	}

	// display appropriate message
	

	if ((error == 1) || (password.length < 6) || (errorChar == 1) || (errorNum == 1))
	{
		alert("The PASSWORD must be a minimum of 6 characters and contain a mixture of letters and numbers")
		txtField.focus();
		return false;
	}
	else
		return true;
}

function checkLimit(txtField, prompt, minchars, maxchars) 
{
	if (txtField.value == ''){alert("Please enter data for "+prompt);txtField.focus();return false;}
	else
	{
		if(txtField.value.length < minchars || txtField.value.length > maxchars)
		{
			alert(prompt+" length should be between "+minchars+" to "+maxchars+" characters.");
			txtField.focus();
			return false;
		}
		else return true;
	}
}

function leftTrim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

