// functions to replace out of stock messages at sku level
function OOSMsg ()
{
  this.msgcode
  this.msgtxt
}

/* Array used to contain the replacement stock messaging */
var OOSMsgs = new Array();
OOSMsgs[0] = new OOSMsg(); OOSMsgs[0].msgcode='GWG'; OOSMsgs[0].msgtxt='Sold out. Item is no longer available.';
OOSMsgs[1] = new OOSMsg(); OOSMsgs[1].msgcode='CLE'; OOSMsgs[1].msgtxt='Sold out. Item is no longer available.';
OOSMsgs[2] = new OOSMsg(); OOSMsgs[2].msgcode='REP'; OOSMsgs[2].msgtxt='Currently out of stock. Item on order.';

/* Modifies the availability message for a sku based on certain criteria. */
function ModOOSMessage(product)
{
  //if the product is out of stock, set the stock msg to the sku level msg
  for (i=0;i<OOSMsgs.length;i++)
  {
    if (OOSMsgs[i].msgcode == product.vvendor_code)
    {
	  //if out of stock
	  if (product.avail == 0)
      {        
		product.avail_msg = OOSMsgs[i].msgtxt;		
      }
	  //if back ordered AND no message already in place...
	  if(product.avail < 0 && product.avail_msg=="")
      {   
      	//DO NOTHING -- JMS FEB 28, 2008     
		//product.avail_msg = OOSMsgs[i].msgtxt;		
      }
    }
  }

  return;
}

function CreateOptionString(prod_var)
{
  var opt_string = "";
  var the_price = "";
  var the_attrs = "";
  var attr2_flag = false;

  //get the price value if it should be included
  if (useVariantPrice=="True")
	{
    the_price = " - $";
    if (on_sale=="True")
		{
      the_price += OKStrOfPenny(prod_var.price_sale);
    }else{
      the_price += OKStrOfPenny(prod_var.price_list);
    }
  }

  //if attr_value2 has a value 
  if (prod_var.attr_value2 != "")
  {
      the_attrs += prod_var.attr_value2;
      attr2_flag = true;
  }

  if (prod_var.attr_value1 != "")
  {
    if (attr2_flag == true)
    {
      the_attrs += " - ";
    }
    the_attrs += prod_var.attr_value1;
  }

  opt_string = the_attrs + the_price + " &nbsp;&nbsp;&nbsp;&nbsp; " + prod_var.avail_msg;


  return opt_string;
}

function CreateOptionStringReverse(prod_var)
{
  var opt_string = "";
  var the_price = "";
  var the_attrs = "";
  var attr1_flag = false;

  //get the price value if it should be included
  if (useVariantPrice=="True")
	{
    the_price = " - $";
    if (on_sale=="True")
		{
      the_price += OKStrOfPenny(prod_var.price_sale);
    }else{
      the_price += OKStrOfPenny(prod_var.price_list);
    }
  }

  //if attr_value2 has a value and it isn't our replacement OOS message
  if (prod_var.attr_value1 != "" )
  {
      the_attrs += prod_var.attr_value1;
      attr1_flag = true;
  }

  if (prod_var.attr_value2 != "" )
  {
    if (attr1_flag == true)
    {
      the_attrs += " - ";
    }
    the_attrs += prod_var.attr_value2;
  }

  opt_string = the_attrs + the_price + " &nbsp;&nbsp;&nbsp;&nbsp; " + prod_var.avail_msg;


  return opt_string;
}

/////////////////////////////////////////////////////

function draw_image_2(){
	var imageFile = pf_id;
	if(product_image[0].image != "" && product_image[0].image.indexOf("t.jpg")==-1 ){
		imageFile = product_image[0].image;				
	}
	
	if (product_image[1].scr=="PRODUCT" && product_image[1].image!="" ) {			
			if (product_image[1].image_show=="TARGET REG" || product_image[1].image_show=="TARGET" ){
				if (product_image[1].image_show=="TARGET REG"){
				 if (user_guid==""){
				  document.write("<A HREF=\"shopper_lookup.asp?target=" + product_image[1].target + "&\" onClick=return(visitargs('shopper_lookup.asp',\"target=" + product_image[1].target + "&\")); target=\"_top\" >");
				 }else {
				  document.write("<A HREF=\"" + product_image[1].target + "\" onClick=return(visitargs('" + product_image[1].target + "')); target=\"_top\" >");
				 }
				}else {
				 document.write("<a HREF=\"" + product_image[1].target + "\" target=\"_top\">");
				}
										
				draw_S7_image(imageFile, "s7product", product_image[1].alt_text, "mainimage", null); 	
				document.write("</a>");
			}
			else {				
				//show image with zoom link
				//if enable_manual_quote...
				if (enable_manual_quote==1) { 
					//set image set as zoom image
					draw_s7_image_wZoomLink(imageFile+"_is", imageFile, "s7product", product_image[1].alt_text, "mainimage", null);
				} else {  
					//set regular image as zoom image
					draw_s7_image_wZoomLink(imageFile, imageFile, "s7product", product_image[1].alt_text, "mainimage", null);
				}
		  }
	} else {
		//show image with zoom link
		//if enable_manual_quote...
		if (enable_manual_quote==1) { 
			//set image set as zoom image
			draw_s7_image_wZoomLink(imageFile+"_is", imageFile, "s7product", product_image[1].alt_text, "mainimage", null);
		} else {  
			//set regular image as zoom image
			draw_s7_image_wZoomLink(imageFile, imageFile, "s7product", product_image[1].alt_text, "mainimage", null);
		}
	}
	
}


