// FILE: tallpaul.js
// PROGRAMMER: Gina Barrett
// MODIFIED BY: Travis Palmer, 9-25-2006
// DESCRIPTION: This file contains various JavaScript functions used by the Tall
//              Pauls Tall Mall website.


// Declare our global variables.

// saved_price is an array that contains the base price, and all the modifiers
// to the base price.
saved_price = new Array();
saved_price[0] = saved_price[1] = 0;

function check(vwitem)
{
	document.getElementByName("vwitem").innerHTML = product
}

function check(width)
{
	// Assign the base price.
	saved_price[0] = width;
	
	// This is a hack to get JavaScript to add the numbers, instead of
	// concatenate the strings.
	width = Math.abs(width) + Math.abs(saved_price[1]);
	
	width = "$ " + width.toFixed(2);
	document.getElementById("text_price").innerHTML = width;
}

function colorone(color)
{
document.getElementById("myColorOne").innerHTML = color
}

function colortwo(color2)
{
document.getElementById("myColorTwo").innerHTML = color2
}

function chooseImage(el){ 
   sel = el.options[el.selectedIndex]; 
    
   if(!sel.value){ 
      alert('Please choose an option'); 
   } 
   else{ 
      img = "" + sel.innerHTML + ""; 
   } 
   document.getElementById('myPrice').innerHTML = img 
} 

function chooseOption(el){ 
   sel = el.options[el.selectedIndex]; 
    
   if(!sel.value){ 
      alert('Please choose an option'); 
   } 
   else{ 
      img = "" + sel.title + ""; 
   } 
   document.getElementById('myOptionA').innerHTML = img 
} 

function update_price(opt) {
	re_opt = new RegExp('\\(\\s*\\+\\s*\\$?\\s*(\\d+(?:\\.\\d+)?|\\.\\d+)\\s*\\)');
	price = 0;
		
	// Clear the modifiers before we calculate them.
	saved_price[1] = 0;
		
	// Calculate the individual modifiers to the base price, and
	// store them in saved_price[1].
	for (i = 0; i < opt.form.elements.length; i++) {
		e = opt.form.elements[i];
		if (e.type.substr(0,6) == "select") {
			if (r_opt = re_opt.exec(e[e.selectedIndex].text)) {
				saved_price[1] += r_opt ? r_opt[1] * 1 : 0;
			}
		}
	}
		
	// Add the base price to the modifiers.
	// Same hack in check() used here when adding.
	final_price = Math.abs(saved_price[0]) + Math.abs(saved_price[1]);
	final_price = "$ " + final_price.toFixed(2);
	
	// Update the total price.
	document.getElementById("text_price").innerHTML = final_price;
}				

function swapColor1(el){ 
   sel = el.options[el.selectedIndex]; 
    
   if(!sel.value){ 
      alert('Please choose an option'); 
   } 
   else{ 
      img = "" + sel.innerHTML + ""; 
   } 
   document.getElementById('myColor').innerHTML = img 
} 

/* MAKE MENUS WORK IN IE */
/* ------------------------------------------------------------------------ */

sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }
}

window.onload=startList;
