include('json2.js');
include('sha256.js');
include("http://www.google.com/recaptcha/api/js/recaptcha_ajax.js");
var aBooks, rint, sint;
google.load('search', '1', {'nocss':true});

var doI = null;


function unHref()
{
 var links = document.getElementsByTagName("a");

 for (var i in links)
 {
  var link = links[i];
  var nonhref = 1;
  if (link.className)
  {
   var hrefTest = link.className.split(' ');
   for (var x in hrefTest)
   {
    if (hrefTest[x] == 'href') nonhref = 0;
    if (hrefTest[x] == 'LOGIN') link.onclick = function () {logIn(); return false;};
   }
  
   if (nonhref) link.onclick = function() {page(this.className); return false;};
  }
 }
}




function bPreview(bCode)
{
 if (document.getElementById('pimage' + bCode))
 {
  document.getElementById('pimage' + bCode).parentNode.removeChild(document.getElementById('pimage' + bCode));
  return;
 }

 var book = document.getElementById('z' + bCode);
 
 var pimage = genEl('div',book,'className=pimage,id=pimage' + bCode);
 var ele = genEl('div',pimage,'className=rind');
 var ele1 = genEl('img',ele,'title=Click to close');
 ele1.src = 'zephscom.php?WHO=' + bCode + '&FETCH=wimage';
 ele.onclick = function ()
  {
   var book = document.getElementById(this.parentNode.id);
   book.parentNode.removeChild(book);
  };

}




function caChing(tot)
{
 var chinged = document.getElementById('zChinged');
 if (isNaN(tot) || tot > 9999999)
 {
  chinged.innerHTML = '<img src="images/ching-err.png" />';
  return;
 }
 else if (tot > 9999.99)
 {
  var ching = String(Math.round(tot)).split('');
 }
 else var ching = Number(tot).toFixed(2).split('');
 
 var allChing = '';
 var zind = 0;
 
 for (var n in ching)
 {
  var rev = (ching.length - 1) - n;
  if (ching[rev] == '.') ching[rev] = 'dot';
  allChing += '<img src="images/ching-' + ching[rev] + '.png" style="right: ' + zind + 'px" />';
  zind += 15;
 }
 chinged.innerHTML = allChing;
}




function checkOut()
{
 if (undefined == window.logger || !logger.authenticated)
 {
  logIn();
  return;
 }
 
 var ppForm = genEl('form',document.body,'style.display=none');
  ppForm.action = 'https://www.paypal.com/cgi-bin/webscr';
  ppForm.method = 'post';
  
  genEl('input',ppForm,'type=hidden,value=_cart','cmd');
  genEl('input',ppForm,'type=hidden,value=1','upload');
  genEl('input',ppForm,'type=hidden,value=orders@zephs.com.au','business');
  genEl('input',ppForm,'type=hidden,value=AUD','currency_code');
  genEl('input',ppForm,'type=hidden,value=utf-8','charset');
  genEl('input',ppForm,'type=hidden,value=AU','country');
  if (logger.details.state == 'Western Australia') genEl('input', ppForm, 'type=hidden,value=5.00', 'handling_cart');
  else genEl('input', ppForm, 'type=hidden,value=10.00', 'handling_cart');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.userName,'custom');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.email,'email');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.address1,'address1');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.address2,'address2');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.suburb,'city');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.firstName,'first_name');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.lastName,'last_name');
  if (logger.details.phone.length > 7) genEl('input',ppForm,'type=hidden,value=' + logger.details.phone,'night_phone_b');
  else genEl('input',ppForm,'type=hidden,value=' + logger.details.mobile,'night_phone_b');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.state,'state');
  genEl('input',ppForm,'type=hidden,value=' + logger.details.postcode,'zip');
  if (! (undefined == window.cart.rewards)) genEl('input',ppForm,'type=hidden,value=' + (cart.rewards.value / 100),'discount_amount_cart');
  
 
 var counter = 1;
 
 for (var i in cart.items)
 {
  var cItem = cart.items[i];
  
  genEl('input',ppForm,'type=hidden,value=' + cItem.ID,'item_number_' + counter);
  genEl('input',ppForm,'type=hidden,value=' + cItem.CODE,'item_name_' + counter);
  genEl('input',ppForm,'type=hidden,value=' + cItem.PRICE,'amount_' + counter);
  genEl('input',ppForm,'type=hidden,value=' + cItem.quantity.value,'quantity_' + counter);
  
  counter++;
 }
 
 ppForm.submit();
}




