function flipPage(page) {
	document.form1.listPage.value = page;
	document.form1.submit();
}
function getTable(table) {
	document.form1.table.value = table;
	document.form1.submit();
}
function tableSort(column) {
	document.form1.sort.value = column;
	document.form1.submit();
}
function tableQuery(field) {
	document.form1.queryfield.value = field.name;
	document.form1.queryvalue.value = field.value;
	document.form1.liistPage.value = 1;
	document.form1.submit();
}
function openInput(vsMode,vsURL)
{
	if (vsMode == 'TABLE') {
		var vlWidth = Number(600);
		var vlHeight = Number(600);
		var vsWinFeatures = String('width='+String(vlWidth)+',innerwidth='+String(vlWidth)+',height='+String(vlHeight)+',innerheight='+String(vlHeight));
		var wInput = window.open(vsURL,'input',vsWinFeatures+',resizable=yes, scrollbars=yes');
	}
	else if (vsMode == 'ORDER') {
		var vlWidth = Number(600);
		var vlHeight = Number(600);
		var vsWinFeatures = String('width='+String(vlWidth)+',innerwidth='+String(vlWidth)+',height='+String(vlHeight)+',innerheight='+String(vlHeight));
		var wInput = window.open(vsURL,'input',vsWinFeatures+',resizable=yes, scrollbars=yes');
	}
	//document.location = vsURL;
}//end openInput
function _onLoad(vsMode)
{
	if (document.form1.queryfield.value!='') {
		//document.form1[document.form1.queryfield.value].value = document.form1.queryvalue.value;
		}
//	if (vsMode == 'DATABASE') {document.form1.elements['id'].focus();}
}

/*Lookup Dialog Code - with thanks to Robbe D. Morris for the example code.
http://www.eggheadcafe.com/articles/javascript_modal_dialog.asp
I have stripped his code down to the bare minimum and use it in conjunction with 
ASP listing windows to return a selected item to the calling page.
Also commmented the code  for my reference.
*/
var modalWindow = null; //Window handle.
var modalInterval; //Interval handle.
var modalReturn = new Object;

modalReturn.value = ''; //initialise the return value..
modalReturn.eventhandler = ''; //Initialise the event handler method.


function modalMaintainFocus() //Maintains the window focus
{
  try
  {
    if (modalWindow.closed)
     {
        window.clearInterval(modalInterval); // Clears the interval timer to stop the function from running.
        eval(modalReturn.eventhandler);  //Not entirely sure what this is for???     
        return;
	 }
    if (modalWindow.onblur)
     {
		modalWindow.focus(); //If the window has not been closed by an event then keep it as the front most window.
		return;
	 }
  }
catch (everything) { }
}
        
 function modalRemoveWatch() //Initialises the return value and event handler.
 {
    modalReturn.value = '';
    modalReturn.eventhandler = '';
 }
        
 function modalShow(winURL, winTitle, winArgs, eventHandler)
 {
	modalRemoveWatch();
	modalReturn.eventhandler = eventHandler;
	//alert(winURL);
	modalWindow=window.open(winURL, winTitle, winArgs);  //Opens the nnew window with the specified URL, Title and settings.
	modalWindow.focus(); //Gives the focus to the new dialog window.
	modalInterval = window.setInterval("modalMaintainFocus()",100); //Causes maintain focus to execute every 100 milliseconds.
 }

function formatPercentage(num)
{
 return Math.round((num-0)*100) + '%';
}

function formatCurrency(num) {
	num = num.toString().replace(/\£|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pence = num%100;
	num = Math.floor(num/100).toString();
	if(pence<10)
	pence = "0" + pence;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '£' + num + '.' + pence);
}

function formatNumber(num, decimals){
	if (isNaN(num)) { return 0};
	if (num=='') { return 0};
	
	var snum = new String(num);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}

function loadXMLDoc(url, stateChangeMethod) 
{
//if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=eval(stateChangeMethod);
xmlhttp.send(null)
}

function writeMessage(text) //Used for debuging.  Requires a div on page called "debug".
{
	document.getElementById("debug").innerHTML = text;
}
	
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	//alert("Test");
	changeImagesArray(changeImages.arguments);
}

	
