// JavaScript Document

function ProcessURL( url )
{
	return url;
}

function NavigatorUrl( url )
{
	//dies = url.indexOf("#");
	//if(-1 == dies) dies = 0;
	//location.href = url.substr(0, dies) + getAdditionalParams() + url.substr(dies);
	location.href = ProcessURL(url);
}

function OrderConf()
{
	window.open('printconf.php', 'OrderConf', 'width=675,height=800,menubar=yes,scrollbars=yes');
}

function hide_textbox(name)
{
	div_ref = eval("document.all." + name + ".style");
	div_ref.visibility = "hidden";	
}

function AddItemNo(itemno)
{
	parent.location.href = '/myaccount/action.php?Action=AddItem&ItemNo='+itemno;
}
function UpdateShipTo(shipto)
{
	self.location.href = '../action.php?Action=UpdateShipTo&ShipTo='+shipto;
}
	
function UpdateCustomer(cusno)
{
	self.location.href = '../action.php?Action=UpdateCustomer&Cus_No='+cusno;
}

function SetParentCustNo(CustomerNo)
{
	parent.document.Cart.cus_no.value = CustomerNo;
	parent.document.Cart.Alt_Adr_Cde.value = null;
	parent.document.getElementById('CustomerSearchDiv').style.display = "none";
	//return true;
	UpdateBillShip ( CustomerNo, null );
}
	
function UpdateBillShip (cusno, shipto)
{
//	parent.location.href = 'action.php?Action=UpdateBillShip&CusNo='+cusno+'&ShipTo='+shipto;
	parent.document.getElementById('CusNo').value = cusno;
	parent.document.getElementById('AltAdrCde').value = shipto;
	EditOrder ( 'UpdateBillShip' );
}

/*
function UpdateBillShip (cusno, shipto)
{
	parent.location.href = 'action.php?Action=UpdateBillShip&CusNo='+cusno+'&ShipTo='+shipto;
	//parent.document.getElementById('CusNo').value = cusno;
	//parent.document.getElementById('Alt_Adr_Cde').value = shipto;
	//EditOrder ( 'UpdateBillShip' );
}
*/

function UpdateShipWPickup ( isChecked, PickupLoc )
{
		if ( isChecked )
		{
			//parent.location.href = 'action.php?Action=SetPickup&Loc='+PickupLoc+'&PickupStatus='+isChecked;
			parent.document.getElementById('Loc').value = PickupLoc;
			parent.document.getElementById('PickupStatus').value = isChecked;
			EditOrder ( 'SetPickup' );
		}
		else
		{
			//parent.location.href = 'action.php?Action=SetPickup&Loc='+PickupLoc+'&PickupStatus='+isChecked;
			parent.document.getElementById('Loc').value = PickupLoc;
			parent.document.getElementById('PickupStatus').value = isChecked;
			EditOrder ( 'SetPickup' );			
		}
}

function EditOrder(Action)
{
	SetAction(Action);
	parent.document.getElementById('Cart').submit();
}

function SetAction(Action)
{
	parent.document.getElementById('MainAction').value = Action;
}

function UpdateShipper ( Action )
{
	parent.document.getElementById('MainAction').value = Action;
	parent.document.getElementById('Cart').submit();	
}

function RemoveProd ()
{
	//document.Edit.Action.value = "Remove";
	document.getElementById('Action').value = "Remove";
	document.Edit.submit ();
}

function SetParentCustNoAndAdr(CustomerNo, AltAdrCde)
{
	parent.document.Cart.cus_no.value = CustomerNo;
	parent.document.Cart.Alt_Adr_Cde.value = AltAdrCde;
	parent.document.getElementById('CustomerSearchDiv').style.display = "none";
	UpdateBillShip ( CustomerNo, AltAdrCde );
	//return true;
}

function SetParentCustNo(CustomerNo)
{
	parent.document.Cart.cus_no.value = CustomerNo;
	parent.document.Cart.Alt_Adr_Cde.value = null;
	parent.document.getElementById('CustomerSearchDiv').style.display = "none";
	UpdateBillShip ( CustomerNo, null );
}

function RefreshCatalogMenu (BackToAddress)
{
	if(BackToAddress != null) parent.document.getElementById('CatalogMenu').src = '/Admin-catalog/CatalogMenu.php?' + BackToAddress;
}

function RemoveCat ()
{
	//document.Edit.Action.value = "Remove";
	document.getElementById('Action').value = "Remove";
	document.Edit.submit ();
}

function DivDisplayChange(BlockName)
{
	if (document.getElementById(BlockName).style.display == "block")
	{
		document.getElementById(BlockName).style.display = "none";
		if(document.getElementById('Span-'+BlockName)) document.getElementById('Span-'+BlockName).innerHTML = "+";
	}
	else
	{
		document.getElementById(BlockName).style.display = "block";
		if(document.getElementById('Span-'+BlockName)) document.getElementById('Span-'+BlockName).innerHTML = "-";
	}
}

function ShowDiv(divName)
{
	document.getElementById(divName).style.display = "block";
}

function HideDiv(divName)
{
	document.getElementById(divName).style.display = "none";
}

function CatalogPrintView(QueryString)
{
	window.open('ProductPrint.php?'+QueryString,"CatalogPrintView","scrollbars=1, menubar=0, resizable=0; width=725,height=700");
}

function ShippingBilling(form)
{
	if(form.ShipAndBillSame.checked)
	{
		form.Ship_to_contact.value = form.Purchaser_Name.value;
		form.Ship_to_Address1.value = form.Bill_to_Address1.value;
		form.Ship_to_Address2.value = form.Bill_to_Address2.value;
		form.Ship_to_city.value = form.Bill_to_city.value;
		form.Ship_to_state.value = form.Bill_to_state.value;
		form.Ship_to_zip.value = form.Bill_to_zip.value;
	}else{
		form.Ship_to_contact.value = '';
		form.Ship_to_Address1.value = '';
		form.Ship_to_Address2.value = '';
		form.Ship_to_city.value = '';
		form.Ship_to_state.value = '';
		form.Ship_to_zip.value = '';
	}
}

function ToggleDiv(DivId)
{
  	var divElement = document.getElementById(DivId);

	$("#"+DivId).slideToggle("medium");
	//divArr = DivId.split("_");
	
	$("#catalogImage").attr("src",catalogImageArr[DivId]);
}
