﻿// JScript 檔

// 物件圖檔路徑
var _HOUSE_PHOTO_PATH = "";

/*擷取顯示文字依byte長度限制，並包括中文為2個byte來計算*/
function abstractStrWithChiese(word, byteLength){
  var count = 0;
  var partialStr = "";
  for(idx=0; idx < word.length; idx++) {
    var c = word.charCodeAt(idx);      
    if (!(c >= 32 && c <= 126)) //中文
      count += 2;
    else 
      count ++;
    if (count > byteLength)
     break;
    partialStr += word.substr(idx, 1);
  }
  //return count;
  //alert("ori: "+word+", after: "+partialStr);
	return partialStr;
}

/**
 * window 客型化
 * 
 * @class HouseListInPictureAndLiteraryWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.HouseListInPictureAndLiteraryWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, extraData) {
	this.funcName = "FWUI.util.HouseListInPictureAndLiteraryWindow";
	if (extraData)
	  this.extraData = extraData;
	else
	  this.extraData = _WEBROOT + "/modules/Showroom/template/HouseListInPictureAndLiterary-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
};
FWUI.util.HouseListInPictureAndLiteraryWindow.prototype = new FWUI.util.BaseList;
FWUI.util.HouseListInPictureAndLiteraryWindow.prototype.extraLoadFiles = function() {
	// 下載 template File for each row
	if (!_STORAGEMAP[this.extraData]) {
		_key = this.extraData;
		new Ajax.Request(this.extraData, {method: 'GET', asynchronous: false, onSuccess: this.templateCallback, onFailure: this.templateCallbackFailure});
	}
};
FWUI.util.HouseListInPictureAndLiteraryWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// list data
	var listing = getHouseListData(xmlDoc, this.extraData);
	data.listing = listing;
	return data;
};
FWUI.util.HouseListInPictureAndLiteraryWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};

/**
 * 客製 list 每一筆 row 的內容
 * 每一筆資料再套用資料的 template
 */
function getHouseListData(xmlDoc, key, caseNameLen) {
	// 客製化 item 的部分
	var items = xmlDoc.getElementsByTagName('items')[0];
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var showPageItems = maxPageItems;
	var item = items.getElementsByTagName('item');
	if (maxPageItems > item.length) {
		showPageItems = item.length;
	}

	// 取出存放在 getNewsListData 裡的 template
	var str = "";
	var template =  _STORAGEMAP[key];
	for (var i = 0; i < showPageItems; i++) {
		var houseId = item[i].getElementsByTagName('houseId')[0].childNodes[0].nodeValue;
		var caseName = "";
		if (item[i].getElementsByTagName('caseName')[0].childNodes[0] != null) {
		    caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		    caseName = decodeURIComponent(caseName);
		    if (caseNameLen && caseNameLen > 0)
		      caseName = abstractStrWithChiese(caseName, caseNameLen);
		}
		//var caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		//caseName = decodeURIComponent(caseName);
		var address = "";
	    if (item[i].getElementsByTagName('address')[0].childNodes[0] != null) {
	        address = item[i].getElementsByTagName('address')[0].childNodes[0].nodeValue;
	    }
	    var positionFrom = "";
	    if (item[i].getElementsByTagName('positionFrom')[0].childNodes[0] != null) {
	        positionFrom = item[i].getElementsByTagName('positionFrom')[0].childNodes[0].nodeValue;
	    }
	    var positionTo = "";
	    if (item[i].getElementsByTagName('positionTo')[0].childNodes[0] != null) {
	        positionTo = item[i].getElementsByTagName('positionTo')[0].childNodes[0].nodeValue;
	    }
	    var sellPrice = "0";
	    if(item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue!=null&&item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue!="")
	        sellPrice = item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
	    var originTrustFee = "0";
	    if(item[i].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue!=null&&item[i].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue!="")
	        originTrustFee = item[i].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue;
	    var houseArea = "0";
	    if(item[i].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue!=null&&item[i].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue!="")
	        houseArea = item[i].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue;
	    var buildingFinishedDate = "0";
	    if (item[i].getElementsByTagName('buildingFinishedDate')[0].childNodes[0] != null) {
	        buildingFinishedDate = item[i].getElementsByTagName('buildingFinishedDate')[0].childNodes[0].nodeValue;
	    }
	    var createdDate = item[i].getElementsByTagName('createdDate')[0].childNodes[0].nodeValue;
	    var parkingSpace = "";
	    if (item[i].getElementsByTagName('parkingSpace')[0].childNodes[0] != null) {
	        parkingSpace = item[i].getElementsByTagName('parkingSpace')[0].childNodes[0].nodeValue;
	    }
	    var totalVisited = item[i].getElementsByTagName('totalVisited')[0].childNodes[0].nodeValue;
	    var totalCollected = item[i].getElementsByTagName('totalCollected')[0].childNodes[0].nodeValue;
	    var photo = "";
	    if (item[i].getElementsByTagName('photo1')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
	    }
	    else if (item[i].getElementsByTagName('photo2')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo2')[0].childNodes[0].nodeValue;
	    }
	    else if (item[i].getElementsByTagName('photo3')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo3')[0].childNodes[0].nodeValue;
	    }
	    var style = "";
	    if (item[i].getElementsByTagName('style')[0].childNodes[0] != null) {
	        style = item[i].getElementsByTagName('style')[0].childNodes[0].nodeValue;
	    }
	    var layout = "";
	    if (item[i].getElementsByTagName('layout')[0].childNodes[0] != null) {
	        layout = item[i].getElementsByTagName('layout')[0].childNodes[0].nodeValue;
	    }
	    var audio = "";
	    if (item[i].getElementsByTagName('audio')[0].childNodes[0] != null) {
	        audio = item[i].getElementsByTagName('audio')[0].childNodes[0].nodeValue;
	    }
	    var leaseFee = "";
	    if (item[i].getElementsByTagName('leaseFee')[0].childNodes[0] != null) {
	        leaseFee = item[i].getElementsByTagName('leaseFee')[0].childNodes[0].nodeValue; //XML已經轉成以元計
	    }
	    
	    //聯賣物件欄位,  "target", "partnerHouseId", "hpPhoto1s", "hpPhoto2s", "hpPhoto3s", "hpPhoto5s"
	    var target = "";
	    if (item[i].getElementsByTagName('target')[0].childNodes[0] != null) {
	        target = item[i].getElementsByTagName('target')[0].childNodes[0].nodeValue;
	    }
	    var partnerHouseId = "";
	    if (item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0] != null) {
	        partnerHouseId = item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto1s = "";
	    if (item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0] != null) {
	        hpPhoto1s = item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto2s = "";
	    if (item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0] != null) {
	        hpPhoto2s = item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto3s = "";
	    if (item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0] != null) {
	        hpPhoto3s = item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto5s = "";
	    if (item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0] != null) {
	        hpPhoto5s = item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0].nodeValue;
	    }
	    var comment = "";
	    if (item[i].getElementsByTagName('comment')[0].childNodes[0] != null) {
	        comment = item[i].getElementsByTagName('comment')[0].childNodes[0].nodeValue;
	    }
	    // 尚未完成的項目
	    var collectHouse = "#";
	    var flag = false;
	    if(sellPrice!="" && originTrustFee!="" && key.indexOf("/modules/Showroom/template/HouseListInPictureAndLiterary-Item.aspx") != -1)
	    {
	        if(parseInt(sellPrice) < parseInt(originTrustFee) && originTrustFee != "0")
	            flag = true;
	    }
	    
	    if (address != "") address = getTextImg(address);
	    if (sellPrice != "") sellPrice = getTextImg(sellPrice);
	    if (originTrustFee != "") originTrustFee = getTextImg(originTrustFee);
	    if (houseArea != "") houseArea = getTextImg(houseArea);
	    if (parkingSpace == "1") {
            var tmpImg = document.createElement('img');
            tmpImg.src = _WEBROOT + "/images/search_btm3.gif";
            tmpImg.width = "70";
            tmpImg.height = "21";
            tmpImg.border = "0";
            var tmpContainer = document.createElement('div');
            tmpContainer.appendChild(tmpImg);
            parkingSpace = tmpContainer.innerHTML;
	    }
	    //加入聯賣物件判斷
	    if (target == "" || target == "cthouse")
	    {
	      photo = getPhotoPath(photo);
	      layout = getPhotoPath(layout);
	    } else if (photo == "") { //聯賣物件無圖檔判斷
        photo = _WEBROOT + "/images/no_200x150.jpg";
      }

	    if (totalVisited == "" || totalVisited == "0") {
	        totalVisited = "";
	    } else {
	        totalVisited = "瀏覽：" + totalVisited + "人";
	    }
	    if (positionFrom != positionTo) {
	        positionFrom += "~" + positionTo;
	    }
	    if(flag)
	        sellPrice = "<img src='/Event/images/cross2.gif' style='position: absolute; z-index: 30; width:35px; height:15px;' alt='' />"+originTrustFee;
	        
        var data = { 
            houseId:houseId, caseName:caseName, address:address, positionFrom:positionFrom, positionTo:positionTo
            , sellPrice:sellPrice, houseArea:houseArea, buildingFinishedDate:buildingFinishedDate, createdDate:createdDate, parkingSpace:parkingSpace
            , totalVisited:totalVisited, totalCollected:totalCollected, photo:photo, collectHouse:collectHouse, style:style
            , leaseFee: leaseFee, layout:layout, audio:audio, index:i,
            target: target, partnerHouseId: partnerHouseId
        };
		str += template.evaluate(data);
	}
	return str;
}

