/*
 *	QChi Medic JSLib
 */
// run search instead of submit on enter
function checkEnter(e){
	var code;
	if (!e) var e = window.event;
	if (e.which) code = e.which;
	else code = e.keyCode; 
	if(code == 13)	{ 
			quicksearch(document.forms[0].query, 'SearchView');
			return false;
			}
		else	{ 
			return true;
			} 
}
// find a random interger between 2 numbers
function rndBetween(start, end) {
    return Math.floor(Math.random()*(end-start)) + start;
}
function deBugAlert( thisText ) {
	//alert( thisText );
}
function hello() {
	alert( 'hello' );
}
function logout() {
window.top.document.location.href='/?Logout&RedirectTo=/biz/qchi-medic.nsf/';
}
function allocatefund() {
	alert( 'Sorry, this feature is still under development' );
}
function quicksearch( thisQuery, thisview ){
	var msg;
	var msgflag;
	msgflag = 'false';
	//deal with reserved url characters and html - stop people cocking the url up
	thisQuery.value = thisQuery.value.replace( /\</g , '' ).replace( /\>/g , '' ).replace( /\&/g , '' ).replace( /\#/g , '' ).replace( /\?/g , '%3F' ).replace( /\//g , '%2F' );
	if( thisQuery.value == '' || thisQuery.value == 'Enter Search Text Here' )  {
		msgflag="true";
		alert( 'Please enter the text you would like to search for.' );
		thisQuery.focus()
	}
	if( msgflag != "true" )  {
		document.location.href='/biz/qchi-medic.nsf/' + thisview + '!SearchView&Query='+ thisQuery.value +'&Start=1&Count=10'
	}
}
// move back and forwards through results page -  get URL attributes via url.attribute or url['attribute']
// the error checking came out cos the links arent even shown if conditions aren't met.
function resultsPage(where) {
	var actualUrl = location.href.substring(1);
	var urlArray = actualUrl.split('&');
	var url = new Object();
	for(i = 0; i < urlArray.length; i++)
	{
		eq = urlArray[i].indexOf('=');
		url[urlArray[i].substring(0,eq)] = unescape(urlArray[i].substring(eq + 1));
	}
	intStart = parseFloat( url['Start'] );
	// intMax = ;
	if ( ( where == "forward" ) ) {	// && ( intStart <= intMax ) ) {
		var newStart = intStart + 10;
		document.location.href="/biz/qchi-medic.nsf/SearchView!SearchView&Query=" + url['Query'] + "&Start=" + newStart + "&Count=" + url['Count'];
		newStart = "";
	} else if ( ( where == "back" ) ) {	// && ( ( intStart - 10 ) >= 1 ) ) {
		var newStart = intStart - 10;
		document.location.href="/biz/qchi-medic.nsf/SearchView!SearchView&Query=" + url['Query'] + "&Start=" + newStart + "&Count=" + url['Count'];
		newStart = "";
	} else { 	return; }
}
function DisplayBalances() {
with( document.forms[0] ) {
	if( FundSource.options[FundSource.selectedIndex].text=='' ) {
		alert( 'Please select the Fund Source' );
		FundSource.focus();
		return
	};
	if( PeriodQuarter.options[PeriodQuarter.selectedIndex].text=='' ) {
		alert( 'Please select the Financial Quarter' )
		PeriodQuarter.focus();
		return
	};
	if( PeriodYear.options[PeriodYear.selectedIndex].text=='' ) {
		alert( 'Please select the Financial Year' )
		PeriodYear.focus();
		return
	};
}
_doClick('$Refresh', this, '_self', '#_FinancialSourcing');
document.forms[0].UseFundNAI.focus();
return;
}
//this variable is global to hold a pop-up window
var newwin;
//this function allows easy maintenance of child window opening, accounting for browser types and to ensure the pop-up is focused
function OpenChildWin( openURL, winname, menu, tools, scroll, loc, stat, resize, x, y, h, w ) {
	if (navigator.appVersion.indexOf('X11') != -1) {
		if(newwin == null) {
			newwin=window.open( openURL, winname, 'menubar='+menu+', toolbar='+tools+', status=' + stat + ',resizable=' + resize + ',scrollbars=' + scroll + ',screenX=' + x + ',screenY=' +y + ',width=' + w + ',height=' + h );
		} else {
			newwin.close();
			newwin=window.open( openURL, winname, 'menubar='+menu+', toolbar='+tools+', status='+stat+',resizable='+resize+',scrollbars='+scroll+',screenX='+x+',screenY='+y+',width=' + w + ',height=' + h);
		}
	} 
	else {
		if (navigator.appName =='Netscape') {
			if(newwin == null) {
				newwin=window.open(openURL,winname,'menubar='+menu+', toolbar='+tools+', status='+stat+',resizable='+resize+',scrollbars='+scroll+',screenX='+x+',screenY='+y+',width=' + w + ',height=' + h);
			} else {
				newwin.close();
				newwin=window.open( openURL,winname,'menubar='+menu+', toolbar='+tools+', status='+stat+',resizable='+resize+',scrollbars='+scroll+',screenX='+x+',screenY='+y+',width=' + w + ',height=' + h);
			}
		} 
		else {
			if(newwin == null) {
				newwin=window.open(openURL,winname,'menubar='+menu+', toolbar='+tools+', status='+stat+',resizable='+resize+',scrollbars='+scroll+',top='+x+',left='+y+',width=' + w + ',height=' + h);
			} else {
				newwin.close();
				newwin=window.open(openURL,winname,'menubar='+menu+', toolbar='+tools+', status='+stat+',resizable='+resize+',scrollbars='+scroll+',top='+x+',left='+y+',width=' + w + ',height=' + h);
			}
		}
	}
}

