var CALL = "Ask";
var Prices = null;

function LoadPrices() {
  if (Prices == null) Prices = new PricesData();
}

function PricesData() {
   this.data = null;
   return importXML( "/orders/prices.xml", "xmlLoaded", false, 2000 );    
}

function xmlLoaded( xml ) {  
  Prices.data = xml; 
  return false;
 }

// XML processing
PricesData.prototype.getPrice = function ( product, edition, ralic, curr ) {
  var node = null;
  curr = curr.toUpperCase();
 
  try {
  if (this.data) {  
    node = this.data.documentElement.firstChild;
    while( node && (node.nodeType == 3)) node = node.nextSibling;
    while( node ){
	  if ((node.nodeType != 3) && (node.getAttribute( "id" ) == product)) { // found product
	     node = node.firstChild;
    	 while( node ){
           if ((node.nodeType != 3) &&
 			   (node.nodeName.toUpperCase() == "EDITION") &&
		   	   (node.getAttribute( "id" ) == edition) &&
			   ((ralic == "") || (node.getAttribute( "raLicence" ) == ralic))
			   ) {
			 node = node.firstChild;
			 while( node ){
               if ((node.nodeType != 3) &&
 		   	       (node.nodeName.toUpperCase() == curr)) {
				  return node.firstChild.nodeValue + " " + curr;
				}
     	       node = node.nextSibling;
			 }
			 return CALL
		   }
   	       node = node.nextSibling;
		 }
		 return CALL;
	  }
	  node = node.nextSibling;
	};
  }
  } catch (excption) {	  
  }
  return CALL;
}


// XML processing
PricesData.prototype.getPromo = function ( product, edition ) {
  var node = null;

 
  try {
  if (this.data) {  
    node = this.data.documentElement.firstChild;
    while( node && (node.nodeType == 3)) node = node.nextSibling;
    while( node ){
	  if ((node.nodeType != 3) && (node.getAttribute( "id" ) == product)) { // found product
	     node = node.firstChild;
    	 while( node ){
           if ((node.nodeType != 3) &&
 			   (node.nodeName.toUpperCase() == "PROMOTION") &&				
		   	   (node.getAttribute( "id" ) == edition)
			   ) {
			 return node.firstChild.nodeValue;
		   }
   	       node = node.nextSibling;
		 }
		 return "";
	  }
	  node = node.nextSibling;
	};
  }
  } catch (excption) {	  
  }
  return "";
}
