var browserType=""+getBrowser();
/*
if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().indexOf("gecko") >= 0 ) {
	   browserType= "gecko"
}
*/
var lcCity;
var lcState;
var lcDay;
var lcSF;
var lcST;
var lcLT;
var lcOC;
var lcTime;
var lcMax;
var lcResetDiv;
var lcStateDiv;
var lcCityDiv;
var lcDayDiv;
var lcSFDiv;
var lcSTDiv;
var lcLTDiv;
var lcOCDiv;
var lcTimeDiv;
var lcSepDiv;
var lcResDiv;
var lcRadDiv;
var lcZip;
var lcZipL;
var lcMapDiv;
var lcHaveResult;
var lcHaveStResult;
var browser;
var lcCountries = "|USA|CANADA";
//var lcCountries = "|USA|CANADA|MEXICO|BRAZIL|GERMANY";
//var lcCountries = "|USA|CANADA|MEXICO|BRAZIL|GERMANY|AUSTRALIA";
    
function getvalues() {
 browser = browserType.split(",");
// alert(browserType);
// alert(browser[2]);
 lcHaveStResult = document.getElementById("havestresult");
 lcHaveResult = document.getElementById("haveresult");
 lcBegin  = document.getElementById("begin");
 lcReset  = document.getElementById("reset");
 lcState  = document.getElementById("statePulldown");
 lcCity   = document.getElementById("cityPulldown");
 lcDay    = document.getElementById("dayPulldown");
 lcSF    = document.getElementById("specfocuspulldown");
 lcST    = document.getElementById("spectopicpulldown");
 lcLT    = document.getElementById("langpulldown");
 lcOC    = document.getElementById("openpulldown");
 lcTime  = document.getElementById("timepulldown");
 lcZip    = document.getElementById("zipcode");
 lcZipL   = document.getElementById("ziplabel");
 lcMax    = document.getElementById("maxdistPulldown");
 lcResetDiv = document.getElementById("resetdiv");
 lcStateDiv = document.getElementById("statediv");
 lcMainDiv = document.getElementById("maindiv");
 lcMain   = document.getElementById("main");
 lcMainP   = document.getElementById("mainPulldown");
 lcCountDiv = document.getElementById("countrydiv");
 lcCount  = document.getElementById("countryPulldown");
 lcCityDiv = document.getElementById("citydiv");
 lcDayDiv = document.getElementById("daydiv");
 lcSFDiv = document.getElementById("specfocusdiv");
 lcSTDiv = document.getElementById("spectopicdiv");
 lcLTDiv = document.getElementById("langdiv");
 lcOCDiv = document.getElementById("opendiv");
 lcTimeDiv = document.getElementById("timediv");
 lcSepDiv = document.getElementById("sepdiv");
 lcResDiv = document.getElementById("resdiv");
 lcRadDiv = document.getElementById("raddiv");
 lcZipDiv = document.getElementById("zipdiv");
 lcMapDiv = document.getElementById("mapdiv");
 lcButDiv = document.getElementById("butdiv");
 lcBut2Div = document.getElementById("but2div");
 lcEntDiv = document.getElementById("enterdiv");
 lcEnter  = document.getElementById("enter");
 lcEnterF = document.getElementById("enterform");
}

function doreset(pcWhich) {
	getvalues();
	
    hidediv(lcEntDiv.id);
    hidediv(lcDayDiv.id);
    hidediv(lcSFDiv.id);
    hidediv(lcSTDiv.id);
    hidediv(lcLTDiv.id);
    hidediv(lcOCDiv.id);
    hidediv(lcTimeDiv.id);
    hidediv(lcSepDiv.id);
    hidediv(lcCityDiv.id);
    hidediv(lcButDiv.id);
    hidediv(lcBut2Div.id);
    hidediv(lcCountDiv.id);
//	formReset('day');
//	formReset('specfocus');
//	formReset('spectopic');
//	formReset('lang');
//	formReset('open');
//	formReset('time');
	formReset('zipform');
	formReset('enterform');
    hidediv(lcRadDiv.id);
    hidediv(lcZipDiv.id);
    hidemap();    
    lcZip.value = "";
    lcCity.selectedIndex = 0;
    lcMapDiv.innerHTML = '';
    lcResDiv.innerHTML = "";
    lcMainP.disabled = false;
    lcState.disabled = false;
    lcCount.disabled = false;
    lcCity.disabled  = false;
    lcMax.disabled = false;
	if (pcWhich == "All"){
	  formReset('day');
	  strip(lcSF);
	  strip(lcST);
	  strip(lcLT);
//	  formReset('spectopic');
//	  formReset('lang');
	  formReset('open');
	  formReset('time');
     
      lcBegin.innerHTML = "<br><b>Begin your meeting search here</b>";
      
      lcHaveResult.value = "" ;
   	  formReset('stateform');
      hidediv(lcStateDiv.id);
  	  hidediv(lcReset.id);
	  formReset('main');
      lcHaveResult.value = "" ;
      lcSelection = document.getElementById("selection");
      lcSelection.value = "Show More Selection Choices";
      if (browser[2] == "msie" || browser[2] == "opera" || browser[2] == "khtml") {
        lcState.selectedIndex = 0;
      } else {
        lcState.value = "Select" ;
      }
      lcHaveStResult.value = "Select" ;
    }
     return true;
}

