/**
* map : google map area
* xmlHttp : Http Object
* divlist : show picture, rent and room type
* icon : make 30 icon 4 type
* makepoint : create point
* sortdetail : create table detail infowindow
* ctr_main_map : google map control
* maker_center : show picture in center point
* loadlabels : show loading in center point
* tempsort : keep temporary variable to sort
* tempid : keep temporary id 
* sortby : condition for sort rent, area, room_on
* typemove : type action event (true/false)
* tempkm : keep temporary oldkm
* tempoldtype : keep temporary type
* tempoldroom : keep temporary room
* darg_flags : check event darg (true/false)
* mouse_flags : check event mouse (true/false)
* infowindow_flags : check event infowindow (true/false)
* times : call function countDown every 1 sec
* counttimes : check send data timeout (10 sec)
* countitem : for check list detail
*/

var map;
var xmlHttp;
var divlist;
var icon = new Array();
var makepoint = new Array();
var sortdetail = new Array();
var ctr_main_map = new Array();
var maker_center;
var loadlabels;
var tempsort = new Array();
var tempid;
var sortby = new Array();
sortby["rent"] = 'desc';
sortby["type"] = 'desc';
sortby["room_on"] = 'desc';
var typemove = true;
var tempkm = 1;
var tempoldtype = "";
var tempoldroom = "";
var darg_flags = false;
var mouse_flags = false;
var infowindow_flags = false;
var times;
var counttimes = 0;
var countitem = 0;

/**
* swapImage Function : (Dreamweaver create code)
* MM_swapImgRestore()
* MM_preloadImages()
* MM_findObj()
* MM_swapImage()
*/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**
* setupIcons Function : setup 30 icon 4 type
*/