function checkPass()
{
 var pass = document.getElementById('password').value;
 var conf = document.getElementById('confirmPassword').value;
 var stat = document.getElementById('passStatus');
  stat.style.color = '#ff0000';
 var goods = /([A-z]+[0-9]+|[0-9]+[A-z]+)/;
 var bads = /[^\w!@#%^&*()\-_+={}\[\]|:<>,\.\?]/;
 if (pass.length < 8) stat.innerHTML = 'Password must be at least 8 characters.';
 else if (!goods.test(pass)) stat.innerHTML = 'Password must contain at least 1 letter and 1 number.';
 else if (bads.test(pass)) stat.innerHTML = 'Password may contain only letter, numbers and !@#%^&*()-_+={}[]|:<>,.? characters.';
 else if (pass != conf) stat.innerHTML = 'Confirmation password does not match.';
 else
 {
  stat.style.color = '#00ff00';
  stat.innerHTML = 'Password O.K.';
  return true;
 }
 return false;
}




function checkUserName()
{
 var uName = document.getElementById('username').value;
 var uStat = document.getElementById('usernameStatus');
  uStat.style.color = '#525a60';
  uStat.innerHTML = 'checking...';
 var checker = Job('checkUserName',uName);
 
 if (checker.available)
 {
  uStat.style.color = '#00ff00';
  uStat.innerHTML = checker.response;
  return true;
 }
 else
 {
  uStat.style.color = '#ff0000';
  uStat.innerHTML = checker.response;
  document.getElementById('username').focus()
  return false;
 }
}




function editAccount ()
{
 if (document.getElementById('editAccountForm'))
 {
  Job('updateAccountDetails',null,formProc('editAccountForm'));
  logIn();
 }
 else
 {
  var stage = document.getElementById('stage');
  stage.innerHTML = '';
  
  var eafDiv = genEl('div',stage,'style.width=500px,style.margin=25px auto');

   var eaForm = makeDetailsForm();
    eaForm.id = 'editAccountForm';
    
   eafDiv.appendChild(eaForm); 
  
  for (var i = 0; i < eaForm.length; i++)
  {
   var fElem = eaForm.elements[i];
   var eId = fElem.id;
   if (logger.details[eId])
   {
    if (fElem.type == 'checkbox')
    {
     if (logger.details[eId] == true) fElem.checked = true;
    }
    else fElem.value = logger.details[eId];
   }
  }
    
   
   var btn = genEl('button',eafDiv,'style.display=block,style.margin=25px auto');
    btn.onclick = function ()
    {
     if(document.getElementById('firstName').value.length > 1 && document.getElementById('lastName').value.length > 1 && document.getElementById('state').value !== 'blank') editAccount();
    };
    btn.appendChild(document.createTextNode('SAVE'));
 }
}




function editEmail ()
{

}




function editPassword ()
{

}




function eMe (e)
{
 if (!e) e = window.event;
 if (e.target) e = e.target;
 else if (e.srcElement) e = e.srcElement;
 return(e);
}



function exco (fetch,who)
{
 var targ = document.getElementById(who.replace(/\+/,"G").replace(/\s/g,"_"));
 if (targ.innerHTML > '')
 {
  targ.innerHTML = '';
  targ.parentNode.style.backgroundColor = '#f4f4f4';
 }
 else
 {
  targ.innerHTML = '<img src="images/loading.gif" />';
  sherpa(fetch,who);
  targ.parentNode.style.backgroundColor = '#d0d0d0';
 }
}




function Job (fetch,who,extra,target)
{
 var data;
 var url = "zephscom.php";
 
 if (target) document.getElementById(target).innerHTML = '<img src="images/loading.gif" style="padding: 25px; margin: auto" />';
 
 data = "FETCH=" + fetch + "&" + "WHO=" + encodeURIComponent(who);
 if (extra) data += "&" + extra;

 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return false;
 }
 xmlHttp.onreadystatechange=function()
 {
  try
  {
 
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
    //JOB = JSON.parse(xmlHttp.responseText);
   }
   
  } 
  catch(err)
  {
   alert(err + "\n\n\n" + xmlHttp.responseText);
  }
  
 }
 xmlHttp.open("POST",url,false);
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlHttp.setRequestHeader("Content-length", data.length);
 xmlHttp.setRequestHeader("Connection", "close");
 xmlHttp.send(data);
 
 if (xmlHttp.responseText)
 {
  if (target) document.getElementById(target).innerHTML = xmlHttp.responseText;
  else return JSON.parse(xmlHttp.responseText);
 }
}




function loading (targ)
{
 document.getElementById(targ).innerHTML = '<img src="images/loading.gif" style="display: block; height: 55px; width: 31px; padding: 25px; margin: auto" />';
}




function logIn ()
{
 var who = null;
 var extra = null;
 
 if (document.getElementById('loginForm'))
 {
  var lForm = document.getElementById('loginForm');
  who = lForm.elements['email'].value;
  var shaF = new jsSHA(lForm.elements['password'].value, 'ASCII');
  var shaP = new jsSHA(shaF.getHash('SHA-256','HEX') + lForm.elements['tStamp'].value, 'ASCII');
  extra =  "P=" + shaP.getHash('SHA-256', 'HEX');
 }
 
 loading('stage');
 logger = Job('LOGIN',who,extra);
 
 var stage = document.getElementById('stage');
  stage.innerHTML ='';
 
 var lB = document.getElementById('loginButton');
 var lL = document.getElementById('loginLink');

 if (logger.authenticated)
 {
  myJournal();
 }
 else
 {
  
  if (logger.response)
  {
   var resp = genEl('h3',stage,'className=error');
    resp.appendChild(document.createTextNode(logger.response));
  }
  
  var suH = genEl('h4',stage,'style.textAlign=center,margin=25px');
   var sU = genEl('button',suH,'style.border=none');
    sU.onclick = function () {signUp();};
    sU.appendChild(document.createTextNode("New customers click here to create your journal."));
     
  var lfDiv = genEl('div',stage,'style.marginLeft=auto,style.marginRight=auto,style.width=500px');
  
   var suI = genEl('h5',lfDiv);
    suI.appendChild(document.createTextNode('You need to sign in to access your journal or purchase plants.'));
  
   if (logger.tStamp)
   {
    
    var lForm = genEl('form',lfDiv,'id=loginForm');
     
     var eLab = genEl('label',lForm,'htmlFor=email');
      eLab.appendChild(document.createTextNode('Email'));
     genEl('br',lForm);
     var eM = genEl('input',lForm,'type=text,size=40,maxLength=150,id=email','email');
     genEl('br',lForm);
     var pLab = genEl('label',lForm,'htmlFor=password');
      pLab.appendChild(document.createTextNode('Password'));
     genEl('br',lForm);
     var pW = genEl('input',lForm,'type=password,size=40,maxLength=64,id=password','password');
     var tS = genEl('input',lForm,'type=hidden','tStamp');
      tS.value = logger.tStamp;
      
     var btn = genEl('button',lfDiv,'style.display=block,style.margin=25px auto 25px auto');
      btn.onclick = function () {logIn();};
      btn.appendChild(document.createTextNode('LOG IN'));
    }
  
 }
 
}




