var CustDet = new Array();
var arrSize = new Array();
var arrShap = new Array();
var arrColr = new Array();
var arrDsgn = new Array();

CustDet[1] = new Array("Mu","Mug(s)",          "smlt", "srbt","wba","0SRGWLHNB","fpoV");
CustDet[2] = new Array("Ju","Jug(s)",          "q13g", "srbz","wba","0SRGWLHN", "fpo");
CustDet[3] = new Array("Pl","Plate(s)",        "825",  "LPF", "wba","0WH",      "fpoE");
CustDet[4] = new Array("Bo","Bowl(s)",         "bprhu","",    "wba","0SRGWLH",  "fpoE");
CustDet[5] = new Array("Pi","Pitcher(s)",      "q13g", "srbz","wba","0SRGWLH1", "fpoV");
CustDet[6] = new Array("Cr","Crock(s)",        "bprhu","",    "wba","0SRGWLH",  "fpoE");
CustDet[7] = new Array("Ca","Candleholder(s)", "",     "k12", "wba","",         "");
CustDet[8] = new Array("Lb","Little Bottle(s)","",     "",    "wba","",         "");
CustDet[9] = new Array("La","Lanthorn(s)",     "",     "",    "wba","",         "");
CustDet[10]= new Array("Ch","Chamberpot(s)",   "wD",   "",    "wba","0SRGL",    "");
CustDet[11]= new Array("In","Inkwell(s)",      "",     "",    "wba","",         "");
CustDet[12]= new Array("Cn","Butter Churn(s)", "yz",   "nD",  "wba","",         "");
CustDet[13]= new Array("Bk","2qt Lidded Baker","",     "sr",  "wba","",         "");
CustDet[14]= new Array("Dl","18th Cent. Doll", "",     "",    "wb","",         "");
CustDet[15]= new Array("Ct","Canteen",         "",     "",    "wba","",         "");
CustDet[16]= new Array("Ud","Unity Mugs",    "ZM",    "s",     "wb","", "");

arrSize[1] = new Array("s","Small (10-14oz)" ,14);
arrSize[2] = new Array("m","Medium (16-20oz)",18);
arrSize[3] = new Array("l","Large (22-26oz)" ,20);
arrSize[4] = new Array("t","Quart (32oz)"    ,25);
arrSize[5] = new Array("q","Quart"           ,20);
arrSize[6] = new Array("r","Quart"           ,20);
arrSize[7] = new Array("1","&#189; Gallon"   ,27);
arrSize[8] = new Array("3","3 Quart"         ,35);
arrSize[9] = new Array("g","Gallon"          ,42);
arrSize[10]= new Array("b","Small"           ,10);
arrSize[11]= new Array("p","Porringer"       ,15);
arrSize[12]= new Array("h","&#189; Gallon"   ,25);
arrSize[13]= new Array("u","3 Quart"         ,30);
arrSize[14]= new Array("8","8-10in"          ,16);
arrSize[15]= new Array("2","12in"            ,25);
arrSize[16]= new Array("5","15in"            ,35);
arrSize[17]= new Array("w","Without Lid"     ,30);
arrSize[18]= new Array("D","Lidded"          ,35);
arrSize[19]= new Array("y","&#189; Gallon"   ,40);
arrSize[20]= new Array("z","Gallon"          ,55);
arrSize[21]= new Array("S","Small (10-14oz)" ,15);
arrSize[22]= new Array("M","Medium (16-20oz)",20);
arrSize[23]= new Array("Z","Small (10-14oz)" ,20);

arrShap[1] = new Array("s","Straight-sided"           ,0 );
arrShap[2] = new Array("r","Round-sided"              ,0 );
arrShap[3] = new Array("b","Bellied"                  ,0 );
arrShap[4] = new Array("t","Tyg"                      ,5 );
arrShap[5] = new Array("z","Shouldered"               ,0 );
arrShap[6] = new Array("L","Plate/Platter"            ,0 );
arrShap[7] = new Array("P","Trencher/Pieplate"        ,2 );
arrShap[8] = new Array("F","Fluted Pieplate"          ,4 );
arrShap[9] = new Array("k","4-6in Candlestick"        ,0 );
arrShap[10]= new Array("1","Finger-ring holder"       ,0 );
arrShap[11]= new Array("2","Fluted finger-ring holder",0 );
arrShap[12]= new Array("n","without Dasher"           ,0 );
arrShap[13]= new Array("D","with wooden Dasher"       ,5 );