//draws purchase etc buttons
function draw_buttons()
{		
    if(exclude_cart.indexOf(','+pvendor_code+',') == -1) {
        if (enable_basket==1) {
        document.write("<input type=\"image\" name=\"pbasket\" src=\"assets/images/"+button+"bskt1.gif\"");
        document.write("alt=\"Add to your shopping cart\" onclick=\"return findsku(true);\">");
        }
    }
    /* Not showing any other buttons
	if (enable_compare==1)
    {
        document.write("<br><INPUT TYPE=Image  NAME=\"cbasket\" SRC=\"assets/images/" + button + "compare.gif\" ");
        document.write("BORDER=0 ALT=\"Add to your compare cart\" onclick=\"return findsku();\"> ");
    }
    if (enable_quote==1)
    {
        document.write("<br><INPUT TYPE=Image  NAME=\"qbasket\" SRC=\"assets/images/" + button + "quote.gif\" ");
        document.write("BORDER=0 ALT=\"Add to your quote cart\" onclick=\"return findsku();\"> ");
    }
    if(exclude_wish.indexOf(','+pvendor_code+',') == -1)
    {
        if (enable_wish==1)
        {
            document.write("<INPUT TYPE=Image  NAME=\"wbasket\" SRC=\"assets/images/" + button + "wish.gif\" ");
            document.write("BORDER=0 ALT=\"Add to your wish cart\" onclick=\"return findsku();\"> ");
        }
    }
    if (enable_manual_quote==1)
    {
        document.write("<br><INPUT TYPE=Image  NAME=\"wbasket\" SRC=\"assets/images/" + button + "mquote.gif\" ");
        document.write("BORDER=0 ALT=\"Add to your quote cart\" onclick=\"return findsku();\"> ");
    }*/
}

//function to add returnpathString to the end of returnpath value (after returnpath input is written to page)
function fillReturnPath(){
    if(document.getElementById("returnpath")){		
			document.getElementById("returnpath").value = "product.asp?dept_id=" + dept_id + "&pf_id="+ pf_id  + "&s_id=" + i_jscript_uu_sid +returnpathString+"&addfrom=product";
    }
}

function toggle(mode)
{
    if(mode==0)
    { //read reviews
        document.getElementById("Read_Reviews").className = "displayedDiv";
        document.getElementById("Write_Review").className="hiddenDiv";
        document.getElementById("Product_Info").className="hiddenDiv";		
        document.getElementById("tab0").src = "assets/images/product/reviews_tab_on.gif";
        document.getElementById("tab2").src = "assets/images/product/specs_tab_off.gif";
    } else if(mode==1){ 
	//write reviews
        document.getElementById("Read_Reviews").className="hiddenDiv";
        document.getElementById("Write_Review").className = "displayedDiv";
        document.getElementById("Product_Info").className="hiddenDiv";		
        document.getElementById("tab0").src = "assets/images/product/reviews_tab_on.gif";
        document.getElementById("tab2").src = "assets/images/product/specs_tab_off.gif";
    } else {
	//specs/info
        document.getElementById("Product_Info").className = "displayedDiv";
        document.getElementById("Read_Reviews").className="hiddenDiv";
        document.getElementById("Write_Review").className="hiddenDiv";		
        document.getElementById("tab0").src = "assets/images/product/reviews_tab_off.gif";
        document.getElementById("tab2").src = "assets/images/product/specs_tab_on.gif";
    }
    return;
}


function setTDheight()
{
    var td = document.getElementById('p_wrapper');
    var newHeight = 0;
    var tabs = document.getElementById('tabs');
    var div1 = document.getElementById("Product_Info");
    var div2 = document.getElementById("Read_Reviews");
    var div3 = document.getElementById("Write_Review");

    if(tabs.offsetHeight != 0)
    {
        if (div1.offsetHeight >= div2.offsetHeight)
        {
            if (div1.offsetHeight >= div3.offsetHeight)
            {
                newHeight = tabs.offsetHeight + div1.offsetHeight;
            }else{
                newHeight = tabs.offsetHeight + div3.offsetHeight;
            }
        }else{
            if (div2.offsetHeight >= div3.offsetHeight)
            {
                newHeight = tabs.offsetHeight + div2.offsetHeight;
            }else{
                newHeight = tabs.offsetHeight + div3.offsetHeight;
            }
        }

        td.style.height = newHeight + "px";

    }else if(tabs.style.pixelHeight)
    {
        //alert (tabs.style.pixelHeight);

        newHeight=div1.style.pixelHeight;
    }
 //alert(tabs.style.offsetHeight);
 return true;
}