//	********************************************************************************************************
//		CAreaListHandler.js
//	********************************************************************************************************
//
//		CREATED FROM:	Robert Stiehler (idaSys)
//		CREATED AT:	03.06.2008
//		
//		UPDATES:
//
//	--------------------------------------------------------------------------------------------------------
//
//	JavaScript arealist handler
//
//	-Class provides methode to set month in table header (setMonth)
//	-Class provides methode to add a country to the table
//	-Class provides methode to add regions to the table
//		if a region should be a part of a country (normaly way to handle regions) it have to be added after
//		adding a coruntry (example: obj.addCountry("TST"); obj.addRegion("TST", "1", "XYZ"); obj.addRegion("TST", "2", "ASD"); etc.
//	-Class provides some dynamicle stuff for colapsing a country etc.
//		-expand/colapse country: obj.expandCountry("TST");
//	********************************************************************************************************

//class CAreaListHandler
//{
//public:
	function CAreaListHandler()
	{		
		//public methods
		this.initMatrix = declared_initMatrix;
		this.setMonath = declared_setMonath;
		this.expandCountry = declared_expandCountry;
		this.setOffer = declared_setOffer;
		this.addCountry = declared_addCountry;
		this.addTopTipCountry = declared_addTopTipCountry;
		this.addRegion = declared_addRegion;
		this.setNoOffers = declared_setNoOffers;
		this.setMinPriceOffer = declared_setMinPriceOffer;
		this.setDynamicChange = declared_setDynamicChange;
		
		//private methodes
		this.isInternetExplorer = declared_isInternetExplorer;
		this.Country_td_price = declared_Country_td_price;
		this.Country_td_space = declared_Country_td_space;
		this.Region_td_space = declared_Region_td_space;
		this.Region_td_price = declared_Region_td_price;
		this.setMoreOfferLine = declared_setMoreOfferLine;
		
		//private attributes
		this.objAreaListNoOffer = new CAreaListNoOffer();
		this.log = xajax_logStringToFile;
	}
	
