// tourDB
// @file	    static.js   für tourDB
// @author	  mrt
// @copyright
//
// @desc      static javascript functions

var gmarkers = [];   // array of markers for Waypoints

/**
* toggles row on/off
*/
function toggleRow( thisrow, thistoggle ) {
  if( document.getElementById(thisrow).style.display=='none' ){
    // show
    document.getElementById(thisrow).style.display = '';
    document.getElementById(thistoggle).src="../img/expand-.gif";
    document.getElementById(thistoggle).alt="Hide Etappe";
    document.getElementById(thistoggle).title="Hide Etappe";
  } else {
    // hide
    document.getElementById(thisrow).style.display = 'none';
    document.getElementById(thistoggle).src="../img/expand+.gif";
    document.getElementById(thistoggle).alt="Show Etappe";
    document.getElementById(thistoggle).title="Show Etappe";
  }
}

/**
*
*/
function encodeMyHtml( text ) {
  //encodedHtml = escape(text);
  var encodedHtml = text;
  encodedHtml = encodedHtml.replace(/Ü/g,"&Uuml;");
  encodedHtml = encodedHtml.replace(/ü/g,"&uuml;");
  encodedHtml = encodedHtml.replace(/Ä/g,"&Auml;");
  encodedHtml = encodedHtml.replace(/ä/g,"&auml;");
  encodedHtml = encodedHtml.replace(/Ö/g,"&Ouml;");
  encodedHtml = encodedHtml.replace(/ö/g,"&ouml;");
  return encodedHtml;
} 

function encodeMyURL( url ) {
  var encodedURL = url;
  encodedURL = encodedURL.replace(/\//g,"%2F");
  encodedURL = encodedURL.replace(/\?/g,"%3F");
  encodedURL = encodedURL.replace(/=/g,"%3D");
  encodedURL = encodedURL.replace(/&/g,"%26");
  encodedURL = encodedURL.replace(/@/g,"%40");
  return encodedURL;
} 

/**
* concatenates array-elements with glue
*/
function implode( glue, pieces ) {
  var str = '';
  for (i=0;i<pieces.length; i++) {
    str = str + pieces[i] + glue;
  }
  return str;
}

/**
*  @desc checks if the argvulue is valid URL
*/
function isURL(argvalue) {
 	var regexp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
 	return regexp.test(argvalue);
}

/**
*  @desc checks if the string contains a URL. Returns the string (without URL) and the URL
*  @param s_obj = new Object(); s_obj.value=[argvalue];
*/
function includesURL(s_obj) {
  var url = false;
  var string_array = s_obj.value.split(' ');
  // check if s_obj.value contains a URL
  for (i = 0; i < string_array.length; i++){ 
    if (isURL(string_array[i])) {
      url = string_array[i];
      string_array[i] = '';
    }        
  }
  if (url) { 
    s_obj.value = implode( ' ', string_array );
  }
  return url;
}

/**
*  @desc: opens HTML ref
*         JS to open trip.php
*
*/
function openHREF( url ) {
  var myRef = window.open( url, "_self" );
}

/**
*  @desc: refresh of header.png
*  @param: delay - time in seconds
*/
function BannerRefresh( delay ) {
  image = "http://traube-online.net/tourDB/headerpng.php?title=tourDB&subtitle=Das%20GPS-Tourenarchiv%20im%20Internet" //name of the image
  tmp = new Date();
  tmp = "&delay="+tmp.getTime()
  if (delay > 0) {
    // reload png
    document.images["headerpng"].src = image+tmp
  }
  setTimeout("BannerRefresh(15)", delay*1000)           // reload the banner in 15sec
}

/**
*  @desc: This function picks up the click and opens the corresponding info window of marker#i
*  @param: i
*/
function mclick(i) {
  if ( i == 999 ) {
    // open InfoWindow for trailhead-marker
    GEvent.trigger(th_marker, "mouseover");     // th_marker is defined in gpxviewer.php
  }  else {
    // open InfoWindow for WP-marker[i]
    // array gmarkers is defined in GPXParser.prototype.CreateMarker(loadgpx.4.js)
    GEvent.trigger(gmarkers[i], "click");   
  }
  // center map on marker

  //MyMap.set_center(gmarkers[i].get_position());
  //MyMap.set_zoom(12);

}

       

