﻿// get flash movie object
  var flashMovie;
  function init() {
	 if (document.getElementById) {
		flashMovie = document.getElementById("ammap");
	 }
  }
  // wait for the page to fully load before initializing
  window.onload = init;
/*
  // set data
  function setData() {
	 if (flashMovie) {
		var txt = document.getElementById("data").value;
		flashMovie.setData(txt);
	 }
  }
  
  // set zoom 
  function setZoom() {
	 if (flashMovie) {
		var zoom_level = document.getElementById("zoom_level").value;     //setZoom(zoom_level, zoom_x, zoom_y, instant);
		var zoom_x = document.getElementById("zoom_x").value;
		var zoom_y = document.getElementById("zoom_y").value;
		flashMovie.setZoom(zoom_level,zoom_x,zoom_y, false); 
	 }
  }
	   
  // reload data
  function reloadData() {
	 if (flashMovie) {
		flashMovie.reloadData();
	 }
  }
  // reload settings
  function reloadSettings() {
	 if (flashMovie) {            
		flashMovie.reloadSettings();
	 }
  }
  // reload all
  function reloadAll() {
	 if (flashMovie) {            
		flashMovie.reloadAll();
	 }
  }
  // set param
  function setParam() {
	 if (flashMovie) {
		var param = document.getElementById("param").value;
		var value = document.getElementById("value").value;
		flashMovie.setParam(param, value);
	 }
  }
  // get param
  function getParam() {
	 if (flashMovie) {
		var param = document.getElementById("getparam").value;            
		flashMovie.getParam(param);
	 }
  } 

  // get data
  function getData() {
	 if (flashMovie) {
		flashMovie.getData();
	 }
  }   

  // export image
  function exportImage() {
	 if (flashMovie) {
		flashMovie.exportImage('../ammap/export.php'); // it is not required to pass filename here if you set it in settings file) 
	 }
  }            

  function getLongLat(){
	 if (flashMovie) {
		flashMovie.getLongLat();
	 }
  }
  function getStageXY(){
	 if (flashMovie) {
		flashMovie.getStageXY();
	 }
  }      
  function getZoomInfo(){
	 if (flashMovie) {
		flashMovie.getZoomInfo();
	 }
  }
  function clickObject(){
	 if (flashMovie) {		 
		var id = document.getElementById("objectid").value;			
		flashMovie.clickObject(id);			
	 }      
  }

  function amSetLongLat(map_id, long, lat){
	 document.getElementById("longitude").value = long;
	 document.getElementById("latitude").value = lat;
  }

  function amSetStageXY(map_id, x, y, x_percent, y_percent){
	 document.getElementById("stage_x").value = x;
	 document.getElementById("stage_y").value = y;
	 document.getElementById("stage_xp").value = x_percent;
	 document.getElementById("stage_yp").value = y_percent;         
  }
  function amSetZoomInfo(map_id, x, y, level){
	 document.getElementById("zoom_x").value = x;
	 document.getElementById("zoom_y").value = y;
	 document.getElementById("zoom_level").value = level;
  }
  */
  
  /*
  function amRegisterClick(map_id, object_id, title, value){	  	  
	  window.location="/go/members/?showResults=true&state="+object_id;
	  //getMembers(object_id,title);
	  //document.getElementById("objectid").value = object_id;
  }
  */
  
  /*
  function amRegisterHover(map_id, object_id, title, value){
	  document.getElementById("objecthoverid").value = title;
  }            
  // return data 
  function amReturnData(map_id, data){
	  document.getElementById("data").value = unescape(data);
  } 
  // return param     
  function amReturnParam(map_id, param){
	  document.getElementById("returnedparam").value = unescape(param); 
  }
  
  function amMapCompleted(map_id){
	  document.getElementById("completed").value = map_id + " completed";
  }         
  */

function getMembers(geoState,title){			
	var stateName = title.split(" (");
	stateName = stateName[0];

	$("#result-container").html('');

	$.getJSON("/default/includes/display_objects/member_directory/find_a_lawyer/jsonMapData.cfm",{id:geoState}, function(j){
		
		var memberList = '<h2 style="margin-left:0; padding-left:0;">' + stateName + '</h2>';
		for (var i = 0; i < j.length; i++) {
			memberList += '<li style="margin-left:1em;"><a href="/go/members/member-directory/member-information/?userID=' + j[i].userID + '">' + Url.decode(j[i].fullName) + '</a></li>';
		}
		memberList = '<ul style="list-style-type:none;">' + memberList + '</ul>';
		$("#result-container").html(memberList);				
	})
}
  
  
  
  /**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {
    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}