function logOut ()
{
 var unlog = Job('LOGOUT');
 var stage = document.getElementById('stage');
  stage.innerHTML = '';
 if (unlog.response.loggedOut)
 {
  if (document.getElementById('zPanel'))
  {
   document.getElementById('zPanel').parentNode.removeChild(document.getElementById('zPanel'));
  }
  
  if (!(undefined == window.cart)) delete cart;
  delete logger;
  
  var ele = genEl('h3',stage,'style.textAlign=center');
   ele.appendChild(document.createTextNode('You have logged out.'));
 }
 else
 {
  var ele = genEl('h3',stage,'style.textAlign=center');
   ele.appendChild(document.createTextNode('For some strange reason we could not log you out, shit happens.'));
 }
}




function makeCart ()
{
 this.items = new Array();
 this.total = function ()
  {
   var cartTotal = 0;
   for (var x in this.items)
   {
    cartTotal += this.items[x].PRICE * this.items[x].quantity.value;
   }
   return cartTotal;
  }
  
  var ele1 = genEl('div',document.body,'id=zPanel');
  ele1.onmouseover = function () {unRoll('zMate','v',360);};
  ele1.onmouseout = function () {reRoll('zMate',null,'v',360);};
  
   var ele2 = genEl('div',ele1,'id=zReg,alt=Cart register,title=min/max Register');
   ele2.onclick = function () {toggleCaChing();};
   
    var ele3 = genEl('div',ele2,'id=zChinged');
    var ele3 = genEl('img',ele2,'src=images/cashreg.png,style.position=absolute,style.top=0px,style.left=0px');
    
   var ele2 = genEl('div',ele1,'id=zMate');
   
    var ele3 = genEl('div',ele2,'id=zMateRind');
    
     var ele4 = genEl('div',ele3,'id=zPad');
     
      var iTab = genEl('table',ele4,'width=100%,cellSpacing=0px');
       genEl('col',iTab);
       genEl('col',iTab,'width=50px');
       genEl('col',iTab,'width=60px');
       genEl('col',iTab,'width=30px');
       genEl('col',iTab,'width=15px');
       var iBod = genEl('tbody',iTab,'id=cartItems');
        var hRow = genEl('tr',iBod);
         var tH1 = genEl('th',hRow);
          tH1.appendChild(document.createTextNode('PLANT'));
         var tH2 = genEl('th',hRow);
          tH2.appendChild(document.createTextNode('QUANTITY'));
         var tH3 = genEl('th',hRow);
          tH3.appendChild(document.createTextNode('SUBTOTAL'));
         var tH4 = genEl('th',hRow);
          tH4.appendChild(document.createTextNode('POINTS'));
         var tH5 = genEl('th',hRow);
      
      if (!(undefined == window.logger) && !(undefined == window.logger.details) && Number(logger.details.rewards) > 0)
      {   
       var ele5 = genEl('div',ele4,'style.textAlign=right,style.margin=20px 25px,style.fontSize=12px');
        var ele6 = genEl('label',ele5,'htmlFor=redeem');
         ele6.appendChild(document.createTextNode('You have ' + logger.details.rewards + ' gardeners points in your account, how many would you like to redeem? '));
        genEl('br',ele5);
        this.rewards = genEl('input',ele5,'type=text,size=5,maxLength=5,style.textAlign=right,value=0,id=redeem');
        this.rewards.onchange = function ()
        {
         if (Number(cart.rewards.value) > Number(logger.details.rewards)) cart.rewards.value = logger.details.rewards;
        };
      }
         
      var clearBut = genEl('button',ele4,'style.margin=25px 10px 10px 50px');
       clearBut.onclick = function ()
       {
        Job('clearCart');
        delete cart;
        document.getElementById('zPanel').parentNode.removeChild(document.getElementById('zPanel'));
       };
       clearBut.appendChild(document.createTextNode('CLEAR'));
       
      var checkBut = genEl('button',ele4,'style.margin=25px 10px 10px 220px');
       checkBut.onclick = function () {checkOut();};
       checkBut.appendChild(document.createTextNode('CHECKOUT'));
  
}




function makeCartItem (plant)
{
 if (undefined == window.cart) cart = new makeCart();
 
 var pQuant = 0;
 if (plant.QUANT)
 {
  pQuant = plant.QUANT;
 }
 else if (plant.quantity)
 {
  if (! plant.quantity.value > 0)
  {
   plant.quantity.value = 1;
   plant.makePrice();
   return;
  }
  else pQuant = plant.quantity.value;
 }
 
 if (cart.items[plant.ID])
 {
  cart.items[plant.ID].quantity.value = pQuant;
  caChing(cart.total());
  if (plant.quantity)
  {
   plant.quantity.value = 1;
   plant.makePrice();
  }
  saveCartItem(cart.items[plant.ID]);
  return;
 }
 
 cart.items[plant.ID] = new function ()
 {
  this.CODE = plant.CODE;
  this.ID = plant.ID;
  this.PRICE = plant.PRICE;
  this.REWARD = plant.REWARD;
  
  this.subtotal = document.createTextNode((pQuant * plant.PRICE).toFixed(2));
  this.points = document.createTextNode(pQuant * plant.REWARD);
  
  this.quantity = genEl('input',null,'type=text,maxLength=4');
  this.quantity.value = pQuant;
  this.quantity.onkeyup = function ()
   {
    var cItem = cart.items[plant.ID];
    
    var quant = Math.floor(this.value.replace(/[^0-9]/g, ''));
    cItem.subtotal.nodeValue = (quant * cItem.PRICE).toFixed(2);
    cItem.points.nodeValue = quant * cItem.REWARD;
    this.value = quant;
    caChing(cart.total());
   };
  this.quantity.onchange = function ()
   {
    saveCartItem(cart.items[plant.ID]);
   };
  
  this.remove = function ()
   {
    cart.items[plant.ID].Row.parentNode.removeChild(cart.items[plant.ID].Row);
    cart.items[plant.ID].quantity.value = 0;
    caChing(cart.total());
    saveCartItem(cart.items[plant.ID]);
    delete cart.items[plant.ID];
   };
  
  
  
   this.Row = genEl('tr');
   var pTd = genEl('td',this.Row);
    pTd.innerHTML = plant.GENUS + ' ' + plant.SPECIES + ' ' + plant.ID;
   var qTd = genEl('td',this.Row,'className=quant');
    qTd.appendChild(this.quantity);
   var sTd = genEl('td',this.Row,'className=subt');
    sTd.appendChild(document.createTextNode('$'));
    sTd.appendChild(this.subtotal);
   var rTd = genEl('td',this.Row,'className=points');
   rTd.appendChild(this.points);
   var dTd = genEl('td',this.Row,'className=del');
    dTd.appendChild(document.createTextNode('X'));
    dTd.onclick = this.remove;

  var cItems = document.getElementById('cartItems');
   cItems.insertBefore(this.Row,cItems.firstChild.nextSibling);
 };
 
 caChing(cart.total());
 
 if (plant.quantity)
 {
  plant.quantity.value = 1;
  plant.makePrice();
 }
 
 saveCartItem(cart.items[plant.ID]);
}




