var xml, xsl;

//function init(xmlFile, xslFile, eleID){
//	xml = loadDocument(xmlFile);
//	xsl = loadDocument(xslFile);
//	doTransform(eleID);
//}

function init(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}		
	doTransform(eleID);
}

var pageName;
function getSingle(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}	
	//alert(singleID + "single" + pageName + "pageName"); 	
	doTransform(eleID);
	window.scroll(0,0);
}

function getvendor(xmlFile, xslFile, eleID, singleID){
	//alert(document.getElementById(eleID).textContent);
	if(document.getElementById(eleID).innerHTML != ''){
		//empty
		document.getElementById(eleID).innerHTML = '';
	}else{
			init('vendor.xml', 'state.xsl', 'main_area', 'allstates');
			xml = loadDocument(xmlFile);
			xsl = loadDocument(xslFile);
			// update the param here 
			for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
				if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
					xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
				}
			}	
//alert(singleID + "**single**" + eleID + "eleID"); 
		doTransform(eleID);
	}
	//window.scroll(0,0);
}
function getvendorOrig(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here -->
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}	
// alert(singleID + "**single**" + eleID + "eleID"); 
	doTransform(eleID);
	window.scroll(0,0);
}


function getPage(){
	return pageName;
}
function loadDocument(fileName){
//load xml file
// code for IE
if (window.ActiveXObject){
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(fileName);
	return xmlDoc;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
	 // *** Mozilla
	//*jn var xsltProcessor = new XSLTProcessor();
	// *** load the XSL file
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", fileName, false);
	myXMLHTTPRequest.send(null);
	// *** get the XML document
	//*jn xslStylesheet = myXMLHTTPRequest.responseXML;
	//*jn xsltProcessor.importStylesheet(xslStylesheet);
	return myXMLHTTPRequest.responseXML;
}else{
	alert('Your browser cannot handle this script');
}
}
function doTransform(myID){
	if (window.ActiveXObject){
	// alert('Your inside the proper area');
	document.getElementById(myID).innerHTML = xml.transformNode(xsl);
	}else{
	// alert('inside FF Transform');
	var xsltProcessor = new XSLTProcessor();
	xsltProcessor.importStylesheet(xsl);
	var resultDocument = xsltProcessor.transformToFragment(xml, document);
	
	// create an empty element node
	// without an ID, any attributes, or any content
	var sp1 = document.createElement("div");
	sp1.setAttribute("id", myID);
	// build a reference to the existing node to be replaced
	var sp2 = document.getElementById(myID);
	var parentDiv = sp2.parentNode;
	// replace existing node sp2 with the new span element sp1
	parentDiv.replaceChild(sp1, sp2);
	document.getElementById(myID).appendChild(resultDocument);
	}
}

function getmessage(){
alert('Your inside the wrong area');
document.getElementById("to").innerHTML=xmlDoc;
}

function showPic (whichID, whichpic) {
  if (!document.getElementById) return true;
  document.getElementById(whichID).getElementsByTagName("img")[0].src = whichpic;
  //return false;	
  styleObj=document.getElementById(whichID).style;
  if (styleObj.display=='none') {
  window.scroll(0,0);
	styleObj.display='';
	}else {
		styleObj.display='none';
	}	
	
}

function hidePic (whichID) {
	styleObj=document.getElementById(whichID).style;
	styleObj.display='none';
	document.getElementById(whichID).getElementsByTagName("img")[0].src = "images/alpha.png";
}


