/*
'======================================================================
' AUTHOR: Tim Sewell
' OVERVIEW: 
' Javascript functions
'
' MODIFICATION DETAILS (LAST 2)
' LAST EDITED: Tim Sewell - 28/04/2004
' COMMENTS:
' 
'======================================================================
*/
function printWin()
{
	var url = window.location.href;

   	var iChars = "?";
	var ok = 1;

	for (var i = 0; i < url.length; i++) {
		if (iChars.indexOf(url.charAt(i)) != -1)
			ok = 0;
	}

	if (ok == 1)
		url = url+"?popup=1"
	else
		url = url+"&popup=1"
		
	popupPrintWindow('',500,600)
	

	if (document.all.excelFrm)
	{
		excelFrm.popup.value=1;
		excelFrm.target='printWindow';
		excelFrm.submit()
	}
	else
		printWindow.location.href=url;
	
}

function excelWin()
{
	if (window.listInput)
		var url = window.listInput.location.href;
	else
		var url = window.location.href;

   	var iChars = "?";
	var ok = 1;

	for (var i = 0; i < url.length; i++) {
		if (iChars.indexOf(url.charAt(i)) != -1)
			ok = 0;
	}

	if (ok == 1)
		url = url+"?popup=1&excel=1"
	else
		url = url+"&popup=1&excel=1"
		
	popupPrintWindow('',500,600)
	if (document.all.excelFrm)
	{
		excelFrm.excel.value=1;
		excelFrm.popup.value=1;
		excelFrm.target='printWindow';
		excelFrm.submit()
	}
	else
		printWindow.location.href=url;

}

function showButton(Elem)
{
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	
	if(elem)
	{
		elem.style.display='inline';
		excelGrey.style.display='none';
	}
}

//======================================================
//	popup DHTML searchbox
//======================================================
function getElementLeft(Elem) {

		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;

}


function getElementTop(Elem) {

		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;

}

function showPopUpSearchBox(Elem,xOffset,yOffset,whatBox)
{
	var whatBox = document.getElementById(whatBox).style
	
	var searchBoxWidth = whatBox.width;
	searchBoxWidth = searchBoxWidth.replace('px','')
	var x = getElementLeft(Elem)
	var y = getElementTop(Elem)
	x = x - Number(searchBoxWidth) + Number(xOffset);
	y = y + Number(yOffset)

	if((x!='') && (y!=''))
	{
		whatBox.left = x;
		whatBox.top = y;
	}
	

	if (cSearch.searchterm)
		cSearch.searchterm.value='';
	
	if(whatBox.visibility=='visible')
		whatBox.visibility='hidden';
	else {
		whatBox.visibility='visible';
	}
}

function checkKeyInputForPopUpSearchBox(Elem,xOffset,yOffset,whatBox)
{
	if(event.keyCode == 13)
	{
		cSearch.submit();
		showPopUpSearchBox(Elem,xOffset,yOffset,whatBox)
	}
}

/*======================================================================
								OPEN POPUP WINDOWS
======================================================================*/

var wHeight = screen.height
var wWidth = screen.width


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+',height='+isHeight+',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 popupPrintWindow(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  printWindow  =   window.open(url,"printWindow",'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  printWindow.focus();
}

function centerScreen(xWidth,xHeight)
{
		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;
}

/*======================================================================
								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
    {
        alert("Please input a valid EMAIL address!")
        testresults=false
       
    }
     return (testresults)
}


function checkForValidEmail(s)
{
    var str = s;
    var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (filter.test(str))
        return true;
    else
        return false;
}