﻿// JScript File
// Browser check

var isNN4up = false;
var isIE4up = false;

var browserVer = parseInt(navigator.appVersion);
var browserName = navigator.appName;

if (browserVer >= 4 ) {
	if (browserName == "Netscape") {
		isNN4up = true;
	}
	else if (browserName == "Microsoft Internet Explorer") {
		isIE4up = true;
	}
}

function winPopup(popURL,WindowName,wt,ht,Scrolling,resizable,top,left) {
	if (Scrolling >0){
	Scrolling=1
	}
	else {
	Scrolling=0
	}
	if (resizable>0){
	resizable=1
	}
	else {
	resizable=0
	}
	if (top>0){
	top=top
	}
	else {
	top=(screen.height-ht)/2
	}
	if (left>0){
	left=left
	}
	else {
	left=(screen.width-wt)/2
	}
	PageURL=popURL;
	settings="toolbar=0,location=0,directories=0,"+
	"status=1,menubar=0,scrollbars=" +Scrolling+","+
	"resizable="+ resizable +",width="+wt+",height="+ht
	+	",top=" + top + ",left="+ left;
	popWin=window.open(PageURL,WindowName,settings);
	//alert((screen.width-popWin.body.offsetWidth)/2);
	//popWin.moveTo((screen.width-popWin.document.body.offsetWidth)/2,(screen.height-popWin.document.body.offsetHeight)/2)
	//popWin.creator=self;
	popWin.focus();	
}


 function noRightClick() {
	if (event.button==2) {
		alert('Please select a zone or material from the menus.')
	}
 }

function setCookie(NameOfCookie, value, expiredays) 
{

	// Three variables are used to set the new cookie. 
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert 
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning 
	// the values to the "document.cookie" object.
	// Note the date is converted to Greenwich Mean time using
	// the "toGMTstring()" function.

	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
 
function getCookie(NameOfCookie)
{

	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.

	if (document.cookie.length > 0) 
	{ 

	// Second we check to see if the cookie's name is stored in the
	// "document.cookie" object for the page.

	// Since more than one cookie can be set on a
	// single page it is possible that our cookie
	// is not present, even though the "document.cookie" object
	// is not just an empty text.
	// If our cookie name is not present the value -1 is stored
	// in the variable called "begin".

	begin = document.cookie.indexOf(NameOfCookie+"="); 
	if (begin != -1) // Note: != means "is not equal to"
	{ 

	// Our cookie was set. 
	// The value stored in the cookie is returned from the function.

	begin += NameOfCookie.length+1; 
	end = document.cookie.indexOf(";", begin);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(begin, end)); } 
	}
	return null; 

	// Our cookie was not set. 
	// The value "null" is returned from the function.

}

function delCookie (NameOfCookie) 
{

	// The function simply checks to see if the cookie is set.
	// If so, the expiration date is set to Jan. 1st 1970.

	if (getCookie(NameOfCookie)) {
	document.cookie = NameOfCookie + "=" +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} 

// generic positive number decimal formatting function
function format (expr, decplaces) {
	// raise incoming value by power of 10 times the
	// number of decimal places; round to an integer; convert to string
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	// pad small value strings with zeros to the left of rounded number
	while (str.length <= decplaces) {
		str = "0" + str
	}
	// establish location of decimal point
	var decpoint = str.length - decplaces
	// assemble final result from: (a) the string up to the position of
	// the decimal point; (b) the decimal point; and (c) the balance
	// of the string. Return finished product.
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
// turn incoming expression into a dollar value
function dollarize (expr) {
	if(expr==null || expr=="" ) {expr=0}
	return "$" + format(expr,2)
}



    function KeyDownHandler(btn)
    {
        // process only the Enter key
        if (event.keyCode == 13)
        {
            // cancel the default submit
            event.returnValue=false;
            event.cancel = true;
            // submit the form by programmatically clicking the specified button
            btn.click();
        }
    }



// JS utilitites

 function makeArray() {
	this.length = makeArray.arguments.length
	for (var i = 0; i < this.length; i++) {
		this[i] = makeArray.arguments[i];
	}
 }

 function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
 }

 function getSearchAsArray() {

	var results = new Array();
	if (isNN4up || isIE4up) {
		var input = unescape(document.location.search.substring(1));
		if (input) {
			var srchArray = input.split("&");
			var tempArray = new Array();
			for (i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=");
			results[tempArray[0]] = tempArray[1];
			}
		}
	}
	return results;
 }

 function showElement(elemID) {
     try {
         if (isIE4up) {
             document.all[elemID].style.visibility = "visible";
         } else if (isNN4up) {
             document.layers[elemID].visibility = "show";
         }
     }
     catch (e) { }
 }

 function hideElement(elemID) {
     try {
         if (isIE4up) {
             document.all[elemID].style.visibility = "hidden";
         } else if (isNN4up) {
             document.layers[elemID].visibility = "hide";
         }
     }
     catch (e) { }
 }
 function resetElement(elemID) {
     try {
         if (isIE4up) {
             if (document.all[elemID]) { document.all[elemID].value = ""; }
         } else if (isNN4up) {
             if (document.layers[elemID]) { document.layers[elemID].value = ""; }
         }
     }
     catch (e) { }
 }