function strip(pcObject) {
  pcObject.length = 0;
  pcObject.options[0]  = new Option("All Meetings","all");
}	

function hidediv(pcId) {
//browserType = "" + browserType;

//alert(browser[2]);
  if (browser[2] == "gecko")
     document.poppedLayer = 
         eval('document.getElementById(pcId)');
  else if (browser[2] == "msie" || browser[2] == "opera" || browser[2] == "khtml")
     document.poppedLayer = 
        eval('document.getElementById(pcId)');
  else
     document.poppedLayer =   
        eval('document.layers[pcId]');
  document.poppedLayer.style.visibility = "hidden";
  document.poppedLayer.style.height = "1px";
  
}

function showdiv(pcId, pcHeight) {
//	alert(browser[2]);
    if (browser[2] == "gecko")
     document.poppedLayer = 
         eval('document.getElementById(pcId)');
    else if (browser[2] == "msie" || browser[2] == "opera"  || browser[2] == "khtml")
     document.poppedLayer = 
        eval('document.getElementById(pcId)');
	else 
     document.poppedLayer = 
         eval('document.layers[pcId]');
  document.poppedLayer.style.visibility = "visible";
  document.poppedLayer.style.height = pcHeight+"px";
//	alert("ID: " + pcId + " Height: " +pcHeight);
}

function showhelp(pcwhich) {	
	switch(pcwhich) {
	  case "Intergroup": 
	    getwind("/WSO/intergroupdef.html", "What is an Intergroup", "660", "580");
	    break;
	    
	  case "Closed": 
	    getwind("/WSO/oc_definition.htm", "Open vs. Closed meetings", "420", "370");
	    break;
	    
	  case "Focus": 
	    getwind("/WSO/sf_definition.htm", "Special Focus meetings", "420", "370");
	    break;
	    
	  case "Topic": 
	    getwind("/WSO/st_definition.htm", "Special Topic meetings", "420", "370");
	    break;
	    
	  default:
	    getwind("/WSO/popupdef.html", "Missing Information", "420", "370");
	    break;
	    
    }
	return false;
}

function makeselect() {
	getvalues();
    lcSelection = document.getElementById("selection");
	
	if (lcSelection.value == "Show More Selection Choices") {
	      showdiv(lcDayDiv.id, "32");
	      showdiv(lcSFDiv.id, "32");
	      showdiv(lcSTDiv.id, "32");
	      showdiv(lcLTDiv.id, "32");
	      showdiv(lcOCDiv.id, "32");
          showdiv(lcTimeDiv.id, "32");
          showdiv(lcSepDiv.id, "40");
	      showdiv(lcBut2Div.id, "32");
          lcSelection.value = "Hide Selection Choices";
	} else {
	      hidediv(lcDayDiv.id);
	      hidediv(lcSFDiv.id);
	      hidediv(lcSTDiv.id);
	      hidediv(lcLTDiv.id);
	      hidediv(lcOCDiv.id);
          hidediv(lcTimeDiv.id);
          hidediv(lcBut2Div.id);          
          hidediv(lcSepDiv.id);
		  formReset('day');
		  formReset('specfocus');
		  formReset('spectopic');
		  formReset('lang');
		  formReset('open');
		  formReset('time');
          lcSelection.value = "Show More Selection Choices";
	}
	return false;
}

