	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}  
		}
	}

	if (!request)
		alert("Error initializing XMLHttpRequest!");

	function exithtml(kkk) {
		//alert(kkk);
		var url = "exithtml.php";
		request.open("GET", url, true);
		request.onreadystatechange = exithtmlback
		request.send(null);
	}
	
	function exithtmlback() {
		if (request.readyState == 4){
			if (request.status == 200){
				response = request.responseText;
				//alert(response);
			} else if (request.status == 404){
				alert("Request URL does not exist");
			} else if (request.status == 403) {
				alert("Access denied.");
			}else{
				alert("Error: status code is " + request.status);
			}
		}
	}

	function registeremail(email) {
		var url = "registeremail.php?email="+email;
		request.open("GET", url, true);
		request.onreadystatechange = registeremailback
		request.send(null);
	}
	
	function registeremailback() {
		if (request.readyState == 4){
			if (request.status == 200){
				response = request.responseText;
				if(eval(response)>0){
					document.getElementById('reemail').disabled=true;
					document.getElementById('reemail').value='此E-mail已經註冊過!!';
				}else{
					document.getElementById('reemail').disabled=false;
					document.getElementById('reemail').value='';
					document.SendMailPost.email.focus();
				}

			} else if (request.status == 404){
				alert("Request URL does not exist");
			} else if (request.status == 403) {
				alert("Access denied.");
			}else{
				alert("Error: status code is " + request.status);
			}
		}
	}

function showMenu(ctrlid, click, offset, duration, timeout, layer, showid, maxh) {
	e = window.event ? window.event : showMenu.caller.arguments[0];
	var ctrlobj = document.getElementById(ctrlid);
	if(!ctrlobj) return;
	if(isUndefined(click)) click = false;
	if(isUndefined(offset)) offset = 0;
	if(isUndefined(duration)) duration = 2;
	if(isUndefined(timeout)) timeout = 500;
	if(isUndefined(layer)) layer = 0;
	if(isUndefined(showid)) showid = ctrlid;
	var showobj = document.getElementById(showid);
	var menuobj = document.getElementById(showid + '_menu');
	if(!showobj|| !menuobj) return;
	if(isUndefined(maxh)) maxh = 400;

	hideMenu(layer);

	for(var id in jsmenu['timer']) {
		if(jsmenu['timer'][id]) clearTimeout(jsmenu['timer'][id]);
	}

	initCtrl(ctrlobj, click, duration, timeout, layer);
	ctrlobjclassName = ctrlobj.className;
	ctrlobj.className += ' hover';
	initMenu(ctrlid, menuobj, duration, timeout, layer);

	menuobj.style.display = '';
	if(!is_opera) {
		menuobj.style.clip = 'rect(auto, auto, auto, auto)';
	}

	setMenuPosition(showid, offset);

	if(is_ie && is_ie < 7) {
		if(!jsmenu['iframe'][layer]) {
			var iframe = document.createElement('iframe');
			iframe.style.display = 'none';
			iframe.style.position = 'absolute';
			iframe.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			document.getElementById('append_parent') ? document.getElementById('append_parent').appendChild(iframe) : menuobj.parentNode.appendChild(iframe);
			jsmenu['iframe'][layer] = iframe;
		}
		jsmenu['iframe'][layer].style.top = menuobj.style.top;
		jsmenu['iframe'][layer].style.left = menuobj.style.left;
		jsmenu['iframe'][layer].style.width = menuobj.w;
		jsmenu['iframe'][layer].style.height = menuobj.h;
		jsmenu['iframe'][layer].style.display = 'block';
	}

	if(maxh && menuobj.scrollHeight > maxh) {
		menuobj.style.height = maxh + 'px';
		if(is_opera) {
			menuobj.style.overflow = 'auto';
		} else {
			menuobj.style.overflowY = 'auto';
		}
	}

	if(!duration) {
		setTimeout('hideMenu(' + layer + ')', timeout);
	}

	jsmenu['active'][layer] = menuobj;
}

