/*
Copyright Paul A Norman 2009 Released under the most freedom version of the GNU in existance at any time
          P.O. Box 1005, Nelson 7040, New Zealand paul@paulanorman.info paul.a.norman@gamil.com 
					http://PaulANorman.com Skype://PaulANorman +6421782433 fax: +64212912433 
*/

/* if needing to take mail services out and turn of notification of search words to owner
   these are the line numbers as at 2010 November, 22

  In		index.html					Line 154
	In		js/main.js 					Line 773
	In		php/searchFor.php		Line 97 through 118


*/


var itemList = new Array();
var product = new Array();

var b = new Array();
var hold = new Array();

var  itemFile;
// var domainNamePath = "http:\/\/henry3\/Christopher\/cats\/"
var domainNamePath = document.location.protocol + "//"+ document.location.host +  document.location.pathname.substr(0,document.location.pathname.lastIndexOf('/')+1);

var itsMozillaLike;
 window.addEventListener ? itsMozillaLike = true : itsMozillaLike = false ;

var orderTrollyJs; 
var currentTab;
var inTrolly = false;

 var priceFactor = 2;
 
 var titleShowA;
 var titleShowB;
 
 var personalInfo;
 var storeNotes;
 var no_items = ""; // no_items called for in init() set in get_html() these are manually maintained excluded items
 var exclussionList = "";
 
 var bookListFile;
 var browserWindow; // used for browser check in function checkBrowsers(where)
 var checkCodetreeParentID = '';
 var codetreeCode = "now_top";
 var checkReplyHTML = '';
 
 var useSearchItem = false;
 var textSearchItem ='';
 var codeTreeHover = false;
 var specialWord;
 
function init()
 {
 // SEE ALSO jQuery(document).ready(function() AT END OF THIS FILE
 
//  moved down 	get_html(domainNamePath + "docs/no-items.txt", "no_items", null);
	
	 document.getElementById("forSearchEngines").style.display='none';
	  // Globals
         titleShowA = document.getElementById('treeSelectTitleA');			   
         titleShowB  = document.getElementById('treeSelectTitleB');
		 storeNotes = new Persist.Store('user_Info');

if (document.location.search == "?clearstorage")
	     {
			  storeNotes.set('user_Info', '');
			 }
    else
		{
			 getStoredInfo();				 
    }
		  
if ((checkLogin(document.location.search) == true) & (document.location.search.length != 23) )
   {
   /* make live when ready.
	 alert(' Please Note - Wholesale Pricing Displayed for Applicable Businesses,\n\n Any G.S.T, freight and or handling (if Applicable) \n Not Added Until Invoice is Issued.'); */
  	 priceFactor = 1;
	 document.getElementById("display_Company").innerHTML = "Business:";
	 document.getElementById("display_YourName").innerHTML = "Your Name:";
	 document.getElementById("productRequestsDisplay").innerHTML += " Wholesale Pricing";
	 document.getElementById("display_account_use").style.display = "block";
	 document.getElementById("cust_account_use").style.display = "block";
	 bookListFile = "docs/1_bookList_Wholesale.html";
	 exclussionList = "docs/no-items-wholesale.txt";
	 termsDoc = "static/terms_Wholesale.html"
	  helpDoc = "static/help_Wholesale.html";	
	 document.getElementById("display_gst").innerHTML = "+"; 
	 withGst = 'plus GST (NZ)';
	 document.getElementById("isBusiness").style.display = "none";
	 specialWord = 'Special';
	  }
		else
		{  // Public
		/* make live when ready.
		 alert(' Please Note - Retail Pricing Displayed ,\n\n G.S.T is included in Shown Prices.\n\n Freight and or handling (if Applicable) \n Not Added Until Order is Confirmed.'); */
		document.getElementById("productRequestsDisplay").innerHTML += " Retail Pricing";
		document.getElementById("cust_account_use").style.display = "none"; // reaffirmed
		document.getElementById("cust_account_use").checked = false; // set for return order email
		bookListFile = "docs/1_bookList_Retail.html";
		exclussionList = "docs/no-items-public.txt";
		termsDoc = "static/terms_Public.html";
		 helpDoc = "static/help_Public.html";
		document.getElementById("display_gst").innerHTML = "incl. "; 
		withGst = 'incl. GST (NZ)';
		specialWord = 'Special';
		 }
		 
  get_html(domainNamePath +  exclussionList, "no_items", null);		 
		
  orderTrollyJs = document.getElementById("orderTrolly");
	currentTab = document.getElementById("orderDataArea");
		

 
  get_html(domainNamePath + bookListFile, "books", null);
//	get_html(domainNamePath + "docs/2010Canv_ind.html", "choosePage", null);
	get_html(domainNamePath + termsDoc, "termsText", null);
	get_html(domainNamePath + helpDoc, "helpText", null);
	
 processItemList();
	// buildSearch();

  }

function buildSearch()
 {
   // allLinks = 
  }
 
	
function checkLogin(checkText)
{
if(checkText.length < 2)
    {return false;}
		
whatsThis = doasc(whatsThisNow);

 for (i=0; i < checkText.length; i++)
	   {
		    if(whatsThis.indexOf(checkText.substr(i,1)) > -1)
				  {
					return false;
					 }		 
		  }
	return true;		
}
	
	
function processItemList()
 {
 
 var fileName ="./docs/1-ITEM.TXT" + getMillis();
 
 var request = createXMLHttpRequest();
 request.open("GET", fileName, true);
 
 request.onreadystatechange = function() 
   {
   	if (request.readyState == 4) 
		    {
        
         if ( (request.responseText.substr(0,6) == '<html>')  |  (request.responseText.substr(0,6) == '[an er') )
         {
          alert("Please Make Sure Inventory List was Created and Uploaded");
		       }
    else	{
		     
				    itemFile =  request.responseText;	 

			//			var crLf = String.fromCharCode(13)+ String.fromCharCode(10);
						var crLf =  String.fromCharCode(10);

						   itemList = itemFile.split(crLf);
							 
						//	 alert("Development Message: "  + itemList.length + " Records Processed.");
							 
				/*		*/ 
							for (i = 0; i < itemList.length; i++) 
							{
							text = itemList[i];
							hold = text.split(",");
							
							if ( no_items.indexOf(hold[0] + ",") > -1 )  // no_items called for in init() set in get_html() these are manually maintained excluded items; comma added 23/02/2010 to avoid partial matches
							   {continue;}
							
							var holdData = new salesObjt(hold);
							buildTree(holdData);
							product[hold[0]] = holdData;
							
							} 
  					} 
			        dataArea = document.getElementById("treeArea");
				 addTree(endSpan + endSpan + endSpan);
				dataArea.innerHTML = buildTreeHTML;
	      }// if (request.readyState == 4)
     }// close function()
		 
 request.send(null);
 
 }
 
