// REPLACE http://localhost/demmer/dev by http://www.demmer.sk

/* CORE FUNCTION 2.0 */
function resetButtons(_pressedButton) { // Navigation/Button method: status prel.OK
// rename to resetButtonImages
  var imageId = "";
  var imageSrc = "";
  var imageIdPrefix = "myImage";
  for (_buttonId = 1; _buttonId <= teacategories; _buttonId++) { // ugly
    if (_buttonId != _pressedButton) {
      imageId = imageIdPrefix+_buttonId;
      var image = dojo.byId(imageId);
      switch (_buttonId) {
        case  1 : imageSrc = "img/demmer/select-cierny-caj-klasicky-dim-2.jpg"; break;
        case  2 : imageSrc = "img/demmer/select-cierny-caj-zmesi-dim-2.jpg"; break;
        case  3 : imageSrc = "img/demmer/select-cierny-caj-A-Z-dim-2.jpg"; break;
        case  4 : imageSrc = "img/demmer/select-zeleny-caj-klasicky-dim-2.jpg"; break;
        case  5 : imageSrc = "img/demmer/select-zeleny-caj-A-Z-dim-2.jpg"; break;
        case  6 : imageSrc = "img/demmer/select-zmesi-korenia-dim-2.jpg"; break;
        case  7 : imageSrc = "img/demmer/select-biely-caj-dim-2.jpg"; break;
        case  8 : imageSrc = "img/demmer/select-ovocne-caje-dim-2.jpg"; break;
        case  9 : imageSrc = "img/demmer/select-rooibos-dim-2.jpg"; break;
        case 10 : imageSrc = "img/demmer/select-bylinkove-caje-dim-2.jpg";
      }
      image.src = imageSrc;
    }
  }
}

/* CORE FUNCTION 2.0 */
//<!-- MOVE TO A TAB IN MAIN MENU -->
function moveTo(page) { // Navigation
  var debug = false;
  if (debug) alert("invoked moveTo("+page+")");
  var tabs = dijit.byId("main-menu");
  var newPage = dijit.byId(page);
  tabs.selectChild(newPage);
  return true;
};

/* CORE FUNCTION 2.0 */
//<!-- SEARCH ENCYCLOPEDIA FUNCTION -->
function searchDb(string) {
  var debug = false;
  if (debug) alert("Invoking 'searchDb("+string+")'");
  var xhrArgs = {
    content: {
      "action" : "search",
      "data"   : string
    },
    url: "http://www.demmer.sk/searchDb.php",
    handleAs: "json",
    preventCache: true, // optional
    headers: {          // optional
      "Content-Type": "text/plain",
      "Content-Encoding": "ISO-8859-1",
      "X-Method-Override": "FANCY-GET"
    },
    load: function(data) {
      if (debug) alert("JSON result: "+data);
      makeSearchResultPane(data);
      return true;
    }, 
    error: function(errmsg,ioargs) {
      var message = "";
      switch (ioargs.xhr.status) {
        case 200: message = "Good request."; break;
        case 404: message = "The requested page was not found"; break;
        case 500: message = "The server reported an error."; break;
        case 407: message = "You need to authenticate with a proxy."; break;
        default:  message = "Unknown error.";
      }
      alert("Status: " + message + " -- " + errmsg);
      return false;
    },
  }
  var deferred = dojo.xhrGet(xhrArgs);
};

/* CORE FUNCTION 2.0 */
function makeSearchResultPane(data) { // requires a div in the body
  var debug = false;
  if (debug) alert("Invoking 'makeSearchResultPane("+data+")'");
  var pFloatingPane;

  var div = document.createElement("div");
//  div.innerHTML = "This is a float"; // create table here
  div.innerHTML = makeTable(data);
  document.body.appendChild(div);  

  pFloatingPane = new dojox.layout.FloatingPane({
      title: "Search Results",
      resizable: true,
      dockable: false,
//      style: "position:absolute;top:30;left:200;width:600px;height:250px;visibility:hidden;",
      style: "position:absolute;top:30;left:200;width:600px;height:250px;",
//      href: "floatingpanetxt.html",
      id: "pFloatingPane"
    },
    div
//    dojo.byId("pFloatingPane")
  );
  pFloatingPane.startup();
//  pFloatingPane.show(); Not needed here. Changed visibility in style
};