/**
 * 客製 HouseList Pagebar
 */
function getHouseListPagebar(pager, func, panelId, windowId, cssSource, templateSource, xmlSource, params, flag) {
	var count = parseInt(pager.getElementsByTagName('count')[0].childNodes[0].nodeValue);
	if (count == 0) return "";
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var currentPage = parseInt(pager.getElementsByTagName('currentPage')[0].childNodes[0].nodeValue);

	var url = "";
	if (xmlSource.indexOf("?") > 0) {
		url = xmlSource.substring(0, xmlSource.indexOf("?"));
	} else {
		url = xmlSource;
	}
	url += "?nt=2&pagesize=" + maxPageItems + "&pageno=";
	//alert(url);

    var tmpContainer = document.createElement('div');
	var table = document.createElement('table');
	var tr1 = document.createElement('tr');
	var td1 = document.createElement('td');
	var tr2 = document.createElement('tr');
	var td2 = document.createElement('td');
	var div = document.createElement('div');

	tmpContainer.appendChild(table);
	table.appendChild(tr1);
	table.appendChild(tr2);
	tr1.appendChild(td1);
	tr2.appendChild(td2);
	td2.appendChild(div);

	table.setAttribute("width", "100%");
	table.setAttribute("border", "0");
	table.setAttribute("cellpadding", "0");
	table.setAttribute("cellspacing", "0");
	table.setAttribute("align", "center");
	td1.setAttribute("height", "1");
	td1.setAttribute("bgcolor", "#CCCCCC");

	div.id = "mem_page";


// 第一頁是否可點
	var first = null;
	if (currentPage == 1) {
	    first = document.createElement('span');
	} else {
	    first = document.createElement('a');
	    if (flag) {
	        first.href = "javascript:GoPage(1)";
	    } else {
	        first.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + "1','" + params + "')";
	    }
	}
	first.innerHTML = "最前頁";
	div.appendChild(first);
    div.appendChild(document.createTextNode('\u00a0'));
	// 上一頁是否可點
	var prev = null;
	if (currentPage == 1) {
	    prev = document.createElement('span');
	} else {
	    prev = document.createElement('a');
	    if (flag) {
	        prev.href = "javascript:GoPage(" + (currentPage - 1) + ")";
	    } else {
	        prev.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + (currentPage - 1) + "','" + params + "')";
	    }
	}
	prev.innerHTML = "上一頁";
	div.appendChild(prev);

	// 開始展開頁次
	var endPage = Math.floor(count / maxPageItems);
	if ((count % maxPageItems) > 0) endPage += 1;

	var prevPages = Math.floor((_PAGERSIZE - 1) / 2 + 0.5);
	if (prevPages >= currentPage) prevPages = currentPage - 1;
	if (prevPages < 0) prevPages = 0;
	
	var pageStart = currentPage - prevPages;
	if (pageStart < 1) pageStart = 1;
	if (pageStart > endPage) pageStart = endPage - _PAGERSIZE + 1;
	
	var pagetEnd = currentPage - prevPages + _PAGERSIZE - 1;
	if (pagetEnd > endPage) pagetEnd = endPage;
//	alert("endPage:" + endPage + "---pagetEnd:" + pagetEnd + "---prevPages:" + prevPages + "---currentPage:" + currentPage);
/*
	var start = (Math.floor(currentPage / _PAGERSIZE) * _PAGERSIZE) + 1;
	if ((currentPage % _PAGERSIZE) == 0) start = start - _PAGERSIZE;
	if (start > endPage) start = endPage - _PAGERSIZE + 1;
	
	var end = (Math.floor(currentPage / _PAGERSIZE) + 1) * _PAGERSIZE;
	if ((currentPage % _PAGERSIZE) == 0) end = end - _PAGERSIZE;
	if (end > endPage) end = endPage;
*/
	for (var i = pageStart; i <= pagetEnd; i++) {
	    var pageItem = null;
		if (i == currentPage) {
			pageItem = document.createElement('span');
		} else {
			pageItem = document.createElement('a');
			if (flag) {
			    pageItem.href = "javascript:GoPage(" + i + ")";
			} else {
			    pageItem.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + i + "','" + params + "')";
			}
		}
		pageItem.innerHTML = i;
		div.appendChild(document.createTextNode('\u00a0'));
		div.appendChild(pageItem);
	}

	// 下一頁是否可點
	var next = null;
	if (currentPage == endPage) {
	    next = document.createElement('span');
	} else {
	    next = document.createElement('a');
	    if (flag) {
	        next.href = "javascript:GoPage(" + (currentPage + 1) + ")";
	    } else {
	        next.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + (currentPage + 1) + "','" + params + "')";
	    }
	}
	next.innerHTML = "下一頁";
	div.appendChild(document.createTextNode('\u00a0'));
	div.appendChild(next);
    // 最後一頁是否可點
	var lastly = null;
	if (currentPage == endPage) {
	    lastly = document.createElement('span');
	} else {
	    lastly = document.createElement('a');
	    if (flag) {
	        lastly.href = "javascript:GoPage(" + endPage + ")";
	    } else {
	        lastly.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + endPage + "','" + params + "')";
	    }
	}
	lastly.innerHTML = "最後頁";
	div.appendChild(document.createTextNode('\u00a0'));
	div.appendChild(lastly);


	return tmpContainer.innerHTML;
}