function salesObjt(hold)
 {
 this.code = hold[0];
 this.description = hold[1];
 this.price = hold[2];
 this.extraInfo = hold[3];
  }
 
 
 /* product code tree building :-
   
   function imgBuild(treeNode)
     function showCodeInfo()
      function buildSpan(treeNode)
       function addTree(html)
          function buildSpanCode(codeText, howFarIn, curProduct)
 
   GLOBALS :-
 */
 
 var buildTreeHTML ='';
 var curHeadings = new Array("","","");
 var treeNode = -1;
 var spacer ="<span class=\"spacer\">&nbsp;</span>";
 var endSpan = ""; //inital value until top three code headings are printed
 

			
 function imgBuild(treeNode)
 {
 var imgShow = "<img id=\"showNode_"+treeNode+"\" title=\"Show\" style=\"vertical-align : middle; display:inline-block;\" src=\"js/Collapsed.gif\">";
 var imgHide = "<img id=\"hideNode_"+treeNode+"\" title=\"Hide\" style=\"vertical-align : middle; display:none;\"  src=\"js/Expanded.gif\">";
 return imgShow + imgHide;
 }
 
 function showCodeInfo(what)
  {
     
     if (what.title == "")
     {titleShowA.innerHTML = "<b><u>Re-order from Known Codes</u></b>"
      itsMozillaLike ? titleShowB.textContent = "": titleShowB.innerText = "";
     }
      else
       { 
			 
			  request = getInnerText(what).replace( " ", "");
	 if (undefined == product[request])
	 {showTitle = "";}
	 else
	 {showTitle = product[request].description;}
			 
			  if (itsMozillaLike)
				  {
					 titleShowA.textContent = showTitle;
             titleShowB.textContent = showTitle;
					 }
					 else
					  {
						 titleShowA.innerText = showTitle;
               titleShowB.innerText = showTitle;
						 }
       }
  }
 function openCloseNode(treeNode)
  {
    openImage = document.getElementById("showNode_"+treeNode);
    closeImage = document.getElementById("hideNode_"+treeNode);
    nodeNum = ((treeNode *1) +1);
    nodeId = "node_"+ nodeNum;
    operateOnNode =  document.getElementById(nodeId);
   // alert(nodeId +': '+ operateOnNode);
 //   alert(treeNode + '  ' +"node_"+((treeNode *1) +1) +"<\n\n" + operateOnNode.outerHTML);
    
    if (openImage.style.display=='none')
        {
	  openImage.style.display='inline-block';
	  closeImage.style.display='none';
	  operateOnNode.style.display='none';
	}
     else
        {
          openImage.style.display='none';
	  closeImage.style.display='inline-block';
	  operateOnNode.style.display='inline';	  
	}
        
  }
 
 function buildSpan(treeNode)
 {
     return  "<span class=\"curssor\" onclick=\'openCloseNode("+treeNode+")\' id=\'node_"+treeNode+"\'>"; 
 }
 
 function makeBlock(nextNode)
  {
    return "<span id=\"node_"+ nextNode + "\" style=\"display:none\">"; 
  }
 
 function addTree(html)
  {
    buildTreeHTML += html;
  }
 // var crLf = String.fromCharCode(13) + String.fromCharCode(10);
  
 
 function buildSpanCode(codeText, howFarIn, curProduct)
   {
     treeNode = treeNode +2; // 1st value = 1
     
    if (treeNode > 3) // not done for beginning of tree - first three headings
    {
     endSpan = "</span>" ;
    }
    
    addTree('<br />'); //tried DIVs
     
     switch(howFarIn)
       {
	case 1:
          addTree( buildSpan(treeNode)   + imgBuild(treeNode) + codeText + spacer + spacer + spacer + "</span>" + makeBlock(treeNode +1));
	break;

        case 2:	
	  addTree( buildSpan(treeNode)  + spacer  + imgBuild(treeNode) + codeText + spacer + spacer + "</span>" + makeBlock(treeNode +1));     
	break;

        case 3:	 
	  addTree( buildSpan(treeNode)+ spacer + spacer + imgBuild(treeNode) + codeText + spacer + "</span>" + makeBlock(treeNode +1));     
 	break;
     
        case 4:
	      // addTree(spacer); // not needed in display
	      // addTree(spacer); // not needed in display
							

	  addTree( spacer + spacer + '<span class=\"productCode\" onmouseout=\"productOut(this);codeTreeOut(this)\" onmouseover=\"productOver(this);codeTreeOver(this)\" onclick=\"thisProduct(this)\">' + curProduct.code +'</span>');

	break;    
       }
     
         
   }

function buildTree(data)
 {
  curProduct = data;
  
  var dataArray = new Array();
    pCode = curProduct.code;
   dataArray = pCode.split(".");  // Codes are in the form of aaa.bbb.ccc.04  sorted a - Z  0 - 9
  
  if ( (dataArray[0] != curHeadings[0]) & (dataArray[1] != curHeadings[1]) & (dataArray[2] != curHeadings[2]) )
       {
	  curHeadings[0]=dataArray[0];  curHeadings[1]=dataArray[1]; curHeadings[2]=dataArray[2]; 
	  
	  addTree(endSpan + endSpan + endSpan);
	 
	  buildSpanCode(dataArray[0], 1, curProduct);
	  buildSpanCode(dataArray[1], 2, curProduct);
	  buildSpanCode(dataArray[2], 3, curProduct);
       }
     else if( (dataArray[1] != curHeadings[1]) & (dataArray[2] != curHeadings[2]) )
       {
	  curHeadings[1]=dataArray[1]; curHeadings[2]=dataArray[2];
	  
	  addTree(endSpan + endSpan);
	  
	    buildSpanCode(dataArray[1], 2, curProduct);
	    buildSpanCode(dataArray[2], 3, curProduct);
       }
     else if( dataArray[2] != curHeadings[2] )
       {
	  curHeadings[2]=dataArray[2];
	  addTree(endSpan);
	  
	   buildSpanCode(dataArray[2], 3, curProduct);
       }
     
     //now the actual prodict code
       buildSpanCode(dataArray[3], 4, curProduct);
  
 }


	
function findInf()
 {
 request = document.getElementById('code').value;
 
 alert(product[request].code +"  "+product[request].description + ", Costing: " + product[request].price + " +Gst");
  } 

function showTree(doThis)
	{
	 
	 treeView = document.getElementById("treeSelect");
	 treeView.style.display = doThis; 
	 
	  document.getElementById("orderTrolly").style.left = "5";
	  document.getElementById("trolleyJpeg").style.left = "575";
	  
	}
	
function  productOut(thisCode)	
	{
      titleShowA.innerHTML = "<b><u>Re-order from Known Codes</u></b>"
      itsMozillaLike ? titleShowB.textContent = "": titleShowB.innerText = "";
	
	}
	 
	function productOver(thisCode)
	 {	 
	 
	 			 
	 	 //if (documentgetElementById("itemTable").innerHTML.indexOf(thisWord) > -1)
		 
	 request = getInnerText(thisCode).replace( / /g, ""); // replace should be redundant
	 
	 if (request == "AddedtotheTrolley")
	  {
		thisCode.setAttribute("title", "  Already in the Order Trolley  ");
		 return;
		  }
	 
	 if (document.getElementById("itemTable").innerHTML.indexOf(request) > -1)
	  {
		thisCode.setAttribute("title", "  Already in the Order Trolley   \n\n" + product[request].description + '\n\n  Click to See  ');
		   return;
			 }
	 
	 if (undefined == product[request])
	     {
			  thisCode.setAttribute("title", "  Appologies, but this Product is Currently not Available.   ");
				thisCode.style.color = 'silver';
				thisCode.style.textDecoration = 'none';
				thisCode.style.cursor = 'default';
				codeInfoMissing(request);
			  }
			else
			 {
			 var thisPrice = product[request].price;
			 
			 extraInfo = product[request].extraInfo;
			 if ((extraInfo != "") & (extraInfo != undefined))
			  {
				 extraInfo = "    " + extraInfo + '\n\n ';
				 }
				  else
					{
					extraInfo = "";
					 }
				 			 
			 thisCode.setAttribute("title", "    " + product[request].description + '\n\n ' +
			 
			 extraInfo +
			 
			  "    $"+(thisPrice.replace("$","") * priceFactor).toFixed(2) + ' ea ' + withGst + '  \n\n   Click — to Add to Shopping Cart ');
   showCodeInfo(thisCode);  // in code tree
			  }	
	 }
	
function thisProduct(which)
 {

  request = getInnerText(which).replace( / /g , "");
	
document.getElementById("cacheImage").innerHTML = 
		 							 "<img  src=\"jpegs/"+ request + ".jpg\" alt=\"\">"; 	// have it ready for later mouseover in shopping trolley
	
	// alert(request);
  if (request == "AddedtotheTrolley")
	   {
		  showOrders();
			 return;
		   }
	
	if (undefined == product[request])
	    {//alert("Product: "+ request + " is regreatably not available at the moment.\n\nPlease check back soon.");
			codeInfoMissing(request);
			return;
			}
	else
 {	 
  var    tableOrder = document.getElementById("itemTable");
	
	
	
	for ( row =0; row < tableOrder.rows.length; row++)
			  {
					 tableOrder.rows[row].style.backgroundColor = "";
					 tableOrder.rows[row].style.border = "none";
				 }
				 
	  itsMozillaLike ? searchText = tableOrder.textContent : searchText = tableOrder.innerText;
	
	
	if (searchText.indexOf(request) > -1 )
	    {
			 // alert('You Have Already Ordered '+ request + "\n\n"+ product[request].description );
			 
			 for ( row =0; row < tableOrder.rows.length; row++)
			  {
				  if (tableOrder.rows(row).innerText.indexOf(request) > -1 )
					 { 
				//	 tableOrder.rows[row].style.textDecoration = "underline";
					 tableOrder.rows[row].style.backgroundColor = "#ffffff";
					 tableOrder.rows[row].style.borderStyle = "solid";
					 tableOrder.rows[row].style.borderColor = "green"
					 tableOrder.rows[row].style.borderSize =  "1px";
					 
					 tableOrder.rows[row].scrollIntoView();
					// break;
					 continue;
					  }

				 }
			 
			 showOrders();
			 return;
			  }
	
	newTR = tableOrder.insertRow(-1);
	newTR.style.textDecoration = 'none';
	
	itsMozillaLike ?  newTR.addEventListener('mouseover', trollyItem, false) 
	               :  newTR.attachEvent('onmouseover', trollyItem) ; 
								 
	//	itsMozillaLike ?  newTR.addEventListener('mouseout', leaveTrolleyItem, false) 
	//                 :  newTR.attachEvent('onmouseout', leaveTrolleyItem) ; 							 
	
	makeCell(newTR, product[request].code);
	makeCell(newTR, product[request].description );
	
	howMany = 1; //public
	
	var thisProduct = product[request].code ;
	if (((thisProduct.indexOf('C.GRC') > -1) 
	     |
		  (thisProduct.indexOf('C.GTC') > -1)
	     |
		  (thisProduct.indexOf('C.PGC') > -1)			
	     |
		  (thisProduct.indexOf('C.PANO') > -1)	
			 |
			(thisProduct.indexOf('C.PC') > -1)	 	
			 |
			(thisProduct.indexOf('LW.ART') > -1)	 				
			)
			&
		 (priceFactor == 1) // wholesale
		  )	
	    {howMany = 5;}
			
			if (((thisProduct.indexOf('W.MW') > -1) 
			)
			&
		 (priceFactor == 1) // wholesale
		  )	
	    {howMany = 10;}
	
	makeCell(newTR, '<input name=\"quantity\" id=\"quantity\" type=\"text\" size=\"2\" value=\"'+howMany+'\">');

var thisPrice = product[request].price;
    thisPrice = "$"+(thisPrice.replace("$","") * priceFactor).toFixed(2);
	makeCell(newTR, thisPrice);
	makeCell(newTR, '<span onmouseout=\"this.style.border=\'none\'\"  onmouseover=\"this.style.border=\'solid red 1px\'\" title=\"Delete this Line\" class=\"delRow\" onclick=\"deleteRow(this)\">X</span>');

	//alert(tableOrder.outerHTML); 
  //  showOrders();
	
	/* which.innerHTML = " Added to the Trolley " ; 
	which.style.textDecoration = "none";
	which.style.color = "darkgray";
	*/
	
	codesToCheck = document.getElementById("treeSelect").getElementsByTagName('span');
   showAsOrdered(codesToCheck, request);
	 
	codesToCheck = document.getElementById("midPanel").getElementsByTagName('span');		 
	 showAsOrdered(codesToCheck, request);	
	  
	} // end else
	
	// alert(product[request].code +"  "+product[request].description + ", Costing: " + product[request].price + " +Gst");
	
  }	