function getfirst(pcValue, pcName) {
	  getvalues();
	
      if (pcValue.indexOf("Select") >= 0) {
        doreset("All");    
        return true;
      }
      
      if (pcValue.indexOf("Enter") >= 0) {
        doreset("Not");    
        hidediv(lcCountDiv.id);
        hidediv(lcStateDiv.id);
        showdiv(lcEntDiv.id, "44");
        showdiv(lcRadDiv.id, "32");
        lcHaveResult.value = pcValue ;
        return true;
      }
      if (true) {
        doreset("Not");    
        lcBegin.innerHTML = "";
        showdiv(lcReset.id, "24");
        if (lcCountries.indexOf(pcValue) > 0 ) {
          showdiv(lcCountDiv.id, "32");
          showdiv(lcStateDiv.id, "32");
          if (pcValue == "USA" ) {
	        showdiv(lcZipDiv.id, "32");
	        showdiv(lcRadDiv.id, "32");
	        lcZipL.innerHTML = "Enter valid U.S. Zip Code:";
	        lcZip.maxlength = "5";
	        lcZip.size = "5";
            hidediv(lcCountDiv.id);
          }
          if (pcValue == "CANADA" ) {
	        showdiv(lcZipDiv.id, "32");
	        showdiv(lcRadDiv.id, "32");
//	        changerad("CANADA");
	        lcZipL.innerHTML = "Enter valid Postal Code (space added):";
	        lcZip.maxlength = "7";
	        lcZip.size = "7";
            hidediv(lcCountDiv.id);
          }
	      changerad(pcValue);
		}	        
        lcHaveResult.value = pcValue ;
      }
      
      if (pcValue != "Zip") {
        lcUrl = "/WSO/populatestate.php?which=";
        if (pcValue != "Country") {        
	      fireAjax(pcName, lcUrl, lcState.id);
        } else {
          hidediv(lcStateDiv.id);
          showdiv(lcCountDiv.id, "32");
	      fireAjax(pcName, lcUrl, lcCount.id);
        }
      }      
      return true;
}    

function getsf(pcObject) {
  if (pcObject.length > 1) {
	return true;
  }
  
  getvalues();
  
    switch (lcMainP.value) {
	  case "USA":
		if (lcState.value == "" || lcState.value == "Select") {
		  alert("Please choose a state first");
		  return false;
		}
		break;
	  case "CANADA":
		if (lcState.value == "" || lcState.value == "Select") {
		  alert("Please choose a province first");
		  return false;
		}
		break;
		
	  case "Country":
	    if (lcCount.value == "" || lcCount.value == "Select") {
		  alert("Please choose a country first");
		  return false;
	    }
		break;
  }
  
  if (pcObject.id == "specfocuspulldown" ) {
    lcUrl = "/WSO/getfocusvalues.php?which=" + lcMainP.value + "&country=" + 
            lcCount.value + "&state=" + lcState.value + "&city=" + lcCity.value + "&current=";
  }
  if (pcObject.id == "spectopicpulldown" ) {
    lcUrl = "/WSO/gettopicvalues.php?which=" + lcMainP.value + "&country=" + 
            lcCount.value + "&state=" + lcState.value + "&city=" + lcCity.value + "&current=";
  }
  if (pcObject.id == "langpulldown" ) {
    lcUrl = "/WSO/getfocusvalues.php?which=" + lcMainP.value + "&country=" + 
            lcCount.value + "&state=" + lcState.value + "&city=" + lcCity.value + "&islang=yes&current=";
  }
    fireAjax(pcObject.id, lcUrl, pcObject.id);
    lcMainP.disabled = true;
    lcState.disabled = true;
    lcCount.disabled = true;
    lcCity.disabled = true;
    lcMax.disabled = true;
}

function changerad(pcValue) {
  d = document.getElementById("maxdistPulldown");
  
  if (pcValue == "USA") {
// Flip the Type Dropdown
	  for (i=0; i < d.length; i++) { 
		  d.options[i].innerHTML = d.options[i].innerHTML.replace("kilometres","miles");
	  }
  } else {
	  for (i=0; i < d.length; i++) { 
		  d.options[i].innerHTML = d.options[i].innerHTML.replace("miles","kilometres");
	  }
   }
}