arrColr[1] = new Array("w","White w/ Blue"   ,0 );
arrColr[2] = new Array("b","Brown"           ,0 );
arrColr[3] = new Array("a","Agate"           ,0 );

arrDsgn[1] = new Array("0","None"                     ,0 );
arrDsgn[2] = new Array("S","Shield"                   ,5 );
arrDsgn[3] = new Array("R","Rosette"                  ,5 );
arrDsgn[4] = new Array("G","G.R."                     ,5 );
arrDsgn[5] = new Array("W","Wheat"                    ,5 );
arrDsgn[6] = new Array("L","Lion Head"                ,5 );
arrDsgn[7] = new Array("H","Shell"                    ,5 );
arrDsgn[8] = new Array("B","Bartman Face (stylized)"  ,5 );
arrDsgn[9] = new Array("N","Greenman Face (realistic)",5 );
arrDsgn[10]= new Array("f","Fleur-de-lis"             ,3 );
arrDsgn[11]= new Array("p","Pyrate"                   ,3 );
arrDsgn[12]= new Array("o","Lions"                    ,3 );

arrDsgn[13]= new Array("1","Bellarmine Bartman"       ,15);
arrDsgn[14]= new Array("V","Flowering Vine (scratch-in)" ,5 );
arrDsgn[15]= new Array("E","Flowering Vine (scratch-in)" ,10);
arrDsgn[16]= new Array("U","Unite or Die"             ,0);

function ModifyCode(sectr,code){
  CustomCode = CustomCode.substr(0,sectr-1)+code+CustomCode.substr(sectr,CustomCode.length);
  if(CustomCode.substr(0,2)=="Pl"){
    if(sectr == 4 && (code == 2 || code == 5)) {
	CustomCode = CustomCode.substr(0,4)+"L"+CustomCode.substr(5,CustomCode.length-5);
    }
    if(sectr == 5 && (code=="P"||code=="F")) {
	CustomCode = CustomCode.substr(0,3)+"8"+CustomCode.substr(4,CustomCode.length-4);
    }
  }
  UpdateCust(CustomCode);
}

function cancelform(){
  custdiv=parent.document.getElementById("Custmzr");
  custdiv.style.visibility = "hidden";
}

function submitform(){
  for(x=0; x < document.Customize.Quantity.value; x++){
    parent.additem(CustomCode,document.Customize.PriceTot.value/document.Customize.Quantity.value,document.Customize.Description.value,'pagecatalog.htm');
  }
}

