// Copyright 2004 - HOCO Enterprises, LLC 
//Beyer for HOCO Enterprises, LLC - July, 2004
//Beyer for HOCO - Convert to server-based system
//Global variables and settings 
//alert('Global Script');
// This global variable tracks the total number of items ordered
var total_ordered = 0;

// This global variable holds the personal details about the user
var current_user;

// This global variable holds the personal details about the stuff
var current_stuff;

// These global variables set the tax rate and shipping charge per item
var tax_rate = 0.07;
var shipping_charge = 8.50;
//This is used for hat descriptions must match cart_display

var hat_desc = new Array(10);
hat_desc[0] = '6 Panel Ball Cap';
hat_desc[1] = '5 Panel Ball Cap';
hat_desc[2] = 'Mesh-Type Ball Cap';
hat_desc[3] = '#3 Large Tote Bag';
hat_desc[4] = '#4 Fleece Blanket with Strap';
hat_desc[5] = 'POCI#5 License Plate Holder';
hat_desc[6] = 'POCI#6 2005 Convention Poster';
hat_desc[7] = 'POCI#7 Window Decal';
hat_desc[8] = 'POCI#8 Flying Disc';

var short_desc = new Array(15);
var desc_count = 7;

short_desc[0] = 'GMC Logo (One Color)';
short_desc[1] = 'Pontiac Logo (Two Tone) with Arrowhead';
short_desc[2] = 'Pontiac Logo (One Color) with Arrowhead';
short_desc[3] = 'GTO Emblem (One Color)';
short_desc[4] = 'GTO 6.5 Litre Emblem';
short_desc[5] = 'GRAND PRIX Script Emblem';
short_desc[6] = '2004 GTO Emblem';
short_desc[7] = "ROYAL GTO's Club Logo";
short_desc[8] = 'Build Your Car(sm) by HOCO<font size=1>&reg;</font>';
short_desc[9] = 'Tri-Power Emblem';
short_desc[10] = 'GTO Judge Emblem';
short_desc[11] = 'GXP Series Emblem';
short_desc[12] = 'GRAND PRIX (GP) Emblem';

var club_short_desc = new Array(07);
var club_desc_count = 2;

club_short_desc[0] = 'Pontiac-Oakland (POCI) Logo';
club_short_desc[1] = "ROYAL GTO's Club Logo";

//This is used for ordering all items except hats and T-Shirts
var color_desc = new Array(12);
var color_count = 12;

color_desc[1] = 'GMC Logo (One Color)';
color_desc[2] = 'Pontiac Logo (Two Tone) with Arrowhead';
color_desc[3] = 'Pontiac Logo (One Color) with Arrowhead';
color_desc[4] = 'GTO Emblem (White)';
color_desc[5] = 'GTO Emblem (Red)';
color_desc[6] = 'GTO Emblem (Black)';
color_desc[7] = 'GTO 6.5 Litre Emblem';
color_desc[8] = 'GRAND PRIX (GP) Emblem - White/Black';
color_desc[9] = 'GRAND PRIX (GP) Emblem - Black/White';
color_desc[10] = '2004 GTO Emblem';
color_desc[11] = 'GTO Judge Emblem';
color_desc[12] = 'Build Your Car (Go to Bottom of Screen)';

var club_color_desc = new Array(07);
var club_color_count = 2;

club_color_desc[1] = "ROYAL GTO's Logo";
club_color_desc[2] = 'Pontiac-Oakland (POCI) Logo';
// POCI no longer under contract - Note Array number changes in all html and cgi 
// Also update HOCO Cart Products script



var jkt_desc = new Array(10);
jkt_desc[0] = 'Varsity Jacket with Leather Sleeves';
jkt_desc[1] = 'Nylon with Fleece Lining';
jkt_desc[2] = "Nylon Coach's Jacket";
jkt_desc[3] = 'Varsity Jacket with Suede Sleeves';
jkt_desc[4] = 'Jean Jacket';
jkt_desc[5] = "Dupont&reg; 66 Nylon Satin Jacket";


