/*************************************************************************************
* Filename: bc.js
* Version:  v1.0
* Date:     2004-Dec-7
* Author:   Chuck Lutz
*
* (c) 2004 MaxedMedia
* 
* Client: Vesta Italian Villas - www.vestaitalianvillas.com
*
* Description:
*
* Javascript for "Vesta Italian Villas" Breadcrumb system. There are three levels of
* breadcrumb paths; from top to bottom they are: Region or Group Size, Locality, and
* Villa name. 
*
* Locality is optionally displayed (see "showloc" below).
***************************************************************************************/

// Global switch for showing or not showing the "Locality" level in breadcrumbs:
showloc = true;

// Global switch for reporting debugging information:
db = false;

/**************************************************
* setBCVals(reggrp, locality, villa)
*
* Sets session cookie values for these data
**************************************************/
function setBCVals(reggrp, locality, villa) {
      
	  // reggrp/Group:
	  if (reggrp) {
	    document.cookie = "reggrp="+reggrp;
	  }
	  
	  // Locality:
	  if (locality) {
		document.cookie = "locality="+locality;
	  }
	  else {
	    document.cookie = "locality=none";
	  }
	  
	  // Villa:
	  if (villa) {
		document.cookie = "villa="+villa;
	  }
	  // Is this really necessary? Since only villa pages display
	  // breadcrumbs (as of now), we don't have to worry about
	  // "residual" values being displayed accidentally on any
	  // reggrp or group pages.
	  //
	  // If reggrp/Group pages display BCs later, then this should
	  // take care of nulling out the most recently set Villa value.
	  else {
	    document.cookie = "villa=none";
	  }
	  
	  // Debug report:
	  if (db) {
	    document.writeln("***setBCVals():**********<br>");
		document.writeln("Parameter Values:<br>");
		document.writeln("Region/Group: " + reggrp   + "<br>");
		document.writeln("Locality: "     + locality + "<br>");
		document.writeln("Villa: "        + villa    + "<br>");
		document.writeln("<br>");
		document.writeln("Breadcrumb Cookie Values:<br>");
		document.writeln("Region/Group: " + getNumberValue(document.cookie,"reggrp")   + "<br>");
		document.writeln("Locality: "     + getNumberValue(document.cookie,"locality") + "<br>");
		document.writeln("Villa: "        + getNumberValue(document.cookie,"villa")    + "<br>");
		document.writeln("<br>");
	  }
	  
}

/**************************************************
* renderBC()
*
* Renders the actual Breadcrumb trail
**************************************************/
function renderBC() {
  // Short names / filename stubs (i.e. <name>.html):
  rg = getNumberValue(document.cookie,"reggrp");
  l  = getNumberValue(document.cookie,"locality");
  v  = getNumberValue(document.cookie,"villa");
  // Long, "friendly" names:
  RG = nameLookup(rg);
  L  = nameLookup(l);
  V  = nameLookup(v);
  
  if (db) {
	document.writeln("***renderBC():***********<br>");
	document.writeln("Breadcrumb Lookup Values:<br>");
	document.writeln("Region/Group: "  + rg + "<br>");
	document.writeln("Locality: "+ l + "<br>");
	document.writeln("Villa: "   + v + "<br>");
	document.writeln("<br>");
  }
	  
  // ****** Write "Home": *********************************************
  document.write('&nbsp;<A HREF="../index.html"><font face="arial, Sans Serif" size="1" color="#682C00">Home</font></A>');
  
  // ****** Write first " >> ": ***************************************
  document.write('<font face="arial, Sans Serif" size="1" color="#682C00">&nbsp;&gt;&gt;&nbsp;</font>');
  
  // ****** Write Region/Group (include " >> " as needed): ******
  // Region is set (include Locality if present):
  if (rg != "none") { 
    document.write('<A HREF="../' + rg +'.html"><font face="arial, Sans Serif" size="1" color="#682C00">' + RG + '</font></A>');
	document.write('<font face="arial, Sans Serif" size="1" color="#682C00">&nbsp;&gt;&gt;&nbsp;</font>');
	
	if ((l != "none") && showloc) {
      document.write('<font face="arial, Sans Serif" size="1" color="#682C00">' + L + '</font>');
	  document.write('<font face="arial, Sans Serif" size="1" color="#682C00">&nbsp;&gt;&gt;&nbsp;</font>');
    }
  }
  // Write a WARNING if Region/Group is missing (i.e. set to "none"):
  else {
    document.write('<font face="arial, Sans Serif" size="1" color="#682C00">WARN:Reg/GrpMissing</font>');
  }
  
  // ****** Write Villa: **********************************************
  if (v != "none") {
    document.write('<font face="arial, Sans Serif" size="1" color="#682C00">' + V + '</font>');
  }
  else {
    document.write('<font face="arial, Sans Serif" size="1" color="#682C00">WARN:VillaMissing</font>');
  }
}