function getnext(pcValue, pcName) {
	getvalues();
    doreset("Not");    
	formReset('zipform');
//    if (lcCountries.indexOf(pcValue) > 0 && (pcValue != "CANADA" && pcValue != "USA")) {
    if (lcCountries.indexOf(lcHaveResult.value) > 0 && (lcHaveResult.value != "CANADA" && lcHaveResult.value != "USA")) {
	    getfirst(pcValue, pcName);
	    return false;
    }
    if (lcCountries.indexOf(lcCount.value) < 0) { 
      lcHaveResult.value = lcMainP.value;
    }
    
    if (pcValue.indexOf("Select") >= 0) {
        if (lcCountries.indexOf(pcValue) > 0) {
          if (lcHaveResult.value == "USA" || lcHaveResult.value == "CANADA") {
            if (lcHaveResult.value == "USA") {
              lcZipL.innerHTML = "Enter valid U.S. Zip Code:";
            } else {
              lcZipL.innerHTML = "Enter valid Postal Code (space added):";
            }
          } else {
            showdiv(lcCountDiv.id, "32");
          }
	      showdiv(lcZipDiv.id, "32");
	      showdiv(lcRadDiv.id, "32");
        }
        lcHaveStResult.value = "" ;
    } else {
	    showdiv(lcCityDiv.id, "32");
	    showdiv(lcButDiv.id, "30");
        if (lcHaveResult.value == "Country"  || (lcCountries.indexOf(lcHaveResult.value) > 0 && (lcHaveResult.value != "USA" && lcHaveResult.value != "CANADA"))) {
          showdiv(lcCountDiv.id, "32");
        }
        
        if (lcHaveResult.value == "Country"  && (lcCountries.indexOf(pcValue) < 0)) {
          hidediv(lcStateDiv.id);
          formReset('stateform');
        }
        
        lcHaveStResult.value = pcValue ;
    }
    
    
    
    lcUrl = "/WSO/populatecity.php?which="+lcHaveResult.value+"&query=";
    lcZip.value="";
	fireAjax(pcName, lcUrl, lcCity.id);
	
    return true;
}    

function fireAjax(inputfield,url,target) {
    // native XMLHttpRequest object
    lcGroupVal = document.getElementById(inputfield).value;
//    document.getElementById(target).value = 'Please Wait......        ';
    updateList(lcGroupVal,url,target);
}

function checkentry(entValue) {
	if (entValue.length < 8) {
		alert("This is not enough of address to obtain any good data");
		return true;
	} else {
//		alert(lcHaveResult.value);
		showdiv(lcButDiv.id, "30")
		return true;
	}
}

function submitbut() {
	getvalues();
	if (lcHaveResult.value == "Enter") {
      lcUrl = "/WSO/getresults.php?enter="+lcEnter.value+"&day="+lcDay.value+"&SF="+lcSF.value+"&ST="+lcST.value+"&lang="+lcLT.value+"&open="+lcOC.value+"&time="+lcTime.value+"&maxdist="+lcMax.value+"&main="+lcHaveResult.value+"&browser="+browser[2];
    } else {
      lcUrl = "/WSO/getresults.php?zip="+lcZip.value+"&state="+lcState.value+"&city="+lcCity.value+"&day="+lcDay.value+"&SF="+lcSF.value+"&ST="+lcST.value+"&lang="+lcLT.value+"&open="+lcOC.value+"&time="+lcTime.value+"&maxdist="+lcMax.value+"&main="+lcHaveResult.value+"&country="+lcCount.value+"&browser="+browserType;
    }
//	alert(lcUrl);	
    hidemap();    
    fireResults(lcUrl, lcResDiv.id);
	return false;
}

function getcheck(thisobj) {
	getvalues();
    lcCheck = thisobj;
    lcCheckResult = document.getElementById("checkresult").value;
    
    lcCVal = lcCheck.name.substr(5);
    
    if (lcCheck.checked) {
    } else {
    }
//    alert(lcCheck.name + " is ");
	return true;
}

var map;
var point;

function decode(url) {
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef";
var encoded = url;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
//alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while

return plaintext;
};
  