function getHouseListPagebarForNews(pager, func, panelId, windowId, cssSource, templateSource, xmlSource, params, flag) {    
    var count = parseInt(pager.getElementsByTagName('count')[0].childNodes[0].nodeValue);
    if (count == 0) return "";
    var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
    var currentPage = parseInt(pager.getElementsByTagName('currentPage')[0].childNodes[0].nodeValue);

    var url = "";
    if (xmlSource.indexOf("?") > 0) {
        url = xmlSource.substring(0, xmlSource.indexOf("?"));
    } else {
        url = xmlSource;
    }
    url += "?nt=2&pagesize=" + maxPageItems + "&pageno=";
    //alert(url);

    var tmpContainer = document.createElement('div');
    var table = document.createElement('table');
    var tr1 = document.createElement('tr');
    var td1 = document.createElement('td');
    var tr2 = document.createElement('tr');
    var td2 = document.createElement('td');
    var div = document.createElement('div');

    tmpContainer.appendChild(table);
    table.appendChild(tr1);
    table.appendChild(tr2);
    tr1.appendChild(td1);
    tr2.appendChild(td2);
    td2.appendChild(div);

    table.setAttribute("width", "100%");
    table.setAttribute("border", "0");
    table.setAttribute("cellpadding", "0");
    table.setAttribute("cellspacing", "0");
    table.setAttribute("align", "center");
    td1.setAttribute("height", "1");
    td1.setAttribute("bgcolor", "#CCCCCC");

    div.id = "mem_page";
    div.align = "center";

    // 第一頁是否可點
    var first = null;
    if (currentPage == 1) {
        first = document.createElement('a');
        first.href = "#";
    } else {
        first = document.createElement('a');
        if (flag) {
            first.href = "javascript:GoPage(1)";
        } else {
            first.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + "1','" + params + "')";
        }
    }
    first.innerHTML = "最前頁";
    first.className = "pageLabel";    
    div.appendChild(first);
    div.appendChild(document.createTextNode('\u00a0'));
    // 上一頁是否可點
    var prev = null;
    if (currentPage == 1) {
        prev = document.createElement('a');
        prev.href = "#";
    } else {
        prev = document.createElement('a');
        if (flag) {
            prev.href = "javascript:GoPage(" + (currentPage - 1) + ")";
        } else {
            prev.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + (currentPage - 1) + "','" + params + "')";
        }
    }
    prev.innerHTML = "上一頁";
    prev.className = "pageLabel";
    div.appendChild(prev);

    // 開始展開頁次
    var endPage = Math.floor(count / maxPageItems);
    if ((count % maxPageItems) > 0) endPage += 1;

    var prevPages = Math.floor((_PAGERSIZE - 1) / 2 + 0.5);
    if (prevPages >= currentPage) prevPages = currentPage - 1;
    if (prevPages < 0) prevPages = 0;

    var pageStart = currentPage - prevPages;
    if (pageStart < 1) pageStart = 1;
    if (pageStart > endPage) pageStart = endPage - _PAGERSIZE + 1;

    var pagetEnd = currentPage - prevPages + _PAGERSIZE - 1;
    if (pagetEnd > endPage) pagetEnd = endPage;
    //	alert("endPage:" + endPage + "---pagetEnd:" + pagetEnd + "---prevPages:" + prevPages + "---currentPage:" + currentPage);
    /*
    var start = (Math.floor(currentPage / _PAGERSIZE) * _PAGERSIZE) + 1;
    if ((currentPage % _PAGERSIZE) == 0) start = start - _PAGERSIZE;
    if (start > endPage) start = endPage - _PAGERSIZE + 1;
	
    var end = (Math.floor(currentPage / _PAGERSIZE) + 1) * _PAGERSIZE;
    if ((currentPage % _PAGERSIZE) == 0) end = end - _PAGERSIZE;
    if (end > endPage) end = endPage;
    */
    for (var i = pageStart; i <= pagetEnd; i++) {
        var pageItem = null;
        if (i == currentPage) {
            pageItem = document.createElement('a');
            pageItem.className = "pageLabel";
            pageItem.href = "#";
        } else {
            pageItem = document.createElement('a');
            if (flag) {
                pageItem.href = "javascript:GoPage(" + i + ")";
            } else {
                pageItem.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + i + "','" + params + "')";
            }
            pageItem.className = "number";
        }
        pageItem.innerHTML = i;         
        div.appendChild(document.createTextNode('\u00a0'));
        div.appendChild(pageItem);
    }

    // 下一頁是否可點
    var next = null;
    if (currentPage == endPage) {
        next = document.createElement('a');
        next.href = "#";
    } else {
        next = document.createElement('a');
        if (flag) {
            next.href = "javascript:GoPage(" + (currentPage + 1) + ")";
        } else {
            next.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + (currentPage + 1) + "','" + params + "')";
        }
    }
    next.innerHTML = "下一頁";
    next.className = "pageLabel"; 
    div.appendChild(document.createTextNode('\u00a0'));
    div.appendChild(next);
    // 最後一頁是否可點
    var lastly = null;
    if (currentPage == endPage) {
        lastly = document.createElement('a');
        lastly.href = "#";
    } else {
        lastly = document.createElement('a');
        if (flag) {
            lastly.href = "javascript:GoPage(" + endPage + ")";
        } else {
            lastly.href = "javascript:GoPage('" + func + "','" + panelId + "','" + windowId + "','" + cssSource + "','" + templateSource + "','" + url + endPage + "','" + params + "')";
        }
    }
    lastly.innerHTML = "最後頁";
    lastly.className = "pageLabel";
    div.appendChild(document.createTextNode('\u00a0'));
    div.appendChild(lastly);


    return tmpContainer.innerHTML;
}