function setMenuPosition(showid, offset) {
	var showobj = document.getElementById(showid);
	var menuobj = document.getElementById(showid + '_menu');
	if(isUndefined(offset)) offset = 0;
	if(showobj) {
		showobj.pos = fetchOffset(showobj);
		showobj.X = showobj.pos['left'];
		showobj.Y = showobj.pos['top'];
		showobj.w = showobj.offsetWidth;
		showobj.h = showobj.offsetHeight;
		menuobj.w = menuobj.offsetWidth;
		menuobj.h = menuobj.offsetHeight;
		menuobj.style.left = (showobj.X + menuobj.w > document.body.clientWidth) && (showobj.X + showobj.w - menuobj.w >= 0) ? showobj.X + showobj.w - menuobj.w + 'px' : showobj.X + 'px';
		menuobj.style.top = offset == 1 ? showobj.Y + 'px' : (offset == 2 || ((showobj.Y + showobj.h + menuobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - menuobj.h >= 0)) ? (showobj.Y - menuobj.h) + 'px' : showobj.Y + showobj.h + 'px');
		if(menuobj.style.clip && !is_opera) {
			menuobj.style.clip = 'rect(auto, auto, auto, auto)';
		}
	}
}

function hideMenu(layer) {
	if(isUndefined(layer)) layer = 0;
	if(jsmenu['active'][layer]) {
		try {
			$(jsmenu['active'][layer].ctrlkey).className = ctrlobjclassName;
		} catch(e) {}
		clearTimeout(jsmenu['timer'][jsmenu['active'][layer].ctrlkey]);
		jsmenu['active'][layer].style.display = 'none';
		if(is_ie && is_ie < 7 && jsmenu['iframe'][layer]) {
			jsmenu['iframe'][layer].style.display = 'none';
		}
		jsmenu['active'][layer] = null;
	}
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function initCtrl(ctrlobj, click, duration, timeout, layer) {
	if(ctrlobj && !ctrlobj.initialized) {
		ctrlobj.initialized = true;
		ctrlobj.unselectable = true;

		ctrlobj.outfunc = typeof ctrlobj.onmouseout == 'function' ? ctrlobj.onmouseout : null;
		ctrlobj.onmouseout = function() {
			if(this.outfunc) this.outfunc();
			if(duration < 3) jsmenu['timer'][ctrlobj.id] = setTimeout('hideMenu(' + layer + ')', timeout);
		}

		if(click && duration) {
			ctrlobj.clickfunc = typeof ctrlobj.onclick == 'function' ? ctrlobj.onclick : null;
			ctrlobj.onclick = function (e) {
				doane(e);
				if(jsmenu['active'][layer] == null || jsmenu['active'][layer].ctrlkey != this.id) {
					if(this.clickfunc) this.clickfunc();
					else showMenu(this.id, true);
				} else {
					hideMenu(layer);
				}
			}
		}

		ctrlobj.overfunc = typeof ctrlobj.onmouseover == 'function' ? ctrlobj.onmouseover : null;
		ctrlobj.onmouseover = function(e) {
			doane(e);
			if(this.overfunc) this.overfunc();
			if(click) {
				clearTimeout(jsmenu['timer'][this.id]);
			} else {
				for(var id in jsmenu['timer']) {
					if(jsmenu['timer'][id]) clearTimeout(jsmenu['timer'][id]);
				}
			}
		}
	}
}

function initMenu(ctrlid, menuobj, duration, timeout, layer) {
	if(menuobj && !menuobj.initialized) {
		menuobj.initialized = true;
		menuobj.ctrlkey = ctrlid;
		menuobj.onclick = ebygum;
		menuobj.style.position = 'absolute';
		if(duration < 3) {
			if(duration > 1) {
				menuobj.onmouseover = function() {
					clearTimeout(jsmenu['timer'][ctrlid]);
				}
			}
			if(duration != 1) {
				menuobj.onmouseout = function() {
					jsmenu['timer'][ctrlid] = setTimeout('hideMenu(' + layer + ')', timeout);
				}
			}
		}
		menuobj.style.zIndex = 50;
		if(is_ie) {
			menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)";
		}
	}
}

