// template_basic 1.7 (tentative release date 2001-11-01)

// functions common to the all IGS web sites

// reloads the page as HTTPS if not already
function globalReloadSecure() {
	if (document.URL.substr(0, 5) == 'http:') {
		window.location = 'https:' + document.URL.substr(5);
	}
}

// ensures page is called as HTTPS if loadSecurelyOnly=true in config.js
var loadSecurelyOnly = loadSecurelyOnly;
if (loadSecurelyOnly) {
	globalReloadSecure();
}


// pops up a centered window
function globalNewWindow(mypage, myname, w, h, scroll, menustuff) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',location='+menustuff+',menubar='+menustuff+',toolbar='+menustuff+',resizable=yes';
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}
//ss's code to open a sized window
function openstatus(path, x, y)
{
	detailWin = eval("'status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y + "'");
	window.open(path, 'new_win', detailWin);
	detailWin.opener=window;
}
//opens windows on some pages under status definitions link
function open_win(path, x, y)
{
	detailWin = eval("'status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y + "'");
	window.open(path, 'new_win', detailWin);
	detailWin.opener=window;
}	
// replaces all instances of one image with another
// use absolute URL in function: http://...
function globalSwapImage(imgOldSrc,imgNewSrc) {
	if (document.images) {
		for (var loop = 0; loop < document.images.length; loop++) {
			if (document.images[loop].src == imgOldSrc) {
				document.images[loop].src = imgNewSrc;
			}
		}
	}
}

// performs simple validation with optional alert
// note: "entered" is the value, not the object itself
function globalNullValidate(entered, alertbox) {
	if (entered) {
		if (entered==null || entered=='') {
			if (alertbox!='') {
				alert(alertbox);
			}
			return false;
		}
		else {
			return true;
		}
	}
	else {
		if (alertbox!='') {
			alert(alertbox);
		}
		return false;
	}
}

// general purpose function to see if a suspected numeric input
// is a positive integer
function globalIsPosInteger(inputVal) {
	inputStr = inputVal.toString();
	if (inputStr==null || inputStr=='') {
			return false;
	}
	else {
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.charAt(i);
			if (oneChar < '0' || oneChar > '9') {
				return false;
			}
		}
		return true;
	}
}

// performs globalIsPosInteger validation with optional alert
// note: "entered" is the object itself
function globalValidatePosInteger(entered,alertbox) {
	if (entered) {
		if (!globalIsPosInteger(entered.value)) {
			if (alertbox!='') {
				alert(alertbox);
			}
			entered.value = '1';
			entered.focus();
			return false;
		}
		return true;
	}
	else {
		if (alertbox!='') {
			alert(alertbox);
		}
		return false;
	}
}

// draws coupon text field
function globalDiscount() {
	if (document.forms['frmMain'].discountVar) {
		if (document.forms['frmMain'].discountVar.value == 'true') {
			document.write('<tr>\n');
			document.write('	<td class="leftbig">Enter Coupon#</td>\n');
			document.write('	<td><input type="text" name="sDiscount" value="" maxlength="35" size="35"></td>\n');
			document.write('</tr>\n');
		}
	}
}

// draws row for discountamount
function globalDiscountAmount(discountAmount) {
	if ((discountAmount == '0.00') || (discountAmount == 'N/A')) {
		return false;
	}
	else {
		document.write('<tr>');
		document.write('	<td align="center" class="matrixdata">Discount Amount:</td>');
		document.write('	<td class="matrixdata">&nbsp;</td>');
		document.write('	<td class="matrixdata">&nbsp;</td>');
		document.write('	<td class="matrixdata">&nbsp;</td>');
		document.write('	<td class="matrixdata">&nbsp;</td>');
		document.write('	<td class="matrixdata">&nbsp;</td>');
		document.write('	<td align="center" class="matrixdata">$ ' + discountAmount + '</td>');
		document.write('</tr>');
	}
}

// draws row for infomessage
function globalInfoMessage(infoMessage) {
	if (infoMessage!='none') {
		document.write('<tr>');
		document.write('	<td align="center" class="matrixdata">Info Message:</td>');
		document.write('	<td colspan="6">' + infoMessage + '</td>');
		document.write('</tr>');
	}
}

// displays check boxes under the search box, if user is authorized
function globalCheckBoxAuth() {
	if (document.forms['frmSearch'].OfficeSupplyAuth.value == 'true') {
		document.write('<br>Managed Inventory<input type="checkbox" value="1" name="minv" checked>&nbsp;Office Supplies<input type="checkbox" value="1" name="oinv">');
	}
	else {
		document.write('<input type="hidden" value="1" name="minv">');
	}
}
//used on search function
function submitForm(formname)
{
	document.forms[formname].submit();
}
//used to redirect all ritas users to www.shopritas.com
function checkUser() {
	var webUser = document.forms['login'].User.value;
	webUser = webUser.substr(0, 5);	
    if (webUser == "ritas") {
        window.location.href = "http://www.shopritas.com";
		return false;	
		}
	else {		
		return true;	
		}
}

