/*********************************************************************************************
* Helper functions
*********************************************************************************************/

// Check if string is non-blank
function isNonBlank (s) {
	var isNonblank_re    = /\S/;
	return String (s).search(isNonblank_re) != -1;
}

// Check if string is numeric
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

// Check if string is valid date
function isDate(str){
  var re = /^(\d{2})[\.](\d{2})[\.](\d{2})$/
  if (!re.test(str)) return false;
  var result = str.match(re);
  var d = result[1];
  var m = result[2];
  var y = result[3];

  if(m < 1 || m > 12) return false;
  if(m == 2){
          var days = ((y % 4) == 0) ? 29 : 28;
  }else if(m == 4 || m == 6 || m == 9 || m == 11){
          var days = 30;
  }else{
          var days = 31;
  }
  return (d >= 1 && d <= days);
}

// Articles list management
function ArtCategories(settings){

	this.categId = 0;
	this.sortOrder = "DESC";
	this.sortField = "article_datestamp";
	this.filterField = "all";
	this.filterText = "";
	this.filterStartDate = "";
	this.filterEndDate = "";
	this.nrPage = 1;
	this.showFilterTools = 0;
	
	this.accessCondition = settings.accessCondition;
	this.themeLocation = settings.themeLocation;
	this.fillSpaceImg = settings.fillSpaceImg;
	this.arrowRightImg = settings.arrowRightImg;
	
	this.jxObj = new jx();
	
/*********************************************************************************************
* Init, save and restore data
*********************************************************************************************/

	//init articles section data (on page refresh or back from another page)
	this.initData = function(){
	
		var strSettings = this.getSavedDisplaySettings();
		
		// if we do not have display settings stored in cookies
		if (strSettings == null) {
			//form fields initialisation
			document.getElementById('filter_field').selectedIndex = 0;
			document.getElementById('filter_text').value = '';
			document.getElementById('filter_start_date').value = '';
			document.getElementById('filter_end_date').value = '';
			document.getElementById('filter_text').disabled = 'disabled';
			document.getElementById('filter_date_container').style.display = 'none';
		}
		else {
		
			// restore data from cookies
			
			var objSettings = eval('(' + strSettings + ')');
			
			this.categId = objSettings.categId;
			this.sortOrder = objSettings.sortOrder;
			this.sortField = objSettings.sortField;
			this.filterField = objSettings.filterField;
			this.filterText = objSettings.filterText;
			this.filterStartDate = objSettings.filterStartDate;
			this.filterEndDate = objSettings.filterEndDate;
			this.nrPage = objSettings.nrPage;
			this.showFilterTools = objSettings.showFilterTools;
			
			// restore category
			this.selectCateg(objSettings.categId, false);
			
			// restore sorting field
			switch (this.sortField) {
				case "article_subject":
					document.getElementById("sort_field").selectedIndex = 0;
					break;
				case "user_name":
					document.getElementById("sort_field").selectedIndex = 1;
					break;
				case "article_reads":
					document.getElementById("sort_field").selectedIndex = 2;
					break;
				case "article_datestamp":
					document.getElementById("sort_field").selectedIndex = 3;
			}
			
			// restore sorting order
			if (this.sortOrder == "ASC") {
				this.selectSortOrder(document.getElementById("sort_asc"));
			}
			else {
				this.selectSortOrder(document.getElementById("sort_desc"));
			}
			
			// restore filter field
			switch (this.filterField) {
				case "all":
					document.getElementById("filter_field").selectedIndex = 0;
					break;
				case "article_subject":
					document.getElementById("filter_field").selectedIndex = 1;
					document.getElementById('filter_text').value = this.filterText;
					break;
				case "user_name":
					document.getElementById("filter_field").selectedIndex = 2;
					document.getElementById('filter_text').value = this.filterText;
					break;
				case "article_datestamp":
					document.getElementById("filter_field").selectedIndex = 3;
					document.getElementById('filter_start_date').value = this.filterStartDate;
					document.getElementById('filter_end_date').value = this.filterEndDate;
			}
			
			this.changeFilterField();
			
		}
	}
	
	// save display data to cookies
	this.saveDisplaySettings = function(){
	
		if (Cookies.test()) {
			
			var strSettings = "{" +
				"'categId':'" + this.categId + "', " +
				"'sortOrder':'" + this.sortOrder + "', " + "'sortField':'" + this.sortField + "', " +
				"'filterField':'" + this.filterField + "', " +
				"'filterText':'" + this.filterText + "', " +
				"'filterStartDate':'" + this.filterStartDate + "', " +
				"'filterEndDate':'" + this.filterEndDate + "', " +
				"'nrPage':'" + this.nrPage + "', " +
				"'showFilterTools':'" + this.showFilterTools + "'}";
			
			//save data to cookie for 2 hours
			Cookies.set("displaySettings", strSettings, 0.1);
			
		}
	}
	
	// return display data from cookies
	this.getSavedDisplaySettings = function(){
		return Cookies.get("displaySettings");
	}
	
/*********************************************************************************************
* Fetch data
*********************************************************************************************/
	
	// get filter form data (before database interrogation)
	this.getInputData = function(){
		
		//display filter tools (if we have clicked on "click here" before a recent "refresh" or "page back")
		if(this.showFilterTools == 1){
			if(document.getElementById("filter_help").style.display == "block") {
				document.getElementById("filter_help").style.display = "none";
				document.getElementById("filter_tools").style.display = "block";
			}
		}

		success = true;		
		//check for valid start and end date 
		if (document.getElementById("filter_field").selectedIndex == 3) {
			if (!isDate(document.getElementById("filter_start_date").value)) {
				success = false;
				if (!isNonBlank(document.getElementById("filter_start_date").value)) {
					document.getElementById("filter_start_date").value = 'zz.ll.aa';
				}
				document.getElementById("filter_start_date").style.color = '#ff0000';
			}
			else {
				document.getElementById("filter_start_date").style.color = '#113355';
			}
			if (!isDate(document.getElementById("filter_end_date").value)) {
				success = false;
				if (!isNonBlank(document.getElementById("filter_end_date").value)) {
					document.getElementById("filter_end_date").value = 'zz.ll.aa';
				}
				document.getElementById("filter_end_date").style.color = '#ff0000';
			}
			else {
				document.getElementById("filter_end_date").style.color = '#113355';
			}
		}
		// get display settings form data
		if (success) {
			this.sortField = document.getElementById("sort_field").value;
			this.filterField = document.getElementById("filter_field").value;
			if (document.getElementById("filter_field").selectedIndex != 3) {
				this.filterText = document.getElementById("filter_text").value;
			}
			else {
				this.filterStartDate = document.getElementById("filter_start_date").value;
				this.filterEndDate = document.getElementById("filter_end_date").value;
			}
		}
		return success;
	}
	
	// get data from database	
	this.getData = function(){
		if (this.getInputData()) {
			filterStr = "";
			if (this.filterText != "") {
				filterStr = '&filterText=' + this.filterText
			}
			else 
				if (this.filterStartDate != "" && this.filterEndDate != "") {
					//convert from zz.ll.aa to ll.zz.aaaa
					var temp = this.filterStartDate.split(".");
					var startDate = temp[1] + "." + temp[0] + "." + '20' + temp[2];
					temp = this.filterEndDate.split(".");
					var endDate = temp[1] + "." + temp[0] + "." + '20' + temp[2];
					filterStr = '&filterStartDate=' + startDate + '&filterEndDate=' + endDate;
				}
			this.jxObj.load('infusions/articles_list_panel/get_articles.php?categId=' + this.categId +
				'&sortOrder=' + this.sortOrder + '&sortField=' + this.sortField +
				'&filterField=' + this.filterField + filterStr +
				'&nrPage=' + this.nrPage + '&themeLocation=' + this.themeLocation +
				'&accessCondition=' + this.accessCondition + '&fillSpaceImg=' + this.fillSpaceImg +
				'&arrowRightImg=' + this.arrowRightImg, function(data){
						arrData = data.split('|||');
						if (arrData[1]) {
							document.getElementById('navigation_panel').innerHTML = arrData[0];
							document.getElementById('articles_list').innerHTML = arrData[1];
						}
						else {
							document.getElementById('navigation_panel').innerHTML = "";
							document.getElementById('articles_list').innerHTML = "<div style = 'margin-right:30px;'>" + arrData[0] + "</div>";
						}
			}, 'text', 'post');
			//save display settings data	
			this.saveDisplaySettings();
		}
		else {
			// display message in case of form data error
			
			document.getElementById('articles_list').innerHTML = "<div style = 'margin: 5px 30px 0 5px;font-weight:bold; color: #ff0000;'>Operatia solicitata nu poate fi efectuata." +
			"Va rugam sa verificati daca ati setat corect criteriile de afisare (a doua sectiune din campul din stanga). " +
			"Erorile sunt semnalate cu rosu in campurile corespunzatoare.<br>&#8226; Pentru datele calendaristice nu se admit campuri vide sau valori incorecte;<br>" +
			"&#8226; In cazul cautarii dupa subiect sau autor, campurile vide nu produc erori, nefiind luate in considerare;<br>" +
			"&#8226; Paginarea nu accepta decat valori numerice, in caz contrar solicitarea nefiind luata in considerare.</div>" +
			"<div style = 'margin: 5px 30px 0 5px;font-weight:bold; color: #555555;'>" +
			"<a href = '#' style = 'text-decoration:underline' onclick = 'return artCategories.resetFilters(true);'>" +
			"Click aici</a> pentru a reseta criteriile de filtrare.</div>";
			
			document.getElementById('navigation_panel').innerHTML = "<div style = 'width:1px; height:40px;'></div>";
		}
	}
	
/*********************************************************************************************
* Form object handlers
*********************************************************************************************/
	
	// get data after selecting a category from the left menu
	this.selectCateg = function(categId, getData){
	
		this.categId = categId;
		var parent = document.getElementById("cat_0").parentNode;
		
		for (i = 0; i < parent.childNodes.length - 1; i++) {
			if (typeof(parent.childNodes[i].childNodes[0]) != "undefined") {
				if (typeof(parent.childNodes[i].childNodes[0].style) != "undefined") {
					parent.childNodes[i].style.border = "1px solid #FFFFFF";
				}
			}
			if (typeof(parent.childNodes[i].id) != "undefined") {
				if (("" + parent.childNodes[i].id.split("_")[1]) == ("" + categId)) {
					parent.childNodes[i].style.border = "1px solid #8d8d8d";
				}
			}
		}
		// fetch data in case of click on category (not a call from another function)
		if (getData) {
			this.nrPage = 1;
			this.getData();
		}
		return false;
	}
	
	// refresh page after selecting display parameters
	this.refreshPage = function(){
		this.nrPage = 1;
		this.getData();
		return false;
	}
	
	// go to specified page
	this.goToPage = function(){
		if (IsNumeric(document.getElementById("nr_page").value)) {
			if (this.nrPage == document.getElementById("nr_page").value) {
				document.getElementById("navigator_msg").style.color = "#ff0000";
			}
			else {
				document.getElementById("navigator_msg").style.color = "#8a8a8a";
				this.nrPage = document.getElementById("nr_page").value;
				document.getElementById("nr_page").style.color = "#8a8a8a";
				this.getData();
			}
		}
		else {
			document.getElementById("nr_page").style.color = "#ff0000";
		}
		return false;
	}
	
	// activate/deactivate filter text field
	this.changeFilterField = function(){
	
		obj = document.getElementById("filter_field");
		
		if (obj.selectedIndex == 3) {
			document.getElementById("filter_text_container").style.display = "none";
			document.getElementById("filter_date_container").style.display = "block";
			this.filterText = "";
			document.getElementById("filter_text").value = "";
		}
		else {
			document.getElementById("filter_text_container").style.display = "block";
			document.getElementById("filter_date_container").style.display = "none";
			this.filterStartDate = "";
			this.filterEndDate = "";
			document.getElementById("filter_start_date").value = "";
			document.getElementById("filter_end_date").value = "";
			
			if (obj.selectedIndex == 0) {
				this.filterText = "";
				document.getElementById("filter_text").value = "";
				document.getElementById("filter_text").disabled = true;
			}
			else {
				document.getElementById("filter_text").disabled = false;
			}
		}
	}
	
	// select sort type (ASC or DESC)	
	this.selectSortOrder = function(obj){
		obj.style.border = "1px solid #8d8d8d";
		if (obj.id == "sort_asc") {
			this.sortOrder = "ASC";
			document.getElementById("sort_desc").style.border = "1px solid #ffffff";
		}
		else {
			this.sortOrder = "DESC";
			document.getElementById("sort_asc").style.border = "1px solid #ffffff";
		}
		return false;
	}
	
	// display filters tools instead of filters help
	this.displayFilterTools = function(){
		document.getElementById("filter_tools").style.display = "block";
		document.getElementById("filter_help").style.display = "none";
		this.showFilterTools = 1;
		return false;
	}
	
	// reset search filters (to none)
	this.resetFilters = function(foundError){
	
		document.getElementById("filter_field").selectedIndex = 0;
		if (foundError = true) {
			document.getElementById("filter_start_date").style.color = '#113355';
			document.getElementById("filter_end_date").style.color = '#113355';
		}
		this.changeFilterField();
		this.refreshPage();
		return false;
		
	}

} //end of ArtCategories class