function makeDetailsForm()
{
 var dForm = genEl('form');
 
  var firstNameLab = genEl('label',dForm,'htmlFor=firstName');
   firstNameLab.appendChild(document.createTextNode('First name '));
   var firstNameLab2 = genEl('span',firstNameLab,'style.fontSize=10px');
    firstNameLab2.appendChild(document.createTextNode('(required)'));
  genEl('br',dForm);
  var firstName = genEl('input', dForm, 'type=text,size=25,maxLength=40,id=firstName', 'FIRST_NAME');
  genEl('br',dForm);
  
  var lastNameLab = genEl('label',dForm,'htmlFor=lastName');
   lastNameLab.appendChild(document.createTextNode('Last name '));
   var lastNameLab2 = genEl('span',lastNameLab,'style.fontSize=10px');
    lastNameLab2.appendChild(document.createTextNode('(required)'));
  genEl('br',dForm);
  var lastName = genEl('input', dForm, 'type=text,size=25,maxLength=40,id=lastName', 'SURNAME');
  genEl('br',dForm);
  
  var address1Lab = genEl('label',dForm,'htmlFor=address1');
   address1Lab.appendChild(document.createTextNode('Address line 1 '));
  genEl('br',dForm);
  var address1 = genEl('input', dForm, 'type=text,size=40,maxLength=60,id=address1', 'ADDRESS_1');
  genEl('br',dForm);
  
  var address2Lab = genEl('label',dForm,'htmlFor=address2');
   address2Lab.appendChild(document.createTextNode('Address line 2 '));
  genEl('br',dForm);
  var address2 = genEl('input', dForm, 'type=text,size=40,maxLength=60,id=address2', 'ADDRESS_2');
  genEl('br',dForm);
  
  var suburbLab = genEl('label',dForm,'htmlFor=suburb');
    suburbLab.appendChild(document.createTextNode('City / Town '));
  genEl('br',dForm);
  var suburb = genEl('input', dForm, 'type=text,size=25,maxLength=40,id=suburb', 'SUBURB');
  genEl('br',dForm);
  
  var stateLab = genEl('label',dForm,'htmlFor=state');
    stateLab.appendChild(document.createTextNode('State '));
   var stateLab2 = genEl('span',stateLab,'style.fontSize=10px');
    stateLab2.appendChild(document.createTextNode('(required)'));
  genEl('br',dForm);
  var state = genEl('select', dForm, 'style.width=280px,id=state', 'STATE');
   state.add(genEl('option',null,'text=Please choose.,value=blank'),null);
   state.add(genEl('option',null,'text=Australian Capital Territory,value=Ausralian Capital Territory'),null);
   state.add(genEl('option',null,'text=New South Wales,value=New South Wales'),null);
   state.add(genEl('option',null,'text=Northern Territory,value=Northern Territory'),null);
   state.add(genEl('option',null,'text=Queensland,value=Queensland'),null);
   state.add(genEl('option',null,'text=South Australia,value=South Australia'),null);
   state.add(genEl('option',null,'text=Tasmania,value=Tasmania'),null);
   state.add(genEl('option',null,'text=Victoria,value=Victoria'),null);
   state.add(genEl('option',null,'text=Western Australia,value=Western Australia'),null);
  genEl('br',dForm);
  
  var postCodeLab = genEl('label',dForm,'htmlFor=postcode');
    postCodeLab.appendChild(document.createTextNode('Postcode '));
  genEl('br',dForm);
  var postCode = genEl('input', dForm, 'type=text,size=4,maxLength=4,id=postcode', 'POSTCODE');
  genEl('br',dForm);
  
  var phoneLab = genEl('label',dForm,'htmlFor=phone');
    phoneLab.appendChild(document.createTextNode('Phone'));
  genEl('br',dForm);
  var phone = genEl('input', dForm, 'type=text,size=10,maxLength=20,id=phone', 'PHONE');
  genEl('br',dForm);
  
  var mobileLab = genEl('label',dForm,'htmlFor=mobile');
    mobileLab.appendChild(document.createTextNode('Mobile'));
  genEl('br',dForm);
  var mobile = genEl('input', dForm, 'type=text,size=15,maxLength=20,id=mobile', 'MOBILE');
  genEl('br',dForm);
  
  var mailing = genEl('input', dForm, 'type=checkbox,id=mailingList', 'MAILING_LIST');
  var mailingLab = genEl('label',dForm,'htmlFor=mailingList');
   var mailingLab2 = genEl('span',mailingLab,'style.fontSize=10px');
    mailingLab2.appendChild(document.createTextNode('I wish to receive emails regarding new plant releases and other exciting news'));
  genEl('br',dForm);
  
 return dForm;
}