/**************************************************
* nameLookup(s)
*
* Mapping between the breacrumb/file names and the
* actual "friendly" names
**************************************************/
function nameLookup(s) {
  switch (s) {
  
    /********************************
	*  FIRST LEVEL: Region or Group *
	********************************/ 
	 
    /********** Regions: ***********/
	
	// Test Regions:
    case "RegA":                     return "reggrp A";
	case "RegB":                     return "reggrp B";
	// Real Regions:
	case "lombardia":                return "Lombardia";
	case "tuscany":                  return "Tuscany";
    case "umbria":                   return "Umbria";
	case "lazio":                    return "Lazio";
	case "liguria":                  return "Liguria";
	case "puglia":                   return "Puglia";
	case "veneto":                   return "Veneto";
	case "campania":                 return "Amalfi Coast";
	
	/********** Groups: ************/
	
	case "villa_search_couples":     return "Couples";
	case "villa_search_2to4":        return "2 to 5 People";
	case "villa_search_6to8":        return "6 to 8 People";
	case "villa_search_10":          return "10 People";
	case "villa_search_10plus":      return "12+ People";
	
	/**************************
	*  SECOND LEVEL: Locality *
	**************************/
	
	// Test Localities:
	case "LocA":                     return "Locality A";
	case "LocB":                     return "Locality B";
	// Real Localities:
	case "lucca":                    return "Lucca Area";
	case "fucmont":                  return "Fucecchio - Montecatini Area";
	case "sienasgim":                return "Siena - S.Gimignano Area";
	case "firhillschi":              return "Hills around Florence, Chianti Area";
	case "firhillsmug":              return "Hills around Florence, Mugello Area";
	case "arezzossep":               return "Arezzo - S. Sepolcro Area";
	case "cortona":                  return "Cortona Area";
	case "chianti":                  return "Chianti Area";
	case "livorno":                  return "Livorno Area";
	case "venice":                   return "Venice";
	case "rome":                     return "Rome";
	case "amalfi_coast":             return "Amalfi Coast";
	
	/**********************
	*  THIRD LEVEL: Villa *
	**********************/  
		  
	// Test Villas:
	case "Villa1":                   return "Villa One";
	case "Villa2":                   return "Villa Two";
	case "Villa3":                   return "Villa Three";
	case "Villa4":                   return "Villa Four";
	// Real Villas:
	case "al_casale":                return "Al Casale";	
	case "almi_apt":                 return "Almi Apartment";
	case "ammira_apt":               return "Ammira Apartment";
	case "antico_mulino":            return "Antico Mulino";
	case "attico_pent":              return "Attico Penthouse";
	case "bianco_apt":               return "Bianco Apartment";
	case "campiello_apt":            return "Campiello Apartment";
	case "casa_jutta_grande":        return "Casa Jutta Grande";
	case "casa_jutta_piccola":       return "Casa Jutta Piccola";
	case "casa_miriana_grande":      return "Casa Miriana Grande";
	case "casa_miriana_piccola":     return "Casa Miriana Piccola";
	case "castella_il_vescovo":      return "Castello Il Vescovo";
	case "chiocciola_apt":           return "Chiocciola Apartment";
	case "como_apt":                 return "Como Apartment";
	case "corte_nova_apts":          return "Corte Nova Apartments";
	case "dario_apt":                return "Dario Apartment";
	case "d_epoca":                  return "Villa d'Epoca";
	case "del_rimedio":              return "Villa del Rimedio";
	case "del_teatro":               return "Villa del Teatro";
	case "focaia":                   return "Villa Focaia";
	case "fabbricciano":             return "Villa Fabbricciano";
	case "francesca":                return "Villa Francesca";
	case "giardino":                 return "Villa Giardino";
	case "gli_archi_grande":         return "Gli Archi Grande";
	case "gli_archi_piccolo":        return "Gli Archi Piccolo";
	case "bianco_apt":               return "Bianco Apartment";
	case "il_cortiletto":            return "Il Cortiletto";
	case "il_bovolo_apt":            return "Il Bovolo Apartment";
	case "il_patio":                 return "Il Patio";
	case "il_pozzo":                 return "Il Pozzo";
	case "loggia":                   return "Villa Loggia";
	case "lucca_apt":                return "Lucca Apartment";
	case "maremma":                  return "Maremma Retreat";
	case "maria_apts":               return "Maria Apartments";
	case "mulino_a_vinci":           return "Mulino a Vinci";
	case "nautico_apt":              return "Nautico Apartment";
	case "nobile":                   return "Villa Nobile";
	case "panoramica":               return "Villa Panoramica";
	case "pietrosa":                 return "Villa Pietrosa";
	case "podere":			         return "Podere";
	case "poggiarellino":            return "Poggiarellino";
	case "rectory":					 return "The Rectory";
	case "remer_apt":                return "Remer Apartment";
	case "res_vistacolle":           return "Residenza Vistacolle";
	case "roccapugliese":            return "Roccapugliese";
	case "roseto":                   return "Villa Roseto";
	case "rotonda":                  return "Villa Rotonda";
	case "terrazza":                 return "Villa Terrazza";
	case "san_cassiano_apt":         return "San Cassiano Apartment";
	case "san_marco_apt":            return "San Marco Apartment";
	case "serenita":                 return "Villa Serenita";
	case "trastevere":               return "Trastevere Apartment";
	case "vedute_apts":              return "Vedute Apartments";
	case "veneto":                   return "Villa Veneto";
	case "villa_del_bosco":          return "Villa del Bosco";
	case "vista":                    return "Villa Vista";
	
	/*****************
	*  FAILURE CASE: *
	*****************/ 
	
	// This should NEVER happen; if it does, a Region/Group, Locality, or Villa name
	// entry is missing in the list above. The unfriendly name will appear in the
	// breadcrumb trail preceded by "WARN:"
	
	default:                         return "WARN:" + s;
  }
}