/**
 * window 客制化
 * 
 * @class HouseListInLiteraryWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.HouseListInLiteraryWindow = function(panelId, windowId, cssSource, templateSource, xmlSource) {
    this.funcName = "FWUI.util.HouseListInLiteraryWindow";
	this.extraData = _WEBROOT + "/modules/Showroom/template/HouseListInLiterary-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
}
FWUI.util.HouseListInLiteraryWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.HouseListInLiteraryWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params);
	return data;
};
FWUI.util.HouseListInLiteraryWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};

/**
* window 客制化
* 
* @class HouseListInPictureWindow
* @param panelId(String) window 放置 的panel id
* @param windowId(String) window id
* @param cssSource(String) css file url
* @param templateSource(String) template file url
* @param xmlSource(String) xml file url
*/
FWUI.util.HouseListInPictureWindowNews = function (panelId, windowId, cssSource, templateSource, xmlSource, params, extraData) {
    this.funcName = "FWUI.util.HouseListInPictureWindowNews";
    if (extraData)
        this.extraData = extraData;
    else
        this.extraData = _WEBROOT + "/modules/Showroom/template/HouseListInPicture-Item-News.aspx"; // url 為已知
    if (xmlSource) {
        this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
    }
};
FWUI.util.HouseListInPictureWindowNews.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.HouseListInPictureWindowNews.prototype.dataReconstitute = function (xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
    // 取得 HTML 資料
    var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
    // list data
    var listing = getHouseListInPictureDataForNews(xmlDoc, this.extraData, this.params);    
    data.listing = listing;
    return data;
};
FWUI.util.HouseListInPictureWindowNews.prototype.windowConfig = function (xmlDoc, data) {
    var pager = xmlDoc.getElementsByTagName('pager')[0];
    data.pager = getHouseListPagebarForNews(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
    
    return data;
};

/**
 * window 客制化
 * 
 * @class HouseListInPictureWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.HouseListInPictureWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params, extraData) {
	this.funcName = "FWUI.util.HouseListInPictureWindow";
	if (extraData)
	  this.extraData = extraData;
  else	
		this.extraData = _WEBROOT + "/modules/Showroom/template/HouseListInPicture-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
};
FWUI.util.HouseListInPictureWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.HouseListInPictureWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// list data
	var listing = getHouseListInPictureData(xmlDoc, this.extraData, this.params);
	data.listing = listing;
	return data;
};
FWUI.util.HouseListInPictureWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};
/**
 * 客製 list 每一筆 row 的內容
 * 每一筆資料再套用資料的 template
 */
function getHouseListInPictureData(xmlDoc, key, colNum, caseNameLen, addrLen, houseAreaFloored) {
    colNum = parseInt(colNum);
	// 客製化 item 的部分
	var items = xmlDoc.getElementsByTagName('items')[0];
	var pager = xmlDoc.getElementsByTagName('pager')[0];

	var str = "";
	var tmpContainer = document.createElement('div');
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var showPageItems = maxPageItems;
	var item = items.getElementsByTagName('item');
	if (maxPageItems > item.length) {
		showPageItems = item.length;
	}
	
	var table = document.createElement('table');
	table.width = "95%";
	table.border = "0";
	table.cellpadding = "0";
	table.cellspacing = "0";
	table.setAttribute("align", "center");

	// 取出存放在 getNewsListData 裡的 template
	var template =  _STORAGEMAP[key];
	for (var i = 0; i < showPageItems; i = i + colNum) {
		if (i > 0) {
		    var td2 = document.createElement('td');
		    td2.setAttribute("colspan", colNum);
		    td2.setAttribute("bgcolor", "#CCCCCC");
		    td2.height = "1";
		    
		    var tr2 = document.createElement('tr');
		    tr2.appendChild(td2);
		    
		    table.appendChild(tr2);
		}
		
		var tr = document.createElement('tr');
		table.appendChild(tr);

        var size = i + colNum;
		for (var j = i; j < size; j++) {
		    // 如未滿 maxPageItems，則加上空的 td 以免layout亂掉
		    if (j >= showPageItems) {
                var td = document.createElement('td');
			    td.width = "20%";
			    tr.appendChild(td);
			    continue;
		    }
		    
        var houseId = item[j].getElementsByTagName('houseId')[0].childNodes[0].nodeValue;
        var caseName = "";
		    if (item[j].getElementsByTagName('caseName')[0].childNodes[0] != null) {
		        caseName = item[j].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		        caseName = decodeURIComponent(caseName);
		        if (caseNameLen && caseNameLen > 0)
		          caseName = abstractStrWithChiese(caseName, caseNameLen);
		    }
		    //var caseName = item[j].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		    //caseName = decodeURIComponent(caseName);
		    var address = "";
        if (item[j].getElementsByTagName('address')[0].childNodes[0] != null) {
            address = item[j].getElementsByTagName('address')[0].childNodes[0].nodeValue;
        }
        var sellPrice = item[j].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
        var houseArea = item[j].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue;
        var photo = "";
        if (item[j].getElementsByTagName('photo1')[0].childNodes[0] != null) {
            photo = item[j].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
        }
        else if (item[j].getElementsByTagName('photo2')[0].childNodes[0] != null) {
            photo = item[j].getElementsByTagName('photo2')[0].childNodes[0].nodeValue;
        }
        else if (item[j].getElementsByTagName('photo3')[0].childNodes[0] != null) {
            photo = item[j].getElementsByTagName('photo3')[0].childNodes[0].nodeValue;
        }
        // 如果有 originTrustFee
        var originTrustFee = "0";
        if(item[j].getElementsByTagName('originTrustFee')[0].childNodes[0] != null)
        {
            originTrustFee = item[j].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue;
        }
        //alert(parseInt(originTrustFee));
        if (originTrustFee != "0" && parseInt(originTrustFee) > parseInt(sellPrice) && key.indexOf("/modules/Event/template/Bargain-Item.aspx")!=-1) {
            originTrustFee = sellPrice;
            sellPrice = item[j].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue;
	    }

      if (address != "")
      {
        address = decodeURIComponent(address);//getTextImg(address); //modify by Andy
        if (addrLen && addrLen > 0)
          address = abstractStrWithChiese(address, addrLen);
      }
      if (sellPrice != "") sellPrice = getTextImg(sellPrice);
      if (houseArea != "")
      {
        if (houseAreaFloored && parseFloat(houseArea) > 999)
          houseArea = ''+Math.floor(parseFloat(houseArea));
        houseArea = getTextImg(houseArea);
      }

	    //聯賣物件欄位,  "target", "partnerHouseId", "hpPhoto1s", "hpPhoto2s", "hpPhoto3s", "hpPhoto5s"
	    var target = "";
	    if (item[i].getElementsByTagName('target')[0].childNodes[0] != null) {
	        target = item[i].getElementsByTagName('target')[0].childNodes[0].nodeValue;
	    }
	    var partnerHouseId = "";
	    if (item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0] != null) {
	        partnerHouseId = item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto1s = "";
	    if (item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0] != null) {
	        hpPhoto1s = item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto2s = "";
	    if (item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0] != null) {
	        hpPhoto2s = item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto3s = "";
	    if (item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0] != null) {
	        hpPhoto3s = item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto5s = "";
	    if (item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0] != null) {
	        hpPhoto5s = item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0].nodeValue;
	    }

	    //加入聯賣物件判斷
	    if (target == "" || target == "cthouse")
	    {
        photo = getPhotoPath(photo);
	    } else if (photo == "") { //聯賣物件無圖檔判斷
        photo = _WEBROOT + "/images/no_200x150.jpg";
      }

	    var data = { 
              houseId:houseId, caseName:caseName, address:address, sellPrice:sellPrice, houseArea:houseArea
              , photo:photo, originTrustFee:originTrustFee, target: target, partnerHouseId: partnerHouseId
          };
			    
			var td = document.createElement('td');
			td.width = "20%";
			td.innerHTML = template.evaluate(data);
			tr.appendChild(td);
		}
	}
	
	tmpContainer.appendChild(table);
    return tmpContainer.innerHTML;
}