// Articles list management
function NewsCategories(settings){

	this.categId = 0;
	this.newsCategories = eval('(' + settings.strNewsCategories + ')');
	this.selNewsIndex = 0; // no id initially selected selected 
	this.nrPage = 1;
	this.nrPages = 1;
	this.accessCondition = settings.accessCondition;
	this.themeLocation = settings.themeLocation;
	this.pageItems = settings.pageItems;
	
	this.categoryImgLocation = settings.categoryImgLocation;
	this.newsLargeImgLocation = settings.newsLargeImgLocation;
	this.newsMediumImgLocation = settings.newsMediumImgLocation;
	this.newsSmallImgLocation = settings.newsSmallImgLocation;
	
	this.editNews = settings.editNews;
	this.arrNews = new Array();
	this.nrNews = 0;
	
	this.adminIdLink = settings.adminIdLink;
	this.adminFolder = settings.adminFolder;
	
	this.jxObj = new jx();

/*********************************************************************************************
* Init, save and restore data
*********************************************************************************************/

	//init articles section data (on page refresh or back from another page)
	this.initData = function(){
		var strSettings = this.getSavedDisplaySettings();
		if (strSettings != null) {
			// restore data from cookies
			var objSettings = eval('(' + strSettings + ')');
			this.categId = objSettings.categId;
			this.nrPage = parseInt(objSettings.nrPage);
			// select saved category without retrieving data for the second time
			this.changeCategory(this.categId, false);
		}
	}
	
	// save display data to cookies
	this.saveDisplaySettings = function(){
	
		if (Cookies.test()) {
			var strSettings = "{" +
				"'categId':'" + this.categId + "', " +
				"'nrPage':'" + this.nrPage + "'}";
			
			//save data to cookie for 2 hours
			Cookies.set("newsDisplaySettings", strSettings, 0.1);
		}
	}

	// return display data from cookies
	this.getSavedDisplaySettings = function(){
		return Cookies.get("newsDisplaySettings");
	}

/*********************************************************************************************
* Fetch data
*********************************************************************************************/

	// get news list from database	
	this.getNewsList = function(categ_id, refresh_focus){
		if(categ_id >= 0) this.categId = categ_id;
		this.jxObj.load('get_news_list.php?categId=' + this.categId + '&accessCondition=' + this.accessCondition + '&nrPage=' + this.nrPage + '&pageItems=' + this.pageItems, 		
		function(data){
			objData = eval('(' + data + ')');
			newsCategories.arrNews = objData.news_list;
			newsCategories.nrNews = objData.nr_news;
			
			if (refresh_focus == true) {
				// refresh focused news on list change (first load or change category)
				newsCategories.createNewsFocus(0);
			}	
			newsCategories.createNewsList();
			//display_weather('container_Meteo');
		}, 'text', 'post');
		this.saveDisplaySettings();
	}

/*********************************************************************************************
* Create visual elements to display data
*********************************************************************************************/

	// create news list pagination
	this.createPagination = function() {
		
		if (this.nrNews == 0) {
			this.nrPages = 1;
		}
		else {
			this.nrPages = Math.floor((this.nrNews - 1) / this.pageItems) + 1;
		}

		// find numbers displayed on the left of current page number
		var numbers_left = this.nrPage < 3 ? this.nrPage - 1 : 2;
		if((this.nrPage >3) && (this.nrPages - this.nrPage < 2)) numbers_left = numbers_left + 2 - (this.nrPages - this.nrPage);  
		
		// find numbers displayed on the right of current page number
		var numbers_right = 5 - numbers_left - 1; 		

		strPagination = "<div style = 'float:left;border-right:1px solid #DFDFDF;padding:3px 5px 3px 5px;'>" + 
								"Pagina " +  this.nrPage + " din " + this.nrPages + 
						"</div>";						
		
		// insert left arrows
		if(this.nrPage - numbers_left > 1) {
			strPagination += "<div style = 'float:left;border-right:1px solid #DFDFDF;padding:3px 5px 3px 5px;'>" +
								 "<a href = '#' onclick = 'return newsCategories.goToPage(1);'><<</a>" + 
							 "</div>";
		}
		
		if(this.nrPage != 1) {
			strPagination += "<div style = 'float:left;border-right:1px solid #DFDFDF;padding:3px 5px 3px 5px;'>" +
								 "<a href = '#' onclick = 'return newsCategories.goToPage(\"" + (this.nrPage -1) + "\");'><</a>" + 
							 "</div>";
		}	
		
		// insert numbers to the left of current page number
		var start_number = this.nrPage - numbers_left;
		for(var i = start_number; i < this.nrPage; i++ ) {
			strPagination += "<div style = 'float:left;background-color:#fff;border-right:1px solid #DFDFDF;" + 
											"padding:3px 5px 3px 5px;'>" + 
									"<a href = '#' onclick = 'return newsCategories.goToPage(\"" + i + "\");'>" + 
										i + "</a>" +
								 "</div>";
		}		
				
		// insert current page number
		strPagination += "<div style = 'float:left;background-color:#fff;border-right:1px solid #DFDFDF;" + 
									"padding:3px 5px 3px 5px;'>" + 
								this.nrPage + 
						 "</div>";
						 
		// insert numbers to the right of current page number
		
		var end_number = this.nrPage + numbers_right <= this.nrPages ? this.nrPage + numbers_right :  this.nrPages;
		for(var i = this.nrPage+1; i <= end_number; i++) {
			strPagination += "<div style = 'float:left;background-color:#fff;border-right:1px solid #DFDFDF;" + 
									"padding:3px 5px 3px 5px;'>" + 
							"<a href = '#' onclick = 'return newsCategories.goToPage(\"" + i + "\");'>" + 
								i + "</a>" + 
						 "</div>";
		}
		
		// insert right arrows
		if(this.nrPage < this.nrPages) {
			strPagination += "<div style = 'float:left;border-right:1px solid #DFDFDF;padding:3px 5px 3px 5px;'>" +
								 "<a href = '#' onclick = 'return newsCategories.goToPage(\"" + (this.nrPage +1) + "\");'>></a>" + 
							 "</div>";
		}
		
		if(this.nrPage + numbers_right < this.nrPages) {
			strPagination += "<div style = 'float:left;border-right:1px solid #DFDFDF;padding:3px 5px 3px 5px;'>" +
								 "<a href = '#' onclick = 'return newsCategories.goToPage(\"" + this.nrPages  + "\");'>>></a>" + 
							 "</div>";
		}
		
		document.getElementById('pagination_container').innerHTML = strPagination;
	}

	// create news list
	this.createNewsList = function() {
		
		if (this.nrNews == 0) {
			strNewsList = "<div style = 'margin-left: 5px;'>Nu exista nici o stire in lista</div>";
		}
		else {
		
			strNewsList = "<div style = 'float:left;'>";
			var index = (this.nrPage - 1) * this.pageItems;
	
			// index number display settings
			strWidth = "width:16px";
			if (index + this.arrNews.length + 1  >= 10) {
				strWidth = 'width:22px';
			} 
			if (index + this.arrNews.length + 1  > 100) {
				strWidth = 'width:28px';
			} 
			
			for (var i = 0; i < this.arrNews.length; i++) {
				
				index++;
				
				//get background colour
				background_color = "#f2f2f2";
				if(this.selNewsIndex == i) {
					background_color = "#fff";
				}
				
				// find images associated with photos in the list
				var imgLocation = "";
				if (this.arrNews[i]['news_photo'] != "") {
					imgLocation = this.newsSmallImgLocation + this.arrNews[i]['news_id'] + "_" + this.arrNews[i]['news_photo'];
				}
				else {
					imgLocation = this.categoryImgLocation + this.newsCategories[this.arrNews[i]['news_cat']];
				}	
				
				strNewsList += "<a href = '#' title = 'Vizualizare rapida' alt = 'Vizualizare rapida' onClick = 'return newsCategories.changeNewsFocus(\"" + i + "\")' style = 'cursor:pointer;'>" +
				"<div id = 'list_news_" + i + "' style = 'float:left;width:100%;background-color:" + background_color +";border-bottom:1px solid #dfdfdf;padding:3px 0 2px 0;margin-top:3px;'>" +
				"<div style = 'float:left;font-size:14px;font-weight:bold;margin-left:2px;text-align:right;"+ strWidth + "'>" +
				index + "." +
				"</div>" +
				"<div style = 'float:left;'>" +
				"<img alt='' width = '50' style='margin:2px 8px 10px 5px;border:1px solid #aaa' src='"+imgLocation+"'/>" +
				"</div>" +
				"<div style = 'float:left;width:75%;line-height:14px;font-weight:bold;padding-top:2px;'>" +
				"<div style = 'padding-right:10px;'>" +
				this.arrNews[i]['news_subject'] +
				"</div>" +
				"<div style = 'margin-top:1px;color:#5a5a5a;font-size:11px;line-height:12px;'>&raquo; Postare: " +
				this.arrNews[i]['news_date'] +
				" (" + this.arrNews[i]['user_name'] + ") " + "</div>" +
				"<div style = 'color:#5a5a5a;font-size:11px;line-height:12px;'>&raquo; Vizualizari: " +
				this.arrNews[i]['news_reads'] +
				"</div>" +
				"<div style = 'color:#5a5a5a;font-size:11px;line-height:12px;'>&raquo; Comentarii: " +
				this.arrNews[i]['news_comments'] +
				"</div>" +
				"</div>" +
				"</div>" +
				"</a>";
			}
			strNewsList += "<div id = 'pagination_container' style = 'float:left;margin-top:10px;background-color:#F2F2F2;border:1px solid #DFDFDF;'></div>";
			
			strNewsList += "</div>"
			strNewsList += "<div style = 'height:100%;'></div>"
		}
		document.getElementById('news_list').innerHTML = strNewsList;
		if (this.nrNews != 0) {
			newsCategories.createPagination();
		}	
	}
	
	// create focused news section
	this.createNewsFocus = function(index) {

		if (this.nrNews == 0) {
			strNewsFocus = "<div>Nu exista nici o stire selectata</div>";
		}
		else {
		
			this.selNewsIndex == index;			
			// find image associated with focused news
			var imgLocation = "";
			var showPopup = false;
			var imgTitle = "";
			//display uploaded or default image for selected news
			if (this.arrNews[index]['news_photo'] != "") {
				showPopup = true;
				imgTitle = "Afisare marita";
				imgLocation = this.newsMediumImgLocation + this.arrNews[index]['news_id'] + "_" + this.arrNews[index]['news_photo'];
			}
			else {
				imgLocation = this.categoryImgLocation + this.newsCategories[this.arrNews[index]['news_cat']];
			}
			
			strNewsFocus = "<div style = 'position:relative;float:left;width:230px;padding:5px 5px 0 0;'>" +
			"<div style = 'float:left;width:230px;'>" +
			"<div style = 'float:left;width:220px;padding-left:0;'>" +
			"<div style = 'font-size:12px;'><a class='link_title' title='Mai multe detalii' href='?readmore="+this.arrNews[index]['news_id']+"' style = 'text-decoration:none;font-size:13px;font-weight:bold;text-decoration:underline'> " +
			this.arrNews[index]['news_subject'] +
			"</a></div>" +
			"</div>" +
			"<div style = 'float:left;width:100%;padding-top:12px;position:relative;'>" +
			"<div style='float:left;padding:0;'><img alt='' width = '80' style='margin: 0 5px 0 0;border: 1px solid #aaa' src='" +
			imgLocation +
			"' title = '" +
			imgTitle +
			"' onclick = 'newsCategories.showPopup(" +
			showPopup +
			");' /></div>" +
			"<div style = 'float:left;line-height:14px;color: #5a5a5a;'>" +
			"<span>&raquo; Postare: " +
			this.arrNews[index]['news_digitdate'] +
			"</span></br>" +
			"<span> &raquo; Autor: " +
			this.arrNews[index]['user_name'] +
			"</span></br>" +
			"</div>" +
			"<div style = 'float:left;height:35px;width:140px;background: transparent url(" +
			this.themeLocation +
			"images/hand_pen.gif) no-repeat scroll right bottom'>" +
			"</div>";
			if (showPopup) {
				strNewsFocus += "<div style = 'float:left;margin-top:5px;position:absolute;left:88px;bottom:0px;'><a href = '#' onclick = 'return newsCategories.showPopup(" + showPopup + ");'>&laquo; Mareste foto </a></div>";
			}
			strNewsFocus += "</div>" +
			"</div>" +
			"<div style = 'clear:both;margin-top:3px;font-size:1px;height:12px;border-bottom:1px dotted #c2c2c2;'></div>" +
			"<div style = 'color: #5a5a5a;font-weight:bold;margin-top:5px;'>&raquo; Detalii pe scurt</div>" +
			"<div style = 'float:left;border-left:1px solid #bbb;padding-top:3px;padding-left:10px;color: #5a5a5a' >" +
			"<a href = '?readmore="+this.arrNews[index]['news_id']+"'>" + this.arrNews[index]['news_news'] + "</a>" +
			"</div>" +
			"<div style = 'clear:both;margin-top:7px;font-size:1px;height:7px;border-bottom:1px dotted #c2c2c2;'></div>" +
			"<div style = 'margin-top:8px;'>" +
			"<a href = '?readmore=" +
			this.arrNews[index]['news_id'] +
			"'>&raquo; Vizualizari: " +
			this.arrNews[index]['news_reads'] +
			", Comentarii: " +
			this.arrNews[index]['news_comments'] +
			"<br />" +
			"&raquo; Citeste intreg articolul </a> <br />" +
			"</div>" +
			"<div style = 'margin-top:5px;'>" +
			"<a href = 'print.php?type=N&item_id=" +
			this.arrNews[index]['news_id'] +
			"'><img src = '" +
			this.themeLocation +
			"images/printer.gif'/> Printeaza stire</a><br />";
			if (this.editNews) {
				strNewsFocus += "<form name='editnews" + this.arrNews[index]['news_id']+"' method='post' action='"+this.adminFolder+"news.php"+this.adminIdLink+"&amp;news_id="+this.arrNews[index]['news_id']+"'></form>";
				strNewsFocus += "<a href = 'javascript:document.editnews" + this.arrNews[index]['news_id'] + ".submit()'><img src = 'images/edit.gif'/> Editeaza stire </a>";
			}
			strNewsFocus += "</div>";
			// create popup image layer
			if (showPopup) {
				strNewsFocus += "<div id = 'popup' onclick='return newsCategories.closePopUp();' style='display:none;background-color:#FFFFFF;border:2px solid #777;left:50%;margin-left:-100px;padding: 20px 20px 5px 20px;position:absolute;top:1px;z-index:1000;'>" +
				"<div style = 'text-align:center;'><img src='" +
				this.newsLargeImgLocation +
				this.arrNews[index]['news_id'] +
				"_" +
				this.arrNews[index]['news_photo'] +
				"'/></div>" +
				"<div style = 'float:left;width: 240px;margin-top:5px;'>Click pe imagine pentru a inchide fereastra</div>" +
				"</div>";
			}
			strNewsFocus += "</div>";
		}
		document.getElementById('selected_news').innerHTML = strNewsFocus;			
	}
	
	// change focused news
	this.changeNewsFocus = function(index) {

		// change news focus only if current selection is different from the previous one
		if (this.selNewsIndex != index) {
			this.selNewsIndex = index;
			newsCategories.createNewsFocus(index);			
		}
		
		for (i = 0; i < this.arrNews.length; i++) {
			if(this.selNewsIndex == i) {
				document.getElementById('list_news_'+ i).style.backgroundColor = "#fff";
			} else {
				document.getElementById('list_news_'+ i).style.backgroundColor = "#f2f2f2";
			}
		}
		
		return false;	
	}
	
	// change news category 
	this.changeCategory = function(categ_id, reset_data){
		
		var parent = document.getElementById("menu_container");
		
		for (i = 0; i < parent.childNodes.length; i++) {
			if (typeof(parent.childNodes[i]) != "undefined") {
				if (typeof(parent.childNodes[i].style) != "undefined") {
					parent.childNodes[i].style.backgroundColor = "#eee";
				}
			}
			if (typeof(parent.childNodes[i].id) != "undefined") {
				if (("" + parent.childNodes[i].id.split("_")[2]) == ("" + categ_id)) {
					parent.childNodes[i].style.backgroundColor = "#fff";					
				}
			}
		}

		if (reset_data == true) {
			// refresh news list and focused news item
			this.categId = categ_id;
			this.nrPage = 1;
			this.selNewsIndex = 0;
			// refresh news list and focused news
			this.getNewsList(categ_id, true);
		}
		
		return false;
	}
	
	// go to specified page
	this.goToPage = function(nr_page){
		this.nrPage = parseInt(nr_page);
		this.selNewsIndex = 0;
		this.getNewsList(this.categId, true);
		return false;
	}
	
	// display enlarged image popup
	this.showPopup = function(show) {
		if(show) {
			var popup = document.getElementById("popup")
			popup.style.display = "inline"
			document.body.style.overflowY = "scroll";
		}
		return false;
	}
	
	// close enlarged image popup
	this.closePopUp = function(){
		var popup = document.getElementById("popup")
		popup.style.display = "none"
		document.body.style.overflowY = "scroll";
		return false;	
	}

} //end of ArtCategories class