function makeNurseryListItem(plant)
{
 plant.Nli = genEl('li');
 
 plant.Nli.innerHTML = plant.SPECIES;
 
 var ele = genEl('span',plant.Nli,'className=id');
 ele.appendChild(document.createTextNode(plant.ID));
 
 var ele = genEl('span',plant.Nli,'className=scomn');
 ele.appendChild(document.createTextNode(plant.SCOMN));
 
 var ele = genEl('div',plant.Nli,'className=nSpec');
 var ele1 = genEl('table',ele);
 var ele2 = genEl('tbody',ele1);
 var ele3 = genEl('tr',ele2);
 var ele4 = genEl('td',ele3,'className=nStat');
 
 if (plant.LIGHT)
 {
 
  var ele5 = genEl('table',ele4);
  var ele6 = genEl('tbody',ele5);
  
  var ele7 = genEl('tr',ele6);
  var ele8 = genEl('td',ele7);
  var ele9 = genEl('img',ele8,'src=images/height.gif,title=Height,alt=Height');
  ele8.appendChild(document.createTextNode(plant.HEIGHT));
  
  var ele7 = genEl('tr',ele6);
  var ele8 = genEl('td',ele7);
  var ele9 = genEl('img',ele8,'src=images/width.gif,title=Width,alt=Width');
  ele8.appendChild(document.createTextNode(plant.WIDTH));
  
  var ele7 = genEl('tr',ele6);
  var ele8 = genEl('td',ele7);
  var ele9 = genEl('img',ele8,'src=images/season.gif,title=Flowering season,alt=Flowering season');
  ele8.appendChild(document.createTextNode(plant.SEASON));
  
  var ele7 = genEl('tr',ele6);
  var ele8 = genEl('td',ele7);
  var ele9 = genEl('img',ele8,'src=images/water.gif,title=Water requirement,alt=Water requirement');
  ele8.appendChild(document.createTextNode(plant.WATER));
 
  var ele7 = genEl('tr',ele6);
  var ele8 = genEl('td',ele7);
  var ele9 = genEl('img',ele8,'src=images/light.gif,title=Light requirement,alt=Light requirement');
  ele8.appendChild(document.createTextNode(plant.LIGHT));
 
 }
 
 var ele4 = genEl('td',ele3,'className=nDesc');
 
 if (plant.IMGH > 0)
 {
  var ele5 = genEl('img',ele4,'title=' + plant.GENUStext + ' ' + plant.SPECIEStext + ' ' + plant.ID + ' - Click to enlarge,alt=' + plant.GENUStext + ' ' + plant.SPECIEStext + ' ' + plant.ID);
  
  ele5.src = 'zephscom.php?WHO=' + plant.ID + '&FETCH=thumb';
  ele5.onclick = function () {popImage(plant);};
 }
 
 var ele5 = genEl('span',ele4,'className=price');
 if (plant.PRICE)
 {
  plant.quantity = genEl('input',ele5,'type=text,maxLength=3,value=1');
  plant.quantity.onkeyup = function (){plant.makePrice();};
  ele5.appendChild(document.createTextNode('for '));
  var ele6 = genEl('span',ele5,'className=subtotal')
  plant.subtotal = document.createTextNode('$' + plant.PRICE);
  ele6.appendChild(plant.subtotal);
  var ele6 = genEl('span',ele5,'className=points');
  plant.points = document.createTextNode('earn ' + plant.REWARD + ' points');
  ele6.appendChild(plant.points);
  var ele6 = genEl('button',ele5);
  ele6.appendChild(document.createTextNode('ADD TO CART'));
  ele6.onclick = function () {makeCartItem(plant);};
  
  plant.makePrice = function ()
   {
    var quant = Math.floor(plant.quantity.value.replace(/[^0-9]/g, ''));
    plant.subtotal.nodeValue = '$' + (quant * plant.PRICE).toFixed(2);
    plant.points.nodeValue = 'earn ' + (quant * plant.REWARD) + ' points';
    plant.quantity.value = quant;
   };
  
  if (plant.NOMAIL)
  {
   var ele6 = genEl('div',ele4,'className=nomail');
   ele6.appendChild(document.createTextNode(plant.NOMAIL));
  }
 }
 else ele5.appendChild(document.createTextNode('Only available at the nursery'));
 
 
 var ele5 = genEl('p',ele4);
 ele5.innerHTML = plant.WEBDESC;
 
 
 return plant.Nli;
}