function showAsOrdered(codeToCheck, request)
{
for (thisSpan in codesToCheck)
	   {
		   if (codesToCheck[thisSpan].innerHTML == request)
		       {  
					              codesToCheck[thisSpan].innerHTML = " Added to the Trolley " ;
					   codesToCheck[thisSpan].style.textDecoration = "none";
					            codesToCheck[thisSpan].style.color = "darkgray";
					  break;   
					 }
		   }   

}	
	
function trollyItem(evt)
 {
 

  itsMozillaLike ?   thisRow = evt.target.parentNode	 : thisRow = event.srcElement.parentNode;
	
	     document.getElementById("trolleyJpeg").style.display = 'none'; // hopefully redundant
		
		thisImg = thisRow.cells[0].innerHTML;
				
		 document.getElementById("trolleyJpeg").innerHTML = 
		 							 "<h3 style=\"margin-top: 15px\">" + product[thisImg].description + "</h3>"
							 + "<img class=\"trollyJpegJpeg\"  lowsrc=\"js/artearoaZlogo.png\" src=\"jpegs/"+ thisImg + ".jpg\" alt=\""+thisImg+"\">" 
							 +  "<p style=\"font-family:arial, helvetica;\">" + product[thisImg].extraInfo + "</p>"
							 +  "<p title=\"Close Image Display\" style=\"text-align:left;\" onclick=\"closeArea(\'trolleyJpeg\')\"><span style=\" background-color:white; color:red; position:relative; left: 10; cursor:hand; cursor:pointer;\"> X </span></p>"
							 ;
 // this looks to see if an image could be being returned if not False shows the display area
		get_html("php/jpegthere.php", "trolleyJpeg", "jpegWanted=" + escape(thisImg));

  }	
	
function closeArea(thisArea)
 {
 // A manual close for occasions when Ajax is too far behind the mousoever closes, on the product images in shopping trolley and codetree
 
 document.getElementById(thisArea).style.display = 'none';
 }	
	
function codeTreeOver(whichCode)	
	{

	if (whichCode.innerHTML.replace(/ /g,"") == 'AddedtotheTrolley')
	     {
			  return;
			  }
	 
	
	syncDisplayToCode(whichCode);
	// alert(whichCode.innerHTML);
       document.getElementById("codeJpeg").style.display = 'none'; // hopefully redundant	

	thisImg = whichCode.innerHTML;
	
	
	// pre build and preload
	
									 document.getElementById("codeJpeg").innerHTML = 
								 "<h3 style=\"margin-top: 15px\">" + product[thisImg].description + "</h3>"
							 + "<img class=\"trollyJpegJpeg\"   lowsrc=\"js/artearoaZlogo.png\"  src=\"jpegs/"+ thisImg + ".jpg\" alt=\""+thisImg+"\">" 
							 +  "<p style=\"font-family:arial, helvetica;\">" + product[thisImg].extraInfo + "</p>"
							 +  "<p title=\"Close Product Display\" id=\"treeSelectClose\" onclick=\"closeArea(\'codeJpeg\')\"><span style=\" background-color:white; color:red; position:relative; left: -10;\"> X </span></p>" ;

 // this looks to see if an image could be being returned if not False shows the display area
		get_html("php/jpegthere.php", "codeJpeg", "jpegWanted=" + escape(thisImg));
	
	 }
	 
function showEnlarged(jpegCode)
{
// alert(jpegCode);

 thisImg = 	jpegCode;
spanClass = "productCode ft15";

  document.getElementById("codeJpeg").style.display = 'none'; // hopefully redundant	
	
	 document.getElementById("codeJpeg").innerHTML = 
	 "<p title=\"Close Product Display\" id=\"treeSelectClose\" style=\"text-align:left;\"   onclick=\"closeArea(\'codeJpeg\')\"><span style=\" background-color:white; color:red; position:relative; left:10px \"> X </span></p>" 
							 + "<h3 style=\"margin-top: 15px\">" + product[thisImg].description + "</h3>"
							 + "<img style=\"zoom:125%\" class=\"trollyJpegJpeg\"   lowsrc=\"js/artearoaZlogo.png\"  src=\"jpegs/"+ thisImg + ".jpg\" alt=\""+thisImg+"\">" 
							 +  "<p style=\"font-family:arial, helvetica;\">" + product[thisImg].extraInfo + "</p>"
							 //+  "<p style=\"font-family:arial, helvetica;\">" + product[thisImg].code + "</p>"
							 +"<p><span class=\""+spanClass+"\" onmouseover=\"productOver(this)\" onclick=\"thisProduct(this);alert(\'Thank You - "+ product[thisImg].description + " - Has Been Placed in the Order Trolley\');\">" + jpegCode + "</span></p>"
							 +  "<p title=\"Close Product Display\" id=\"treeSelectClose\" onclick=\"closeArea(\'codeJpeg\')\"><span style=\" background-color:white; color:red; position:relative; left: -10;\"> X </span></p>" ;

 // this looks to see if an image could be being returned if not False shows the display area
		get_html("php/jpegthere.php", "codeJpeg", "jpegWanted=" + escape(thisImg));

}	 
	 
function codeTreeOut(whichCode)
	{
	 document.getElementById("codeJpeg").style.display ="none"; 
   codetreeCode = "now_top";	 
	 
	}
	
function leaveTrolleyItem() 
 {
  document.getElementById("trolleyJpeg").style.display ="none"; 	
	}
	
	
function makeCell(thisTr, html)	
	{
	newTD = thisTr.insertCell(-1);
	newTD.innerHTML = html;
	newTD.scrollIntoView();
	 }
	
function deleteRow(which)
 {
 

  	var    tableOrder = document.getElementById("itemTable");
 //tableOrder.deleteRow(which.parentNode.parentNode.rowIndex);
thisRow = which.parentNode.parentNode;
 
 if(thisRow.style.textDecoration == 'none')
    { 
		 thisRow.style.textDecoration='line-through';	
		 which.style.color = 'green';
		 which.style.backgroundColor = '#f0ffff';
		 which.style.borderColor = 'green';
		// which.style.fontWeight = 'bold';
		 which.style.fontSize = '12pt';
		 which.style.textDecoration='none';
		 which.title = 'Restore this Line for Order';
		 which.innerHTML = '&#43;';
		 
		 	 
		 }
		 else
		  {
		  	thisRow.style.textDecoration = 'none';
				which.style.color = 'darkred';
				which.style.borderColor = 'red';
				which.style.backgroundColor = '';
			//	which.style.fontWeight = 'normal';
				which.style.fontSize = '10pt';
				which.title = 'Delete this Line';
				which.innerHTML = 'X';
			 }
 
  }	
	
