//搜索API
var loadSearchUrl ="http://www.mapdh.com/starmaps/maplteService?url=";
var sourceUrl2 ="http://nearby.myemap.com.cn/getCityNameByLid.jsp";//ECityNameByLidSearch
var sourceUrl3 ="http://bus.myemap.com.cn/getStationList.jsp";//EGetStationListSearch
var sourceUrl4 ="http://pic.myemap.com.cn/image.jsp";//EImageSearch
var sourceUrl5 ="http://index.myemap.com.cn/search.jsp";//ELocalSearch
var sourceUrl6 ="http://nearby.myemap.com.cn/nearby.jsp";//ENearbySearch(周边搜索)
var sourceUrl7 ="http://index.myemap.com.cn/poi.jsp";//EPoiSearch
var sourceUrl8 ="http://nearby.myemap.com.cn/getPosition.jsp";//EPositionSearch
var sourceUrl9 ="http://traffic.myemap.com.cn/bus.jsp";//EQRouteSearch  公交搜索

var sourceUrl10 ="http://traffic.myemap.com.cn/searchline.jsp";//根据关键字查询线路
var sourceUrl15 ="http://traffic.myemap.com.cn/getLine.jsp";//根据线路lid去查询线路详细信息


var sourceUrl11 ="http://traffic.myemap.com.cn/searchstop.jsp";//Exact Match   单站点查询   http://bus.myemap.com.cn/queryStation.jsp
var sourceUr112 ="http://traffic.myemap.com.cn/searchstop.jsp";//Fuzzy search 单站点查询    http://bus.myemap.com.cn/queryBusStation.jsp
var sourceUrl13 ="http://route.myemap.com.cn/route.jsp";//ERouteSearch  公交换乘  
var sourceUrl14 ="http://search.myemap.com.cn/searchRoad.jsp";//ESearchRoadSearch

var sourceUrl20="http://traffic.myemap.com.cn/getLine.jsp";//?cid=110000&lineId=ZNCVDVMWCIESDVD


var EClass = {create:function () {
	return function () {
		this.initialize.apply(this, arguments);
	};
}};

/////////////////////////ERequest////////////////////////////
function ERequest(url, callMethod) {
	showHint(url, callMethod);
}

