 var go = true;


 function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}


function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}
 

     

    function amMapCompleted(map_id)
    {
      flashMovie = document.getElementById(map_id);
    }
    



     function find_for_country(id_country,country_caption)
     {
           if (id_country != 'all')$('#partners_content').html('<h4 style="margin-left: 8px;">'+country_caption+'</h4>');
           else $('#partners_content').html('');
           
            
         

          $.post('/async/Get_country_representations/index.html', {'id_country':id_country}, function(data){
                    
                    for (var i in data)
                    {
                    
                         /*
                           $('#partners_content').append('<div class="anketa"><a href="http://'+data[i].domainname+'.masterforex.org/" class="anketa_full_link"></a>\n\
                                                            <div class="clear"></div>\n\
                                                            <div class="rightalign">'+data[i].phone+' </div> <div style="font-size: 11px;" class="leftalign"><strong>&nbsp;'+data[i].caption+'</strong></div>\n\
                                                            <div class="clear"></div>\n\
                                                            <img src="/images/agents/photo_'+data[i].agentid+'.jpg">\n\
                                                            <div class="a_main_info">\n\
                                                            <strong>Address</strong>\n\
                                                            <br>'+data[i].contact_info+'<br>\n\
                                                            <a href="mailto:'+data[i].email+'">'+data[i].email+' </a>\n\
                                                            </div>\n\
                                                            <div class="clear"></div></div>');
                          */
                           if(data[i].domainname == 'Port Harcourt')
                             $('#partners_content').append('<div class="anketa"><a href="http://www.masterforexng.com" class="anketa_full_link"></a>\n\
                                                            <div class="clear"></div>\n\
                                                            <div class="rightalign">'+data[i].phone+' </div> <div style="font-size: 11px;" class="leftalign"><strong>&nbsp;'+data[i].caption+'</strong></div>\n\
                                                            <div class="clear"></div>\n\
                                                            <img src="/images/agents/photo_'+data[i].agentid+'.jpg">\n\
                                                            <div class="a_main_info">\n\
                                                            <strong>Address</strong>\n\
                                                            <br>'+data[i].contact_info+'<br>\n\
                                                            <a style="text-align:right; float:right;" href="http://www.masterforexng.com/">partners site</a>\n\
                                                            </div>\n\
                                                            <div class="clear"></div></div>');
                           else if(data[i].domainname == 'spb')
                             $('#partners_content').append('<div class="anketa"><a href="http://masterforex.org/Ru/About/seminar/index.html" class="anketa_full_link"></a>\n\
                                                            <div class="clear"></div>\n\
                                                            <div class="rightalign">'+data[i].phone+' </div> <div style="font-size: 11px;" class="leftalign"><strong>&nbsp;'+data[i].caption+'</strong></div>\n\
                                                            <div class="clear"></div>\n\
                                                            <img src="/images/agents/photo_'+data[i].agentid+'.jpg">\n\
                                                            <div class="a_main_info">\n\
                                                            <strong>Address</strong>\n\
                                                            <br>'+data[i].contact_info+'<br>\n\
                                                            <a style="text-align:right; float:right;" href="http://masterforex.org/Ru/About/seminar/index.html">partners site</a>\n\
                                                            </div>\n\
                                                            <div class="clear"></div></div>');
			     else
                            $('#partners_content').append('<div class="anketa"><a href="http://'+data[i].domainname+'.masterforex.org/" class="anketa_full_link"></a>\n\
                                                            <div class="clear"></div>\n\
                                                            <div class="rightalign">'+data[i].phone+' </div> <div style="font-size: 11px;" class="leftalign"><strong>&nbsp;'+data[i].caption+'</strong></div>\n\
                                                            <div class="clear"></div>\n\
                                                            <img src="/images/agents/photo_'+data[i].agentid+'.jpg">\n\
                                                            <div class="a_main_info">\n\
                                                            <strong>Address</strong>\n\
                                                            <br>'+data[i].contact_info+'<br>\n\
                                                            <a style="text-align:right; float:right;" href="http://'+data[i].domainname+'.masterforex.org/">partners site</a>\n\
                                                            </div>\n\
                                                            <div class="clear"></div></div>');                                  
                                                            
                                                            
                       //   if (id_country != 'all') $('#citys').append('<option value="'+data[i].oid_city+'">'+data[i].city_caption+'</option>');
                    }
                    return false;
                }, 'json');

                 return false;
     }
     
     function click_for_country(id_country,country_caption)
     {
           find_for_country(id_country,country_caption);
           
           go = false;
            flashMovie.clickObject(id_country);
           go = true;  
           
     }



        function buildAllCountrys()
            {
                           $.post('/async/Get_ALLcountrys/index.html', {}, function(data){

                             $('#country').html('');
                            for (var i in data)
                            {   
                                $('#country').append('<a style="font-size: 14px;" href="#" onclick = "click_for_country(\''+data[i].oid+'\' , \''+data[i].caption+'\' );" >'+data[i].caption+'</a>');
                            }
                        }, 'json');

                find_for_country('all');

                return false;
            }




       
       function amRegisterClickAnywhere(map_id, object_id, title, value)
        {
         if(typeof(object_id)!='undefined')
         {
               if(strpos(object_id,'city',1)!=false)
                   {
                       // alert(title__object_id);
                     if(go == true)
                     {
                     
                     $.post('/async/Get_domainname/index.html', {'id_city':object_id}, function(data)
                     {
                            domain =  data.domainname; 
                            if(domain != 'nigeria')window.location = 'http://'+domain.toLowerCase()+'.masterforex.org';
                     }, 'json');
                     
                      
                     } 
                   }
               else if(object_id.length == 2)
                   {        
                     if(go == true)
                       find_for_country(object_id,title);
                      
                   }
                  return false;
         }   
        }
         

 
         
   
