
    defaultAd ="<iframe src='defad.jsp' width='150px' height='350px' frameborder='0'></iframe>";

    function showLatLng()
    {
      if (document.getElementById("latlng").style.display=="block")
        hideBlock("latlng");
      else
        showBlock("latlng");        

      return false;
    }

    function setControlLine(usr)
    {
      var s;
      if (usr==null)
      {
       s='User: <input class="baseFont" style="width:80px" id="loginUserName" type="text" name="user" title="Type your user name"> Pwd: <input type="password" class="baseFont" style="width:80px" id="loginUserPassword" name="pwd" title="your password here"> <input type="button" class="baseFont" value="Login" title="Existing users login" onClick="loginUser()">'
        +'&nbsp;'
        +'<a href="javascript:void(0)" onClick="registerUser();return false;" title="New user registration">New user?</a>';
      }
      else
      {
        s="<b>User:</b> <em>"+usr.name+"</em>&nbsp;&nbsp;";
        if (usr.latitude && usr.longitude && usr.mt && usr.zoom)
          if (eval(usr.latitude)>0 && eval(usr.longitude)>0) 
           s+="<a href='javascript:void(0)' title='Home location' onClick='moveMap("+usr.latitude+","+usr.longitude+","+usr.zoom+","+usr.mt+");return false;'>Home</a>&nbsp;&nbsp;"        
                 
        s+="<a href='javascript:void(0)' title='User settings' onClick='getUsettings();return false;'>Settings</a>&nbsp;&nbsp;"
          +"<a href='javascript:void(0)' title='My communities' onClick='getCsettings();return false;'>Communities</a>&nbsp;&nbsp;&nbsp;&nbsp;"
          +"<a href='javascript:void(0)' onClick='logoutUser();return false;' title='Logout'>Logout</a>"; 
      }

      if (document.getElementById("controlLine"))
         document.getElementById("controlLine").innerHTML = s;

      if (currentCommunity==null)
      { 
       if (usr==null) s=getShowTypeSelect1();
       else           s=getShowTypeSelect3();
      }
      else
      { 
       if (usr==null) s=getShowTypeSelect2();
       else           s=getShowTypeSelect4();
      }

      if (document.getElementById("showTypes"))
         document.getElementById("showTypes").innerHTML = s;                   
    }

    function showHideBlock(id)
    {
      if (document.getElementById(id))
      {
        if (document.getElementById(id).style.display=="none")
          document.getElementById(id).style.display="block";
        else
          document.getElementById(id).style.display="none";
      }
    }


    function hideBlock(id)
    {
      if (document.getElementById(id))
        document.getElementById(id).style.display="none";
    }

    function hideBlocks(ara)
    {
      for (i=0; i<ara.length; i++)
       hideBlock(ara[i]);
    }

    function showBlock(id)
    {
      if (document.getElementById(id))
        document.getElementById(id).style.display="block";
    }

    function showBlockByObj(obj)
    {
      if (obj)
        obj.style.display="block";
    }

    function hideLast()
    {
        if (lastMarker) 
        {
          map.removeOverlay(lastMarker);
          lastMarker=null;
        }
    }

    function ImageInput()
    {
      var o = document.getElementById("iType");

      if (o.checked)
      {
        hideBlock("uploadImage");
        showBlock("imageSet"); 
      }
      else
      {
        hideBlock("imageSet");
        showBlock("uploadImage"); 
      }       
    }

    function AudioInput()
    {
      var o = document.getElementById("aType");

      if (o.checked)
      {
        hideBlock("uploadAudio");
        showBlock("audioSet"); 
      }
      else
      {
        hideBlock("audioSet");
        showBlock("uploadAudio"); 
      }       
    }


    function showDefaultAd(id)
    {
      var o = document.getElementById(id);

      if (!o) return;

      o.innerHTML = defaultAd; 
      showBlock(id);
    } 

    function emptyArray(ara)
    {
      if (ara==null) return true;
      if (ara.length==0) return true;

      return false;
    }

    function getexpirydate( nodays)
    {
      var UTCstring;
      Today = new Date();
      nomilli=Date.parse(Today);
      Today.setTime(nomilli+nodays*24*60*60*1000);
      UTCstring = Today.toUTCString();
      return UTCstring;
    }

    function getcookie(cookiename) 
    {
     var cookiestring=""+document.cookie;
     var index1=cookiestring.indexOf(cookiename);
     if (index1==-1 || cookiename=="") return ""; 
     var index2=cookiestring.indexOf(';',index1);
     if (index2==-1) index2=cookiestring.length; 
     return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
    }

   function setcookie(name,value,duration){
   cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
   document.cookie=cookiestring;
   }

   function validUrl(sUrl)
   {
     var i = sUrl.indexOf("http://");
     var i1 = sUrl.indexOf("https://");

     if (i!=0 && i1!=0) return false;

     return true;
   }

   function DirectLink(map)
   {
     var center = map.getCenter();
     var sUrl="http://map.linkstore.ru/index.jsp?"

       var filter=getFilter();
       if (filter=="1") 
       {
           if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name); 
       }
       else
        if (filter=="2") 
        { 
          if (currentUser!=null)
           sUrl+="&userId="+currentUser.id;
        }
        else
         if (filter=="3") 
          { 
            if (currentUser!=null)
             sUrl+="&userId="+currentUser.id;

            if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name) 
          }             

       document.forms['linkForm'].lat.value=center.lat();
       document.forms['linkForm'].lng.value=center.lng();
       document.forms['linkForm'].zml.value=map.getZoom();
       document.forms['linkForm'].mt.value=getApplicationMapType(map);
       document.forms['linkForm'].action="http://map.linkstore.ru/index.jsp"; //sUrl;
       document.forms['linkForm'].submit();
   }

   function MailTo(map)
   {
     var center = map.getCenter();
     var sUrl="http://map.linkstore.ru/index.jsp?"
              +"lng="+center.lng()
              +"&lat="+center.lat()
              +"&mt="+getApplicationMapType(map)
              +"&"+"zml="+map.getZoom();

       var filter=getFilter();
       if (filter=="1") 
       {
           if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name); 
       }
       else
        if (filter=="2") 
        { 
          if (currentUser!=null)
           sUrl+="&userId="+currentUser.id;
        }
        else
         if (filter=="3") 
          { 
            if (currentUser!=null)
             sUrl+="&userId="+currentUser.id;

            if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name) 
          }             

     var subjectLine='Take a look at this map from http://map.linkstore.ru'; 
     var bodyText='You can see this map at: '+sUrl;

     var message='mailto:?subject='+escape(subjectLine)+'&body='+escape(bodyText);
     var messageIE='mailto:?subject='+(subjectLine)+'&body='+escape(bodyText);     

     if(document.all) location.href=messageIE; 
     else  location.href=message; 
   }

   function MailTo1(_sUrl)
   {
     var sUrl=decodeURIComponent(_sUrl);
     var subjectLine='Take a look at this info from http://map.linkstore.ru'; 
     var bodyText='You can see this on map at: '+sUrl;

     var message='mailto:?subject='+escape(subjectLine)+'&body='+escape(bodyText);
     var messageIE='mailto:?subject='+(subjectLine)+'&body='+escape(bodyText);     

     if(document.all) location.href=messageIE; 
     else  location.href=message; 
   }

   function getGoogleMapType(mapType)
   {
     if (mapType=='0') return G_NORMAL_MAP;
     else
      if (mapType=='1') return G_SATELLITE_MAP;
      else
       if (mapType=='2') return G_HYBRID_MAP;

     return G_NORMAL_MAP;
   }

  function getApplicationMapType(map)
  {
   var ct=map.getCurrentMapType();

   if (ct==G_NORMAL_MAP) return 0;
   else
    if (ct==G_SATELLITE_MAP) return 1;
    else
      if (ct==G_HYBRID_MAP) return 2;

   return 0; 
  }

  function getVerbalMapType(t)
  {
   if (t==0) return "standard";
   else
    if (t==1) return "satellite";
    else
      if (t==2) return "hybrid";

   return "standard"; 
  }


  function validEmail(str)
  {
     var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     if(emailRegEx.test(str)) return true;
     else                     return false;
  }

  function validName(str) 
  {
    var nameRegEx = /^[a-zA-Z]([a-zA-Z0-9_\.\-])+$/;
    if(str.match(nameRegEx)) return true;
    else                     return false;
  }

  function getXHTML(map)
  {
       var center = map.getCenter();

       var sUrl="<iframe src='http://map.linkstore.ru/index.jsp?a=ro"
        + "&lat="+center.lat()
        + "&lng="+center.lng()
        + "&zml="+map.getZoom()
        + "&mt="+getApplicationMapType(map)
        + "&embed=1"
        + "&w=700"
        + "&h=500";

       var filter=getFilter();
       if (filter=="1") 
       {
           if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name)
       }
       else
        if (filter=="2") 
        { 
          if (currentUser!=null)
           sUrl+="&userId="+currentUser.id;
        }
        else
         if (filter=="3") 
          { 
            if (currentUser!=null)
             sUrl+="&userId="+currentUser.id;

            if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name)
          }             

       sUrl+= "' "
           + " width='700px' height='500px'"
           + " scrolling='none' frameborder='0'>"
           + "</iframe>";

     return sUrl;
  }

  function getRSSUrl(map)
  {
    var b = map.getBounds();
    var sw = b.getSouthWest();
    var ne = b.getNorthEast();   

    var sUrl = "http://linkstore.ru/servlet/GeoData"
        + "?lat1="+sw.lat()
        + "&lng1="+sw.lng()
        + "&lat2="+ne.lat()
        + "&lng2="+ne.lng();

       var filter=getFilter();
       if (filter=="1") 
       {
           if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name)
       }
       else
        if (filter=="2") 
        { 
          if (currentUser!=null)
           sUrl+="&userId="+currentUser.id;
        }
        else
         if (filter=="3") 
          { 
            if (currentUser!=null)
             sUrl+="&userId="+currentUser.id;

            if (currentCommunity!=null)
             sUrl+="&communityId="+currentCommunity.id+"&cn="+encodeURIComponent(currentCommunity.name)
          }             

    return sUrl;
  }

  function mainBeforeAction()
  {
    showBlock("loading"); 
  }

  function mainAfterAction()
  {
    hideBlock("loading");
  }

  function inArray(whatVar, whereAra)
  {
    for (i=0; i<whereAra.length; i++)
     if (whatVar==whereAra[i]) return true;

    return false;
  }

  function getFilter()
  {
    var obj = document.getElementById("showTypeSelect");
    if (obj)
    {
     var ind = obj.selectedIndex;
     return obj.options[ind].value;
    }
    else
     return -1;
  }

  function getBookMarksNew(sUrl)
  {
    var s="";

    s+="<script type='text/javascript'>";
    s+="addthis_url='"+sUrl+"';"   
    s+="addthis_title='Map from GeoLinks';"
    s+="addthis_pub='abava';";     
    s+="</script><script type='text/javascript' src='http://s7.addthis.com/js/addthis_widget.php?v=12'></script>";
    return s;
  }

  function getBookMarks(sUrl)
  {
    var s="";

    s+="<"+"a href='http://del.icio.us/post?url="+sUrl+"'>"+"<"+"img border='0' src='icons/delicious.gif' alt='Add to Del.icio.us'/>"+"<"+"/a> ";
    s+="<"+"a href='http://digg.com/submit?phase=2&url="+sUrl+"'>"+"<"+"img border='0' src='icons/digg.gif' alt='Add to Digg'/>"+"<"+"/a> ";
    s+="<"+"a href='http://technorati.com/faves?add?="+sUrl+"'>"+"<"+"img border='0' src='icons/technorati.gif' alt='Add to Technorati'/>"+"<"+"/a> ";
    s+="<"+"a href='http://blinklist.com/index.php?Action=Blink/addblink.php&url="+sUrl+"'>"+"<"+"img border='0' src='icons/blinklist.gif' alt='Add to Blinklist'/>"+"<"+"/a> ";
    s+="<"+"a href='http://furl.net/storeIt.jsp?u="+sUrl+"'>"+"<"+"img border='0' src='icons/furl.gif' alt='Add to Furl'/>"+"<"+"/a> ";
    s+="<"+"a href='http://reddit.com/submit?url="+sUrl+"'>"+"<"+"img border='0' src='icons/reddit.gif' alt='Add to Reddit'/>"+"<"+"/a ";

    return s;
  }

  function getInfoWindowHtml(obj)
  {
    var html = "<b>#</b> "+obj.id+" <em>"+obj.dt+"</em>";
    html+="<br/>";
    if (obj.image!='')
    {
      html+="<"+"a style='text-decoration:none' href='";

      if (validUrl(obj.image)) html+=obj.image; 
      else                     html+="http://www.linkstore.ru/map/image/"+obj.image;
   
      html+="' target='_blank'>"+"<"+"image src='";
   
      if (validUrl(obj.image)) html+=obj.image; 
      else                     html+="http://www.linkstore.ru/map/image/"+obj.image;

      html+="' width='75' height='75' border='0' align='left' hspace='5' vspace='2'>"+"<"+"/a>";
    }

    if (obj.title!='')
    {
      if (obj.link!='')
      {

        html+="<span id='favicon'></span> "; 

        html+="<"+"a style='text-decoration:none' href='"+obj.link+"' target='_blank' title='See the original location'>"+obj.title+"<"+"/a> "; 

        // html+="<"+"sup><img src='http://www.linkstore.ru/map/icons/ext.gif' border='0' alt='External link'>"+"<"+"/sup>";        
      }
      else
        html+=obj.title;
    }
    else
        html+="It is here!";

    if (obj.txt!='')
    {
        html+="<br/>";
        if (obj.txt.length<=100) html+=obj.txt;
        else                     html+=obj.txt.substring(0,100)+"...";
    }

    return html;

  }

  function deletePoint(pointId)
  {
    if (confirm('Delete info. Are you sure?'))
    {
      cjAjaxEngine("/servlet/GeoData?f=dp&id="+pointId,handlerDelete,errorDelete,mainBeforeAction,mainAfterAction); 
    }
  }

  function error2()
  {
      alert("Error. Could not load markers");
  }

  function error3()
  {
      alert("Error. Could not load communities");
  }

  function errorDelete()
  {
    alert("Connection error. Could not delete");
  }

  function handlerDelete(txt, xmlDoc)
  {
    if (txt!='') alert(txt);
    else         reloadMap();
  }

  function isCommunityLink(obj)
  {
    if (currentUser==null) return false;
    if (obj.communityid==null) return false;
    if (eval(obj.communityid)<=1) return false;
    if (obj.community=='none') return false;

    if (currentCommunity!=null)
     if (eval(currentCommunity.id)==eval(obj.communityid)) return false;

    return true;
  }

  function gotoCommunityById(id)
  {
    var url="/servlet/GeoData?f=jc&communityId="+id;
    if (currentUser==null) url+="&userId=0"
    else                        url+="&userId="+currentUser.id;
    url+="&fict="+(new Date()).getTime();

    cjAjaxEngine(url,handlerGotoCommunity, errorGotoCommunity,mainBeforeAction,mainAfterAction);
 
    return true;
 }

 function errorGotoCommunity()
 {
   alert("Error: could not join to community");
 }

 function handlerGotoCommunity(txt, xmlDoc)
 {
  if (txt.indexOf("{")!=0) alert(txt);
  else
  {
    var c = eval("("+txt+")");  
    var s = "<"+"a href='javascript:void(0)' onClick='getCommunityInfo("+c.id+");return false;' title='Community info'>"+c.name+"<"+"/a>";
    document.getElementById("communityInfo").innerHTML=s;

    s="";
    if (currentUser!=null) s = getShowTypeSelect4();
    else                   s = getShowTypeSelect2();

    if (document.getElementById("showTypes"))
         document.getElementById("showTypes").innerHTML = s;  

    currentCommunity = c;
    moveMap(c.latitude,c.longitude, c.zoom, c.mt);
  }
 } 

 function proxyClickInfo(s,lat,lng)
 {
  try
  {
   parent.location.hash="#"+lat+"|"+lng+"||";
  }
  catch (ex)
  {
   parent.location=s+"#"+lat+"|"+lng+"||";
  }
 }

 function proxyMarkerInfo(s,obj)
 {
  if (obj.link=='') obj.link=' ';

  try
  {
   parent.location.hash="#"+obj.latitude+"|"+obj.longitude+"|"+obj.id+"|"+obj.link+"|"+obj.title+"||";
  }
  catch (ex)
  {
   parent.location=s+"#"+obj.latitude+"|"+obj.longitude+"|"+obj.id+"|"+obj.link+"|"+obj.title+"||";
  }
 }

 function showChat()
 {
  if (document.getElementById("chat").style.display=="block")
  {
     hideBlock("chat");
     showBlock("oldData");
  }
  else 
  {
     showBlock("chat");
  }
 }
 