var jkt_price = new Array(10);
jkt_price[0] = 194.95;
jkt_price[1] = 124.95;
jkt_price[2] = 104.95;
jkt_price[3] = 174.95;
jkt_price[4] = 124.95;
jkt_price[5] = 95.00;

var shirt_desc = new Array(10);
shirt_desc[0] = 'Short Sleeve Sport Shirt (50/50)';
shirt_desc[1] = 'Short Sleeve Sport Shirt (High Cotton)';
shirt_desc[2] = 'Short Sleeve Racing Shirt (High Cotton)';
shirt_desc[3] = 'My First Wheels Sport Shirt (50/50)';
shirt_desc[4] = 'My First Wheels Sport Shirt (High Cotton)';
shirt_desc[5] = 'Long Sleeve Denim Shirt (High Cotton)';

var shirt_price = new Array(10);
shirt_price[0] = 26.95;
shirt_price[1] = 26.95;
shirt_price[2] = 31.95;
shirt_price[3] = 25.95;
shirt_price[4] = 25.95;
shirt_price[5] = 31.95;

//Below is for club T-Shirts
var tshirt_desc = new Array(10);
tshirt_desc[0] = '[#13] The Great One (GTO T-Shirt)';
tshirt_desc[1] = '[#16H] WS Firebird ("The Muscle Lives" T-Shirt)';
tshirt_desc[2] = "(POCI#9) - POCI: Fabulous 50's";
tshirt_desc[3] = '(POCI#10) - POCI: The Early Years';
tshirt_desc[4] = '(POCI#11) - POCI: Heavy Muscle';
tshirt_desc[5] = '(POCI#12) - POCI: Big Iron';
tshirt_desc[6] = '(POCI#14) - POCI: Still Plays with Pontiacs';
tshirt_desc[7] = '(POCI#15) - POCI: Future Pontiac Lovers';

var tshirt_price = new Array(10);
tshirt_price[0] = 17.00;
tshirt_price[1] = 17.00;
tshirt_price[2] = 14.00;
tshirt_price[3] = 14.00;
tshirt_price[4] = 14.00;
tshirt_price[5] = 14.00;
tshirt_price[6] = 16.00;
tshirt_price[7] = 10.00;


//Below is for GM T-Shirts (tshirtw = "t-shirts without logo on sleeve")
var tshirtw_desc = new Array(05);
tshirtw_desc[0] = '[#80H] - "80 Years of Pontiac" T-Shirt';
tshirtw_desc[1] = tshirt_desc[0]
tshirtw_desc[2] = tshirt_desc[1]

var tshirtw_price = new Array(05);
tshirtw_price[0] = 15.00;
tshirtw_price[1] = 17.00;
tshirtw_price[2] = 17.00;

var sweatshirt_desc = new Array(10);
sweatshirt_desc[0] = 'Fleece Sweatshirt (50/50)';
sweatshirt_desc[1] = 'Fleece Sweatshirt (High Cotton)';
sweatshirt_desc[2] = 'My First Wheels Sweatshirt (50/50)';
sweatshirt_desc[3] = 'My First Wheels Sweatshirt (High Cotton)';

var swt_price = new Array(10);
swt_price[0] = 31.95;
swt_price[1] = 31.95;
swt_price[2] = 30.95;
swt_price[3] = 30.95;

//For non-Clubs
var front_designs = new Array(20);
var back_designs = new Array(20);
populate_designs();

//List all available designs and YOUR CAR
function populate_designs(){
     front_designs[0] = new add_design('Select Front of Jacket Design'); 
     back_designs[0] = new add_design('Select Back of Jacket Design'); 
     for (var counter = 1; counter <= color_count; counter++){ 
        front_designs[counter] = new add_design(color_desc[counter]);
        back_designs[counter] = new add_design(color_desc[counter]);
     }
}

//For Club Designs
var club_front_designs = new Array(10);
var club_back_designs = new Array(10);
populate_club_designs();