/* CORE FUNCTION 2.0 */
/* JSON FUNCTION     */
function showProductDetail(pNumber,target) { 
// JSON function
  var debug = false;
  if (debug) alert("calling 'showProductDetail("+pNumber+","+target+")'");

  // Close any open floating panes
  if (dijit.byId("pFloatingPane")) {
    pFloatingPane = dijit.byId("pFloatingPane");
    pFloatingPane.close();
    pausecomp(300); // delay here equal to fade-out!
  }

// Changes color of clicked anchor simulating "visited" link
  if (dojo.byId(pNumber)) {
    product_link = dojo.byId(pNumber);
    product_link.style["color"] = "#333";
//    if (debug) alert("found link "+product_link.style["color"]);
  }

  var xhrArgs = {
    content: {
      "pNumber"  : pNumber,
      "language" : 2
    },
    url: "http://www.demmer.sk/getProductData-1.0.php",
    handleAs: "json",
    preventCache: true, // optional
    headers: {          // optional
      "Content-Type": "text/plain",
      "Content-Encoding": "ISO-8859-1",
      "X-Method-Override": "FANCY-GET"
    },
    load: function(data) {
      createFloatingPane(data,target);
      return true;
    },
    error: function(errmsg,ioargs) {
      var message = "";
      switch (ioargs.xhr.status) {
        case 200: message = "Good request."; break;
        case 404: message = "The requested page was not found"; break;
        case 500: message = "The server reported an error."; break;
        case 407: message = "You need to authenticate with a proxy."; break;
        default:  message = "Unknown error.";
      }
      alert("Status: " + message + " :: " + errmsg);
      return false;
    },
  }
  var deferred = dojo.xhrGet(xhrArgs);
};

/* CORE FUNCTION 2.0 */
/* DOJO FUNCTION     */
function createFloatingPane(data,target) { // Requires a div in the body
  var debug = false;
  if (debug) alert("Invoking 'createFloatingPane("+data+","+target+")'");

  // calculate size string.length, products_images_size

  var div = document.createElement("div"); // Recreating floatingpane requires a new div
  var _target = dojo.byId(target); // Controls the positioning of the floatingpane
  _target.appendChild(div);
  var pFloatingPane;
  pFloatingPane = new dojox.layout.FloatingPane({
      title: "Inform&#225;cie o produkte", // Translate into SJ
      resizable: true,
      dockable: false,
      style: "position:absolute;top:50;left:500;width:560px;height:550px;visibility:hidden;",
// ---->  consider sending top, left coordinates to function
//      iconSrc: "img/logo_cervene.jpg", // DOES NOT WORK
      duration: "300",
//      href: "productDetail-2.0-b.html", // remove, set content later
      id: "pFloatingPane"
    },
    div
  );
  pFloatingPane.startup();
  var contents = makeProductDetail(data); // :: looks as if I have to make the page dynamically
  if (debug) alert(contents);
//  var testValue = dojo.byId("pd-header-main").innerHTML;
//  var testValue = dijit.byId("pd-header-main").innerHTML;
//  var testValue = pFloatingPane.getElementById("pd-header-main").innerHTML;
//  var testValue = document.getElementById("pd-header-main").innerHTML;
//  alert(testValue);
  pFloatingPane.set('content',contents);
  pFloatingPane.show();
};

