var dom = (document.getElementById)? true : false;
var ns6 = dom && !document.all;
var SmOptArray=new Array();
var LgOptArray=new Array();
var SmMatArray=new Array();
var LgMatArray=new Array();
var x = 0;
var s = 0;
var l = 0;
var sm = 0;
var lm = 0;
var currOpt = 0;

function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function changeOption(x){
frametable = FIND("showframeopt");
mattable = FIND("showmatopt");
eloptions = FIND("optionstable");
thisform = FIND("orderform")
	if(x.toLowerCase() == "small framed"){
		frametable.innerHTML = SmOptLoop();
		mattable.innerHTML = SmMatLoop();
		eloptions.style.visibility = "visible";
		eloptions.style.display = "block";
	}else if(x.toLowerCase() == "large framed"){
		frametable.innerHTML = LgOptLoop();
		mattable.innerHTML = LgMatLoop();
		eloptions.style.visibility = "visible";
		eloptions.style.display = "block";
	}else{
		eloptions.style.visibility = (dom && !ns6)? "hidden" : "hide";
		eloptions.style.display = "none";
		for(i=0;i<thisform.elements.length;i++){
			if(thisform[i].name == 'Frame' || thisform[i].name == 'Mat'){
				thisform[i].checked = false;
				thisform[i].checked = false;
			}
		}
	}
}

function OptItem(img, name, price){
	this.img = img
	this.name = name
	this.price = price
}

function SmMat(img, name, price) {
	SmMatArray[SmMatArray.length] = new OptItem(img, name, price);
	sm++;
}

function LgMat(img, name, price) {
	LgMatArray[LgMatArray.length] = new OptItem(img, name, price);
	lm++;
}

function SmOpt(img, name, price) {
	SmOptArray[SmOptArray.length] = new OptItem(img, name, price);
	s++;
}

function LgOpt(img, name, price) {
	LgOptArray[LgOptArray.length] = new OptItem(img, name, price);
	l++;
}

function SmMatLoop(){
newtable = '<table width="100%" align="center" cellspacing="3" cellpadding="0"><tr><td><strong>'+SmMatHeader+'</strong></td></tr></table><table width="100%">'
	for(currOpt = 0; currOpt < sm; currOpt ++){
		var breakrow = currOpt % MatNumCols
			if(breakrow == 0){
				newtable += '<tr>';
			}
		newtable += '<td><table width="100%"><tr><td width=1><input name="Mat" id="Mat" type="radio" value="'+ SmMatArray[currOpt].name;
			if(SmMatArray[currOpt].price!= ""){
				newtable += ' (+' + SmMatArray[currOpt].price + ')'
			}
		newtable += '" onClick="updateOptionPrice(this.form,this);"'
			if(currOpt == 0){
				newtable += ' checked';
			}
		newtable += '></td><td>' + SmMatArray[currOpt].img + '</td>';
		newtable += '<td>' + SmMatArray[currOpt].price + '</td></tr>';
		newtable += '<tr><td></td><td>' + SmMatArray[currOpt].name + '</td></tr></table>';
			if(breakrow == MatNumCols - 1){
				newtable += '</tr>';
			}
	}
	newtable += '</table>';
return(newtable)
}

function LgMatLoop(){
newtable = '<table width="100%" align="center" cellspacing="3" cellpadding="0"><tr><td><strong>'+LgMatHeader+'</strong></td></tr></table><table width="100%">'
	for(currOpt = 0; currOpt < lm; currOpt ++){
		var breakrow = currOpt % MatNumCols
			if(breakrow == 0){
				newtable += '<tr>';
			}
		newtable += '<td><table width="100%"><tr><td width=1><input name="Mat" id="Mat" type="radio" value="'+ LgMatArray[currOpt].name;
			if(LgMatArray[currOpt].price!= ""){
				newtable += ' (+' + LgMatArray[currOpt].price + ')'
			}
		newtable += '" onClick="updateOptionPrice(this.form,this);"';
			if(currOpt == 0){
				newtable += ' checked';
			}
		newtable += '></td><td>' + LgMatArray[currOpt].img + '</td>';
		newtable += '<td>' + LgMatArray[currOpt].price + '</td></tr>';
		newtable += '<tr><td></td><td>' + LgMatArray[currOpt].name + '</td></tr></table>';
			if(breakrow == MatNumCols - 1){
				newtable += '</tr>';
			}
	}
	newtable += '</table>';
return(newtable)
}

function SmOptLoop(){
newtable = '<table><tr><td><strong>'+SmFrHeader+'</strong></td></tr></table><table width="100%" align="center" cellspacing="3" cellpadding="0">'
	for(currOpt = 0; currOpt < s; currOpt ++){
		var breakrow = currOpt % FrNumCols
			if(breakrow == 0){
				newtable += '<tr>';
			}
		newtable += '<td><table><tr><td width=1><input name="Frame" id="Frame" type="radio" value="'+ SmOptArray[currOpt].name;
			if(SmOptArray[currOpt].price!= ""){
				newtable += ' (+' + SmOptArray[currOpt].price + ')'
			}
		newtable += '" onClick="updateOptionPrice(this.form,this);"';
			if(currOpt == 0){
				newtable += ' checked';
			}
		newtable += '></td><td>' + SmOptArray[currOpt].img + '</td>';
		newtable += '<td>' + SmOptArray[currOpt].price + '</td></tr>';
		newtable += '<tr><td></td><td>' + SmOptArray[currOpt].name + '</td></tr></table>';
			if(breakrow == FrNumCols - 1){
				newtable += '</tr>';
			}
	}
	newtable += '</table>';
return(newtable)
}

