﻿this.zUserKey='7VAp5ULHiDEyMG7iMWaEv';
// jsr_class.js
//
// JSONscriptRequest -- a simple class for making HTTP requests
// using dynamically generated script tags and JSON
//
// Author: Jason Levitt
// Date: December 7th, 2005
//
// A SECURITY WARNING FROM DOUGLAS CROCKFORD:
// "The dynamic <script> tag hack suffers from a problem. It allows a page 
// to access data from any server in the web, which is really useful. 
// Unfortunately, the data is returned in the form of a script. That script 
// can deliver the data, but it runs with the same authority as scripts on 
// the base page, so it is able to steal cookies or misuse the authorization 
// of the user with the server. A rogue script can do destructive things to 
// the relationship between the user and the base server."
//
// So, be extremely cautious in your use of this script.
//
//
// Sample Usage:
//
// <script type="text/javascript" src="jsr_class.js"></script>
// 
// function callbackfunc(jsonData) {
//      alert('Latitude = ' + jsonData.ResultSet.Result[0].Latitude + 
//            '  Longitude = ' + jsonData.ResultSet.Result[0].Longitude);
//      aObj.removeScriptTag();
// }
//
// request = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&
//            output=json&callback=callbackfunc&location=78704';
// aObj = new JSONscriptRequest(request);
// aObj.buildScriptTag();
// aObj.addScriptTag();
//
//


// Constructor -- pass a REST request URL to the constructor
//
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);
    this.scriptObj = null;
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);    
}

//一般ヘルパー
zCurrentResults = null;
var ZGeneral = function() {
    return {
        getWidth : function(node) {
	        if ( node != null )
		        return parseInt(node.style.width);
        },
        getHeight : function(node) {
	        if ( node != null )
		        return parseInt(node.style.height);
        },
        setWidth : function(node,val) {
	        if ( node != null )
		        node.style.width = val + 'px';
        },
        setHeight : function(node,val) {
	        if ( node != null )
		        node.style.height = val + 'px';
        },
        OpenInNewWindow : function( url ) {
	        var theWin = null;
                theWin = window.open( url, "ZenkeiWindow" );
		if (theWin.focus) {theWin.focus()}
        },
        OpenInNewWindowWithSize : function( url, width, height, properties ) {
	        var theWin = null;
	        if ( ( properties == null ) || ( properties.length == 0 ) ) {
	            theWin = window.open( url, "ZenkeiWindow", "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes" );
            } else if ( properties == "blank" ) {
                theWin = window.open( url, "ZenkeiWindow" );
            } else {
                theWin = window.open( url, "ZenkeiWindow", "width=" + width + ",height=" + height + "," + properties );
            }
	    if (theWin.focus) {theWin.focus()}
        },
        ShowError : function(error) {
            if ( error != null ) {
                alert( error.Title + '\n' + error.Message );
            }
        },
        getEventSource : function(e) {
            e = e || window.event;
            return e.target || e.srcElement;
        },
        LimitItemTitle : function( title ) {
            var TITLE_MAXCHARS = 19;
            if ( ( title == null ) || ( title.length < TITLE_MAXCHARS ) ) {
                return title;
            } else {
                return title.substring(0,TITLE_MAXCHARS) + "...";
            }
        },
        LimitItemTitle3Lines : function( title ) {
            var TITLE_MAXCHARS = 59;
            if ( ( title == null ) || ( title.length < TITLE_MAXCHARS ) ) {
                return title;
            } else {
                return title.substring(0,TITLE_MAXCHARS) + "...";
            }
        },
        purge : function(d) {
            var a = d.attributes, i, l, n;
            if (a) {
                l = a.length;
                for (i = 0; i < l; i += 1) {
                    n = a[i].name;
                    if (typeof d[n] === 'function') {
                        
                        d[n] = null;
                    }
                }
            }
            a = d.childNodes;
            if (a) {
                l = a.length;
                for (i = 0; i < l; i += 1) {
                    this.purge(d.childNodes[i]);
                }
            }
        },
        ClearSelection : function() {
            if (document.selection && document.selection.empty)
                document.selection.empty();
            else if (window.getSelection && window.getSelection().removeAllRanges)
                window.getSelection().removeAllRanges();
        },
        EqualArrays : function(array1, array2) {
            if (array1.length != array2.length) return false;
            for (var i = 0; i < array2.length; i++) {
                if (array1[i] != array2[i]) return false;
            }
            return true;
        },
        CreateCookie : function(name,value,days) {
	        if (days) {
		        var date = new Date();
		        date.setTime(date.getTime()+(days*24*60*60*1000));
		        var expires = "; expires="+date.toGMTString();
	        }
	        else var expires = "";
	        document.cookie = name+"="+value+expires+"; path=/";
        },
        ReadCookie : function(name) {
	        var nameEQ = name + "=";
	        var ca = document.cookie.split(';');
	        for(var i=0;i < ca.length;i++) {
		        var c = ca[i];
		        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	        }
	        return null;
        }
    };
}();

function ZBrowserIsCompatible() {
    if (!window.RegExp) return false;
    var AGENTS = ["opera","msie","safari","firefox","netscape","mozilla"];
    var agent = navigator.userAgent.toLowerCase();
    for (var i = 0; i < AGENTS.length; i++) {
        var agentStr = AGENTS[i];
        if (agent.indexOf(agentStr) != -1) {
            var versionExpr = new RegExp(agentStr + "[ \/]?([0-9]+(\.[0-9]+)?)");
            var version = 0;
            if (versionExpr.exec(agent) != null) {
                version = parseFloat(RegExp.$1);
            }
            if (agentStr == "opera") 
                return version >= 8.02;
            if (agentStr == "safari") 
                return version >= 125;
            if (agentStr == "msie") 
                return (version >= 6 &&agent.indexOf("powerpc") == -1);
            if (agentStr == "netscape") 
                return version >= 7.2;
            if (agentStr == "firefox") 
                return version >= 1.0;
            if (agentStr == "mozilla") 
                return false;
        }
    }
    return !!document.getElementById;
}

function ZUnloadGadgets() {
    if (typeof(ClearCurrentList) == 'function') {
        ClearCurrentList();
    }
    if (typeof(ClearCurrentFeatured) == 'function') {
        ClearCurrentFeatured();
    }
    if (typeof(GUnload) == 'function') {
        //MapClearOverlays();
        GUnload();
    }
}

///////////////////////////ZTabs class///////////////////////////

function ZTabs( parentDiv, instanceName ) {
    this.tabCount = 0;
    this.tabsDiv = null;
    this.AddTab = AddTab;
    this.SwitchTab = SwitchTab;
    this.panels = new Array();
    this.instanceName = instanceName;
    this.parentDiv = parentDiv;
    this.Event_TabChange = Event_TabChange;

    if ( ( parentDiv == null ) || ( instanceName == null ) ) return null;
    
	this.tabsDiv = document.createElement('div');
	this.tabsDiv.id = parentDiv.id + 'Tabs';
	this.tabsDiv.className = 'ZTabs';
	var tabsDivWidth = ZGeneral.getWidth(parentDiv);
	ZGeneral.setWidth(this.tabsDiv, tabsDivWidth);
    this.tabsDiv.innerHTML = "<ul></ul>";
	parentDiv.appendChild(this.tabsDiv);
	
    function Event_TabChange() {
        //this is meant to be overriden by ZTabs users
    }
	
	function AddTab( tabText, existingPanel ) {
	    if ( tabText == null ) return null;
        	
	    var newTabId = this.tabsDiv.id + '_Tab' + this.tabCount;
	    var newTabLinkId = newTabId + '_Link';
        
	    var index = this.tabsDiv.innerHTML.lastIndexOf("</ul>");
	    if ( index < 0 ) index = this.tabsDiv.innerHTML.lastIndexOf("</UL>"); //IE Hack
        if ( index >= 0 ) {
	        this.tabsDiv.innerHTML = this.tabsDiv.innerHTML.substring(0,index) +
	                                    "<li><a id=\"" + newTabLinkId + "\" href=\"#\" onclick=\"" + this.instanceName + ".SwitchTab(" + this.tabCount + ");return false;\">" +
	                                    "<span>" + tabText + "</span></a></li>" +
                                        this.tabsDiv.innerHTML.substring(index);
        } //絶対に<ul></ul>がある

        var newPanel;
        
        if ( ( typeof(existingPanel) != 'undefined' ) && ( existingPanel != null ) ) {
            newPanel = existingPanel;
        } else {
            newPanel = document.createElement('div');
            newPanel.id = newTabId;
            var newPanelWidth = ZGeneral.getWidth(this.tabsDiv.parentNode);
            ZGeneral.setWidth(newPanel, newPanelWidth);
        }
            
        this.panels.push(newPanel);
        this.tabCount++
        
        if ( this.tabsDiv.parentNode.childNodes.length == 1 ) { //is the first panel added
            this.SwitchTab( this.tabCount - 1);
        }

        return newPanel;
    };
        
    function SwitchTab( tabNumber ) {
        if ( this.tabCount <= tabNumber ) return false;
        
        if ( this.tabsDiv.parentNode.childNodes.length > 1 ) {
            this.tabsDiv.parentNode.removeChild( this.tabsDiv.parentNode.childNodes[1] );
        }
        
        this.tabsDiv.parentNode.appendChild(this.panels[tabNumber]);
        
        //select tab
        var lis = this.tabsDiv.getElementsByTagName("li");
        for ( i=0; i < lis.length; i++) {
            if ( tabNumber == i ) {
                lis[i].id = "current";
            } else {
                lis[i].id = "";
            }
        }
        
        this.Event_TabChange(tabNumber);
        return true;
    };
    
}

this.zFeaturedGadgetInstanceName = new Array();
this.zFeaturedGadgetInstance = new Array();
this.zFeaturedGadgetPanels = new Array();
this.zFeaturedJSONrequest = new Array();
this.zFeaturedWindowProperties = null;