function sendOrder(whatType, Message)	
 {
	 // Process verification of essential data then call  sendOrderOff(); if 
	  	 
		
	 switch (whatType) 
	  {
	   case 'customer':
		
		// lets do dome verification first, we are happy to only receive the email address to kick things off so do not need to verify the rest of the input. 
	
	  // Pear php will endeavour to confirm the email address when sending, and send a response, so we look for obvious errors here, assuming that the person knows their own email address!

    if ( checkEmailAddress() != true)
		         {break;}
		 
		 termsOk = document.getElementById("acceptTerms");
		 	 
	   if (termsOk.checked != true)
		   {
			  termsOk.focus();
				alert("  First Please ...  Do You Accept the Terms and Conditions?  \n\n  If You Do PLease Tick The Box Provided.  ");
			  }
       else // All Ready and OK
			 {
			// alert('Development Message:\n\n Hosting Service Yet to Turn Pear Package Mail on.  \n\n  Orders Can Not Be Procesed Yet.');
       
			// alert('We Regret That our Web Services Provider is Unable to Process Orders at Present.\n\nPlease\n Email us on sales@artearoa.com \n Phone us on +6421 976 521 ( 021 976 521 )\n or Phone / Fax us on +6498280132 ( 09 828 0132 )\n\n  (You Can Copy and Paste Your Order into Your Message \n - We Will Need to Confirm Item Numbers)'); showTab('orderDataArea');
	
		  	sendOrderOff('productOrder');
			 }
			 
	     break;
			 
		  // here down redundant ?
						
	   case 'message':
	    alert(Message); //replace with functionality
	   break;	 
	 
	   case 'missing':
	    alert("Missing Product MYOB Code? :  " + Message); //replace with functionality
	   break; 
			
			} //end switch
	 
  }


function checkEmailAddress()
 {
 	 combined = document.getElementsByName("cust_Email_1")[0].value + document.getElementsByName("cust_Email_2")[0].value;

		 if (    // beginnig of if test
		      (document.getElementsByName("cust_Email_1")[0].value != document.getElementsByName("cust_Email_2")[0].value) // entered email is not the same in both boxes
					|
					(combined == "")               // there is nothing entered
					|
					(combined.indexOf(" ") != -1)  // there is a space somewhere
					|
					(combined.indexOf(".") == -1)  // there is no dot in anything
					|
					(combined.indexOf("@") == -1)  // ...  @ missing
					|
					(combined.length < 12)         /* combined inputs less than twelve characters, seems too short
					                                  a@b.tv = six characters - shortest possible? 
																						http://www.eph.co.uk/resources/email-address-length-faq/
																						http://en.wikipedia.org/wiki/E-mail_address
																						*/
				 )	// end of if test
		     {				 
				 alert(
				     "Please Check Your Email Address:- \n\n" +
				     document.getElementsByName("cust_Email_1")[0].value +
						 "\n" +
						 document.getElementsByName("cust_Email_2")[0].value
						 );	
						 showTab('orderAddressArea');
						 document.getElementsByName("cust_Email_1")[0].focus();		 
				  return false;
				  }
		    else // all is ok
        {
				return true; 
				}
 
 }	
	
	// Global
	
	var OrderInformation;
	
	var nameFrom;
	var emailFrom;
	
	
function sendOrderOff(whichType)
 {
 allItems = document.getElementById("personal_info").childNodes;
 
 var  buildEmail = "\n";
  
	 for ( x in allItems)
	      {
				thisNode = allItems[x];
			
				  if ( (thisNode.name != undefined) & (thisNode.name != "") & (thisNode.name != "item") & (thisNode.name != "cust_Email_1") )
				   {
			
				// alert(allItems[x].getAttribute('type').toLowerCase());
					 switch(thisNode.tagName.toLowerCase())
					 {
					 
					case 'input':
					  if (thisNode.type.toLowerCase() == 'checkbox')
						    {aspectText = thisNode.checked;}
							else
							  {aspectText = thisNode.value; }	
					 	
						break;
						
					case 'textarea':
					  
					    itsMozillaLike ?  aspectText = allItems[x].value : aspectText = allItems[x].innerText;
					  break;			
				
					 }
					
					 buildEmail += thisNode.name + ':  \n' + clearAmpersands(aspectText + '') + '\n\n'; // force cast to string + '' otherwise we appeaar to be attmpting to put a boolean into a regular expression in function clearAmpersands()
					 		 }
					 
					 }
					 
					 
 	
	fullEmailAddress = 
	clearAmpersands(document.getElementById("cust_Firstname").value) + " " +   
  clearAmpersands(document.getElementById("cust_Surname").value) + " <" + 
  clearAmpersands(document.getElementById("cust_Email_2").value) + ">"	;	
	
	
	if (whichType == 'contactMessage')
	 {

	 
	 buildEmail = "emailbody=" + buildEmail + "&fullEmailAddress=" + fullEmailAddress + "&cust_Firstname="+ 
  clearAmpersands(document.getElementById("cust_Firstname").value) + "&cust_Surname="+ 
  clearAmpersands(document.getElementById("cust_Surname").value);
		    buildEmail += "&cust_Message_Subject=" + clearAmpersands(document.getElementById("cust_Message_Subject").value) 	;
	  itsMozillaLike ?  buildEmail += "&cust_Message_Contents=" +   clearAmpersands(document.getElementById("cust_Message_Contents").value) 
			                                              :
											buildEmail += "&cust_Message_Contents=" +  clearAmpersands(document.getElementById("cust_Message_Contents").innerText)
                                                    ;

	 //  	alert(buildEmail);
	
     get_html("php/contactMessage.php", "contactMessage", buildEmail);
	alert("Thank you, your message is being sent.");
      leaveTrolleyItem(); // closes mouse over image display if open	 
	   return;
	  }
	
   buildOrderUp = '\n\nOrdered These Items:\n\n';
	 	 
	/*  buildEmail += orderText;
    itsMozillaLike ? 
		  buildEmail += document.getElementById("itemTable").textContent.replace(/X/g,"\n\n") 
		: buildEmail += document.getElementById("itemTable").innerText.replace(/X/g,"\n\n")
		;
		*/
		
		orderTable = document.getElementById("itemTable").rows;
		for (i =1; i < orderTable.length; i++)
		  {
			  if (orderTable[i].style.textDecoration == 'line-through')
				   { continue;} // don't send customer deleted row items
				
			  for (j=0; j < orderTable[i].cells.length; j++)
				  {					  
					if (j == 2)
					 {
						itsMozillaLike ? cellText = "x"+ orderTable[i].cells[j].getElementsByTagName("input")[0].value  : cellText = "x"+ orderTable[i].cells[j].getElementsByTagName("input")[0].value ;
								  }
					     else
						   {
							   itsMozillaLike ? cellText =  orderTable[i].cells[j].textContent 
							                  : cellText =  orderTable[i].cells[j].innerText;
						    }
								
						 if (cellText != "X")
						 {
						     buildEmail += cellText + '  ';
							 }  
					 }buildEmail +=  "\n\n";
			   
			  }
					 buildEmail = clearAmpersands(buildOrderUp + buildEmail) + "\n\n";
				///buildEmail = buildEmail.replace(/&/g," and ");
					
		
					
	// alert("?emailbody=" + buildEmail + "&fullEmailAddress=" + fullEmailAddress + "&cust_Firstname="+ document.getElementById("cust_Firstname").value );			
					
 buildEmail = "emailbody=" + buildEmail + "&fullEmailAddress=" + fullEmailAddress + "&cust_Firstname="+ 
  clearAmpersands(document.getElementById("cust_Firstname").value) + "&cust_Surname="+ 
  clearAmpersands(document.getElementById("cust_Surname").value) ; 

	//  alert(buildEmail);
	
      get_html("php/sending.php", "sendOrder", buildEmail);

 leaveTrolleyItem(); // closes mouse over image display if open
 closeTrolley();

  }	
		
function closeTrolley()
 {
 // ensure mesasage area is invosoble to show ordering functions
 document.getElementById('sendMessageArea').style.display='none';

 document.getElementById("orderTrolly").style.display="none";
  inTrolly = false;
	leaveTrolleyItem();

  }		
		
function clearAmpersands(thisText)		
{

 thisText =  thisText.replace(/=/g," equals ");
return  thisText.replace(/&/g," and ");
 }
 
function codeInfoMissing(product_code)
{
 //alert(">" + product_code + "<");
 
if (product_code == "AddedtotheTrolley")
   {return;}
	 
if ( window.confirm(" We appologise but it appears there is \n missing product information here.\n\n"+
      "  Please click \"OK\" to let us know or \"Cancel\" to continue. \n\nThank you.") == true)
  {
	fullEmailAddress = document.getElementById("cust_Firstname").value + " " + document.getElementById("cust_Surname").value+ " <" + document.getElementById("cust_Email_1").value + ">"	;		
	
	  buildMessage = "codeInfo=" + escape(product_code) + "&cust_Firstname=" + escape(document.getElementById("cust_Firstname").value)+ "&fullEmailAddress=" + escape(fullEmailAddress)  + "&millitext=nothing";

	  get_html("php/missing_code.php", "codeCorrection", buildMessage);
		
	}	

}		
		
function  showOrders(evt)
 {
 
 //  itsMozillaLike ? whoWantsToOpenTheTrolly = evt.target : whoWantsToOpenTheTrolly = window.event.srcElement ;
 
 codeTreeOut('');  // hide trolly mouseover
 
   if (treeSelect.style.display.toLowerCase() == 'block')
	 {
	  document.getElementById("orderTrolly").style.left = "265";
	  document.getElementById("trolleyJpeg").style.left = "865";
		}
	 else
	 {
	  document.getElementById("orderTrolly").style.left = "5";
	  document.getElementById("trolleyJpeg").style.left = "605";
		}
 
			document.getElementById("orderTrolly").style.display = "block";
				showTab('orderDataArea');
		
  }	
	