function makePlant(idee)
{
 loading('speciesBox');
 
 plant = Job('plant',idee);
 
 var sBox = document.getElementById('speciesBox');
  sBox.innerHTML = '';
  
 var iBox = genEl('div',sBox,'className=innerBox');
  
 var titleG = genEl('h2',iBox,'className=titleG');
  titleG.innerHTML = plant.GENUS;
 var titleS = genEl('h3',iBox,'className=titleS');
  titleS.innerHTML = plant.SPECIES;
 var pId = genEl('span',titleS,'className=id');
  pId.appendChild(document.createTextNode(plant.ID));
 var titleC = genEl('h3',iBox,'className=titleC');
  titleC.appendChild(document.createTextNode(plant.SCOMN));
 if (plant.IMGH > 0)
 {
  var portrait = genEl('img',iBox,'className=portrait');
   portrait.height = plant.IMGH;
   portrait.width = plant.IMGW;
   var pDesc = plant.GENUStext + ' ' + plant.SPECIEStext + ' ' + plant.ID;
   portrait.alt = pDesc;
   portrait.title = pDesc;
   portrait.src = 'zephscom.php?FETCH=wimage&WHO=' + plant.ID;
 }

 var sTab = genEl('table',iBox,'className=stats');
  var stBod = genEl('tbody',sTab);
   var stIrow = genEl('tr',stBod);
    var stirtdH = genEl('td',stIrow);
     var stirH = genEl('img',stirtdH,'alt=Height,title=Height,src=images/height.gif');
    var stirtdW = genEl('td',stIrow);
     var s = genEl('img',stirtdW,'alt=Width,title=Width,src=images/width.gif');
    var stirtdS = genEl('td',stIrow);
     var stirS = genEl('img',stirtdS,'alt=Season,title=Season,src=images/season.gif');
    var stirtdWat = genEl('td',stIrow);
     var stirWat = genEl('img',stirtdWat,'alt=Water,title=Water,src=images/water.gif');
    var stirtdL = genEl('td',stIrow);
     var stirL = genEl('img',stirtdL,'alt=Light,title=Light,src=images/light.gif');
   var stDrow = genEl('tr',stBod);
    var stdrH = genEl('td',stDrow);
     stdrH.appendChild(document.createTextNode(plant.HEIGHT));
    var stdrW = genEl('td',stDrow);
     stdrW.appendChild(document.createTextNode(plant.WIDTH));
    var stdrS = genEl('td',stDrow);
     stdrS.appendChild(document.createTextNode(plant.SEASON));
    var stdrWat = genEl('td',stDrow);
     stdrWat.appendChild(document.createTextNode(plant.WATER));
    var stdrL = genEl('td',stDrow);
     stdrL.appendChild(document.createTextNode(plant.LIGHT));
   
 if (plant.STOCK > 0)
 {
  var price = genEl('span',sBox,'className=price');
  
  if (plant.PRICE)
  {
   plant.quantity = genEl('input',price,'type=text,maxLength=3,value=1');
   plant.quantity.onkeyup = function (){plant.makePrice();};
   price.appendChild(document.createTextNode('for '));
   var subt = genEl('span',price,'className=subtotal')
   plant.subtotal = document.createTextNode('$' + plant.PRICE);
   subt.appendChild(plant.subtotal);
   var poin = genEl('span',price,'className=points');
   plant.points = document.createTextNode('earn ' + plant.REWARD + ' points');
   poin.appendChild(plant.points);
   var a2c = genEl('button',price);
   a2c.appendChild(document.createTextNode('ADD TO CART'));
   a2c.onclick = function () {makeCartItem(plant);};
   
   plant.makePrice = function ()
    {
     var quant = Math.floor(plant.quantity.value.replace(/[^0-9]/g, ''));
     plant.subtotal.nodeValue = '$' + (quant * plant.PRICE).toFixed(2);
     plant.points.nodeValue = 'earn ' + (quant * plant.REWARD) + ' points';
     plant.quantity.value = quant;
    };
   
   if (plant.NOMAIL)
   {
    var nomail = genEl('div',sBox,'className=nomail');
    nomail.appendChild(document.createTextNode(plant.NOMAIL));
   }
  }
  else price.appendChild(document.createTextNode('Only available at the nursery'));
 }
  
 var gSearch = genEl('button',iBox,'title=Google search');
  var gsImage = genEl('img',gSearch,'src=images/search.gif,alt=Google search');
  gSearch.onclick = function () {perch(plant.GENUStext + ' ' + plant.SPECIEStext);};
 
 var desc = genEl('p',sBox,'className=desc');
  desc.innerHTML = plant.WEBDESC; 
 
}




function myJournal()
{
 var stage = document.getElementById('stage');
 stage.innerHTML = '';
 
 var ele = genEl('div',null,'style.textAlign=center');
 
  var ele1 = genEl('h3',ele);
   ele1.appendChild(document.createTextNode('Welcome back ' + logger.details.userName + '.'));
  
  var logout = genEl('button',ele,'style.margin=40px');
   logout.appendChild(document.createTextNode('LOG OUT'));
   logout.onclick = function () {logOut();};
   
  var editacc = genEl('button',ele,'style.margin=40px');
   editacc.appendChild(document.createTextNode('EDIT ACCOUNT'));
   editacc.onclick = function () {editAccount();};
  
 stage.appendChild(ele);
 
 if (logger.cart)
 {
  for (var i in logger.cart.items)
  {
   makeCartItem(logger.cart.items[i]);
  }
  delete logger.cart;
 }
}




function NurseryList(who)
{
 loading('nurseryList');
 
 plants = Job('nurseryList',who);
 
 var NL = genEl('div',null,'id=nurseryList');

 var List = genEl('ul',NL,'className=nurseryList');
 
 var increment = 10000;
 
 for (var a in plants.genera)
 {
  var Gitem = genEl('li',List);
   Gitem.style.zIndex = increment;
  Gitem.innerHTML = plants.genera[a].species[0].GENUS;
  var Gist = genEl('ul',Gitem);
  
  increment--;
  
  for (var b in plants.genera[a].species)
  {
   var sItem = makeNurseryListItem(plants.genera[a].species[b]);
    sItem.style.zIndex = increment;
   Gist.appendChild(sItem);
   increment--;
  }

 }
 
 
 document.getElementById('nurseryList').parentNode.replaceChild(NL,document.getElementById('nurseryList'));
}




function page(xtract)
{
 allNames = xtract.split(' ')
 var fetch, who
 var load = 0
 for (var x in allNames)
 {
  if(allNames[x].substring(0,5) == 'fetch')
  {
   fetch = allNames[x].substring(5)
  }
  if(allNames[x].substring(0,3) == 'who')
  {
   who = allNames[x].substring(3)
  }
  if(allNames[x].substring(0,4) == 'load')
  {
   load = allNames[x].substring(4)
  }
 }


 if(load) loading(load)
 sherpa(fetch,who)
}



