//write a mail-link

function writeMailLink(mailName,mailDomain,appendage,otherStrings)
{
	var eMailAddress = mailName + "@" + mailDomain + "." + appendage;
	var mailtoString = "mailto:" + eMailAddress;
	
	if ((otherStrings != "") && (otherStrings != null))
	{
		mailtoString += "?" + otherStrings;
	}
	
	document.write("<a class='mailWebLink' href='" + mailtoString + "'>" + eMailAddress + "</a>");
}

//open new window woth only the window frame

function openBigScreenshot(scrnName)
{
	window.open("Popups/" + scrnName,"_blank","maximized=1,resizable=1,scrollbars=1,location='0,menubar=0,status=0,toolbar=0");
}

//set status texts

function setStatusText(statusText)
{
	status = " .:: " + statusText;
	return true;
}

function setImageMapStatusText(statusText)
{
	sText = " .:: " + statusText;
	setTimeout("self.status=sText;",0);
	return true;
}

//get and write prices from an xml to the price lists

function loadXmlFile(currencyList)
{
	
	if (document.implementation.createDocument)
	{
		var xmlDocument = document.implementation.createDocument("", "", null);
		xmlDocument.onload = function () {setPrice(currencyList, xmlDocument)}
	}
	else if(window.ActiveXObject)
	{
		var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
		xmlDocument.onreadystatechange = function () 
		{
			if (xmlDocument.readyState == 4){
				setPrice(currencyList, xmlDocument);
			}
		};
	}
	
	var currency = currencyList.options[currencyList.selectedIndex].text;
	xmlDocument.load("Uploads/XML/" + xmlFileName + "_" + currency.toUpperCase() + ".xml");
	
	return xmlDocument;
}

/*
function generateCurrencyDdl(ddlName)
{
	alert('hallo');
	var currencyXml = loadXmlFile("currencies");
	var currencies = currencyXml.getElementsByTagName("Currencies");
	
	//alert("currencies: " + currencies[0].childNodes.length);
	
	for (i = 0; i < currencies[0].childNodes.length; i++)
	{
		newEntry = new Option(currencies[0].childNodes[i].getAttribute('name'),currencyXml[i].getAttribute("factor"),false,false);
				
		var ddList = document.getElementsByName(ddlName)[0];
		
		alert("ddl: " + ddList);
		
		ddList.options[ddList.length] = newEntry;
	}
}
*/

function setPrice(currencyList, priceXml)
{
	var currencyFactor = currencyList.options[currencyList.selectedIndex].value;
	var prices = priceXml.getElementsByTagName("Prices");
	
	var browser = window.navigator.appName;

	if( browser != "Microsoft Internet Explorer")
	{
		 var elementnames=   evaluateXPath(priceXml,"//PriceInfo//Prices//Price/@name");
		if(elementnames != null)
		{
			for(var i in elementnames)
			{		
			var elementPrices = evaluateXPath(priceXml, "//PriceInfo//Prices//Price/@value");
			if(document.getElementById(elementnames[i].nodeValue))
			{
			document.getElementById(elementnames[i].nodeValue).innerHTML = elementPrices[i].nodeValue;
			}
			}
			
		}
	}
	else
	{
	
	if (prices[0].firstChild.nodeName == "Price")
	{
		for (i = 0; i < prices[0].childNodes.length; i++)
		{
			var elementName = prices[0].childNodes[i].getAttribute("name");
		
			if (document.getElementById(elementName))
			{
				document.getElementById(elementName).innerText  = prices[0].childNodes[i].getAttribute("value") + ".00";
			}	
		}
	}
	else
	{
		for (i = 0; i < prices[0].childNodes.length; i++)
		{
			for (j = 0; j < prices[0].childNodes[i].childNodes.length; j++)
			{
				var elementName = prices[0].childNodes[i].childNodes[j].getAttribute("name");
			
				if (document.getElementById(elementName))
				{					
					var price = prices[0].childNodes[i].childNodes[j].getAttribute("value");
					if (price.indexOf(".") == -1)
					{
						document.getElementById(elementName).innerText  = price + ".00";
					}
					else
					{
						document.getElementById(elementName).innerText  = price;
					}
				}	
			}
		}
	}
	}
	setPriceList(currencyList, priceXml);
}

function setPriceList(currencyList, priceXml){
	
	var currencyFactor = currencyList.options[currencyList.selectedIndex].text;
	
	var lnk0 = document.getElementById("lnkPriceList0");
	var lnk1 = document.getElementById("lnkPriceList1");
	var lnk2 = document.getElementById("lnkPriceList2");
	var lnk3 = document.getElementById("lnkPriceList3");
	if( (lnk0 != null) || (lnk1 != null) || (lnk2 != null) || (lnk3 != null) )
	{ 
		var browser = window.navigator.appName;

		if( browser != "Microsoft Internet Explorer")
		{
		 var oldhref=   evaluateXPath(priceXml,"//PriceInfo//PriceLists//" + lang.toUpperCase() + "//PriceList/@file");
		var href = "Uploads/PDF/" + oldhref[0].nodeValue;
		}
		else
		{
		var xmlNode = priceXml.selectSingleNode("//PriceInfo//PriceLists//" + lang.toUpperCase() + "//PriceList");
		var href = "Uploads/PDF/" + xmlNode.getAttribute("file");
		}
		
		lnk0.href = href;
		lnk1.href = href;
		lnk2.href = href;
		lnk3.href = href;
	}
}

// Evaluate an XPath expression aExpression against a given DOM node
// or Document object (aNode), returning the results as an array
// thanks wanderingstan at morethanwarm dot mail dot com for the
// initial work.
function evaluateXPath(aNode, aExpr) {
  var xpe = new XPathEvaluator();
  var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ?
    aNode.documentElement : aNode.ownerDocument.documentElement);
  var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null);
  var found = [];
  var res;
  while (res = result.iterateNext())
    found.push(res);
  return found;
}



function refreshPrices(currencyList)
{
	var currencyFactor = currencyList.options[currencyList.selectedIndex].text;
	 loadXmlFile(currencyList);
}