function hideArea(what)
 {
  what.style.display = 'none';
  if (what.id == "orderTrolly")
	    {inTrolly = false;}
   }	
	 
function orderTabOver()
 {
   window.event.srcElement.className = 'orderTabButton orderTabButtonHover';
	   }	 
		 
function orderTabOut()
 {
   window.event.srcElement.className = 'orderTabButton';
	   }		 
		 
function orderHideOver(btn)
 {
   btn.className = 'orderHideForm orderTabButtonHover';
	 //alert(window.event.srcElement.innerText)
	   }	 
		 
function orderHideOut(btn)
 {
   btn.className = 'orderHideForm';
	   }				 
	
//	currentTab is Golobal
function showTab(show)		 
 {
 
 currentTab.style.display = 'none';
 var newTab = document.getElementById(show);
 
 newTab.style.display='block'; 
 currentTab = newTab;
  }
	
function createXMLHttpRequest() 
{
 if (typeof XMLHttpRequest != "undefined") 
    {
	    return new XMLHttpRequest();
     } else if (typeof ActiveXObject != "undefined") 
		    {
	       return new ActiveXObject("Microsoft.XMLHTTP");
        } 
			 else {
	            throw new Error("XMLHttpRequest not supported");
             }
 }

 function getMillis()
 {
 //use millis to get around IE caching problems gives a new appearnance to the httpXml request
   d = new Date();
	 return  "?millis="+  d.getTime()
 }	
	

    // Native XMLHttpRequest object


