function draw_sku_option()
{
	if (product_var.length >= 1 ){
		if(product_var.length==1){
			document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
			document.write("<TR VALIGN=TOP ><TD class=ProductAttrlabel>" + attr_label[0] + "</TD><TD>");
			document.write("&nbsp;" + product_var[0].attr_value1 + "</TD></TR>");
			document.write("<TR VALIGN=TOP ><TD class=ProductAttrlabel>" + attr_label[1] + "</TD><TD>");
			document.write("&nbsp;" + product_var[0].attr_value2 + "</TD></TR>");
			document.write("<TR><TD colspan=2>" + product_var[0].avail_msg + "</TD>");
			document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
			document.write("</TR></TABLE></TD>");
		}else{	
			document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
			document.write("<TR VALIGN=TOP ><TD class=ProductAttrlabel ><b>Select From:</b><br></TD></TR><TR><TD>");
			document.write("<SELECT class=ProductAttr NAME=sku  >");
			i=0;
			labelstr="";
			while (attr_label[i]!= "" && i < attr_values.length ) {
				labelstr=labelstr + attr_label[i] + " ";
				i++;
			}
			writeoption("",labelstr ,sel_values[0]);
			for (atn=0;atn< product_var.length ;atn++){
				if(product_var[atn].avail!="0"){
					if (useVariantPrice=="True"){
						if (on_sale=="True"){
							writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + " - " + product_var[atn].attr_value2 + " - $"+ OKStrOfPenny(product_var[atn].price_sale)) + " - " + product_var[atn].avail_msg + "" ,sel_values[0]);
						}else{
							writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + " - " + product_var[atn].attr_value2 + " - $"+ OKStrOfPenny(product_var[atn].price_list)) + " - " + product_var[atn].avail_msg + "" ,sel_values[0]);
						}
					}else{
						if (product_var[atn].avail_msg==""){
							product_var[atn].avail_msg="on back order";
						}
						writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + " - " + product_var[atn].attr_value2) + " - " + product_var[atn].avail_msg + "",sel_values[0]);
					}
				}
			}
			document.write("</SELECT></TD>");	
			document.write("</TR></TABLE></TD>");
		}
	}
} //end draw_sku_option

function draw_sku_option2()
{
	var dropdownattr1 = "";
	var attrname = "";
	var dropdown_label="";
	document.write("<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0>");
	document.write("<TR VALIGN=TOP ><TD class=\"ProductAttrlabel\">Please select the following options:</td></tr>");
	
	if (product_var.length >= 1 ){
		if(product_var.length!=1){
			for (outer=0;outer<attr_values.length;outer++)
			{
				attrname = "attr" + (outer+1);
				document.write("<TR VALIGN=TOP ><TD>");
				//alert(outer+" "+attr_values[outer].length)
				if (attr_values[outer].length==1)
				{
					document.write("<select name="+attrname+" id="+attrname+" onchange=\"get_values("+(outer+1)+");findprice();\" class=\"ProductAttr\" style=\"display:none\">");
					if (attr_label[outer]=="")
					{
						dropdown_label="Attribute";
					}else
					{
						dropdown_label=attr_label[outer];
					}
					//document.write('<option value="" selected>'+dropdown_label+'</option>');
					for(innerarr=0;innerarr<attr_values[outer].length;innerarr++)
					{
					  dropdownattr1=attr_values[outer][innerarr];
					  document.write('<option value=\''+dropdownattr1+'\'>'+dropdownattr1+'</option>');
					}
					document.write("</select>");
					////document.write("<div id=single_option"+attrname+">"dropdown_label+": "+dropdownattr1+"</div>");
					document.write("<div id=single_option"+(outer+1)+">"+dropdownattr1+"</div>");
				}else{
					document.write("<select name="+attrname+" id="+attrname+" onchange=\"get_values("+(outer+1)+");findprice();\" class=\"ProductAttr\">");
					if (attr_label[outer]=="")
					{
						dropdown_label="Attribute";
					}else
					{
						dropdown_label=attr_label[outer];
					}
					document.write('<option value="" selected>'+dropdown_label+'</option>');
					attr_values[outer].sort(smart_sort);
					for(innerarr=0;innerarr<attr_values[outer].length;innerarr++)
					{
					  dropdownattr1=attr_values[outer][innerarr];
					  document.write('<option value=\''+dropdownattr1+'\'>'+dropdownattr1+'</option>');
					}
					document.write("</select>");
					document.write("<div id=single_option"+(outer+1)+"></div>");
				}
				document.write("</TD></TR>");
			}
			document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"\" >");
		}
		else
		{
			//jas - 15.APR.08 - added to handle only one sku on page
			document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
		}
	}
	//document.write("<tr><td>Qty: <input type=text name=qty value=1 size=1></TD></TR>");
	document.write("</table>");
	//document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
	document.write("<INPUT TYPE=HIDDEN  NAME=qty VALUE='1'>");
} //end draw_sku_option

