function joinList(addy) {
    var url
    if( addy ) {
        url='subscribe.php?email='+addy;
    } else { 
        url='subscribe.php';
    }
	window.open( url, "Info", "location=no,left=100px,top=100px,screenX=100px,screenY=100px,resizable=1,height=145px,width=400px" );
}

function popitup(url) {
	newwindow=window.open(url,'Preview','height=175,width=410,scrollbars=0,location=0');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popupInfo(file,lang,width,height) {
    if( !width ) { var width=400; }
    if( !height ) { var height=450; }
    theWindow = window.open('popup_help/'+file+'_'+lang+'.html','','width='+width+',height='+height+',scrollbars=yes');
    theWindow.moveTo(50,50);
}

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported, please contact us if you have problems ordering.");
   return null;
}

function checkQtyElement(id) {
  if( document.getElementById(id) ) {
    return document.getElementById(id).value;
  }  else { 
    return 1;
  }
}

function getPopupInfo(products_id) {
  var xmlHttpReq = false;
  xmlHttpReq = createXMLHttpRequest();
  xmlHttpReq.open('get', 'ajax_product_info.php?products_id='+products_id, true);
  xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttpReq.onreadystatechange = function() {
  if( xmlHttpReq.readyState != 4 ) { return; }
    var theText = xmlHttpReq.responseText;
    Tip(theText);
//    return tooltip(theText);
  };
  xmlHttpReq.send("");
}

function addCart(itemcode,action) {
  if( !action ) { action='add_product'; }
  var xmlHttpReq = false;
  var qty_id = 'qty'+itemcode;
  var qty = checkQtyElement(qty_id);
  xmlHttpReq = createXMLHttpRequest();
  xmlHttpReq.open('post', 'ajax_shoppingcart.php?action='+action+'&ajax', true);
  xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttpReq.onreadystatechange = function() {
    if( xmlHttpReq.readyState != 4 ) { return; }
      var cart_box = document.getElementById('shopping_cart');
      var theText = xmlHttpReq.responseText;
      cart_box.innerHTML = theText;
      if( !supress_cart&&(document.getElementById('shopping_cart').style.visibility=='hidden'||document.getElementById('shopping_cart').style.visibility=='') ) { 
        toggleCartVisibility();
      } else {
        Tip('Added!');
      }
    };
  xmlHttpReq.send("action="+action+"&products_id="+itemcode+"&qty="+qty);
}

function toggleCartVisibility() {
    var cart;
    if(document.getElementById) { 
      cart = document.getElementById("shopping_cart");
    } else if (window.keywords_form) { 
      cart = window.shopping_cart;
    }
    if(cart.style.visibility==''||cart.style.visibility=='hidden') {
      cart.style.visibility='visible';
    } else {
      cart.style.visibility='hidden';
    }
}

var cart_position = 'left';

function toggleCartLocation() {
  if( cart_position=='right' ) {
    cart_position='left';
    move_upper_left();
  } else {
    cart_position='right';
    move_upper_right();
  }
}