//public:
	function declared_initMatrix()
	{
		try
		{	
			if(this.isInternetExplorer())
			{
				while(document.getElementById("eingabe").firstChild)
				{
					var nodeTOdel = document.getElementById("eingabe").firstChild;
					document.getElementById("eingabe").removeChild(nodeTOdel);
				}
			}
			else
			{
				var tmp = "";
				tmp += '<thead>';
				tmp += '<tr>';
				tmp += '	<th colspan="2">';
				tmp += '		<span style="visibility:hidden;">Länder</span>';
				tmp += '		<select style="visibility:hidden;" name="land">';
				tmp += '			<option>alle L&auml;nder</option>';
				tmp += '			<option>Landx</option>';
				tmp += '		</select>';
				tmp += '	</th>';
				tmp += '	<th class="r2_stat_headline" id="monath1" width="104px">&nbsp;</th>';
				tmp += '	<th></th>';
				tmp += '	<th class="r2_stat_headline" id="monath2" width="104px">&nbsp;</th>';
				tmp += '	<th></th>';
				tmp += '	<th class="r2_stat_headline" id="monath3" width="104px">&nbsp;</th>';
				tmp += '	<th></th>';
				tmp += '	<th class="r2_stat_headline" id="monath4" width="104px">&nbsp;</th>';
				tmp += '	<th></th>';
				tmp += '	<th class="r2_stat_headline"><a href="javascript:nextMonth();" class="r2_stat_next_month"><img src="img_konzept3/clearpixel.gif" height="7" width="8" alt="Monat weiterblättern" title="Monat weiterblättern" /></a></th>';
				tmp += '	<th></th>';
				tmp += '</tr>';
				tmp += '</thead>';
				
				document.getElementById("areaTable").innerHTML = tmp;
			}
		}
		catch(e) {this.log("CAreaListHandler::initMatrix\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setNoOffers()
	{
		try
		{
			var TableRow = document.createElement("tr");
			
			var TableColumn1 = document.createElement("td");
			var Colspan = document.createAttribute("colspan");
			Colspan.nodeValue = "12";
			TableColumn1.setAttributeNode(Colspan);
			TableColumn1.appendChild(this.objAreaListNoOffer.createNoOffersBox());
			
			TableRow.appendChild(TableColumn1);
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
			
			$("#arrowToBottom").ifixpng();
			
			myInit();
		}
		catch(e) {this.log("CAreaListHandler::setNoOffers\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setDynamicChange()
	{
		try
		{
			var TableRow = document.createElement("tr");
			
			var TableColumn1 = document.createElement("td");
			var Colspan = document.createAttribute("colspan");
			Colspan.nodeValue = "12";
			TableColumn1.setAttributeNode(Colspan);
			this.objAreaListNoOffer.setHeadline("individuelle Reisen");
			TableColumn1.appendChild(this.objAreaListNoOffer.createNoOffersBox());
			
			TableRow.appendChild(TableColumn1);
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
			
			$("#arrowToBottom").ifixpng();
			
			myInit();
		}
		catch(e) {this.log("CAreaListHandler::setDynamicChange\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setMonath(MonthField, MonthName)
	{
		try
		{
			document.getElementById(MonthField).innerHTML = MonthName;
		}
		catch(e) {this.log("CAreaListHandler::setMonath\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setMoreOfferLine()
	{
		try
		{
			var TableRow = document.createElement("tr");
						
			var TableColumn1 = document.createElement("td");
			var Colspan = document.createAttribute("colspan");
			Colspan.nodeValue = "12";
			TableColumn1.setAttributeNode(Colspan);
			
			var FieldSet = document.createElement("fieldset");
			var Legend = document.createElement("legend");
			Legend.innerHTML = "weitere Angebote";
			Legend.align = "center";
			Legend.style.padding = "8px";
					
			FieldSet.appendChild(Legend);
			TableColumn1.appendChild(FieldSet);
			TableRow.appendChild(TableColumn1);
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
		}
		catch(e) {this.log("CAreaListHandler::setMoreOfferLine\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setOffer(Country, Region, Month, minPrice, TLC, Type)
	{
		try
		{
			var spanLayer = document.createElement("span");
			spanLayer.innerHTML = "ab " + minPrice + ",- &euro;&nbsp;";
			
			
			var Link = document.createElement("a");
			
			if(Type == "Range")
				Link.href = "javascript:document.frmMoveToHotellist.frmAdults.value=document.getElementById('adult').value;document.frmMoveToHotellist.frmDeparture.value=document.getElementById('departureAirport').value;document.frmMoveToHotellist.frmDepDateRangeUntil.value=document.getElementById('arrivalDate').value;document.frmMoveToHotellist.frmDepDateRangeFrom.value=document.getElementById('departureDate').value;document.frmMoveToHotellist.frmArrival.value='" + TLC + "';document.frmMoveToHotellist.frmMinPriceAdult.value='" + minPrice + "';document.frmMoveToHotellist.frmDuration.value=arrAreaListCriteria[3];document.frmMoveToHotellist.submit();";
			else
				Link.href = "javascript:document.frmMoveToHotellist.frmAdults.value=document.getElementById('adult').value;document.frmMoveToHotellist.frmDeparture.value=document.getElementById('departureAirport').value;document.frmMoveToHotellist.frmMonth.value=" + Type + ";document.frmMoveToHotellist.frmArrival.value='" + TLC + "';document.frmMoveToHotellist.frmMinPriceAdult.value='" + minPrice + "';document.frmMoveToHotellist.frmDuration.value=arrAreaListCriteria[3];document.frmMoveToHotellist.submit();";
			
			Link.appendChild(spanLayer);
			
			var Image1 = document.createElement("img");
			Image1.src = "img_konzept3/stat_arrowblue.gif";
			Image1.id = Country + "_" + Region + "_" + Month + "_arrow";
			
			Link.appendChild(Image1);
			
			document.getElementById(Country + "_" + Region + "_" + Month + "_Price").appendChild(Link);			
		}
		catch(e) {this.log("CAreaListHandler::setOffer\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setMinPriceOffer(name, number, minPrice)
	{
		try
		{
			var spanLayer = document.createElement("span");
			spanLayer.innerHTML = "ab " + minPrice + ",- &euro;&nbsp;";	
			spanLayer.style.color = "#909090";
			
			document.getElementById("min_" + name + "_" + number).removeChild(document.getElementById("min_" + name + "_" + number).firstChild);
			document.getElementById("min_" + name + "_" + number).appendChild(spanLayer);
		}
		catch(e) {this.log("CAreaListHandler::setMinPriceOffer\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_addTopTipCountry(Name)
	{
		try
		{
			//create tbale row with attributes
			var TableRow = document.createElement("tr");
			TableRow.id = Name + '_head';
			TableRow.onclick = function(){
				try
				{
					objAreaListHandler.expandCountry(Name);
				}
				catch(e) {this.log("CAreaListHandler::addTopTipCountry\n" + e.message, "logging/JSExceptionLog.txt");}
			}
			
			//set mousecursor to pointer (so it looks like a anchor
			TableRow.onmouseover = function (){
				this.style.cursor = "pointer";
			}
			
			//set mousecursor to default
			TableRow.onmouseout = function (){
				this.style.cursor = "default";
			}
			
			//create table column with name of country
			var TableColumn1 = document.createElement("td");
			TableColumn1.id = Name + '_icon';
			TableColumn1.className = 'r2_stat_regio_close_img';
			TableColumn1.style.background = "transparent url(img_konzept3/stat_regio_bg_toptip.gif) repeat-x scroll 0% 0%";
			
			//create  anker with attributes
			var Link1 = document.createElement("a");
			Link1.href = "javascript:/*objAreaListHandler.expandCountry('" + Name + "');*/";
			
			//create image with attributes
			var Image1 = document.createElement("img");
			Image1.src = "img_konzept3/clearpixel.gif";
			Image1.alt = "Monat weiterblättern";
			Image1.title = "Monat weiterblättern";
			Image1.width = "9";
			Image1.height = "9";
			
			Link1.appendChild(Image1); //add image to link
			TableColumn1.appendChild(Link1); //add link with image to column
			TableRow.appendChild(TableColumn1); //add colument to row
			
			var TableColumn2 = document.createElement("td");
			TableColumn2.className = "r2_stat_regio_open";
			TableColumn2.id = Name + "_r2_stat_regio_open";
			
			TableColumn2.innerHTML = Name;
			TableColumn2.style.color = "#FFFFFF";
			TableColumn2.style.background = "transparent url(img_konzept3/stat_regio_bg_toptip.gif) repeat-x scroll 0% 0%";
			TableRow.appendChild(TableColumn2);
			
			for(var i = 0; i < 5; i++)
			{
				TableRow.appendChild(this.Country_td_price(Name, i));
				TableRow.appendChild(this.Country_td_space());				
			}
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
		}
		catch(e) {this.log("CAreaListHandler::addTopTipCountry\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_addCountry(Name)
	{
		try
		{
			//create tbale row with attributes
			var TableRow = document.createElement("tr");
			TableRow.id = Name + '_head';
			TableRow.onclick = function(){
				try
				{
					objAreaListHandler.expandCountry(Name);
				}
				catch(e) {this.log("CAreaListHandler::addCountry\n" + e.message, "logging/JSExceptionLog.txt");}
			}
			
			//set mousecursor to pointer (so it looks like a anchor
			TableRow.onmouseover = function (){
				this.style.cursor = "pointer";
			}
			
			//set mousecursor to default
			TableRow.onmouseout = function (){
				this.style.cursor = "default";
			}
			
			//create table column with name of country
			var TableColumn1 = document.createElement("td");
			TableColumn1.id = Name + '_icon';
			TableColumn1.className = 'r2_stat_regio_close_img';
			
			//create  anchor with attributes, anchor is just a dummy for mouse look. the real action is in onclick above
			var Link1 = document.createElement("a");
			Link1.href = "javascript:/*objAreaListHandler.expandCountry('" + Name + "');*/";
						
			//create image with attributes
			var Image1 = document.createElement("img");
			Image1.src = "img_konzept3/clearpixel.gif";
			Image1.alt = "Monat weiterblättern";
			Image1.title = "Monat weiterblättern";
			Image1.width = "9";
			Image1.height = "9";
			
			Link1.appendChild(Image1); //add image to link
			TableColumn1.appendChild(Link1); //add link with image to column
			TableRow.appendChild(TableColumn1); //add colument to row
			
			var TableColumn2 = document.createElement("td");
			TableColumn2.className = "r2_stat_regio_open";			
			TableRow.appendChild(TableColumn2);
			TableColumn2.innerHTML = Name;
			
			for(var i = 0; i < 5; i++)
			{
				TableRow.appendChild(this.Country_td_price(Name, i));
				TableRow.appendChild(this.Country_td_space());				
			}
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
		}
		catch(e) {this.log("CAreaListHandler::addCountry\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_addRegion(Country, RegionNo, RegionName)
	{
		try
		{
			//create tbale row with attributes
			var TableRow = document.createElement("tr");
			TableRow.id = Country + '_' + RegionNo;
			TableRow.style.display = "none";
			
			var TableColumn1 = document.createElement("td");
			TableColumn1.innerHTML = "&nbsp;";
			TableRow.appendChild(TableColumn1);
			
			var TableColumn2 = document.createElement("td");
			TableColumn2.className = "r2_stat_area";
			
			TableColumn2.innerHTML = RegionName;
			TableRow.appendChild(TableColumn2);
			
			TableRow.appendChild(this.Region_td_price(Country, RegionName, "Month1_Price"));			
			TableRow.appendChild(this.Region_td_space());
			TableRow.appendChild(this.Region_td_price(Country, RegionName, "Month2_Price"));
			TableRow.appendChild(this.Region_td_space());
			TableRow.appendChild(this.Region_td_price(Country, RegionName, "Month3_Price"));
			TableRow.appendChild(this.Region_td_space());
			TableRow.appendChild(this.Region_td_price(Country, RegionName, "Month4_Price"));
			TableRow.appendChild(this.Region_td_space());
			
			var TableColumn11 = document.createElement("td");
			TableColumn11.className = "r2_stat_price";
			TableColumn11.align = "center";
			
			var Link1 = document.createElement("a");
			Link1.href = "javascript:nextMonth();";
			Link1.className = "r2_stat_next_month";
						
			//create image with attributes
			var Image1 = document.createElement("img");
			Image1.src = "img_konzept3/clearpixel.gif";
			Image1.alt = "Monat weiterblättern";
			Image1.title = "Monat weiterblättern";
			Image1.width = "8";
			Image1.height = "7";
			
			Link1.appendChild(Image1); //add image to link
			TableColumn11.appendChild(Link1); //add link with image to column
			TableRow.appendChild(TableColumn11); //add colument to row
			
			TableRow.appendChild(this.Region_td_space());
			
			if(this.isInternetExplorer())
				document.getElementById("eingabe").appendChild(TableRow);
			else
				document.getElementById("areaTable").appendChild(TableRow);
		}
		catch(e) {this.log("CAreaListHandler::addRegion\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_expandCountry(Country)
	{
		try
		{
			var i = 0;
			
			while(document.getElementById(Country + '_' + i))
			{
				if(document.getElementById(Country + '_' + i).style.display != "none")
					document.getElementById(Country + '_' + i).style.display = "none";
				else
					document.getElementById(Country + '_' + i).style.display = "";//"table-row";
					
				i++;
			}
			
			if(document.getElementById(Country + "_icon").className == "r2_stat_regio_open_img")
				document.getElementById(Country + "_icon").className = "r2_stat_regio_close_img";
			else
				document.getElementById(Country + "_icon").className = "r2_stat_regio_open_img";
		
		}
		catch(e) {this.log("CAreaListHandler::expandCountry\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//private:
	function declared_isInternetExplorer()
	{
		var browser = navigator.userAgent.toLowerCase();
		var explorer = ((browser.indexOf("msie") != -1) && (browser.indexOf("opera") == -1));
		
		if(explorer)
			return true;
		else
			return false;
	}
	
//private:
	function declared_Country_td_price(Name, Number)
	{
		var TableColumn = document.createElement("td");
		TableColumn.className = "r2_stat_regio_price";
		TableColumn.innerHTML = "&nbsp;";
		TableColumn.id = "min_" + Name + "_" + Number;
		TableColumn.align = "right";
		
		return TableColumn;
	}

//private:
	function declared_Country_td_space()
	{
		var TableColumn = document.createElement("td");
		TableColumn.className = "r2_stat_regio_space";
		
		return TableColumn;
	}
	
//private:
	function declared_Region_td_space()
	{
		var TableColumn = document.createElement("td");
		TableColumn.className = "r2_stat_space";
		
		return TableColumn;
	}
	
//private:
	function declared_Region_td_price(Country, RegionName, month)
	{
		var TableColumn3 = document.createElement("td");
		TableColumn3.id = Country + '_' + RegionName + '_' + month; //Month1_Price;
		TableColumn3.className = "r2_stat_price";
		TableColumn3.align = "right";
		TableColumn3.innerHTML = "&nbsp;";
		
		TableColumn3.onmouseover = function()
					{
						this.style.background = '#e7ebf9';
						return false;
					}

		TableColumn3.onmouseout = function()
					{
						this.style.background = '#f7f7f7';
						return false;
					}
				
		return TableColumn3;
	}
//};