function draw_related(){
if (page_option_4!=1){
  //horizontal
 if (nRelated>0){
  document.write("<table><TR class=relProduct >");
  for (atn=0;atn< nRelated ;atn++){
    //document.write("<BR>");   
   if(Related_prod[atn].image !="" && rel_image_enable !="NONE" ){
   document.write("<TD class=relProduct WIDTH=170 VALIGN=TOP ALIGN=CENTER >");
   document.write("<A HREF=\"product.asp?pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&\" onClick=return(visitargs('product.asp','pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&')); >");
   if (rel_image_width !=""){
   document.write("<img ALIGN=CENTER ");
   document.write(" WIDTH =\"" + rel_image_width + "\" ");
   document.write("BORDER=0  VSPACE=0  HSPACE=0  ALT=\"" + Related_prod[atn].name + "\" SRC=\"assets/product_images/" + Related_prod[atn].image + "\"></A>");
   }
   else {
   document.write("<img ALIGN=CENTER WIDTH =\"" + Related_prod[atn].width + "\" BORDER=0  VSPACE=0  HSPACE=0  ALT=\"" + Related_prod[atn].name + "\" SRC=\"assets/product_images/"+ Related_prod[atn].image +"\"></A>");
   }
   document.write("");
   }
  document.write("<BR>");
  document.write("<A HREF=\"product.asp?pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&\" onClick=return(visitargs('product.asp','pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&')); >");
  document.write(Related_prod[atn].name + "</A>");
   /* - customer does not want any prices shown     
   if (page_option_5== 1){
   if (Related_prod[atn].list_price!="" && Related_prod[atn].sale_price!="" ){
   document.write("<font class=ListPricewSaleR >"+ rel_list_pricelab + Related_prod[atn].list_price + " </font>");
   document.write("<font class=SalePriceR >"+ rel_sale_pricelab + Related_prod[atn].sale_price + " </B></font>");
   }
   else {
    if (Related_prod[atn].list_price!="" && Related_prod[atn].sale_price=="" ){
    document.write("<font class=ListPricewoSaleR >" + rel_our_pricelab + Related_prod[atn].list_price + " </font>");

    }
   }
   
        }
   */
        document.write("</TD>");
  }
   document.write("</TR></table>"); 
 }
} 
if (page_option_4==1){
 if (nRelated>0){
  document.write(" <TABLE BORDER=0>");
  for (atn=0;atn< nRelated ;atn++){
   if(Related_prod[atn].image !="" && rel_image_enable !="NONE" ){
   document.write("<TR class=relProduct ><TD class=relProduct WIDTH=100% VALIGN=TOP ALIGN=CENTER >");
   if (rel_image_width !=""){
   document.write("<img ALIGN=CENTER ");
   document.write(" WIDTH =\"" + rel_image_width + "\" ");
   document.write("BORDER=0  VSPACE=0  HSPACE=0  ALT=\"" + Related_prod[atn].name + "\" SRC=\"assets/product_images/" + Related_prod[atn].image + "\"></A>");
   }
   else {
   document.write("<img ALIGN=CENTER WIDTH =\"" + Related_prod[atn].width + "\" BORDER=0  VSPACE=0  HSPACE=0  ALT=\"" + Related_prod[atn].name + "\" SRC=\"assets/product_images/"+ Related_prod[atn].image +"\"></A>");
   }
   document.write("</TD></TR>");
   }
        document.write(" <TR class=relProduct ><TD class=relProduct WIDTH=100% VALIGN=TOP ALIGN=CENTER >");
  document.write("<A HREF=\"product.asp?pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&\" onClick=return(visitargs('product.asp','pf_id=" + Related_prod[atn].pf_id + "&dept_id=" + Related_prod[atn].dept_id + "&')); >");
  document.write(Related_prod[atn].name + "</A>");
        if (page_option_5== 1){
   if (Related_prod[atn].list_price!="" && Related_prod[atn].sale_price!="" ){
   document.write("<font class=ListPricewSaleR >" + rel_list_pricelab + Related_prod[atn].list_price + " </font>");
   document.write("<font class=SalePriceR >" + rel_sale_pricelab + Related_prod[atn].sale_price + " </B></font>");
   }
   else {
    if (Related_prod[atn].list_price!="" && Related_prod[atn].sale_price=="" ){
    document.write("<font class=ListPricewoSaleR >"+ rel_our_pricelab + Related_prod[atn].list_price + " </font>");

    }
   }
        }
        document.write("</TD> </TR>");
  }
 }document.write("</TABLE>");
} 

}    
 