function ZFeaturedGadget(featuredGadgetPanel, instanceName, autoScroll, order) {

    if ( ( featuredGadgetPanel == null ) || ( instanceName == null ) ) {
        return null;
    }
    this.Event_Clear=Event_Clear;
    this.SetRowContentsOrder = SetRowContentsOrder;
    this.AddQuery = AddQuery;
    this.AddQueries = AddQueries;
    this.DataReceived = DataReceived;
    this.ClearCurrentList = ClearCurrentList;
    this.ChangeFieldUnit = ChangeFieldUnit;
    this.ReplaceFieldValue = ReplaceFieldValue;
    this.ReplaceFieldLabel = ReplaceFieldLabel;
    this.featuredDivs = new Array();
    this.featuredGadgetPanel = featuredGadgetPanel;
    this.zFillList = zFillList;
    this.zSetAutoScrollTimeout = null;
    this.zRowsLocation = new Array();
    this.zGetRowHTML = zGetRowHTML;
    this.SetTimeBetweenScrolls = SetTimeBetweenScrolls;
    this.SetTimeBetweenRowStops = SetTimeBetweenRowStops;
    this.AutoScroll = AutoScroll;
    this.ScrollToNext = ScrollToNext;
    this.AddCustomHTMLToCell = AddCustomHTMLToCell;
    this.timeBetweenScrolls = 80; //ミリ秒
    this.timeBetweenRowStops = 2000;
    this.autoScroll = autoScroll;
    this.customHTML = "";
    this.animationTimeout = null;
    this.scrollType = 0;
    this.SetNewWindowSize = SetNewWindowSize;
    this.SetNewWindowProperties = SetNewWindowProperties;
    this.SetScrollType = SetScrollType;
    this.ShowDetailLabels = ShowDetailLabels;
    this.ShowLargeThumbnails = ShowLargeThumbnails;
    this.detailLabels = false;
    this.scrollDelta = 1;
    this.windowWidth = 0;
    this.windowHeight = 0;
    this.useLargeThumbnails = false;
    this.data = null;

    this.fieldsToOverrideRatios = new Array();
    this.fieldsToOverride = new Array();
    this.fieldsToOverrideUnits = new Array();
    this.fieldsToOverrideDecimals = new Array();
    this.fieldsToReplace = new Array();
    this.fieldsToReplaceOldValues = new Array();
    this.fieldsToReplaceNewValues = new Array();
    this.fieldsLabelToReplace = new Array();
    this.fieldsLabelToReplaceOldValues = new Array();
    this.fieldsLabelToReplaceNewValues = new Array();
    
    if ( order != null ) {
        this.featuredRowContentsOrder = order;
    } else {
        this.featuredRowContentsOrder = new Array("Thumb","Title","Address","Details");
    }
    this.index = zFeaturedGadgetInstance.length;
    
    zFeaturedGadgetInstance.push(this);
    zFeaturedGadgetInstanceName.push(instanceName);
    
    this.featuredGadgetPanel.className = 'ZFeatured';
    zFeaturedGadgetPanels.push(this.featuredGadgetPanel);
    
    featuredGadgetPanel.onmousemove=function(event) {
    
        if ( ( typeof(zFeaturedGadgetInstance) == 'undefined' )||( zFeaturedGadgetInstance == null )) return;
        
        var index = -1;
        for (var i=0; i < zFeaturedGadgetInstance.length; i++) {
            if ( zFeaturedGadgetPanels[i] == this ) {
                index = i;
                break;
            }
        }
        
        window.clearTimeout(zFeaturedGadgetInstance[index].zSetAutoScrollTimeout);
        zFeaturedGadgetInstance[index].zSetAutoScrollTimeout = null;
	    if ( typeof(zFeaturedGadgetInstance[index]) != 'undefined' ) {
        	zFeaturedGadgetInstance[index].AutoScroll(false);
	    }
    };
    featuredGadgetPanel.onmouseout=function(event) {
        
        if ( ( typeof(zFeaturedGadgetInstance) == 'undefined' )||( zFeaturedGadgetInstance == null )) return;
        
        var index = -1;
        for (var i=0; i < zFeaturedGadgetInstance.length; i++) {
            if ( zFeaturedGadgetPanels[i] == this ) {
                index = i;
                break;
            }
        }
	    if ( typeof(zFeaturedGadgetInstance[index]) != 'undefined' ) {
	        if ( zFeaturedGadgetInstance[index].zSetAutoScrollTimeout == null ) {
                zFeaturedGadgetInstance[index].zSetAutoScrollTimeout = window.setTimeout("zFeaturedGadgetInstance[" + index + "].AutoScroll(true)", 500);
	        }
	    }
    };
    
    function ShowLargeThumbnails(largeThumbs) {
        this.useLargeThumbnails = largeThumbs;
    }
    
    function ReplaceFieldValue(field, oldValue, newValue) {
        if ( (field==null) || (oldValue==null) || (newValue==null) ) return false;
        this.fieldsToReplace.push(field);
        this.fieldsToReplaceOldValues.push(oldValue);
        this.fieldsToReplaceNewValues.push(newValue);
        return true;
    }

    function ReplaceFieldLabel(field, oldValue, newValue) {
        if ((field == null) || (oldValue == null) || (newValue == null)) return false;
        this.fieldsLabelToReplace.push(field);
        this.fieldsLabelToReplaceOldValues.push(oldValue);
        this.fieldsLabelToReplaceNewValues.push(newValue);
        return true;
    }
    
    function ChangeFieldUnit(field, factor, unit, maxDecimals) {
        if ((field == null) || (factor == null) || (unit == null) || (maxDecimals == null)) return false;
        this.fieldsToOverride.push(field);
        this.fieldsToOverrideRatios.push(factor);
        this.fieldsToOverrideUnits.push(unit);
        this.fieldsToOverrideDecimals.push(Math.pow(10,maxDecimals));
        return true;
    }
    
    
    function SetScrollType(type) {
        this.scrollType = type;
    }
    
    function ShowDetailLabels(show) {
        this.detailLabels = show;
    }
    
    function SetNewWindowSize(w,h) {
        this.windowWidth = w;
        this.windowHeight = h;
    }
    
    function SetNewWindowProperties(properties) {
        zFeaturedWindowProperties = properties;
    }
         
    function SetRowContentsOrder(order) {
        if ( !ZGeneral.EqualArrays(this.featuredRowContentsOrder,order) ) {
            this.featuredRowContentsOrder = order;
        }
    }
    
    function SetTimeBetweenScrolls( time ) {
        if ( time > 0 ) { 
            this.timeBetweenScrolls = time;
        }
    }
    
    function SetTimeBetweenRowStops( time ) {
        if ( time > 0 ) { 
            this.timeBetweenRowStops = time;
        }
    }
    
    function AddCustomHTMLToCell( html ) {
        this.customHTML = html;
    }
    
    function AddQueries(queries, titles) {
        this.queries = queries;
        this.titles = titles;
        var firstQuery = null;
        var firstTitle = null;
        //reverse to use pop
        if ( this.queries != null ) {
            this.queries.reverse();
            firstQuery = this.queries.pop();
        }
        if ( this.titles != null ) {
            this.titles.reverse();
            firstTitle = this.titles.pop();
        }
        //start poping queries
        if ( firstQuery != null ) {
            this.AddQuery(firstQuery, firstTitle);
        }
    }
    
    function AutoScroll(scroll) {    
        if ( this.autoScroll && scroll && (this.animationTimeout==null)) {
            this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", this.timeBetweenScrolls);
        } else {
            window.clearTimeout(this.animationTimeout);
            this.animationTimeout = null;
        }
    }

    function Event_Clear() {
        ClearCurrentList();
    }
    
    function ClearCurrentList() {
        while (this.featuredGadgetPanel.firstChild) {
            this.featuredGadgetPanel.firstChild.onclick=null;
            this.featuredGadgetPanel.firstChild.onmouseover=null;
            this.featuredGadgetPanel.firstChild.onmouseout=null;
            this.featuredGadgetPanel.removeChild(this.featuredGadgetPanel.firstChild);
        };
        this.featuredDivs = new Array();
        this.zRowsLocation = new Array();
    }
    
    function AddQuery(bq, title) {
        if ( ( title != null ) && ( title.length > 0 ) ) {
            var titleDiv = document.createElement('div');
            titleDiv.className = 'ZFeaturedCategoryTitle';
            titleDiv.innerHTML = title;
            this.featuredGadgetPanel.appendChild(titleDiv);
        }

        var request = 'http://gadgets.zenkei.net/SaaS/items.aspx?bq=' + encodeURI(bq).replace(/\+/g, "%2B");
        request += "&key=" + zUserKey;
        request += '&callback=' + zFeaturedGadgetInstanceName[this.index] + '.DataReceived';
        
        //console.log(bq);

        zFeaturedJSONrequest[this.index] = new JSONscriptRequest(request);
        zFeaturedJSONrequest[this.index].buildScriptTag();
        zFeaturedJSONrequest[this.index].addScriptTag();
        return true;
    }
    
    function ScrollToNext() {
        if (this.autoScroll) {
            var scrollTopBefore = this.featuredGadgetPanel.scrollTop;
            
            this.featuredGadgetPanel.scrollTop += this.scrollDelta;
            
            //if reached bottom reset to 0
            if ( this.featuredGadgetPanel.scrollTop == scrollTopBefore) {
                if ( ( this.scrollType == 0 ) || ( this.scrollType == 2 ) ) {
                    this.featuredGadgetPanel.scrollTop = 0;
                } else if ( ( this.scrollType == 1 ) || ( this.scrollType == 3 ) ) {
                    this.scrollDelta = this.scrollDelta * -1;
                    this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", 
                        this.timeBetweenRowStops);
                    return false;
                }
            }
            
            if ( ( ( this.scrollType == 2 ) || ( this.scrollType == 3 ) ) ) {
                
                for (i=0; i < this.zRowsLocation.length; i++) {  
                    if ( ( this.zRowsLocation[i] == this.featuredGadgetPanel.scrollTop ) && 
                         ( this.zRowsLocation[i] > 20 ) ) {
                        this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", 
                            this.timeBetweenRowStops);
                        return false;
                    }
                }
            }
            
            this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", 
                this.timeBetweenScrolls);
        }
    }
    
    function DataReceived( data ) {
        this.data = data;
        this.zFillList( data );
        zFeaturedJSONrequest[this.index].removeScriptTag();
        //start poping queries
        if ( this.queries != null ) {
            var nextQuery = this.queries.pop();
            var nextTitle = null;
            if ( this.titles!=null ) {
                this.titles.pop();
            }
            if ( nextQuery != null ) {
                this.AddQuery(nextQuery, nextTitle);
            } else {
                if ( this.autoScroll ) {
                    this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", 1500);
                }
            }
        }
        else if ( this.autoScroll ) {
            this.animationTimeout = window.setTimeout(zFeaturedGadgetInstanceName[this.index]+".ScrollToNext()", 1500);
        }
    }
    
    function zFillList( data ) {
        if ( ( data == null ) || ( data.ResultSet == null ) ) return;
         
        var noAddress = true;
        var c=0;
        for (c=0; c < this.featuredRowContentsOrder.length; c++) {
            if ( this.featuredRowContentsOrder[c] == "Address" ) {
                noAddress = false;
                break;
            }
        }
        
        var points = data.ResultSet.Result;
        
        //override units specified by ChangeFieldUnit()
        for ( i=0; i < this.fieldsToOverride.length; i++ ) {
            for ( a=0; a < data.ResultSet.detailFields.length; a++ ) {
                if (data.ResultSet.detailFields[a] == this.fieldsToOverride[i]) {
                    data.ResultSet.detailUnits[a] = this.fieldsToOverrideUnits[i];
                    for (b=0; b < points.length; b++ ) {
                        points[b].details[a] = points[b].details[a] * this.fieldsToOverrideRatios[i];
                        points[b].details[a] = Math.round(points[b].details[a] * this.fieldsToOverrideDecimals[i]) /
                            this.fieldsToOverrideDecimals[i];
                    }
                    break;
                }
            }
        }
        
        //replace values specified by ReplaceFieldValue()
        for ( i=0; i < this.fieldsToReplace.length; i++ ) {
            for ( a=0; a < data.ResultSet.detailFields.length; a++ ) {
                if (data.ResultSet.detailFields[a] == this.fieldsToReplace[i]) {
                    for (b=0; b < points.length; b++) {
                        if (points[b].details[a] == this.fieldsToReplaceOldValues[i]) {
                            points[b].details[a] = this.fieldsToReplaceNewValues[i];
                        }
                    }
                    break;
                }
            }
        }

        //replace labels specified by ReplaceFieldLable()
        if (this.detailLabels) {
            for (i = 0; i < this.fieldsLabelToReplace.length; i++) {
                for (a = 0; a < data.ResultSet.detailFields.length; a++) {
                    if (data.ResultSet.detailFields[a].toLowerCase() == this.fieldsLabelToReplace[i].toLowerCase()) {
                        if (data.ResultSet.details[a] = this.fieldsLabelToReplaceOldValues[i]) {
                            data.ResultSet.details[a] = this.fieldsLabelToReplaceNewValues[i];
                        }
                    }
                }
            }
        }
         
        for ( i=0; i < points.length; i++ ) {
            if ( ( this.windowWidth > 0 ) && ( this.windowHeight > 0 ) ) {
                //override size in database
                points[i].PlayerWidth = this.windowWidth;
                points[i].PlayerHeight = this.windowHeight;
            }
            this.featuredDivs[i] = document.createElement('div');
            this.featuredDivs[i].className = 'ZFeaturedRow';
            this.featuredDivs[i].id = points[i].Id;
            this.featuredDivs[i].innerHTML = this.zGetRowHTML(points[i], data.ResultSet.detailUnits, data.ResultSet.details,
                data.ResultSet.detailFields, noAddress);
            this.featuredDivs[i].zPCUrl = points[i].PCUrl;
            this.featuredDivs[i].zPlayerWidth = points[i].PlayerWidth;
            this.featuredDivs[i].zPlayerHeight = points[i].PlayerHeight;
            
            //クリックされたときのイベント
            this.featuredDivs[i].onclick=function(event) {
                ZGeneral.OpenInNewWindowWithSize(this.zPCUrl, this.zPlayerWidth, this.zPlayerHeight, zFeaturedWindowProperties);
            };
            this.featuredDivs[i].onmouseover=function(event) {
                this.className = 'ZFeaturedRowSelected';
            };
            this.featuredDivs[i].onmouseout=function(event) {
                this.className = 'ZFeaturedRow';
            };

            this.featuredGadgetPanel.appendChild(this.featuredDivs[i]);
            
            if ((i == 0) || (this.featuredDivs[i].offsetTop > this.zRowsLocation[this.zRowsLocation.length - 1])) {
                if (this.featuredGadgetPanel.offsetTop != this.featuredDivs[i].offsetParent.offsetTop) {
                    this.zRowsLocation.push(this.featuredDivs[i].offsetTop - this.featuredGadgetPanel.offsetTop);
                } else {
                    this.zRowsLocation.push(this.featuredDivs[i].offsetTop);
                }
            }
        }
    }

    function zGetRowHTML(point,units,details,detailFields,noAddress) {
        if ( point == null ) return "";
        var code="";
        var c=0;
        var i=0;
        var unit="";
        for (c=0; c < this.featuredRowContentsOrder.length; c++) {
            if ( this.featuredRowContentsOrder[c] == "Thumb" ) {
                code += '<div class="ZFeaturedThumbImageWrapper">';
                code += '<img class="ZFeaturedThumbImage" src="';
                if ( ( point.ThumbnailUrl != null ) && ( point.ThumbnailUrl.length > 0 ) ) {
                    if (this.useLargeThumbnails) {
                        point.ThumbnailUrl = point.ThumbnailUrl.replace("_thumb.jpg","_largethumb.jpg");
                    }
                    code += point.ThumbnailUrl;
                } else {
                    code += "http://gadgets.zenkei.net/SaaS/images/noimage.jpg";
                }              
                code += '" alt="' + point.Id + '">';
                code += '</div>';
            } else if ( this.featuredRowContentsOrder[c] == "PlanThumb" ) {
                code += '<div class="ZFeaturedThumbImageWrapper">';
                code += '<img class="ZFeaturedThumbImage" src="';
                if ( ( point.PlanThumbnailUrl != null ) && ( point.PlanThumbnailUrl.length > 0 ) ) {
                    code += point.PlanThumbnailUrl;
                } else {
                    code += "http://gadgets.zenkei.net/SaaS/images/noimage.jpg";
                }
                code += '" alt="' + point.Id + '">'; 
                code += '</div>';
            } else if ( this.featuredRowContentsOrder[c] == "Title" ) {
                code += '<div class="ZFeaturedItemTitle"><label>' + point.Title + '</label></div>';
            } else if ( this.featuredRowContentsOrder[c] == "Address" ) {
                if ( point.details != null ) {
                    for ( i=0; i<point.details.length; i++ ) {
                        if ( detailFields[i] == "Address1" ) {
                            if ( point.details[i].length == 0) point.details[i]="&nbsp;"; //to force space
                            code += '<div class="ZFeaturedItemAddress"><label>' + point.details[i] + '</label></div>'; //住所
                            break;
                        }
                    }
                }
            } else if ( this.featuredRowContentsOrder[c] == "Details" ) {
                if ( point.details != null ) {
                    for ( i=0; i<point.details.length; i++ ) {
                        unit=units[i];
                        detail=details[i];
                        if ( (detailFields[i] != "Address1") || noAddress ) {
                            if ( point.details[i].length == 0 ) { point.details[i]="&nbsp;"; detail=""; unit=""; }
                            code += '<div class="ZFeaturedDetailCell_' + detailFields[i] + '">';
                            if ( this.detailLabels ) {
                                code += '<label class="ZLabelName">' + detail + '</label> ';
                            }   
                            code += '<label class="ZValue">' + point.details[i] + '</label>';
                            code += '<label class="ZUnit">' + unit + '</label>';
                            code += '</div>';
                        }
                    }
                }
            } else if ( this.featuredRowContentsOrder[c] == "Button" ) {
                code += '<div class="ZFeaturedDetailsButtonCell"><input type="button" class="ZButton" value="詳細" ';
                code += 'onclick="ZGeneral.OpenInNewWindowWithSize(\'' + point.PCUrl + '\', ' + point.PlayerWidth + ', ' + point.PlayerHeight + ',\'' + zFeaturedWindowProperties + '\');"></div>';
            } else if ( this.featuredRowContentsOrder[c] == "Text" ) {
                code += '<div class="ZFeaturedItemText"><label>' + point.Text + '</label></div>';
            }
        }
        
        code += this.customHTML;
        return code;
    }

}

function ClearCurrentFeatured() {
    if ( zFeaturedGadgetInstance[0] != null ) {
        zFeaturedGadgetInstance[0].AutoScroll(false);
        zFeaturedGadgetInstance[0].ClearCurrentList();
    }
}
var zSearchGadgetInstanceName = '';var zSearchGadgetForm = null;var zSearchGadgetInstance = null; var JSONrequest=null; var zSearchActiveForm = null; var zMaxResults = 100;
this.zSearchRefreshListeners = new Array();
this.zSearchClearListeners = new Array();
this.zSearchSearchStartListeners = new Array();

