function newWindow(newhtm)
{
   win1 = window.open(newhtm,'test',config='scrollbars=yes,height=400,width=450')
   win1.focus()
}

// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//This function replaces the blanks in the string with + signs
function stringFilter(input) {
s = input;
filteredValues = " ";     // Strip out blanks
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) != -1) {returnString += "+"} //replace blanks with + signs
else {returnString += c};
}
input = returnString;
return input;
}

//This function replaces the blanks in the string with _ signs
function stringFilter2(input) {
s = input;
filteredValues = " ";     // Strip out blanks
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) != -1) {returnString += "_"} //replace blanks with + signs
else {returnString += c};
}
input = returnString;
return input;
}

//This function checks to see if the shopping cart is empty before going to checkout
function checkOut() {
if (countnum == null || countnum == 0)
{alert("Your Shopping Cart is empty.  There is nothing to checkout!")}
   else { 
   document.cart.submit();
   }
} 

//This function removes a product from the shopping cart
function removeItem(x) {
if (x == countnum && x != 1) {
   var y = x - 1;
   var newname = "cname" + y;
   var redoit = getCookie(newname);
   setCookie("test",redoit);
}
var named = "cname" + x;
delCookie(named);
if (x == 1 && countnum > 2) {
   var xyz = getCookie("cname2");
   setCookie("cname1",xyz);
}
var newcount = countnum - 1;
setCookie("counter",newcount);
self.location.reload();
}

// formats a decimal to two digits
function fix(num) {
 string = "" + num;
 if (string.indexOf('.') == -1) {
  return string + '.00'; }
 seperation = string.length - string.indexOf('.');
 if (seperation > 3) {
  return string.substring(0,string.length-seperation+3); }
 else if (seperation == 2) {
  return string + '0';}
 return string;
}

//Empty shopping cart and delete all cookies
function emptyCart() {
 for (i=1; i<=countnum; i++) {
 var namer1 = "cname" + i;
 delCookie(namer1);
 };
 delCookie('counter');
 self.location.reload();
}

//Update shopping cart when quantity number is changed on an item
function upDate(number) {
  if (countnum == null || countnum == 0)
 {alert("Your Shopping Cart is empty.  There is nothing to update!");return false};
  if (number == 1) {
  var revcookie = getCookie("test");
  delCookie("test");
  revcookie = revcookie.split(",");
  revcookie[3] = document.cart.quant.value;
  revcookie = revcookie.join(",");
  setCookie("test",revcookie);
  if (document.cart.quant.value == 0) {removeItem(1)}; 
  self.location.reload();
  }
 else {
  var lastcookie = getCookie("test");
  delCookie("test");
  lastcookie = lastcookie.split(",");
  lastcookie[3] = document.cart.quant[number - 1].value;
  lastcookie = lastcookie.join(",");
  setCookie("test",lastcookie);
  for (i=1; i<=number; i++) { 
  var x = i - 1;
  var namer2 = "cname" + i;
  var revcookie = getCookie(namer2);
  delCookie(namer2);
  revcookie = revcookie.split(",");
  revcookie[3] = document.cart.quant[x].value;
  revcookie = revcookie.join(",");
  setCookie(namer2,revcookie);
  if (document.cart.quant[x].value == 0) {removeItem(i)}; 
  }
 self.location.reload();
 }
}