var HotelInfoUpdater = Class.create();

HotelInfoUpdater.prototype = {
  
  initialize: function() {
  },
  
  ajaxUpdate: function(ajaxResponse) {
    this.setActionStats(ajaxResponse.getElementsByTagName("HotelInfo"), 
			ajaxResponse.getAttribute("lang"), ajaxResponse.getAttribute("userid"), ajaxResponse.getAttribute("custid"));
  },
	
  setActionStats: function(aStats, lang, userid, custid) {
    var hotelid = "";
    var name = "";
    var addr1 = "";
    var zip = "";
    var city = "";
    var country = "";
    var email = "";
    var urlhotel = "";
    var phone1 = "";
    var classifval = "";
    var photo = ""; 
    var desc="";
    var url = "";
    
    hotelid = aStats[0].getAttribute("hotelid");
    if (hotelid > 0) {
	if (userid.length > 0) {
	  url = "/reservit/fiche_htl.php?userid="+userid+"&hotelid="+hotelid;
	} else {
	  url = "/reservit/reserhotel.php?lang="+lang+"&action=fiche_htl&hotelid="+hotelid;
	}
    }

    if (aStats[0].getElementsByTagName("name").length > 0) {
      name = aStats[0].getElementsByTagName("name").item(0).firstChild.nodeValue;
    }
    
    if (aStats[0].getElementsByTagName("addr1").length > 0) {
      addr1 = aStats[0].getElementsByTagName("addr1").item(0).firstChild.nodeValue;
    }

    if (aStats[0].getElementsByTagName("zip").length > 0) {
      zip = aStats[0].getElementsByTagName("zip").item(0).firstChild.nodeValue;
    }
    if (aStats[0].getElementsByTagName("city").length > 0) {
      city = aStats[0].getElementsByTagName("city").item(0).firstChild.nodeValue;
    }
    if (aStats[0].getElementsByTagName("country").length > 0) {
      country = aStats[0].getElementsByTagName("country").item(0).firstChild.nodeValue;
    }
    if (aStats[0].getElementsByTagName("email").length > 0) {
      email = aStats[0].getElementsByTagName("email").item(0).firstChild.nodeValue;
    }
    if (aStats[0].getElementsByTagName("urlhotel").length > 0) {
      urlhotel = aStats[0].getElementsByTagName("urlhotel").item(0).firstChild.nodeValue;
    }
    if (aStats[0].getElementsByTagName("phone1").length > 0) {
    }
    if (aStats[0].getElementsByTagName("description").length > 0) {
      desc = aStats[0].getElementsByTagName("description").item(0).firstChild.nodeValue.substr(0,250);
    }

    classifval = "";
    if (aStats[0].getElementsByTagName("classificationhotel").length > 0 && 
	aStats[0].getElementsByTagName("classificationhotel").item(0).childNodes.length > 0)
      {
	if (is_ie && 
	    aStats[0].getElementsByTagName("classificationhotel").item(0).childNodes.item(0).childNodes.length > 0)
	  {
	    for (idx=0; idx<aStats[0].getElementsByTagName("classificationhotel").item(0).childNodes.item(0).childNodes.item(0).nodeValue; idx++)
	      {
		if (custid == 121)
		  {
		    classifval += " *";
		  }
		else
		  {
		    classifval += "<img src='/general/images/customer/"+custid+"/star.gif'/>";
		  }
	      }
	  }
	else if (!is_ie && 
		 aStats[0].getElementsByTagName("classificationhotel").item(0).getAttribute("Code") == "1" &&
		 aStats[0].getElementsByTagName("classificationhotel").item(0).childNodes.item(1).childNodes.length > 0)
	  {
	    for (idx=0; idx<aStats[0].getElementsByTagName("classificationhotel").item(0).childNodes.item(1).childNodes.item(0).nodeValue; idx++)
	      {
		if (custid == 121)
		  {
		    classifval += " *";
		  }
		else
		  {
		    classifval += "<img src='/general/images/customer/"+custid+"/star.gif'/>";
		  }
	      }
	  }
      }


    if (aStats[0].getElementsByTagName("photo").length > 0 && 
	aStats[0].getElementsByTagName("photo").item(0).childNodes.length > 0)
      {
	if (is_ie && 
	    aStats[0].getElementsByTagName("photo").item(0).childNodes.item(0).childNodes.length > 0)
	  {
	    if (aStats[0].getElementsByTagName("photo").item(0).childNodes.item(0).childNodes.item(1))
	      {
		photo = "<img src='"+aStats[0].getElementsByTagName("photo").item(0).childNodes.item(0).childNodes.item(1).firstChild.nodeValue+"' width='130'/>";
	      }
	    else if (aStats[0].getElementsByTagName("photo").item(0).childNodes.item(0).childNodes.item(0))
	      {
		photo = "<img src='"+aStats[0].getElementsByTagName("photo").item(0).childNodes.item(0).childNodes.item(0).firstChild.nodeValue+"' width='130'/>";
	      }
	  }
	else if (!is_ie && 
		 aStats[0].getElementsByTagName("photo").item(0).childNodes.item(1).childNodes.length >= 4)
	  {
	    photo = "<img src='"+aStats[0].getElementsByTagName("photo").item(0).childNodes.item(1).childNodes.item(3).firstChild.nodeValue+"' width='130'/>";
	  }
	else if (!is_ie && 
		 aStats[0].getElementsByTagName("photo").item(0).childNodes.item(1).childNodes.length == 3)
	  {
	    photo = "<img src='"+aStats[0].getElementsByTagName("photo").item(0).childNodes.item(1).childNodes.item(1).firstChild.nodeValue+"' width='130'/>";
	  }
      }

    var strStatus = "";
    var strStatus = "";
    if (name != "")
      {
	if (url!="") strStatus += this.constructHeader("<span><a href='"+url+"' target='_parent'>"+name+"</a></span>");
	else strStatus += this.constructHeader("<span>"+name+"</span>");
      }

    var str = "<table><tr>";
    if (photo != "") str += this.constructHeader("  <td id='photo1'>"+photo+"</td>");
    str += "  <td id='infos'>";
    if (classifval != "") str += this.constructHeader("<div id='star'>"+classifval+"</div>");
    if (addr1 != "") str += this.constructHeader("<div id='addr'>"+addr1+"</div>");
    if (zip != "") str += this.constructHeader("<div id='zip'>"+zip+"</div>");
    if (city != "") str += this.constructHeader("<div id='city'>"+city+"</div>");
    if (desc != "") str += this.constructHeader("<div id='desc'>"+desc+"...</div>");
    if (hotelid != "" && url!="") str += this.constructHeader("  <div id='more'><a href='"+url+"' target='_parent'>"+msg[1]+"</a></div>");
    str += "  </td></tr>";
    str += "  </table>";

    var element = document.getElementById("selecthtl"); if (element) element.innerHTML = str;
    var element1 = document.getElementById("status"); if (element1) element1.innerHTML = strStatus;
  },

  constructHeader: function (txt) {
    text = txt;
    return text;
  }
}

hotelInfo = new HotelInfoUpdater();
ajaxEngine.registerRequest( 'displayHotelInfo', '/scripts/recupHotelInfo.php' );
ajaxEngine.registerAjaxObject( 'hotelInfo', new HotelInfoUpdater() );
