/*
 * Kirtland's Yarn Barn popup window code
 */
 
   var ybPopup = null;
   var strScriptBegin = "<scr" + "ipt language='JavaScript'>";
   var strScriptEnd = "</scr" + "ipt>";
	
   function popupImage(imgURL, height, width)
   {
      var wHeight = Math.max(height, 200) + 100;
      var wWidth  = Math.max(width, 200) + 50;
      var windowFormat = "resizable=yes,scrollbars=yes,height=" + wHeight.toString() + ",width=" + wWidth.toString();
      
      if (ybPopup == null || ybPopup.closed)
         ybPopup = window.open(null, "yarnBarnPopup", windowFormat);
      else
         ybPopup.resizeTo(wWidth, wHeight);

      if (!ybPopup)
      {
         alert("Unable to open popup window. Please make sure you do not have a 'popup blocker' installed that is preventing the window from opening.");
         return;
      }

      with (ybPopup.document)
      {
         clear();
         writeln("<html>");
         writeln("<head>");
            writeln("<title>Kirtland's Yarn Barn</title>");
            writeln(strScriptBegin);
               writeln("function bodyLoaded() { window.focus(); }");
            writeln(strScriptEnd);
         writeln("</head><body><center>");
         if (height > 0 && width > 0)
            writeln("<img src='" + imgURL + "' height='" + height.toString() + "' width='" + width.toString() + "'><br>");
         else
            writeln("<img src='" + imgURL + "'><br>");
			
         writeln("<a href='javascript:close();'>[Close Window]</a>");
         writeln("</center></body></html>");
         close();
      }
      ybPopup.focus();

    }
 	
    function popupColorCard(yarnPartNo)
    {
       var windowFormat = "resizable=yes,scrollbars=yes,height=500,width=570";
       var strURL = "http://www.yarnbarn.com/yarn/popupColorCard.asp?partNo=" 
	 		+ yarnPartNo;
       var rePartNo = /^..-...-(.+)/;
       rePartNo.exec(yarnPartNo);
       var popupName = RegExp.$1;
       var oPopup = window.open(strURL, popupName, windowFormat);
       if (oPopup)
       {
          oPopup.focus();
       }
       else
          alert("Unable to open color card window. Please make sure you do not have a 'popup blocker' installed that is preventing the window from opening.");
    }

    function popupURL(strURL)
    {
       var windowFormat = "resizable=yes,scrollbars=yes,height=500,width=570";

       if (ybPopup == null || ybPopup.closed)
          ybPopup = window.open(null, "yarnBarnPopup", windowFormat);
       else
          ybPopup.resizeTo(570, 500);

       if (ybPopup)
       {
          ybPopup.location = strURL;
          ybPopup.focus();
       }
       else
          alert("Unable to open popup window. Please make sure you do not have a 'popup blocker' installed that is preventing the window from opening.");
    }


    function closePopup()
    {
       if (ybPopup != null)
          ybPopup.close();
    }
