/* JavaScript Library for Colonial Chair Company*/
/* Image and Description loading for Chair Gallery and Class Photos*/


function loadXML(xmlfile)
{
//load xml file
// code for IE

if (window.ActiveXObject)
{
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(xmlfile);
	displayChair("01");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
	xmlDoc=document.implementation.createDocument("","",null);
	xmlDoc.async=false;
	xmlDoc.load(xmlfile);
	displayChair("01");
}
else
{
	alert('Your browser cannot handle this script');
}
}

function loadXMLDoc(url)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp!=null)
  {
  xmlHttp.onreadystatechange=state_Change;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
  else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function GetXmlHttpObject()
{
var xmlHttp=null;

try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
  }
return xmlHttp;
}

function state_Change()
{
	
// if xmlhttp shows "loaded"
if (xmlHttp.readyState==4)
  {
	xmlDoc=xmlHttp.responseXML.documentElement;
	displayChair("01");
    return true;
  // if "OK"
  if (xmlHttp.status==0)
    {
    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}


/*format lines of descriptions strip out null and add line break */
function fmt(dstring)
{
	if (dstring=="x")
	{
	   dstring="";
	}
	else
	{
		dstring = dstring + "<br />";
	}
return(dstring);
}

function displayChair(chairID)
{
	chairID=location.search + "";
	i=Number(chairID.substr(chairID.length-2,2))-1;
	document.title = "Colonial Chair: " + xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;	
	
	

	descr1=fmt(xmlDoc.getElementsByTagName("descript1")[i].childNodes[0].nodeValue);
	descr2=fmt(xmlDoc.getElementsByTagName("descript2")[i].childNodes[0].nodeValue);
	descr3=fmt(xmlDoc.getElementsByTagName("descript3")[i].childNodes[0].nodeValue);
	descr4=fmt(xmlDoc.getElementsByTagName("descript4")[i].childNodes[0].nodeValue);
	descr5=fmt(xmlDoc.getElementsByTagName("descript5")[i].childNodes[0].nodeValue);
	price=fmt(xmlDoc.getElementsByTagName("price")[i].childNodes[0].nodeValue);	

	document.getElementById("chairinfo").innerHTML = descr1 + descr2 + descr3 + descr4 + descr5 + price;	
document.getElementById('chairname').innerHTML=xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;
	document.getElementById('chairimg').src = xmlDoc.getElementsByTagName("fileloc")[i].childNodes[0].nodeValue;
	document.getElementById('chairimg').title=xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;
	document.getElementById('chairimg').alt=xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;
	document.getElementById('title').innerHTML=xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;

}