function makeProductDetail(data) {
  var debug = false;
  if (debug) alert("calling 'makeProductDetail("+data+")'");
//  var country = decode(data['origin']);
//  var flag = getIconHref(data['origin']);

  var flagsImageDir = "img/flags/";
  var manufacturersDir = "img/"+data['manufacturers_keyword']+"/";
  var text = "";

  var imageMaxDim = 100;
// scale manufacturers image
  var maxImageDim = 120;

  var imgW = data['manufacturers_image_width'];
  var imgH = data['manufacturers_image_height'];
  var scale = 1.0;
  if ( imgW >= imgH ) {
    if ( imgW > maxImageDim )
      scale = maxImageDim / imgW;
  } else {
    if ( imgH > maxImageDim )
      scale = maxImageDim / imgH;
  }
  imgW = parseInt(imgW*scale);
  imgH = parseInt(imgH*scale);

//  var imgW = 120;
//  var imgH = 105;
  text += "<div id='productDetail'>"; // not needed
  text += "<div id='pd-header'>";
  text += "<div id='pd-header-left'><img src='" + manufacturersDir + data['manufacturers_image'] + "' width='" + imgW + "' height='" + imgH + "'></div>";
  text += "<div id='pd-header-main'>" + (data['products_parent_name']!=null?data['products_parent_name']:"") + "</div>";
  text += "</div>"; // pd-header

  text += "<div id='pd-title'>";

  if ( data['products_categories_id'] == 2 ) {
    text += "<div id='pd-title-left'>" + data['products_manufacturers_pid'] + "</div>";
  } else if ( data['countries_flag_url'] != null ) {
    text += "<div id='pd-title-left'><img src='" + flagsImageDir + data['countries_flag_url'] + "' border='0' height='24' width='36'></div>";
  } else {
    text += "<div id='pd-title-left'><img src='img/spacer_36x24.gif' height='24' width='36'></div>";
  }

  products_price = formatNumber(data['products_price'],2,' ',',','&euro; ','','-','');
  text += "<div id='pd-title-right'>" + products_price + "&nbsp;/ " + data['units_definitions_value'] + "</div>";
  text += "<div id='pd-title-middle'>" + data['products_name'] + "</div>";
  text += "</div>"; // pd-title

  text += "<div id='pd-body'>";
  if ( data['products_categories_id'] == 2 ) {
    if ( data['countries_flag_url'] != null ) {
      text += "<div id='pd-body-left'><img src='" + flagsImageDir + data['countries_flag_url'] + "' border='0' height='24' width='36'></div>";
    } else {
    text += "<div id='pd-body-left'><img src='img/spacer_36x24.gif' height='50' width='36'></div>";
    }
  } else text += "<div id='pd-body-left'><img src='img/spacer_36x24.gif' height='50' width='36'></div>";

  if ( data['products_images_url'] != null ) {
    // Format image size
    imageWidth = data['products_images_width'];
    imageHeight = data['products_images_height'];
    imageBorder = data['products_images_border'];
    if ( imageWidth > 100 || imageHeight > 100 ) {
      if ( imageWidth <= imageHeight ) {
        imageHeight = parseInt(imageHeight/imageWidth*imageMaxDim);
        imageWidth = imageMaxDim;
      } else {
        imageWidth = parseInt(imageWidth/imageHeight*imageMaxDim);
        imageHeight = imageMaxDim;
      }
    }
    if ( imageBorder > 0 ) imageBorder = '1px solid #666';
    text += "<div id='pd-body-right'><img id='pd-body-right-img' src='" + manufacturersDir + data['products_images_url'] + "' border='" + imageBorder + "' height='" + imageHeight + "px' width='" + imageWidth + "px'></div>";
  } else {
    text += "<div id='pd-body-right'><img id='pd-body-right-img' src='img/noimage_100x100.png' border='0' height='100' width='100'></div>";
  }
  text += "<div id='pd-body-middle'>" + data['products_description_long'] + "</div>";
  text += "</div>";

  text +="<div id='pd-footer'>";
  if (data['products_categories_id'] == 2 ) {
    text += "<table id='pd-footer-table' border='0'>";
    text += "<tr><td class='footerIcons'><img src='img/icons/spoon_55x55.jpg' border='0' height='55' width='55'></td><td class='footerIcons'><img src='img/icons/thermometer_55x55.jpg' border='0' height='55' width='55'></td><td class='footerIcons'><img src='img/icons/clock_55x55.jpg' border='0' height='55' width='55'></td><td rowspan='2' width='100%'></td>";
    // CONDITIONAL
    if (data['categories_id'] != "") {
      text += "<td class='footerIcons'><img src='img/demmer/Bio_50x55.gif' border='0' height='50' width='55'></td></tr>";
    } else { 
      text += "<td class='footerIcons'></td></tr>";
    }
    if (data['preparation_id']>0) {
      text += "<tr><td class='footerText'>"+data['preparation_dosage']+"&nbsp;/l</td>";
      text += "<td class='footerText'>"+data['preparation_temperature']+"&#176;C</td>";
      text += "<td class='footerText'>"+data['preparation_infusion_time']+" min</td>";
      // number of infusions
    }
    // CONDITIONAL
    if (data['categories_id'] != "") {
      text += "<td class='footerText'>AT&#45;N&#45;01&#45;BIO</td>";
    } else {
      text += "<td class='footerText'></td>";
    }

    text += "</tr></table>";
    text += "</div>";
  }
//  text += "<div id='pd-copyright'><hr noshade>&copy; Demmers Teahouse, Bratislava / Arcimboldo, 2007-2011</div>";
  text += "</div>"; // productDetail
  return text;
};

