////////////////////////////////////////////////////
// GLOBAL VARIABLES FOR THE SCRIPTS
////////////////////////////////////////////////////

  // Server addresses
  //---------------------------------
//  var URL_Web_server = 'http://fuentelcarro.fadlan.com:81/Fuentelcarro/'
//  var URL_Web_server = 'http://fuentelcarro.fadlan.com:81/'
  var URL_Web_server = '/'

  // Browser used
  //---------------------------------
  var Browser = navigator.appName;

   
  // Clear Status Bar
  //-----------------
  window.status = '';
   
//==================================================


//==================================================
// Name:    URLEncode
// Purpose:   Chenges spaces to plus signs.
// Passed In: String to Change
// Returns:   Chenged String
//==================================================
function URLEncode(sString)
{
  var iPos = sString.indexOf(' ', 0);
  while (iPos != -1)
  {
    sString = sString.substring(0, iPos) + '+' + sString.substring(iPos+1, sString.length);
    iPos = sString.indexOf(' ', 0);
  }
  return sString;
}


//==================================================
function PhotoExpand(s,w,h) {
  var h1 = h + 50

  var ptr = s.indexOf('PhotoPics/S_')
  if (ptr == -1) return false;
  var fotoname = s.substring(ptr + 12, s.length)
   
  var config1 = 'toolbar=no,status=no,menubars=no,scrollbars=no,resizable=yes'
      config1 += ',location=no,directories=no,width='+w+',height='+h1

  var redir="foto_ampliada.htm?Img=" + fotoname + "&w=" + w + "&h=" + h

  var OpenWindow=window.open(redir, "newwin", config1);

  OpenWindow.focus()
}
 
////////////////////////////////////////////////////
//  G E N E R I C   F U N C T I O N S
////////////////////////////////////////////////////
//==================================================
// Name:  getCookie
// Purpose: Reads a Client Cookie
// Passed In: Name of the cookie
// Returns: Value of the Cookie or null if cookie
//    does not exist.
//==================================================
function getCookie(Name)
{
  var search = Name + "="
  if (document.cookie.length > 0) {
    // if there are any cookies
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
      // if cookie exists
      offset += search.length

      // set index of beginning of value
      end = document.cookie.indexOf(";", offset)

      // set index of end of cookie value
      if (end == -1)
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
}
 
//==================================================
// Name:  RemovePlus
// Purpose: Changes '+' by ' ' (spaces)
// Passed In: string -  String to be analysed
// Returns: Value of the String 
//==================================================
function RemovePlus(sString) {
  var iPos = sString.indexOf('+', 0);
  while (iPos != -1)
  {
    sString = sString.substring(0, iPos) + ' ' + sString.substring(iPos+1, sString.length);
    iPos = sString.indexOf('+', 0);
  }
  return sString;
}

//==================================================
// Name:  getCookieKey
// Purpose: Reads a Client Cookie Key
// Passed In: name -    Name of the cookie
//    key -   Name of the key
// Returns: Value of the Cookie key or null if key
//    does not exist.
//==================================================
function getCookieKey(name, key) {
   var CookieVal = getCookie(name);
   if (CookieVal == undefined) return null;
   var arg = key + "=";
   var i = CookieVal.indexOf(arg, 0);
   if (i == -1) return null;
   i = i + arg.length;
   var j = CookieVal.indexOf("&", i);
   if (j == -1) j=CookieVal.length;
   return RemovePlus(CookieVal.substring(i, j));
}

//==================================================
// Name:  setCookie
// Purpose: Writes a Client Cookie
// Passed In: name -    Name of the cookie
//    value -   Value of the cookie
//    expires - Expiration date of the cookie
//    path -    Path for which the cookie is valid
//    domain -  domain for which the cookie is valid
//    secure -  boolean indicating that cookie reuires
//        a secure transmission.
// Returns: None.
//==================================================
function setCookie(name, value, expires, path, domain, secure)
{
  var caution = false;

  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "")
  if (!caution || (name + "=" + escape(value)).length <= 4000)
    document.cookie = curCookie
  else
    if (confirm("Cookie exceeds 4KB and will be cut!"))
      document.cookie = curCookie
}