/**
* 客製 list 每一筆 row 的內容
* 每一筆資料再套用資料的 template
*/
function getHouseListInPictureDataForNews(xmlDoc, key, colNum, caseNameLen, addrLen, houseAreaFloored) {
    colNum = parseInt(colNum);
    // 客製化 item 的部分
    var items = xmlDoc.getElementsByTagName('items')[0];
    var pager = xmlDoc.getElementsByTagName('pager')[0];

    var str = "";
    var tmpContainer = document.createElement('div');
    var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
    var showPageItems = maxPageItems;
    var item = items.getElementsByTagName('item');
    if (maxPageItems > item.length) {
        showPageItems = item.length;
    }

    var table = document.createElement('table');
    table.width = "95%";
    table.border = "0";
    table.cellpadding = "0";
    table.cellspacing = "0";
    table.setAttribute("align", "center");

    // 取出存放在 getNewsListData 裡的 template
    var template = _STORAGEMAP[key];
    for (var i = 0; i < showPageItems; i = i + colNum) {
        if (i > 0) {            
            var td2 = document.createElement('td');
            td2.setAttribute("colspan", colNum);
            //td2.setAttribute("bgcolor", "#CCCCCC");
            td2.height = "1";
            var img = new Image();
            img.src = '../images/NewsImages/dotted_line.jpg';
            img.width = 1024;
            img.height = 10;
            td2.appendChild(img);

            var tr2 = document.createElement('tr');
            tr2.appendChild(td2);

            table.appendChild(tr2);
        }

        var tr = document.createElement('tr');
        table.appendChild(tr);

        var size = i + colNum;
        for (var j = i; j < size; j++) {
            // 如未滿 maxPageItems，則加上空的 td 以免layout亂掉
            if (j >= showPageItems) {
                var td = document.createElement('td');
                td.width = "20%";
                tr.appendChild(td);
                continue;
            }

            var houseId = item[j].getElementsByTagName('houseId')[0].childNodes[0].nodeValue;
            var caseName = "";
            if (item[j].getElementsByTagName('caseName')[0].childNodes[0] != null) {
                caseName = item[j].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
                caseName = decodeURIComponent(caseName);
                if (caseNameLen && caseNameLen > 0)
                    caseName = abstractStrWithChiese(caseName, caseNameLen);
            }
            //var caseName = item[j].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
            //caseName = decodeURIComponent(caseName);
            var address = "";
            if (item[j].getElementsByTagName('address')[0].childNodes[0] != null) {
                address = item[j].getElementsByTagName('address')[0].childNodes[0].nodeValue;
            }
            var sellPrice = item[j].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
            var houseArea = item[j].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue;
            var photo = "";
            if (item[j].getElementsByTagName('photo1')[0].childNodes[0] != null) {
                photo = item[j].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
            }
            else if (item[j].getElementsByTagName('photo2')[0].childNodes[0] != null) {
                photo = item[j].getElementsByTagName('photo2')[0].childNodes[0].nodeValue;
            }
            else if (item[j].getElementsByTagName('photo3')[0].childNodes[0] != null) {
                photo = item[j].getElementsByTagName('photo3')[0].childNodes[0].nodeValue;
            }
            // 如果有 originTrustFee
            var originTrustFee = "0";
            if (item[j].getElementsByTagName('originTrustFee')[0].childNodes[0] != null) {
                originTrustFee = item[j].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue;
            }
            //alert(parseInt(originTrustFee));
            if (originTrustFee != "0" && parseInt(originTrustFee) > parseInt(sellPrice) && key.indexOf("/modules/Event/template/Bargain-Item.aspx") != -1) {
                originTrustFee = sellPrice;
                sellPrice = item[j].getElementsByTagName('originTrustFee')[0].childNodes[0].nodeValue;
            }

            if (address != "") {
                address = decodeURIComponent(address); //getTextImg(address); //modify by Andy
                if (addrLen && addrLen > 0)
                    address = abstractStrWithChiese(address, addrLen);
            }
            //if (sellPrice != "") sellPrice = getTextImg(sellPrice);
            if (houseArea != "") {
                if (houseAreaFloored && parseFloat(houseArea) > 999)
                    houseArea = '' + Math.floor(parseFloat(houseArea));
                //houseArea = getTextImg(houseArea);
            }

            //聯賣物件欄位,  "target", "partnerHouseId", "hpPhoto1s", "hpPhoto2s", "hpPhoto3s", "hpPhoto5s"
            var target = "";
            if (item[i].getElementsByTagName('target')[0].childNodes[0] != null) {
                target = item[i].getElementsByTagName('target')[0].childNodes[0].nodeValue;
            }
            var partnerHouseId = "";
            if (item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0] != null) {
                partnerHouseId = item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0].nodeValue;
            }
            var hpPhoto1s = "";
            if (item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0] != null) {
                hpPhoto1s = item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0].nodeValue;
            }
            var hpPhoto2s = "";
            if (item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0] != null) {
                hpPhoto2s = item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0].nodeValue;
            }
            var hpPhoto3s = "";
            if (item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0] != null) {
                hpPhoto3s = item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0].nodeValue;
            }
            var hpPhoto5s = "";
            if (item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0] != null) {
                hpPhoto5s = item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0].nodeValue;
            }

            //加入聯賣物件判斷
            if (target == "" || target == "cthouse") {
                photo = getPhotoPath(photo);
            } else if (photo == "") { //聯賣物件無圖檔判斷
                photo = _WEBROOT + "/images/no_200x150.jpg";
            }

            var data = {
                houseId: houseId, caseName: caseName, address: address, sellPrice: sellPrice, houseArea: houseArea
              , photo: photo, originTrustFee: originTrustFee, target: target, partnerHouseId: partnerHouseId
            };

            var td = document.createElement('td');
            td.width = "20%";
            td.innerHTML = template.evaluate(data);
            tr.appendChild(td);
        }
    }    
    tmpContainer.appendChild(table);
    return tmpContainer.innerHTML;
}