function setCartButton( sku ){
   var imgName = "";
   var index = "";

   try{
   if ( sku != null ){

      //find index in variant list
      for ( atn = 0; atn < product_var.length; atn++){
         if ( product_var[atn].sku == sku ){
            if ( product_var[atn].avail < 0 ) imgName="preorder.gif";
            else if ( product_var[atn].avail > 0 ) imgName="addtobag.gif";
             
            if ( imgName != "" ){
               document.getElementById("pbasket").src = "assets/images/images/images2010/product/" + imgName;
               document.getElementById("pbasket").style.display = "block";

            } else {
	        document.getElementById("pbasket").style.display = "none";
            }
            
            break;
         }
      }
   }
   }catch(e){}
} 


function initCartButton(){
   var boCnt = 0;
   var soCnt = 0;

   //If all sku's are on backorder set button to preorder.
   for ( atn = 0; atn < product_var.length; atn++){
      if ( product_var[atn].avail < 0 ) boCnt ++;
      if ( product_var[atn].avail == 0 ) soCnt ++;
   }

   if ( boCnt == product_var.length || soCnt == product_var.length) setCartButton( product_var[0].sku );
 

}


function draw_sku_option(){
   var stockMsg = "";
  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>");
	  
	  if (product_var[0].avail != 0) {
   		num_avail=1;
	       temp_avail = ""
   		if(product_var[0].attr_value1 =="" || product_var[0].attr_value1==" "){
			temp_avail="One Size";
		}else{
                     temp_avail=product_var[0].attr_value1;
              }
		document.write("<select class=\"dropmenu\"><option>Select Size</option><option>" + temp_avail + " - " + product_var[0].avail_msg + "</option></select>");
   	  }else{
   		document.write("<span class=\"errorField\"><font color='red'>SOLD OUT</font></span>");
   	  }
   	  document.write("<INPUT TYPE=HIDDEN  NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
       //  setCartButton(product_var[0].sku);
   	//  document.write("</TD></TR></TABLE></TD>");
   	}else{
	  //at least 1+ products in array
	  
	  var sellable=false;
	  for (j=0;j<product_var.length;j++){
		if(product_var[j].avail != "0"){sellable=true;}
	  }
	  if(sellable==true){

		//document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
		//document.write("<TR VALIGN=TOP><TD>");
		document.write("<SELECT class=dropmenu onchange=\"setCartButton(this.value);\"NAME=sku  >");
			i=attr_values.length-1;
			labelstr="";
			while (attr_label[i]!= "" && i >=0 ) {
			labelstr=labelstr + attr_label[i] + " ";
			i=i-1;
			}
			writeoption("","Select Size " ,sel_values[0]);
			for (atn=0;atn< product_var.length ;atn++){
				if (useVariantPrice=="True"){
					if (on_sale=="True"){
					writeoption(product_var[atn].attr_value1 + " $"+ OKStrOfPenny(product_var[atn].price_sale) ,sel_values[0]);
					} else {
					writeoption(product_var[atn].attr_value1 + " $"+ OKStrOfPenny(product_var[atn].price_list) ,sel_values[0]);
					}
				} else {
                                   ( product_var[atn].avail == 1 ) ? stockMsg="( 1 Left )" : stockMsg="";
					writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + " - " + product_var[atn].avail_msg + " " + stockMsg) ,sel_values[0]);
				}
			}
		document.write("</SELECT>");	
		//document.write("</TD></TR></TABLE></TD>");
	  }else{
	  	//document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
		//document.write("<TR VALIGN=TOP><TD>");
		document.write("<span class='errorField'><font color='red'>SOLD OUT</font></span>");
		document.write("<INPUT TYPE=HIDDEN  NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
   	  	//document.write("</TD></TR></TABLE></TD>");
              enable_basket=0;
	  }
	}
  }else{
  	//document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
	//document.write("<TR VALIGN=TOP><TD>");
	document.write("<span class='errorField'><font color='red'>SOLD OUT</font></span>");
	//document.write("</TD></TR></TABLE></TD>");
  }
}

