var colorkey = "taco";
var showhide = "hidden";
var layerkey = "taco";
var timerid;
var timerid2;


function stoptimeout (onoff) {
	window.clearTimeout(timerid);
}

function settimer () {
	timerid = setTimeout("document.getElementById('mainimage').src='productimages/'+ colorkey +'_md.jpg'", 250);
}

function setImage () {
	document.getElementById("mainimage").src="productimages/"+ colorkey +"_md.jpg";
}

function setaltImage (alt) {
	document.getElementById("mainimage").src="productimages/"+ colorkey +"_alt_"+ alt +"_md.jpg";
}

function showhidedescription () {
	var myzap = document.getElementById(15001).style.height;
		if (myzap == "127px"){
		document.getElementById(15001).style.height="auto";
		}
		if (myzap != "127px"){
		document.getElementById(15001).style.height="127px";
		document.getElementById(15001).style.overflow="hidden";
		}
	}
	
	

function setclicked (thisimage, color, sku, key) {
	var numberofthumbs = color;
	var mysku = sku;
	var mycolorkey = colorkey;
	var mykey = key;
	for ( x = 1 ; x <= numberofthumbs.length  ; x++ ){
		if ("'"+ mysku +"'"=="'"+ mycolorkey +"'"|| mycolorkey == "default"){
		document.getElementById(mykey).style.background="#FFCC00";
		}
		if ("'"+ x +"'"!="'"+ key +"'"){
		document.getElementById(x).style.background="";
		}
	}}

function selectSize (tacos, sizes, models, prices, skus, title, color, ship) {
	var mysizes = document.getElementById('newSizes');
	var mymodels = document.getElementById('newModel');
	if (mysizes != null){
		hasSize (tacos, sizes, models, prices, skus, title, color, ship);
	}
	if (mymodels != null){
		var modeltacos = "newModel";
		hasSize (modeltacos, sizes, models, prices, skus, title, color, ship);
	}
	else
	document.getElementById("pricetosend").value = prices;
	document.getElementById("skutosend").value = skus;
	document.getElementById("titletosend").value = title + " " + color + " " + ship;
}

function hasSize (tacos, sizes, models, prices, skus, title, color, ship) {
	
	//i=color index 1  itemarray= sm, md, lg
  var generalTitle = title;
  var generalColor = color;
  var ItemArray = sizes;
  var modelArray = models;
  var priceArray = prices;
  var skuArray = skus;
  var myEleSize ;
  var x ;
  // Empty the second drop down box of any choices
  for (var q=document.getElementById(tacos).options.length;q>=0;q--) document.getElementById(tacos).options[q]=null;
  
  // ADD Default Choice - in case there are no values
  myEleSize = document.createElement("option") ;
  myEleSize.setAttribute('value', ["0"]);
  var txt = document.createTextNode("[Select a size]");
  myEleSize.appendChild(txt)

  // newSizes.add(myEle) ;
  document.getElementById(tacos).appendChild(myEleSize)
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length || x < modelArray.length ; x++ ) {
      myEleSize = document.createElement("option") ;
      //myEle.value = x ;
	  if (priceArray[x] == null){
		var generalprice = priceArray[0];
	  }else{
		  var generalprice = priceArray[x];
		  }
	if (skuArray[x] == null){
		var generalsku = skuArray[0];
	  }else{
		  var generalsku = skuArray[x];
		  }
      myEleSize.setAttribute('value', [generalprice, generalsku, generalTitle, ItemArray[x], modelArray[x], generalColor, ship]);
      // myEle.text = ItemArray[x] ;
      var txt = document.createTextNode(ItemArray[x] || modelArray[x]);
      myEleSize.appendChild(txt)
      // newSizes.add(myEle) ;
      document.getElementById(tacos).appendChild(myEleSize);
    }
  }

function contentHide(sku) {
	document.getElementById("detailwrapper").removeChild(document.getElementById("remover"));
}

function newLink(info) {
	document.location.href = info;
}
function setPrice(info) {
	allinfo = info.split(',');
	document.getElementById("pricetosend").value = allinfo[0];
	document.getElementById("skutosend").value = allinfo[1];
	document.getElementById("titletosend").value = allinfo[2] + " " + allinfo[3]+ " " +allinfo[4]+ " " +allinfo[5]+ " " +allinfo[6];
	
	if (document.getElementById("checksize").childNodes.length == 1){
	document.getElementById("checksize").removeChild (document.getElementById("checksize").childNodes[0]);
	}
	if (document.getElementById("pricechange").childNodes.length == 2){
	document.getElementById("pricechange").removeChild (document.getElementById("pricechange").childNodes[1]);
	}
	
	var checksize = document.getElementById("checksize");
	var checkprice = document.getElementById("pricechange");
	var mySizeholder = document.createElement("span") ;
	var myPriceholder = document.createElement("span") ;

      var txtsize = document.createTextNode(allinfo[3] || allinfo[4]);
	   var txtprice = document.createTextNode(allinfo[0]);
	  
      mySizeholder.appendChild(txtsize)
	  myPriceholder.appendChild(txtprice)
	  myPriceholder.setAttribute('id', "pricer");
      // newSizes.add(myEle) ;
      document.getElementById("checksize").appendChild(mySizeholder);
	  document.getElementById("pricechange").appendChild(myPriceholder);
}