/////////////////showHint--Ajax/////////////////////
var xmlHttp;
function showHint(url, callMethod) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("AJAX not be suppported!");
		return;
	}
	xmlHttp.onreadystatechange = stateChanged;
	function stateChanged() {
		if (xmlHttp.readyState == 4) {
			callMethod(eval(xmlHttp.responseText));
		}
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
    // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
    // Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
///////////////////////EByLidInfoSearch/////////////////////////////////
var EByLidInfoSearch = EClass.create();
EByLidInfoSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, byLidInfoSearch:function (word, wordInfo) {

	this.word = word;
	this.optsInfo = wordInfo;
	
	if (word == null) {
		alert("lineID can not be null");
		return;
	}
	if (this.optsInfo.lid != null) {
		var pars = "?lineId=" + this.optsInfo.lid + "&cid=" + this.optsInfo.cid;
		var u = sourceUrl15 + pars;
		var par = encodeURIComponent(u);
		url = loadSearchUrl + par;
		this.resSearch(url);
	} else {
		alert("Encryption latitude and longitude can not be empty");
		return;
	}
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EByLidInfo(cid,lid) {
    this.cid = cid || null;
	this.lid = lid || null;
} 

///////////////////////ECityNameByLidSearch/////////////////////////////////
var ECityNameByLidSearch = EClass.create();
ECityNameByLidSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, CityNameByLidSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	if (this.optsInfo.lid != null) {
		var pars = "?lid=" + this.optsInfo.lid;
		var u = sourceUrl2 + pars;
		var par = encodeURIComponent(u);
		url = loadSearchUrl + par;
		this.resSearch(url);
	} else {
		alert("Encryption latitude and longitude can not be empty");
		return;
	}
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function ECityNameByLidInfo(lid) {
	this.lid = lid || null;
} 
/////////////////////EGetStationListSearch////////////////////////////
var EGetStationListSearch = EClass.create();
EGetStationListSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, GetStationListKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var pars = "?routeName=" + this.word + "&cid=" + this.optsInfo.cid + "&start=" + this.optsInfo.start + "&end=" + this.optsInfo.end;
	var u = sourceUrl3 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};

function EGetStationListInfo(cid, routeName, start, end) {
	this.cid = cid || null;
	this.routeName = routeName || null;
	this.start = start || null;
	this.end = end || null;
} 
////////////////////////EImageSearch////////////////////////////
var EImageSearch = EClass.create();
EImageSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, ImageSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	if (this.optsInfo.z != null && this.optsInfo.ua != null && this.optsInfo.p != null && this.optsInfo.U != null && this.optsInfo.D != null && this.optsInfo.L != null && this.optsInfo.R != null) {
		var pars = "?lid=" + this.word + "&z=" + this.optsInfo.z + "&ua=" + this.optsInfo.ua + "&p=" + this.optsInfo.p + "&U=" + this.optsInfo.U + "&D=" + this.optsInfo.D + "&L=" + this.optsInfo.L + "&R=" + this.optsInfo.R;
		var u = sourceUrl4 + pars;
		var par = encodeURIComponent(u);
		url = loadSearchUrl + par;
		this.resSearch(url);
	} else {
		alert("Fill can not be empty");
		return;
	}
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EImageInfo(lid, z, ua, p, U, D, L, R) {
	this.lid = lid || null;
	this.ua = ua || null;
	this.z = z || null;
	this.p = p || null;
	this.U = U || null;
	this.D = D || null;
	this.L = L || null;
	this.R = R || null;
} 
	/////////////////ELocalSearch////////////////////////
var ELocalSearch = EClass.create();
ELocalSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, LocalSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
					//alert(this.optsInfo.cid);
					//alert(this.optsInfo.pid);
					//alert(this.optsInfo.row);
					//alert(this.optsInfo.tid);
					//alert(this.optsInfo.addr);
					//alert(this.optsInfo.tab);
	var pars = "";//"?word="+this.word+"&cid="+this.optsInfo.cid+"&pid="+this.optsInfo.pid+"&row="+this.optsInfo.row+"&tid="+this.optsInfo.tid+"&addr="+this.optsInfo.addr+"&tab="+this.optsInfo.tab;
                    //pars.push("?word=" + this.word); //关键字
					//((this.optsInfo.cid == null) ? '' : pars.push("&cid="+this.optsInfo.cid)); //关键字
					//((this.optsInfo.pid == null) ? '' : pars.push("&pid="+this.optsInfo.pid)); //关键字
					//((this.optsInfo.row == null) ? '' : pars.push("&row="+this.optsInfo.row)); //关键字
					//((this.optsInfo.tid == null) ? '' : pars.push("&tid="+this.optsInfo.tid)); //关键字
					//((this.optsInfo.addr == null) ? '' : pars.push("&addr="+this.optsInfo.addr)); //关键字
					//((this.optsInfo.tab == null) ? '' : pars.push("&tab="+this.optsInfo.tab)); //关键字
	pars += "?word=" + this.word;
	pars += (this.optsInfo.cid == null) ? "" : "&cid=" + this.optsInfo.cid;
	pars += (this.optsInfo.pid == null) ? "" : "&pid=" + this.optsInfo.pid;
	pars += (this.optsInfo.row == null) ? "" : "&row=" + this.optsInfo.row;
	pars += (this.optsInfo.tid == null) ? "" : "&tid=" + this.optsInfo.tid;
	pars += (this.optsInfo.addr == null) ? "" : "&addr=" + this.optsInfo.addr;
	pars += (this.optsInfo.tab == null) ? "" : "&tab=" + this.optsInfo.tab;
	//pars += (this.optsInfo.tab == null) ? "" : "&tab=0" ;
	var u = sourceUrl5 + pars;
	//document.location.href = u;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	//document.location.href = u;

	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};

function ELocalInfo(cid, pid, row, tid, word, addr, tab) {
	this.cid = cid || null;
	this.pid = pid || null;
	this.row = row || null;
	this.tid = tid || null;
	this.word = word || null;
	this.addr = addr || null;
	this.tab = tab || null;
} 
/////////////////////ENearbySearch///////////////////////////
var ENearbySearch = EClass.create();
ENearbySearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, NearbySearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	
	var pars = "?word=" + this.word + "&lid=" + this.optsInfo.lid + "&tid=" + this.optsInfo.tid + "&r=" + this.optsInfo.r + "&pid=" + this.optsInfo.pid + "&row=" + this.optsInfo.row;
	var u = sourceUrl6 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function ENearbyInfo(lid, tid, r, pid, row, word) {
	this.lid = lid || null;
	this.tid = tid || null;
	this.r = r || null;
	this.pid = pid || null;
	this.row = row || null;
	this.word = word || null;
} 
	//////////////////EPoiSearch//////////////////////////
var EPoiSearch = EClass.create();
EPoiSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, PoiSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var pars = "?cid=" + this.word + "&id=" + this.optsInfo.id;
	var u = sourceUrl7 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EPoiInfo(id, cid) {
	this.id = id || null;
	this.cid = cid || null;
} 
	//////////////////EPositionSearch//////////////////////////////