/**
 * window 客制化
 * 
 * @class LayerListPhotoWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.LayerListPhotoWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, extraData) {
    this.funcName = "FWUI.util.LayerListPhotoWindow";
  if (extraData) //modify by Andy, for blog house list to specify item-template
    this.extraData = extraData;
  else
		this.extraData = _WEBROOT + "/modules/HomePage/template/LayerListPhoto-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
}
FWUI.util.LayerListPhotoWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.LayerListPhotoWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// data list
	data.listing = getLayerListPhotoData(xmlDoc, this.extraData);
	// data count
	var count = parseInt(xmlDoc.getElementsByTagName('count')[0].childNodes[0].nodeValue);
	data.count = count;
	return data;
};
FWUI.util.LayerListPhotoWindow.prototype.windowConfig = function(xmlDoc, data) {
	//var pager = xmlDoc.getElementsByTagName('pager')[0];
	//data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params);
    var prevPage = 0;
    var nextPage = 0;
    var count = parseInt(xmlDoc.getElementsByTagName('count')[0].childNodes[0].nodeValue);
    var maxPageItems = parseInt(xmlDoc.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
    var currentPage = parseInt(xmlDoc.getElementsByTagName('currentPage')[0].childNodes[0].nodeValue);
    if (count > 0) {
        if (count > (currentPage * maxPageItems)) nextPage = currentPage + 1;
        if (currentPage > 1) prevPage = currentPage - 1;
    }

    data.prevPage = prevPage;
    data.nextPage = nextPage;

	var rowNoBegin = 0;
	var rowNoEnd = 0;
	if (count > 0) {
	    rowNoBegin = (currentPage - 1) * maxPageItems + 1;
	    rowNoEnd = currentPage * maxPageItems;
	    if (rowNoBegin < 0) rowNoBegin = 0;
	    if (rowNoEnd < 0) rowNoEnd = 0;
	}

	data.rowNoBegin = rowNoBegin;
	data.rowNoEnd = rowNoEnd;

	return data;
};
function getLayerListPhotoData(xmlDoc, key, caseNameLen, addrLen, houseAreaFloored) {
	// 客製化 item 的部分
	var items = xmlDoc.getElementsByTagName('items')[0];
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var showPageItems = maxPageItems;
	var item = items.getElementsByTagName('item');
	if (maxPageItems > item.length) {
		showPageItems = item.length;
	}

	// 取出存放在 getNewsListData 裡的 template
	var str = "";
	var template =  _STORAGEMAP[key];
	for (var i = 0; i < showPageItems; i++) {
		var houseId = item[i].getElementsByTagName('houseId')[0].childNodes[0].nodeValue;
		var caseName = "";
		if (item[i].getElementsByTagName('caseName')[0].childNodes[0] != null) {
		    caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		    caseName = decodeURIComponent(caseName);
        if (caseNameLen && caseNameLen > 0)
          caseName = abstractStrWithChiese(caseName, caseNameLen);
		}
		//var caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		//caseName = decodeURIComponent(caseName);
	    var sellPrice = item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
	    var sellPriceInText = item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
	    var houseArea = item[i].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue;
	    var photo = "";
	    if (item[i].getElementsByTagName('photo1')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
	    }
	    else if (item[i].getElementsByTagName('photo2')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo2')[0].childNodes[0].nodeValue;
	    }
	    else if (item[i].getElementsByTagName('photo3')[0].childNodes[0] != null) {
	        photo = item[i].getElementsByTagName('photo3')[0].childNodes[0].nodeValue;
	    }

	    if (sellPrice != "") sellPrice = getTextImg(sellPrice);
	    if (houseArea != "")
      {
        //alert("ori: "+houseArea+", Math.floor(parseFloat(houseArea)): "+Math.floor(parseFloat(houseArea)));
        if (houseAreaFloored && parseFloat(houseArea) > 999)
          houseArea = ''+Math.floor(parseFloat(houseArea));
        //alert(houseArea);
        houseArea = getTextImg(houseArea);
      }
	    //聯賣物件欄位,  "target", "partnerHouseId", "hpPhoto1s", "hpPhoto2s", "hpPhoto3s", "hpPhoto5s"
	    var target = "";
	    if (item[i].getElementsByTagName('target')[0].childNodes[0] != null) {
	        target = item[i].getElementsByTagName('target')[0].childNodes[0].nodeValue;
	    }
	    var partnerHouseId = "";
	    if (item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0] != null) {
	        partnerHouseId = item[i].getElementsByTagName('partnerHouseId')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto1s = "";
	    if (item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0] != null) {
	        hpPhoto1s = item[i].getElementsByTagName('hpPhoto1s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto2s = "";
	    if (item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0] != null) {
	        hpPhoto2s = item[i].getElementsByTagName('hpPhoto2s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto3s = "";
	    if (item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0] != null) {
	        hpPhoto3s = item[i].getElementsByTagName('hpPhoto3s')[0].childNodes[0].nodeValue;
	    }
	    var hpPhoto5s = "";
	    if (item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0] != null) {
	        hpPhoto5s = item[i].getElementsByTagName('hpPhoto5s')[0].childNodes[0].nodeValue;
	    }
      
	    //加入聯賣物件判斷
	    if (target == "" || target == "cthouse")
	    {
        photo = getPhotoPath(photo);
	    } else if (photo == "") { //聯賣物件無圖檔判斷
        photo = _WEBROOT + "/images/no_200x150.jpg";
      }

	    var address = "";
	    if (item[i].getElementsByTagName('address')[0].childNodes[0] != null) {
	        address = decodeURIComponent(item[i].getElementsByTagName('address')[0].childNodes[0].nodeValue);
        if (addrLen && addrLen > 0)
          address = abstractStrWithChiese(address, addrLen);
	    }

      var data = { 
          houseId:houseId, caseName:caseName, address:address, sellPrice:sellPrice, houseArea:houseArea, photo:photo, sellPriceInText:sellPriceInText, target: target, partnerHouseId: partnerHouseId
      };
		str += template.evaluate(data);
	}
	// 如未滿 maxPageItems，則加上空的 td 以免layout亂掉
	for (var i = showPageItems; i < maxPageItems; i++) {
	    str += "<td width='54'></td>";
	}
	return str;
}


/**
 * window 客制化
 * 
 * @class FranchiseListWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.FranchiseListWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params) {
    this.funcName = "FWUI.util.FranchiseListWindow";
	this.extraData = _WEBROOT + "/modules/AboutCompany/template/SearchFranchise-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
}
FWUI.util.FranchiseListWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.FranchiseListWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// list data
	var listing = getFranchiseListItemsData(xmlDoc, this.extraData);
	data.listing = listing;
	return data;
};
FWUI.util.FranchiseListWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};
function getFranchiseListItemsData(xmlDoc, key) {
	// 客製化 item 的部分
	var items = xmlDoc.getElementsByTagName('items')[0];
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var showPageItems = maxPageItems;
	var item = items.getElementsByTagName('item');
	if (maxPageItems > item.length) {
		showPageItems = item.length;
	}
	
	var str = "";
	var template =  _STORAGEMAP[key];
	for (var i = 0; i < showPageItems; i++) {
		var franchiseId = "";
	    if (item[i].getElementsByTagName('franchiseId')[0].childNodes[0] != null) {
	        franchiseId = item[i].getElementsByTagName('franchiseId')[0].childNodes[0].nodeValue;
	    }
	    var franchiseName = "";
	    if (item[i].getElementsByTagName('franchiseName')[0].childNodes[0] != null) {
	        franchiseName = item[i].getElementsByTagName('franchiseName')[0].childNodes[0].nodeValue;
	    }
	    var captainName = "";
	    if (item[i].getElementsByTagName('captainName')[0].childNodes[0] != null) {
	        captainName = item[i].getElementsByTagName('captainName')[0].childNodes[0].nodeValue;
	    }
	    var franchiseTel = "";
	    if (item[i].getElementsByTagName('franchiseTel')[0].childNodes[0] != null) {
	        franchiseTel = item[i].getElementsByTagName('franchiseTel')[0].childNodes[0].nodeValue;
	    }
	    var franchiseFax = "";
	    if (item[i].getElementsByTagName('franchiseFax')[0].childNodes[0] != null) {
	        franchiseFax = item[i].getElementsByTagName('franchiseFax')[0].childNodes[0].nodeValue;
	    }
	    var countyId = "";
	    if (item[i].getElementsByTagName('countyId')[0].childNodes[0] != null) {
	        countyId = item[i].getElementsByTagName('countyId')[0].childNodes[0].nodeValue;
	    }
	    var townshipId = "";
	    if (item[i].getElementsByTagName('townshipId')[0].childNodes[0] != null) {
	        townshipId = item[i].getElementsByTagName('townshipId')[0].childNodes[0].nodeValue;
	    }
	    var address = "";
	    if (item[i].getElementsByTagName('address')[0].childNodes[0] != null) {
	        address = item[i].getElementsByTagName('address')[0].childNodes[0].nodeValue;
	    }
	    var teamNature = "";
	    if (item[i].getElementsByTagName('teamNature')[0].childNodes[0] != null) {
	        teamNature = item[i].getElementsByTagName('teamNature')[0].childNodes[0].nodeValue;
	    }
	    var email = "";
	    if (item[i].getElementsByTagName('email')[0].childNodes[0] != null) {
	        email = item[i].getElementsByTagName('email')[0].childNodes[0].nodeValue;
	    }
	    var photo1 = "";
	    if (item[i].getElementsByTagName('photo1')[0].childNodes[0] != null) {
	        photo1 = item[i].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
	    }
	    var photo2 = "";
	    if (item[i].getElementsByTagName('photo2')[0].childNodes[0] != null) {
	        photo2 = item[i].getElementsByTagName('photo2')[0].childNodes[0].nodeValue;
	    }
	    var captainMobile = "";
	    if (item[i].getElementsByTagName('captainMobile')[0].childNodes[0] != null) {
	        captainMobile = item[i].getElementsByTagName('captainMobile')[0].childNodes[0].nodeValue;
	    }
	    var captainAccountNo = "";
	    if (item[i].getElementsByTagName('captainAccountNo')[0].childNodes[0] != null) {
	        captainAccountNo = item[i].getElementsByTagName('captainAccountNo')[0].childNodes[0].nodeValue;
	    }
	    var crtDate = "";
	    if (item[i].getElementsByTagName('crtDate')[0].childNodes[0] != null) {
	        crtDate = item[i].getElementsByTagName('crtDate')[0].childNodes[0].nodeValue;
	    }
	    var comName = "";
	    if (item[i].getElementsByTagName('comName')[0].childNodes[0] != null) {
	        comName = item[i].getElementsByTagName('comName')[0].childNodes[0].nodeValue;
	    }
	    var style = "#FFFFFF";
	    if ((i % 2) == 1) style = "#EEEEEE";

        var data = { 
            franchiseId:franchiseId, franchiseName:franchiseName, captainName:captainName, franchiseTel:franchiseTel, franchiseFax:franchiseFax
            , countyId:countyId, townshipId:townshipId, address:address, teamNature:teamNature, email:email
            , photo1:photo1, photo2:photo2, captainMobile:captainMobile, captainAccountNo:captainAccountNo, crtDate:crtDate
            , comName:comName, style:style
        };
		str += template.evaluate(data);
	}
	return str;
}



function getTextImg(str) {
    var tmpImg = document.createElement('img');
    tmpImg.src = _WEBROOT + "/images/TextImg.ashx?str=" + str;
    tmpImg.align = "absmiddle";//"top";
    tmpImg.border = "0";
    var tmpContainer = document.createElement('div');
    tmpContainer.appendChild(tmpImg);
    return tmpContainer.innerHTML;
}

function getPhotoPath(photo) {
    if (photo == "") {
        photo = _WEBROOT + "/images/no_200x150.jpg";
    } else {
        photo = _HOUSE_PHOTO_PATH + photo;
    }
    return photo;
}

// HouseList頁面共用的 function
function goShowroom(form1, showroom) {
    form1.pageno.value = "";
    form1.pagesize.value = "";
    form1.refreshData.value = "1";
    form1.action = _WEBROOT + "/Showroom/HouseListIn" + showroom + ".aspx";
    form1.submit();
}



FWUI.util.RentingHouseListInPictureAndLiteraryWindow = function(panelId, windowId, cssSource, templateSource, xmlSource) {
	this.funcName = "FWUI.util.RentingHouseListInPictureAndLiteraryWindow";
	this.extraData = _WEBROOT + "/modules/Showroom/template/RentingHouseListInPictureAndLiterary-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
};
FWUI.util.RentingHouseListInPictureAndLiteraryWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;



/**
 * window 客制化
 * 
 * @class SoldHouseListInLiteraryWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.SoldHouseListInLiteraryWindow = function(panelId, windowId, cssSource, templateSource, xmlSource) {
    this.funcName = "FWUI.util.SoldHouseListInLiteraryWindow";
	this.extraData = _WEBROOT + "/modules/Showroom/template/SoldHouseListInLiterary-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
}
FWUI.util.SoldHouseListInLiteraryWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.SoldHouseListInLiteraryWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// list data
	var listing = getSoldHouseListInLiteraryData(xmlDoc, this.extraData);
	data.listing = listing;
	return data;
};
/**
 * 客製 list 每一筆 row 的內容
 * 每一筆資料再套用資料的 template
 */