function getmap(pcVariable) {
    var longlat = pcVariable.split(',');
    lcID = "mapdiv"+longlat[2];
    lcButID = "mapbut"+longlat[2];
    
    message1 = decode(longlat[3]);
    message2 = decode(longlat[4]);
    message3 = decode(longlat[5]);
    message4 = decode(longlat[6]);
    lcButton = document.getElementById(lcButID);
    lcmapdiv = document.getElementById(lcID);
    
    if ((lcButton.innerHTML == "<b>Show Meeting on Map</b>" || lcButton.innerHTML == "<B>Show Meeting on Map</B>") && GBrowserIsCompatible()) {
      lcmapdiv = document.getElementById(lcID);
      lcmapdiv.style.height = "550px";
      lcmapdiv.style.width = "550px";
     
      var map = new GMap2(document.getElementById(lcID));
        map.setCenter(new GLatLng(longlat[1], longlat[0]), 15);
        var point = new GLatLng(longlat[1], longlat[0]);
        var marker2 = createMarker(point,'',message1+' ' + message2+'<br>Location: ' + message3+'<br>Address: '+message4);
        map.addOverlay(marker2);
        
        GEvent.trigger(marker2, "click"); 
        var mapTypeControl = new GMapTypeControl();
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
        var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
        map.addControl(mapTypeControl, topRight);
        GEvent.addListener(map, "dblclick", function() {
          map.removeControl(mapTypeControl);
          map.addControl(new GMapTypeControl(), bottomRight);
        });
//      map.addControl(new GSmallMapControl());
      map.addControl(new GLargeMapControl());
     
//    alert('ding1' + lcHaveResult.value);
      if (lcHaveResult.value == "Country" || lcHaveResult.value == "Canada") {
        _mPreferMetric = true; 
      } else {
        _mPreferMetric = false; 
      }
//    alert('ding2');
  
      map.addControl(new GScaleControl());       
      map.enableScrollWheelZoom();
      lcButton.innerHTML = "<b>Hide Map</b>";
	} else {
      lcButton.innerHTML = "<b>Show Meeting on Map</b>";
	  mapunload();
	  map = null;
	  point = null;
      lcmapdiv.innerHTML = "";
      lcmapdiv.style.height = "auto";
	}
//    alert('ding3');
}

var GUnload;

function mapunload() {
	if (GUnload) {
	  GUnload();
    }
}    

function hidemap() {
	  mapunload();
	  map = null;
	  point = null;
      lcMapDiv.innerHTML = "";
      lcMapDiv.style.height = "auto";
      lcMapDiv.style.border = "";
}      


function getmeeting(meetnum) {
    lcmeetdiv = document.getElementById("meetdiv"+meetnum);
    lcImage = 'meetImg' + meetnum;  
    if (lcmeetdiv.name == undefined) {
      lcmeetdiv.innerHTML = 'Please wait...';
      lcmeetdiv.name = '0';
      lcUrl2 = "/WSO/getmeeting.php?meetnum="+meetnum;
      updateRes(lcUrl2,lcmeetdiv.id);
      document.images[lcImage].src = "/WSO/uparrow.gif";   
//      document.getElementById(lcButton).innerHTML = "Hide meeting details";
    } else {
      if (lcmeetdiv.name == '0') {
		lcmeetdiv.name = lcmeetdiv.innerHTML;
        document.images[lcImage].src = "/WSO/glass24.gif";   
//        document.getElementById(lcButton).innerHTML = "Get meeting details";
        lcmeetdiv.innerHTML = "<hr>";
      } else {
        lcmeetdiv.innerHTML = lcmeetdiv.name;
        lcmeetdiv.name = '0';
        document.images[lcImage].src = "/WSO/uparrow.gif";   
//        document.getElementById(lcButton).innerHTML = "Hide meeting details";
      }
	}
return false;
}

function getcity(pcValue, pcName) {	
   if (pcValue.indexOf('Select') >= 0) {
     hidediv(lcRadDiv.id);
	 showdiv(lcZipDiv.id, "32");
     lcResDiv.innerHTML = "";
     return true;
    } else {
     showdiv(lcRadDiv.id, "32");
     hidediv(lcZipDiv.id);
//      lcMax.options[lcMax.selectedIndex].innerHTML = "Select Radius (optional)";
    }
}

function getigwind(pcIGValue) {
  getwind(pcIGValue,"Intergroup",800,600);
  return true;
}

function printlist(pcVal) {
  getwind(pcVal,"Printable OA meeting list",680,600);
//  getwind("/WSO/printresults.php","Printable OA meeting list",680,600);
  return false;
}