function ebygum(eventobj) {
	if(!eventobj || is_ie) {
		window.event.cancelBubble = true;
		return window.event;
	} else {
		if(eventobj.target.type == 'submit') {
			eventobj.target.form.submit();
		}
		eventobj.stopPropagation();
		return eventobj;
	}
}

function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}

function getmertomap(metro_id) {
	//alert(kkk);
	var url = "searchmerto.php?metro_id="+metro_id+"&gettype=1";
	request.open("GET", url, true);
	request.onreadystatechange = getmertomapback
	request.send(null);
}

function getmertomapback() {
	if (request.readyState == 4){
		if (request.status == 200){
			response = request.responseText;
			pointXY=response.split(",");
			map.panTo(new GLatLng (pointXY[1], pointXY[0]));
			setTimeout( 'getbounds()' ,250);
			setTimeout( 'searchmerto()' ,500);
		} else if (request.status == 404){
			alert("Request URL does not exist");
		} else if (request.status == 403) {
			alert("Access denied.");
		}else{
			alert("Error: status code is " + request.status);
		}
	}
}

function searchmerto() {
	//alert(kkk);
	var url = "searchmerto.php?gettype=2&lng1="+lng1+"&lng2="+lng2+"&lat1="+lat1+"&lat2="+lat2;
	request.open("GET", url, true);
	request.onreadystatechange = searchmertoback
	request.send(null);
}

function searchmertoback() {
	if (request.readyState == 4){
		if (request.status == 200){
			response = request.responseText;
			showmetromap(response);
		} else if (request.status == 404){
			alert("Request URL does not exist");
		} else if (request.status == 403) {
			alert("Access denied.");
		}else{
			alert("Error: status code is " + request.status);
		}
	}
}

function gometromap(metro_id) {
	getmertomap(metro_id);
}

function showmetromap(metroDatas) {
	clearMaker();
    MapFlagObj.length = 0;
	metroDatasSplit=metroDatas.split(",");
	var kkk=0;
	for(kk=0;kk<metroDatasSplit.length;kk++){
		metroData=metroDatasSplit[kk];
		if(metroData.length>0){
			metroDataSplit=metroData.split("##");
			title=metroDataSplit[5];
			makerdata="<div align='left'><a href='index.php?selpage="+metroDataSplit[4]+"&sbp="+metroDataSplit[0]+"&viewid="+metroDataSplit[1]+"&selpageflag="+eval(Math.random()*1000)+"'>"+title+"</a><br>住址："+metroDataSplit[6]+"</div>";

			posn = new GLatLng(metroDataSplit[3], metroDataSplit[2]);
			MapFlagObj[kkk++] = createMarker(posn,makerdata); 
			//MapFlagObj.push(marker);
		}
	}
}

function clearMaker(){
	for(ii=0;ii<MapFlagObj.length;ii++){
		map.removeOverlay(MapFlagObj[ii]);
	}
}
function createMarker(posn,  makerdata) {
	var marker = new GMarker(posn, mOpt);
	map.addOverlay(marker);  
	marker.disableDragging();
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(makerdata);
	});
	return marker;
}

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var jsmenu = new Array();
jsmenu['active'] = new Array();
jsmenu['timer'] = new Array();
jsmenu['iframe'] = new Array();



function in_array(stringToSearch, arrayToSearch) {
    for (s = 0; s <arrayToSearch.length; s++) {
        thisEntry = arrayToSearch[s].toString();
        if (thisEntry == stringToSearch) {
            return true;
        }
    }
    return false;
}

function pagetags(itemname,TagName){
	NewThisItemValue='';
	ThisItem=document.getElementById(itemname);
	ThisItemValue=ThisItem.value;
	ThisItemValueSplit=ThisItemValue.split(" ");
	if( in_array(TagName, ThisItemValueSplit) ){
		for (s = 0; s <ThisItemValueSplit.length; s++) {
			ThisArrayValues = ThisItemValueSplit[s].toString();
			if ( ThisArrayValues != TagName && ThisArrayValues!='') {
				NewThisItemValue+= ' ' + ThisArrayValues;
			}
		}
		ThisItem.value = NewThisItemValue;
	}else{
		ThisItem.value+= ' ' + TagName;
	}
}