// Images management
function ImgPopup(){
	// display enlarged image popup
	this.showPopup = function(show) {
		if(show) {
			var popup = document.getElementById("popup")
			popup.style.display = "inline"
			document.body.style.overflowY = "scroll";
		}
		return false;
	}
	
	// close enlarged image popup
	this.closePopUp = function(){
		var popup = document.getElementById("popup")
		popup.style.display = "none"
		document.body.style.overflowY = "scroll";
		return false;	
	}
} //end of ImgPopup class

function display_weather(id_container) {		
	if(typeof document.getElementById(id_container) != undefined) {
	document.getElementById(id_container).innerHTML = "<center>Bucuresti <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15420.gif\' border=0 height=28 width=53></a><center>" +
	"<center> Constanta <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15480.gif\' border=0 height=28 width=53></a><center>"+
	"<center> Iasi <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15090.gif\' border=0 height=28 width=53></a> <center>" +
	"<center> Bacau <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15150.gif\' border=0 height=28 width=53></a><center>" +
	"<center> Timisoara <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15247.gif\' border=0 height=28 width=53></a><center>" +
	"<center> Craiova <img src=\'http://banners.wunderground.com/weathersticker/smalltemptr_metric/language/www/global/stations/15450.gif\' border=0 height=28 width=53></a>";
	}

}