function show_mf_map()
{

//$('#mf_dynamic_map').html('___');

      $('#mf_dynamic_map').html('<div class="tarnsp_bg" id="tarnsp_bg" ></div> <div class="partners_map" id="partners_map" > <div class="p_map_close"><a href="#" title="close">X</a></div> <div class="p_map_info rightalign"> <div class="country" id= "country"> <h4>Choose your country</h4> </div> <div class="partners_content" id="partners_content"> </div> </div> <div class="leftalign flash_map"> <div id="flashcontent"> <strong style="position:absolute; display:block; margin-top:5px; margin-left:10px; color:#fff;" >You need to upgrade your Flash Player</strong> </div> <div class="map_border"></div> </div> </div>');
              
                   
            		var so = new SWFObject("/ammap/ammap.swf", "ammap", "518", "355", "8", "#444444");
                so.addParam("wmode", "transparent");
            
            		so.addVariable("path", "/ammap/");
                            so.addVariable("map_id", "ammap");
            
            		so.addVariable("settings_file", escape("/ammap/ammap_settings.x"));                  
            		so.addVariable("data_file", escape("/ammap/ammap_data.x"));
                            so.addVariable("preloader_color", "#999999");
            		so.write("flashcontent");
            	
    	
              buildAllCountrys();

            $('#mf_dynamic_map').css('display','block');   
           //$('#partners_map').css('display','block');
          
}


 $(document).click(function(event) {

              if($(event.target).attr('id')!='show_map' && $('#mf_map').css('display')!='none')
                $('#mf_map').fadeOut('fast');
              
          });  

   
          
     $('#show_map').live('click', function(e) {
               
              $('#mf_map').fadeIn('slow');
              e.stopPropagation(); 
            
        });
        
         
        
       $('.p_map_close a').live('click', function() {

           $('#tarnsp_bg').css('display','none');
           $('#partners_map').css('display','none');
        });