function ZSearchGadget( searchContainer, instanceName, htmlIndex ) { 
this.constructBaseQuery = constructBaseQuery;
this.searchContainer = searchContainer;
this.RegisterListener = RegisterListener;
this.NotifyListeners = NotifyListeners;
this.DataReceived = DataReceived;
this.SetMaxResults = SetMaxResults;
this.Event_LocationChange = Event_LocationChange;
this.StartSearch = StartSearch;
this.StartSearchWheneverTabChanged = StartSearchWheneverTabChanged;
this.SetFixedQuery = SetFixedQuery;
this.fixedQuery = '';
zSearchGadgetInstanceName = instanceName;zSearchGadgetInstance = this;if ( typeof(searchContainer.AddTab) == 'function' ) {
   this.isTabbed = true;   searchContainer.Event_TabChange = Event_TabChange;
} else { 
   this.isTabbed = false;}if ( this.searchContainer == null ) return null;
var searchTabHTMLs=new Array();
	function constructBaseQuery(form) { 

	    if ( form == null ) return "";
	    if ( form.elements.length == 0 ) return "";
	    
	    // クエリーのため
	    var bq = "";
	    var lastid = "";
	    var lasttype = "";
	    var tmpquery = "";
	    var tailquery = "";
	    
	    for(var i = 0; i < form.elements.length; i++) {
	        var type = "";
	        
            var enable = false;
	        var value = form.elements[i].value;
	        if ( ( value != null ) && ( value != "" ) ) {
	            // 処理すべきtypeをチェックする
	            type = form.elements[i].type;
	            if ( (type == 'select-one') || (type == 'hidden') ) {
	                enable = true;
	            } else if ( ((type == 'checkbox') || (type == 'radio')) && (form.elements[i].checked) ) { // checkbox, radioはチェックされた場合のみ
                    enable = true;
	            } else if ( type == 'text' ) {
                    enable = true;
	            }
	        }

	        // クエリーを構築する
	        if ( enable ) {
    	        var id = form.elements[i].id;
    	        
	            //頭のZを削除
	            if ( id.indexOf('Z') == 0 ) {
	                id = id.substring(1);
	            }
	            
	            // id名を"_"の前後に分割する
	            var idhead = "";
	            var idtail = "";
	            var pos;
	            if ( id.length >= 16 ) {
	                var idstr = id.substring(0, 16).toLowerCase();
    	            if ( (idstr == "stationtrainline") ||
                         (idstr == "station2trainlin") ) {
                        
                        idhead = "StationTrainLine";
        	            pos = id.indexOf("_");  // 最初の '_' で分割
	                    if ( pos >= 0 ) {
	                        idtail = id.substring(pos + 1);
	                    }
                    } else {
        	            pos = id.lastIndexOf("_");  // 最後の '_' で分割
	                    if ( pos >= 0 ) {
	                        idhead = id.substring(0, pos);
	                        idtail = id.substring(pos + 1);
	                    }
                    }
	            } else {
    	            pos = id.lastIndexOf("_");  // 最後の '_' で分割
	                if ( pos >= 0 ) {
	                    idhead = id.substring(0, pos);
	                    idtail = id.substring(pos + 1);
	                }
	            }

	            // select-oneの列，checkboxの列が終わっているかチェック
	            if ( (tmpquery.length > 0) && ((lasttype == 'select-one') || (lasttype == 'checkbox')) ) {
	                if ( type != lasttype ) {
                        bq += "(" + tmpquery + ")";
                        tmpquery = "";
                    }
                    else if (((idhead != "") && (idhead != lastid)) || 
                             ((idhead == "") && (id != lastid))) {
                        bq += "(" + tmpquery + ")";
                        tmpquery = "";
                    }
	            }

                if (id == 'ReturnValue') {
                    tailquery = "&returnValue=" + value;
                } else {
    	            if ( id.length >= 6 ) {
    	                var idstr = id.substring(0, 6).toLowerCase();
        	            if ( (idstr == "direct") ) {
        	                // directの場合は、そのまま埋め込む
        	                bq += value;
        	            } else {
        	                var ret = new Array(2);
	                        ret = convertToQuery( id, idhead, idtail, type, value, bq, tmpquery );   // クエリーに変換
	                        bq       = ret[0];
	                        tmpquery = ret[1];
        	            }
                    } else {
       	                var ret = new Array(2);
                        ret = convertToQuery( id, idhead, idtail, type, value, bq, tmpquery );   // クエリーに変換
                        bq       = ret[0];
                        tmpquery = ret[1];
                    }
	            }

	            lastid = id;
	            if ( idhead != "" ) {
	                lastid = idhead;
	            }
	            lasttype = type;
	        }
	    }
	    
	    // select-oneの列，checkboxの列が終わっているかチェック
	    if ( tmpquery.length > 0 ) {
            if ( (lasttype == 'select-one') || (lasttype == 'checkbox') ) {
                bq += "(" + tmpquery + ")";
            }
	    }

        bq += tailquery;
		return bq;
	}

	// 数値化できるかどうかを判別する
	// true, falseも数値化できることに注意
	function isNumber( v ) {
	    return (+v == v);
	}

	// クエリー文字列を整形して返す
	// caseZeroがtrueならば，_High，_Lowでvalueが0の場合はクエリーを作らない
	function formatString( query, id, idhead, idtail, value, caseZero ) {
	    var retQuery = query;
	    if ( !isNumber( value ) ) {
	        retQuery += '[' + id + ':' + value + ']';
	    } else if ( idtail == 'Low' ) {
	        if ( (value != 0) || !caseZero ) {
	            retQuery += '[' + idhead + '>=' + value + ']';
	        }
	    } else if ( idtail == 'High' ) {
	        if ( (value != 0) || !caseZero ) {
	            retQuery += '[' + idhead + '<=' + value + ']';
	        }
	    } else {
	        retQuery += '[' + id + '=' + value + ']';
	    }

	    return retQuery;
	}

	// クエリー文字列を作る
	function convertToQuery( id, idhead, idtail, type, value, bq, tmpquery ) {
	    
	    var ary = new Array(2);
	    ary[0] = bq; 
	    ary[1] = tmpquery;

	    switch (type) {
	        case 'select-one':
	            // 'Madori'の場合
	            if ( id == 'Madori' ) {
	                var roomcount = value.substring(0, 1);
	                var roomtype  = value.substring(1);
	                // "xLDK以上"
	                if (roomtype != 'Z') {
	                    ary[1] += "([MadoriType:" + roomtype + "][MadoriHeyakazu=" + roomcount + "])";
	                } else {
	                    ary[1] += "[MadoriHeyakazu>=" + roomcount + "]";
	                }

	            // 'Station' + 'TrainLine'の場合
	            } else if ( idhead == 'StationTrainLine' ) {
	                var station = "";
	                var line    = "";
    	            var pos = value.lastIndexOf("_");
	                if ( pos >= 0 ) {
    	                station = value.substring(0, pos);
	                    line    = value.substring(pos + 1);
                        ary[1] += "([Station:" + station + "][TrainLine:" + line + "])|([Station2:" + station + "][TrainLine2:" + line + "])";
	                }

                // それ以外の場合
	            } else if ( value != "" ) {
    	            ary[1] = formatString( tmpquery, id, idhead, idtail, value, true );
	            }
	            break;
	        case 'checkbox':
	            // checkboxの先頭かどうか
	            if ( tmpquery != "" ) {
	                ary[1] += "|";
	            }
	            
	            // 'Madori'の場合だけは特別
	            if ( idhead == 'Madori' ) {
	                var roomcount = idtail.substring(0, 1);
	                var roomtype  = idtail.substring(1);
	                // "xLDK以上"
	                if (roomtype != 'Z') {
	                    ary[1] += "([MadoriType:" + roomtype + "][MadoriHeyakazu=" + roomcount + "])";
	                } else {
	                    ary[1] += "[MadoriHeyakazu>=" + roomcount + "]";
	                }

	            // 'Station' + 'TrainLine'の場合
	            } else if ( idhead == "StationTrainLine" ) {
	                var station = "";
	                var line    = "";
    	            var pos = value.lastIndexOf("_");
	                if ( pos >= 0 ) {
    	                station = idtail.substring(0, pos);
	                    line    = idtail.substring(pos + 1);
                        ary[1] += "([Station:" + station + "][TrainLine:" + line + "])|([Station2:" + station + "][TrainLine2:" + line + "])";
	                }
	                
	            // 'Address'の場合
	            } else if ( (id == 'Address1') ||  (id == 'Address2') || (id == 'Address3') || (id == 'Address4') ) {
	                ary[1] += '[' + id + ':' + value + ']';
	                
	            // 'Lifestyle'の場合
	            } else if ( id == 'Lifestyle' ) {
	                ary[1] += '[' + id + ':' + value + ']';
	                
	            // 'MadoriHeyakazu'の場合
	            } else if ( id == 'MadoriHeyakazu' ) {
	                ary[1] += '[' + id + ':' + value + ']';
	                
	            // 'MadoriType'の場合
	            } else if ( id == 'MadoriType' ) {
	                ary[1] += '[' + id + ':' + value + ']';
                
                // それ以外の場合
	            } else { //if ( idtail != "" ) {
	                ary[1] += '[' + id + ':1]';  // valueは無視する
	            }
	            break;
	        case 'radio':
	            ary[0] = formatString( bq, id, idhead, idtail, value, true );
	            break;
	        case 'hidden':
	            // Type, SubType, Order, latitude, longitude
                ary[0] = formatString( bq, id, idhead, idtail, value, false );
    	        break;
	        case 'text':
   	            ary[0] = formatString( bq, id, idhead, idtail, "%" + value + "%", true );
	            break;
	        default:
	            break;
	    }

	    return ary;
	}

    function DataReceived( data ) {
        
        //display message
        var resultsMessage = document.getElementById("ZResultsMessage");
        
        if ( data == null ) {
            if ( resultsMessage != null ) resultsMessage.innerHTML = "データが取得できません　";
        } else if ( typeof(data.ResultSet) != 'undefined' ) {
            zCurrentResults = data;
            if ( data.ResultSet.totalResultsAvailable == 0 ) {
                if ( resultsMessage != null ) resultsMessage.innerHTML = "条件に当たる物件が見つかりません　";
            } else {
                if ( data.ResultSet.totalResultsAvailable >= zMaxResults ) {
                    if ( resultsMessage != null ) resultsMessage.innerHTML = zMaxResults + "件以上が見つかりました　";
                } else {
                    if ( resultsMessage != null ) resultsMessage.innerHTML = data.ResultSet.totalResultsAvailable + "件が見つかりました　";
                }
            }
        } else {
            
            zCurrentResults = data;
            if ( resultsMessage != null ) resultsMessage.innerHTML = "エラーが発生しました　";
        }
        
        this.NotifyListeners( "Refresh" );
        JSONrequest.removeScriptTag();
    }
    
    function SetMaxResults(max) {
        if ( max > 0 ) {
            zMaxResults =max;
        }
    }

    function RegisterListener( eventType, functionToFire ) {
        if ( eventType == "Refresh" ) {
            zSearchRefreshListeners.push(functionToFire);
        } else if ( eventType == "Clear" ) {
            zSearchClearListeners.push(functionToFire);
        } else if ( eventType == "SearchStart" ) {
            zSearchSearchStartListeners.push(functionToFire);
        }
    }

    function NotifyListeners( eventType ) {
        if ( eventType == "Refresh" ) {
            if ( zSearchRefreshListeners == null ) return;
            for (var i=0; i < zSearchRefreshListeners.length; i++) {
                window.setTimeout("zSearchRefreshListeners[" + i + "]()",1);
            }
        } else if ( eventType == "Clear" ) {
            if ( zSearchClearListeners == null ) return;
            
            for (var i=0; i < zSearchClearListeners.length; i++) {
                window.setTimeout("zSearchClearListeners[" + i + "]()",1);
            }
        } else if ( eventType == "SearchStart" ) {
            if ( zSearchSearchStartListeners == null ) return;
            for (var i=0; i < zSearchSearchStartListeners.length; i++) {
                window.setTimeout("zSearchSearchStartListeners[" + i + "]()",1);
            }
        }
    }
    
    function Event_LocationChange() {
        if (zMap == null) return;
        
        if ( zSearchActiveForm != null ) {
	        ZSearchRefreshResults(zSearchActiveForm);
	}
    }

    var StartSearchAlreadyCalled = false;
    
    function Event_TabChange(tabNumber) {
        StartSearchAlreadyCalled = false;
        
        if ( !StartSearchWheneverTabChangedFlag ) {
            if ( zSearchActiveForm != null ) {
                zSearchActiveForm = null;
                zSearchGadgetInstance.NotifyListeners("Clear");
            }
        }
        var resultsMessage = document.getElementById("ZResultsMessage");
        if ( resultsMessage != null ) {
            resultsMessage.innerHTML = "条件を指定してください　";
        }
        if ( StartSearchWheneverTabChangedFlag ) {
            if ( !StartSearchAlreadyCalled ) {
                StartSearch();
            }
        }
    }
    
    function StartSearch() {
        StartSearchAlreadyCalled　= true;
        zSearchGadgetForm=document.getElementById("ZSearchGadgetForm");
        window.setTimeout("ZSearchRefreshResults(zSearchGadgetForm)",700);
    }

    var StartSearchWheneverTabChangedFlag = false;
    function StartSearchWheneverTabChanged(change) {
        if ( change == true ) {
            StartSearchWheneverTabChangedFlag = true;
        }
    }
   
    function SetFixedQuery(query) {
        this.fixedQuery = query;
    }
}

var zPriceHigh = 0;
var zPriceLow  = 0;
var zSenyuuMensekiHigh = 0;
var zSenyuuMensekiLow  = 0;
var zTochiMensekiHigh = 0;
var zTochiMensekiLow  = 0;
function ZSearchRefreshResults(form) {

    if ( zSearchGadgetInstance.fixedQuery != '' ) { //fixed query
        window.setTimeout("ZSearchRefreshResultsImp()",1);
        return true;
    }
    
    zSearchActiveForm = form;

    if ( zSearchActiveForm.elements["ZChinryou_High"] != null && zSearchActiveForm.elements["ZChinryou_Low"] != null ) {
        if (zSearchActiveForm.elements["ZChinryou_High"].value != 0 && 
            parseInt(zSearchActiveForm.elements["ZChinryou_High"].value) - parseInt(zSearchActiveForm.elements["ZChinryou_Low"].value) < 0) {
    	    
    	    zSearchActiveForm.elements["ZChinryou_High"].value = zPriceHigh;
    	    zSearchActiveForm.elements["ZChinryou_Low"].value  = zPriceLow;
	        alert("希望 [最高] 価格が [最低] 価格以上になるように選んで下さい");
	        return false;
	    } else {
    	    zPriceHigh = zSearchActiveForm.elements["ZChinryou_High"].value;
    	    zPriceLow  = zSearchActiveForm.elements["ZChinryou_Low"].value;
	    }
	}
    if ( zSearchActiveForm.elements["ZPrice_High"] != null && zSearchActiveForm.elements["ZPrice_Low"] != null ) {
        if (zSearchActiveForm.elements["ZPrice_High"].value != 0 && 
            parseInt(zSearchActiveForm.elements["ZPrice_High"].value) - parseInt(zSearchActiveForm.elements["ZPrice_Low"].value) < 0) {

    	    zSearchActiveForm.elements["ZPrice_High"].value = zPriceHigh;
    	    zSearchActiveForm.elements["ZPrice_Low"].value  = zPriceLow;
	        alert("希望 [最高] 価格が [最低] 価格以上になるように選んで下さい");
	        return false;
	    } else {
    	    zPriceHigh = zSearchActiveForm.elements["ZPrice_High"].value
    	    zPriceLow  = zSearchActiveForm.elements["ZPrice_Low"].value
	    }
    }
    if ( zSearchActiveForm.elements["ZSenyuuMenseki_High"] != null && zSearchActiveForm.elements["ZSenyuuMenseki_Low"] != null ) {
        if (zSearchActiveForm.elements["ZSenyuuMenseki_High"].value != 0 && 
            parseInt(zSearchActiveForm.elements["ZSenyuuMenseki_High"].value) - parseInt(zSearchActiveForm.elements["ZSenyuuMenseki_Low"].value) < 0) {

    	    zSearchActiveForm.elements["ZSenyuuMenseki_High"].value = zSenyuuMensekiHigh;
    	    zSearchActiveForm.elements["ZSenyuuMenseki_Low"].value  = zSenyuuMensekiLow;
	        alert("[最高] 面積が [最低] 面積以上になるように選んで下さい");
	        return false;
	    } else {
    	    zSenyuuMensekiHigh = zSearchActiveForm.elements["ZSenyuuMenseki_High"].value
    	    zSenyuuMensekiLow  = zSearchActiveForm.elements["ZSenyuuMenseki_Low"].value
	    }
    }
    if ( zSearchActiveForm.elements["ZTochiMenseki_High"] != null && zSearchActiveForm.elements["ZTochiMenseki_Low"] != null ) {
        if (zSearchActiveForm.elements["ZTochiMenseki_High"].value != 0 && 
            parseInt(zSearchActiveForm.elements["ZTochiMenseki_High"].value) - parseInt(zSearchActiveForm.elements["ZTochiMenseki_Low"].value) < 0) {

    	    zSearchActiveForm.elements["ZTochiMenseki_High"].value = zTochiMensekiHigh;
    	    zSearchActiveForm.elements["ZTochiMenseki_Low"].value  = zTochiMensekiLow;
	        alert("[最高] 面積が [最低] 面積以上になるように選んで下さい");
	        return false;
	    } else {
    	    zTochiMensekiHigh = zSearchActiveForm.elements["ZTochiMenseki_High"].value
    	    zTochiMensekiLow  = zSearchActiveForm.elements["ZTochiMenseki_Low"].value
	    }
    }

    if (zMap != null) {
        var latLow = document.getElementById("ZLatitude_Low");
        var latHigh = document.getElementById("ZLatitude_High");
        var lngLow = document.getElementById("ZLongitude_Low");
        var lngHigh = document.getElementById("ZLongitude_High");
        
        if ( (latLow!=null) && (latHigh!=null) && (lngLow!=null) && (lngHigh!=null) ) {
        
	        var bounds = zMap.getBounds();
	        var nortEast = bounds.getNorthEast();
	        var southWest = bounds.getSouthWest();
	                
		latLow.value = southWest.lat();
		latHigh.value = nortEast.lat();
		lngLow.value = southWest.lng();
		lngHigh.value = nortEast.lng();
	}
    }


    window.setTimeout("ZSearchRefreshResultsImp()",1);
    return true;
}


