
var _SHOW_THUMBS=0;function getXMLParser(s){var parser=null;if(document.implementation&&document.implementation.createDocument){parser=(new DOMParser()).parseFromString(s,"text/xml");}else if(window.ActiveXObject){parser=new ActiveXObject("Microsoft.XMLDOM");parser.async=false;if(parser.loadXML(s)==false){alert("error, malformed xml");};}else{alert('Your browser cannot handle this script (no xml parser found)');}
return parser;}
function parseErrorDetails(parseError)
{
    var S =  "errorCode: " + parseError.errorCode + "\n";
        S += "filepos  : " + parseError.filePos + "\n";
        S += "line     : " + parseError.line + "\n";
        S += "linepos  : " + parseError.linepos + "\n";
        S += "reason   : " + parseError.reason + "\n";
        S += "srcText  : " + parseError.srcText + "\n";
        S += "url      : " + parseError.url + "\n";
    return S;

}
function frapper_mkPoint(pt,node){var point=new GPoint(parseFloat(pt.getAttribute("long")),
parseFloat(pt.getAttribute("lat")));var name=pt.getAttribute("name");var loc=pt.getAttribute("loc");var shoutout=pt.getAttribute("shoutout");var mug=pt.getAttribute("mug");var tiny=pt.getAttribute("tiny");var marker=new GMarker(point);var html="";if(mug){html="<div class='shoutoutbox'><b>"+name+" <font color=#888888>"+loc+"</font>"+"</b>"+"<br>"+mug+"<br>"+shoutout+"</div>";}else{html="<div class='shoutoutbox'><b>"+name+" <font color=#888888>"+loc+"</font>"+"</b>"+"<br>"+shoutout+"</div>";}
map.addOverlay(marker);GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(html);});var alink=document.createElement("A");alink.href="javascript:void(0);";if(_SHOW_THUMBS){alink.innerHTML=tiny+'&nbsp;'+name;}else{alink.appendChild(document.createTextNode(name));}
alink.handler=function(){marker.openInfoWindowHtml(html);}
alink.onclick=alink.handler;var atext=document.createElement("font");atext.innerHTML='&nbsp;'+loc+"<BR>";atext.setAttribute('color','#888888');var nobr=document.createElement("NOBR");nobr.appendChild(alink);nobr.appendChild(atext);node.appendChild(nobr);}
function frapper_loadMembers(){
var request=GXmlHttp.create();
var mb=map.getBoundsLatLng();
request.open('GET',"frappers.xml",true);
request.onreadystatechange=function(){
if(request.readyState==4){

var xmlDoc=request.responseXML;
if (xmlDoc.parseError.errorCode != 0) {alert("XML parse error: " + parseErrorDetails(xmlDoc.parseError)); }

var frappers=xmlDoc.documentElement.getElementsByTagName("frapper");

document.getElementById("memlist_count").innerHTML=frappers.length;var tab1=document.createElement("TABLE");var tabbody1=document.createElement("TBODY");for(var i=0;i < frappers.length;i++){var tabtr=document.createElement("TR");var tabtd=document.createElement("TD");frapper_mkPoint(frappers[i],tabtd);tabtr.appendChild(tabtd);tabbody1.appendChild(tabtr);}
tab1.appendChild(tabbody1);document.getElementById("memlist").appendChild(tab1);}
}
request.send(null);}
var toggle=0;function showhide(cName){var arrDiv=document.getElementsByTagName("div");for(var i=0;i<arrDiv.length;i++){if(arrDiv[i].className==cName){if(arrDiv[i].style.display=="none"){arrDiv[i].style.display="block";}else{arrDiv[i].style.display="none";}
}
}
}
function dotoggle(pName,cA,cB){var linkDiv=document.getElementById(pName);if(toggle==0){toggle=1;linkDiv.innerHTML="In the US? Click Here";showhide(cA);showhide(cB);document.forms.addgroup.showcity.value=1;}else{toggle=0;linkDiv.innerHTML="Not in the US? Click Here";showhide(cB);showhide(cA);document.forms.addgroup.showcity.value=0;}
}
if(navigator.userAgent.indexOf("Safari")> 0){isSafari=true;isMoz=false;isIE=false;}
else if(navigator.product=="Gecko"){isSafari=false;isMoz=true;isIE=false;}
else{isSafari=false;isMoz=false;isIE=true;}
function liveUpdaterUri(id,uri){function constructUri(){var separator="?";if(uri.indexOf("?")>=0)
separator="&";return uri+separator+"s="+escape(document.getElementById(id).innerHTML);}
return liveUpdater(constructUri,function(){});}
function liveUpdaterUriFunc(id,uri,postFunc,preFunc){function constructUri(){var separator="?";if(uri.indexOf("?")>=0)
separator="&";return uri+separator+"s="+escape(document.getElementById(id).innerHTML);}
return createLiveUpdaterFunction(constructUri,postFunc,preFunc);}
/*
  liveUpdater returns the live update function to use
  uriFunc: The function to generate the uri
  postFunc: <optional> Function to run after processing is complete
  preFunc: <option> Function to run before processing starts
*/
function liveUpdater(uriFunc,postFunc,preFunc){if(!postFunc)postFunc=function(){};if(!preFunc)preFunc=function(){};return createLiveUpdaterFunction(uriFunc,postFunc,preFunc);}
function recreateTR(parentElement,subtree){for(var i=parentElement.childNodes.length-1;i>=0;i--){parentElement.removeChild(parentElement.childNodes[i]);}
for(var i=0;i<subtree.childNodes.length;i++){var cell=document.createElement(subtree.childNodes[i].nodeName);copyAttributes(subtree.childNodes[i],cell);cell.innerHTML=flattenChildren(subtree.childNodes[i].childNodes)
parentElement.appendChild(cell);}
}
function createLiveUpdaterFunction(uriFunc,postFunc,preFunc){var request=false;if(window.XMLHttpRequest){request=new XMLHttpRequest();}
function update(){if(request&&request.readyState < 4)
request.abort();if(!window.XMLHttpRequest)
request=new ActiveXObject("Microsoft.XMLHTTP");preFunc();request.onreadystatechange=processRequestChange;request.open("GET",uriFunc());request.send(null);return true;}
function processRequestChange(){if(request.readyState==4){var xmlDoc=request.responseXML
var body=xmlDoc.getElementsByTagName("body");if(body.length>0){var nodes=body[0].childNodes
for(var i=0;i<nodes.length;i++){if(nodes[i].nodeType==1&&nodes[i].getAttribute("id")!=null){var id=nodes[i].getAttribute("id")
if(isIE&&nodes[i].nodeName=='tr'){recreateTR(document.getElementById(id),nodes[i]);}
else{document.getElementById(id).innerHTML=flattenChildren(nodes[i].childNodes)
}
}
}
}
var scripts=xmlDoc.getElementsByTagName("script");for(var i=0;i<scripts.length;i++){if(scripts[i].firstChild!=null){var script=scripts[i].firstChild.nodeValue
if(script!=null){eval(script)
}
}
}
postFunc();}
}
return update;}
function autocomplete(id,popupId,uri){var inputField=document.getElementById(id);var popup=document.getElementById(popupId);var options=new Array();var current=0;var originalPopupTop=popup.offsetTop;function constructUri(){var separator="?";if(uri.indexOf("?")>=0)
separator="&";return uri+separator+"city="+escape(inputField.value);}
function hidePopup(){popup.style.visibility='hidden';}
function handlePopupOver(){removeListener(inputField,'blur',hidePopup);}
function handlePopupOut(){if(popup.style.visibility=='visible'){addListener(inputField,'blur',hidePopup);}
}
function handleClick(e){inputField.value=eventElement(e).innerHTML;popup.style.visibility='hidden';inputField.focus();}
function handleOver(e){options[current].className='';current=eventElement(e).index;options[current].className='selected';}
function post(){current=0;options=popup.getElementsByTagName("li");if((options.length > 1)
||(options.length==1
&&options[0].innerHTML!=inputField.value)){setPopupStyles();for(var i=0;i < options.length;i++){options[i].index=i;addOptionHandlers(options[i]);}
options[0].className='selected';}
else{popup.style.visibility='hidden';}
}
function setPopupStyles(){var maxHeight
if(isIE){maxHeight=200;}
else{maxHeight=window.outerHeight/3;}
if(popup.offsetHeight < maxHeight){popup.style.overflow='hidden';}
else if(isMoz){popup.style.maxHeight=maxHeight+'px';popup.style.overflow='-moz-scrollbars-vertical';}
else{popup.style.height=maxHeight+'px';popup.style.overflowY='auto';}
popup.scrollTop=0;popup.style.visibility='visible';}
function addOptionHandlers(option){addListener(option,"click",handleClick);addListener(option,"mouseover",handleOver);}
var updater=liveUpdater(constructUri,post);var timeout=false;function start(e){if(timeout){window.clearTimeout(timeout);timeout=false;}
if(e.keyCode==38){if(current > 0){options[current].className='';current--;options[current].className='selected';options[current].scrollIntoView(false);}
}
else if(e.keyCode==40){if(current < options.length-1){options[current].className='';current++;options[current].className='selected';options[current].scrollIntoView(false);}
}
else if((e.keyCode==13||e.keyCode==9)&&popup.style.visibility=='visible'){inputField.value=options[current].innerHTML;popup.style.visibility='hidden';inputField.focus();if(isIE){event.returnValue=false;}
else{e.preventDefault();}
}
else{timeout=window.setTimeout(updater,50);}
}
addKeyListener(inputField,start);addListener(popup,'mouseover',handlePopupOver);addListener(popup,'mouseout',handlePopupOut);}
/* Functions to handle browser incompatibilites */
function eventElement(event){if(isMoz){return event.currentTarget;}
else{return event.srcElement;}
}
function addKeyListener(element,listener){if(isSafari)
element.addEventListener("keydown",listener,false);else if(isMoz)
element.addEventListener("keypress",listener,false);else
element.attachEvent("onkeydown",listener);}
function addListener(element,type,listener){if(element.addEventListener){element.addEventListener(type,listener,false);}
else{element.attachEvent('on'+type,listener);}
}
function removeListener(element,type,listener){if(element.removeEventListener){element.removeEventListener(type,listener,false);}
else{element.detachEvent('on'+type,listener);}
}
/* XML Helper functions */
function flatten(node){if(node.nodeType==1){return '<'+node.nodeName+flattenAttributes(node)+'>'+
flattenChildren(node.childNodes)+'</'+node.nodeName+'>';}
else if(node.nodeType==3){return node.nodeValue;}
}
function flattenAttributes(node){var buffer=''
for(var i=0;i<node.attributes.length;i++){var attribute=node.attributes[i];buffer+=' '+attribute.name+'="'+attribute.value+'"'
}
return buffer;}
function flattenChildren(nodes){var buffer='';if(nodes.length > 0){for(var i=0;i<nodes.length;i++){buffer+=flatten(nodes[i]);}
}
return buffer;}
function copyAttributes(source,destination){for(var i=0;i<source.attributes.length;i++){var attribute=source.attributes[i];destination.setAttribute(attribute.name,attribute.value);}
destination.className=source.getAttribute('class');}
