
var debugtxt;
var basehref = "";


function getSelectVal(theElem) {
var idx = theElem.selectedIndex;
var val = theElem.options[idx].value
return(val);
}


function setSelectVal(theElem, theVal) {
var numOpts = theElem.options.length;
var i;
var foundOpt = false;
for (i=0;i<numOpts;i++) {
	if (theElem.options[i].value == theVal) {
		theElem.options[i].selected = true;
		foundOpt = true;
	}
}
return(foundOpt);
}



function getRadioVal(theElems) {
var elem;
var val = "";
var idx;
var numElems = theElems.length;

if (numElems > 1) {
	for (idx=0;idx<numElems;idx++) {
		var theElem = theElems[idx];
		if (theElem.checked == true) {
			val = theElem.value;	
		}
	}
} else {
	if (theElems[0].checked == true) {
		val = theElem.value;	
	}
}
return(val);
}

function setRadioVal(theElem, theVal) {
var numOpts = theElem.options.length;
var i;
var foundOpt = false;
for (i=0;i<numOpts;i++) {
	if (theElem.options[i].value == theVal) {
		theElem.options[i].checked = true;
		foundOpt = true;
	}
}
return(foundOpt);
}




function fillTodaysDate(theElem) {
var today = new Date();
var theYear = today.getYear();
if (theYear < 1000) {
	theYear += 1900;
}
var theMonth = (today.getMonth() + 1);
var dateval = (theYear + "-" + theMonth + "-" + today.getDate());
//alert("filling today's date:" + dateval);
theElem.value = dateval;
return(false);
}



function fillCurrentTime(theElem) {
var today = new Date();
var theHour = today.getHours();
var theMinute = (today.getMinutes());
var dateval = (theHour + ":" + theMinute);

theElem.value = dateval;
return(false);
}




function fillFilename(filename, targElem) {
var start = filename.lastIndexOf("/");

if (start < 1) {
        start = filename.lastIndexOf("\\");
}

if (start < 1) {
        start = filename.lastIndexOf(":");
}

var file = filename.substring(start+1,filename.length);
if (file != '') {
        targElem.value = file;
}

}





function writeWindow(windowname, opener, htmltext, params, focus) {
sWindow = window.open('',windowname,params);
sWindow.document.open();
sWindow.document.write(htmltext);
sWindow.document.close();
if (!focus)  opener.focus(); 
if (focus) opener.blur();
return (sWindow);
}

function relocateOpener(targetwindow, newurl) {
targetwindow.document.location.href=newurl;
targetwindow.focus();
return (false);
}

function relocDisplayFrame (theURL) {
//alert("relocating frame to " + theURL);
parent.frames['display'].document.location.href = theURL;
return(false);
}

function relocate(targetform, elemname) {
var newloc = "";
var formElem= targetform.elements[elemname];
var idx = formElem.selectedIndex;
var locval = formElem.options[idx].value;
newloc += locval;
if (locval) {
 document.location.href = basehref + newloc;
 return true;
} else {
 return false;
}

}


function popWindow(inWindowname, opener, URL, inParams) {
var defaultParams = "width=740,height=500,scrollbars=yes,menubar=no,location=no,status=yes,resizable";
var defaultWindowname = "Popup Window";
var params;
var windowname;

if (!inParams) {
 params = defaultParams;
} else {
 params = inParams;
}
if (!inWindowname) {
 windowname = defaultWindowname;
} else {
 windowname = inWindowname;
}
var uWindow = window.open(URL,windowname,params);
return(false);
}



function popSendEmail(emailaddress) {
var params = ("width=700,height=400,location,resizable,status");
var theURL = ("mailto:" + emailaddress);
//popWindow = window.open(theURL,'EmailSender',params);
//popWindow.opener = this.window;
//popWindow.close();
document.location.href = theURL;
return (false);
}





// UTILITY FOR GETTING JSDATA FROM A POPUP WINDOW.  
// page_jsdata.html contains an init() function that is called onLoad.
//   the jsdata page calls the function loadJSData(dataArray, dataset, datagroup),
//   passing in the array of data, and the dataset/datagroup requested
//   ** it is the responsibility of this page to the call to loadJSData appropriately for this page context

function dataPop(startHTML, theURL, inParams) {
var defaultParams = "top=0,left=0,screenX=0,screenY=0,fullscreen=yes,scrollbars=no,menubar=0,location=0,status=0";
defaultParams += (",width=" + screen.width);
defaultParams += (",height=" + screen.height);
var windowname = "CustomerDataPop";
var params;

if (!inParams) {
 params = defaultParams;
} else {
 params = inParams;
}

var dataPop;

//dataPop = window.open('/html/eng/man/blank.html',windowname,params);
//dataPop.document.open();
//dataPop.document.write(startHTML);
//dataPop.document.close();
//dataPop.document.location.href = theURL;

dataPop = window.open(theURL,windowname,params);

dataPop.opener = this.window;
}




