/*** Enquiry Form - Steve Deane
 ******************************
 *    Consumables: Find all cell in column 1 with text, add an Enquire link
 *    Enquire link has the contents of the cell in it to pass to
 *    enquire form  
 *    Equipment: Do the same as above for the h2 
 * ***/

$(document).ready(function(){
 
  //Stripe the table 
  $(".consume tr:even").addClass("alt"); //adds "alt" class to every even row
   $('.consume').columnHover({eachCell:true, hoverClass:'tdHover'}); 
  $(".equipment tr:even").addClass("alt2"); //adds "alt" class to every even row
  $(".contact tr:even").addClass("alt2"); //adds "alt" class to every even row
  
  /*** Enquiry Form ***/
  
  // Consumables
  $('table.productList tr td:first-child').each(function () {
    if ($(this).html()!="" && $(this).html()!=" ") {
      $(this).addClass("alt");
      //$(this).siblings().addClass("trDivide");
      var productName = $(this).html();
      var link = "http://www.copyfax.com.au/contact-us?q="+productName;
      var htmlStr = $(this).html() + "&nbsp;&nbsp;&nbsp;<a href='" + link + "' alt='" + productName + "' title='" + productName + "'>Enquire&nbsp;&raquo;</a>";
      $(this).html(htmlStr);
    }
  });
  
  // Equipment
  $('table.equipment tr td h2').each(function () {      
      var productName = $(this).html();
      var link = "http://www.copyfax.com.au/contact-us?q="+productName;
      var htmlStr = "&nbsp;&nbsp;&nbsp;<a href='" + link + "' alt='" + productName + "' title='" + productName + "'>Enquire&nbsp;&raquo;</a>";
      //$(this).html(htmlStr);
      $(this).append(htmlStr);
  });
   
  if(gup('q') != "") {
    $("[name=enquireAbout]").val(gup('q').replace("%20", " "));
  }
});

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}







/*** Enquiry Form - Rough Work ***/
  //$("table.productList tr td:first-child a").attr("href","javascript:void(0);");
  //$("table.productList tr td:last-child").html("Enquire About");
  //$("table.productList tr td:last-child").html($("table.productList tr td:first-child").html());
  //$("table.productList tr td:first-child").addClass("enquire");
  //$("table.productList tr td:first-child").click(function () {
        //this.innerHTML=$("table.productList tr td:last-child").prevAll().text;
        //alert($(this).prevAll().html());
        //this.innerHTML = "Added...";
        //var productName = $(this).html();
        //alert(productName);
        //window.location="http://copyfax.nutwork.com.au/contact-us?q="+productName;
    //}); 
    
  /*** Enquiry Form ***/       
  /*if ($("table.productList tr td:first-child").html()!="") {
        $("table.productList tr td:first-child").addClass("alt");
  } */

  /*$("table.productList tr td:last-child").addClass("enquire"); 
  $("table.productList tr td:last-child").click(function () {
        var productName = $(this).html();
        window.location="http://copyfax.nutwork.com.au/contact-us?q="+productName;
  }); */
