//
function CustomerDetails(CustId)
{
var MyUrl = "customer_details.asp?CustId="+CustId;
var WinProps = "width=500,height=500,top=0,left=0,scrollbars=yes,status=yes,resizable=yes";
var CustDetailsWindow = window.open(MyUrl,'Customer_Details',WinProps);
}

//
function ApplyDiscount(DiscountValue)
{
var TheForm = document.Products;
var SlaveIdList = "start" + TheForm.SlaveIdList.value;
SlaveIdList = SlaveIdList.replace("start#","");
var SlaveArray = SlaveIdList.split("#");
var div = Math.pow(10,2);

for(i=0; i<=SlaveArray.length-1; i++)
	{
	var ProdId = SlaveArray[i];
	var TradePrice = TheForm.elements["trade_price_"+ProdId].value;
	var DiscountedPrice = Math.round(TheForm.elements["rrp_"+ProdId].value * DiscountValue * div) / div;
	TheForm.elements["price_"+ProdId].value = DiscountedPrice;
	TheForm.elements["profit_"+ProdId].value = Math.round((DiscountedPrice - TradePrice) * div) / div;
	}
}

//
function HideStarterKit()
{
if(document.StarterKit.SelectedId)
	{
	if(document.StarterKit.SelectedId.value != "")
		{
		var SelectedId = document.StarterKit.SelectedId.value;
		var MyUrl = "index.asp?PageName=Processing&Action=HideStarter&SelectedId="+SelectedId+"&PreviousPage="+PreviousPage;
		document.location = MyUrl;
		}
	else
		{
		alert("Please select a species to hide !!");
		}
	}
else
	{
	alert("Please select a species to hide !!");
	}
}

//
function RestoreStarterKit(TheForm)
{
var SelectedId = TheForm.StarterToRestore.options[TheForm.StarterToRestore.selectedIndex].value;
if(SelectedId != "")
	{
	var MyUrl = "index.asp?PageName=Processing&Action=RestoreStarter&SelectedId="+SelectedId+"&PreviousPage="+PreviousPage;
	document.location = MyUrl;
	}
else
	{
	alert("Please select a species to restore !!");
	}
}

//
function EditStarter()
{
var TheForm = document.StarterKitAdmin,EquipmentList="",Id,Qty,VivSize="",VivLength,VivWidth,VivHeight;
for(i = 0; i <=100 ; i++)
	{
	if(TheForm.elements["required_"+i])
		{
		Id = TheForm.elements["Id_"+i].value;
		Qty = parseInt(TheForm.elements["Qty_"+i].options[TheForm.elements["Qty_"+i].selectedIndex].value);
		EquipmentList = EquipmentList+Id+","+Qty+"end";
		}
	else
		{
		break;
		}
	}
if(TheForm.edit_viv.checked == true)// if a vivarium is listed then combine the sizes
	{
	VivLength = TheForm.VivLength.options[TheForm.VivLength.selectedIndex].value + "Lx";
	VivWidth = TheForm.VivWidth.options[TheForm.VivWidth.selectedIndex].value + "Wx";
	VivHeight = TheForm.VivHeight.options[TheForm.VivHeight.selectedIndex].value + "H";
	VivSize = VivLength + VivWidth + VivHeight;
	}
TheForm.action="complete_setup_admin.asp?VivSize="+VivSize+"&EquipmentList="+EquipmentList;
TheForm.submit();
}

//
function EditStarterKit()
{
if(document.StarterKit.SelectedId)
	{
	if(document.StarterKit.SelectedId.value != "")
		{
		var SelectedId = document.StarterKit.SelectedId.value;
		var MyUrl = "complete_setup_admin.asp?Action=EditStarter&SelectedId="+SelectedId;
		var WinProps = "width=600,height=600,top=0,left=0,scrollbars=yes,status=yes,resizable=yes";
		var StarterKitWindow = window.open(MyUrl,'Starter_kits',WinProps);
		}
	else
		{
		alert("Please select a species to edit !!");
		}
	}
else
	{
	alert("Please select a species to edit !!");
	}
}

//
function AddStarterKit()
{
var MyUrl = "complete_setup_admin.asp";
var WinProps = "width=600,height=500,top=0,left=0,scrollbars=yes,status=yes,resizable=yes";
var StarterKitWindow = window.open(MyUrl,'Starter_kits',WinProps);
}

//
function PicUpdate(FormElement,TheForm,PicId)
{
var PictureName = FormElement.value;
var ThisPicture = document.images[PicId];
ThisPicture.src = "images/reptile_pics/"+PictureName;
}