function fixDecimals(value) {
var rv = value;

//rv = roundAccuracy(value, 2);

rv = oldFixDecimals(rv);
return (rv);

}

/// The following is the old code, which /almost/ worked. ;-)
function oldFixDecimals(value) {
var rv = value;
if (rv == 0) {
	rv = ("0.00");
}
  //alert("starting with: " + rv);
  rv = (rv * 100);
  rv = (rv + .5);
  //alert("parsing " + rv + " for integer value.");
  rv = parseInt(rv);
  //alert("integer value is: " + rv);
  rv = rv / 100;
 
  //alert("float value is: " + rv);

  var rvString = rv.toString();

  //alert("rvString is: " + rvString);

  var idx = rvString.indexOf(".");
  if (idx == (-1)) {
    //alert("decimal not found in rvString: " + rvString);
    rvString = rvString + ".00";
  } else {
    //alert("decimal found in rv: " + rvString);
  	if (idx == (rvString.length-2)) {
    rvString = rvString + "0";
  	}
  }


return(rv);
}

function roundAccuracy(num, accuracy){
	var factor=Math.pow(10,accuracy);
	return Math.round(num*factor)/factor;
}



function confirmWindowClose(msg) {
var retval = true;
var message = "Are you sure you want to close this window?";
if (msg != "") {
	message = msg;
}
retval = confirm(message);
if (retval) {
	if (window.top == window) {
		window.close();
	} else {
		retval = confirm("This window is part of a frameset, Are you sure you want to close the whole frameset?  (cancel to send ONLY THIS FRAME to a blank page)");
		if (retval) {
			top.window.close();
		} else {
			document.location.href = "/html/eng/man/blank.html";
		}
	}
}
return(retval);
}





function closeWindow() {
if (window.top == window) {
	window.close();
} else {
	retval = confirm("This window is part of a frameset, Are you sure you want to close the whole frameset?  (cancel to send ONLY THIS FRAME to a blank page)");
	if (retval) {
		top.window.close();
	} else {
		document.location.href = "/html/eng/man/blank.html";
	}
}
return(retval);
}





function dumpDebug() {
var i;
var theText = "";
for (i in document) {
	theText += (i + "=" + document.i + "<br>\n");
}
writeWindow("theWindow", this.window, theText);
}



function getAll(theForm) {
	var i;
	for (i=0;i<theForm.elements.length;i++) {
		//debugtxt += (theForm.elements[i].name + "\n");
		if (theForm.elements[i].name.substring(0,5) == "quant") {
			theForm.elements[i].value = "1";
		}
	}
	//alert(debugtxt);
return(false);
}

function trashAll(theForm) {
	var i;
	if (theForm.elements) {
		for (i=0;i<theForm.elements.length;i++) {
			//debugtxt += (theForm.elements[i].name + "\n");
			if (theForm.elements[i].name.substring(0,6) == "remove") {
				theForm.elements[i].checked = "true";
			}
		}
	}
	//alert(debugtxt);
return(false);
}

function getNone(theForm) {
	var i;
	for (i=0;i<theForm.elements.length;i++) {
		if (theForm.elements[i].name.substring(0,5) == "quant") {
			theForm.elements[i].value = "";
		}
	}
return(false);
}





function toggleCanvas(canvasName, checkedState) {
var targetCanvas = document.getElementById("canvas" + canvasName);
if (checkedState == true) {
        var sourceCanvas = document.getElementById("source" + canvasName);
        targetCanvas.innerHTML = sourceCanvas.innerHTML;
} else {
        targetCanvas.innerHTML = "";
}
return(false);
}



function showMessage(messageName, canvasName) {
var messageSource = (messageName + "Source");
var messageTarget = "";
if (canvasName) {
	messageTarget = canvasName;
} else {
	messageTarget = "messageCanvas";
}
var hideMessage = ("<div align=\"center\"><a href=\"#\" onClick=\"return showMessage('blank', '" + messageTarget + "');\" style=\"font-size:10px;\">Hide This Message</a></div>");
var target = document.getElementById(messageTarget);
var source = document.getElementById(messageSource);
if (messageName == "blank") {
	target.innerHTML = "";
} else {
	target.innerHTML = source.innerHTML + hideMessage;
}
return(false);
}

