function OnLoad()
{
   var hrefString = window.location.href.toLowerCase();
   var hrefColor  = "#FF0000";
   
   if (hrefString.substring(hrefString.length - 8, hrefString.length) == "riga.com"  || 
       hrefString.substring(hrefString.length - 9, hrefString.length) == "riga.com/" || 
       hrefString.indexOf("default.asp") > -1)
   {
      document.getElementById("mindex").style.color= hrefColor;
      document.getElementById("findex").style.color= hrefColor;
   }else if (hrefString.indexOf("arrive.asp") > -1)
   {
      document.getElementById("marrive").style.color= hrefColor;
      document.getElementById("farrive").style.color= hrefColor;
   }else if (hrefString.indexOf("accommodation.asp") > -1)
   {
      document.getElementById("maccommodation").style.color= hrefColor;
      document.getElementById("faccommodation").style.color= hrefColor;
   }else if (hrefString.indexOf("around.asp") > -1)
   {
      document.getElementById("maround").style.color= hrefColor;
      document.getElementById("faround").style.color= hrefColor;
   }else if (hrefString.indexOf("to-do.asp") > -1)
   {
      document.getElementById("mto_Do").style.color= hrefColor;
      document.getElementById("fto_Do").style.color= hrefColor;
   }else if (hrefString.indexOf("photos.") > -1)
   {
      document.getElementById("fphotos").style.color= hrefColor;
   }else if (hrefString.indexOf("words.asp") > -1)
   {
      document.getElementById("fwords").style.color= hrefColor;
   }else if (hrefString.indexOf("latvia.asp") > -1 || 
             hrefString.indexOf("in-latvia.com") > -1 ||
             hrefString.indexOf("in-latvia.com/") > -1)
   {
      document.getElementById("mLatvia").style.color= hrefColor;
      document.getElementById("fLatvia").style.color= hrefColor;
   }

   SearchQuery();
}

//Less parameter better for Google Search and time to load
var browseWin1, browseWin2; //two active subwindows so user can compare

function OpenBrowse(theURL)
{
  if (browseWin2 && !browseWin2.closed) {
     browseWin2.close();
  }
  browseWin2 = browseWin1;

	var theTitle  = theURL; /* nothing interesting yet */
  var winWidth  = screen.availWidth;
  var winHeight = (screen.availHeight / 6) * 5;
  /* winLeft  = screen.availLeft useful when taskbar in vertical but property only in NN4+ */ 
		
  var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left=0,toolbar=yes,location=yes,scrollbars=yes,resizable=yes,titlebar=no';

  browseWin1= window.open("", "_blank", winSettings);
  browseWin1.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"+
          "<html><head>"+
					"<title>" + theTitle + "</title>" +
					"<link rel=\"stylesheet\" href=\"assets/in-Riga.css\" type=\"text/css\"></head>" +
					"<frameset rows=\"12%, 88%\">" +
							"<frame src=\"frame-top.aspx?link=" + theURL + "\" name=\"RigaHead\" marginwidth=\"0\" scrolling=\"no\" frameborder=\"0\" />" + 
					    "<frame src=\"" + theURL.replace(/\"/g, "&quot;") + "\" name=\"RigaInfo\" marginwidth=\"0\" scrolling=\"yes\" frameborder=\"0\" />" + 
              "<noframes>"+
					       "Seems that your browser does not support FRAMES, please go to: " + theURL + " to visit the link" +
					    "</noframes>" +
					"</frameset></html>");
		browseWin1.document.close();
}

function OpenBrowsePop(theURL)
{
  if (browseWin2 && !browseWin2.closed) {
     browseWin2.close();
  }
  browseWin2 = browseWin1;

	var theTitle  = theURL; /* nothing interesting yet */
  var winWidth  = screen.availWidth;
  var winHeight = (screen.availHeight / 3) * 2;
  /* winLeft  = screen.availLeft useful when taskbar in vertical but property only in NN4+ */ 
		
  var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left=0,toolbar=yes,location=no,scrollbars=yes,resizable=yes,titlebar=no';

  browseWin1= window.open("", "_blank", winSettings);
  browseWin1.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"+
          "<html><head>"+
					"<title>" + theTitle + "</title>" +
					"<link rel=\"stylesheet\" href=\"assets/in-Riga.css\" type=\"text/css\"></head>" +
					"<frameset rows=\"25%, 75%\">" +
							"<frame src=\"frame-top.aspx?org=pop&link=" + theURL + "\" name=\"RigaHead\" marginwidth=\"0\" scrolling=\"no\" frameborder=\"0\" />" + 
					    "<frame src=\"" + theURL + "\" name=\"RigaInfo\" marginwidth=\"0\" scrolling=\"yes\" frameborder=\"0\" />" + 
              "<noframes>"+
					       "Seems that your browser does not support FRAMES, please go to: " + theURL + " to visit the link" +
					    "</noframes>" +
					"</frameset></html>");
		browseWin1.document.close();
}