function UpdateCust(UpCode){
  var price=0; // Pass this in, instead of initializing.
  CustomCode = UpCode;

  var strType = "";
  var intType = 0;
  for (var zz=1;zz<CustDet.length;zz++){
    if(UpCode.substr(0,2)==CustDet[zz][0]){
	strType = CustDet[zz][1];
	intType = zz;
    }
  }
  if(UpCode.substr(0,2)=="Pl") strType = "";
  if(UpCode.substr(0,2)=="Ca") strType = "";

  // Extract item price
  for (var x=1;x<arrSize.length;x++){
    if(UpCode.charAt(3) == arrSize[x][0]) price=arrSize[x][2];
  }
  if (intType==7||intType==8) price=8;
  if (intType==9) price=30;
  if (intType==11) price=15;
  if (intType==13) price=35;
  if (intType==14) price=13;
  if (intType==15) price=30;

  for (x=1;x<arrShap.length;x++){
    if(UpCode.charAt(4) == arrShap[x][0]) price=price+arrShap[x][2];
  }
  for (x=1;x<arrDsgn.length;x++){
    if(UpCode.charAt(6) == arrDsgn[x][0]) price=price+arrDsgn[x][2];
  }

  if(UpCode.substr(0,2)=="Pl"&&UpCode.charAt(3)=="8"&&UpCode.charAt(6)=="E") price=price-5;

  if(UpCode.charAt(5) == "a"){   // Agateware +3$ for mug,sm.bwl,btl. $7 else
    if(price<19) {price=price+3;}
    else         {price=price+7;}
  }

  // Export updating product information
  document.Customize.PriceTot.value = price * parseInt(document.Customize.Quantity.value);

  var imgID = "images/Cart/"+UpCode.substr(0,2)+UpCode.substr(4,1)+".gif";
  var shaID = document.getElementById("ShapePic");
  shaID.src = imgID;

  var strSize = "";
  switch(UpCode.charAt(3)){			// Size Buttons
    case "s":
	strSize = "small-sized";
    	document.Customize.Size[0].checked = true;
    	break;
    case "q":
	strSize = "1-quart";
    	document.Customize.Size[0].checked = true;
    	break;
    case "b":
	strSize = "Small";
    	document.Customize.Size[0].checked = true;
	break;
    case "8":
	strSize = "8-10 inch";
	document.Customize.Size[0].checked = true;
	break;
    case "w":
	strSize = "without Lid";
	document.Customize.Size[0].checked = true;
	break;
    case "y":
	strSize = "1/2-gallon";
	document.Customize.Size[0].checked = true;
	break;
    case "m":
	strSize = "medium-sized";
    	document.Customize.Size[1].checked = true;
    	break;
    case "1":
	strSize = "1/2-gallon";
    	document.Customize.Size[1].checked = true;
    	break;
    case "p":
	strSize = "Porringer";
    	document.Customize.Size[1].checked = true;
	break;
    case "D":
	strSize = "lidded";
	document.Customize.Size[1].checked = true;
	break;
    case "z":
	strSize = "gallon";
	document.Customize.Size[1].checked = true;
	break;
    case "2":
	strSize = "12 inch";
	document.Customize.Size[1].checked = true;
	document.Customize.Shape[0].checked = true;
	break;
    case "r":
	strSize = "1-quart";
    	document.Customize.Size[2].checked = true;
    	break;
    case "l":
	strSize = "large-sized";
    	document.Customize.Size[2].checked = true;
    	break;
    case "3":
	strSize = "3-quart";
    	document.Customize.Size[2].checked = true;
    	break;
    case "5":
	strSize = "15 inch";
	document.Customize.Size[2].checked = true;
	document.Customize.Shape[0].checked = true;
	break;
    case "t":
	strSize = "quart-sized";
    	document.Customize.Size[3].checked = true;
    	break;
    case "g":
	strSize = "1-gallon";
    	document.Customize.Size[3].checked = true;
    	break;
    case "h":
	strSize = "1/2-gallon";
    	document.Customize.Size[3].checked = true;
	break;
    case "u":
	strSize = "3-quart";
    	document.Customize.Size[4].checked = true;
	break;
    case "Z":
	strSize = "small-sized";
    	document.Customize.Size[0].checked = true;
	document.Customize.Shape[0].checked = true;
    	document.Customize.Color[0].checked = true;
    	break;
    case "M":
	strSize = "medium-sized";
    	document.Customize.Size[1].checked = true;
    	break;
    default:
  }

  var strShape = "";
  switch(UpCode.charAt(4)){			// Shape Buttons
    case "s":
	strShape = "straight-sided";
    	document.Customize.Shape[0].checked = true;
    	break;
    case "L":
	if(document.Customize.Size[0].checked==true){strShape = "Plate";}
	else {strShape = "Platter"}
	document.Customize.Shape[0].checked = true;
	break;
    case "k":
	strShape = "candle-stick";
    	document.Customize.Shape[0].checked = true;
    	break;
    case "n":
	strShape = "without dasher";
    	document.Customize.Shape[0].checked = true;
    	break;
    case "r":
	strShape = "round-sided";
    	document.Customize.Shape[1].checked = true;
    	break;
    case "P":
	strShape = "Trencher / Pie Plate";
	document.Customize.Shape[1].checked = true;
	break;
    case "1":
	strShape = "finger-ring candle holder";
    	document.Customize.Shape[1].checked = true;
    	break;
    case "D":
	strShape = "with wooden Dasher";
    	document.Customize.Shape[1].checked = true;
    	break;
    case "b":
	strShape = "bellied";
    	document.Customize.Shape[2].checked = true;
    	break;
    case "F":
	strShape = "Fluted Pie Plate";
	document.Customize.Shape[2].checked = true;
	break;
    case "2":
	strShape = "fluted finger-ring candle holder";
    	document.Customize.Shape[2].checked = true;
    	break;
    case "t":
	strShape = "tyg";
    	document.Customize.Shape[3].checked = true;
    	break;
    case "z":
	strShape = "shouldered";
    	document.Customize.Shape[3].checked = true;
    	break;
    default:
  }

  var imgID = "images/Cart/"+UpCode.substr(5,1)+".jpg";
  var colID = document.getElementById("ColorPic");
  colID.src = imgID;

  var strColor = "";
  switch(UpCode.charAt(5)){			// Color Buttons
    case "w":
	strColor = "White";
    	document.Customize.Color[0].checked = true;
    	break;
    case "b":
	strColor = "Brown";
    	document.Customize.Color[1].checked = true;
    	break;
    case "a":
        strColor = "Agate";
        document.Customize.Color[2].checked = true;
        break;
    default:
  }

  var imgID = "images/Cart/des"+UpCode.substr(6,1)+".gif";
  var sprID = document.getElementById("SprigPic");
  sprID.src = imgID;  

  var strDesign = "";
  switch(UpCode.charAt(6)){
    case "S":						// Designs
	strDesign = "a raised Shield design.";
	sprID.style.display = "block";
    	document.Customize.Design[1].checked = true;
	break;
    case "R":
	strDesign = "a raised Rosette.";
	sprID.style.display = "block";
    	document.Customize.Design[2].checked = true;
	break;
    case "G":
	strDesign = "a George Rex (King George of England) sprig.";
	sprID.style.display = "block";
    	document.Customize.Design[3].checked = true;
	break;
    case "W":
	strDesign = "a raised Wheat design.";
	sprID.style.display = "block";
    	document.Customize.Design[4].checked = true;
	break;
    case "L":
	strDesign = "a raised Lion head.";
	sprID.style.display = "block";
    	document.Customize.Design[5].checked = true;
	break;
    case "H":
	strDesign = "a raised Shell design.";
	sprID.style.display = "block";
    	document.Customize.Design[6].checked = true;
	break;
    case "1":								//Belarmine
	strDesign = "a Bellarmine Bartman design.";
	sprID.style.display = "block";
    	document.Customize.Design[7].checked = true;
	break;
    case "N":
	strDesign = "a realistic Green Man sprig.";
	sprID.style.display = "block";
    	document.Customize.Design[7].checked = true;
	break;
    case "B":
	strDesign = "a raised Bartman face.";
	sprID.style.display = "block";
    	document.Customize.Design[8].checked = true;
	break;
    case "f":
	strDesign = "a French fleur-de-Lis stamp.";
	sprID.style.display = "block";
    	document.Customize.Design[CustDet[intType][5].length+0].checked = true;
	break;
    case "p":
	strDesign = "a Pyrate stamp.";
	sprID.style.display = "block";
    	document.Customize.Design[CustDet[intType][5].length+1].checked = true;
	break;
    case "o":
	strDesign = "a Rampant lion stamp.";
	sprID.style.display = "block";
    	document.Customize.Design[CustDet[intType][5].length+2].checked = true;
	break;
    case "V":
    case "E":
	strDesign = "an etched Leaf &amp; Vine pattern.";
	sprID.style.display = "block";
    	document.Customize.Design[CustDet[intType][5].length+3].checked = true;
	break;
    case "U":
	strDesign = "a Unite or Die stamp.";
	sprID.style.display = "none";
    	document.Customize.Design[1].checked = true;
	break;
    default:
	strDesign = "no additional design.";
	sprID.style.display = "none";
    	if (CustDet[intType][5]!="") document.Customize.Design[0].checked = true;
  }

  // Update description
  var strDesc = strColor;
  if (strSize != "") strDesc = strDesc + ", " + strSize;
  if (strShape!= "") strDesc = strDesc + ", " + strShape;
  if (strType != "") strDesc = strDesc + " " + strType;
  strDesc = strDesc + " with " + strDesign;
  document.Customize.Description.value = strDesc;
}
