﻿//
// program.js
// Copyright(c) 2008 Ready Action Media
//

var Browser = {
    version: parseInt(navigator.appVersion),
    isNetscape: navigator.appName.indexOf("Netscape") != -1,
    isMicrosoft: navigator.appName.indexOf("Microsoft") != -1
    };

function Product(num,name,cost) {
    this.Number = num;
    this.Name = name;
    this.Cost = cost;
}

// Product items
var ProductItems = new Array();
ProductItems["001C"] = new Product("001C", "Baby Girl Birdie", "2.50");
ProductItems["002C"] = new Product("002C", "Baby Boy Birdie", "2.50");
ProductItems["003C"] = new Product("003C", "Little Girl Birdie", "2.50");
ProductItems["004C"] = new Product("004C", "Heart Birdie", "2.50");
ProductItems["005C"] = new Product("005C", "Crab Birdie", "2.50");
ProductItems["006C"] = new Product("006C", "Birthday Birdie", "2.50");
ProductItems["007C"] = new Product("007C", "Birthday Balloon Birdie", "2.50");
ProductItems["008C"] = new Product("008C", "Butterfly Birdie", "2.50");
ProductItems["009C"] = new Product("009C", "Bug Birdie", "2.50");
ProductItems["010C"] = new Product("010C", "Star Birdie", "2.50");
ProductItems["011C"] = new Product("011C", "Flower Birdie", "2.50");
ProductItems["012C"] = new Product("012C", "Pink Thank You", "6.00");
ProductItems["013C"] = new Product("013C", "Green Thank You", "6.00");
ProductItems["014C"] = new Product("014C", "Birthday Cake", "2.00");

// Tags
ProductItems["001T"] = new Product("001T", "Baby Girl Birdie", "1.50");
ProductItems["002T"] = new Product("002T", "Baby Boy Birdie", "1.50");
ProductItems["003T"] = new Product("003T", "Little Girl Birdie", "1.50");
ProductItems["004T"] = new Product("004T", "Heart Birdie", "1.50");
ProductItems["005T"] = new Product("005T", "Crab Birdie", "1.50");
ProductItems["006T"] = new Product("006T", "Birthday Birdie", "1.50");
ProductItems["007T"] = new Product("007T", "Birthday Balloon Birdie", "1.50");
ProductItems["008T"] = new Product("008T", "Butterfly Birdie", "1.50");
ProductItems["009T"] = new Product("009T", "Bug Birdie", "1.50");
ProductItems["010T"] = new Product("010T", "Star Birdie", "1.50");
ProductItems["011T"] = new Product("011T", "Flower Birdie", "1.50");

// Bags
ProductItems["001BS"] = new Product("001BS", "Red Ticking - Flower", "4.00");
ProductItems["001BM"] = new Product("001BM", "Red Ticking - Flower", "6.00");
ProductItems["001BL"] = new Product("001BL", "Red Ticking - Flower", "8.00");
ProductItems["002BS"] = new Product("002BS", "Orange Gingham - Crab", "4.00");
ProductItems["002BM"] = new Product("002BM", "Orange Gingham - Crab", "6.00");
ProductItems["002BL"] = new Product("002BL", "Orange Gingham - Crab", "8.00");
ProductItems["003BS"] = new Product("003BS", "Pink Dot - Baby Pin", "4.00");
ProductItems["003BM"] = new Product("003BM", "Pink Dot - Baby Pin", "6.00");
ProductItems["003BL"] = new Product("003BL", "Pink Dot - Baby Pin", "8.00");
ProductItems["004BS"] = new Product("004BS", "Blue - Baby Pin", "4.00");
ProductItems["004BM"] = new Product("004BM", "Blue - Baby Pin", "6.00");
ProductItems["004BL"] = new Product("004BL", "Blue - Baby Pin", "8.00");
ProductItems["005BS"] = new Product("005BS", "Yellow Seersucker - Star", "4.00");
ProductItems["005BM"] = new Product("005BM", "Yellow Seersucker - Star", "6.00");
ProductItems["005BL"] = new Product("005BL", "Yellow Seersucker - Star", "8.00");
ProductItems["006BS"] = new Product("006BS", "Yellow Stripe - Bug", "4.00");
ProductItems["006BM"] = new Product("006BM", "Yellow Stripe - Bug", "6.00");
ProductItems["006BL"] = new Product("006BL", "Yellow Stripe - Bug", "8.00");
ProductItems["007BS"] = new Product("007BS", "Pink Seersucker - Pink Seer", "4.00");
ProductItems["007BM"] = new Product("007BM", "Pink Seersucker - Pink Seer", "6.00");
ProductItems["007BL"] = new Product("007BL", "Pink Seersucker - Pink Seer", "8.00");

function createPPItem(n,v) {
    if (typeof n != "string" || typeof v != "string" )
        throw new "createPPItem(): Invalid parameter(s)";
    var ppi;
    if ( Browser.isMicrosoft )
    {
        ppi = document.createElement("<input name=\"" + n + "\"></input");
    }
    else
    {
        ppi = document.createElement("input");
        ppi.setAttribute("name", n);
    }
    ppi.setAttribute("type", "hidden" );
    ppi.setAttribute("value", v);
    return ppi;
}

function createPP(x) {   
}

function viewCart() {
	var f = document.forms["viewcart"];
	if ( f != null ) {
		f.submit();
	}
}

function addItem(x) {
	if (typeof x != "string" )
		throw new "addItem(): Invalid parameter.";
	var f = document.forms["addtocart"];

	if ( f == null ) {
		alert("'addtocart' form does not exist");
	}
	else {
	    var item = ProductItems[x];
	    if ( item == null || item == undefined ) {
	        alert("Invalid item number.");
	    }
	    else {
		    f.item_number.setAttribute("value", item.Number);
		    f.item_name.setAttribute("value", item.Name);
		    f.amount.setAttribute("value", item.Cost);		
		    f.submit();
		}
	}
}

function getItem(x) {
    if ( typeof x == "string" ) {
        var o = document.getElementById(x);
        if ( o != null )
            return o.options[o.selectedIndex].value;
    }
    return null;       
}