/**************************************************
* getNumberValue(c, val)
*
* Taken from Jaworski.
**************************************************/
function getNumberValue(c,val) {
  // Theoretically the call below is unnecessary since you can't
  // have spaces in cookies, but hey, whatever, that's what he
  // had...
  c=removeBlanks(c);
  // Create array of (Name,Value) pairs:
  var pairs=c.split(";");
  // Iterate through the (Name,Value) pairs
  for(var i=0;i<pairs.length;++i) {
   // Get a single (Name,Value) pair
   var pairSplit=pairs[i].split("=");
   // Does the Name match the one we were passed?
   if(pairSplit[0]==val) {
    // There might not be a value for this name...
    if(pairSplit.length>1) {
	  // ... if there is, return it
	  return pairSplit[1];
    }
    else {
	  // ... or "None" otherwise
	  // MAYBE CHANGE TO return null;
	  return "None";
	}
   }
 }
 // If we didn't find the Name in the list, return 0 as the Value
 return 0;
}

/**************************************************
* removeBlanks(s)
*
* Taken from Jaworski.
**************************************************/
function removeBlanks(s) {
  var temp="";
  for(var i=0;i<s.length;++i) {
   var c=s.charAt(i);
   if(c!=" ") temp += c;
  }
  return temp;
}