function dotest(msgval) {
	alert(msgval);
}

function getwind(targurl,wintitle,winwidth,winheight) {

var win= null;
var w=winwidth;
var h=winheight;
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars=2,';
settings +='resizable=yes';
wintitle = wintitle.replace(/ /g,"_");

//IE is problematic with the title, so lose it!
if (browserType.indexOf("msie") >= 0) {
  wintitle = "";
}

lcWin = window.open(targurl,wintitle,settings);

if (!lcWin) {
  alert('Your popup blocker needs to be set to a lower setting to do this!');
} else {
  lcWin.focus();
}

}

function getig(pcButVal) {
    var ValSplit = pcButVal.split(',');
	getvalues();
    lcIGButton = document.getElementById("igbut"+ValSplit[1]);
    lcIGDiv    = document.getElementById("igdiv"+ValSplit[1]);
//	alert(lcIGButton.innerHTML);
    if (lcIGButton.innerHTML == "<b>Get Intergroup Info</b>" || lcIGButton.innerHTML == "<B>Get Intergroup Info</B>" ) {    
      lcUrl = "/WSO/getig.php?ignum="+ValSplit[0];
      fireResults(lcUrl, lcIGDiv.id);
      lcIGButton.innerHTML = "<b>Hide Intergroup Info</b>";
    } else {
      lcIGButton.innerHTML = "<b>Get Intergroup Info</b>";
      lcIGDiv.innerHTML = "";
    }

	return false;
}

function fireResults(url,target) {
    document.getElementById(target).innerHTML = 'Please wait...';
    updateRes(url,target);
}

function linkfire(pcHref) {
//	alert(pcHref);
    getwind(pcHref,"Meeting Definitions",600,600);
	return false;
}

function updateRes(url,lbToChange) {
    targetlb = document.getElementById(lbToChange);
    loadXML2Doc(url);
	}

var req;
var targetlb;
var targettb;

function processReq2Change () {
    if ((req.readyState == 4) && (req.status == 200)) {
		response  = req.responseText;
//		alert(response);
		if (response.indexOf("^") < 0) {
			response = "^" + response;
		}
        var m = response.split('^');        
        var d = m[1].split('|');
		if (response.length > 0) {
		   targetlb.innerHTML  = m[1];
		} else {
		   targetlb.innerHTML  = "Sorry, there has been a problem";
		}

		if (m[0].length > 1) {	    
         document.getElementById("mapresult").value = m[0];
//         alert(m[0]);
		}
		
    }
}

function processReq24Value () {
    if ((req.readyState == 4) && (req.status == 200)) {
		response  = req.responseText;
		targettb.value='';
		if (d.length > 0) {	    
			for (i=0; i < d.length; i++) { 
				opttext  = d[i];
				targettb.value  = opttext;
			} 
		} else {
			    targettb.value  = "No Values";
		}
		
    }
}

function mapit(sentobj) {
//alert('meeting:'+sentobj);
    butonbj = document.getElementById(sentobj);
    pcCoords = document.getElementById("mapresult").value;
//alert(pcCoords);
    var coords = pcCoords.split('|');
    if ((butonbj.innerHTML == "<b>Show mapped meetings</b>" || butonbj.innerHTML == "<B>Show mapped meetings</B>") && GBrowserIsCompatible()) {
  	  butonbj.innerHTML = "<b>Hide mapped meetings</b>";	
      lcMapDiv.style.height = "550px";
      lcMapDiv.style.width = "550px";
      lcMapDiv.innerHTML = "<B>Please wait...</B>";
     
      var map = new GMap2(document.getElementById("mapdiv"));
//      map.addControl(new GSmallMapControl());
      map.addControl(new GLargeMapControl());
      map.setCenter(new GLatLng(0,0),0);
	  var bounds = new GLatLngBounds();
      
	  for (z=0; z < coords.length - 1; z++) { 
        var coord2 = coords[z].split(',');
        var point = new GLatLng(coord2[1], coord2[0]);
        var marker2 = createMarker(point,'',coord2[2]);
        map.addOverlay(marker2);
        bounds.extend(point);        
	  } 
	  
      map.setZoom(map.getBoundsZoomLevel(bounds));
      map.setCenter(bounds.getCenter());
	  
      map.enableScrollWheelZoom();
      lcMapDiv.style.border = "4px solid black";
      var mapTypeControl = new GMapTypeControl();
      var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
      var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
      map.addControl(mapTypeControl, topRight);
      GEvent.addListener(map, "dblclick", function() {
      map.removeControl(mapTypeControl);
      map.addControl(new GMapTypeControl(), bottomRight);      
      });
      if (lcHaveResult.value == "Country" || lcHaveResult.value == "Canada") {
        _mPreferMetric = true; 
      } else {
        _mPreferMetric = false; 
      }
  
      map.addControl(new GScaleControl());       
//      window.location = "#mapbutanc"          
     
	} else {
	  butonbj.innerHTML = "<b>Show mapped meetings</b>";	
	  hidemap();
//      window.location = "#top"
	}

}

      var gmarkers = [];
      var htmls = [];
      var to_htmls = [];
      var from_htmls = [];
      var i=0;


      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
      var icon = new GIcon();
      icon.image = "/WSO/oamarker.png";
      icon.shadow = "/WSO/shadow-oa.png";
      icon.iconSize = new GSize(40.0, 32.0);
      icon.shadowSize = new GSize(57.0, 32.0);
      icon.iconAnchor = new GPoint(20.0, 16.0);
      icon.infoWindowAnchor = new GPoint(20.0, 16.0);
        
