﻿function FormSubmit(id)
{
	formID = document.getElementById(id);
	formID.submit();
}

function FormSubmitSubValue(formid,elemid,val)
{
	formID = document.getElementById(formid);
	formID.elements[elemid].value = val;
	formID.submit();
}

function ConfirmSubmitSubValue(formid,elemid,val,msg)
{
	if (confirm(msg)){
		formID = document.getElementById(formid);
		formID.elements[elemid].value = val;
		formID.submit();
	}
}

function ConfirmAddToCart(id,prodNum,qty) {
	if (qty < 1) alert("The quantity must be a positive, non-zero value.");
	else UpdatePricebox(id);
//	else if (confirm("Please click OK to confirm the addition of '"+prodNum+"' to your shopping cart.")){
//		UpdatePricebox(id);
//	}
}

function DivCancelBubble(obj,evt)
{
	if (window.event) window.event.cancelBubble = true;
	else evt.stopPropagation();
}

function PopupFromCB(cbid)
{
	var cbID = document.getElementById(cbid);

//	OutwaterPopup((document.getElementById(cbid)).options[cbID.selectedIndex].value);
	OutwaterPopup(cbID.options[cbID.selectedIndex].value);
}

function numOnly(e) 
{
    var charCode;

	if (window.event){
		charCode = window.event.keyCode;
	}
	else {
		charCode = (e.charCode) ? e.charCode : e.which;
	}

	switch(charCode){
		case 8:		//backspace
		case 9:		//tab
		case 16:	//shift
		case 37:	//arrow keys
		case 38:	//arrow keys
		case 39:	//arrow keys
		case 40:	//arrow keys
		case 46:	//del key
					return true;
	}
	if ((charCode >= 48) && (charCode <= 57)) return true;
	if ((charCode >= 96) && (charCode <= 105)) return true;

    if (window.event) event.returnValue = false;
	else e.preventDefault();
	
    return false;
}

function GetRadioObjValue(radioObj) {
	for (var i = 0; i < radioObj.length; i++) {
		if (radioObj[i].checked) return (radioObj[i].value);
	}
	return (null);
}

function SetRadioObjValue(radioObj,val) {
	for (var i = 0; i < radioObj.length; i++) {
		if (radioObj[i].value == val) radioObj[i].checked = true;
	}
	return (null);
}

function SearchSubmit(radioObj, alphaValue, searchValue) {
	switch (GetRadioObjValue(radioObj)) {
		case "PartNumber": PartSearch(searchValue,'PartNumber');
			break;
		case "PageNumber": GoToPage(searchValue);
			break;
		case "AlphaIndex": AlphaIndex(alphaValue);
			break;
		case "Keyword": PartSearch(searchValue,'Keyword');
			break;
	}
}

function GoToLink($link)
{
	window.location = $link;
}
