function strToInt(aStr){
	if ((aStr==null)|(aStr==''))
		return 0
	else
		return parseInt(aStr);
}
function FavItem(oNode){
	this.ID = oNode.getAttribute("FID");
	this.Title = oNode.getAttribute("FTitle");
	this.URL = oNode.getAttribute("FURL");
	this.Desc = oNode.getAttribute("FDesc");
	this.Order = strToInt(oNode.getAttribute("FOrder"));
	this.Key = oNode.getAttribute("FKey");
	this.Share = oNode.getAttribute("FShare");
	this.Class = oNode.getAttribute("FClass");
	this.Hits0 = parseInt(oNode.getAttribute("FHits0"));
	this.Hits = parseInt(oNode.getAttribute("FHits"));
	this.Date = oNode.getAttribute("FDate");
	this.Lock = oNode.getAttribute("FLock");
	this.Level = strToInt(oNode.getAttribute("FLevel"));
	if ((this.URL.indexOf(':')==-1)|(this.URL.indexOf(':')>7)) this.URL = 'http://' + this.URL;
}

function BlogItem(oNode){
	this.ID = oNode.getAttribute("FID");
	this.Title = oNode.getAttribute("FTitle");
//	this.Content = oNode.getAttribute("FContent");
	this.Key = oNode.getAttribute("FKey");
	this.Top = oNode.getAttribute("FTop");
	this.Share = oNode.getAttribute("FShare");
	this.Class = oNode.getAttribute("FClass");
	this.Hits0 = parseInt(oNode.getAttribute("FHits0"));
	this.Hits = parseInt(oNode.getAttribute("FHits"));
	this.Date = oNode.getAttribute("FDate");
	this.Level = strToInt(oNode.getAttribute("FLevel"));
}


var sArrItemOrder='Order';

function cmpArrItem(a,b){
	return a[sArrItemOrder]>b[sArrItemOrder]?1:-1;
}
function cmpArrItemb(a,b){
	return a[sArrItemOrder]>b[sArrItemOrder]?-1:1;
}
function sortArrItem(sOrder){
	if (typeof(sOrder)=='string') sArrItemOrder=sOrder;
	if (sArrItemOrder.substr(0,1)=='-'){
		sArrItemOrder=sArrItemOrder.substr(1);
			arrItem = arrItem.sort(cmpArrItemb);
	}else{
			arrItem = arrItem.sort(cmpArrItem);
	}
}

function applyTemplate(){
	var sResult = '';
	var sTpl = document.getElementById('ItemTemplate').innerHTML;
	var strTem = '';
	for (var i=0;i<arrItem.length;i++){
		strTem = sTpl;
		for (j in arrItem[i]){
			strTem = strTem.replace(new RegExp('\\$\\{' + j + '\\}','g'),arrItem[i][j]);
		}
		sResult = sResult + strTem;
	}
	document.getElementById('Main_ItemList').innerHTML = sResult;
}

function showFolders(TabIdx,sFld){
	try{
		var arrDat=top.arrFolderData;
		var sResult = '';
		var sTpl = document.getElementById('FldTemplate').innerHTML;
		var strTem = '';
		for (var i=0;i<arrDat.length;i++){
			if ((arrDat[i].TabIdx == TabIdx) && (arrDat[i].ID.length == sFld.length+3) && (arrDat[i].ID.substr(0,sFld.length)==sFld)){
				strTem = sTpl;
				for (j in arrDat[i]){
					strTem = strTem.replace(new RegExp('\\$\\{' + j + '\\}','g'),arrDat[i][j]);
				}
				sResult = sResult + strTem;
			}
		}
		document.getElementById('Main_FldList').innerHTML = sResult;
	}catch(e){
		window.setTimeout('showFolders('+TabIdx+',"'+sFld+'")', 1000);
	}
}

function SearchEx(sSearch,arrFld){
	if (top.CurSearch == sSearch) return;
	top.CurSearch = sSearch;
	document.getElementById('Main_ItemSearch').innerHTML = '';
	if (sSearch=='') return;
	var strSearch=sSearch.replace('\\','\\\\');
	strSearch=strSearch.replace('\*','\\*');
	strSearch=strSearch.replace('\(','\\(');
	strSearch=strSearch.replace('\)','\\)');
	strSearch=strSearch.replace('\[','\\[');
	strSearch=strSearch.replace('\?','\\?');
	strSearch=strSearch.replace('\+','\\+');
	var sResult = '';
	var sTpl = document.getElementById('ItemTemplate').innerHTML;
	var strTem = '';
	for (var i=0;i<arrItem.length;i++){
		strTem = sTpl;
		bFind=false;
		for (var k=0;k<arrFld.length;k++){
			if (arrItem[i][arrFld[k]].search(new RegExp(strSearch,'ig'))!=-1){
				for (j in arrItem[i]){
					strTem = strTem.replace(new RegExp('\\$\\{' + j + '\\}','g'),arrItem[i][j]);
				}
				sResult = sResult + strTem;
				break;
			}
		}
	}
	document.getElementById('Main_ItemSearch').innerHTML = sResult;
}