function get_html(fileName, where, query) 
{
 // alert(fileName);	
 var request = createXMLHttpRequest();
 var buildHTML  = "";
 var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
 
 // getMillis() forces a unique file name to get around caching issues 
 request.open("post", fileName + getMillis(), true);

 request.setRequestHeader("Content-Type", contentType);

 
 request.onreadystatechange = function() 
   {
   	if (request.readyState == 4) 
		    {
         //alert('>'+request.responseText.substr(0,6)+'<');
         if (  (request.responseText.indexOf('[an er') > -1 ))
            {
          alert("File Missing: "+ fileName + "\n\n" + request.responseText);
		       }
    else	{
		        reply =  request.responseText;	 
						
						
							
						switch(where)
					   	{
							
				case "showMessage":
				  
				break;		
				
				case "browserCheck":
					 browserWindow.document.body.innerHTML = reply ;
				break;
							
				case "termsText":
						   document.getElementById("termsText").innerHTML = reply;		
							 break;
							 
				case "helpText":
						   document.getElementById("helpText").innerHTML = reply;		
							 break;
							 
							 				
				 case "books":
						   document.getElementById("books").innerHTML = reply;
						   // reposition scrollable list
						   scrollAndClick(document.getElementById(where).childNodes.item(0));
							 
							   bookList = document.getElementById("books").getElementsByTagName("span");
							 
							   for ( kk =0; kk < bookList.length; kk++)
								  {
								
									 if (itsMozillaLike == true)
									   {
										 bookList[kk].addEventListener('mouseover',classOver , false);
										 bookList[kk].addEventListener('mousedown', classDown, false);
										 bookList[kk].addEventListener('mouseout', classOut, false);
									   bookList[kk].addEventListener('click', clicked, false);	
										 bookList[kk].setAttribute('selected',"false");									 
										  }
										 else
										  {
										bookList[kk].attachEvent("onmouseover", classOver);	
										bookList[kk].attachEvent("onmousedown", classDown);		
										bookList[kk].attachEvent("onmouseout", classOut);	
									  bookList[kk].attachEvent("onclick", clicked);
										bookList[kk].setAttribute('selected',"false");
											 }
											}// end 				 for ( kk =0; kk < bookList.length; kk++)				
									
								// Now we set first node to show as chosen (white background) and set its flag selected true	

									classList = "page_links page_links_mouseclicked";									 
									 itsMozillaLike ? bookList[0].setAttribute("class", classList)	: bookList[0].setAttribute("className", classList);

bookList[0].setAttribute("selected","true");
							   
							 // ="()" ="()" ="()" ="(this)"
						  break;
							
						  case "doSearch":
							// reply = unescape(reply);
					  // 	alert(reply); // run into choosePage	
						  useSearchItem = true;
						// this deliberately runs into    case "choosePage" no break
		          case "choosePage": 
						
						    document.getElementById("choosePage").innerHTML ="";
					      document.getElementById("choosePage").innerHTML = reply;
					       var thisBook = document.getElementById("choosePage");
	//	alert(thisBook.childNodes.length);			   
					         for (J = 0; J < thisBook.childNodes.length; J++)
                	    {
											 										 
                			 thisRef = thisBook.childNodes[J]; 
											 if (thisRef.nodeType != 1) {continue}; // not a tag, perhaps a text node or blank space
											 
 //  alert(thisRef.tagName);	
                				if (thisRef.tagName.toLowerCase() == "a")
                						{	
                						   thisHref = thisRef.getAttribute("href");
                						   startPos = thisHref.lastIndexOf("/");
                							 ourFile = thisHref.substr(startPos +1, thisHref.length - (startPos +1));
                						    
                							 //startPos = 8;
															 startPos = ourFile.indexOf("-");
                							 ourDir = ourFile.substr(0, startPos )
                							 
       // 4Xbrowser -  build fill path based on inedx.html location replace ./ with http://  + that  							 
															 
															 thisHref = domainNamePath + ourDir + '/' + ourFile;
                						  
															
															// don't want the links generated by pdftohtml utility to be use but replaced
															 thisRef.style.display = "none";
																 
																 
						 if ( (thisRef.getAttribute('colourise') != null) & (thisRef.getAttribute('colourise') != undefined) )			 
								{colourise = ' colourise=\"' + thisRef.getAttribute('colourise') + '\"'; }
							else
							  	{colourise = '';}		
														
																	thisSpanMake = '<span pageRef=\"' +
                								  thisHref   + '\" '+ colourise +' title=\"'+ thisRef.title +'\" onclick=\"showPage(this);\">'+
                										   thisRef.innerHTML + '</span>';

 // alert(thisSpanMake);
																																								
														    buildHTML += thisSpanMake;
                							}
                			 }
               thisBook.innerHTML = buildHTML ;
							 
							 pageList = thisBook.getElementsByTagName("span");
							 
							   for ( kk =0; kk < pageList.length; kk++)
								  {
									 if ( (pageList[kk].getAttribute('colourise') != null) & (pageList[kk].getAttribute('colourise') != undefined) )
																    { 
																		 pageList[kk].style.color = pageList[kk].getAttribute('colourise');
																//		 pageList[kk].style.fontWeight = '600';
																		 
																		 } //  
         		
									
									 if (itsMozillaLike)
									   {
										 pageList[kk].addEventListener('mouseover', classOver , false);
										 pageList[kk].addEventListener('mousedown', classDown, false);
										 pageList[kk].addEventListener('mouseout', classOut, false);
										 pageList[kk].addEventListener('click', clicked, false);	
										 pageList[kk].setAttribute('selected',"false");			
		
										  }
										 else
										  {
										pageList[kk].attachEvent("onmouseover", classOver);	
										pageList[kk].attachEvent("onmousedown", classDown);		
										pageList[kk].attachEvent("onmouseout", classOut);	
										pageList[kk].attachEvent("onclick", clicked);
										pageList[kk].setAttribute('selected',"false");	
																				 }	
									 }
									 							 
                	          // reposition scrollable list to show top item
														
								if (document.getElementById("choosePage").innerHTML.indexOf("Search Results") > -1)
                    {scrollAndClick(document.getElementById("choosePage").childNodes[1])}
										else
										  { scrollAndClick(document.getElementById("choosePage").childNodes[0]);}
                			
                  break;
						 
                case "midPanel": 
	
	//alert( reply); 
	// alert("midPanel");
					var thisPage = document.getElementById("midPanel");
	               // Global checkReplyHTML
								 
								   if (checkReplyHTML == reply.replace(/artearoaZemail/g,"<img src=\"js/artearoaZemail.jpg\" title=\"Click to Send Message\" class=\"likeLinkNoBlue\"  onclick=\"showContactArea()\">"))
									        {
													 											 
											 scrollCodeIntoView();		
											 
													break;
													} // END/ if (checkReplyHTML == reply)
										 
		
									///	checkReplyHTML = reply.replace("background image","&nbsp;For Pricing&#151; &#13;&#13; Mouse Over Green Underlined &#13; Codes &#13;&#13;      Click To Order ");
	checkReplyHTML = reply;
	  checkReplyHTML = checkReplyHTML.replace("background image","");
											
											// Mozilla and IE ok, but Chrmoe is is applying the css! have to limit was used
												 
												 bodyStart = checkReplyHTML.toLowerCase().indexOf('<body') ; //'blue"> peculiar to these files
											 
												 bodyEnd = checkReplyHTML.toLowerCase().indexOf("</body");
												 											 
												 bodyInnerHtml = checkReplyHTML.substr(bodyStart, bodyEnd - bodyStart);	
											 								
							  thisPage.innerHTML = "<span class=\"zero\" id=\"now_top\">now_top</span>" + bodyInnerHtml;
	//	alert(thisPage.innerHTML);
															
	           thisImg = thisPage.getElementsByTagName("IMG");
						 						 
						 thisImg = thisImg[0];
						
											 thisSrc = thisImg.getAttribute("src");
	 //alert(thisSrc);											 
										   startPos = thisSrc.lastIndexOf("/");
											 ourSrc = thisSrc.substr(startPos +1, thisSrc.length - (startPos +1));
										    
											 startPos = 8;
											 ourDir = ourSrc.substr(0, startPos )
// alert( ourSrc)
											 ourSrc = ourSrc.replace(".png",".jpg"); // the pngs were taking too long for dialup
// alert( ourSrc);											 
											 thisSrc =  domainNamePath + ourDir + '/' + ourSrc;
	// alert(thisSrc);
											 itsMozillaLike ? thisImg.setAttribute("src", thisSrc) : thisImg.src = thisSrc ;
											 
											 thisImg.style.position = "relative";
											 thisImg.style.left="-10px";

//  alert(thisImg.src);											 
											 
 allDivs = thisPage.getElementsByTagName("div");											 
						       		
		pageArea = allDivs;
					 															
	//	alert(pageArea.childNodes.length);
					numUpToHere = 0;
											 
						 for (J = 0; J < pageArea.length; J++)
					    {
							 thisRef = pageArea[J]; 
							 
							 if (thisRef.nodeType != 1)
                    {
										 continue; // not a tag - in Mozilla like browmsers safari and Chrome
										 }

								
								 if (thisRef.tagName.toLowerCase() == "div")
											 {
											 
											 if ( (thisRef.childNodes[0] != null) && (thisRef.childNodes[0].childNodes[0] != null ) && (thisRef.childNodes[0].childNodes[0].tagName.toLowerCase() == "span"))
											     {
													  thisSpan = thisRef.childNodes[0].childNodes[0]}
													  else {continue}
											 
											 tagWords = thisSpan.innerHTML.split(" ");
											 
											 for (k = 0; k < tagWords.length; k++)
											   {
												   thisWord = tagWords[k];
													 
													 
													   if (thisWord.substr(thisWord.length -1, 1) == ".")
														  {continue;}// don't want a trailing dot
															
														 dotCount = 0;
													   for (w = 0; w < thisWord.length; w++)
														   {
															
															   if (thisWord.substr(w,1) == ".")
																   {
																	  dotCount++;
																	  }
															  }
																
																titleCase= false;
														  if (dotCount > 2)
															 {
															 //spanClass capturs the orginal class the\at pdftohtml set this can be importanting for span with and centering look.
															// itsMozillaLike ? spanClass = thisSpan.class : spanClass = thisSpan.className; 
															 
															   spanClass = "productCode";
																 
																 if((thisWord.indexOf("GTC") > -1) | (thisWord.indexOf("PGC") > -1))
																   {spanClass = "productCode ft10";}
													
																	 
																 if((thisWord.indexOf("GRC") > -1) | (thisWord.indexOf("C.PANO") > -1))
																   {spanClass = "productCode ft15";}
																												 
												         if (document.getElementById("itemTable").innerHTML.indexOf(thisWord) > -1)
																 		{spanClass = "productGray ft15";}		
															 numUpToHere++;
															 tagWords[k] = "<span class=\""+spanClass+"\" onmouseover=\"productOver(this)\" onclick=\"thisProduct(this)\">" +
															              thisWord + "</span>&nbsp;&nbsp;&nbsp;<img src=\"js/Picture2.bmp\" onclick=\"showEnlarged(\'" + thisWord + "\')\" style=\"z-index:100;cursor:hand; cursor:pointer\" title=\"Click to Enlarge\">";																						
																			
															  }
																else // dotCount 2 or less
																{
																 titleCase = true;
																}
												  } // end  for (k = 0; k < tagWords.length; k++) 
													
													thisSpan.innerHTML = tagWords.join(" ");					 
										
											    if (titleCase == true) 
											      {
														thisSpan.innerHTML = "<span class=\"ft1\">" + thisSpan.innerHTML + "</span>";
														 }
														 
														 if( (thisSpan.innerHTML.indexOf("GTC") > -1) | (thisSpan.innerHTML.indexOf("PGC") > -1) )			
														 {
														 thisSpan.innerHTML = "<span class=\"ft10\">" + thisSpan.innerHTML + "</span>";
														  }
														 							
															 if( (thisSpan.innerHTML.indexOf("GRC") > -1) | (thisSpan.innerHTML.indexOf("C.PANO") > -1) )			
														 {
														 thisSpan.innerHTML = "<span class=\"ft15\">" + thisSpan.innerHTML + "</span>";
														  }						
																									 
														 
											 } // end else if (thisRef.tagName.toLowerCase() == "span")
							}	
							
// 					  document.getElementById("now_top").scrollIntoView(true	);		
							
							 thisPage = document.getElementById("midPanel");
							thisPage.innerHTML =	thisPage.innerHTML.replace(/artearoaZemail/g,"<img src=\"js/artearoaZemail.jpg\" title=\"Click to Send Message\" class=\"likeLinkNoBlue\"  onclick=\"showContactArea()\">");
							thisPage.innerHTML =	thisPage.innerHTML.replace(/artearoaZlogo/g,"<img src=\"js/artearoaZlogo.png\" class=\"artearoaZlogo likeLinkNoBlue\" title=\"Click to Send Message\" class=\"likeLinkNoBlue\"  onclick=\"showContactArea()\">");

							scrollCodeIntoView();		 
							
				//			document.getElementById("now_top").style.display = 'inline-block';
			 
 
           
					 
				//		   getImagePreviews();
						//	alert(reply);
						//	alert(document.getElementById(where).outerHTML);
						 break;
						
						case "sendOrder":
						   alert(reply);  
						
						 break;
						 
						case "contactMessage":
						
						if (reply == "ok")
						 {
						  alert(" Thank you for your message \n - a copy has been emailed to you.  ");
					
							document.getElementById('cust_Message_Subject').value = '';
							document.getElementById('cust_Message_Contents').value = '';
							closeTrolley();
						    }
							else
							 {
						 alert('  Unfotrunately your message could not be sent, \n  please check your email address and try again.  ');
     	 // alert(reply);
							showContactArea();
							 document.getElementById("cust_Email_1").focus();
							   }	
						
						break;						 
					  
						case "no_items":
					   no_items = reply; // no_items called for in init() set in get_html() these are excluded items from code tree
					  break;
					  
					 case "codeCorrection":
					     alert(reply);	
						 break;
						 	  
					 case "trolleyJpeg":
					   // alert(reply);
							
							if (reply != "False")
							   {
								// document.getElementById("trollyJpeg").innerHTML = "<img class=\"trollyJpegJpeg\"  src=\"jpegs/"+reply+"\" alt=\""+reply+"\">";

								 document.getElementById("trolleyJpeg").style.display ="block";
								   }
					 break;			
					 
					 case "codeJpeg":
					   // alert(reply);
							
							if (reply != "False")
							   {
								// document.getElementById("codeJpeg").innerHTML = "<img class=\"trollyJpegJpeg\"  src=\"jpegs/"+reply+"\" alt=\""+reply+"\">";

								 document.getElementById("codeJpeg").style.display ="block";
								   }
					 break;							 
								
						 default:    
						} 
						
			     } //else
	      }// if (request.readyState == 4)
     }// close function()
		 
 request.send(query);
}

function scrollAndClick(what)
 {
 	what.scrollIntoView();
	clickSomething(what);
  }
	
var newWin; //Global
	
