function IeSearchEngine(xmlFile, xsltFile){
	// not code for Mozilla, Firefox, Opera, etc.
	if (document.implementation && document.implementation.createDocument)
	  return;
	if (!window.ActiveXObject)
	  return;

	this.xslt = new ActiveXObject("Msxml2.XSLTemplate");
	this.xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	this.xslProc;
	this.xslDoc.async = false;
	this.xslDoc.resolveExternals = false;
	this.xslDoc.load(xsltFile);
	this.xslt.stylesheet = this.xslDoc;
	this.xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	this.xmlDoc.async = false;
	this.xmlDoc.resolveExternals = false;
	this.xmlDoc.load(xmlFile);
	this.xslProc = this.xslt.createProcessor();
	this.xslProc.input = this.xmlDoc;
}

IeSearchEngine.prototype.displayResults = function (){
	var currencySelected = document.forms[0].currency.options[document.forms[0].currency.selectedIndex].value
	var languageSelected = document.forms[0].language.options[document.forms[0].language.selectedIndex].value

	this.xslProc.addParameter("languageSelected", languageSelected);
	this.xslProc.addParameter("currencySelected", currencySelected);

	this.xslProc.transform();
	var str;
	str = this.xslProc.output;
	document.getElementById("divId").innerHTML=str;
}

function SearchEngine(xmlFile, xsltFile){
	// code for Mozilla, Firefox, Opera, etc.
	if (!(document.implementation && document.implementation.createDocument))
	  return;

	this.xmlLoaded = false;
	this.xslLoaded = false;
	this.xmlFile = xmlFile;
	this.xsltFile = xsltFile;
	this.objXMLSerializer = new XMLSerializer;
	this.xProcessor = new XSLTProcessor();
	this.data = document.implementation.createDocument("", "", null);
	this.transformer = document.implementation.createDocument("", "", null);
	this.data.addEventListener("load", xml_onload, false);
	this.transformer.addEventListener("load", xslt_onload, false);
	this.transformer.xp = this.xProcessor;


	// functions for Mozilla, Firefox, Opera
	function xml_onload(){
		searchEngine.xmlLoaded = true;
		searchEngine.displayResults();
	}
	function xslt_onload(){
		this.xp.importStylesheet(this);
		searchEngine.xslLoaded = true;
	}

	// attempt to load the data - Mozilla, Firefox, Opera
	try {
		this.transformer.load(this.xsltFile);
		this.data.load(this.xmlFile);
	} 
	catch (exception) {
		// for Safari

		// the xsl first
		this.xslDoc = new XMLHttpRequest();
		this.xslDoc.onreadystatechange = processXslReqChange
		this.xslDoc.open("GET", this.xsltFile, true);
		this.xslDoc.send("");

		// then the xml
		this.xmlDoc = new XMLHttpRequest();
		this.xmlDoc.onreadystatechange = processXmlReqChange
		this.xmlDoc.open("GET", this.xmlFile, true);
		this.xmlDoc.send("");
	}

	// functions for safari
	function processXmlReqChange() {
		// only if xmlDoc shows "loaded"
		if (this.readyState == 4) {
			// only if status is "OK"
			response = this.responseXML;
			searchEngine.data = response;
			searchEngine.xmlLoaded = true;
			// ready to show the results
			searchEngine.displayResults();
		}
	}

	function processXslReqChange() {
		// only if xslDoc shows "loaded"
		if (this.readyState == 4) {
			// only if status is "OK"
			response = this.responseXML; //.documentElement;
			searchEngine.transformer.xp.importStylesheet(response);
			searchEngine.xslLoaded = true;
		}
	}
}

SearchEngine.prototype.displayResults = function (){

	var currencySelected = document.forms[0].currency.options[document.forms[0].currency.selectedIndex].value
	var languageSelected = document.forms[0].language.options[document.forms[0].language.selectedIndex].value

	this.xProcessor.setParameter(null, "languageSelected", languageSelected);
	this.xProcessor.setParameter(null, "currencySelected", currencySelected);
	var resultDoc = this.xProcessor.transformToDocument(this.data);
	var strResult = this.objXMLSerializer.serializeToString(resultDoc);
	this.writeLayer("divId", strResult);
}

SearchEngine.prototype.writeLayer = function(ID, sText){
	if (document.layers) {
		var oLayer = document.layers[ID].document;
		oLayer.open();
		oLayer.write(sText);
		oLayer.close();
	}
	else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
		document.getElementById(ID).innerHTML = sText;
	}
		else if (document.all) document.all[ID].innerHTML = sText
}

// code for Mozilla, Firefox, Opera, etc.
var searchEngine = new SearchEngine("payPalButtons.xml", "payPalButtons.xsl");
// for IE
var ieSearchEngine = new IeSearchEngine("payPalButtons.xml", "payPalButtons.xsl");

function displayOnLoad() {
	// code for IE only
	if (window.ActiveXObject) {
		ieSearchEngine.displayResults();
	}
}

function displayShopping() {
	// code for IE
	if (window.ActiveXObject) {
		ieSearchEngine.displayResults();
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		searchEngine.displayResults();
	}
}