function getSoldHouseListInLiteraryData(xmlDoc, key) {
	// 客製化 item 的部分
	var items = xmlDoc.getElementsByTagName('items')[0];
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	var maxPageItems = parseInt(pager.getElementsByTagName('maxPageItems')[0].childNodes[0].nodeValue);
	var showPageItems = maxPageItems;
	var item = items.getElementsByTagName('item');
	if (maxPageItems > item.length) {
		showPageItems = item.length;
	}

	// 取出存放在 getNewsListData 裡的 template
	var str = "";
	var template =  _STORAGEMAP[key];
	for (var i = 0; i < showPageItems; i++) {
		var houseId = item[i].getElementsByTagName('houseId')[0].childNodes[0].nodeValue;
		var caseName = "";
		if (item[i].getElementsByTagName('caseName')[0].childNodes[0] != null) {
		    caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		    caseName = decodeURIComponent(caseName);
		}
		//var caseName = item[i].getElementsByTagName('caseName')[0].childNodes[0].nodeValue;
		//caseName = decodeURIComponent(caseName);
		var address = "";
	    if (item[i].getElementsByTagName('address')[0].childNodes[0] != null) {
	        address = item[i].getElementsByTagName('address')[0].childNodes[0].nodeValue;
	    }
	    var sellPrice = item[i].getElementsByTagName('sellPrice')[0].childNodes[0].nodeValue;
	    var houseArea = item[i].getElementsByTagName('houseArea')[0].childNodes[0].nodeValue;
	    var landArea = item[i].getElementsByTagName('landArea')[0].childNodes[0].nodeValue;
	    var photo1 = "";
	    if (item[i].getElementsByTagName('photo1')[0].childNodes[0] != null) {
	        photo1 = item[i].getElementsByTagName('photo1')[0].childNodes[0].nodeValue;
	    }
	    var usage = "";
	    if (item[i].getElementsByTagName('totalVisited')[0].childNodes[0] != null) {
	        usage = item[i].getElementsByTagName('totalVisited')[0].childNodes[0].nodeValue;
	    }
	    var unitPrice = ""; //sold item: In WebXmlDataComposer, unitPrice is placed in ["totalCollected"]
	    if (item[i].getElementsByTagName('totalCollected')[0].childNodes[0] != null) {
	        unitPrice = item[i].getElementsByTagName('totalCollected')[0].childNodes[0].nodeValue;
	    }
	    var style = "";
	    if (item[i].getElementsByTagName('style')[0].childNodes[0] != null) {
	        style = item[i].getElementsByTagName('style')[0].childNodes[0].nodeValue;
	    }
	    var buildingFinishedDate = "";
	    if (item[i].getElementsByTagName('buildingFinishedDate')[0].childNodes[0] != null) {
	        buildingFinishedDate = item[i].getElementsByTagName('buildingFinishedDate')[0].childNodes[0].nodeValue;
	    }

	    if (address != "") address = getTextImg(address);
	    //if (unitPrice != "") unitPrice = getTextImg(unitPrice);
	    var area = parseFloat(houseArea) / 3.3058;
	    area = Math.round(area * 100) / 100;
	    houseArea = getTextImg(area);

	    var area2 = parseFloat(landArea) / 3.3058;
	    area2 = Math.round(area2 * 100) / 100;
	    landArea = getTextImg(area2);

	    //unitPrice = parseFloat(sellPrice) / area;
	    unitPrice = Math.round(unitPrice * 10) / 10;
	    unitPrice = getTextImg(unitPrice);
	    if (sellPrice != "") sellPrice = getTextImg(sellPrice);
	    var hta = item[i].getElementsByTagName('hta')[0].childNodes[0].nodeValue;
	    var htu = item[i].getElementsByTagName('htu')[0].childNodes[0].nodeValue;
	    var htc = item[i].getElementsByTagName('htc')[0].childNodes[0].nodeValue;
	    var htaName = item[i].getElementsByTagName('htaName')[0].childNodes[0].nodeValue;
	    var htuName = item[i].getElementsByTagName('htuName')[0].childNodes[0].nodeValue;
	    var htcName = item[i].getElementsByTagName('htcName')[0].childNodes[0].nodeValue;
	    //alert("htaName: "+htaName + ", htuName: "+htuName+", htcName: "+htcName);

      var data = {
          houseId:houseId, caseName:caseName, address:address, sellPrice:sellPrice, houseArea:houseArea
          , landArea:landArea, unitPrice:unitPrice, style:style, buildingFinishedDate:buildingFinishedDate, hta:hta
          , htu:htu, htc:htc, htaName:htaName, htuName:htuName, htcName:htcName
      };
		str += template.evaluate(data);
	}
	return str;
}