function showMore(moreInfo, which, imgWidth, imgHeight)
  {
	var extraInfo, infoBuffer;
	
	if (moreInfo != "")
	 {
	  extraInfo = "<div style=\'left: 10; overflow-y: auto; height: 50px; width : " + ((imgWidth * 1)- 20) + ";\'>" + moreInfo + "</div>"
	  infoBuffer = 60;
	   }
	 else
	  { 
		 extraInfo ="";
		 infoBuffer = 0;
		 }	 
	
	imgHeight = (imgHeight *1) + 60 + ( infoBuffer * 1);

		if  ( newWin !=	 undefined) 
	   {
		 newWin.close();
		  }
	 
 newWin=	window.open("./blank.html", "ourWin", "height="+((imgHeight *1) + 33) +",width="+((imgWidth *1)+30)+",status=yes,toolbar=no,menubar=no,location=no");
	 contents = '<img  galleryimg=\"no\"  onload=\"document.getElementById(\'waiting\').style.display=\'none\';\" style=\"z-index: 1; display:block\" src=\".\/docs\/'+which+'\" alt=\"'+extraInfo+'\"><br /><br />'+extraInfo+'<div style=\"position:relative;text-align: right\"><br /><button style=\"z-index:100\" onclick=\"window.close()\">Close</button></div>';
 // alert(newWin.location.href);
	newWin.document.writeln(contents);
	
	 contents = "<DIV id=\"waiting\" style=\"z-index:2; background-color:white; position:absolute; top: 5;  border:black double 1mm; height : 100; width: 200; text-align:center;\"><span style=\"vertical-align :middle; color:maroon; text-align:center; font-family: arial; font-size:12pt; padding:3; background-color: cornsilk;\"><br /><br />Please Wait<br />Image Loading</span></DIV>"; 
	newWin.document.writeln(contents);
	
	contents = "<DIV style=\"background-color:white; position:absolute; top :5; z-index:3; width:"+imgWidth+"; height:"+imgHeight+"; color: navy; font-size: 14pt; text-align: center; opacity: 0.1; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=10);\"><br /><br />Artearoa.com <br /> <br />Artearoa.com <br /> <br /> Artearoa.com <br /> <br />Artearoa.com <br /><br />  Artearoa.com <br /><br />   Artearoa.com <br /><br /></DIV>";
	newWin.document.writeln(contents);
	
	newWin.document.close();

   newWin.document.title="Artearoa Product "+which+" View";
	 newWin.document.location.reload(false)
  newWin.focus();

	 }
	 
function getImagePreviews()
{/* Create preload of larger images - download in advance of need but don't show
   used later with image mouseover in previewLgeImg() */
  var j, imgRef;
   
 	 pageLinkContainer = document.getElementById("midPanel");
 pageLength = pageLinkContainer.childNodes.length;
 
 for (j =0; j < pageLength; j++)
			  {
				
				 if ((pageLinkContainer.childNodes[j].nodeType != 3) &&(pageLinkContainer.childNodes[j].tagName=="IMG"))
				   {
				
					  imgRef = pageLinkContainer.childNodes[j].getAttribute("src");
						if (imgRef == null){continue;}
					  imgRef = imgRef.replace('.jpg','_Lge.jpg');				
				
				
						var newImgHTML = '<img style="display:none" src=\"'+imgRef+'\">';
					
				   var  newImg = document.createElement(newImgHTML);
						pageLinkContainer.appendChild(newImg);	 
				
						}
				 }
 }
	 
function moveProduct(whichWay)
 {
 var j, here, k;
 
 	 pageLinkContainer = document.getElementById("choosePage");
 
 for (j =0; j < pageLinkContainer.childNodes.length; j++)
			  {
				 thisNode = pageLinkContainer.childNodes[j];
				  if ( thisNode.getAttribute("selected")=="true")
					  {
						 here = j;
						 break
						 }
				 }
			
				//alert(j); 
				 
	switch (whichWay)
  {
   case "back":
			if (here == 0) {k = pageLinkContainer.childNodes.length -1 ; }
        else {k = here - 1; }
	 break
   case "forward": 
			if (here == pageLinkContainer.childNodes.length -1) {k = 0; }
        else {k = here + 1; }   // 2 becasue crossbrowser childNodes includes text nodes   
   break
	 }
	// alert(k);
var thisElement = pageLinkContainer.childNodes[k];
	// alert(getInnerText(thisElement));
	 clickSomething(pageLinkContainer.childNodes[k]);
	 pageLinkContainer.childNodes[k].scrollIntoView();
 }	 	 	
 
function arrowMouse(which, src)
  {
	 which.src = 'js/'+src;
	
	 } 
 
function classOver(e)
 {
 itsMozillaLike ? thisElement = e.target : thisElement = window.event.srcElement;
 
 if ((thisElement.tagName == "SPAN") && (thisElement.getAttribute("selected") != "true"))
     {
		    window.addEventListener	 ?  thisElement.setAttribute("class", "page_links page_links_mouseover") :  thisElement.setAttribute("className", "page_links page_links_mouseover");
		   }
 
 }
 
function  classDown(e)
 {
  itsMozillaLike ? thisElement = e.target : thisElement = window.event.srcElement;
 
	if ((thisElement.tagName == "SPAN") && (thisElement.getAttribute("selected") != "true"))
     {
		 thisElement.className = "page_links page_links_mousedown"
		 
		   }
 }
 
function classOut(e)  
{
  itsMozillaLike ? thisElement = e.target : thisElement = window.event.srcElement;
	
	if ((thisElement.tagName == "SPAN") && (thisElement.getAttribute("selected") != "true"))
     {
		 thisElement.className = "page_links page_links_mouseout"
		 
		   }
 }
 
 function clicked(evt)
 {
 
 itsMozillaLike ? thisElement = evt.target : thisElement = window.event.srcElement;
 
 //alert(thisElement.tagName);
 
	if (thisElement.tagName == "SPAN")
     {
	//	 alert(thisElement.parentNode.tagName);
		 whichContainer = thisElement.parentNode;
		 
		 document.title = "Artearoa.com - " + getInnerText(thisElement);
		 
		 
      for (j =0; j < whichContainer.childNodes.length; j++)
			  {
				 if(whichContainer.childNodes[j].nodeType == 1) // cover Mozilla like behaviour
				 {
				 // specialWord is a global
				 
				 
				 
				 		if (whichContainer.childNodes[j].innerHTML.indexOf(specialWord) > -1)
						 {classList = " specialsX page_links"; // page_links_mouseout
						 //alert(whichContainer.childNodes[j].style.cssText);
						 }
						 else
						 {classList = "page_links page_links_mouseout";}
						 
			  itsMozillaLike ? 	whichContainer.childNodes[j].setAttribute("class",classList) : whichContainer.childNodes[j].setAttribute("className", classList);

         whichContainer.childNodes[j].setAttribute("selected","false");		
  
				 }
				} 

			 itsMozillaLike ? thisElement.setAttribute("class", "page_links page_links_mouseclicked")	: thisElement.setAttribute("className", "page_links page_links_mouseclicked");
thisElement.setAttribute("selected","true");

			}
 }
 
 function previewLgeImg(e)
 {
  var buildHeading = new Array();
	//var a = new String();
	
   var thisElement = getEventElement(e);
	if (thisElement.tagName == "IMG") 
     {
  imgRef = thisElement.getAttribute("src");
		 imgRef = imgRef.replace('.jpg','_Lge.jpg');
		 //alert(imgRef);
		 document.getElementById("preview").src = imgRef + getMillis();	
	 buildHeading = imgRef.split("_");
   // alert (buildHeading.length); 
		 extraTextBuild = "";
		 
		 for ( a in buildHeading)
		   {
			// alert(buildHeading[a]);
			  if ((buildHeading[a].length > 2) && (buildHeading[a].indexOf(":") == -1) && (buildHeading[a].indexOf("jpg") == -1)  )
				{
				  extraTextBuild += buildHeading[a] + " ";
				  }
				
			   }
		document.getElementById("extraText").innerHTML = extraTextBuild;
				 
		
		 }
	}
	
 
 
 function showBook(what)
 {
   //Globals
	 codetreeCode = "now_top";
   useSearchItem = false;
 get_html( what, "choosePage", null);
 }
 		 	
			
 function showPage(what)
 {
  
  get_html(what.getAttribute("pageRef"), "midPanel", null);
 }

 function clickSomething(thing)
 {
 // from http://groups.google.com/group/mozilla.dev.tech.dom/browse_thread/thread/78e15cb742b88adf
 
 if ( itsMozillaLike) 
 { 
 var evt = document.createEvent("MouseEvents"); 
 evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, 
 false, false, false, 0, null); 
 thing.dispatchEvent(evt); 
}
else // IE like ? mostly ...
{ 
  thing.click()
 }

  }

 
function getEventElement(arg)
 {
 //IE
 if(window.event){ 
       return window.event.srcElement;			 
			 }
			 else //try for Mozilla
			 {
			  return arg.target 
			  }
    
//	Mozilla
 
  } 
	
function getInnerText(o)
{
  return itsMozillaLike ? o.textContent : o.innerText;
}	

// copyright notice script   from http://www.dynamicdrive.com/forums/showthread.php?t=5090
var message= String.fromCharCode(169, 32, 174, 32, 8482)+ "\n\nPlease contact us if you wish to use any images here.\n\nAll material is Copyrighted and some material is Trademarked.\n\ncopyright_request@artearoa.com\n\n" ;

function click(e) {
if (document.all) {
if ((event.button==2||event.button==3) && event.srcElement.tagName=="IMG") 
{ alert(message); return false;}
 if (event.button==1)
     {
		   if ( (orderTrollyJs.style.display != 'none') && (inTrolly == false) )
		     {
				   closeTrolley();
			   }
				else
				 {inTrolly = false;} 
			}	 
   }
if (document.layers) {if (e.which == 3) { alert(message); return false;}}
}// --------- end function


function mouseover(e)
  {
   // document.getElementById("rightTopBox").innerHTML = getEventElement(e).getAttribute("title"); 
     // alert("Hi")
  }
 
 document.onmouseover=mouseover;
  
