function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>'); 
}
/*include the prototype ajax library*/
//IncludeJavaScript("http://cableorganizer.com/minicart/prototype.js");
//document.write("<link rel=\"stylesheet\" media=\"all\" type=\"text/css\" href=\"http://cableorganizer.com/minicart/minicartStyle.css\" />");

//document.write("hello");

/**** REPLACE THE VALUES IN THESE LINES ****/
var serialnum="0001141555";
var cartURL="http://cableorganizer.com/cgi-cableorganizer/sb/order.cgi?storeid=*2c1a6fd87fca711cfc46084ad07ff145fd0847be4c9b4183&function=show";
var textColor="black";
var backgroundColor="transparent";
var showCart="no";       // only "yes" or "no"
var cartColor="black";    // only "black" or "white"
var textAlign="left";     // only "left" "right" or "center"

/**** DON'T CHANGE ANYTHING BELOW HERE ****/

var linkColor=textColor;
var cookies=document.cookie;  //read in all cookies

var start = cookies.indexOf("ss_cart_" + serialnum + "="); 
var cartvalues = "";
var linecount = 0;
var start1;
var end1;
var tmp;

// *****************************************Link *********************************************************




if (start == -1)  //No cart cookie
{
  document.write("<a href=\""+cartURL+"\" class=\"mpt\"> ");
  document.write("0 Items <img src=\"http://images.cableorganizer.com/t07/check-out.png\" alt=\"Check Out!\" /></a> ");
  document.write("</div>\n");
}
else   //cart cookie is present
{
document.write("<div class=\"popup\" ><ul><li>");
document.write("<a href=\"");
document.write(cartURL + "\"");
document.write(">");
//document.write("<a href=\"http://cableorganizer.com/cgi-cableorganizer/sb/order.cgi?storeid=*2c1a6fd87fca711cfc46084ad07ff145fd0847be4c9b4183&function=show\">");
document.write("\n");
  start = cookies.indexOf("=", start) +1;  
  var end = cookies.indexOf(";", start);  

  if (end == -1)
  {
    end = cookies.length;
  }

  cartvalues = unescape(cookies.substring(start,end)); //read in just the cookie data

  start = 0;
  while ((start = cartvalues.indexOf("|", start)) != -1)
  {
    start++;
    end = cartvalues.indexOf("|", start);
    if (end != -1)
    {
      linecount++;

      if (linecount == 2) // Total Quantity of Items
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        document.write("<a  href=\"" + cartURL + "\" style=\"color:" + linkColor + "\">");
        document.write("<b>"+tmp.substring(colon+1,end - start));
        if ((tmp.substring(colon+1,end - start)) == 1 )
        {
          document.write(" Item");
        }
        else
        {
          document.write(" Items");
        }
        document.write(": ");
      }

      if (linecount == 3)  // Product Subtotal
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        document.write(tmp.substring(colon+1,end - start));
        document.write(" </b></a>");
      }

      start = end;
    }
    else
      break;
    }
  } // end while loop




var start = cookies.indexOf("ss_cart_" + serialnum ); 
//alert("start "+start);
var cartvalues = "";
var linecount = 0;
var start1;
var end1;
var tmp;

// *****************************************Shopping Cart *********************************************************
  //document.write("<table class=\"shopTable\"><tr><td>\n");
  //document.write("<dl id=\"web1\"> <dt>Your&nbsp;Shopping&nbsp;Cart\n");
 // document.write("</dt><dd><table class=\"shopTable\">\n");

