var requesttype;
var def_sel_value;
var my_cid, my_rid;
var locationmenucallback;
var xlocationmenu = new xMenu1('', 'locationmenu', 'locationmenuiframe', 10, '', 0);
var xtriggerobj;
var xalloption;
var xdisplacement;
var xtargetuser;
var xparentobj;
var xisshowspotcount;
var acObjBrowse = null;
//var ac_callback = null;
var changeLCountry = null;
var changeLRegion = null;
var changeLCity = null;
function handler()
{
try
{
if (ajax_abort || http_request.readyState == 4)
{
xlocationmenu.onClose();
if(!ajax_abort && http_request.status == 200)
{
var htmlarray = new Array();
if(http_request.responseXML != null)
{
nodes = http_request.responseXML.getElementsByTagName('country');
if (nodes.length==0)
{
nodes = http_request.responseXML.getElementsByTagName('region');
if (nodes.length==0)
nodes = http_request.responseXML.getElementsByTagName('city');
}
var shortcutsarray = new Array();
if (nodes.length>0)
{
namenodes = http_request.responseXML.getElementsByTagName('name');
valuenodes = http_request.responseXML.getElementsByTagName('value');
prioritynodes = http_request.responseXML.getElementsByTagName('priority');
dialcodenodes = http_request.responseXML.getElementsByTagName('dialcode');
currencynodes = http_request.responseXML.getElementsByTagName('currency');
isonodes = http_request.responseXML.getElementsByTagName('iso');
spotcountnodes = http_request.responseXML.getElementsByTagName('spots');
var query = "cid=";
if ((my_cid!=null && my_cid>0) || (my_rid!=null))
{
query+= my_cid + "&rid=";
if (my_rid!=null) query+= my_rid + "&ctid=";
}
var optionarray = new Array();
cnt = 0;
for (var k = 0; k<nodes.length; k++)
{
if (prioritynodes[k].childNodes[0].nodeValue!="0")
{
if(namenodes[k].childNodes[0].nodeValue!= "")
{
if (dialcodenodes.length==0) //region /city
{
shortcutsarray.push(getLink(namenodes[k].childNodes[0].nodeValue, ["xMenuCallback(\"/browse.jsp?",query,'", "',namenodes[k].childNodes[0].nodeValue,'",\"',valuenodes[k].childNodes[0].nodeValue,'\")']));
}
else
{
if (spotcountnodes[k].childNodes[0].nodeValue==0 && xisshowspotcount)
{
optionarray.push(getOption(namenodes[k].childNodes[0].nodeValue + (xisshowspotcount ? " (" + spotcountnodes[k].childNodes[0].nodeValue + ")" : ""), [valuenodes[k].childNodes[0].nodeValue,",",dialcodenodes[k].childNodes[0].nodeValue,",",currencynodes[k].childNodes[0].nodeValue,",",isonodes[k].childNodes[0].nodeValue]));
continue;
}
shortcutsarray.push(getLink(namenodes[k].childNodes[0].nodeValue + (xisshowspotcount ? " (" + spotcountnodes[k].childNodes[0].nodeValue + ")" : ""), ["xMenuCallback(\"/browse.jsp?",query,'", "',namenodes[k].childNodes[0].nodeValue,'",\"',valuenodes[k].childNodes[0].nodeValue,",",dialcodenodes[k].childNodes[0].nodeValue,",",currencynodes[k].childNodes[0].nodeValue,",",isonodes[k].childNodes[0].nodeValue,'\")'], isonodes[k].childNodes[0].nodeValue));
}
if(++cnt%3==0) shortcutsarray.push("</tr><tr>");
}
}
if (dialcodenodes.length==0) //region /city
optionarray.push(getOption(namenodes[k].childNodes[0].nodeValue, [valuenodes[k].childNodes[0].nodeValue]));
else
optionarray.push(getOption(namenodes[k].childNodes[0].nodeValue + (xisshowspotcount ? " (" + spotcountnodes[k].childNodes[0].nodeValue + ")" : ""), [valuenodes[k].childNodes[0].nodeValue,",",dialcodenodes[k].childNodes[0].nodeValue,",",currencynodes[k].childNodes[0].nodeValue,",",isonodes[k].childNodes[0].nodeValue]));
}
var shortcuts="";
if (shortcutsarray.length>0)
{
if (xalloption) shortcutsarray.push(getLink("All Destinations", ["xMenuCallback(\"/browse.jsp?",query,'", "All Destinations",\"0\")']));
shortcuts += "<img src=\"/images/des_shortcut1.jpg\" width=\"21\" height=\"20\" border=\"0\" /><img src=\"/images/spacer.gif\" border=\"0\" width=\"340\" height=\"1\" /><img src=\"/images/des_shortcut2.jpg\" width=\"22\" height=\"20\" border=\"0\" /></p>"
+ "<div style=\"padding-left:10px;\">"
+ "<table width=\"370\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr>" + shortcutsarray.join("") + "</tr></table></div>"
+ "<img src=\"/images/des_shortcut3.jpg\" width=\"21\" height=\"20\" border=\"0\" /><img src=\"/images/spacer.gif\" border=\"0\" width=\"340\" height=\"1\" /><img src=\"/images/des_shortcut4.jpg\" width=\"22\" height=\"20\" border=\"0\" /></p>";
//all links
}
else
{
if (xalloption) optionarray.push(getOption("All Destinations", ["0"]));
}
htmlarray.push(shortcuts);
htmlarray.push("<div>"); //pull down
htmlarray.push("<table width=\"390\" border=\"0\" cellpadding=\"0\" style=\"height:160px; background-image:url(/images/des_map.gif); background-position:top right; background-repeat: no-repeat;\"><tr><td align=\"left\" valign=\"top\"><h2>complete list</h2><br><span style=\"padding-left:10px;\">");
htmlarray.push("<select class=\"browse_pulldown\" id=\"location_select\">");
htmlarray.push(optionarray.join(""));
htmlarray.push("</select>");
htmlarray.push("&nbsp;<img width='37' height='22' style='cursor:pointer;' align=\"absmiddle\" src='/images/buttons/go.png' onclick=\"xMenuCallback('/browse.jsp?");
htmlarray.push(query);
htmlarray.push("', xGetElementById('location_select').options[xGetElementById('location_select').selectedIndex].text, xGetElementById('location_select').options[xGetElementById('location_select').selectedIndex].value);\">");
htmlarray.push("</td></tr></table></div>");
}
var title="", tablewidth="430";
if (htmlarray.length>0)
{
if (shortcuts!="") 	title = "shortcuts";
}
else
{
if (xtargetuser)
{
title  = "There is no spot for filtering.";
}
else
{
title  = "oops, the tree will be ready soon. Contact us if you would like to help.";
}
tablewidth="220";
}
var html = "<table id='tb001' width='" + tablewidth + "' border=\"0\" style=\"border-width:2px; border-style:solid; border-color:#57B6DD;\"><tr><td align=\"left\" style=\"padding-left: 20px; padding-right: 20px; padding-top: 5px\"><h2>" + title + "</h2>";
if (/* my_cid!=null && ac_callback!=null */ (changeLCountry!=null || changeLRegion!=null || changeLCity!=null) && nodes.length>0)
{
html += "<input type='text' class='terms' id='loc_ac' value=' Enter location name here...'>";
}
html += "</td></tr><tr><td align=center>" + htmlarray.join("");
html += "</td></tr><tr><td align='right'>";
html += "<a class='terms' onclick='xlocationmenu.onClose();' style='cursor:pointer;'>close</a>";
html += "</td></tr></table>";
xGetElementById("locationmenu").innerHTML = html;
xlocationmenu.onOpen(xWidth(xGetElementById("tb001")), xHeight(xGetElementById("tb001")), xtriggerobj, xdisplacement, xparentobj);
if (/* my_cid!=null && ac_callback!=null */ (changeLCountry!=null || changeLRegion!=null || changeLCity!=null) && nodes.length>0)
{
if (acObjBrowse==null) acObjBrowse = new ACObject('acObjBrowse');
var par="";
if (my_cid!=null) par = "cid=" + my_cid;
if (my_rid!=null) par += "&rid=" + my_rid;
acObjBrowse.SetAC(xGetElementById("loc_ac"), "searchLoc", par, locationACCallbackDespatcher, xtriggerobj, 'xGetElementById("loc_ac").select();');
xGetElementById("loc_ac").focus();
}
return;
}
}
hideWait();
alert("Cannot execute request, please try again later.");
}
}
finally
{
http_request=null;
}
}
function defACLocationCallback(originate_obj, result, txt, param)
{
var txts = txt.split(",");
var o = xGetElementById("location_select");
if (o)
{
for (var k=0; k<o.length; k++)
{
if (o.options[k].value.indexOf(txts[0])==0)
{
xMenuCallback("/browse.jsp?cid=",o.options[k].text,o.options[k].value);
break;
}
}
}
}
function xMenuCallback(url, name, value)
{
var v = value.split(",");
if (locationmenucallback!=null)
{
if (v.length==1)
locationmenucallback(url, name, v[0], xtriggerobj);
else
locationmenucallback(url, name, v[0], xtriggerobj, v[1], v[2], v[3]);
}
else
{
window.location.href=url + v[0];
}
}
function getOption(name, valuearray)
{
var opt=new Array();
opt.push("<option value=\"");
opt.push(valuearray.join(""));
opt.push("\"");
if (def_sel_value==valuearray[0]) opt.push(" selected");
opt.push(">");
opt.push(name);
opt.push("</option>");
return opt.join("");
}
function getLink(name, linkarray, iso)
{
var a = new Array();
a.push("<td style=\"word-wrap: break-word; width: 128px; \">"); //individual link
if (iso!=null)
{
a.push("<img width='16' height='11' src=\"/imgs/flags/");
a.push(iso);
a.push(".gif\">&nbsp;");
}
a.push("<a class=\"terms\" href='javascript:");
a.push(linkarray.join(""));
a.push("'>");
a.push(name);
a.push("</a>");
a.push("</td>");
return a.join("");
}
function getSpot(langid, spot_guid, triggerobj, displacement)
{
if ((xlocationmenu.triggerObj()!=triggerobj) ||
(!xlocationmenu.isOpen()))
{
initMenu(null, triggerobj, null, displacement, null);
makeRequest("/com/popupspot.jsp?lang=" + langid + "&sid=" + spot_guid, getspot_handler);
}
else
xlocationmenu.onClose();
}
function getspot_handler()
{
try
{
if (ajax_abort || http_request.readyState == 4)
{
xlocationmenu.onClose();
if(!ajax_abort && http_request.status == 200)
{
xGetElementById("locationmenu").innerHTML = http_request.responseText.replace(/(^\s*)|(\s*$)/g, "");
xlocationmenu.onOpen(xWidth(xGetElementById("popupspottable")), xHeight(xGetElementById("popupspottable")), xtriggerobj, xdisplacement);
return;
}
alert("Cannot execute request, please try again later.");
}
}
finally
{
http_request=null;
}
}
function getCountry(langid, countryid, alloption, triggerobj, callback, displacement, targetuser, session, fid, parentobj, isshowspotcount, changecountrycb, changeregioncb, changecitycb)
{
if ((xlocationmenu.triggerObj()!=triggerobj) ||
(!xlocationmenu.isOpen()))
{
changeLCountry = changecountrycb;
changeLRegion = changeregioncb;
changeLCity = changecitycb;
my_cid=my_rid=null;
if (changeLCountry!=null && changeLRegion!=null && changeLCity!=null) my_cid=0;
requesttype = "country";
def_sel_value = countryid;
xparentobj = parentobj;
xisshowspotcount = isshowspotcount;
initMenu(alloption, triggerobj, callback, displacement, targetuser, parentobj);
if (targetuser)
{
if (fid)
makeRequest("/xs", handler, "lang=" + langid + "&doc=country&u=" + targetuser + "&fid=" + fid);
else
makeRequest("/xs", handler, "lang=" + langid + "&doc=country&u=" + targetuser + (session==null ? "" : "&s=" + session));
}
else
makeRequest("/xs?lang=" + langid + "&doc=country", handler);
}
else
xlocationmenu.onClose();
}
function getRegion(langid, countryid, regionid, alloption, triggerobj, callback, displacement, targetuser, session, fid, parentobj, changeregioncb, changecitycb)
{
if ((xlocationmenu.triggerObj()!=triggerobj) ||
(!xlocationmenu.isOpen()))
{
if (countryid<=0) return false;
changeLCountry = null;
changeLRegion = changeregioncb;
changeLCity = changecitycb;
my_cid=my_rid=null;
requesttype = "region";
def_sel_value = regionid;
my_cid = countryid;
xparentobj = parentobj;
initMenu(alloption, triggerobj, callback, displacement, targetuser, parentobj);
if (targetuser)
{
if (fid)
makeRequest("/xs", handler, "lang=" + langid + "&doc=city&cid=" + countryid + "&u=" + targetuser + "&fid=" + fid);
else
makeRequest("/xs", handler, "lang=" + langid + "&doc=city&cid=" + countryid + "&u=" + targetuser + (session==null ? "" : "&s=" + session));
}
else
makeRequest("/xs?lang=" + langid + "&doc=city&cid=" + countryid, handler);
}
else
xlocationmenu.onClose();
}
function getCity(langid, countryid, regionid, cityid, alloption, triggerobj, callback, displacement, targetuser, session, fid, parentobj, changecitycb)
{
if ((xlocationmenu.triggerObj()!=triggerobj) ||
(!xlocationmenu.isOpen()))
{
if (regionid<=0) return false;
changeLCountry = null;
changeLRegion = null;
changeLCity = changecitycb;
my_cid=my_rid=null;
requesttype = "region";
def_sel_value = cityid;
my_cid = countryid;
my_rid = regionid;
xparentobj = parentobj;
initMenu(alloption, triggerobj, callback, displacement, targetuser, parentobj);
if (targetuser)
{
if (fid)
makeRequest("/xs", handler, "lang=" + langid + "&doc=city&cid=" + countryid + "&rid=" + regionid + "&u=" + targetuser + "&fid=" + fid);
else
makeRequest("/xs", handler, "lang=" + langid + "&doc=city&cid=" + countryid + "&rid=" + regionid + "&u=" + targetuser + (session==null ? "" : "&s=" + session));
}
else
makeRequest("/xs?lang=" + langid + "&doc=city&cid=" + countryid + "&rid=" + regionid , handler);
}
else
xlocationmenu.onClose();
}
function initMenu(alloption, triggerobj, callback, displacement, targetuser, parentobj)
{
xlocationmenu.onClose();
xGetElementById("locationmenu").innerHTML = "<table id='tb001'><tr><td><img src='/imgs/wait1.gif' width='16' height='16'></td></tr></table>";
xalloption = alloption;
locationmenucallback = callback;
xtriggerobj = triggerobj;
xdisplacement = displacement;
xtargetuser = targetuser;
xlocationmenu.onOpen(xWidth(xGetElementById("tb001")), xHeight(xGetElementById("tb001")), xtriggerobj, xdisplacement, parentobj);
}
function showWait(parentobj)
{
xlocationmenu.onClose();
if (typeof(xpopupcommenu)!="undefined") xpopupcommenu.onClose();
try{
if(window.ActiveXObject){
xGetElementById("locationmenu").style.filter="alpha(opacity=\"50\")";
}else{
xGetElementById("locationmenu").style.opacity=0.4;
}
if (xGetElementById("locationmenuiframe"))
{
if(window.ActiveXObject){
xGetElementById("locationmenuiframe").style.filter="alpha(opacity=\"50\")";
}else{
xGetElementById("locationmenuiframe").style.opacity=0.4;
}
}
} catch (e) {}
xGetElementById("locationmenu").innerHTML = "<table id='tb001' width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/imgs/wait1.gif' width='16' height='16'></td></tr></table>";
xlocationmenu.onOpen(xWidth(parentobj), xHeight(parentobj), parentobj, 7);
}
function hideWait()
{
try{
if(window.ActiveXObject){
xGetElementById("locationmenu").style.filter="alpha(opacity=\"100\")";
}else{
xGetElementById("locationmenu").style.opacity=1;
}
if (xGetElementById("locationmenuiframe"))
{
if(window.ActiveXObject){
xGetElementById("locationmenuiframe").style.filter="alpha(opacity=\"100\")";
}else{
xGetElementById("locationmenuiframe").style.opacity=1;
}
}
} catch (e) {}
xlocationmenu.onClose();
}
function locationACCallbackDespatcher(obj, txt, id, param)
{
if (changeLCountry==null && changeLRegion==null && changeLCity==null)
{
defACLocationCallback(obj, txt, id, param);
return;
}
var txts = txt.split(",");
var ids = id.split(",");
var c=null, r=null, ct=null;
var c_name=null, r_name=null, ct_name=null;
if (ids[0]!=0)
{
c = ids[0];
c_name = txts[txts.length-1];
if (ids[1]!=0)
{
r_name = txts[txts.length-2];
r = ids[1];
}
if (ids[2]!=0)
{
ct_name = txts[txts.length-3];
ct = ids[2];
}
}
else
{
if (ids[1]!=0 && ids[2]!=0)
{
r_name = txts[txts.length-1];
r = ids[1];
ct_name = txts[txts.length-2];
ct = ids[2];
}
else if (ids[1]!=0)
{
r_name = txts[txts.length-1];
r = ids[1];
}
else if (ids[2]!=0)
{
ct_name = txts[txts.length-1];
ct = ids[2];
}
}
if (c!=null)
{
if (changeLCountry)
{
var o = xGetElementById("location_select");
var params = null;
if (o)
{
for (var k=0; k<o.length; k++)
{
if (o.options[k].value.indexOf(c+",")==0)
{
params = o.options[k].value.split(",");
break;
}
}
}
if (params)
changeLCountry(null, c_name, c, obj, params[1], params[2], params[3], (r==null));
else
changeLCountry(null, c_name, c, obj, null, null, null, (r==null));
}
}
if (r!=null)
{
obj = xGetElementById(obj.id.replace("country", "region"));
if (changeLRegion) changeLRegion(null, r_name, r, obj, (ct==null));
}
if (ct!=null)
{
if (obj!=null) obj = xGetElementById(obj.id.replace("region", "city"));
if (changeLCity) changeLCity(null, ct_name, ct, obj);
}
}