//get_values receives the attr number of the dropdown that has changed.
//
function get_values(ddnum)
{
  var thisattr,nextdd,tempattr,tempdd;
  var ctr = 0;
  var optstr = "";
  var tempopt;
  var attr_flag = true;
  var selection = "";
  var sel_flag = false;


  switch(attr_values.length)
  {
    case 5:
      var dd5 = document.getElementById('attr5');
    case 4:
      var dd4 = document.getElementById('attr4');
    case 3:
      var dd3 = document.getElementById('attr3');
    case 2:
      var dd2 = document.getElementById('attr2');
      var dd1 = document.getElementById('attr1');

      for (i=ddnum+1;i<=attr_values.length;i++)
      {
        //clear out the next dropdown
        nextdd = eval("dd"+i);
        //store the selected value so that it will remain selected if available
        selection = nextdd.value;
        for (j=nextdd.options.length-1;j>=0;j--)
        {
          nextdd.options[j] = null;
        }
var sortarray= new Array();
//~ sortarray[0]=attr_label[i];
        //loop thru product array
        for (atn=0;atn< product_var.length;atn++)
        {
          attr_flag = true;

          for (k=1;k<=i-1;k++)
          {
            //check each dropdown up to one before nextdd
            tempattr = eval("product_var[atn].attr_value"+k);
            tempdd = eval("dd"+k).value;
            if (tempattr != tempdd)
            {
              //this product doesn't match our selected values
              attr_flag = false;
            }
          }
          if (attr_flag == true)
          {
	  if (product_var[atn].avail !="0"){
              //store the attr if it is new
              thisattr = eval("product_var[atn].attr_value"+i);
              if (optstr.indexOf(";" + thisattr + ";") == -1)
              {
                optstr += ";" + thisattr + ";";
                //add to array here and sort instead of writing option
sortarray[ctr]=thisattr;
                ctr++;
              }
	   }
          }
        }
	//write options here and clear array
	//~ if (sortarray.length==0)
	//~ {
		//~ nextdd.style.display = "none";
		//~ document.getElementById("single_option"+i).innerHTML="currently unavailable";
	//~ }else 
	if (sortarray.length==1)
	{
		nextdd.style.display = "none";
		for (s=0;s<sortarray.length;s++){
			if (sortarray[s] == selection) { sel_flag = true; }else{ sel_flag = false; }
			tempopt = new Option(sortarray[s],sortarray[s],sel_flag);
			nextdd.options[s] = tempopt;
			document.getElementById("single_option"+i).innerHTML=sortarray[s];
		}
	}else
	{
		
		tempopt = new Option(attr_label[i-1],attr_label[i-1],false);
		nextdd.options[0] = tempopt;
		sortarray.sort(smart_sort);
		if (sortarray.length==0)
		{	
			nextdd.style.display = "none";
			document.getElementById("single_option"+i).innerHTML="Currently Unavailable";
			document.getElementById("avail_mess").innerHTML = "";
			
		}else
		{
			nextdd.style.display = "block";
			document.getElementById("single_option"+i).innerHTML="";
		}
		for (s=0;s<sortarray.length;s++){
			if (sortarray[s] == selection) { sel_flag = true; }else{ sel_flag = false; }
			tempopt = new Option(sortarray[s],sortarray[s],sel_flag);
			nextdd.options[s+1] = tempopt;
		}
	}
//sortarray.clear();
        optstr = "";
        ctr = 0;
        selection = "";
      }
      break;
    case 1: //1 dropdown - do nothing here
    case 0: //no dropdowns - do nothing here
    default:

      break;
  }
}