function draw_image_2(){
	var imgHTML = "";
	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\">");
			}
			document.write("<img ALIGN =" + product_image[1].align + " "); 
			if (product_image[1].width!=""){document.write("WIDTH =" + product_image[1].width + " ");}
			// jat 1/11/08- removing border around main image
			document.write(" border=\"0\" class=\"mainimage\" ALT=\"" + product_image[1].alt_text + "\" ");         
			document.write(" SRC=\"" + porder_code + pvendor_code +"01.jpg\" name=\"big\" id=\"big\"></a>");
		}else{
			//product_image[1].image_show=="NONE"
			imgHTML = "<a href=\"01_z.jpg\" class=\"MagicThumb\" id=\"product_img\"";
			imgHTML += "rel=\"rel=expand-speed: 1000; keep-thumbnail: false; background-color: #000000; background-opacity: 50; background-speed: 200; caption-speed: 250; caption-height: 300; caption-width: 300; show-loading: true; loading-msg: Loading...; loading-opacity: 75; expand-position: center; keyboard: true; keyboard-ctrl: false; expand-trigger-delay: 200; click-to-initialize: false; swap-image-delay: 200; slideshow-speed: 1000; slideshow-loop: true; buttons-display: previous, next, close; expand-effect: cubic; restore-effect: cubic; caption-source: span; caption-position: bottom; image-size: fit-screen; expand-align: screen; link-target: _self; expand-trigger: click; restore-trigger: auto; swap-image: mouseover; slideshow-effect: dissolve; buttons: show; buttons-position: top right\">";
			
			document.write(imgHTML);
			document.write("<img ALIGN =\"" + product_image[1].align + "\" "); 
			if (product_image[1].width!=""){document.write("WIDTH =" + product_image[1].width + " ");}
			// jat 1/11/08 - removing border around main image
			document.write(" border=\"0\" class=\"mainimage\" ALT=\"" + product_image[1].alt_text + "\" ");    
			
			// ** jat 1/30/08 - removing pvendor_code from main image url
			//document.write(" SRC=\"" + porder_code + pvendor_code +"a.jpg\" name=\"big\" id=\"big\">");
			document.write(" SRC=\"" + porder_code +"01.jpg\"></a></a>");
		}  		
	}
}


function draw_image_2(){
   var isLetter = 	/^[a-zA-Z]$/
   var imgHTML = "";
   var baseImg = "";
   var baseImgZoom = "";

   if ( isLetter.test( altImages[0] )){
      //baseImg = "a.jpg";
      //baseImgZoom = "a.jpg";
   } else {
      baseImg = "01.jpg";
      baseImgZoom = "01_z.jpg";
   }
   imgHTML = '<a href="' + porder_code + baseImgZoom + '"';
   imgHTML += 'class="MagicThumb" id="product_img" rel="rel=expand-speed: 1000; keep-thumbnail: false; ';
   imgHTML += 'background-color: #000000; background-opacity: 50; background-speed: 200; caption-speed: 250; caption-height: 300; caption-width: 300; ';
   imgHTML += 'show-loading: true; loading-msg: Loading...; loading-opacity: 75; expand-position: center; keyboard: true; keyboard-ctrl: false; ';
   imgHTML += 'expand-trigger-delay: 200; click-to-initialize: false; swap-image-delay: 200; slideshow-speed: 1000; slideshow-loop: true; ';
   imgHTML += 'buttons-display: previous, next, close; expand-effect: cubic; restore-effect: cubic; caption-source: span; caption-position: bottom; ';
   imgHTML += 'image-size: fit-screen; expand-align: screen; link-target: _self; expand-trigger: click; restore-trigger: auto; ';
   imgHTML += 'swap-image: mouseover; slideshow-effect: dissolve; buttons: show; buttons-position: top right">';
   imgHTML += '<img src="' + porder_code + baseImg + '"/>';
   imgHTML +='<div id="zoomlayer"><font class="zoomlayerTxt">Click to Zoom</font></div></a></a>';
   
   document.write(imgHTML);

}
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=536,height=460,left = 372,top = 302');");
}

function swapJImg(img, state){
	var tmpsrc = img.src;
	if(state == 0){
		// display the 'on' image
		img.src = (img.src).replace("_off", "_on");
	}else{
		// display the 'off' image
		img.src = (img.src).replace("_on", "_off");
	}
}