function ZSearchRefreshResultsImp() {
    
    if ( zSearchGadgetInstance==null ) return;
    
    ZSetWaitingMessage();
    zSearchGadgetInstance.NotifyListeners( "SearchStart" );
    
    var bq = "";
    if ( zSearchGadgetInstance.fixedQuery == '' ) {
        bq = zSearchGadgetInstance.constructBaseQuery(zSearchActiveForm);
    } else {
        bq = zSearchGadgetInstance.fixedQuery;
    }
   
    if ( bq == "" ) {
        alert("ベースクエリが作れない");
        return false;
    }
    
    var request = 'http://gadgets.zenkei.net/SaaS/items.aspx?bq=' + encodeURI(bq).replace(/\+/g, "%2B");
    if ( request.indexOf("&maxResults") < 0 ) {
        request += "&maxResults=" + zMaxResults;
    }
    request += "&key=" + zUserKey;
    request += '&callback=' + zSearchGadgetInstanceName + '.DataReceived';
    
    //console.log(bq);

    JSONrequest = new JSONscriptRequest(request);
    JSONrequest.buildScriptTag();
    JSONrequest.addScriptTag();
    
    return true;
}

function ZSetWaitingMessage() {
    var resultsMessage = document.getElementById("ZResultsMessage");
    if ( resultsMessage != null ) {
        resultsMessage.innerHTML = "お待ちください...　<img src=\"http://gadgets.zenkei.net/SaaS/images/loader.gif\" border=0>　　";
    }
}
/*
*Based on ExtMapTypeControl Class v1.3 
*  Copyright (c) 2007, Google 
*  Author: Pamela Fox, others

*/

function GControlNotSupported() {};

if (typeof(GControl)=='undefined') {
	ExtMapTypeControl.prototype = new GControlNotSupported();
} else {
	ExtMapTypeControl.prototype = new GControl();
}


function ExtMapTypeControl(opt_opts) {
  this.options = opt_opts || {};
};
var lastMarkerLocation;
this.panorama = null;
var newsOverlays = null;


/**
 * Is called by GMap2's addOverlay method. Creates the button 
 *  and appends to the map div.
 * @param {GMap2} map The map that has had this ExtMapTypeControl added to it.
 * @return {DOM Object} Div that holds the control
 */ 
ExtMapTypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var me = this;
  var StreetViewDiv = null;
  var mapTypes = map.getMapTypes();
  var mapTypeDivs = me.addMapTypeButtons_(map);
  this.ActivateStreetView = ActivateStreetView;

  GEvent.addListener(map, "addmaptype", function() {
    var newMapTypes = map.getMapTypes();
    var newMapType = newMapTypes.pop();
    var newMapTypeDiv = me.createButton_(newMapType.getName());
    newMapTypeDiv.setAttribute('title', newMapType.getAlt());
    mapTypes.push(newMapType);
    mapTypeDivs.push(newMapTypeDiv);
    me.resetButtonEvents_(map, mapTypeDivs);
    container.appendChild(newMapTypeDiv);
  });
  GEvent.addListener(map, "removemaptype", function() {
    for (var i = 0; i < mapTypeDivs.length; i++) {
      GEvent.clearListeners(mapTypeDivs[i], "click");
      container.removeChild(mapTypeDivs[i]);
    }
    mapTypeDivs = me.addMapTypeButtons_(map);
    me.resetButtonEvents_(map, mapTypeDivs);
    for (var i = 0; i < mapTypeDivs.length; i++ ) {
      container.appendChild(mapTypeDivs[i]);
    }
  });

  if (me.options.showStreetView) {
	StreetViewDiv = me.createButton_("ｽﾄﾘｰﾄﾋﾞｭｰ");
	StreetViewDiv.setAttribute('title', 'ストリートビューを見る');
	StreetViewDiv.style.marginRight = "8px";
	StreetViewDiv.style.visibility = 'hidden';
	StreetViewDiv.firstChild.style.cssFloat = "left";
	StreetViewDiv.firstChild.style.styleFloat = "left";

	StreetViewDiv.style.visibility = 'visible';

	GEvent.addDomListener(StreetViewDiv.firstChild, "click", function() {
		HandleStreetViewClick();
	});

	me.toggleButton_(StreetViewDiv.firstChild, false);
	container.appendChild(StreetViewDiv);
  }

  if (me.options.showNews) {
	var NewsDiv = me.createButton_("地域ﾆｭｰｽ");
	NewsDiv.setAttribute('title', '地域ニュースを見る');
	NewsDiv.style.marginRight = "8px";
	NewsDiv.style.visibility = 'hidden';
	NewsDiv.firstChild.style.cssFloat = "left";
	NewsDiv.firstChild.style.styleFloat = "left";
	NewsDiv.style.visibility = 'visible';

	GEvent.addDomListener(NewsDiv.firstChild, "click", function() {
		if (!newsOverlays) {
			getLocalNews();
			
		} else {
			if ( newsOverlays != null ) {
				for (var i=0;i<newsOverlays.length;i++) {
					map.removeOverlay(newsOverlays[i]);
				}
				newsOverlays = null;
			}
		}
		me.toggleButton_(NewsDiv.firstChild, newsOverlays);
	});

	me.toggleButton_(NewsDiv.firstChild, true);
	container.appendChild(NewsDiv);
	getLocalNews();
  }

  if (me.options.showNearPlaces) {
	var NearPlacesDiv = me.createButton_("近くの物件");
	NearPlacesDiv.setAttribute('title', '近くの物件を見る');
	NearPlacesDiv.style.marginRight = "8px";
	NearPlacesDiv.style.visibility = 'hidden';
	NearPlacesDiv.firstChild.style.cssFloat = "left";
	NearPlacesDiv.firstChild.style.styleFloat = "left";
	NearPlacesDiv.style.visibility = 'visible';

	GEvent.addDomListener(NearPlacesDiv.firstChild, "click", function() {
		if (!isShowingNearPlaces) {
			//表示
			if (( nearPlacesOverlays != null )&&(nearPlacesOverlays.length>0)) {
				for (var i=0;i<nearPlacesOverlays.length;i++) {
					map.addOverlay(nearPlacesOverlays[i]);
				}
				
			} else {
				alert("近くに他の物件がありません。");
				return;
			}
		} else {
			if (( nearPlacesOverlays != null )&&(nearPlacesOverlays.length>0)) {
				for (var i=0;i<nearPlacesOverlays.length;i++) {
					map.removeOverlay(nearPlacesOverlays[i]);
				}
			}
		}
		isShowingNearPlaces = !isShowingNearPlaces;
		me.toggleButton_(NearPlacesDiv.firstChild, isShowingNearPlaces);
  	});
	isShowingNearPlaces = true;
	me.toggleButton_(NearPlacesDiv.firstChild, true);
	container.appendChild(NearPlacesDiv);

	if (( nearPlacesOverlays != null )&&(nearPlacesOverlays.length>0)) {
		for (var i=0;i<nearPlacesOverlays.length;i++) {
			map.addOverlay(nearPlacesOverlays[i]);
		}
	}
  }

  for (var i = 0; i < mapTypeDivs.length; i++ ) {
    container.appendChild(mapTypeDivs[i]);
  }

  map.getContainer().appendChild(container);

  function HandleStreetViewClick() {
	if (!overlayInstance) {
			overlayInstance = new GStreetviewOverlay();
			map.addOverlay(overlayInstance);
			if ( lastMarkerLocation == null ) {
				lastMarkerLocation = map.getCenter();
			}
			guyMarker = new GMarker(lastMarkerLocation, {icon: guyIcon, draggable: true});
			GEvent.addListener(guyMarker, "dragend", onDragEnd);
			GEvent.addListener(guyMarker, "click", openPanoramaBubble);
			map.addOverlay(guyMarker);
			var panoNode = getPanoramaViewNode();
			guyMarker.openInfoWindow(panoNode,{suppressMapPan:true});
			setTimeout("openPanoramaBubble();",500);
			if ( lastPov!= null ) {
				onYawChange(lastPov.yaw);
			} else {
				
			}
		} else {
			map.removeOverlay(overlayInstance);
			overlayInstance = null;
			map.removeOverlay(guyMarker);
			guyMarker = null;
		}
		me.toggleButton_(StreetViewDiv.firstChild, overlayInstance);
  }

  function ActivateStreetView(activate) {

	if (activate!=(overlayInstance!=null)) {
		HandleStreetViewClick()
	}
  }

  return container;
};

function showLabelDiv(thumbUrl,title,point) {
	var coords = zMap.fromLatLngToContainerPixel(point);
	coords.x = coords.x - ZGeneral.getWidth(labelDiv) / 2; coords.y = coords.y - 165;
	var shortTitle = title.substring(0,13);
	labelDiv.style.width = '170px';
	labelDiv.innerHTML='<center><img height=115 src="' + thumbUrl + '" style="padding-bottom:4px"><br>' + shortTitle;
	if ( title.length > 13 ) {
		labelDiv.innerHTML+='<center>' + title.substring(13,26);
		labelDiv.style.height = '152px';
		coords.y=coords.y-15;
		if (coords.y<-10) {coords.y=coords.y+190;}
	} else {
		labelDiv.style.height = '138px';
		if (coords.y<-10) {coords.y=coords.y+180;}
    }
    if (coords.x < 0) { coords.x = 0; }
	labelDiv.innerHTML += '</center>';
	labelDiv.style.visibility = 'visible';
	labelDiv.style.left=coords.x + 'px';
	labelDiv.style.top=coords.y + 'px';
}

function showThisPropertyLabelDiv(point) {
	var coords = zMap.fromLatLngToContainerPixel(point);
	coords.x=coords.x-28;coords.y=coords.y-65;
	labelDiv.style.width = '49px';
	labelDiv.style.height = '18px';
	labelDiv.innerHTML='<img src="../images/thisproperty.gif">';

	labelDiv.style.visibility = 'visible';
	labelDiv.style.left=coords.x + 'px';
	labelDiv.style.top=coords.y + 'px';
}

function addNewsMarkers(items) {
	for (var i = 0; i < items.length; ++i) {
		var latitude = items[i]['latitude'];
		var longitude = items[i]['longitude'];
		var thumbUrl = items[i]['thumbUrl'];
		var title = items[i]['title'];
		var description = items[i]['description'];
		var link = items[i]['link'];

		var newsIcon = new GIcon();
		newsIcon.image = "http://zenkei.net/zws/images/mapicon.png";
		newsIcon.iconSize = new GSize(20, 20);
		newsIcon.iconAnchor = new GPoint(10, 10);
		newsIcon.infoWindowAnchor = new GPoint(10, 10);

		newsOverlays[i] = new GMarker(new GPoint(longitude,latitude),newsIcon);
		newsOverlays[i].title = title;
		newsOverlays[i].thumbUrl = thumbUrl;
		newsOverlays[i].link = link;
		
		GEvent.addListener(newsOverlays[i], 'mouseover', function(point) {
			showLabelDiv(this.thumbUrl,this.title,point)
		});
		GEvent.addListener(newsOverlays[i], 'mouseout', function(point) {
			labelDiv.style.visibility = 'hidden';
		});
		GEvent.addListener(newsOverlays[i], 'click', function(point) {
			ZGeneral.OpenInNewWindow(this.link);
		});

		zMap.addOverlay(newsOverlays[i]);
	}
}

function getLocalNews() {
	if ( newsOverlays != null ) {
		for (var i=0;i<newsOverlays.length;i++) {
			zMap.removeOverlay(newsOverlays[i]);
		}
		newsOverlays = null;
	}

	if ((zMap == null)||(zMap.getZoom()<14)) return;

	//金沢の物件だけに「地域ニュース」ボタンを出す
	var distance = 0.25;
	var kanazawaCenterLat = 36.575281758;
	var kanazawaCenterLng = 136.740335152;

	var latitude = zMap.getCenter().lat();
	var longitude = zMap.getCenter().lng();
	if ((latitude < kanazawaCenterLat+distance) && (latitude > kanazawaCenterLat-distance) &&
	    (longitude < kanazawaCenterLng+distance) && (longitude > kanazawaCenterLng-distance)) {
		newsOverlays = new Array();
		var request = GetXmlHttpObject();
		var requestUrl = 'http://zenkei.net/zws/User/getLocalNews.aspx?latitude=' + latitude + '&longitude=' + longitude;
		request.onreadystatechange = function() {
			if(request.readyState == 4 && request.status == 200) {
				var parser = new SimpleXmlParser(request.responseXML);
				
				items = parser.getItems('item');

				if ( (items ==null) || (items.length == 0) ) {

				} else {
					addNewsMarkers(items);
				}
			}
		};
		request.open("GET", requestUrl, true);
		request.setRequestHeader("Content-Type", "text/xml");
	  	request.send(null);
	}
}