//List all available designs 
function populate_club_designs(){
     club_front_designs[0] = new add_design('Select Front of Jacket Design'); 
     club_back_designs[0] = new add_design('Select Back of Jacket Design'); 
     for (var counter = 1; counter <= club_color_count; counter++){ 
        club_front_designs[counter] = new add_design(club_color_desc[counter]);
        club_back_designs[counter] = new add_design(club_color_desc[counter]);
     }
}

function add_design(design){
     this.design = design
}

// For non-Clubs
function populate_design_lists(item, front_list, back_list, n_switch){
//Note: Below logic also in sweatshirt_display.htm

        if (item.substr(0,3) == 'swt'){
           front_designs[0] = new add_design('Select Small Sweatshirt Design'); 
           back_designs[0] = new add_design('Select Large Sweatshirt Design'); 
        }
	if (n_switch == '2' || n_switch == '3'){ 
	   //Reset the list
	   back_list.length = 0
	   for (counter = 0; counter <= color_count; counter++){
             back_list.options[counter] = new Option(back_designs[counter].design)
	     if (n_switch == '2'){
               front_list.options[front_list.counter] = null
	     }
	   }
	   if (n_switch == '2'){front_list.length = 0}
	   back_list.options[0].selected = true
	}
	if (n_switch == '1' || n_switch == '3'){ 
	   //Reset the list
	   front_list.length = 0
	   for (counter = 0; counter <= color_count; counter++){
             front_list.options[counter] = new Option(front_designs[counter].design)
	     if (n_switch == '1'){
		back_list.options[back_list.counter] = null
	     }
	   }
	   if (n_switch == '1'){back_list.length = 0}
	   front_list.options[0].selected = true
	}

        //Netscape 4 needs to refresh the page
//	if (its_ns4){history.go(0)}
	document.images[item + '_front'].src = '../images/space.gif';	
	document.images[item + '_back'].src = '../images/space.gif';
        oldcolor = '';
        clrstr = '_thumb'
        findclr = document.images[item + '_top_front'].src.indexOf(clrstr);
        cstr = document.images[item + '_top_front'].src.substr(findclr - 3, 3);
        oldcolor = '_' + cstr
        document.images[item + '_mid_front'].src = '../embimages/' + item + '_ft_mid' + oldcolor + '_thumb.jpg';
        if(item.substr(0,3) == 'jkt'){
	   document.images[item + '_mid_back'].src = '../embimages/' + item + '_bk_mid' + oldcolor + '_thumb.jpg';
	}
}

// For Clubs
function populate_club_design_lists(c_item, c_front_list, c_back_list, c_n_switch){
//Note: Below logic also in sweatshirt_display.htm

        if (c_item.substr(0,3) == 'swt'){
           club_front_designs[0] = new add_design('Select Small Sweatshirt Design'); 
           club_back_designs[0] = new add_design('Select Large Sweatshirt Design'); 
        }
	if (c_n_switch == '2' || c_n_switch == '3'){ 
	   //Reset the list
	   c_back_list.length = 0
	   for (counter = 0; counter <= club_color_count; counter++){
             c_back_list.options[counter] = new Option(club_back_designs[counter].design)
	     if (c_n_switch == '2'){
               c_front_list.options[c_front_list.counter] = null
	     }
	   }
	   if (c_n_switch == '2'){c_front_list.length = 0}
	   c_back_list.options[0].selected = true
	}
	if (c_n_switch == '1' || c_n_switch == '3'){ 
	   //Reset the list
	   c_front_list.length = 0
	   for (counter = 0; counter <= club_color_count; counter++){
             c_front_list.options[counter] = new Option(club_front_designs[counter].design)
	     if (c_n_switch == '1'){
		c_back_list.options[c_back_list.counter] = null
	     }
	   }
	   if (c_n_switch == '1'){c_back_list.length = 0}
	   c_front_list.options[0].selected = true
	}

        //Netscape 4 needs to refresh the page
//	if (its_ns4){history.go(0)}
	document.images[c_item + '_front'].src = '../images/space.gif';	
	document.images[c_item + '_back'].src = '../images/space.gif';
        oldcolor = '';
        clrstr = '_thumb'
        findclr = document.images[c_item + '_top_front'].src.indexOf(clrstr);
        cstr = document.images[c_item + '_top_front'].src.substr(findclr - 3, 3);
        oldcolor = '_' + cstr
        document.images[c_item + '_mid_front'].src = '../embimages/' + c_item + '_ft_mid' + oldcolor + '_thumb.jpg';
        if(c_item.substr(0,3) == 'jkt'){
	   document.images[c_item + '_mid_back'].src = '../embimages/' + c_item + '_bk_mid' + oldcolor + '_thumb.jpg';
	}
}