var genWin;
function OpenWindow(theURL, theTitle, theWidth, theHeight)
{
  if (genWin && !genWin.closed) {
     genWin.close()
  }
  
  var availHeight = screen.availHeight - 50;  //discount for Windows taskbar		
  var winWidth  = (screen.availWidth >= theWidth ) ? theWidth : screen.availWidth;
  var winHeight = (availHeight       >= theHeight) ? theHeight : availHeight;
  var winLeft   = (screen.availWidth-winWidth)/2;
		
  var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left='+winLeft+',toolbar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no';
      
  genWin = window.open(theURL, "_blank", winSettings);
}

var photoWin;
function OpenPhoto(theURL, theTitle, theWidth, theHeight)
{
  if (photoWin && !photoWin.closed) {
     photoWin.close()
  }
  
  var availHeight = screen.availHeight - 50;  //discount for Windows taskbar
		
  var winWidth  = (screen.availWidth >= theWidth ) ? theWidth : screen.availWidth;
  var winHeight = (availHeight       >= theHeight) ? theHeight : availHeight;
  var winLeft   = (screen.availWidth-winWidth)/2;
		
  var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left='+winLeft+',toolbar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no';
      
  photoWin = window.open(theURL, "_blank", winSettings);

  /*
    photoWin.document.write("<html><head><title>"+theTitle+"</title></head><body>" +
       "<img src=\""+theURL+ "\" width=\""+theWidth+ "\" height=\""+theHeight+ "\" name=\"photo\""+
       " onclick=\"javascript:photo.height*=2;photo.width*=2\" "+
       " ondblclick=\"javascript:photo.height/=2;photo.width/=2\">"+
					  "</body></html>");
		  photoWin.document.close();
  */
}

var mapWin1, mapWin2; //two active subwindows so user can compare
function OpenMap(theTitle, theUrl, theAddress)
{
  if (mapWin2 && !mapWin2.closed) {
     mapWin2.close();
  }
  mapWin2 = mapWin1;

  var winWidth  = 700;
  var winHeight = 600;
  var winLeft   = (screen.availWidth-winWidth)/2;
		
  var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left='+winLeft+',toolbar=no,location=no,scrollbars=no,resizable=no,titlebar=no';

  mapWin1 = window.open("http://www.in-riga.com/map-search.aspx?lang=en" + 
                        "&title=" + escape(theTitle.replace(/ /g, "-")) +
                        "&url=" + escape(theUrl) +
                        "&address=" + escape(theAddress.replace(/ /g, "-")),
  //mapWin1 = window.open("http://www.118.lv/karte?lang=en&isearch=" + theAddress, 
  //mapWin1 = window.open("http://link2.map24.com/?lid=3a3e90a1&amp;maptype=JAVA&amp;width0=1500&amp;q0=Riga%20" + theAddress + "&amp;country0=LV&amp;logo_url0=&amp;name0=&amp;description0=", 
                        "_blank", winSettings);
                        
}

//Write the map icon and the link to open the window with the map
function WriteMapFull(theTitle, theUrl, theAddress) {
   document.write("<a href=\"javascript:\" onclick=\"OpenMap('" + theTitle + "','" + theUrl + "','" + theAddress + "')\" >");
   document.write("<img src=\"assets/images/icon_Map.gif\" width=\"25\" height=\"10\" alt=\"Check the Location in the Map\" /></a>");
}
//Overload with only 1 parameter
function WriteMap(theAddress) {
    WriteMapFull('In-Riga.com', 'http://www.in-riga.com/', theAddress);
}

function WriteEM(user, domain) {

   document.write('<a href=\"');
   document.write('mailto:');
   document.write(user + '@' + domain + '\">');
   document.write(user + '@' + domain + '</a>');
}

// ADD TO FAVOURITES: FIRST STEP
function AddFavour(lang){
    var url = window.location;  //For cross browser use window.location
    var title = document.title;

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    } else if (window.opera) { // Opera 7+
        return false; // do nothing - the rel="sidebar" should do the trick
    } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
        alert('Unfortunately, this browser does not support the requested action,'
                                     + ' please bookmark this page manually.');
    }
}

// EMAIL LINK TO FRIEND: FIRST STEP
function EmailLink(lang){
var subjMsg;

   switch (lang.toLowerCase()){
   case 'es':
	  subjMsg = "Mira este link con información sobre Riga";
      break;
   case 'it':
   default:
      subjMsg = "I thought this link with information about Riga might interest you.";
   }
   window.location = "mailto:"+"?subject="+ subjMsg + "&body="+ document.title + "%0D%0A  " + window.location;
}