//        var marker = new GMarker(point, icon);
        var marker = new GMarker(point);

        // The info window version with the "to here" form open
        to_htmls[i] = html + '<br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
           '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/>';
        // The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';

          
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        
        
        gmarkers[i] = marker;
        htmls[i] = html;
        i++;
        return marker;
      }

      // functions that open the directions forms
      function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }

function getXML2HTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}
function loadXML2Doc(url) {
    req=getXMLHTTP();
	if(req){
        req.onreadystatechange = processReq2Change;
        req.open("GET", url, true);
        req.send(null);
	}
}
function load2XMLValue(url) {
    req=getXMLHTTP();
	if(req){
        req.onreadystatechange = processReq4Value;
        req.open("GET", url, true);
        req.send(null);
	}
}

function updateList(sentvalue,url,lbToChange) {
	targetlb = document.getElementById(lbToChange);
//alert(url + sentvalue);
    if (sentvalue.length == 0) {
		targetlb.length=0;
	    targetlb.options[0]  = new Option("No Values","");
    	return true;
    	}
	targetlb.length=0;
	targetlb.options[0]  = new Option("Retrieving.......","");

    loadXMLDoc(url + sentvalue);
	}

var req;
var targetlb;
var targettb;

function processReqChange () {
    if ((req.readyState == 4) && (req.status == 200)) {
		response  = req.responseText;
//alert(response);	    
        var d = response.split('|');
		targetlb.length=0;
// Use stuff to get an alert of all elements in a readable form		
		stuff = "";
		if (d.length > 0) {
			for (i=0; i < d.length; i++) { 
//				stuff = stuff + d[i] + "\n";
				lnFound1 = d[i].indexOf('$');
				if (lnFound1 > 0) {   
                  var e = d[i].split('$');				
				  opttext = e[1];
				  optvalue = e[0];
/*				  
                  if (i==0) {
	                what = 'XX'+optvalue+'XX';
              	    lnWhich3 = optvalue.indexOf('Select');
	                alert(lnWhich3);	    
                }
*/				  				  
                } else {
				  opttext = d[i];
				  optvalue = d[i];
			    }
				targetlb.options[i]  = new Option(opttext,optvalue );
			} 
//			    alert(stuff);
		} else {
			    targetlb.options[0]  = new Option("No Values","");
		}
    }
    else {
    }
}

function processReq4Value () {
    if ((req.readyState == 4) && (req.status == 200)) {
		response  = req.responseText;
		
        var d = response.split('|');
		targettb.value='';
		if (d.length > 0) {	    
			for (i=0; i < d.length; i++) { 
				opttext  = d[i];
				targettb.value  = opttext;
			} 
		} else {
			    targettb.value  = "No Values";
		}
    }
    else {
    }
}
function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}
function loadXMLDoc(url) {
//	alert(url);
    req=getXMLHTTP();
	if(req){
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
	}
}
function loadXMLValue(url) {
    req=getXMLHTTP();
	if(req){
        req.onreadystatechange = processReq4Value;
        req.open("GET", url, true);
        req.send(null);
	}
}

