var ListOfFinishes;
var xFinishes;
var currFinish = 0;

function createXML(xmlTEXT)
{
var text = xmlTEXT;

// code for IE
if (window.ActiveXObject)
  {
  ListOfFinishes=new ActiveXObject("Microsoft.XMLDOM");
  ListOfFinishes.async="false";
  ListOfFinishes.loadXML(text);
  }
// code for Mozilla, Firefox, Opera, etc.
else
  {
  var parser=new DOMParser();
  ListOfFinishes=parser.parseFromString(text,"text/xml");
  }
}

function HideAjaxSection() {
	document.getElementById('ajaxPanel').className = 'ajaxOff';
}

function ShowAjaxSection() {
	document.getElementById('ajaxPanel').className = 'ajaxOn';
}

function HideInformationSection() {
	document.getElementById('txtInformation').className = 'ajaxOff';
}

function ShowRoom(rm_name)	{
	HideAjaxSection();
	var callback = {
		success: function(o) {
			document.getElementById('typeOfFinishes').innerHTML = o.responseText;
			var firstTypeOfFinish = document.getElementById('typeOfFinishes').getElementsByTagName('a');	
			if (firstTypeOfFinish.length > 0)
			{
				firstTypeOfFinish[0].onclick();
			}
		}
	}
	var connectionObject = YAHOO.util.Connect.asyncRequest('GET', 'GetTypeOfFinishesByName.aspx?rm_name=' + rm_name, callback);	
}

function ShowFinishes(rm_name, tofs_id)	{
	HideInformationSection();
	var linkElements = document.getElementById('typeOfFinishes').getElementsByTagName('a');	
	for(var i=0; i<linkElements.length; i++) {
		linkElements[i].className = '';
	}
	var callback = {
		success: function(o) {
			createXML(o.responseText);
			var x = ListOfFinishes.documentElement;
			xFinishes = x.getElementsByTagName('finish');
			DisplayFinish(0);
			ShowAjaxSection();
		}
	}
	var connectionObject = YAHOO.util.Connect.asyncRequest('GET', 'GetListOfFinishesByName.aspx?rm_name=' + rm_name + '&tofs_id=' + tofs_id, callback);	
}

function DisplayFinish(Fx) {
if (xFinishes.length == 0) {
	//no data - clear winodow//
	document.getElementById('btnPrev').className = "off";
	document.getElementById('btnNext').className = "off";
}
else {
/* button section */
	document.getElementById('btnPrev').className = "";
	document.getElementById('btnNext').className = "";
	if (Fx == (xFinishes.length - 1)) {
		document.getElementById('btnNext').className = "off";
	}
	
	if (Fx == 0) {
		document.getElementById('btnPrev').className = "off";
	}
	if (Fx < xFinishes.length){
		for (j=0; j<xFinishes[Fx].childNodes.length; j++)
		{
			if (xFinishes[Fx].childNodes[j].nodeName != 'img') {
				if (xFinishes[Fx].childNodes[j].childNodes.length == 0)	{
					document.getElementById(xFinishes[Fx].childNodes[j].nodeName).innerHTML = 'N/a';
				}
				else {
					document.getElementById(xFinishes[Fx].childNodes[j].nodeName).innerHTML = xFinishes[Fx].childNodes[j].firstChild.nodeValue;
				}
			}
			else {
				document.getElementById('finishImage').src = xFinishes[Fx].childNodes[j].firstChild.nodeValue;
			}
		}
	}
	else
	{
		document.getElementById('btnPrev').className = "off";
		document.getElementById('btnNext').className = "off";
	}
	currFinish = Fx;
}
}

function DisplayFinishPrev() {
	DisplayFinish(currFinish - 1);
}
function DisplayFinishNext() {
	DisplayFinish(currFinish + 1);
}