function GetXmlHttpObject()
{
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function onDragEnd() {
	var latlng = guyMarker.getLatLng();
	if (panorama) {
		client.getNearestPanorama(latlng, onResponse);
	}
}

function openPanoramaBubble() {
	var panoNode = getPanoramaViewNode();
	
	guyMarker.openInfoWindow(panoNode,{suppressMapPan:true});
	if (panorama!=null) {
		panorama.remove();
	}
	panorama = new GStreetviewPanorama(panoNode,{latlng:guyMarker.getLatLng(), pov:lastPov});
	if ( panorama!= null ) {
		GEvent.addListener(panorama, "newpano", onNewLocation);
		GEvent.addListener(panorama, "yawchanged", onYawChange);
		GEvent.addListener(panorama, "initialized", onPathMove);
		GEvent.addListener(panorama, "error", onPanoError);
	}
}

function getPanoramaViewNode() {
	var smallNode = document.getElementById('pano');
	if (smallNode == null) {
		smallNode = document.createElement('div');
		smallNode.style.width = '305px';
		smallNode.style.height = '234px';
		smallNode.style.padding = '5px';
		smallNode.id = 'pano';
	} else {
		
	}
	return smallNode;
}

function onPanoError(errorCode) {
	//panorama = null;
	lastMarkerLocation = guyMarker.getLatLng();
	if (errorCode==GStreetviewPanorama.ErrorValues.FLASH_UNAVAILABLE)
	{
		guyMarker.openInfoWindow("<font size=-1>Flash(TM) プラグインがインストールされてません。</font>",{suppressMapPan:true});
	}
	else
	{
		guyMarker.openInfoWindow("<center><font size=-1>ストリートビューのアイコンを<br />青いラインの上に移動してください。</font></center>",{suppressMapPan:true});
	}
}

function onNewLocation(lat, lng) {
	var latlng = new GLatLng(lat, lng);
	guyMarker.setLatLng(latlng);
}

function onYawChange(newYaw) {
  var GUY_NUM_ICONS = 16;
  var GUY_ANGULAR_RES = 360/GUY_NUM_ICONS;
  if (newYaw < 0) {
    newYaw += 360;
  }
  lastPov = panorama.getPOV();
  guyImageNum = Math.round(newYaw/GUY_ANGULAR_RES) % GUY_NUM_ICONS;
  guyImageUrl = "http://maps.gstatic.com/mapfiles/cb/man_arrow-" + guyImageNum + ".png";
  guyMarker.setImage(guyImageUrl);
}

function onResponse(response) {
  if (response.code != 200) {
//    guyMarker.setLatLng(lastMarkerLocation);
  } else {
    var latlng = new GLatLng(response.Location.lat, response.Location.lng);
    guyMarker.setLatLng(latlng);
    lastMarkerLocation = latlng;
    
  }
  openPanoramaBubble();
}

function onPathMove(streetViewLocation) {
	onNewLocation(streetViewLocation.latlng.lat(), streetViewLocation.latlng.lng());
}

/*
 * Creates buttons for map types.
 * @param {GMap2} Map object for which to create buttons.
 * @return {Array} Divs containing the buttons.
 */
ExtMapTypeControl.prototype.addMapTypeButtons_ = function(map) {
  var me = this;
  var mapTypes = map.getMapTypes();
  var mapTypeDivs = new Array();
  for (var i = 0; i < mapTypes.length; i++) {
    mapTypeDivs[i] = me.createButton_(mapTypes[i].getName());
    mapTypeDivs[i].setAttribute('title', mapTypes[i].getAlt());
  }
  me.resetButtonEvents_(map, mapTypeDivs);
  return mapTypeDivs;
};

/*
 * Ensures that map type button events are assigned correctly.
 * @param {GMap2} Map object for which to reset events.
 * @param {Array} mapTypeDivs Divs containing map type buttons.
 */
ExtMapTypeControl.prototype.resetButtonEvents_ = function(map, mapTypeDivs) {
  var me = this;
  var mapTypes = map.getMapTypes();
  for (var i = 0; i < mapTypeDivs.length; i++) {
    var otherDivs = new Array;
    for (var j = 0; j < mapTypes.length; j++ ) {
      if (j != i) {
        otherDivs.push(mapTypeDivs[j]);
      }
    }
    me.assignButtonEvent_(mapTypeDivs[i], map, mapTypes[i], otherDivs);
  }
  GEvent.addListener(map, "maptypechanged", function() {
    var divIndex = 0;
    var mapType = map.getCurrentMapType();
    for (var i = 0; i < mapTypes.length; i++) {
      if (mapTypes[i] == mapType) {
        divIndex = i;
      }
    }
    GEvent.trigger(mapTypeDivs[divIndex], "click");
  });
};

/*
 * Creates simple buttons with text nodes. 
 * @param {String} text Text to display in button
 * @return {DOM Object} The div for the button.
 */
ExtMapTypeControl.prototype.createButton_ = function(text) {
  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  buttonDiv.style.cssFloat = "left";
  buttonDiv.style.styleFloat = "left";
  var textDiv = document.createElement("div");
  textDiv.appendChild(document.createTextNode(text));
  textDiv.style.width = "6em";
  buttonDiv.appendChild(textDiv);
  return buttonDiv;
};

/*
 * Assigns events to MapType buttons to change maptype
 *  and toggle button styles correctly for all buttons
 *  when button is clicked.
 *  @param {DOM Object} div Button's div to assign click to
 *  @param {GMap2} Map object to change maptype of.
 *  @param {Object} mapType GMapType to change map to when clicked
 *  @param {Array} otherDivs Array of other button divs to toggle off
 */  
ExtMapTypeControl.prototype.assignButtonEvent_ = function(div, map, mapType, otherDivs) {
  var me = this;

  GEvent.addDomListener(div, "click", function() {
    for (var i = 0; i < otherDivs.length; i++) {
      me.toggleButton_(otherDivs[i].firstChild, false);
    }
    me.toggleButton_(div.firstChild, true);
    map.setMapType(mapType);
  });
};

/*
 * Changes style of button to appear on/off depending on boolean passed in.
 * @param {DOM Object} div  Button div to change style of
 * @param {Boolean} boolCheck Used to decide to use on style or off style
 */
ExtMapTypeControl.prototype.toggleButton_ = function(div, boolCheck) {
   div.style.fontWeight = boolCheck ? "bold" : "";
   div.style.border = "1px solid white";
   var shadows = boolCheck ? ["Top", "Left"] : ["Bottom", "Right"];
   for (var j = 0; j < shadows.length; j++) {
     div.style["border" + shadows[j]] = "1px solid #b0b0b0";
  } 
};

/*
 * Required by GMaps API for controls. 
 * @return {GControlPosition} Default location for control
 */
ExtMapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
};

/*
 * Sets the proper CSS for the given button element.
 * @param {DOM Object} button Button div to set style for
 */
ExtMapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#000000";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "0px";
  button.style.margin= "0px";
  button.style.textAlign = "center";
  button.style.fontSize = "12px"; 
  button.style.cursor = "pointer";
};

function SimpleXmlParser(xmlDoc) { // (1) pass in the DOMDocument (either created manually or from an XMLHttpRequest.responseXML)
  this.xmlDoc = xmlDoc; 
}

SimpleXmlParser.prototype.getItems = function(key) {
  var xmlDoc = this.xmlDoc;
  var items = [];
     var objNodeList = xmlDoc.getElementsByTagName(key); // (3) get the specific tags the user wants
     for (var i = 0; i < objNodeList.length; ++i) {
       var xmlItem = objNodeList.item(i);
       var item = {};
       var added = false;
       for (var j = 0; j < xmlItem.childNodes.length; ++j) {
         var child = xmlItem.childNodes.item(j);
         if (child.childNodes.length > 0) { // (4) pull out the text for the children of the main tag
           var name = child.nodeName;
           var value = child.childNodes[0].nodeValue;
           item[name] = value;
           added = true;
         }

       }
       if (added) {
         items.push(item);     
       }
     }
  return items;
}
this.zMap = null;
this.zPoints = new Array();
this.zIgnoreRefresh = false;
this.zBigMarker = null;
this.zMapSelectedListeners = new Array();
this.zMapLocationChangedListeners = new Array();
this.zShowBalloons = true;
this.zIsDisplayingThumbs = false;
this.zSelectedPoint = null;
this.zMapLoadUpLayer = null;
this.zResetIgnoreTimeout = null;
this.zMapGadgetPanel = null;
this.thumbsCheckbox = null;
this.zMapWindowWidth = 0;
this.zMapWindowHeight = 0;
this.zMapWindowProperties = null;
this.zMapFocusOnRefresh = true;
this.zIsShowingNews = false;
this.zExtControl = null;
this.zRememberLocation = false;
this.zDefaultLatitude = "36.5780410014";
this.zDefaultLongitude = "136.6477775573";
this.zDefaultZoom = 11;

if (typeof(GStreetviewClient)!='undefined') {
	this.client = new GStreetviewClient();
}
this.overlayInstance = null;

this.lastPov=null;
this.guyIcon;
this.zDetailsToShowInBalloon = new Array();
this.zDefaultIcon = null;
this.zDefaultIcons = new Array();
this.zMapTypeControl = null;
var labelDiv;
var labelDivBig;

function DefaultIcon(url, w, h, selectedUrl, detailsTable) {

    this.detailsTable = detailsTable;
    this.iconUrl = url;
    this.selectedIconUrl = selectedUrl;
    this.icon = new GIcon();
    this.icon.image = url;
    this.icon.iconSize = new GSize(w, h);
    this.icon.iconAnchor = new GPoint(w/2, h/2);
    this.icon.infoWindowAnchor = new GPoint(w/2, -5);
}

function BalloonContents(detailsTable, numberOfDetails) {
    this.detailsTable = detailsTable;
    this.numberOfDetails = numberOfDetails;
}

function ZMapGadget(mapGadgetPanel, mapTypes, showSearchBox, controlTypes, rememberLocation) {

    this.CenterAndZoom = CenterAndZoom;
    this.SetMapType = SetMapType;
    this.SetDefaultIcon = SetDefaultIcon;
    this.ShowThumbnails = ShowThumbnails;
    this.ShowBalloons = ShowBalloons;
    this.AddCustomElement = AddCustomElement;
    this.RemoveCustomElement = RemoveCustomElement;
    this.AddCustomControl = AddCustomControl;
    this.Event_Refresh = Event_Refresh;
    this.Event_Clear =Event_Clear;
    this.Event_ItemSelected = Event_ItemSelected;
    this.Event_SearchStart = Event_SearchStart;
    this.RegisterListener = RegisterListener;
    this.SetNewWindowSize = SetNewWindowSize;
    this.SetNewWindowProperties = SetNewWindowProperties;
    this.SetFocusOnFirstRefresh = SetFocusOnFirstRefresh;
    this.ShowStreetView = ShowStreetView;
    this.ShowLocalNews = ShowLocalNews;
    this.ShowDetailsInBalloon = ShowDetailsInBalloon;
    var ADDRESS_SEARCH_HEIGHT = 30;

    if (typeof (rememberLocation) != 'undefined') {
        zRememberLocation = rememberLocation;
    }
    
    if ( mapGadgetPanel == null ) return null;
    if ( showSearchBox == null ) showSearchBox = true;
    
    zMapGadgetPanel = mapGadgetPanel;
    mapGadgetPanel.id = 'ZMapGadget';
    
    if ( showSearchBox ) {
        var addressDiv = document.createElement('div');
        addressDiv.id = 'ZMapGadgetAddressSearch';
        var addressDivWidth = ZGeneral.getWidth(mapGadgetPanel);
        var addressDivHeight = ADDRESS_SEARCH_HEIGHT;
        ZGeneral.setWidth(addressDiv, addressDivWidth);
        ZGeneral.setHeight(addressDiv, addressDivHeight);
        addressDiv.style.textAlign = 'center';
        addressDiv.innerHTML = '<input name="ZAddressBox" class="ZText" id="ZAddressBox" type="text" size=26 onKeyPress="return zCheckEnter(event);">';
        addressDiv.innerHTML += '<input id="ZAddressSearchButton" class="ZButton" type="button" value="地域検索" onclick="zLaunchSearch()">';
        addressDiv.innerHTML += '　<input name="ZThumbsCheckbox" class="ZCheckbox" id="ZThumbsCheckbox" type="checkbox" value="thumbs" onclick="window.setTimeout(\'zThumbCheckClicked()\',1);">';
        addressDiv.innerHTML += '<label for="ZThumbsCheckbox">サムネイル</label>';

        mapGadgetPanel.appendChild(addressDiv);
    }
    
    var mapDiv = document.createElement('div');
    mapDiv.id = 'ZMapGadgetGoogleMap';
    var mapDivWidth = ZGeneral.getWidth(mapGadgetPanel);
    ZGeneral.setWidth(mapDiv, mapDivWidth);
    mapGadgetPanel.appendChild(mapDiv);
    
    zCreateGMap( mapTypes, mapDiv, controlTypes );
	GEvent.addDomListener(mapDiv, "DOMMouseScroll", zWheelZoom);
	GEvent.addDomListener(mapDiv, "mousewheel", zWheelZoom);
	
	var topPane = zMap.getPane(G_MAP_MAP_PANE);
    mapDiv.appendChild(topPane);
    
    zMapLoadUpLayer = document.createElement('div');
    zMapLoadUpLayer.id = 'ZMapGadgetLoadingLayer';
    zMapLoadUpLayer.style.visibility = 'hidden'; 
    zMapLoadUpLayer.style.position = 'absolute'; 
    zMapLoadUpLayer.style.left = (mapDiv.offsetLeft + (mapDiv.offsetWidth)/2 - 50) + 'px'; 
    zMapLoadUpLayer.style.top = (mapDiv.offsetTop + (mapDiv.offsetHeight)/2 - 40) + 'px'; 

    zMapLoadUpLayer.innerHTML='<table align="center" width=100><tr><td align="center"><img src="http://gadgets.zenkei.net/SaaS/images/loading.gif" alt="" /><br /><br /><label>お待ちください</label></td></tr></table>';
    ZGeneral.setWidth(zMapLoadUpLayer, 100);
    mapGadgetPanel.appendChild(zMapLoadUpLayer);
    
    thumbsCheckbox = document.getElementById("ZThumbsCheckbox");


	guyIcon = new GIcon(G_DEFAULT_ICON);
	guyIcon.image = "http://maps.gstatic.com/mapfiles/cb/man_arrow-0.png";
	guyIcon.transparent = "http://maps.gstatic.com/mapfiles/cb/man-pick.png";
	guyIcon.imageMap = [
		26,13, 30,14, 32,28, 27,28, 28,36, 18,35, 18,27, 16,26,
	        16,20, 16,14, 19,13, 22,8
	];
	guyIcon.iconSize = new GSize(49, 52);
	guyIcon.iconAnchor = new GPoint(25, 35);  // near base of guy's feet
	guyIcon.infoWindowAnchor = new GPoint(25, 5);  // top of guy's head


	labelDiv = document.createElement('div');
	labelDiv.id = 'ZTitleLabel';
	labelDiv.style.visibility = 'hidden'; 
	labelDiv.style.position = 'absolute';  
	labelDiv.style.width = '160px';
	labelDiv.style.background='#FFFFFF';
	labelDiv.style.fontSize='9pt';
	labelDiv.style.padding='5px';
	mapDiv.appendChild(labelDiv);

	labelDivBig = document.createElement('div');
	labelDivBig.id = 'ZTitleLabelBig';
	labelDivBig.style.visibility = 'hidden';
	labelDivBig.style.position = 'absolute';
	labelDivBig.style.width = '300px';
	labelDivBig.style.height = '140px';
	labelDivBig.style.background = '#FFFFFF';
	labelDivBig.style.border = 'thin solid #666666';
	labelDivBig.style.fontSize = '9pt';
	labelDivBig.style.padding = '5px';
	
	mapDiv.appendChild(labelDivBig);
    
    function SetFocusOnFirstRefresh(f) {
        zMapFocusOnRefresh = f;
    }

    function ShowDetailsInBalloon(detailsTable, numberOfFields) {
	if (numberOfFields < 1) return;
	switch (detailsTable) {
		case "saleTochi": detailsTable="M11_SALE_TOCHI"; break;
		case "saleKodate": detailsTable="M12_SALE_KODATE"; break;
		case "saleMansion": detailsTable="M13_SALE_MANSION"; break;
		case "saleAllBuilding": detailsTable="M14_SALE_ALLBUILDING"; break;
		case "salePartBuilding": detailsTable="M15_SALE_PARTBUILDING"; break;
		case "rentResidence": detailsTable="M16_RENT_RESIDENCE"; break;
		case "rentBusiness": detailsTable="M17_RENT_BUSINESS"; break;
	}
	var balloonContents = new BalloonContents(detailsTable, numberOfFields);
	zDetailsToShowInBalloon.push(balloonContents);
    }

    function ShowLocalNews(show) {
	zIsShowingNews = show;
	if (show) {
		getLocalNews();
	}
    }

    function ShowStreetView(show,activate) {
	if (show==false) return;

	if (G_API_VERSION < "200") return;

	zExtControl = new ExtMapTypeControl({showStreetView:true, showNearPlaces:false, showNews: false});
	zMap.addControl(zExtControl);
	if (zMapTypeControl!=null){
		zMap.removeControl(zMapTypeControl);
	}
	if (activate) {
		zExtControl.ActivateStreetView(true);
	}
    }
    
    function SetNewWindowSize(w,h) {
        zMapWindowWidth = w;
        zMapWindowHeight = h;
    }
    
    function SetNewWindowProperties(properties) {
        zMapWindowProperties = properties;
    }

    function SetDefaultIcon(url, w, h, selectedUrl, detailsTable) {
        if ( ( url == null ) || ( w == null ) || ( h == null ) ) return;
        
	
        //キャッシュカスタムアイコン
        var iconCash = new Image(w, h);
        iconCash.src = url;
        var iconSelectedCash = new Image(w, h);
        iconSelectedCash.src = selectedUrl;

        if ((typeof(detailsTable)=='undefined')||(detailsTable==null)) {
		//global icon
	        zDefaultIcon = new DefaultIcon(url, w, h, selectedUrl, null);
	} else {
		//icon for each details table
		switch (detailsTable) {
			case "saleTochi": detailsTable="M11_SALE_TOCHI"; break;
			case "saleKodate": detailsTable="M12_SALE_KODATE"; break;
			case "saleMansion": detailsTable="M13_SALE_MANSION"; break;
			case "saleAllBuilding": detailsTable="M14_SALE_ALLBUILDING"; break;
			case "salePartBuilding": detailsTable="M15_SALE_PARTBUILDING"; break;
			case "rentResidence": detailsTable="M16_RENT_RESIDENCE"; break;
			case "rentBusiness": detailsTable="M17_RENT_BUSINESS"; break;
		}
		var defaultIcon = new DefaultIcon(url, w, h, selectedUrl, detailsTable);
		zDefaultIcons.push(defaultIcon);
	}
    }
    
    function ShowThumbnails( show ) {
        thumbsCheckbox = document.getElementById("ZThumbsCheckbox");
        zIsDisplayingThumbs = show;
        if ( thumbsCheckbox != null ) {
            thumbsCheckbox.checked = show;
        }
    }
    
    function ShowBalloons( show ) {
        zShowBalloons = show;
    }
    
    function GetPosition( positionBase, x, y ) {
        var pos = null;
        if ( positionBase == "BOTTOM_LEFT" ) {
            pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(x,y));
        } else if ( positionBase == "BOTTOM_RIGHT" ) {
            pos = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(x,y));
        } else if ( positionBase == "TOP_LEFT" ) {
            pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));
        } else {
            pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
        }
        return pos;
    }
    
    function AddCustomElement( element, positionBase, x, y ) {
        if ( ( element==null ) || ( positionBase==null ) || 
             ( x==null ) || ( y==null ) ) return false;
        var pos = GetPosition( positionBase, x, y );
        pos.apply(element);
        zMap.getContainer().appendChild(element);
        return true;
    }
    
    function RemoveCustomElement( element ) {
        zMap.getContainer().removeChild(element);
    }
    
    function AddCustomControl( control,positionBase, x, y ) {
        var pos = GetPosition( positionBase, x, y );
        zMap.addControl(control,pos);
    }

    function CenterAndZoom( longitude, latitude, zoomLevel ) {

        if ( zMap == null ) return;
        if ( ( latitude == "" ) || ( longitude == "" ) ) {
	        return false;
	    }
	    
	    if (zRememberLocation) {
	        if (LoadLocationFromCookie()) {
	            return;
	        }
	    }
	    
	    zMap.setCenter(new GLatLng(latitude, longitude), 17 - zoomLevel);
        return true;
    }

   
    function SetMapType( mapType ) {
        if ( zMap == null ) return;
        
        if ( mapType == "SATELLITE" ) {
		    zMap.setMapType(G_SATELLITE_MAP);
        } else if ( mapType == "HYBRID" ) {
		    zMap.setMapType(G_HYBRID_MAP);
        } else {
		    zMap.setMapType(G_NORMAL_MAP);
        }
    }

    function Event_Refresh() {
        if ( zMap == null ) return;
        if ( zCurrentResults != null ) {
            if ( typeof(zCurrentResults.ResultSet) != 'undefined' ) {
                window.setTimeout("zFillMap()",1);
                zMapGadgetPanel.style.visibility='visible'; //ensure visibility

                if ( zMapFocusOnRefresh ) {                    
                    zMapGadgetPanel.focus();
                    zMapFocusOnRefresh = true;
                }
                ZGeneral.ClearSelection();
            } else if ( typeof(zCurrentResults.Error) != 'undefined' ) {
                ZGeneral.ShowError( zCurrentResults.Error );
            } else {
                //items.aspxおかしい
            }
        }   
    }

    function Event_Clear() {
        //clear all        
	    MapClearOverlays();
    }
    
    function Event_SearchStart() {
        zIgnoreRefresh = true;
        for ( i=0; i < zPoints.length; i++ ) {
            if ( zPoints[i]!=null ) zPoints[i].hide();
        }
        if ( zBigMarker != null ) zBigMarker.hide();
        if ( zShowBalloons ) {
            zMap.closeInfoWindow();    
        }
        zMapLoadUpLayer.style.visibility = 'visible'; 
        if ( zResetIgnoreTimeout != null ) {
		    window.clearTimeout(zResetIgnoreTimeout);
		}
        zResetIgnoreTimeout = window.setTimeout("zResetIgnoreRefresh()",1000);
    }

    function Event_ItemSelected( item ) {
        
        if ( zMap == null ) return;
        if ( item != null ) {
            for (i=0; i < zPoints.length; i++) {
                if ( zPoints[i].id == item ) {
                    zIgnoreRefresh = true;
                    var point = zPoints[i].getPoint();
                    
                    zPoints[i].Select(false);
		            if ( zResetIgnoreTimeout != null ) {
		                window.clearTimeout(zResetIgnoreTimeout);
		            }
                    zResetIgnoreTimeout = window.setTimeout("zResetIgnoreRefresh()",1200);
		            return;
                }
            } 
        }
        
        //リストで選択された物件は位置情報がない
        if ( item != null ) {
            alert("選択された物件は位置情報がありません。");
        }
        
        //return to default icon (if set)
        if ( zIsDisplayingThumbs ) {
            if ( zBigMarker != null ) {
                ZPurgeMarker(zBigMarker);
                zMap.removeOverlay(zBigMarker);
            }
        } else if ( defaultIcon != null ) {
            if ( zSelectedPoint != null ) {
                zSelectedPoint.setImage(defaultIcon.iconUrl);
            }
        }
        if ( zShowBalloons ) {
            zMap.closeInfoWindow();    
        }
    }

    function RegisterListener( eventType, functionToFire ) {
	    if ( eventType == "Select" ) {
	        zMapSelectedListeners.push(functionToFire);
	    } else if ( eventType == "LocationChange" ) {
	        zMapLocationChangedListeners.push(functionToFire);
	    }
    }
}
function MapClearOverlays() {
    if ( zMap== null ) return;
    
    while ( zPoints.length > 0 ) {
        var marker = zPoints.pop();
        ZPurgeMarker(marker);
    }
    
    if ( zIsDisplayingThumbs ) {
        if ( zBigMarker != null ) {
            ZPurgeMarker(zBigMarker);
            zMap.removeOverlay(zBigMarker);
        }
    }
    ZPurgeMarker(zSelectedPoint);
    zSelectedPoint=null;
    
    MapNotifyListeners("Select", null);
    zMap.clearOverlays();

    //remove street view if present
    if (zExtControl!=null) {
	zExtControl.ActivateStreetView(false);
    }
}