/* CORE FUNCTION 2.0 */
/* JSON FUNCTION     */
function showProductList(pCategory,target,offset) { 
  var debug = false;
  if (debug) alert("calling 'showProductList("+pCategory+","+target+","+offset+")'");

  // Close any open floating panes
  if (dijit.byId("pFloatingPane")) {
    pFloatingPane = dijit.byId("pFloatingPane");
    pFloatingPane.close();
//    alert(pFloatingPane.id); 
    pausecomp(300); // delay here equal to fade-out!
  }

  var xhrArgs = {
    content: {
      "pCategory" : pCategory,
      "language"  : 2,
      "offset"    : offset 
    },
    url: "http://www.demmer.sk/getProductData-1.0.php",
    handleAs: "json",
    preventCache: true, // optional
    headers: {          // optional
      "Content-Type": "text/plain",
      "Content-Encoding": "ISO-8859-1",
      "X-Method-Override": "FANCY-GET"
    },
    load: function(data) {
      var _target = dojo.byId(target);
      var contents = makeProductList(data,pCategory,target,offset);
      if (debug) alert(contents);
      _target.innerHTML = contents;
      return true;
    },
    error: function(errmsg,ioargs) {
      var message = "";
      switch (ioargs.xhr.status) {
        case 200: message = "Good request."; break;
        case 404: message = "The requested page was not found"; break;
        case 500: message = "The server reported an error."; break;
        case 407: message = "You need to authenticate with a proxy."; break;
        default:  message = "Unknown error.";
      }
      alert("Status: " + message + " :: " + errmsg);
      return false;
    },
  }
  var deferred = dojo.xhrGet(xhrArgs);
};

/* CORE FUNCTION 2.0 */
/* JSON FUNCTION     */
function makeScrollList(pCategory,target,anchor) { 
  var debug = false;
  if (debug) alert("calling 'makeScrollList("+pCategory+","+target+","+anchor+")'");

  // Close any open floating panes
  if (dijit.byId("pFloatingPane")) {
    pFloatingPane = dijit.byId("pFloatingPane");
    pFloatingPane.close();
//    alert(pFloatingPane.id); 
    pausecomp(300); // delay here equal to fade-out!
  }

  var xhrArgs = {
    content: {
      "pCategory" : pCategory,
      "language"  : 2
    },
    url: "http://www.demmer.sk/getProductData-1.0.php",
    handleAs: "json",
    preventCache: true, // optional
    headers: {          // optional
      "Content-Type": "text/plain",
      "Content-Encoding": "ISO-8859-1",
      "X-Method-Override": "FANCY-GET"
    },
    load: function(data) {
      var contents = makeScrollTable(data,anchor);
      if (debug) alert(contents);
      createScrollPane3(contents,target);
      return true;
    },
    error: function(errmsg,ioargs) {
      var message = "";
      switch (ioargs.xhr.status) {
        case 200: message = "Good request."; break;
        case 404: message = "The requested page was not found"; break;
        case 500: message = "The server reported an error."; break;
        case 407: message = "You need to authenticate with a proxy."; break;
        default:  message = "Unknown error.";
      }
      alert("Status: " + message + " :: " + errmsg);
      return false;
    },
  }
  var deferred = dojo.xhrGet(xhrArgs);
};

