// constants
var c_DeleteConfirmMsg = "Are you sure you want to delete this entry?"; 
var c_TransferConfirmMsg = "Are you sure you want to transfer these records?"; 

// methods
function OpenWindow(URL, Width, Height, HideTools){
	var intHeight;
	var intWidth;
	var Top;
	var Left;
	var Features;
	var Timer= new Date();
	if(Width){
		intWidth = Width;
	}
	else{
		intWidth = screen.availWidth * .80;
	}
	
	if(Height){
		intHeight = Height;
	}
	else{
		intHeight = screen.availHeight * .80;
	}
	Top = (screen.availHeight-intHeight) / 2
	Left = (screen.availWidth-intWidth) / 2
	if(HideTools){
		window.open(URL,Timer.getUTCMilliseconds(), "SCROLLBARS=1,TOOLBAR=0,RESIZABLE=1,MENUBAR=0,HEIGHT=" + intHeight + ",WIDTH=" + intWidth + ",TOP=" + Top +  ",LEFT=" + Left)
	}else{
		window.open(URL,Timer.getUTCMilliseconds(), "SCROLLBARS=1,TOOLBAR=1,RESIZABLE=1,MENUBAR=1,HEIGHT=" + intHeight + ",WIDTH=" + intWidth + ",TOP=" + Top +  ",LEFT=" + Left)
	}	
}
function OpenWindow1(URL, WinName, Width, Height, HideTools){
	var intHeight;
	var intWidth;
	var Top;
	var Left;
	var Features;
	var Timer= new Date();
	if(Width){
		intWidth = Width;
	}
	else{
		intWidth = screen.availWidth * .80;
	}
	
	if(Height){
		intHeight = Height;
	}
	else{
		intHeight = screen.availHeight * .80;
	}
	Top = (screen.availHeight-intHeight) / 2
	Left = (screen.availWidth-intWidth) / 2
	if(HideTools){
		window.open(URL,WinName, "SCROLLBARS=1,TOOLBAR=0,RESIZABLE=1,MENUBAR=0,HEIGHT=" + intHeight + ",WIDTH=" + intWidth + ",TOP=" + Top +  ",LEFT=" + Left)
	}else{
		window.open(URL,WinName, "SCROLLBARS=1,TOOLBAR=1,RESIZABLE=1,MENUBAR=1,HEIGHT=" + intHeight + ",WIDTH=" + intWidth + ",TOP=" + Top +  ",LEFT=" + Left)
	}	
}
function PrintReport(){
	document.all("PrintHref").style.display = "none"
	document.all("CloseHref").style.display = "none"
	window.print()
	document.all("PrintHref").style.display = ""
	document.all("CloseHref").style.display = ""

}
function ConfirmDelete(){
	var blnDelete = confirm("Are you sure you want to delete this entry?")
	if(blnDelete){
		document.Form1.DeleteItem.value = "1"
		document.Form1.submit();
		
	}else{
		document.Form1.DeleteItem.value = "0"
		return false;
	}
}
function ConfirmSubmit(strMsg){
	if(confirm(strMsg)) {
		document.forms[0].submit();
	} 		
	else {
		return false;
	}
}
function ValidateAndConfirmSubmit(strMsg, strErrMsg, strSummaryValidorID) {
	var bSuccess = true; 
	if (typeof(Page_ClientValidate) == 'function') {
		bSuccess = Page_ClientValidate();
	}
	if (bSuccess) { 
		if(confirm(strMsg)) {
			document.forms[0].submit();
		} 		
		else {
			return false;
		}
	} else { 
		var sErrors = '';
		if (strSummaryValidorID != null) {
			var valSum = document.getElementById(strSummaryValidorID);
			sErrors = valSum.innerText;
		}
		if (strErrMsg != null) {
			alert(strErrMsg + ' ' + sErrors); 
		}
		else {
			alert('Please fix errors, then try again.' + ' ' + sErrors); 
		}
	}
}
function MoveToFirstValidationError() {
// NOT TESTED - confirm this works before using
	var spans = document.getElementsByTagName('span');
	if (spans!=null) {
		for (var i=0; i<spans.length - 1; i++) {
			if (spans[i].controltovalidate != null) {
				if (spans[i].style.visibility != 'hidden') {
					var elem = document.getElementById(spans[i].controltovalidate);
					elem.focus();
					return;
				}
			}
		}
	}
}
function replaceString(oldS,newS,fullS) {
// Replaces oldS with newS in the string fullS
   for (var i=0; i<fullS.length; i++) {
	   if (fullS.substring(i,i+oldS.length) == oldS) {
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
		}
	}
	return fullS
}

// Allows a user to return a value 
// from the querystring in a request.querystring("key") syntax

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();