function LgOptLoop(){
newtable = '<table><tr><td><strong>'+LgFrHeader+'</strong></td></tr></table><table width="100%" align="center" cellspacing="3" cellpadding="0">'
	for(currOpt = 0; currOpt < l; currOpt ++){
		var breakrow = currOpt % FrNumCols
			if(breakrow == 0){
				newtable += '<tr>';
			}
		newtable += '<td><table><tr><td width=1><input name="Frame" id="Frame" type="radio" value="'+ LgOptArray[currOpt].name;
			if(LgOptArray[currOpt].price!= ""){
				newtable += ' (+' + LgOptArray[currOpt].price + ')'
			}
		newtable += '" onClick="updateOptionPrice(this.form,this);"';
			if(currOpt == 0){
				newtable += ' checked';
			}
		newtable += '></td><td>' + LgOptArray[currOpt].img + '</td>';
		newtable += '<td>' + LgOptArray[currOpt].price + '</td></tr>';
		newtable += '<tr><td></td><td>' + LgOptArray[currOpt].name + '</td></tr></table>';
			if(breakrow == FrNumCols - 1){
				newtable += '</tr>';
			}
	}
	newtable += '</table>';
return(newtable)
}

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) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {

        for (var counter = 1; counter <= pad_total; counter++) 

            value_string += "0"
        }
    return value_string
}

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function updateOptionPrice(thisform,thisinput){
	var price = basePrice;
	var thedifference = 0;
	var pricevalAr = new Array();
	var direction = "add";
	var modPrice = "";
	if(price != "")
		price = parseFloat(price);
	else
		price = 0;

	for(i=0;i<thisform.elements.length;i++){ 
		priceval = 0;
		pricevalAr = 0;
		if(thisform.elements[i].type == "select-one"){
			priceval = thisform.elements[i].options[thisform.elements[i].selectedIndex].value
			
			if(priceval.indexOf("(+$") > -1) {
				pricevalAr = priceval.split("(+$");
				direction = "add";
			}else if(priceval.indexOf("(+") > -1) {
				pricevalAr = priceval.split("(+");
				direction = "add";
			}else if(priceval.indexOf("(-") > -1) {
				pricevalAr = priceval.split("(-");
				direction = "sub";
			}else if(priceval.indexOf("(-$") > -1) {
				pricevalAr = priceval.split("(-$");
				direction = "sub";
			}else if(priceval.indexOf("(*") > -1) {

				pricevalAr = priceval.split("(*");
				direction = "mult";
			}
			if(pricevalAr.length > 1){
				priceval = pricevalAr[1].split(")");
				priceval = parseFloat(priceval[0]);
			} else {
				priceval = 0;
			} 
			if(direction == "add")
				price = price + priceval
			else if(direction == "sub")
				price = price - priceval
			else {
				thedifference = (price * priceval) - price;
				price = price * priceval;
				if(thisinput) thisinput.value = "(+" + thedifference + ")";
			}
		} else {
			if(thisform.elements[i].type == "radio"){
				if(thisform.elements[i].checked){
					priceval = thisform.elements[i].value;
					fullinput = priceval;
					if(priceval.indexOf("(+$") > -1) {
						pricevalAr = priceval.split("(+$");
						direction = "add";
					} else if(priceval.indexOf("(+") > -1) {
						pricevalAr = priceval.split("(+");
						direction = "add";
					} else if(priceval.indexOf("(-") > -1) {
						pricevalAr = priceval.split("(-");
						direction = "sub";
					}else if(priceval.indexOf("(-$") > -1) {
						pricevalAr = priceval.split("(-$");
						direction = "sub";
					}else if(priceval.indexOf("(*") > -1) {
						pricevalAr = priceval.split("(*");
						direction = "mult";
					}
					if(pricevalAr.length > 1){
						priceval = pricevalAr[1].split(")");
						priceval = parseFloat(priceval[0]);
					}else
						priceval = 0;
					if(direction == "add")
						price = price + priceval
					else if(direction == "sub")
						price = price - priceval
					else {
						thedifference = (price * priceval) - price;
						price = price * priceval;
						if(thisinput) thisinput.value = "(+" + round_decimals(thedifference,2) + ")";
					}
				}
			}
		}
	}
	modPrice = modPrice + "$" + toDollarsAndCents(price);
	if (document.all){
		dispprice.innerHTML = modPrice;
	}else if (document.getElementById){
		document.getElementById("dispprice").innerHTML = modPrice;
	}

}
function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById("sub"+obj);
	var el2 = document.getElementById("arrow"+obj);
	var ar = document.getElementById("leftnav").getElementsByTagName("span");
		if(el.style.display != "block"){ 
				for (var i=0; i<ar.length; i++){
					if (ar[i].className=="submenu") 
					ar[i].style.display = "none";
					document.getElementById("arrow"+i).innerHTML ='<img src="/lib/yhst-20535199497037/spacer.gif">';
				}
			el2.innerHTML ='<img src="/lib/yhst-20535199497037/arrow-down.gif">';
			el.style.display = "block";
		}else{
			el.style.display = "none";
			el2.innerHTML ='<img src="/lib/yhst-20535199497037/spacer.gif">';
		}
	}
}

function makeWin(imsrc, ww, wh) {
ww=ww+25; wh=wh+50;
w1=window.open('','w1','width='+ww+',height='+wh+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
w1.document.open();
w1.document.write("<html><head><title>Image Zoom<\/title><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"><META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\"><\/head>");
w1.document.write("<body bgcolor='#FFFFFF' text='#000000' leftmargin=2 topmargin=10><p align=center>");
w1.document.write("<img name=theimg src=" + imsrc + "><br>");
w1.document.write("<a href=\"javascript:window.close();\"><font size=1 face=tahoma color=#000000>close window<\/font><\/a><\/body><\/html>");
w1.document.focus();
};