//
function GetHTMLSocialBook(numLinks)
{
   var arrayLinks = [["Del.icio.us", "del.icio.us/post?url="],
                     ["Digg.com",    "digg.com/submit?phase=2&url="],
                     ["Reddit.com",  "reddit.com/submit?url="],
                     ["Furl.net",  "www.furl.net/storeIt.jsp?u="],
                     ["Shadows.com",  "www.shadows.com/features/tcr.htm?url="],
                     ["Y! MyWeb",  "myweb2.search.yahoo.com/myresults/bookmarklet?u="],
                     ["Blinkbits", "www.blinkbits.com/bookmarklets/save.php?v=1&source_url="],
//                     ["Spurl", "ttp://www.spurl.net/spurl.php?url="],
                     ["StumbleUpon",  "www.stumbleupon.com/submit?url="],
                     ["PreFound",  "www.prefound.com/submit?url="],
                     ["Technorati","technorati.com/faves?sub=addfavbtn&amp;add="],
                     ["LinkAGoGo","www.linkagogo.com/go/AddNoPopup?url="]];

   var iLink= Math.floor(Math.random() * arrayLinks.length);
   for (var i=0; i< numLinks; i++)
   {
      document.write("<a href=\"http://" + 
                  arrayLinks[iLink][1] + window.location + 
                  "\" title=\"Submit this site to " + arrayLinks[iLink][0] + "  and let people know about Riga\"" + 
                  "target=\"_blank\">" + arrayLinks[iLink][0] +"</a><br>");
      iLink++;
      if (iLink >= arrayLinks.length) iLink= 0;
   }
}

/////////////////////////////////////////////////////////////
//Floating window scripts
function JSFX_FloatTopRight(section)
//From http://www.javascript-fx.com
{
        var startX = 0, startY = 120;
        var ns = (navigator.appName.indexOf("Netscape") != -1);
        var d  = document;
        var px = document.layers ? "" : "px";
        function ml(id)
        {
          var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
          if(d.layers)el.style=el;
          el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;};
          el.x = startX; el.y = startY;
          return el;
        }
        window.stayTopRight=function()
        {
          var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
          var dY = (pY > startY) ? pY : startY;
          ftlObj.y += (dY - ftlObj.y)/8;
          ftlObj.sP(ftlObj.x, ftlObj.y);
          setTimeout("stayTopRight()", 40);
        }
        ftlObj = ml(section);
        stayTopRight();
}

function JSFX_FloatTopLeft(section)
//From http://www.javascript-fx.com
{
  var startX = 0, startY = 120;
  var ns = (navigator.appName.indexOf("Netscape") != -1);
  var d  = document;
  var px = document.layers ? "" : "px";

  function mlLeft(id)
  {
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		
		return el;
 }

 window.stayTopLeft=function()
 {
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var dY = (pY > startY) ? pY : startY;
		
		ftlObj.y += (dY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 40);
 }

 ftlObj = mlLeft(section);
 stayTopLeft();
}

//!!! Does not work
function FloatLeftY(section)
{
    var startY = 120;
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d  = document;
    var px = document.layers ? "" : "px";
    function ml(id)
    {
      var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
      if(d.layers)el.style=el;
      el.sP=function(y){this.style.top=y+px;};
      el.y = startY;
      return el;
    }
    window.stayLeftY=function()
    {
      var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
      var dY = (pY > startY) ? pY : startY;
      ftlObj.y += (dY - ftlObj.y)/8;
      ftlObj.sP(ftlObj.y);
      setTimeout("stayLeftY()", 10);
    }
    ftlObj = ml(section);
    stayLeftY();
}


////////////////////////////////////////////////////////////
//Search for a word if the query string contains "?search=" (Only works in MS IE - Windows)
function SearchQuery()
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
      if (location.search.length > 8 && location.search.substring(1, 8) == "search=")  //"?search="
      {
         var srchString = unescape(location.search.substring(8, location.search.length));
         srQuery(document.body, srchString, false, true);
      }
    }
}

// Global range object variable
var rng;

function getArgs(caseSensitive, wholeWord) {
    var isCaseSensitive = (caseSensitive) ? 4 : 0;
    var isWholeWord = (wholeWord) ? 2 : 0;
    return isCaseSensitive ^ isWholeWord;
}
   
// Prompted search and replace
function srQuery(container, search, caseSensitive, wholeWord)
{
    var nextOccurrence = true;
    
    if (search)
    {
        var args = getArgs(caseSensitive, wholeWord);
        rng = document.body.createTextRange( );
        rng.moveToElementText(container);
        while (rng.findText(search, 10000, args) && nextOccurrence)
        {
            rng.select( );
            rng.scrollIntoView( );
            nextOccurrence = confirm("Go to next occurrence of \"" + search.toUpperCase() + "\" ?");
            rng.collapse(false);
        }    
    }
}

function ToggleLayer(layerId)
{
   var layer= document.getElementById(layerId);
   
   if (layer.style.display == 'block')
   {
       layer.style.display='none';
   }
   else
   {
       layer.style.display='block';
   }
}