function setupIcons(){
	var icon_defs = new GIcon();
    icon_defs.iconSize = new GSize(32, 25);
    icon_defs.shadowSize = new GSize(32, 25);
    icon_defs.iconAnchor = new GPoint(10, 10);
    icon_defs.infoWindowAnchor = new GPoint(11, 25);
    icon_defs.image = "http://www.toyohirakumap.com/images/icon/00.png";
    for (var type = 0; type < 9; type++){
	switch (type){
		case 0 : 
			icon["10"] = new GIcon(icon_defs);
			icon["10"].image = "images/icon/00.png";
    			icon["10"].shadow = "images/icon/00_s.png";
			break;
		case 1 : 
			icon["20"] = new GIcon(icon_defs);
      			icon["20"].image = "images/icon/00.png";
      			icon["20"].shadow = "images/icon/00_s.png";
			break;
		case 2 : 
			icon["30"] = new GIcon(icon_defs);
      			icon["30"].image = "images/icon/00.png";
    			icon["30"].shadow = "images/icon/00_s.png";
			break;
		case 3 : 
			icon["40"] = new GIcon(icon_defs);
      			icon["40"].image = "images/icon/00.png";
      			icon["40"].shadow = "images/icon/00_s.png";
			break;
		case 4 : 
			icon["50"] = new GIcon(icon_defs);
      			icon["50"].image = "images/icon/00.png";
      			icon["50"].shadow = "images/icon/00_s.png";
			break;
		case 5 : 
			icon["60"] = new GIcon(icon_defs);
      			icon["60"].image = "images/icon/00.png";
      			icon["60"].shadow = "images/icon/00_s.png";
			break;
		case 6 : 
			icon["70"] = new GIcon(icon_defs);
      			icon["70"].image = "images/icon/00.png";
      			icon["70"].shadow = "images/icon/00_s.png";
			break;
		case 7 : 
			icon["80"] = new GIcon(icon_defs);
      			icon["80"].image = "images/icon/00.png";
      			icon["80"].shadow = "images/icon/00_s.png";
			break;
		case 8 : 
			icon["99"] = new GIcon(icon_defs);
      			icon["99"].image = "images/icon/00.png";
      			icon["99"].shadow = "images/icon/00_s.png";
			break;
		}
    }

    for(var index = 1; index <= max_icon; index++ ){
	switch (type){
		case 0 : 
			icon["a"+index] = new GIcon(icon_defs);
     			icon["a"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["a"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 1 : 
			icon["b"+index] = new GIcon(icon_defs);
          		icon["b"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["b"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 2 : 
			icon["c"+index] = new GIcon(icon_defs);
          		icon["c"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["c"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 3 : 
			icon["d"+index] = new GIcon(icon_defs);
          		icon["d"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["d"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 4 : 
			icon["e"+index] = new GIcon(icon_defs);
          		icon["e"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["e"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 5 : 
			icon["f"+index] = new GIcon(icon_defs);
          		icon["f"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["f"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		case 6 : 
			icon["g"+index] = new GIcon(icon_defs);
          		icon["g"+index].image = "images/icon/00.png";
          		if (shadowicon){
          			icon["g"+index].shadow = "images/icon/00_s.png";
          		}
			break;
		}
    }
}

/**
* countDown Function : check timeout in 10 sec
*/
function countDown(){
	counttimes++;
	if (counttimes >= 60){
		clearInterval(times);
		counttimes = 0;
		xmlHttp.abort();
		return2oldposition();		
		loadlables.hide();
		map.enableDragging();
		alert("Error Report : Time Out Or Data Error Please try again");
		return false;
	}else{
		map.disableDragging();
	}
}
/**
* createXMLHttpRequest Function : check browser and create xmlHttp object
*/
function createXMLHttpRequest() {
	try{
		if (window.ActiveXObject) {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		else if (window.XMLHttpRequest) {
			 xmlHttp = new XMLHttpRequest();
		}
	}catch(e){
		alert("あなたはこのブラウザを使用することができません。");
	}
}
/**
* startRequest Function : check and send data to action form
*/
function startRequest() {
	createXMLHttpRequest();
	loadlables.show();
	maker_center.hide();
	delCtr(ctr_main_map);
	map.disableDragging();
	map.disableInfoWindow();
    var pForm = document.forms[0];
    var pBody = getRequestBody(pForm);
    xmlHttp.open("post", pForm.action, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    times = setInterval('countDown()',1000);
    xmlHttp.onreadystatechange = function () {
	   if (xmlHttp.readyState == 4) {			
       		if (xmlHttp.status == 200) {   	       		
				filtering(eval('(' + xmlHttp.responseText + ')'));
				clearInterval(times);
				counttimes = 0;
				chkitem(countitem);
				setCenter2oldFrom();
				maker_center.show();
				loadlables.hide();
				lockSearchbtn("inline");				
				setMainctr();				
				tempkm = window.frm.oldkm.value-0;
	        } else {
            	showErrorstatus(xmlHttp.status);
            }
       }else if (xmlHttp.readyState != 4){
       		lockSearchbtn("none");
       }
    };	
    xmlHttp.send(pBody);        
}
/**
* getRequestBody Function : get form data
* @param pForm : object form
* @return : Array Data
*/
function getRequestBody(pForm) {
	var nParams = new Array();
	tempoldtype = "";
	tempoldroom = "";
	var index = 0;
	for (var i=0 ; i < pForm.elements.length; i++) {
		if (encodeURIComponent(pForm.elements[i].type.toString()) == "checkbox"){
			if (pForm.elements[i].checked == true){
				if (encodeURIComponent(pForm.elements[i].name.toString().replace("[]","")) == "chktype"){
					tempoldtype += ","+encodeURIComponent(pForm.elements[i].value);
				}else if (encodeURIComponent(pForm.elements[i].name.toString().replace("[]","")) == "chkroom"){
					tempoldroom += ","+encodeURIComponent(pForm.elements[i].value);
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "chkpet"){
					document.pForm.oldchkpet.value = encodeURIComponent(pForm.elements[i].value);
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "comp_day"){
					document.pForm.oldcomp_day.value = encodeURIComponent(pForm.elements[i].value);
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "parking"){
					document.pForm.oldparking.value = encodeURIComponent(pForm.elements[i].value);
				}				
				var pParam = encodeURIComponent(pForm.elements[i].name);
				pParam += "=";
				pParam += encodeURIComponent(pForm.elements[i].value);		
				index++;
			}else{
				if (encodeURIComponent(pForm.elements[i].name.toString().replace("[]","")) == "chktype"){
					tempoldtype += "";
				}else if (encodeURIComponent(pForm.elements[i].name.toString().replace("[]","")) == "chkroom"){
					tempoldroom += "";
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "chkpet"){
					document.pForm.oldchkpet.value = "";
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "comp_day"){
					document.pForm.oldcomp_day.value = "";
				}else if (encodeURIComponent(pForm.elements[i].name.toString()) == "parking"){
					document.pForm.oldparking.value = "";
				}
				index++;
				continue;
			}
		}else{		
			var pParam = encodeURIComponent(pForm.elements[i].name);
			pParam += "=";
			pParam += encodeURIComponent(pForm.elements[i].value);		
		}
        nParams.push(pParam);
	} 
	return nParams.join("&");        
}

/**
* showErrorstatus Function : show error code
* @param status_code : error code
*/
function showErrorstatus(status_code){
	switch(status_code){
        case 400 : alert("Error Report : Bad Request"); break;
        case 401 : alert("Error Report : Unauthorized"); break;
        case 402 : alert("Error Report : Payment Required"); break;
        case 403 : alert("Error Report : Forbidden"); break;
        case 404 : alert("Error Report : Not Found"); break;
        case 405 : alert("Error Report : Method Not Allowed"); break;
        case 406 : alert("Error Report : Not Acceptable"); break;
        case 407 : alert("Error Report : Proxy Authentication Required"); break;
        case 408 : alert("Error Report : Request Time-out"); break;
        case 409 : alert("Error Report : Conflict"); break;
        case 410 : alert("Error Report : Gone"); break;
        case 411 : alert("Error Report : Length Required"); break;
        case 412 : alert("Error Report : Precondition Failed"); break;
        case 413 : alert("Error Report : Request Entity Too Large"); break;
        case 414 : alert("Error Report : Request-URI Too Large"); break;
        case 415 : alert("Error Report : Unsupported Media Type"); break;
        case 500 : alert("Error Report : Internal Server Error"); break;
        case 501 : alert("Error Report : Not Implemented"); break;
        case 502 : alert("Error Report : Bad Gateway"); break;
        case 503 : alert("Error Report : Service Unavailable"); break;
        case 504 : alert("Error Report : Gateway Time-out"); break;
        case 505 : alert("Error Report : HTTP Version not supported"); break;
        default : alert("Error Code : "+status_code); break;
	}	
}
/**
* lockSearchbtn Function : lock search button
* @param style : style display search buttion (none/inline)
*/
function lockSearchbtn(style){
	document.getElementById("btnsearch").style.display = style;
}
/**
* Gmap_Load Function : load map, event and set data
*/
function Gmap_Load() {
    if (GBrowserIsCompatible()) {
		setupIcons();
		chkwindowsize();
		var mdiv = document.getElementById("map");
		map = new GMap2(mdiv);
		setMainctr();
        document.frm.oldkm.value = start_km;
		map.setCenter(new GLatLng(start_lat,start_lng), start_zoom);
   		GEvent.addListener(map, 'zoomend', zoomend); 
   		GEvent.addListener(map, 'dragend', dragend); 
   		GEvent.addListener(map, 'drag', drag); 
   		GEvent.addListener(map, 'move', move); 
   		GEvent.addListener(map, 'moveend', moveend); 
		savecenter();
		setIconcenter();
		setCenter2oldFrom();
		setCenter2From();
		startRequest();		
	}
}
/**
* loadlable Function : create loading.. lable
*/
function loadlable(){
	loadlables = new ELabel(map.getCenter(), "<img src='images/loading.jpg' border='0'>",null, new GSize(-44,15),90);
   	map.addOverlay(loadlables); 
	loadlables.hide();
}
/**
* setIconcenter Function : create picture in center point and set to center
*/
function setIconcenter(){
	if (maker_center != null){
		maker_center.setPoint(map.getCenter());
		loadlables.setPoint(map.getCenter());
	}else{
    	loadlables = new ELabel(map.getCenter(), "<img src='images/loading.gif' border='0'>" ,null, new GSize(-50,-50),90);
		maker_center = new ELabel(map.getCenter(), "<img src='images/cpoint.png' border='0'>",null, new GSize(-8.5,-8.5));
       	map.addOverlay(loadlables);
   		map.addOverlay(maker_center);
	}
}
/**
* setMainctr Function : create google map control
*/
function setMainctr(){
	ctr_main_map[0] = new GLargeMapControl();	
	ctr_main_map[1] = new GScaleControl();
	ctr_main_map[2] = new GOverviewMapControl(new GSize(100,100));
	ctr_main_map[3] = new GMapTypeControl();
	for (var i = 0 ; i < ctr_main_map.length; i++){
		map.addControl(ctr_main_map[i]);
	}
}
/**
* delCtr Function : delete google map control
* @param arr : array control
*/
function delCtr(arr){
	for (var i = 0 ; i < arr.length; i++){
		map.removeControl(arr[i]);
	}
	ctr_main_map.length = 0;
}
/**
* savecenter Function : save center lat,lng
*/
function savecenter(){
	map.savePosition();
}
/**
* setCenter2From Function : set center to form newlat,newlng
*/
function setCenter2From(){
	document.frm.newlat.value = map.getCenter().lat();
	document.frm.newlng.value = map.getCenter().lng();
}
/**
* setCenter2oldFrom Function : set center to form oldlat,oldlng and set data to other oldform
*/
function setCenter2oldFrom(){
	document.frm.oldlat.value = map.getCenter().lat();
	document.frm.oldlng.value = map.getCenter().lng();
	document.frm.oldchktype.value = tempoldtype.slice(1);
	document.frm.oldchkroom.value = tempoldroom.slice(1);
}
/**
* zoomend Function : save center, set data and picture center
*/
function zoomend(){
	typemove = true;
	savecenter();
	setIconcenter();
	setCenter2From();
}
/**
* moveend Function : check send data if over area and picture center
*/
function moveend(){
	setIconcenter();
	if (typemove){
		inarea();
	}
}
/**
* move Function : set typemove
*/
function move(){
	typemove = true;
}
/**
* drag Function : set darg_flags, typemove and picture center
*/
function drag(){
	darg_flags = true;
	typemove = true;
	setIconcenter();
}
/**
* drag Function : set typemove and save center
*/
function dragend(){
	typemove = true;
	savecenter();
}
/**
* inarea Function : send data if over area
*/
function inarea(){
	savecenter();
	var oldlat = window.frm.oldlat.value-0;
	var oldlng = window.frm.oldlng.value-0;
	setCenter2From();
	var newlat = window.frm.newlat.value-0;
	var newlng = window.frm.newlng.value-0;
	if ((Math.abs(Math.abs(oldlat)-Math.abs(newlat)) > ylat*tempkm || Math.abs(Math.abs(oldlng)-Math.abs(newlng)) > xlng*tempkm) && !infowindow_flags){
		chkfiltering();
	}
}
/**
* return2oldposition Function : return to last lat,lng
*/
function return2oldposition(){
	map.setCenter(new GLatLng(window.frm.oldlat.value-0,window.frm.oldlng.value-0),map.getZoom());
}
/**
* filtering Function : check data and set data
* @param pointArray : Arry json data from database
*/
function filtering(pointArray){
	var result = false;
	var articles;
	var article;
	var id;
	var lat;
	var lng;
	var position;
	var icontype;
	var name;
	var type;
	var picture_url;
	var price;
	var detail_url;
	var multi_detail;
	var result_str;
	var multi_name;
	var count_array;
	var type_name;
	var structure;
	var comp_day;
	var room_on;
	var comp_cd = "";
	var arti_cd = "";
	var status;
	try{		
		if (pointArray['multi']['locate'].length > 0){
			for (var i in pointArray['multi']['locate']) {
				articles = pointArray['multi']['locate'][i];
				article = articles['articles']['article'];
				var splitid = article[0]['arti_cd'].split("-");
				tempid = splitid[0];
				lat = articles['lat'];
				lng = articles['lng'];
				position = new GLatLng(lat,lng);
				icontype = articles['icon_type'];
				type_name = articles['type_name'];
				structure = articles['structure'];
				comp_day = articles['comp_day'].split("-");
				multi_detail = "";
				multi_detail = createHeaderopeninfowindow(type_name,structure,comp_day[0]+"年"+comp_day[1]+"月",tempid,article[0]['picture_url']);
				multi_detail += "<table width='100%' border='1' cellpadding='0' cellspacing='0' class='tablestyle' bordercolor='#CCCCCC'>";		
				multi_name = "";
				result_str = "";	
				count_array = article.length;
				
				status = articles['status'];
				if (status == "r" && makepoint["arr"+tempid] != null){
					removeMarker(tempid);
				}else if (status == "s" && makepoint["arr"+tempid] != null){
					continue;
				}else if (status == "d" && makepoint["arr"+tempid] == null){
					continue;
				}else if (status == "n" && makepoint["arr"+tempid] != null){
					continue;
				}
				sortdetail["arr"+tempid] = "";	
				if (makepoint["arr"+tempid] == null ){
					var subdiv = document.createElement('div');
					var tempdiv = "div"+tempid;
					subdiv.setAttribute('id',tempdiv);
					for (var j in article){
						id = article[j]['id'];
						arti_name = article[j]['name'];
						type = article[j]['arrange_name'];
						area = article[j]['area'];
						if (area == "") { area = "0"; }
						room_no = article[j]['room_no'];
						picture_url = article[j]['picture_url'];
						price = convert(article[j]['price']);		
						comp_cd = article[j]['comp_cd'];
						arti_cd = article[j]['arti_cd'];
//						detail_url = "/arti_detail.php?comp_cd="+comp_cd+"&arti_cd="+arti_cd;
						detail_url = "/advance.php?code="+arti_cd;
						sortdetail["arr"+tempid] += detail_url+"|"+price+"|"+type+"|"+room_no+"#";
						multi_name = ","+arti_name;
						multi_detail += "<tr><td align='centser'id='link"+tempid+j+"' width=25><a href='"+detail_url+"' target='_blank' >詳細</a></td><td align='center' id='arti_name"+tempid+j+"' width=140 >"+arti_name+"</td></tr>";
						result_str += createList(id,picture_url,price,type,detail_url,"multi",count_array);
					}
				}
				if (count_array > 1){
					multi_detail += "</table></div></TD></TR></table></TD></TR></table>";
					result = createMarker(position,tempid,multi_name.slice(1),icon[icontype],multi_detail,"multi",count_array);
				}else if (count_array == 1){
					result = createMarker(position,tempid,arti_name,icon[icontype],detail_url,"multi",count_array);
				}
				if (makepoint["arr"+tempid] != null && !result){
					subdiv.innerHTML = result_str;
				}else if (result){
					subdiv.innerHTML = result_str;
				}
			}
		}
	}catch(e){
		alert("No Data in Area");
	}
	darg_flags = false;
	map.enableDragging();
	map.enableInfoWindow();
}
/**
* createMarker Function : create makepoint or remove makepoint
* @param position : lat,lng
* @param id : id makepoint
* @param icon : icon type
* @param detail_url : detail infowindow or link detail url
* @param markertype : single data or multi data
* @param count_array : check single data or multi data
*/
function createMarker(position, id, name, icon,detail_url,markertype,count_array) {

	if (makepoint["arr"+id] == null){
		countitem++;
	    makepoint["arr"+id] = new GMarker(position, {title: name, icon: icon });
		if (markertype == "standalone" || count_array == 1){
		    GEvent.addListener(makepoint["arr"+id], 'mouseout', function() { if (darg_flags){ mouse_flags=false; darg_flags=false; } } ); 
		    GEvent.addListener(makepoint["arr"+id], 'click', function() { if ((!darg_flags && !mouse_flags)){ window.open(detail_url);} if (darg_flags){darg_flags=false;} } ); 
		    GEvent.addListener(makepoint["arr"+id], 'infowindowopen', function() { infowindow_flags = true; lockSearchbtn("none");}); 
		    GEvent.addListener(makepoint["arr"+id], 'infowindowclose', function() { infowindow_flags = false; lockSearchbtn("inline"); return2oldposition(); }); 
		}else if (markertype == "multi" && count_array > 1){
   			GEvent.addListener(makepoint["arr"+id], 'mouseout', function() { if (darg_flags){ mouse_flags=false; darg_flags=false; } } ); 
		    GEvent.addListener(makepoint["arr"+id], 'click', function() { if ((!darg_flags && !mouse_flags)){ makepoint["arr"+id].openInfoWindow(detail_url);} if (darg_flags){darg_flags=false;} } ); 
		    GEvent.addListener(makepoint["arr"+id], 'infowindowopen', function() { infowindow_flags = true; lockSearchbtn("none");}); 
		    GEvent.addListener(makepoint["arr"+id], 'infowindowclose', function() { infowindow_flags = false; lockSearchbtn("inline"); return2oldposition(); }); 
		}
		map.addOverlay(makepoint["arr"+id]);
		return true;
	}else{
		removeMarker(id);
		return false;
	}
	return false;
}
/**
* removeMarker Function : remove makepoint and list detail
* @param id : id makepoint
*/
function removeMarker(id){
	countitem--;
	map.removeOverlay(makepoint["arr"+id]);
	makepoint["arr"+id] = null;
	sortdetail["arr"+id] = null;
	var tempdiv = document.getElementById("div"+id);
}
/**
* createList Function : create list detail
* @param id : id makepoint
* @param picture_url : picture path
* @param price : data rent
* @param type : data type room
* @param detail_url : detail infowindow or link detail url
* @param markertype : single data or multi data
* @param count_array : check single data or multi data
*/
function createList(id,picture_url,price,type,detail_url,markertype,count_array){
	var str;
			str = "<div style='float:left'><table border='1' bordercolor='#CCCCCC' cellpadding='2' height='"+detail_height+"' cellspacing='0' style='margin-right: 3px; margin-top: 3px;' >";
			str += "<tr><td align='center'><a href='"+detail_url+"' target='_blank' /><img src='"+picture_url+"' border='0' width='"+pic_size+"'></a></td></tr>";
			str += "<tr><td align='center'><a href='"+detail_url+"' target='_blank' />"+price+"円 "+type+"</a></td></tr>";
			str += "</table></div>";
			return str;
}
/**
* chkresize Function : check resize window and return to save position
* @param id : id makepoint
*/
function chkresize(){
/*    
	typemove = false;
	if (window.ActiveXObject){
		chkwindowsize();
	}
	map.returnToSavedPosition();
*/
}
/**
* chkwindowsize Function : check screen size
* @param id : id makepoint
*/
function chkwindowsize(){
    return;
}
/**
* createHeaderopeninfowindow Function : create header table for infowindow
* @param type_name : type apartment
* @param structure : type structure
* @param comp_day : building date
* @param id : id makepoint
* @param picture : picture path
*/
function createHeaderopeninfowindow(type_name,structure,comp_day,id,picture){
	var html = "";
	html  = '<TABLE class="tablestyle" cellSpacing=0 cellPadding=2 border=1 style="WIDTH: 270px;" bordercolor="#CCCCCC">';
	html += '<TR><TD colSpan=4>';
	html += '<TABLE cellSpacing=0 cellPadding=0 border=1 style="WIDTH: 100%;" bordercolor="#CCCCCC">';
//	html += '<TR><TD width=25 >&nbsp;</TD><TD align=center width=140><a href="#" id=sarti_name onclick="sorttype(\''+id+'\',\'arti_name\');">名称</a></TD></TR>';
	html += '<TR><TD width=25 >&nbsp;</TD><TD align=center width=140>名称</TD></TR>';
	html += '<TR><TD colSpan=5><DIV style="WIDTH: 100%; OVERFLOW-X: hidden; OVERFLOW: scroll; HEIGHT: 80px; ">';
	return html;
}
/**
* sorttype Function : sort rent, area and room_on
* @param id : id makepoint
* @param col : colum sort
*/
function sorttype(id,col){
	var temparr = [];
	var arrdetail = sortdetail["arr"+id].split("#");
	for (var i = 0 ; i < arrdetail.length-1; i++){
		var subdeatil = arrdetail[i].split("|");
		tempsort[i] = new Array();
		tempsort[i]['link'+id] = subdeatil[0];
		tempsort[i]['arti_name'+id] = subdeatil[1].replace(/,/g,"")-0;
	}
	tempid = id;
	switch (col){
		case 'arti_name' : 
					tempsort = bbsort(tempsort,tempid,sortby[col],col);
					if (sortby[col] == 'asc'){ 
						sortby[col] = 'desc'; 
						document.getElementById("s"+col).innerHTML = "名称&#9661;";
					}else{ 
						sortby[col] = 'asc'; 
						document.getElementById("s"+col).innerHTML = "名称&#9651;";
					}
					break;
		case 'rent' : 
					tempsort = bbsort(tempsort,tempid,sortby[col],col);
					if (sortby[col] == 'asc'){ 
						sortby[col] = 'desc'; 
						document.getElementById("s"+col).innerHTML = "家賃&#9661;";
					}else{ 
						sortby[col] = 'asc'; 
						document.getElementById("s"+col).innerHTML = "家賃&#9651;";
					}
					clearsort("type","room_on","間取り","部屋番号");
					break;
		case 'type' : 
					tempsort = bbsort(tempsort,tempid,sortby[col],col);
					if (sortby[col] == 'asc'){ 
						sortby[col] = 'desc'; 
						document.getElementById("s"+col).innerHTML = "間取り&#9661;";
					}else{ 
						sortby[col] = 'asc'; 
						document.getElementById("s"+col).innerHTML = "間取り&#9651;";
					}
					clearsort("rent","room_on","家賃","部屋番号");
					break;
		case 'room_on' : 
					tempsort = bbsort(tempsort,tempid,sortby[col],col);
					if (sortby[col] == 'asc'){ 
						sortby[col] = 'desc'; 
						document.getElementById("s"+col).innerHTML = "部屋番号&#9661;";
					}else{ 
						sortby[col] = 'asc'; 
						document.getElementById("s"+col).innerHTML = "部屋番号&#9651;";
					}
					clearsort("type","rent","間取り","家賃");
					break;
	}
	for (var i = 0 ; i < arrdetail.length-1; i++){
		document.getElementById("link"+eval(tempid+""+i)).innerHTML = "<a href='"+tempsort[i]['link'+tempid]+"' target='_blank' >詳細</a>";
		document.getElementById("arti_name"+eval(tempid+""+i)).innerHTML = convert(tempsort[i]['arti_name'+tempid]+"");
	}
}
/**
* clearsort Function : clear colum name
* @param col1 : colum id1
* @param col2 : colum id2
* @param col1name : colum name1
* @param col2name : colum name2
*/
function clearsort(col1,col2,col1name,col2name){
	sortby[col1] = "asc";
	sortby[col2] = "asc";
	document.getElementById("s"+col1).innerHTML = col1name;
	document.getElementById("s"+col2).innerHTML = col2name;
}
/**
* bbsort Function : sort data
* @param data : array data for sort
* @param tempid : id makepoint
* @param type : type sort (asc/desc)
* @param field : filed sort (rent/area/room_on)
*/
function bbsort(data,tempid,type,field){
	var temparr = new Array();
	for (var i = 0; i < data.length; i++){
		temparr[i] = new Array();
		for (var j = i+1; j < data.length; j++){
			if (type == "desc"){
				if (data[i][field+""+tempid] < data[j][field+""+tempid]){
					temparr[i]['link'+tempid] = data[i]['link'+tempid];
					temparr[i]['rent'+tempid] = data[i]['rent'+tempid];
					temparr[i]['type'+tempid] = data[i]['type'+tempid];
					temparr[i]['room_on'+tempid] = data[i]['room_on'+tempid];
					data[i]['link'+tempid] = data[j]['link'+tempid];
					data[i]['rent'+tempid] = data[j]['rent'+tempid];
					data[i]['type'+tempid] = data[j]['type'+tempid];
					data[i]['room_on'+tempid] = data[j]['room_on'+tempid];
					data[j]['link'+tempid] = temparr[i]['link'+tempid];
					data[j]['rent'+tempid] = temparr[i]['rent'+tempid];
					data[j]['type'+tempid] = temparr[i]['type'+tempid];
					data[j]['room_on'+tempid] = temparr[i]['room_on'+tempid];
				}
			}else if (type == "asc"){
				if (data[i][field+""+tempid] > data[j][field+""+tempid]){
					temparr[i]['link'+tempid] = data[j]['link'+tempid];
					temparr[i]['rent'+tempid] = data[j]['rent'+tempid];
					temparr[i]['type'+tempid] = data[j]['type'+tempid];
					temparr[i]['room_on'+tempid] = data[j]['room_on'+tempid];
					data[j]['link'+tempid] = data[i]['link'+tempid];
					data[j]['rent'+tempid] = data[i]['rent'+tempid];
					data[j]['type'+tempid] = data[i]['type'+tempid];
					data[j]['room_on'+tempid] = data[i]['room_on'+tempid];
					data[i]['link'+tempid] = temparr[i]['link'+tempid];
					data[i]['rent'+tempid] = temparr[i]['rent'+tempid];
					data[i]['type'+tempid] = temparr[i]['type'+tempid];
					data[i]['room_on'+tempid] = temparr[i]['room_on'+tempid];
				}
			}
		}
	}
	return data;
}
/**
* convert Function : convert int to string price format (xx,xxx)
* @param prices : integer for convert to string price format
*/
function convert(prices){
	var price = prices.split(".");
	price[0] = price[0].replace(/,/g,"");
	var price_int = parseInt(price[0].length/3);
	if ((price[0].length/3) >= price_int && price[0].length > 3){
		var rs = false;
		var temp = new Array();
		if ((price[0].length/3) == price_int){
			rs = true;
		}
		for (var i = 0; i < price_int; i++){
			temp[price_int-(i)] = price[0].substr(price[0].length-((i+1)*3),3);
		}
		if (rs){
			temp = temp.slice(1);
		}else{
			temp[0] = price[0].substr(0,price[0].length-(price_int*3));
		}
		price[0] = temp;
	}
	if (price.length > 1){
		return price[0]+"."+price[1];
	}else{
		return price[0];
	}
}
/**
* chkfiltering Function : send data and check data rent when startprice > endprice and endprice != null
*/
function chkfiltering(){
/*
	if ((window.frm.startprice.value-0 > window.frm.endprice.value-0) && window.frm.endprice.value != ""){
		alert("賃料の範囲を正しく入力してください。 ");
		return2oldposition();
	}else{
		startRequest();		
	}
*/
	startRequest();
}
/**
* chkitem Function : count list data for show and hide list data
*/
function chkitem(countitem){
	if (countitem == 0){
		document.getElementById("retMSG").value = "該当物件がありませんでした。";
	}else if (countitem < 0){
		alert("Error Report : Item Error");
	}else if (countitem > 0){
		document.getElementById("retMSG").value = countitem + "件検索されました。";
	}
}