function perch(who)
{
 var searchControl = new google.search.SearchControl()
 var zeb = new google.search.WebSearch()
 var zim = new google.search.ImageSearch()
 searchControl.addSearcher(zeb)
 searchControl.addSearcher(zim)
 searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET)
 searchControl.setLinkTarget("zearched")
 searchControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING)
 var drawOptions = new google.search.DrawOptions()
 drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED)
 drawOptions.setInput('')
 
 searchControl.draw(document.getElementById('speciesBox'), drawOptions)
 searchControl.execute(who)
 
 document.getElementById('speciesBox').firstChild.firstChild.appendChild(google.search.Search.getBranding())

}




function popImage(plant)
{
 if (plant.popped)
 {
  plant.Nli.appendChild(plant.popped)
  return;
 }
 
 plant.popped = genEl('div',plant.Nli,'className=pimage');
 var ele = genEl('div',plant.popped,'className=rind');
 var ele1 = genEl('img',ele,'title=Click to close');
 ele1.src = 'zephscom.php?WHO=' + plant.ID + '&FETCH=wimage';
 ele.onclick = function () {plant.Nli.removeChild(plant.popped);};
 
}




function reRoll(fetch,who,dir,pix)
{
 rint = window.clearInterval(rint)
 var targ = document.getElementById(fetch)
 if (who) targ.parentNode.style.backgroundImage = 'url(images/loading.gif)'
 
 if (dir == 'h')
 {
  if (! Number(targ.style.width.replace('px','')) == pix) return
  targ.style.width = pix + 'px'
  rint = window.setInterval(
   function()
   {
    targ.style.width = (Number(targ.style.width.replace('px','')) - (pix / 12)) + 'px'
    if (Number(targ.style.width.replace('px','')) <= (pix / 12))
    {
     rint = window.clearInterval(rint)
     targ.style.width = '1px'
     if (who == 'perch') perch(null)
     else if (who) sherpa(fetch,who)
    }
   }
  ,20)
 }
 else
 {
  if (! Number(targ.style.height.replace('px','')) == pix) return
  targ.style.height = pix + 'px'
  rint = window.setInterval(
   function()
   {
    targ.style.height = (Number(targ.style.height.replace('px','')) - (pix / 12)) + 'px'
    if (Number(targ.style.height.replace('px','')) <= (pix / 12))
    {
     rint = window.clearInterval(rint)
     targ.style.height = '1px'
     targ.scrollTop = 0
     if (who == 'perch') perch(null)
     else if (who) sherpa(fetch,who)
    }
   }
  ,20)
 }

}




function saveCartItem (plant)
{
 var data;
 var url = "zephscom.php";
 
 data = "FETCH=saveCartItem&WHO=" + encodeURIComponent(plant.ID) + "&QUANT=" + plant.quantity.value;

 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return false;
 }
 xmlHttp.onreadystatechange=function()
 {
  try
  {
 
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
    return true;
   }
   
  } 
  catch(err)
  {
   alert(err + "\n\n\n" + xmlHttp.responseText);
  }
  
 }
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlHttp.setRequestHeader("Content-length", data.length);
 xmlHttp.setRequestHeader("Connection", "close");
 xmlHttp.send(data);
}




function scroller(who,dir)
{
 sint = window.clearInterval(sint)
 var targ = document.getElementById(who)
 if (dir == 'd') sint = window.setInterval(function(){targ.scrollTop += 8; if(targ.scrollTop >= targ.scrollHeight) sint = window.clearInterval(sint)},50)
 else if (dir == 'u') sint = window.setInterval(function(){targ.scrollTop += -8; if(targ.scrollTop <= 0) sint = window.clearInterval(sint)},50)
 else if (dir == 'b') targ.scrollTop = targ.scrollHeight
 else if (dir == 't') targ.scrollTop = 0
}



function sherpa(fetch,who,targ)
{
 var data
 var url = "zephscom.php"
 
 if (targ) loading(targ)
 
 data = "FETCH=" + fetch + "&" + "WHO=" + encodeURIComponent(who)

 xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request")
  return false
 }
 xmlHttp.onreadystatechange=function()
 {
  try
  {
 
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
    //eval(unescape(xmlHttp.responseText))
   }
   
  } 
  catch(err)
  {
   alert(err.description + "\n\n\n" + xmlHttp.responseText)
  }
  
 }
 xmlHttp.open("POST",url,false)
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
 xmlHttp.setRequestHeader("Content-length", data.length)
 xmlHttp.setRequestHeader("Connection", "close")
 xmlHttp.send(data)
 
 try
 {
  eval(unescape(xmlHttp.responseText))
 }
 catch(err)
 {
  alert(err)
 }
}