var EPositionSearch = EClass.create();
EPositionSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, PositionKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var pars = null;
	if (this.optsInfo.lid != null || this.optsInfo.lat != null || this.optsInfo.lon != null) {
		if (this.optsInfo.lid != null) {
			pars = "?lid=" + this.optsInfo.lid;
		} else {
			pars = "?lat=" + this.optsInfo.lat + "&lon=" + this.optsInfo.lon;
		}
	} else {
		alert("Non-full-empty");
		return;
	}
	var u = sourceUrl8 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EPositionInfo(lid, lat, lon) {
	this.lid = lid || null;
	this.lat = lat || null;
	this.lon = lon || null;
} 
////////////////////////EQRouteSearch////////////////////////////////
var EQRouteSearch = EClass.create();
EQRouteSearch.prototype = {initialize:function () {
	this.call = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, qRouteSearchKeyword:function (wordInfo) {
	var pars = null;
	this.optsInfo = wordInfo;
	var u = null;
	if (this.optsInfo.start == null || this.optsInfo.end == null) {
		pars = "?cid=" + this.optsInfo.cid + "&sid=" + this.optsInfo.sid + "&eid=" + this.optsInfo.eid + "&flag=" + this.optsInfo.flag;
	} else {
		pars = "?cid=" + this.optsInfo.cid + "&start=" + this.optsInfo.start + "&end=" + this.optsInfo.end + "&flag=" + this.optsInfo.flag;
	}
	u = sourceUrl9 + pars;
	//document.location.href = u;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EQRouteInfo(cid, start, end, sid, eid,flag) {
	this.cid = cid || null;
	this.start = start || null;
	this.end = end || null;
	this.sid = sid || null;
	this.eid = eid || null;
	this.flag = flag || 2;
} 
	///////////////EQueryRouteSearch//////////////////////////
var EQueryRouteSearch = EClass.create();
EQueryRouteSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, queryRouteSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var pars = "?word=" + this.word + "&cid=" + this.optsInfo.cid;
	var u = sourceUrl10 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EQueryRouteInfo(cid, roadName) {
	this.cid = cid || null;
	this.roadName = roadName || null;
} 
//////////////////////EQueryStationSearch:公交站点查询//////////////////////////////////
var EQueryStationSearch = EClass.create();
EQueryStationSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, queryStationSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var u = null;
	if (this.optsInfo.cid != null) {
		var pars = "?word=" + this.optsInfo.word + "&cid=" + this.optsInfo.cid + "&pid=" + this.optsInfo.pid + "&row=" + this.optsInfo.row;
		if (this.optsInfo.pid == null || this.optsInfo.row == null) {
			u = sourceUr112 + pars;
		} else {
			u = sourceUrl11 + pars;
		}
		var par = encodeURIComponent(u);
		url = loadSearchUrl + par;
		//window.location.href = url;
		this.resSearch(url);
	} else {
		alert("City Code can not be empty");
		return;
	}
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function EQueryStationInfo(cid, word, pid, row) {
	this.cid = cid || null;
	this.word = word || null;
	this.pid = pid || null;
	this.row = row || null;
} 

/////////////////////ERouteSearch/////////////////////////////////////导航搜索
var ERouteSearch = EClass.create();
ERouteSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, RouteSearchKeyword:function (wordInfo) {
	
	this.optsInfo = wordInfo;
	
	var pars = "?dLid=" + this.optsInfo.dLid + "&sLid=" + this.optsInfo.sLid + "&style=" + this.optsInfo.style + "&toll=" + this.optsInfo.toll;
	var u = sourceUrl13 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function ERouteInfo(sLid, dLid, style, toll) {
	this.sLid = sLid || null;
	this.dLid = dLid || null;
	this.style = style || 0;
	this.toll = toll || 0;
} 

////////////////////ESearchRoadSearch//////////////////////////////////

var ESearchRoadSearch = EClass.create();
ESearchRoadSearch.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, SearchRoadSearchKeyword:function (word, wordInfo) {
	this.word = word;
	this.optsInfo = wordInfo;
	if (word == null) {
		alert("keyWord can not be null");
		return;
	}
	var pars = "?roadName=" + this.word + "&cid=" + this.optsInfo.cid;
	var u = sourceUrl14 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};
function ESearchRoadInfo(roadName, cid) {
	this.roadName = roadName || null;
	this.cid = cid || null;
}
///////////////////ELineSearchByLineId:根据线路lineid和cid去查询线路/////////////////
var ELineSearchByLineId = EClass.create();
ELineSearchByLineId.prototype = {initialize:function () {
	this.call = null;
	this.word = null;
	this.optsInfo = null;
}, setCallback:function (call) {
	this.call = call;
}, lineSearchByLineId:function (lineId, wordInfo) {
	this.lineId = lineId;
	this.optsInfo = wordInfo;
	if (lineId == null) {
		alert("lineId can not be null");
		return;
	}
	var pars = "?lineId=" + this.lineId;
	pars += (this.optsInfo.cid == null) ? "" : "&cid=" + this.optsInfo.cid;
	var u = sourceUrl20 + pars;
	var par = encodeURIComponent(u);
	url = loadSearchUrl + par;
	this.resSearch(url);
}, resSearch:function (url) {
	var re = new ERequest(url, this.call);
}};

function ELineSearchInfo(cid,lineId) {
	this.cid = cid || null;
	this.lineId = lineId || null;
} 

