
function validateResultCode(rCode){var granularity="",streetConfidence="",adminAreaConfidence="",postalCodeConfidence="";if(rCode.length<5)
return false;granularity=rCode.substring(0,2);streetConfidence=rCode.charAt(2);adminAreaConfidence=rCode.charAt(3);postalCodeConfidence=rCode.charAt(4);if(granularity.indexOf("L")>=0||granularity.indexOf("I")>=0||granularity.indexOf("B")>=0||granularity.indexOf("Z")>=0||granularity.indexOf("A5")>=0){if((adminAreaConfidence=="A"&&postalCodeConfidence=="A")||(adminAreaConfidence=="A"&&postalCodeConfidence=="X")){return true;}}
return false;}
function appendHiddenFields(frm,address,addParams){var input;input=createInputElement("hidden","hdnAddress",address.getStreet());frm.appendChild(input);input=createInputElement("hidden","hdnCity",address.getCity());frm.appendChild(input);input=createInputElement("hidden","hdnStateProvince",address.getState());frm.appendChild(input);input=createInputElement("hidden","hdnPostalcode",address.getPostalCode());frm.appendChild(input);if(address.getMQLatLng){input=createInputElement("hidden","hdnLatitude",address.getMQLatLng().getLatitude());frm.appendChild(input);input=createInputElement("hidden","hdnLongitude",address.getMQLatLng().getLongitude());frm.appendChild(input);}
if(addParams){for(var i=0;i<addParams.length;i++){input=createInputElement("hidden",addParams[i][0],addParams[i][1]);frm.appendChild(input);}}}
function addressToString(loc,node){var b;if(loc.getStreet()!=""){node.appendChild(document.createTextNode(loc.getStreet()));node.appendChild(document.createElement("br"));}
addSp=false;if(loc.getCity()!=""){node.appendChild(document.createTextNode(loc.getCity()));addSp=true;}
if(loc.getState()!=""){if(addSp)
node.appendChild(document.createTextNode(", "));node.appendChild(document.createTextNode(loc.getState()));addSp=true;}
if(loc.getPostalCode()!=""){if(addSp)
node.appendChild(document.createTextNode(" "));node.appendChild(document.createTextNode(loc.getPostalCode()));addSp=true;}
if(loc.getCounty()!=""){if(addSp)
node.appendChild(document.createElement("br"));node.appendChild(document.createTextNode("("+loc.getCounty()+")"));}}
function addressToStringHTML(loc){var b,html="";if(loc.getStreet()!=""){html+=loc.getStreet();html+="<br/>";}
var addSp=false;if(loc.getCity()!=""){html+=loc.getCity();addSp=true;}
if(loc.getState()!=""){if(addSp)
html+=", ";html+=loc.getState();addSp=true;}
if(loc.getPostalCode()!=""){if(addSp)
html+=" ";html+=loc.getPostalCode();addSp=true;}
if(loc.getCounty()!=""){if(addSp)
html+="<br/>";html+="("+loc.getCounty()+")";}
return html;}
function buildGeocodeResultTable(parentid,locationcollection,page,addParams){var tbl=document.createElement("table");tbl.className="ambgeocode";tbl.cellPadding=4;tbl.cellSpacing=0;tbl.border=0;var tr,td,th,a,frm,href,ind,val;var loc;for(var i=0;i<locationcollection.getSize();i++){loc=locationcollection.getAt(i);tr=document.createElement("tr");td=document.createElement("td");td.className="ambgeocode";a=document.createElement("a");frm=document.createElement("form");frm.action=page;frm.id="frm"+i;frm.method="get";appendHiddenFields(frm,loc,addParams);td.appendChild(frm);if(page.indexOf("javascript:")<0){href="javascript:document.getElementById('"+frm.id+"').submit();"}
else{href=page;ind=href.lastIndexOf(")");if(href.charAt(ind-1)=="(")
val="'"+frm.id+"'";else
val=",'"+frm.id+"'";href=href.substring(0,ind)+val+href.substring(ind);}
a.href=href;addressToString(loc,a);td.appendChild(a);tr.appendChild(td);tbl.appendChild(tr);}
var parent=document.getElementById(parentid);if(!browserCheck.ie){removeAllChildren(parent);parent.appendChild(tbl);}
else{parent.innerHTML=tbl.outerHTML;}}
function buildGeocodeResultTableJS(parentid,locationcollection,fnct,additionalFields){var tbl=document.createElement("table");tbl.cellPadding=4;tbl.cellSpacing=0;tbl.border=0;var tr,td,th,a,frm;tr=document.createElement("tr");td=document.createElement("td");td.appendChild(document.createTextNode("Geocode Result"));td.className="ambgeocode";tr.appendChild(td);tbl.appendChild(tr);var loc,href;for(var i=0;i<locationcollection.getSize();i++){loc=locationcollection.getAt(i);tr=document.createElement("tr");td=document.createElement("td");td.className="ambgeocode";a=document.createElement("a");href="javascript:"+fnct+"("
href+="\""+loc.getStreet()+"\",";href+="\""+loc.getCity()+"\",";href+="\""+loc.getState()+"\",";href+="\""+loc.getPostalCode()+"\",";href+="\""+loc.getCounty()+"\",";href+="\""+loc.getCountry()+"\",";href+=loc.getMQLatLng().getLatitude()+",";href+=loc.getMQLatLng().getLongitude();if(additionalFields){if(additionalFields!=""){href+=",";href+=additionalFields;}}
href+=");";a.href=href;addressToString(loc,a);td.appendChild(a);tr.appendChild(td);tbl.appendChild(tr);}
var node=document.getElementById(parentid);removeAllChildren(node);node.appendChild(tbl);}