// 加盟店員工的所有物件
FWUI.util.FranchiseEmployeeHouseWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params) {
    this.funcName = "FWUI.util.FranchiseEmployeeHouseWindow";
	this.extraData = _WEBROOT + "/modules/Franchise/template/FranchiseEmployeeHouse-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
}
FWUI.util.FranchiseEmployeeHouseWindow.prototype = new FWUI.util.HouseListInLiteraryWindow;
FWUI.util.FranchiseEmployeeHouseWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};
// 加盟店的所有物件
FWUI.util.FranchiseHouseWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params) {
    this.funcName = "FWUI.util.FranchiseHouseWindow";
	this.extraData = _WEBROOT + "/modules/Franchise/template/FranchiseHouse-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
}
FWUI.util.FranchiseHouseWindow.prototype = new FWUI.util.HouseListInLiteraryWindow;
FWUI.util.FranchiseHouseWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};



// 搶售屋
FWUI.util.BargainWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params) {
	this.funcName = "FWUI.util.BargainWindow";
	this.extraData = _WEBROOT + "/modules/Event/template/Bargain-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
};
FWUI.util.BargainWindow.prototype = new FWUI.util.HouseListInPictureWindow;
FWUI.util.BargainWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};

//Add by Andy for Blog
/**
 * window 客制化
 * 
 * @class BlogLayerListPhotoWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.BlogLayerListPhotoWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, extraData) {
    this.funcName = "FWUI.util.LayerListPhotoWindow";
  if (extraData) //modify by Andy, for blog house list to specify item-template
    this.extraData = extraData;
  else
		this.extraData = _WEBROOT + "/modules/blog/template/LayerListPhoto-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
}
FWUI.util.BlogLayerListPhotoWindow.prototype = new FWUI.util.LayerListPhotoWindow;
FWUI.util.BlogLayerListPhotoWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// data list
	data.listing = getLayerListPhotoData(xmlDoc, this.extraData, 12, 12, true); //顯示長度 => 12 = caseNameLen, 12 = addrLen, houseAreaFloored=無條件捨去
	// data count
	var count = parseInt(xmlDoc.getElementsByTagName('count')[0].childNodes[0].nodeValue);
	data.count = count;
	return data;
};

/**
 * window 客制化
 * 
 * @class BlogHouseListInPictureWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.BlogHouseListInPictureWindow = function(panelId, windowId, cssSource, templateSource, xmlSource, params, extraData) {
	this.funcName = "FWUI.util.HouseListInBlogPictureWindow";
	if (extraData)
	  this.extraData = extraData;
  else	
		this.extraData = _WEBROOT + "/modules/Showroom/template/HouseListInPicture-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, params);
	}
};
FWUI.util.BlogHouseListInPictureWindow.prototype = new FWUI.util.HouseListInPictureWindow;
FWUI.util.BlogHouseListInPictureWindow.prototype.dataReconstitute = function(xmlDoc, panelId, windowId, cssSource, templateSource, xmlSource, params) {
	// 取得 HTML 資料
	var data = FWUI.util.getHtmlData(xmlDoc, this.windowId);
	// list data
	var listing = getHouseListInPictureData(xmlDoc, this.extraData, this.params, 12, 12, true); //顯示長度 => 12 = caseNameLen, 12 = addrLen, houseAreaFloored=無條件捨去
	data.listing = listing;
	return data;
};
FWUI.util.BlogHouseListInPictureWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};
/**
 * window 客制化
 * 
 * @class BlogHouseListInLiteraryWindow
 * @param panelId(String) window 放置 的panel id
 * @param windowId(String) window id
 * @param cssSource(String) css file url
 * @param templateSource(String) template file url
 * @param xmlSource(String) xml file url
 */
FWUI.util.BlogHouseListInLiteraryWindow = function(panelId, windowId, cssSource, templateSource, xmlSource) {
    this.funcName = "FWUI.util.BlogHouseListInLiteraryWindow";
	this.extraData = _WEBROOT + "/modules/Blog/template/HouseListInLiterary-Item.aspx"; // url 為已知
	if (xmlSource) {
		this.init(panelId, windowId, cssSource, templateSource, xmlSource, '');
	}
}
FWUI.util.BlogHouseListInLiteraryWindow.prototype = new FWUI.util.HouseListInPictureAndLiteraryWindow;
FWUI.util.BlogHouseListInLiteraryWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params);
	return data;
};
FWUI.util.BlogHouseListInLiteraryWindow.prototype.windowConfig = function(xmlDoc, data) {
	var pager = xmlDoc.getElementsByTagName('pager')[0];
	data.pager = getHouseListPagebar(pager, this.funcName, this.panelId, this.windowId, this.cssSource, this.templateSource, this.xmlSource, this.params, true);
	return data;
};