function findsku()
{if (typeof attr_values!="undefined"){
	if(product_var.length>1){
	//var sku_flds = document.getElementsByName("sku");
	//var qty_flds = document.getElementsByName("qty");
	var matchsku=false;
	var eachsku=0;
	var selectedsku;
	while (matchsku==false && eachsku<product_var.length)
	{
		var matching=true;
		for (drop=1;drop<=attr_values.length ;drop++)
		{
			//document.getElementById('this').value=document.getElementById('dropsku'+drop).options[document.getElementById('dropsku'+drop).selectedIndex].value;
			if (eval("product_var["+eachsku+"].attr_value"+drop)!=document.getElementById('attr'+drop).options[document.getElementById('attr'+drop).selectedIndex].value){matching=false;}
		}
		if (matching==true){selectedsku=eval("product_var["+eachsku+"].sku");matchsku=true;
		//sku_flds.value="selectedsku";
		//qty_flds.value="1";
		//alert(selectedsku);
		document.form1.sku.value=selectedsku;
		//document.form1.submit();
		return true;

		}
		eachsku=eachsku+1;
	}
	}
	}
}

function findprice(){
if (typeof attr_values!="undefined"){
	//var sku_flds = document.getElementsByName("sku");
	//var qty_flds = document.getElementsByName("qty");
	var matchsku=false;
	var eachsku=0;
	var selectedskuprice;
	var listprice;
	var avail_message;
	while (matchsku==false && eachsku<product_var.length)
	{
		var matching=true;
		for (drop=1;drop<=attr_values.length ;drop++)
		{
			//document.getElementById('this').value=document.getElementById('dropsku'+drop).options[document.getElementById('dropsku'+drop).selectedIndex].value;
			if (eval("product_var["+eachsku+"].attr_value"+drop)!=document.getElementById('attr'+drop).options[document.getElementById('attr'+drop).selectedIndex].value){matching=false;}
		}
		if (matching==true){
		avail_message = eval("product_var["+eachsku+"].avail_msg");
		if (eval("product_var["+eachsku+"].price_sale")!="" && eval("product_var["+eachsku+"].price_sale")!="0" && eval("product_var["+eachsku+"].price_sale")<eval("product_var["+eachsku+"].price_list")){
			listprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_list)");matchsku=true;
			selectedskuprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_sale)");matchsku=true;
			document.getElementById("prod_price").innerHTML = "<font class='ListPricewSale'><br>Regular Price:&nbsp;$"+listprice+"</font><font class='SalePrice'><br>ON SALE!&nbsp;$"+selectedskuprice+"</font><br>";
			document.getElementById("avail_mess").innerHTML = "<br>"+avail_message;
		}else{
			selectedskuprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_list)");matchsku=true;
			document.getElementById("prod_price").innerHTML = "<font class='ListPricewoSaleP'><br>Selected Item Price&nbsp;$"+selectedskuprice+"</font><br>";
			document.getElementById("avail_mess").innerHTML = "<br>"+avail_message;
		}
		
		//sku_flds.value="selectedsku";
		//qty_flds.value="1";
		//document.form1.sku.value=selectedsku;
		//document.form1.submit();
		return true;

		}
		eachsku=eachsku+1;
	}
	}
}