function signUp(challenge,response)
{
 var stage = document.getElementById('stage');

 if (document.getElementById('signUpForm1'))
 {
  var challenge = Recaptcha.get_challenge();
  var response = Recaptcha.get_response();
  var userName = document.getElementById('username');
  var email = document.getElementById('email');
  var password = document.getElementById('password');
  var confirmPassword = document.getElementById('confirmPassword');
  var err = genEl('p',null,'className=error');
  var valid = true;
  
  if (response) Recaptcha.destroy();
  else
  {
   err.appendChild(document.createTextNode('You did not provide a response to the reCAPTCHA and we can not verify that you are human.'));
   genEl('br',err);
   valid = false;
  }
   
  if (!isEmail(email.value))
  {
   err.appendChild(document.createTextNode('You entered an invalid email address.'));
   genEl('br',err);
   valid = false;
  }
  
  if (password.value != confirmPassword.value)
  {
   err.appendChild(document.createTextNode('Your password was not entered correctly.'));
   genEl('br',err);
   valid = false;
  }
  
  if (valid)
  {
   var shaP = new jsSHA(password.value,'ASCII');
   var humanTest = Job('SIGNUP',userName.value,'E=' + email.value + '&P=' + shaP.getHash('SHA-256','HEX') + '&C=' + challenge + '&R=' + response);
   
   if (!humanTest.isHuman)
   {
    err.appendChild(document.createTextNode('Your reCAPTCHA response was incorrect and we can not verify that you are human.'));
    genEl('br',err);
    valid = false;
   }
  }


  if (valid)
  {
   stage.innerHTML = '';
   
   var sfDiv = genEl('div',stage,'style.width=500px,style.margin=25px auto');

    var sForm = makeDetailsForm();
     sForm.id = 'signUpForm2';
     
    sfDiv.appendChild(sForm);
     
    var btn = genEl('button',sfDiv,'style.display=block,style.margin=25px auto');
     btn.onclick = function ()
     {
      if(document.getElementById('firstName').value.length > 1 && document.getElementById('lastName').value.length > 1 && document.getElementById('state').value !== 'blank') signUp();
     };
     btn.appendChild(document.createTextNode('Sign Up'));
    
    document.getElementById('firstName').focus();
 
   return;
  }
 
  
  genEl('br',err);
  err.appendChild(document.createTextNode('Please try again.'));
 }
 else if (document.getElementById('signUpForm2'))
 {
  var signed = Job('SIGNUP',null,formProc('signUpForm2'));
  
  stage.innerHTML = signed.response;
  
  return;
 }

  stage.innerHTML = '';
  
  if (err) stage.appendChild(err);
  
  var sfDiv = genEl('div',stage,'style.width=500px,style.margin=25px auto');
  
  var sForm = genEl('form',sfDiv,'id=signUpForm1');
   var uLab = genEl('label',sForm,'htmlFor=username');
    uLab.appendChild(document.createTextNode('User name'));
   genEl('br',sForm);
   var uName = genEl('input',sForm,'type=text,size=40,maxLength=64,id=username','username');
    var uBut = genEl('button',sForm,'style.margin=5px 20px');
     uBut.appendChild(document.createTextNode('Check'));
     uBut.onclick = function () {checkUserName();};
   var uStat = genEl('span',sForm,'id=usernameStatus,style.fontFamily=sans-serif,style.fontSize=12px');
   genEl('br',sForm);
   genEl('br',sForm);
   var eLab = genEl('label',sForm,'htmlFor=email');
    eLab.appendChild(document.createTextNode('Email '));
   genEl('br',sForm);
   var eM = genEl('input',sForm,'type=text,size=40,maxLength=256,id=email','email');
   genEl('br',sForm);
   genEl('br',sForm);
   var pLab = genEl('label',sForm,'htmlFor=password');
    pLab.appendChild(document.createTextNode('Password '));
   genEl('br',sForm);
   var pW = genEl('input',sForm,'type=password,size=40,maxLength=64,id=password','password');
    pW.onkeyup = function () {checkPass();};
   genEl('br',sForm);
   var pStat = genEl('div',sForm,'id=passStatus,style.fontFamily=sans-serif,style.fontSize=12px');
   genEl('br',sForm);
   var cpLab = genEl('label',sForm,'htmlFor=confirmPassword');
    cpLab.appendChild(document.createTextNode('Confirm password'));
   genEl('br',sForm);
   var cP = genEl('input',sForm,'type=password,size=40,maxLength=64,id=confirmPassword','confirmPassword');
    cP.onkeyup = function () {checkPass();};
   genEl('br',sForm);
 
  sForm.appendChild(document.createTextNode('Enter the two words'));
  
  var Rel = genEl('div',sfDiv,'id=recaptchaDiv,style.margin=5px 25px 25px 25px');

  Recaptcha.create('6LfnZ7sSAAAAAMxo5yfltOe9YalM1za5YOsRecvE', 'recaptchaDiv', {theme: 'white'});
  
  var btn = genEl('button',sfDiv,'style.display=block,style.margin=25px auto');
   btn.onclick = function () {if (checkUserName() && checkPass()) signUp();};
   btn.appendChild(document.createTextNode('Continue'));
  
  uName.focus();
}




function toggleCaChing()
{
 window.zReg = document.getElementById('zReg');
 if (zReg.style.height == '44px') zReg.style.height = '180px';
 else zReg.style.height = '44px';
}




function unRoll(who,dir,pix)
{
 rint = window.clearInterval(rint)
 var targ = document.getElementById(who)
 targ.parentNode.style.backgroundImage = ''
 
 if (dir == 'h')
 {
  if (Number(targ.style.width.replace('px','')) > 1) return
  targ.style.width = '1px'
  rint = window.setInterval(
   function()
   {
    targ.style.width = (Number(targ.style.width.replace('px','')) + (pix / 12)) + 'px'
    if (Number(targ.style.width.replace('px','')) >= (pix - (pix / 12)))
    {
     rint = window.clearInterval(rint)
     targ.style.width = pix + 'px'
    }
   }
  ,20)
 }
 else
 {
  if (Number(targ.style.height.replace('px','')) > 1) return
  targ.style.height = '1px'
  rint = window.setInterval(
   function()
   {
    targ.style.height = (Number(targ.style.height.replace('px','')) + (pix / 12)) + 'px'
    if (Number(targ.style.height.replace('px','')) >= (pix - (pix / 12)))
    {
     rint = window.clearInterval(rint)
     targ.style.height = pix + 'px'
    }
   }
  ,20)
 }

}








function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta)
	{
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	}
	else if (event.detail)
	{
		delta = -event.detail/3;
	}
	
	if (delta)
	{
	 var targ = eMe(event);
 
  while(targ.parentNode != null && (targ.scrollHeight <= targ.parentNode.scrollHeight || targ.parentNode.scrollHeight == 0))
  {
   targ = targ.parentNode;
  }
  
  //alert(delta)
	 if (delta < 0)
	 {
	  targ.scrollTop += 25;
	 }
	 else
	 {
	  targ.scrollTop += -25;
	 }
	}
	
 if (event.preventDefault) event.preventDefault();
 event.returnValue = false;
}




/* Initialization code. */
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

if (window.addEventListener) window.addEventListener('DOMContentLoaded', unHref ,false);
window.onload = unHref;