//
function AddStarter(TheForm)
{
var VivLength,VivWidth,VivHeight,TypeSelect,VivStyle,VivSize,Classification,EquipmentList,ListLength;
var Species,LatinName,SpecimenSizeHatchling,SpecimenSizeAdult,info,PictureName,NewList="",myurl;

VivLength = TheForm.VivLength.value + "Lx";
VivWidth = TheForm.VivWidth.value + "Wx";
VivHeight = TheForm.VivHeight.value + "H";
VivSize = VivLength + VivWidth + VivHeight;

VivStyle = escape(TheForm.VivStyle.value);
TypeSelect = TheForm.TypeSelect.value;
Classification = TheForm.Classification.value;
Species = escape(TheForm.Species.value);
LatinName = escape(TheForm.LatinName.value);
SpecimenSizeHatchling = escape(TheForm.SpecimenSizeHatchling.value);
SpecimenSizeAdult = escape(TheForm.SpecimenSizeAdult.value);
info = escape(TheForm.info.value);
PictureName = escape(TheForm.PictureName.value);

ListLength = TheForm.EquipmentList.length;
if(ListLength != 0)
{
for(i = 0; i <=ListLength-2; i++)
	{
	NewList = NewList + TheForm.EquipmentList.options[i].value + "end";
	}
NewList = NewList + TheForm.EquipmentList.options[ListLength-1].value;
}
myurl = "complete_setup_admin.asp?Action=AddNewStarter";
myurl = myurl + "&VivSize="+VivSize;
myurl = myurl + "&VivStyle="+VivStyle;
myurl = myurl + "&TypeSelect="+TypeSelect;
myurl = myurl + "&Classification="+Classification;
myurl = myurl + "&Species="+Species;
myurl = myurl + "&LatinName="+LatinName;
myurl = myurl + "&SpecimenSizeHatchling="+SpecimenSizeHatchling;
myurl = myurl + "&SpecimenSizeAdult="+SpecimenSizeAdult;
myurl = myurl + "&EquipmentList="+NewList;
myurl = myurl + "&info="+info;
myurl = myurl + "&PictureName="+PictureName;

document.location = myurl;
}

//
function move(fbox, tbox)
{
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++)
	{
	arrLookup[tbox.options[i].text] = tbox.options[i].value;
	arrTbox[i] = tbox.options[i].text;
	}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++)
	{
	arrLookup[fbox.options[i].text] = fbox.options[i].value;
	if (fbox.options[i].selected && fbox.options[i].value != "")
		{
		arrTbox[tLength] = fbox.options[i].text;
		tLength++;
		}
	else
		{
		arrFbox[fLength] = fbox.options[i].text;
		fLength++;
		}
	}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++)
	{
	var no = new Option();
	no.value = arrLookup[arrFbox[c]];
	no.text = arrFbox[c];
	fbox[c] = no;
	}
for(c = 0; c < arrTbox.length; c++)
	{
	var no = new Option();
	no.value = arrLookup[arrTbox[c]];
	no.text = arrTbox[c];
	tbox[c] = no;
	}
}

//
function EditContents(MasterId)
{
var MyUrl = "edit_product.asp?MasterId="+MasterId;
var WinProps = "width=1200,height=700,top=0,left=0,scrollbars=yes,status=yes,resizable=yes";
var EditWindow = window.open(MyUrl,'edit_contents',WinProps);
}

//
function GetFileName(Id)
{
var MyUrl = "get_file_name.asp";
MyUrl = MyUrl+"?Id="+Id;
var WinProps = "width=200,height=50,top=0,left=0,scrollbars=no,status=no,resizable=no";
var EditWindow = window.open(MyUrl,'getfilename',WinProps);
}

//
function EditCategory()
{
var MyUrl = "edit_category.asp";
var WinProps = "width=500,height=650,top=0,left=0,scrollbars=yes,status=no,resizable=yes";
var EditWindow = window.open(MyUrl,'edit_category',WinProps);
}

//
function EditSubCategory(CurrentCategory)
{
var MyUrl = "edit_sub_category.asp?CurrentCategory="+CurrentCategory;
var WinProps = "width=500,height=650,top=0,left=0,scrollbars=yes,status=no,resizable=yes";
var EditWindow = window.open(MyUrl,'edit_category',WinProps);
}

//
function AddNewProductCategory(CurrentCategory,ParentId)
{
var MyUrl = "add_product_category.asp?CurrentCategory="+CurrentCategory;
var MyUrl = MyUrl + "&ParentId="+ParentId;
var WinProps = "width=1000,height=500,top=0,left=0,scrollbars=yes,status=no,resizable=yes";
var EditWindow = window.open(MyUrl,'edit_category',WinProps);
}

//
function UpdateCategory()
{
document.EditCategory.action = "edit_category.asp?Action=Save";
document.EditCategory.submit();
}

//
function UpdateSubCategory(CurrentCategory)
{
document.EditSubCategory.action = "edit_sub_category.asp?Action=Save&CurrentCategory="+CurrentCategory;
document.EditSubCategory.submit();
}

//
function EditProducts(MasterId)
{
var RelatedList = "";
var RelatedLength = document.Products.elements['related_items_'+MasterId].length;
for(i = 0; i <= RelatedLength - 1; i ++)
	{
	if(i == RelatedLength - 1)
		{
		RelatedList  = RelatedList + document.Products.elements['related_items_'+MasterId].options[i].value;
		}
	else
		{
		RelatedList  = RelatedList + document.Products.elements['related_items_'+MasterId].options[i].value + "#";
		}	
	}
document.Products.related_items.value = RelatedList;
document.Products.action = "edit_product.asp?Action=Save";
document.Products.submit();
}

//
function EditNewProductCategory()
{
document.Products.action = "add_product_category.asp?Action=Save";
document.Products.submit();
}

//
function CloseWindow()
{
window.opener.location = window.opener.location;
window.close();
}