function makeScrollTable(data,anchor) {
  var debug = false;
  if (debug) alert("calling 'makeScrollTable("+data+")'");
  maxImageDim = 200;
  var text = "<table class='productTable' cellpadding='0' border='1'>";
  dojo.forEach(data, function(item) {
    imgDir = 'img/'+item['manufacturers_keyword']+'/';
    products_price = formatNumber(item['products_price'],2,' ',',','&euro; ','','-','');
    // Image formatting
    imgW = item['products_images_width'];
    imgH = item['products_images_height'];
    scale = 1.0;
    if ( imgW >= imgH ) {
      if ( imgW > maxImageDim )
         scale = maxImageDim / imgW;
    } else {
      if ( imgH > maxImageDim )
         scale = maxImageDim / imgH;
    }
    imgW = parseInt(imgW*scale);
    imgH = parseInt(imgH*scale);    
    text += "<tr><td><a onclick='showProductDetail(\""+item['products_id']+"\",\""+anchor+"\");' style='color:#000000;cursor:pointer;'><table border='0'><tr><td rowspan='3'><img name='myImg1' id='dolfin1' src='"+imgDir + item['products_images_url'] + "' width='" + imgW + "' height='" + imgH + "' border='" + item['products_images_border'] + "' alt='dolfin 1'><td colspan='2'><img src='img/spacer.gif' width='200' height='1'></td></tr><tr><td colspan='2'>" + item['products_name'] + "</td></tr><tr><td>" + item['units_definitions_value'] + "</td><td>" + products_price + "</td></tr></table></a></td></tr>";
  });
  text += "</table>";
  return text;
}

/*
function getIconHref(code) { // deprecated
  var iconHref;
  switch (code) { // uppercase from database
    case "IN" : iconHref = "img/flags/in_36x24.gif"; break;
    case "CN" : iconHref = "img/flags/cn_36x24.gif"; break;
    case "NP" : iconHref = "img/flags/np_36x24.gif"; break;
    case "SL" : iconHref = "img/flags/sl_36x24.gif"; break;
    case "JP" : iconHref = "img/flags/jp_36x24B.gif"; break;
    case "VT" : iconHref = "img/flags/vt_36x24.gif"; break;
    case "TW" : iconHref = "img/flags/tw_36x24.gif"; break;
    case "ID" : iconHref = "img/flags/id_36x24B.gif"; break;
    default   : iconHref = "img/spacer_36x24.gif"; // demmer
  }
  return iconHref;
};

function decode(code) { // deprecated
  var cleartext;
  switch (code) { // uppercase from database
    case "IN" : cleartext = "INDIA"; break;
    case "CN" : cleartext = "&#268;&#205;NA"; break;
    case "NP" : cleartext = "NEP&#193;L"; break;
    case "SL" : cleartext = "SR&#205; LANKA"; break;
    case "JP" : cleartext = "JAPONSKO"; break;
    case "VT" : cleartext = "VIETNAM"; break;
    case "TW" : cleartext = "TAJWAN"; break;
    case "ID" : cleartext = "INDON&#201;ZIA"; break;
    default   : cleartext = ""; // Neochutene/Ochutene
  }
  return cleartext;
};
*/