function LoadLocationFromCookie() {
    var cookieValue = ZGeneral.ReadCookie("ZLastLocation");
    if ((cookieValue != null) && (cookieValue.length > 0)) {
        var array = cookieValue.split(",");
        if ((array != null) && (array.length == 3)) {
            zMap.setCenter(new GLatLng(array[0], array[1]), array[2]*1);
            return true;
        }
    }
    return false;
}

function ZPurgeMarker(marker) {
    if ( marker != null ) {
        GEvent.clearListeners( marker,"click" );
        marker = null;
    }
}

function MapNotifyListeners( eventType, data, data2 ) {
    if ( eventType == "Select" ) {
        if ( zMapSelectedListeners == null ) return;
        for (var i=0; i < zMapSelectedListeners.length; i++) {
            zMapSelectedListeners[i](data,data2);
        }
    } else if ( eventType == "LocationChange" ) {
        if ( zMapLocationChangedListeners == null ) return;
        for (var i=0; i < zMapLocationChangedListeners.length; i++) {
            window.setTimeout("zMapLocationChangedListeners[" + i + "]()",1);
        }
    }
}

if ( typeof(GMarker) != 'undefined' ) {
    GMarker.prototype.id = "";
    GMarker.prototype.windowHTML="";
    GMarker.prototype.index=0;
    GMarker.prototype.zMap = null;
    GMarker.prototype.thumbImage = null;
    GMarker.prototype.zIconUrl = null;
    GMarker.prototype.zSelectedIconUrl = null;
    GMarker.prototype.PCUrl = null;
    GMarker.prototype.Initialize = function(zMap, isThumb) {
        if (zMap == null) return;

        this.zMap = zMap;
        GEvent.addListener(this, 'mouseover', function(point) {
            if (zBigMarker != null) {
                ZPurgeMarker(zBigMarker);
                zMap.removeOverlay(zBigMarker);
            }
            if (isThumb == true) {
                var icon = new GIcon(this.getIcon());
                icon.iconAnchor = new GPoint(45, 35);
                icon.infoWindowAnchor = new GPoint(45, -5);
                icon.iconSize = new GSize(90, 70);
                zBigMarker = new GMarker(this.getPoint(), { zIndexProcess: zOrderOfCreation, icon: icon });
                zBigMarker.id = this.id;
                zBigMarker.windowHTML = this.windowHTML;
                zBigMarker.index = this.index;
                zBigMarker.PCUrl = this.PCUrl;

                GEvent.addListener(zBigMarker, 'mouseout', function(overlay, point) {
                    if (zBigMarker != null) {
                        setTimeout("zMap.removeOverlay(zBigMarker);ZPurgeMarker(this);", 1);

                    }
                });
                zMap.addOverlay(zBigMarker);


                if (this.thumbImage != null) {
                    zBigMarker.setImage(this.thumbImage);
                }

            } else if (zShowBalloons) {

                if (this.windowHTML != null) {
                    showLabelDivBig(this.windowHTML, point);
                    //this.openInfoWindowHtml(this.windowHTML, {suppressMapPan:true});
                }
            }

        });

        GEvent.addListener(this, 'mouseout', function(point) {
            if (zShowBalloons) {
                labelDivBig.style.visibility = 'hidden';
                //zMap.closeInfoWindow();
            }
        });
    }
    GMarker.prototype.Select=function(suppressMapPan) {
    
        
        if ( zIsDisplayingThumbs ) {
            GEvent.trigger(this,'mouseover');
        } else if ( this.zSelectedIconUrl != null ) {
            if (( zSelectedPoint != null ) && ( zSelectedPoint.zIconUrl != null )) {
                zSelectedPoint.setImage(zSelectedPoint.zIconUrl);
            }
            //bring to front
            zMap.removeOverlay(this);
            
            var icon = new GIcon(this.getIcon());
            icon.image = this.zSelectedIconUrl;
            
            zSelectedPoint = new GMarker( this.getPoint(),{zIndexProcess:zOrderOfCreation, icon:icon});
	    zSelectedPoint.Initialize(zMap, false);
            zSelectedPoint.id = this.id;
            zSelectedPoint.windowHTML = this.windowHTML;
            zSelectedPoint.index = this.index;
            zSelectedPoint.zIconUrl = this.zIconUrl;
            zSelectedPoint.zSelectedIconUrl = this.zSelectedIconUrl;
	    zSelectedPoint.PCUrl = this.PCUrl;
            zPoints[this.index] = zSelectedPoint;
            zMap.addOverlay(zSelectedPoint);
	    }
	    if ( zShowBalloons ) {

            if (zMapGadgetPanel.parentNode != null) {
                if ((typeof (suppressMapPan) != 'undefined') && (suppressMapPan == true)) {
                    showLabelDivBig(this.windowHTML, this.getPoint());
			        zMap.setCenter(this.getPoint());
		        } else if ((this.windowHTML != null) && (this.windowHTML.length > 0)) {
		            showLabelDivBig(this.windowHTML, this.getPoint());
		        }
            } else {
		        showLabelDivBig(this.windowHTML, this.getPoint());
            }
        }
    }
    G_NORMAL_MAP.getName = function(shortName) {
        if(shortName) {return "地図"}
        return "地図";
    }

    G_SATELLITE_MAP.getName = function(shortName) {
        if(shortName) {return "衛星"}
        return "衛星写真";
    }

    G_HYBRID_MAP.getName = function(shortName) {
        if(shortName) {return "地図+写真"}
        return "地図+写真";
    }

    G_NORMAL_MAP.getMaximumResolution = function(a) {return 19;};
    G_SATELLITE_MAP.getMaximumResolution = function(a) {return 19;};
    G_HYBRID_MAP.getMaximumResolution = function(a) {return 19;};

    G_NORMAL_MAP.getMinimumResolution = function(a) {return 6;};
    G_SATELLITE_MAP.getMinimumResolution = function(a) {return 6;};
    G_HYBRID_MAP.getMinimumResolution = function(a) {return 6;};
}

function zResetIgnoreRefresh() {
    zIgnoreRefresh = false;
}

function zThumbCheckClicked() {
    if ( thumbsCheckbox != null ) {
        if ( zIsDisplayingThumbs != thumbsCheckbox.checked ) {
            zIsDisplayingThumbs = thumbsCheckbox.checked;
            zMapRefresh();
        }
    }
}

function zMapRefresh() {
    zMapLoadUpLayer.style.visibility = 'visible';
    MapClearOverlays();
    if ( ( zCurrentResults != null ) && ( zCurrentResults.ResultSet.Result != null ) )
    {
        window.setTimeout("zFillMap()",1);
    } else {
        zMapLoadUpLayer.style.visibility = 'hidden';
    }
}