function setColor(color, price) {
	if (document.getElementById("checkcolor").childNodes.length == 1){
	document.getElementById("checkcolor").removeChild (document.getElementById("checkcolor").childNodes[0]);
	}
	if (document.getElementById("checksize").childNodes.length == 1){
	document.getElementById("checksize").removeChild (document.getElementById("checksize").childNodes[0]);
	}
	if (document.getElementById("pricechange").childNodes.length == 2){
	document.getElementById("pricechange").removeChild (document.getElementById("pricechange").childNodes[1]);
	}
	var checkcolor = document.getElementById("checkcolor");
	var myColorholder = document.createElement("span") ;
	
	var txtcolor = document.createTextNode(color + " ");
	myColorholder.appendChild(txtcolor)
	myColorholder.setAttribute('id', "colorchecker");
	document.getElementById("checkcolor").appendChild(myColorholder);
	
	var checkprice = document.getElementById("pricechange");
	var myPriceholder = document.createElement("span") ;

	   var txtprice = document.createTextNode(price);
	  
	  myPriceholder.appendChild(txtprice)
	  myPriceholder.setAttribute('id', "pricer");
      // newSizes.add(myEle) ;
	  document.getElementById("pricechange").appendChild(myPriceholder);
}

function validate_color()
{
if (document.getElementById('colorchecker').firstChild.nodeValue==false)
  {alert("Select a Color by Clicking on a Thumbnail");return false}
  if (document.getElementById('newSizes') != null){
  with (document.getElementById('newSizes'))
{
	if (value==null||value=="0")
  {alert("Select a Size from the Drop Down");return false}
else {return true}
}
}
} 

function validate_size()
{
with (document.getElementById('newSizes'))
{
	if (document.getElementById('newSizes') != null && value==null||value=="0")
  {alert("Select a Size from the Drop Down");return false}
else {return true}
}
}


function validate_model()
{
with (document.getElementById('newModel'))
{
	if (value==null||value=="0")
  {alert("Select a Model from the Drop Down");return false}
else {return true}
}
}



function validate_form(thisform)
{
with (thisform)
{
//var newColor = document.getElementById('colorhead');
	//var colorbox = document.getElementById('colorchecker').firstChild.nodeValue; 
	var mysizes = document.getElementById('newSizes');
	var mymodels = document.getElementById('newModel');
	var mycolor = document.getElementById('colorhead');
	
//	if (validate_color2910AC(choice2910AC,"Choose Color")==false)
 // {choice2910AC.focus();return false}
	if (mycolor != null){
      if(validate_color()==false){
	  mycolor.focus();return false}
	}
	
	if (mysizes != null){
      if(validate_size()==false){
	  mysizes.focus();return false}
	}
	
	if (mymodels != null){
      if(validate_model()==false){
	  mymodels.focus();return false}
	}
	
	/*if (newColor != null){
	if (validate_color(colorbox, "Select a Color")==false)
  {newColor.focus();return false}
	} */
	
	
	 
	/* if (newModel != null){
     if (validate_model(newModel, "Select a Model from the Drop Down")==false)
  {newModel.focus();return false}
	}*/
}}

function stoptimeout2 () {
	window.clearTimeout(timerid2);
}

function settimer2 (id) {
	timerid2 = setTimeout("document.getElementById("+"'"+ id +"'"+").style.visibility='hidden'", 200);
	}

function setvisibility (id) {
		var maincategories = document.getElementsByTagName("div").id="navdrop";
		
		for ( x = 1 ; x <= maincategories.length+3 ; x++ ){
		var cheese = id;
		var cheese2 = ("catagory"+x);
		if ("'"+ cheese2 +"'"=="'"+ id +"'"){
		document.getElementById(id).style.visibility="visible";
		}
		else if ("'"+ cheese2 +"'"!="'"+ id +"'"){
		document.getElementById(cheese2).style.visibility="hidden";
		}
	}
	}
	
	function eattacos (id) {
		var maincategories = document.getElementsByTagName("div").id="tulips";
		for ( x = 1 ; x <= 4  ; x++ ){
		var cheese = ("seccatagory"+x );
		var cheese3 = ("seccatagory"+id );
		if ("'"+ cheese3 +"'"=="'" + "seccatagory"+ x +"'"){
		document.getElementById(cheese3).style.visibility="visible";
		}
		else if ("'"+ cheese3 +"'"!="'" + "seccatagory"+ x +"'"){
		document.getElementById(cheese).style.visibility="hidden";
		}
	}
	}