/* CORE FUNCTION 2.0 */
function makeProductList(data,pCategory,target,offset) { 
  var debug = false;
  if (debug) alert("calling 'makeProductList("+data+","+pCategory+","+target+","+offset+")'");

  var leftOffset = (offset>0?parseInt(offset)-1:-1);
  var rightOffset = parseInt(offset)+1;  
  var country;
  var text = "<table id='tea-table' cellpadding='0' cellspacing='0' border='0' align='center'>";
  dojo.forEach(data, function(item) {
    if ( country != item['countries_name'] ) { // first instance of a new subcategory
      country = item['countries_name'];
      // Create subcategory header
text += "<tr><td colspan='4'><img src='img/spacer.gif' height='8' width='1'></td></tr>";
      text += "<tr><td class='country' colspan='4'>"+country+"</td></tr>";
    }
    // Add product list item
    text += "<tr><td class='products_manufacturers_pid'>" + item['products_manufacturers_pid'] + "<img src='img/spacer.gif' height='2' width='10'></td><td class='products_name'>";
    text += "<a class='products_name' id='" + item['products_id'] + "' onclick='showProductDetail(\""+item['products_id']+"\",\"teaProductDetail\");'>";
    text += item['products_name'] + "</a><img src='img/spacer.gif' height='2' width='10'></td>";
    text += "<td class='spacer'><img src='img/spacer.gif' height='2' width='10'></td>";
    // Format price
    products_price = formatNumber(item['products_price'],2,' ',',','&euro; ','','-','');
    text += "<td class='products_price'>" + products_price + "&nbsp;/ " + item['units_definitions_value'] + "</td></tr>";
    // Spacer between list entries
//    text += "<tr><td colspan='4'><img src='img/spacer.gif' height='4' width='1'></td></tr>";
    if (item['more'] != null)
      more = item['more'];
    else more = false;
  });
  text += "<tr><td colspan='4'><center>";
  if (leftOffset>=0)
    text += "<a onclick='showProductList(\""+pCategory+"\",\""+target+"\",\""+leftOffset+"\");'><img src='img/icons/left1_30x30.png' height='30' width='30'></a>";
  else text += "<img src='img/spacer.gif' height='30' width='30'>";
  text += "<img src='img/spacer.gif' height='4' width='4'>";
  if (more)
    text += "<a onclick='showProductList(\""+pCategory+"\",\""+target+"\",\""+rightOffset+"\");'><img src='img/icons/right1_30x30.png' height='30' width='30'></a>";
  else text += "<img src='img/spacer.gif' height='30' width='30'>";
  return text+"</center></td></tr></table>";
};

/* CORE FUNCTION 2.0 */
function createScrollPane(productCategory,target) {
  var debug = false;
  if (debug) alert("Invoking 'createScrollPane("+productCategory+","+target+")'");
  var anchor = dojo.byId(target);
  var scrollPane = new dojox.layout.ScrollPane({
      orientation: "horizontal"
    // style:"width:200px; height:200px; border:1px solid #ededed; overflow: hidden;"
    },
    anchor
  );
  var contents = makeProductTable();
  scrollPane.set('content',contents);
};

function createScrollPane2(productCategory,target) { // Vertical scrollpane needs style parameter
  var debug = false;
  if (debug) alert("Invoking 'createScrollPane2("+productCategory+","+target+")'");
  var anchor = dojo.byId(target);
  var scrollPane = new dojox.layout.ScrollPane({
      orientation: "vertical",
      style: "width:500px; height:300px; border:1px solid #ededed; overflow: hidden;"
    },
    anchor
  );
  var contents = makeScrollList(productCategory,'_dummy');
  alert(contents);
  scrollPane.set('content',contents);
};

function createScrollPane3(contents,target) { // Vertical scrollpane needs style parameter
  var debug = false;
  if (debug) alert("Invoking 'createScrollPane3("+contents+","+target+")'");
  var anchor = dojo.byId(target);
  var scrollPane = new dojox.layout.ScrollPane({
      orientation: "vertical",
      style: "width:500px; height:300px; border:0px solid #ededed; overflow: hidden;"
    }, /* Probable bug in ScrollPane: these parameter values must be declared in the programmatic construction (JS) */
    anchor
  );
  scrollPane.set('content',contents);
};

function makeProductTable() {
  var html = "<table class='productTable' cellpadding='0px' border='0'><tr>";
  html += "<td><a onclick='showProductDetail(\"1101\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg1' id='dolfin1' src='img/dolfin/poiress.JPG' height='150' width='108' alt='dolfin 1'></a><p>hruska<BR>&euro; 2,95</p></td>";
  html += "<td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg2' id='dolfin2' src='img/dolfin/t_70_lait.jpg' height='150' width='108' alt='dolfin 2'></a><p>mliecna<BR>&euro; 2,95</p></td>";
  html += "<td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg3' id='dolfin3' src='img/dolfin/t_70_lait_amandes_grillees.jpg' height='150' width='108' alt='dolfin 3'></a><p>mliecna s restovanimi mandlami<BR>&euro; 2,95</p></td>";
  html += "<td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg4' id='dolfin4' src='img/dolfin/t_70_lait_cannelle_ceylan.jpg' height='150' width='108' alt='dolfin 4'></a><p>hruska<BR>&euro; 2,95</p></td>";
  html += "<td id='last'><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg5' id='dolfin5' src='img/dolfin/t_70_lait_hot_masala.jpg' height='150' width='108' alt='dolfin 5'></a><p>hruska<BR>&euro; 2,95</p></td>"; // NOTE id="last" for the last cell
  html += "</tr></table>";
  return html;
};