function zFillMap() {
    var points = zCurrentResults.ResultSet.Result;
    //clear all
    if ( points == null ) { zMapLoadUpLayer.style.visibility = 'hidden';  return; }

    if ( zIsDisplayingThumbs ) {
        if ( zBigMarker != null ) {
            ZPurgeMarker(zBigMarker);
            zMap.removeOverlay(zBigMarker);
        }
    } else if ( zDefaultIcon != null ) {
        if ( zSelectedPoint != null ) {
            zSelectedPoint.setImage(zDefaultIcon.iconUrl);
            zSelectedPoint=null;
        }
    }
    if ( zShowBalloons ) {
        zMap.closeInfoWindow()
    }

    //display local news if StretView is showing
	if ((zIsShowingNews)&&(typeof("getLocalNews")!='undefined')) {
		getLocalNews();
	}
    
    var count = 0;
    for ( i=0; i < points.length; i++ ) {
        if ( ( points[i].Latitude != "" ) && ( points[i].Longitude != "" ) ) { //include points with location info
        
            if ( ( zMapWindowWidth > 0 ) && ( zMapWindowHeight > 0 ) ) {
                //override size in database
                points[i].PlayerWidth = zMapWindowWidth;
                points[i].PlayerHeight = zMapWindowHeight;
            }
            
            if ( ( points[i].ThumbnailUrl == null ) || ( points[i].ThumbnailUrl.length == 0) ) {
	            points[i].ThumbnailUrl = 'http://gadgets.zenkei.net/SaaS/images/noimage.jpg';
	        }
        
            if ( zIsDisplayingThumbs ) {
                if ( i >= zPoints.length ) {
                    var icon = new GIcon();
                    icon.image = points[i].ThumbnailUrl;
                    icon.iconSize = new GSize(38, 30);
                    icon.iconAnchor = new GPoint(19, 15);
                    icon.infoWindowAnchor = new GPoint(19, -5);
                    zPoints[i]=new GMarker( new GPoint(points[i].Longitude,points[i].Latitude), icon );
                    zPoints[i].Initialize(zMap, true);
                    zPoints[i].index=i;
                    zPoints[i].id=points[i].Id;
		    zPoints[i].PCUrl = points[i].PCUrl;
                    zMap.addOverlay(zPoints[i]);
                } else {
                    zPoints[i].setPoint( new GLatLng(points[i].Latitude,points[i].Longitude) );
                    zPoints[i].id=points[i].Id;
                    zPoints[i].setImage(points[i].ThumbnailUrl);
                    zPoints[i].thumbImage = points[i].ThumbnailUrl;
		    zPoints[i].PCUrl = points[i].PCUrl;
                    zPoints[i].show();
                }
            } else {
		var iconToSet=null;
		var iconUrlToSet=null;
		var iconSelectedUrlToSet=null;

		if (( this.zDefaultIcons != null )&&( this.zDefaultIcons.length>0 )) {
			//詳細テーブル毎にアイコンが指定

			var defaultIcon = ZGetDefaultIconForDetailsTable(points[i].DetailsTable);
			if (defaultIcon!=null) {
				iconToSet=defaultIcon.icon;
				iconUrlToSet=defaultIcon.iconUrl;
				iconSelectedUrlToSet=defaultIcon.selectedIconUrl;
			} else if ( this.zDefaultIcon != null ) {
				//グローバルアイコン
				iconToSet=zDefaultIcon.icon;
				iconUrlToSet = zDefaultIcon.iconUrl;
				iconSelectedUrlToSet = zDefaultIcon.selectedIconUrl;
			}
		} else if ( this.zDefaultIcon != null ) {
			//グローバルアイコン
			iconToSet=zDefaultIcon.icon;
			iconUrlToSet = zDefaultIcon.iconUrl;
			iconSelectedUrlToSet = zDefaultIcon.selectedIconUrl;
		}

		zPoints[i]=new GMarker( new GPoint(points[i].Longitude,points[i].Latitude), iconToSet );
		zPoints[i].zIconUrl = iconUrlToSet;
		zPoints[i].zSelectedIconUrl = iconSelectedUrlToSet;
		zPoints[i].Initialize(zMap, false);
                zPoints[i].index=i;
                zPoints[i].id=points[i].Id;
		zPoints[i].PCUrl = points[i].PCUrl;
                zMap.addOverlay(zPoints[i]);
            }
            
            if ( zShowBalloons ) {
		var detailsToShowInBalloon = ZGetContentsToShowInBalloon(points[i].DetailsTable);
		if (detailsToShowInBalloon<1) {
	                zPoints[i].windowHTML=ZInfoWindowHTML(points[i].PCUrl,points[i].MobileUrl,points[i].UserID+'_'+points[i].Id,ZGeneral.LimitItemTitle3Lines(points[i].Title),points[i].ThumbnailUrl,points[i].Text);
		} else {
			zPoints[i].windowHTML=ZInfoWindowHTMLDetails(points[i].PCUrl,points[i].MobileUrl,points[i].UserID+'_'+points[i].Id,ZGeneral.LimitItemTitle3Lines(points[i].Title),points[i].ThumbnailUrl,points[i].Text,points[i].details,zCurrentResults.ResultSet.details,zCurrentResults.ResultSet.detailUnits, detailsToShowInBalloon)
		}
            }
            count++;
        }
    }

    //hide unused icons
    if ( zPoints != null ) {
        for ( i=count; i < zPoints.length; i++ ) {
            if ( zPoints[i] != null ) zPoints[i].hide();
        }
    }
    zMapLoadUpLayer.style.visibility = 'hidden';
}

function ZGetContentsToShowInBalloon(detailsTable) {
	for ( var i=0; i < this.zDetailsToShowInBalloon.length; i++ ) {
		if (this.zDetailsToShowInBalloon[i].detailsTable==detailsTable) {
			return this.zDetailsToShowInBalloon[i].numberOfDetails;
		}
	}
	return 0;
}

function ZGetDefaultIconForDetailsTable(detailsTable) {
	for ( var i=0; i < this.zDefaultIcons.length; i++ ) {
		if (this.zDefaultIcons[i].detailsTable==detailsTable) {
			return this.zDefaultIcons[i];
		}
	}
	return null;
}

function ZInfoWindowHTML(address, maddress, bukkenId, title, thumbaddress, text )
{
	var htmlCode;
	
	htmlCode = "<div id='ZMapGadgetBalloon' style='width:290px;padding-right:6px;word-wrap:break-word;'>";
	htmlCode = htmlCode + "<font size='2'>";
	htmlCode = htmlCode + "<b>" + title + "</b><br /><center><table border=0 cellpading=0 cellspacing=0 width=290><tr><td><img src=\"" + thumbaddress + "\" align='left' width='90' height='70' border='0'>";
	htmlCode = htmlCode + "</font><font size='2' color='#555555'></td><td align='left'><div style='height: 85px; width: 190px; overflow: hidden'><font size='2'>" + text + "</font></div></td></tr></table>";
	htmlCode = htmlCode + "</div>";
	return htmlCode;
}

function ZInfoWindowHTMLDetails(address, maddress, bukkenId, title, thumbaddress, text, details, detailTitles, detailUnits, unitsToShow ) 
{
	var htmlCode;
	
	htmlCode = "<div id='ZMapGadgetBalloon' style='width:290px;padding-right:6px;word-wrap:break-word;'>";
	htmlCode = htmlCode + "<font size='2'><b>" + title + "</b></font><center><table border=0 cellpading=0 cellspacing=0 width=290><tr><td><img src=\"" + thumbaddress + "\" align='left' width='90' height='70' border='0'>";
	htmlCode = htmlCode + "</font><font size='2' color='#555555'></td><td align='left'><div style='height: 85px; width: 190px; overflow: hidden;padding-top:3px;'>";
	htmlCode = htmlCode + "<table border=0 cellpading=0 cellspacing=1>";
	for (var i=0; (i<unitsToShow)&&(i<details.length); i++)
	{
		if ((details[i]!=null) && (details[i].length>0) && (details[i]!="0") && (details[i]!="1900/01/01"))
		{
			htmlCode = htmlCode + "<tr><td valign='top' style='text-overflow:ellipsis;white-space:nowrap;'><font size='2'><b>" + detailTitles[i] + "</b></font></td><td>&nbsp;</td><td valign='top'><font size='2'>" +  details[i] + detailUnits[i] + "</font></td></tr>";
		}
	}
	
	htmlCode = htmlCode + "</table>";
	htmlCode = htmlCode + "</font></div></td></tr></table>";
	htmlCode = htmlCode + "</div>";
	return htmlCode;
}

function zWheelZoom(a) {
    if(window.event) { a.returnValue = false; } // IE
    if(a.cancelable) { a.preventDefault(); } // DOM-Standard 
    
    if ((a.detail || -a.wheelDelta) < 0)
        zMap.zoomIn();
    else
        zMap.zoomOut();
} 

function zOrderOfCreation(marker,b) {
    return 1;
}

function zCheckEnter(e){ //e is event object passed from function invocation
    var characterCode;
    if(e && e.which) {
        e = e;
        characterCode = e.which;
    } else {
        e = e;
        characterCode = e.keyCode;
    }

    if(characterCode == 13) {
        zLaunchSearch();
        return false;
    } else {
        return true;
    }
}

function showLabelDivBig(html, point) {
    var coords = zMap.fromLatLngToContainerPixel(point);
    coords.x = coords.x - ZGeneral.getWidth(labelDivBig) / 2; coords.y = coords.y - ZGeneral.getHeight(labelDivBig) - 30;
    labelDivBig.innerHTML = html;
    labelDivBig.style.visibility = 'visible';
    if (coords.x < 0) { coords.x = 0; }
    if (coords.y < 0) { coords.y = coords.y + ZGeneral.getHeight(labelDivBig) + 45; }
    labelDivBig.style.left = coords.x + 'px';
    labelDivBig.style.top = coords.y + 'px';
}

function zLaunchSearch() {
    var addressBox = document.getElementById("ZAddressBox");
    if ( addressBox.value == "" ) {
        alert("地域名を入力してください");
        addressBox.focus();
        return false;
    }

    geoCoder = new GClientGeocoder();
    geoCoder.getLatLng(addressBox.value, zCenterMapTo);
}

function zCenterMapTo( point ) {
    if ( point != null ) {
	zMap.setCenter(new GLatLng(point.y,point.x),14);
    } else {
        alert("地域が見つかりませんでした。確認してから、再度入力してください");
    }
}

function zCreateGMap( mapTypes, mapDiv, controlTypes ) {
    if ( ( mapTypes == null ) || (mapTypes.length == 0 ) || 
       ( ( mapTypes.indexOf('MAP') > -1 ) && ( mapTypes.indexOf('SATELLITE') > -1 ) &&
         ( mapTypes.indexOf('HYBRID') > -1 ) ) ) {
        zMap = new GMap2( mapDiv,{mapTypes:[G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP]});
    } else if ( mapTypes.indexOf('MAP') > -1 ) {
        if ( mapTypes.indexOf('SATELLITE') > -1 ) {
            zMap = new GMap2( mapDiv,{mapTypes:[G_NORMAL_MAP,G_SATELLITE_MAP]});
        } else if ( mapTypes.indexOf('HYBRID') > -1 ) {
	        zMap = new GMap2( mapDiv,{mapTypes:[G_NORMAL_MAP,G_HYBRID_MAP]});
        } else {
            zMap = new GMap2( mapDiv,{mapTypes:[G_NORMAL_MAP]});
        }
    } else if ( mapTypes.indexOf('SATELLITE') > -1 ) {
        if ( mapTypes.indexOf('HYBRID') > -1 ) {
	        zMap = new GMap2( mapDiv,{mapTypes:[G_SATELLITE_MAP,G_HYBRID_MAP]});
        } else {
            zMap = new GMap2( mapDiv,{mapTypes:[G_SATELLITE_MAP]});
        }
    } else if ( mapTypes.indexOf('HYBRID') > -1 ) {
        zMap = new GMap2( mapDiv,{mapTypes:[G_HYBRID_MAP]});
    } else {
        zMap = new GMap2( mapDiv,{mapTypes:[G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP]});
    }

    if ( controlTypes != null ) {
        if ( controlTypes.indexOf("LARGE_MAP_CONTROL") > -1 ) {
            zMap.addControl(new GLargeMapControl());
        }
        if ( controlTypes.indexOf("SMALL_MAP_CONTROL") > -1 ) {
            zMap.addControl(new GSmallMapControl());
        }
        if ( controlTypes.indexOf("MAP_TYPE_CONTROL") > -1 ) {
	    this.zMapTypeControl = new GMapTypeControl();
            zMap.addControl(this.zMapTypeControl);
        }
        if ( controlTypes.indexOf("OVERVIEW_MAP_CONTROL") > -1 ) {
            zMap.addControl(new GOverviewMapControl());
        }
        if ( controlTypes.indexOf("SCALE_MAP_CONTROL") > -1 ) {
            zMap.addControl(new GScaleControl());
        }
    } else {
        //default control set
        zMap.addControl(new GSmallMapControl());
	    this.zMapTypeControl = new GMapTypeControl();
            zMap.addControl(this.zMapTypeControl);
	}

	if (!zRememberLocation || !LoadLocationFromCookie()) {
	    zMap.setCenter(new GLatLng(zDefaultLatitude, zDefaultLongitude, zDefaultZoom)); //金沢駅
	}
    zMap.enableContinuousZoom();

    GEvent.addListener(zMap, 'click', function(overlay, point) {
		
	    if ( overlay ) {
		    if ((typeof(overlay.Select) == 'function')&&((typeof(guyMarker)=='undefined')||(guyMarker!=overlay))) {
			    zIgnoreRefresh = true;
		            overlay.Select();
	            	    
			    MapNotifyListeners("Select", overlay.id, overlay.index);
			    if ( zResetIgnoreTimeout != null ) {
			        window.clearTimeout(zResetIgnoreTimeout);
			    }
			    zMap.closeInfoWindow();

			    zResetIgnoreTimeout = window.setTimeout("zResetIgnoreRefresh()",1000);
			    if ((overlay.PCUrl!=null)&&(overlay.PCUrl.length>0)) {
				    ZGeneral.OpenInNewWindow(overlay.PCUrl);
			    }
		    }
	    } else {
	        if ( zIsDisplayingThumbs ) {
                if ( zBigMarker != null ) {
                    ZPurgeMarker(zBigMarker);
                    zMap.removeOverlay(zBigMarker);
                }
            } else if ( zDefaultIcon != null ) {
                if ( zSelectedPoint != null ) {
                    zSelectedPoint.setImage(zSelectedPoint.iconUrl);
                }
            }
	        MapNotifyListeners("Select", null);
	    }
    });

    GEvent.addListener(zMap, "moveend", function() {
        if (zIgnoreRefresh) {
            return false;
        }
        if (typeof this.zReloadTimeoutID == "number") {
            window.clearTimeout(this.zReloadTimeoutID);
        }
        this.zReloadTimeoutID = window.setTimeout("MapNotifyListeners('LocationChange', null);", 150);
        if (zRememberLocation) {
            if ((zDefaultLatitude != zMap.getCenter().lat()) || (zDefaultLongitude!=zMap.getCenter().lng()) || (zMap.getZoom()!=zDefaultZoom)) {
                ZGeneral.CreateCookie("ZLastLocation", zMap.getCenter().lat() + "," + zMap.getCenter().lng() + "," + zMap.getZoom(), 120);
            }
        }

    });
}

this.zListGadgetPanel = null;
this.zListSelectedDiv = null;
this.zListDivs = new Array();
this.zListselectedListeners = new Array();
this.zListMaxResults = 20;
this.zListCurrentStart = 0;
this.zListRowContentsOrder = new Array("Thumb","Title","Address","Details","Button");
this.zListContainerDiv = null;
this.zListFooterDiv = null;
this.zListCustomHTML = "";
this.zListWindowWidth = 0;
this.zListWindowHeight = 0;
this.zListWindowProperties = null;
this.detailLabels = false;
var MAX_PAGEJUMPS = 8;