if (document.layers) { document.captureEvents(Event.MOUSEDOWN);}
document.onmousedown=click;
//

function addEvent(el, eType, fn, uC) { // from http://javascript.about.com/library/bldom21.htm
if (el.addEventListener) {
el.addEventListener(eType, fn, uC);
return true;
} else if (el.attachEvent) {
return el.attachEvent('on' + eType, fn);
} else {
el['on' + eType] = fn;
}
} 

function stopProp(e) { // from http://javascript.about.com/library/bldom21.htm
if (e && e.stopPropogation) e.stopPropogation();
else if (window.event && window.event.cancelBubble)
window.event.cancelBubble = true;
}

function stopDef(e) {
if (e &&e.preventDefault) e.preventDefault();
else if (window.event && window.event.returnValue)
window.eventReturnValue = false;
} 

function erasePersonal()
{
  storeNotes.set('user_Info', "");
	
	allItems = document.getElementById("personal_info").childNodes; //orderAddressArea
	 for ( x in allItems)
	      {				
				  if ( (allItems[x].name != undefined) & (allItems[x].name != "") & (allItems[x].name != "item") )
				   {

					 switch(allItems[x].tagName.toLowerCase())
			 		 {					 
				 	case 'input':
					
					  if (allItems[x].type.toLowerCase() == 'checkbox')
						    {
								allItems[x].checked = false;}
							else
							  {allItems[x].value = ""; 
								}	
					 	
						break;
						
					case 'textarea':
					  itsMozillaLike ?  allItems[x].value ="" : allItems[x].innerText ="";
					  break;			
				
					  }// switch
					} // if					 
		 	  } // for
 }
 
function savePersonal()
{ 
//alert(document.getElementById("personal_info").innerHTML);
//document.getElementById("personal_info").innerHTML

  personalInfo ={
     
		 cust_Surname: escape(document.getElementById("cust_Surname").value),
	 cust_Firstname: escape(document.getElementById("cust_Firstname").value),
 cust_account_use: escape(document.getElementById("cust_account_use").checked),
     cust_Email_1: escape(document.getElementById("cust_Email_1").value),
		 cust_Email_2: escape(document.getElementById("cust_Email_2").value),
		   cust_Phone: escape(document.getElementById("cust_Phone").value),
	 cust_Returning: escape(document.getElementById("cust_Returning").checked),	
	 	 cust_Address: escape(document.getElementById("cust_Address").value),
    cust_Comments: escape(document.getElementById("cust_Comments").value)
   }	 
	 
	 str  = JSON.stringify( personalInfo);

  storeNotes.set('user_Info', str);
	 
 } 
 
function getStoredInfo()
 {
//  alert(Persist.type);
//	  alert(Persist.size);
		
 storeNotes.get('user_Info', function(ok, val) {
      if ((ok) & (val != "") & (val != null))
       { 
			
	personalInfo = JSON.parse(val); // Global Variable:  personalInfo
	
		allItems = document.getElementById("personal_info").childNodes; //orderAddressArea		
			for ( x in allItems)
	      {				
				  if ( (allItems[x].name != undefined) & (allItems[x].name != "") & (allItems[x].name != "item") )
				   {

					 switch(allItems[x].tagName.toLowerCase())
			 		 {					 
				 	case 'input':
					
					  if (allItems[x].type.toLowerCase() == 'checkbox')
						    {
								allItems[x].checked = unescape(personalInfo[allItems[x].id])}
							else
							  {allItems[x].value = unescape(personalInfo[allItems[x].id]); 
								}	
					 	
						break;
						
					case 'textarea':
					  itsMozillaLike ?  allItems[x].value =unescape(personalInfo[allItems[x].id]) : allItems[x].innerText = unescape(personalInfo[allItems[x].id]);
					  break;			
				
					  }// switch
					} // if					 
		 	  } // for
	
	        } // if (ok)
			
    }); // function(ok	
		 
  } // function getStoredInfo()
	
//document.getElementById("personal_info").innerHTML = val ;

/*
				*/
				
function findWord()
 {
 var  getThis = document.getElementById("searchWord").value.toLowerCase();
 
 
 // Globals textSearchItem checkReplyHTML
  textSearchItem = getThis;
	checkReplyHTML = "";
	
 var  foundProducts = new Array();
  
	 for (itemX in product)
	   {
		  if ((product[itemX].description.toLowerCase().indexOf(getThis) > -1) | (product[itemX].extraInfo.toLowerCase().indexOf(getThis) > -1))
   {foundProducts.push(product[itemX].code);}
		   }
 
 thisCodeList = foundProducts.join();
 
 var buildSearch = "searchWord=" + escape(getThis) + "&bookListFile=" + escape(bookListFile) + "&requiredCodes=" +escape(thisCodeList) ;

 document.getElementById("midPanel").innerHTML = "<div style=\"height:200;\">&nbsp;</div><p class=\"searched\">Searching  for &#151;  <span style=\"color:blue;  \">" + getThis + "</span> ... </p>";

 get_html("php/searchFor.php", "doSearch", buildSearch); 
 
 // alert(foundProducts.join("\n"));
  }				
	
function syncDisplayToCode(thisCode)	
{
 /* // Global checkCodetreeParentID

 if (checkCodetreeParentID == thisCode.parentNode.id)
      {
			return;
			  }
				
	checkCodetreeParentID = thisCode.parentNode.id
	*/
thisCodeCode = thisCode.innerHTML;

// Golbal codetreeCode
codetreeCode = thisCodeCode;

 var  getThis = escape(thisCodeCode);
 
 thisCodeList = thisCodeCode;
 
 var buildSearch = "searchWord=" + escape(getThis) + "&bookListFile=" + escape(bookListFile) + "&requiredCodes=" +escape(thisCodeList) + "&codeSearch=" + escape(thisCodeCode) ;

 // document.getElementById("midPanel").innerHTML = "";

   //Global
  codeTreeHover = true;

//  alert(buildSearch);
  get_html("php/searchFor.php", "midPanel", buildSearch);
}
	
	function showContactArea()
	 {
	document.getElementById('sendMessageArea').style.display='block'; 
	showOrders(); showTab('orderAddressArea');
	document.getElementById("cust_Message_Subject").focus();
	  }
		
 function orderSendEmail()
  {
	// do any preprocessing here:
	
	    if ( checkEmailAddress() == true)
		   {
			 
			 sendOrderOff('contactMessage');
			 }
			 
	 
	 }		
	 
 function checkBrowsers(where)
  {
	 
	browserWindow =	window.open('about:blank','_blank','width=600,height=350');
  browserWindow.document.title ="Checking Browser Version";
	browserWindow.document.body.style.cssText ="font-family: avant garde, arial, helvetica, sans-serif; font-size:11pt; background-color:ivory; margin:20px;"
	browserWindow.document.body.innerHTML ="<p>Please Wait, Check Being Performed.</p>";
	
	get_html("php/nameBrowser.php", "browserCheck", null); 

		
// where.title = theseResults;
  
 
 }	 
 
 function scrollCodeIntoView()
  {		
		// document.getElementById("now_top").scrollIntoView(true	);	
	//	alert(codetreeCode); 

	var scrollItem = getScrollItem();
 
				 thisPage = document.getElementById("midPanel");

						 midAreaSpans = thisPage.getElementsByTagName("span") ;
					 for ( J = 0; J < midAreaSpans.length; J++)
					       {
								 if ( midAreaSpans[J].innerHTML.toLowerCase().indexOf(scrollItem.toLowerCase())> -1 )
								    {
										 if (scrollItem == "now_top")
										    {//  alert("Scroll Into View True");
											  midAreaSpans[J].scrollIntoView(true);
											  }
												else
												{
												// alert("Scroll Into View False");
										    midAreaSpans[J].scrollIntoView(false);
										    }
										 return;
										  }
									}
										
	 //  gotoTopMidpanel();
	}
	
	function getScrollItem()
	{
	// All globals here
	
	if (codeTreeHover == true)
	     {			 
			 codeTreeHover = false; // reset as it is a single event
			// alert('codeTreeHover: ' + codetreeCode);
			 return codetreeCode;
			 }
			 
	if  (useSearchItem == true)
	      {
				// alert('useSearchItem: ' + textSearchItem);
				return textSearchItem;
				}
			
			// remaining is default setting: -
			  
			//   alert('book click: ' + codetreeCode);
				return "now_top";
			
	
	}
	
	function gotoTopMidpanel()
	{
	 document.getElementById("now_top").style.top = 0;				
					 
	 document.getElementById("now_top").scrollIntoView(true	);
	
	}
	
	// jQuery added index.html 13th November 2010 Paul
	
	jQuery(document).ready(function() {
	 // alert('Hi jQuery Loaded');
	 // SEE ALSO function init() AT TOP OF THIS FILE
	 
         jQuery("#searchWord").keyup(function(event){
				           if(event.keyCode == 13){ // if user expects Enter key to launch searh it will now.
            jQuery("#searchWordButton").click();
                          }
  					  }); // END ("#searchWord").keyup
							
}); // jQuery(document).ready
	
	