if (start == -1)  //No cart cookie
{
  /*document.write("<table class=\"shopTable\" id=\"popupDiv\"><tr><td>\n");
  document.write("<dl id=\"web1\"> <dt>");
  document.write("</dt><dd><table class=\"shopTable\">\n");
  document.write("</table> \n");
  document.write("</p></dl></td></tr></table></a></li></ul></div> \n");*/

}
else   //cart cookie is present
{
  document.write("<a  href=\""+cartURL+" \"><img class=\"linkItems\" src=\"http://images.cableorganizer.com/t07/check-out.png\"></a>");
  //document.write("<img src=\"http://images.cableorganizer.com/cart/check-out.png\">");
  document.write("<table class=\"shopTable\" id=\"popupDiv\"><tr><td>\n");
  document.write("<dl id=\"web1\"> <dt>Your&nbsp;Shopping&nbsp;Cart \n");
  //document.write("<div class=\"close\" ><a href=\"#\" onClick=\"document.getElementById('popupDiv').style.visibility='hidden';\">close x</a></div>");
  document.write("</dt><dd><table class=\"shopTable\">\n");
  
//alert("present");
  start = cookies.indexOf("=", start) +1;  
  var end = cookies.indexOf(";", start);  

  if (end == -1)
  {
    end = cookies.length;
  }

  cartvalues = unescape(cookies.substring(start,end)); //read in just the cookie data

  start = 0;
  var count=0;
  while ((start = cartvalues.indexOf("|", start)) != -1)
  {
    start++;
    end = cartvalues.indexOf("|", start);
    if (end != -1)
    {
      linecount++;

      if (linecount == 3)  // Product Subtotal
      {
        start1 = start;
        end1 = end;
        document.write("<tr>");
        document.write("<td><b>Qty</b></td>");
        document.write("<td><b>Picture</b></td>");
        document.write("<td align=\"center\"><b>Product</b></td>");
        document.write("<td align=\"center\"><b>SKU</b></td>");
        document.write("<td align=\"center\"><b>Price</b></td></tr>\n");
        document.write("</tr>\n");
      }

      var quantity;
      var product;
      var price;
      var reelprice;
      if (linecount > 3)  // individual products
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        quantity=tmp.substring(0,colon);
        colon2 = tmp.indexOf(":", colon+1);
        product= tmp.substring(colon2+1,end - start);

        reelprice=tmp.substring(colon+1,colon2);
        price=reelprice;
        var ok=0;
        var length=price.length;
        
        //create the roght number for price to do a good request
        for(i=length-1;i>length-4;i--){
          if(price.charAt(i)=='0'){
            price=price.substring(0,price.length-1);
            ok+=1;
          }else if(i==length-1){
              break;          
          }
          if(ok==2){
            price=price.substring(0,price.length-1);
            break;
          }
        }
        price=price.substring(1);
        
        //create the good product to do a good request
        
        for(i=length-1;i>0;i--){
          if(product.charAt(i)==' '){
            product=product.substring(0,product.length-1);
          }else{
            break;
          }
        }
        
        document.write("<tr>");
        
    
       var http_request = false;
        var sku;
        var image;
        var response;
        var link;
        
         function makeRequest(url) {
           http_request = false;
            if (window.XMLHttpRequest) { // Mozilla, Safari,...
               http_request = new XMLHttpRequest();
               if (http_request.overrideMimeType) {
                  http_request.overrideMimeType('text/xml');
               }
            } else if (window.ActiveXObject) { // IE
               try {
                  http_request = new ActiveXObject("Msxml2.XMLHTTP");
               } catch (e) {
                  try {
                     http_request = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (e) {}
               }
            }
            if (!http_request) {
               alert('Cannot create XMLHTTP instance');
               return false;
            }
            http_request.onreadystatechange = alertContents;
            http_request.open('GET', url, false);
            http_request.send(null);
         }
      
         function alertContents() {
           if (http_request.readyState == 4) {
               if (http_request.status == 200) {
                 response=http_request.responseText;
                 //alert("response "+response);
                 var tabresponse=response.split("@#$");
                 sku=tabresponse[0];
                 image=tabresponse[1];
                 link=tabresponse[2];
                 
                 
               } else {
                  alert('There was a problem with the request.');
               }
            }
         }

        
        var address;
        address="http://cableorganizer.com/minicart/getProduct2.php?product="+product+"&price="+price+"&quantity="+quantity;
        //alert("address"+address);
        makeRequest(address);
        
   
        //Qty
        document.write("<td align=\"center\">");
        document.write(quantity);
        document.write("</td>");
        //Picture
        document.write("<td align=\"center\">");
        
        if(link!=undefined){
          document.write("<a href=\""+link+"\"><img height=\"40\" width=\"40\" src=\""+image+"\" ></a>");
        }
        document.write("</td>");
        //Product
        document.write("<td align=\"center\">");
        if(link!=undefined){
          document.write("<a href=\""+link+"\">"+product+"</a>")
        }else{
          document.write(product);
        }
        
        document.write("</td>");
        //SKU
        document.write("<td align=\"center\" >");
        if(sku!=undefined){
              document.write(sku);
        }
        document.write("</td>");
        //Price
        document.write("<td align=\"right\">");
        document.write(reelprice);
        document.write("</td></tr>\n");
      }

      start = end;
    }
    else
    {
      break;
    }
  } // end while loop

  //close minicart HTML
  document.write("<tr><td></td><td></td>");
  document.write("<td colspan=\"2\" class=\"subtotal\"><b>Subtotal</b></td>");
  document.write("<td align=\"right\">");
  tmp = cartvalues.substring(start1,end1);
  colon = tmp.indexOf(":", 0);
  document.write(tmp.substring(colon+1,end1 - start1));
  document.write("</td>");
  document.write("</tr>");
  
   document.write("</tr>");
  
  document.write("</table>\n");
 document.write("<br>");
  document.write("<div class=\"checkout\">")
   document.write("<hr class=\"line\">");
  document.write("<a href=\""+cartURL+"\"><img src=\"http://images.cableorganizer.com/t07/check-out.png\"></a>");
  document.write("</div>");
   document.write("<br>");
  document.write("</dd></dl></td></tr></table>  </a></li></ul>\n");
  

}

document.write("</div>\n");