function ZListGadget(listGadgetPanel) {
    
    this.Event_Refresh = Event_Refresh;
    this.Event_Clear =Event_Clear;
    this.Event_ItemSelected = Event_ItemSelected;
    this.Event_SearchStart = Event_SearchStart;
    this.RegisterListener = RegisterListener;
    this.SetMaxResults = SetMaxResults;
    this.SetRowContentsOrder = SetRowContentsOrder;
    this.AddCustomHTMLToCell = AddCustomHTMLToCell;
    this.SetNewWindowSize = SetNewWindowSize;
    this.SetNewWindowProperties = SetNewWindowProperties;
    this.ShowDetailLabels = ShowDetailLabels;
    this.ChangeFieldUnit = ChangeFieldUnit;
    this.ReplaceFieldValue = ReplaceFieldValue;
    this.ReplaceFieldLabel = ReplaceFieldLabel;
    
    if ( listGadgetPanel == null ) return null;
    
    zListGadgetPanel = listGadgetPanel;
    zListGadgetPanel.id = 'ZListGadget';
    zListGadgetPanel.className = 'ZList';
    
    zListContainerDiv = document.createElement('div');
    zListContainerDiv.className = 'ZListContainer';
    zListGadgetPanel.appendChild(zListContainerDiv);
    
    zListFooterDiv = document.createElement('div');
    zListFooterDiv.className = 'ZListFooter';
    zListFooterDiv.innerHTML = "";
    zListFooterDiv.style.visibility = 'hidden';
    zListGadgetPanel.appendChild(zListFooterDiv);

    fieldsToOverrideRatios = new Array();
    fieldsToOverride = new Array();
    fieldsToOverrideUnits = new Array();
    fieldsToOverrideDecimals = new Array();
    fieldsToOverrideOnce = false;
    fieldsToReplace = new Array();
    fieldsToReplaceOldValues = new Array();
    fieldsToReplaceNewValues = new Array();
    fieldsLabelToReplace = new Array();
    fieldsLabelToReplaceOldValues = new Array();
    fieldsLabelToReplaceNewValues = new Array();
    
    function SetRowContentsOrder(order) {
        if ( !ZGeneral.EqualArrays(zListRowContentsOrder,order) ) {
            zListRowContentsOrder = order;
            zFillList();
            if ( zListSelectedDiv != null ) {
                zListSelectedDiv.className = 'ZListRowSelected';
            }
        }
    }
   
    function SetNewWindowSize(w,h) {
        zListWindowWidth = w;
        zListWindowHeight = h;
    }
    
    function SetNewWindowProperties(properties) {
        zListWindowProperties = properties;
    }
    
    function SetMaxResults( num ) {
        if ( ( num > 0 ) && ( num <=30 ) ) {
            zListMaxResults = num;
        }
    }
    
    function AddCustomHTMLToCell( html ) {
        zListCustomHTML = html;
    }
    
    function ShowDetailLabels(show) {
        detailLabels = show;
    }

    function ReplaceFieldValue(field, oldValue, newValue) {
        if ((field == null) || (oldValue == null) || (newValue == null)) return false;
        fieldsToReplace.push(field);
        fieldsToReplaceOldValues.push(oldValue);
        fieldsToReplaceNewValues.push(newValue);
        return true;
    }

    function ReplaceFieldLabel(field, oldValue, newValue) {
        if ((field == null) || (oldValue == null) || (newValue == null)) return false;
        fieldsLabelToReplace.push(field);
        fieldsLabelToReplaceOldValues.push(oldValue);
        fieldsLabelToReplaceNewValues.push(newValue);
        return true;
    }
    
    function ChangeFieldUnit(field, factor, unit, maxDecimals) {
        if ( (field==null) || (factor==null) || (unit==null) || (maxDecimals==null)) return false;
        fieldsToOverride.push(field);
        fieldsToOverrideRatios.push(factor);
        fieldsToOverrideUnits.push(unit);
        fieldsToOverrideDecimals.push(Math.pow(10,maxDecimals));
        return true;
    }
 
    function Event_Refresh() {
        if ( zCurrentResults != null ) {
            if ( typeof(zCurrentResults.ResultSet) != 'undefined' ) {
                zListCurrentStart = 0;
                fieldsToOverrideOnce = false;
                zFillList();
            } else if ( typeof(zCurrentResults.Error) != 'undefined' ) {
                ZGeneral.ShowError( zCurrentResults.Error );
            } else {
                //items.aspxおかしい
            }
        }
    }

    function Event_Clear() {
        HideCurrentList();
    }

    function Event_ItemSelected( item, index ) {
        if ( zListSelectedDiv != null ) {
            zListSelectedDiv.className ='ZListRow';
        }
        
        //リストに入ってない場合、その件があるページに移動
        if ( ( index < zListCurrentStart ) || ( index >= (zListCurrentStart+zListMaxResults) ) ) {
            HideCurrentList();
            zListCurrentStart = ( ( index / zListMaxResults) | 0 ) * zListMaxResults;
            zFillList();
        }
        
        if ( ( item != null ) && ( zListDivs != null ) ) {
            var itemToSelect = null;
            for (i=0; i < zListDivs.length; i++) {
                if ( zListDivs[i].id == item ) {
                    itemToSelect = zListDivs[i];
                    break;
                }
            }
            if ( itemToSelect != null ) {
                itemToSelect.className="ZListRowSelected";
                itemToSelect.parentNode.parentNode.scrollTop = itemToSelect.offsetTop - itemToSelect.parentNode.parentNode.offsetTop; //containerがある
                zListSelectedDiv = itemToSelect;
            }
        }
    }
    
    function Event_SearchStart() {
        zListFooterDiv.innerHTML = "";
        zListFooterDiv.style.visibility = 'hidden';
        HideCurrentList();
    }

    function RegisterListener( eventType, functionToFire ) {
	    if ( eventType == "Select" ) {
	        zListselectedListeners.push(functionToFire);
	    }
    }
}

function ClearCurrentList() {
    if (( typeof(zListContainerDiv) == 'undefined' )||( zListContainerDiv == null )) return;
    while (zListContainerDiv.firstChild) {
        zListContainerDiv.firstChild.onclick=null;
        zListContainerDiv.removeChild(zListContainerDiv.firstChild);
    };
    
    zListDivs = new Array();
    zListSelectedDiv = null;
    fieldsToOverrideOnce = false;
}

function HideCurrentList() {
    for ( i=0; i < this.zListDivs.length; i++ ) {
        this.zListDivs[i].style.visibility = 'hidden';
    }
    zListSelectedDiv = null;
}

function ListNotifyListeners( eventType, data ) {
    if ( eventType == "Select" ) {
        if ( zListselectedListeners == null ) return;
        for (var i=0; i < zListselectedListeners.length; i++) {
            zListselectedListeners[i](data);
        }
    }
}

function zFillList() {

    if ( ( zCurrentResults == null ) || ( zCurrentResults.ResultSet == null ) ) return;

    var points = zCurrentResults.ResultSet.Result;
    //clear all

    if ( ( points == null ) || ( points.length == 0 ) ) {
        zListFooterDiv.innerHTML = "";
        zListFooterDiv.style.visibility = 'hidden';
        return;
    }
    
    var noAddress = true;
    var c=0;
    for (c=0; c < zListRowContentsOrder.length; c++) {
        if ( zListRowContentsOrder[c] == "Address" ) {
            noAddress = false;
            break;
        }
    }

    //override units specified by ChangeFieldUnit()
    if ( fieldsToOverrideOnce == false ) {
        for ( i=0; i < fieldsToOverride.length; i++ ) {
            for ( a=0; a < zCurrentResults.ResultSet.detailFields.length; a++ ) {
                if (zCurrentResults.ResultSet.detailFields[a] == fieldsToOverride[i]) {
                    zCurrentResults.ResultSet.detailUnits[a] = fieldsToOverrideUnits[i];
                    for (b=0; b < points.length; b++ ) {
                        points[b].details[a] = points[b].details[a] * fieldsToOverrideRatios[i];
                        points[b].details[a] = Math.round(points[b].details[a] * fieldsToOverrideDecimals[i]) /
                            fieldsToOverrideDecimals[i];
                    }
                    break;
                }
            }
        }
        fieldsToOverrideOnce = true; // To override once
    }
    
    //replace values specified by ReplaceFieldValue()
    for (i = 0; i < this.fieldsToReplace.length; i++) {
        for (a = 0; a < zCurrentResults.ResultSet.detailFields.length; a++) {
            if (zCurrentResults.ResultSet.detailFields[a] == fieldsToReplace[i]) {
                for (b = 0; b < points.length; b++) {
                    if (points[b].details[a] == fieldsToReplaceOldValues[i]) {
                        points[b].details[a] = fieldsToReplaceNewValues[i];
                    }
                }
                break;
            }
        }
    }

    //replace labels specified by ReplaceFieldLable()
    if (this.detailLabels) {
        for (i = 0; i < this.fieldsLabelToReplace.length; i++) {
            for (a = 0; a < zCurrentResults.ResultSet.detailFields.length; a++) {
                if (zCurrentResults.ResultSet.detailFields[a].toLowerCase() == fieldsLabelToReplace[i].toLowerCase()) {
                    if (zCurrentResults.ResultSet.details[a] = fieldsLabelToReplaceOldValues[i]) {
                        zCurrentResults.ResultSet.details[a] = fieldsLabelToReplaceNewValues[i];
                    }
                }
            }
        }
    }
    
    var i = 0;
    var count = 0;
    for ( i=zListCurrentStart; (i < points.length)&&(i < zListMaxResults+zListCurrentStart); i++ ) {
        if ( ( zListWindowWidth > 0 ) && ( zListWindowHeight > 0 ) ) {
            //override size in database
            points[i].PlayerWidth = zListWindowWidth;
            points[i].PlayerHeight = zListWindowHeight;
        }
            
        if ( count >= this.zListDivs.length ) {
            this.zListDivs[count] = document.createElement('div');
            this.zListDivs[count].className = 'ZListRow';
            this.zListDivs[count].id = points[i].Id;
            this.zListDivs[count].innerHTML = zGetRowHTML(points[i],zCurrentResults.ResultSet.detailUnits,zCurrentResults.ResultSet.details,zCurrentResults.ResultSet.detailFields,noAddress);
            
            //クリックされたときのイベント
            this.zListDivs[count].onclick=function(event) {
                if ( zListSelectedDiv != null ) {
                    zListSelectedDiv.className = 'ZListRow';
                }
                this.className = 'ZListRowSelected';
                zListSelectedDiv = this;
                ListNotifyListeners("Select", this.id);
            };
            this.zListContainerDiv.appendChild(this.zListDivs[count]);
        } else {
            this.zListDivs[count].className = 'ZListRow';
            this.zListDivs[count].id = points[i].Id;
            this.zListDivs[count].innerHTML = zGetRowHTML(points[i],zCurrentResults.ResultSet.detailUnits,zCurrentResults.ResultSet.details,zCurrentResults.ResultSet.detailFields,noAddress);
            this.zListDivs[count].style.visibility = 'visible';
        }
        count++;
    }
    
    //hide unused rows
    for ( i=count; i < this.zListDivs.length; i++ ) {
        this.zListDivs[i].style.visibility = 'hidden';
    }
    
    zListFooterDiv.innerHTML = zGetFooterHTML(points.length);
    zListFooterDiv.style.visibility = 'visible';
    
    zListGadgetPanel.scrollTop = 0;
}

function zGetFooterHTML(total) {
    var code = '<table width=100%><tr>';
    
    code +='<td align="left" width=16%>';
    if ( zListCurrentStart > 0 ) {
        code+='<a href="#" onclick="HideCurrentList();zListCurrentStart=' + (zListCurrentStart-zListMaxResults) + ';zFillList();ListNotifyListeners(\'Select\', null);return false;">前の' + zListMaxResults + '件</a>';
    }
    code +='</td>';
    
    code +='<td align="center" width=68%>';
    var pageCount=1;
    var start=0;
    var end=total;
    
    if ( end > zListMaxResults*MAX_PAGEJUMPS ) {
        if ( zListCurrentStart > zListMaxResults*(MAX_PAGEJUMPS-2) ) {
            start = zListCurrentStart - zListMaxResults*(MAX_PAGEJUMPS-2);
            if ( start >= total - zListMaxResults*(MAX_PAGEJUMPS-1) ) {
                start -= zListMaxResults;
            }
        }
        end = start + zListMaxResults*MAX_PAGEJUMPS;
        if ( end > total ) end = total;
        pageCount += Math.floor(start/zListMaxResults);
    }
    for (i=start; i<end; i+=zListMaxResults) {
        if ( zListCurrentStart == i ) {
            code+= '<label>' + pageCount + '</label> ';
        } else {
            code+= '<a href="#" onclick="HideCurrentList();zListCurrentStart=' + i + ';zFillList();ListNotifyListeners(\'Select\', null);return false;">' + pageCount + '</a> ';
        }
        pageCount++;
    }
    code+='</td>';
    
    code +='<td align="right" width=16%>';
    if ( total > ( zListCurrentStart + zListMaxResults ) ) {
        code+='<a href="#" onclick="HideCurrentList();zListCurrentStart=' + (zListCurrentStart+zListMaxResults) + ';zFillList();ListNotifyListeners(\'Select\', null);return false;">次の' + zListMaxResults + '件</a>';
    }
    code +='</td>';
    
    code += '</tr></table>';
    
    return code;
}

function zGetRowHTML(point,units,details,detailFields,noAddress) {
    if ( point == null ) return "";
    var code="";
    var c=0;
    var unit="";
    for (c=0; c < zListRowContentsOrder.length; c++) {
        if ( zListRowContentsOrder[c] == "Thumb" ) {
            code += '<img class="ZListThumbImage" src="';
            if ( ( point.ThumbnailUrl != null ) && ( point.ThumbnailUrl.length > 0 ) ) {
                code += point.ThumbnailUrl;
            } else {
                code += "http://gadgets.zenkei.net/SaaS/images/noimage.jpg";
            }
            code += '">';
        } else if ( zListRowContentsOrder[c] == "PlanThumb" ) {
            code += '<img class="ZListThumbImage" src="';
            if ( ( point.PlanThumbnailUrl != null ) && ( point.PlanThumbnailUrl.length > 0 ) ) {
                code += point.PlanThumbnailUrl;
            } else {
                code += "http://gadgets.zenkei.net/SaaS/images/noimage.jpg";
            }
            code += '">';
        } else if ( zListRowContentsOrder[c] == "Title" ) {
            code += '<div class="ZListItemTitle"><label>' + ZGeneral.LimitItemTitle(point.Title) + '</label></div>';
        } else if ( zListRowContentsOrder[c] == "Address" ) {
	        if ( point.details != null ) {
	            for ( i=0; i<point.details.length; i++ ) {
                    if ( detailFields[i] == "Address1" ) {
                        if ( point.details[i].length == 0) point.details[i]="&nbsp;"; //to force space
                        code += '<div class="ZListItemAddress"><label>' + point.details[i] + '</label></div>'; //住所
                        break;
                    }
                }
	        }
        } else if ( zListRowContentsOrder[c] == "Details" ) {
	        if ( point.details != null ) {
                for ( i=0; i<point.details.length; i++ ) {  // i=0からに修正 2008.4.30
                    unit=units[i];
                    detail=details[i];
                    if ( (detailFields[i] != "Address1") || noAddress ) {   // 順番指定に"Address"がある場合は、Detailsの"Address1"は無視する
                        if (point.details[i].length == 0) { point.details[i] = "&nbsp;"; detail = ""; unit = ""; }
                        code += '<div class="ZListDetailCell_' + detailFields[i] + '">';
                        if ( this.detailLabels ) {
                            code += '<label class="ZLabelName">' + detail + '</label>';
                        }
                        code += '<label class="ZValue">' + point.details[i] + '</label>';
                        code += '<label class="ZUnit">' + unit + '</label>';
                        code += '</div>';
                    }
                }
	        }
        } else if ( zListRowContentsOrder[c] == "Button" ) {
            code += '<div class="ZListDetailsButtonCell"><input type="button" class="ZButton" value="詳細" onclick="ZGeneral.OpenInNewWindowWithSize(\'' + point.PCUrl + '\', ' + point.PlayerWidth + ', ' + point.PlayerHeight + ',\'' + zListWindowProperties + '\');"></div>';
        } else if ( zListRowContentsOrder[c] == "Text" ) {
            code += '<div class="ZListItemText"><label>' + point.Text + '</label></div>';
        }

    }
    code += this.zListCustomHTML;
    return code;
}