function createFavicon(link,defImg,className)
{
  var cue = document.createElement("img");
  if (className)
    cue.className=className;

  cue.style.width='16px'; 
  cue.style.height='16px'; 

  var domain = link.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/);
  domain = RegExp.$2;

  var cuesrc = "http://"+domain+"/favicon.ico";
  cue.setAttribute("src",cuesrc);
  cue.onerror = function () 
  {
	this.src = defImg;
        this.style.width='1px'; 
        this.style.height='1px'; 
  }

  return cue;
}

function chatWithUser(uName,uId)
{
   parent.showMeeboChat(uName,uId);
} 

function videoChatWithUser(uName,uId)
{
   parent.showTokboxChat(uName,uId);
} 

function getCommunitiesCloudCode(list)
{ 
  var max = 0;
  var i = 0;
  var comm;
  for (i=0; i<list.length; i++)
  {
   comm = list[i];
   if (eval(comm.points) > max) max = eval(comm.points);     
  } 

  var s = "";
 
  for (i=0; i<list.length; i++)
  {
   comm = list[i]; 
   var fontSize=(150.0*(1.0+(1.5*eval(comm.points)-max/2)/max));
      
   s+="<a style='font-size:"+fontSize+"%' href='javascript:void(0)' onClick='gotoCommunityById("+comm.id+");return false;' title='"+comm.description+"'>"+comm.name+"</a>";
   s+=" ";
  } 
  
  return s;
}