function makeProductTable2() {
  var html = "<table class='productTable' cellpadding='0px' border='0'>";
  html += "<tr><td><a onclick='showProductDetail(\"1101\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg1' id='dolfin1' src='img/dolfin/poiress.JPG' height='150' width='108' alt='dolfin 1'></a></td></tr>";
  html += "<tr><td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg2' id='dolfin2' src='img/dolfin/t_70_lait.jpg' height='150' width='108' alt='dolfin 2'></a></td></tr>";
  html += "<tr><td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg3' id='dolfin3' src='img/dolfin/t_70_lait_amandes_grillees.jpg' height='150' width='108' alt='dolfin 3'></a></td></tr>";
  html += "<tr><td><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg4' id='dolfin4' src='img/dolfin/t_70_lait_cannelle_ceylan.jpg' height='150' width='108' alt='dolfin 4'></a></td></tr>";
  html += "<tr><td id='last'><a onclick='showProductDetail(\"110\",\"chocoProductDetail\");' style='color:#000000;cursor:pointer;'><img src='img/spacer.gif' width='200px' height='1px'><img name='myImg5' id='dolfin5' src='img/dolfin/t_70_lait_hot_masala.jpg' height='150' width='108' alt='dolfin 5'></a></td></tr>"; // NOTE id="last" for the last cell
  html += "</table>";
  return html;
};

/* CORE FUNCTION 2.0 */
/* BUTTON CONTROL    */
function changeImg(buttonId,imgSrc) { // Button method: status OK
// change name to buttonImage
  var imageIdPrefix = "myImage";
  if (buttonId != activeButton) {
    var imageId = imageIdPrefix+buttonId;
    dojo.byId(imageId).src=imgSrc;
  }
};

/* BUTTON CONTROL    */
// initiate(productGroup) function by quering db
var teacategories = 10; // Modify
var activeButton = 0;
var controls2productCategories = new Array();
controls2productCategories[1] = 1;
controls2productCategories[2] = 8;
controls2productCategories[3] = 2;
controls2productCategories[4] = 4;
controls2productCategories[5] = 5;
controls2productCategories[6] = 7;
controls2productCategories[7] = 6;
controls2productCategories[8] = 3;
controls2productCategories[9] = 9;
controls2productCategories[10] = 10;

/* CORE FUNCTION 2.0 */
/* BUTTON CONTROL    */
function contentList(buttonId) { // rename
  var debug = false;
  var _target = "productlist"; // argument
//  var _productCategory = parseInt(type)+99;
  var _productCategory = controls2productCategories[buttonId];
  if (debug) alert(_productCategory);
  activeButton = buttonId;
  var cpane1 = dojo.byId("tea-list"); // not used
  var cpane2 = dojo.byId("tea-img");
  cpane2.innerHTML = ""; // hide image
  resetButtons(buttonId);
  showProductList(_productCategory,_target,0); // _limit _offset
};

// source: http://www.sean.co.uk/a/webdesign/javascriptdelay.shtm
function pausecomp(millis) {
  var date = new Date();
  var curDate = null;
  do { 
    curDate = new Date(); 
  } while(curDate-date < millis);
}; 

// source: http://javascript.about.com/library/blnumfmt.htm
// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
  var x = Math.round(num * Math.pow(10,dec));
  if (x >= 0) n1=n2='';
  var y = (''+Math.abs(x)).split('');
  var z = y.length - dec; 
  if (z<0) z--; 
  for(var i = z; i < 0; i++) y.unshift('0'); 
  if (z<0) z = 1; 
  y.splice(z, 0, pnt); 
  if(y[0] == pnt) y.unshift('0'); 
  while (z > 3) {z-=3; y.splice(z,0,thou);}
  var r = curr1+n1+y.join('')+n2+curr2;
  return r;
};