// function round_decimals(original_number, decimals)
//
//     original_number    A floating-point number.
//     decimals           The number of decimal places.
//
// Returns: the original_number rounded to decimals decimal places.

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

// function pad_with_zeros(rounded_value, decimal_places)
//
//     rounded_value    A rounded floating-point number.
//     decimals         The number of decimal places.
//
// Returns: the rounded_number padded with extra zeros 
// to get the specified number of decimal places.

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {

        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

// Find active radio button
function radio_active(radio_group){
	
     // Run though the group 
     for (cnt = 0; cnt < radio_group.length; cnt++){

	// When we find the activated button, return the index
	if (radio_group[cnt].checked){
           return cnt
        }
     }
     // If no button is activated, return -1
     return -1	

}

//Print the screen
function prntpage(text){
   text=document
   print(text)
}

// Create Customer Screen
function picwindow(picture,w,h) {
w = w + 20;
h = h + 20;
 if (newindow != '') {PicWindow.close();} 
newindow = 'open';
PicWindow = window.open("","PicWindow",
   "width=" + w + ", height=" + h + ",toolbar=no,location=no,directories=no,status=no," +
   "menubar=no,scrollbars=no,resizable=no,");
PicWindow.moveTo(150,150);
partbeg = '<HTML>' +
	'<HEAD>' +	
	'<TITLE>HOCO Picture Window</TITLE>' +
	'</HEAD>' +
	'<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#007070">';
pic = '<center><img src="../embimages/' + picture + '" border="no"></center>';
theend = '</BODY>' +
        '</HTML>';

	self.PicWindow.document.write(partbeg);
	self.PicWindow.document.write(pic);
	self.PicWindow.document.write(theend);
	self.PicWindow.document.close();
}

// Create Cart Screen as Window only
function cart_window(cart_in) {
   if (document.forms[0].cart_open_status.value == 'not_open'){
	document.forms[0].cart_open_status.value = 'cart_open';
   }
//   alert('CartWindow = ' + CartWindow);
   if (!CartWindow.closed && CartWindow.location){
      CartWindow.focus();
   }
   else{
      cartfile = "https://www.hoco.com/embroidery/cart" + cart_in + ".html";
      CartWindow = window.open(cartfile,"CartWindow",
        "width=750,height=500,toolbar=no,location=no,directories=no,status=no," +
        "menubar=no,scrollbars=yes,resizable=no,");
      CartWindow.moveTo(50,50);
   }
}

// Do not delete window.location command - hard to find that works with Netscape
function refresh_page(switch_in){
//alert('switch-in = ' + switch_in);
   if (switch_in == 0){ 
      window.location.reload( true );
   }
   if (switch_in == 3 || switch_in == 12 || switch_in == 13){ 
      document.forms.hat_display.submit();
   }
   if (switch_in == 4 || switch_in == 14){
      document.forms.jacket_display.submit();
   }
   if (switch_in == 5 || switch_in == 15){
      document.forms.shirt_display.submit();
   } 
   if (switch_in == 6 || switch_in == 16){
      document.forms.sweatshirt_display.submit();
   } 
   if (switch_in == 7 || switch_in == 17){
      document.forms.tshirt_display.submit();
   } 
}

<!-- Original:  Gilbert Davis -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

function loadImages() {
if (document.getElementById) {  // DOM3 = IE5, NS6
document.getElementById('hidepage').style.visibility = 'hidden';
}
else {
if (document.layers) {  // Netscape 4
document.hidepage.visibility = 'hidden';
}
else {  // IE 4
document.all.hidepage.style.visibility = 'hidden';
      }
   }
}


// End of global variables and settings
