// pads values from calcPrice with the proper number of zeros
function openHelpWin(pageToLoad)
{
	var helpWin;
	helpWin = window.open(pageToLoad, "helpWin", "fullscreen=no,toolbar=no,status=yes,menubar=yes,scrollbars=yes,directories=no,location=no,width=440,height=400");
	if (helpWin.focus())
		helpWin.focus();
}

function openShippingWin(pageToLoad)
{
	var shippingWin;
	shippingWin = window.open(pageToLoad, "shippingWin", "fullscreen=no,toolbar=no,status=yes,menubar=yes,scrollbars=yes,directories=no,location=no,width=740,height=500");
	if (shippingWin.focus())
		shippingWin.focus();
}

function openHelpWinCard(pageToLoad)
{
	var helpWin;
	helpWin = window.open(pageToLoad, "helpWin", "fullscreen=no,toolbar=no,status=yes,menubar=yes,scrollbars=yes,directories=no,location=no,width=440,height=340");
	if (helpWin.focus())
		helpWin.focus();
}

function popUp(url,w,h)  {
        window.open(url,'popup','width='+w+',height='+h+',scrollbars=0, resizable=0, status=0, toolbar=0');
}

function popUpSVC(url,w,h)  {
        window.open(url,'popup','width='+w+',height='+h+',scrollbars=1, resizable=1, status=0, toolbar=0');
}

function popUpCentinel(url) {
	popupWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,width=570,height=450');
	self.name = "mainWin"; 
}

function padZero(str)
{
	var newS = new String(str)
	if((newS == 0) || (parseInt(str) == 0))
	{
		return ""
	}
	var iPos = newS.indexOf(".")
		if (iPos == -1)
		{
			return newS + ".00"
		}
		else
		{
			var tempS = new String()
			iPos +=1
			tempS = newS.substring(iPos, newS.length)			

			if(tempS.length == 1)
			{
				newS = newS + "0"
			}
		}
	return newS.toString()
}

// calculates price dynamically (used in delivery/create order page)
function calcPrice(price,item) {

	var curInput = "";
	var curNumber = 0;
	var input = "";
	var number = 0;
	var numberout;
	var subtotal;
	var subtotalout;
	
	// get current value of item
	eval("curInput = document.neworder.p" + item + ".value");
	if(curInput != "") { curNumber = parseFloat(curInput) };
	
	eval("input = document.neworder.p" + item + "_quantity[document.neworder.p" + item + "_quantity.selectedIndex].value");
	number = Math.round((parseFloat(input) * price) * 100) / 100;
	if (number == 0)
		numberout = "";
	else
		numberout = padZero(number);
	
	eval("document.neworder.p" + item + ".value = numberout");
	
	// get current subtotal value
	if(document.neworder.subtotal.value == "")
	   subtotal = 0;
	else
	   subtotal = parseFloat(document.neworder.subtotal.value);
	   
	// do math, round to nearest hundredth
	subtotal = Math.round(((subtotal - curNumber) + number)*100)/100;
	if (subtotal == 0) 
		subtotalout = "";
	else
		subtotalout = padZero(subtotal);
	
	// set value of subtotal form item
	document.neworder.subtotal.value = subtotalout;
}

// function change to the action property of a form
function changeFormAction(url,formName) {
	eval("document." + formName + ".action='" + url + "'");
	eval("document." + formName + ".submit()");
}

// function to change the value of a hidden form item
function changeHiddenValue(formName,elementName,newValue) {
	eval("document." + formName + "." + elementName + ".value='" + newValue + "'");
}

// function used to delete an item in the shopping cart (used in shopping cart page)
function deleteItem(itemNum) {
	eval("document.shoppingcart.quantity_" + itemNum + ".value = 0");
	document.shoppingcart.submit();
}

// function used to delete an item in the ship to multiple address page
function RemoveItem(subCart, itemNum) {
	eval("document." + subCart + ".qty_" + itemNum + ".value = 0");
	eval("document." + subCart + ".submit()");
}

// function used to delete an item in the ship to multiple address page
function RemoveAllItems(subCart) {
	myForm = eval("document." + subCart);
	
	for(i = 0; i < myForm.elements.length; i++)
	{
		elementName = myForm.elements[i].name;
		if (myForm.elements[i].name.indexOf("qty_") >= 0)
		{
			myForm.elements[i].value = 0;
		}
	}
	
	myForm.submit();
}

function SelectAll(formName, selectName)
{
	mySelectBox = eval("document." + formName + "." + selectName);

	for (i = 0; i < mySelectBox.length; i ++)
	{
		mySelectBox.options[i].selected = true;
	}
}

function DeselectAll(formName, selectName)
{
	mySelectBox = eval("document." + formName + "." + selectName);

	for (i = 0; i < mySelectBox.length; i ++)
	{
		mySelectBox.options[i].selected = false;
	}
}

// go to specified url - function can be called from an on-click event
// in a table cell - used in top and left navigation
function goToUrl(url) {
	window.location = url;
}

// find object (used in navigation)
function mnet_findobj(n, d) {
  var p,i,x;
   
  if(!d) d=document;
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
   }
   
  if(!(x=d[n])&&d.all) 
  	x=d.all[n]; 
  	
  for (i=0;!x&&i<d.forms.length;i++) 
  	x=d.forms[i][n];
  	
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  	x=mnet_findobj(n,d.layers[i].document);
  	
  if(!x && d.getElementById) 
	x=d.getElementById(n); 
  
  return x;
}


// show/hide layer visibility (used in navigation)
function mnet_showhidelayers() {
  var i,p,v,obj,args=mnet_showhidelayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  	if ((obj=mnet_findobj(args[i]))!=null) { 
  		v=args[i+2];
    	if (obj.style) {
    		obj=obj.style; 
    		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
    	}
    	obj.visibility=v; 
    }
}

function changeRow(id,onStyle,offStyle) {

	var handle = document.getElementById(id);
	handle.className = onStyle;

}

// name window
window.name = 'main';
