// JavaScript Document
var address;
function ref(url,param,handler)
{
	address=url;
position=(url.indexOf('='));
newHash=(url.substring(position+1,url.length));

if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
	if (!handler){
		
	 xmlhttp.onreadystatechange=xmlhttpChange;
	}



  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  
  }
// code for IE
else if (window.ActiveXObject)
  {
	  
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
    
	if (xmlhttp)
    {
	
if (!handler){
	 xmlhttp.onreadystatechange=xmlhttpChange;
	}
	if(handler=='gallery'){
	xmlhttp.onreadystatechange=function mozgallery(){
	 if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {

	var txt=xmlhttp.responseXML;

	product=txt.getElementsByTagName('name')[0].firstChild.nodeValue;
	description=txt.getElementsByTagName('description')[0].firstChild.nodeValue;
	cat=txt.getElementsByTagName('cat')[0].firstChild.nodeValue;
	subcat=txt.getElementsByTagName('sub')[0].firstChild.nodeValue;
	full=txt.getElementsByTagName('full')[0].firstChild.nodeValue;
	
	price=parseInt(txt.getElementsByTagName('price')[0].firstChild.nodeValue);
	image=document.getElementById('img');

	image.src="images/gallery/"+full;
	
	document.getElementById('namenode').innerHTML=product;
	
	document.getElementById('description').innerHTML=description+"<hr noshade='noshade'>"+subcat+"&ndash;$" + price.toPrecision(2);
	
	ref('scroll.php','scroll');

}
	}
}
}
		
	   if(handler=='login'){
	xmlhttp.onreadystatechange=function iehandler(){ 	// if xmlhttp shows "loaded"

if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
	
	var txt=xmlhttp.responseText
	
var txt=xmlhttp.responseXML.documentElement;
	valid=txt.firstChild.firstChild.nodeValue;
	name=txt.lastChild.firstChild.nodeValue
	formdiv=document.getElementById(logform)
	
	
if (valid=="true"){formdiv.innerHTML="<strong>"+name+" logged in</strong>";}
		
	
		
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
	}
	
	
	}
if(handler=='gallery'){ 
xmlhttp.onreadystatechange=function iegallery(){
	 if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {

	var txt=xmlhttp.responseXML;

	product=txt.getElementsByTagName('name')[0].firstChild.nodeValue;
	desc=txt.getElementsByTagName('description')[0].firstChild.nodeValue;
	cat=txt.getElementsByTagName('cat')[0].firstChild.nodeValue;
	subcat=txt.getElementsByTagName('sub')[0].firstChild.nodeValue;
	full=txt.getElementsByTagName('full')[0].firstChild.nodeValue;
	
	price=parseInt(txt.getElementsByTagName('price')[0].firstChild.nodeValue);
	image=document.getElementById('img');

	image.src="images/gallery/"+full;
	
	document.getElementById('namenode').innerHTML=product;
	
	document.getElementById('description').innerHTML=desc+"<hr noshade='noshade'>"+subcat+"&ndash;$" + price.toPrecision(2);
	
	ref('scroll.php','scroll');
}

	}}
}

if(handler=='scroll'){
	
	xmlhttp.onreadystatechange=function iescroller(){
	if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {

	var txt=xmlhttp.responseText;
document.getElementById('scrolllay').innerHTML=txt;
if(document.getElementById('scroller').offsetWidth>300){
document.getElementById('lft').style.visibility="visible";
		document.getElementById('rght').style.visibility="visible";
}
}
	}
}
}
	xmlhttp.open("GET",url,true)
   	xmlhttp.send()
    }
  }
}

function xmlhttpChange()
{
	// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {

	var txt=xmlhttp.responseText;
	document.getElementById('contentLay').scrollTop=0;
	document.getElementById('contentLay').innerHTML=txt;
	makeHistory(newHash);
_uacct = "UA-640798-2";
urchinTracker(address);
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
else if(xmlhttp.readyState<4){
	document.getElementById('contentLay').innerHTML="<em>Loading...</em>";
	}
}
function handleHistory()
{
	
  if ( window.location.hash != "#"+newHash )
  {
	  
		  
    newHash = window.location.hash;
    ref('template.php?id='+newHash.replace("#",""));
	  
  }
  return true;
}
function pollHash() {
  handleHistory();
  window.setInterval("handleHistory()", 1000);
  return true;
}
function makeHistory(newHash)
{
  
  if (window.location.hash==NaN){
  newHash=1;}
  window.location.hash = newHash;
}