// set cookie data

function setCookie(cookieName, value)
{
  document.cookie = cookieName + "=" + escape(value)
}




// retrieve cookie data
function getCookie(name)
{
  var CValue="";
  var cook = document.cookie.split(';');
  var nameIs = name + "=";
  for(var i=0; i < cook.length; i++) 
    {
    var spc = cook[i];
    while (spc.charAt(0)==' ') 
 spc = spc.substring(1, spc.length); //delete spaces
    if (spc.indexOf(nameIs) == 0) 
 {
 CValue = spc.substring(nameIs.length, spc.length);
 //alert(CValue);
 return CValue;
 }
    }
  return null;
}


	var awardsdb = new Array()
	var propertiesdb = new Array()
	var banners = new Array()
	var arrayindex = 0
	
	var relative_path = ""
	
	var CurrentProperty = ""
	
	var CurrentMapDivId = getCookie("DMICurrentMapDivId")
	
	
	
	


	// constructs a single banner record
	function construct(name, imgfile, url, title ,height, width)
	{
	   this.name = name  // banner name
	   this.imgfile = imgfile  // image file name
	   this.url = url  // the URL this banner should execute
	   this.title=title  // nice name for banner
	   this.height=height  // image height in pixels
	   this.width=width  // image width in pixels
	   return this
	}

	
	//--------------------------------------------------------------------------
	
	
	function getCurrentMapDivId()
	{
		// if not initialized yet, check if cookie exists
		return CurrentMapDivId
	}
	
	function setCurrentMapDivId(newmapdivid)
	{
		CurrentMapDivId = newmapdivid	
	}
	
	//--------------------------------------------------------------------------
	
	
	// constructs a single awards database record
	function awards_construct(property, shortname, awardgiver, award, dates)
	{
		this.property = property  // long property name
		this.shortname = shortname  // short property directory name
		this.awardgiver = awardgiver  // 
		this.award = award  // actual name of award
		this.dates = dates
		return this
	}



	// constructs a single property database record
	// maparea = Map Area if all other args are null or Country or State
	function properties_construct(maparea, location, caption, URL, bannername1, bannername2)
	{
		// create an div id from the maparea - remove all spaces - no spaces allowed in IDs or CSS names		
		if (URL == "") {
			var tempstr = maparea
			var index = tempstr.indexOf(" ")
			if (index > 0) {
			
				this.div_id = tempstr.substring(0, index) + tempstr.substring(index + 1, tempstr.length);
			}
			else {
				this.div_id = maparea
			}
		}
		else {
			this.div_id = "";
		}
	
		this.maparea = maparea  // State/country or map area if only argument - this is what prints out at the top of the div
		this.location = location  // typically a city
		this.caption = caption  // the active (linked) text displayed next to the book/page icon - if any
		this.URL=URL  // the property specific part of the name for the directory and URLs for this linked item
		this.banner1=bannername1
		this.banner2=bannername2
		return this
	}
	
	
	function addindex()
	{
		arrayindex = arrayindex + 1
		return(arrayindex)
	
	}


	function has_awards(resortnm)
	{
		for (var row = 1; row < awardsdb.length; row++) {
			if (awardsdb[row].shortname == resortnm) {
				if (awardsdb[row].award != "") {
					return(1)
				}
			}
		}
		return(0)
	}
	


	function get_propertiesdb_index(propertyid)
	{
		for (var row = 1; row < propertiesdb.length; row++) {
			if (propertiesdb[row].URL == propertyid) {			
				return(row)
			}
		}
		return(0)
	}
	
	
	
	function get_div_id_index(div_id)
	{
		for (var row = 1; row < propertiesdb.length; row++) {
			if (propertiesdb[row].div_id == div_id) {			
				return(row)
			}
		}
		return(0)
	}
	
	
	function AddBanner(bannernum)
	{
		var Banner1 = ""
		var Banner2 = ""
		var bannername = ""
		var contentstring = '<img src="../../main_images/sngl_pxl_clr.gif" alt="" height="1" width="1" border="0">'
		
		if (CurrentProperty != "") {
			
			var row = get_propertiesdb_index(CurrentProperty)
			if (row) {
									
				Banner1 = propertiesdb[row].banner1
				Banner2 = propertiesdb[row].banner2
   					
   			}

			
		if ((Banner1 != "") && (bannernum == 1)){
			bannername = Banner1
		}
		else if ((Banner2 != "") && (bannernum == 2)){
			bannername = Banner2
		}
		else {
			bannername = ""
		}
		
				
		if (bannername != "") {
			for (var row = 1; row < banners.length; row++) {
				
				if (banners[row].name == bannername) {
					contentstring = ""
					if (banners[row].url != "") {
						contentstring += '<a href="'
						contentstring +=  banners[row].url
						contentstring += '" target="_blank" title="'
						contentstring += banners[row].title
						contentstring += '">'
					}
					contentstring += '<img height="' + banners[row].height
					contentstring += '" width="' + banners[row].width
					contentstring += '" src="../../banners/' + banners[row].imgfile
					contentstring += '" border="0">'
				}
			}			
		}
							
	}

	document.write(contentstring)
}
	
	
	
	function GenerateDivs()
	{
		var contentstring = ""
		var currentcity = ""
		var newcity = 0
		var currentstate = ""
		var newstate = 0
				
		var StartOfMapArea = 0
		
		var relativepath = ""
		
		if (CurrentProperty == "") {
			relativepath = "properties/"
			
		}
		else {
			relativepath =  "../"
		}
		
		
		for (var row = 1; row < propertiesdb.length; row++) {


			if (propertiesdb[row].URL == "") {

				// ========== NEXT GEOGRAPHIC LOCATION?
				// If we've already output a location, close it before starting a new one
				if (StartOfMapArea == 1) {
					// Close out current Map Area Div
					contentstring += '</td></tr></table></div>'	
				}
				
				StartOfMapArea = 1
					
				newcity = 1   // will also be new city
				newstate = 1 // and new state/country
		
								
				contentstring += '<div id="' + propertiesdb[row].div_id + '" valign="top"><table border="0" width="135"><tr width="135"><td width="135">'
				contentstring += '<div align="center" class="PropertyHead">' + propertiesdb[row].maparea + '</div>'	
					
			}	
		
			
			else {
			
				// ========== NEXT PROPERTY
				// ========== NEXT STATE/COUNTRY?
				
				if (propertiesdb[row].maparea != currentstate) {
			 	
					newstate = 0
					
       				contentstring += '<div class="PropertyState" align="left">' + propertiesdb[row].maparea + '</div>'
					currentstate = propertiesdb[row].maparea
			 
			 	}
				 // ========== NEXT CITY
				if (propertiesdb[row].location != currentcity) {
					if (newcity != 1) {
						
					}
				
					newcity = 0
				
       				contentstring += '<div class="PropertySubHead">-' + propertiesdb[row].location + '-<br></div>'	
					currentcity = propertiesdb[row].location
				}
			
				// ========== PROPERTY LINK
			
				
				contentstring += '<div class="PropertyIndent"><A HREF="' + relativepath + propertiesdb[row].URL + '_files/' + propertiesdb[row].URL + '.html" CLASS="PropertySubSubHead">'        
				contentstring += propertiesdb[row].caption + '</A><br></div>'
				
					
		  	}// End Next Property
	   
	   		
		}   // End For
		contentstring += '</td></tr></table></div>'
		document.write(contentstring)
		
		if (CurrentMapDivId != "") {
		
			OpenThisLocation(CurrentMapDivId)
		}
	}
	
	
	
	function HideAll()
	{
		var obj
		
		for (var row = 1; row < propertiesdb.length; row++) {
			if (propertiesdb[row].div_id != "") {			
				obj = document.getElementById(propertiesdb[row].div_id);
				obj.style.visibility = "hidden";
			}
		}
	}



	function ShowOne(loctext)
	{
		var div_id = ""
		
		var index = 0
		
		if (loctext != null) {
		
			index = get_div_id_index(loctext)
		
		
		
			if(document.getElementById)	  //gecko(NN6) + IE 5+
    		{
				var obj = document.getElementById(propertiesdb[index].div_id);
				obj.style.visibility = "visible";
				setCookie("DMICurrentMapDivId", propertiesdb[index].div_id);
   	 		}
   	 	}	
	}
	
	
	function OpenThisLocation(loctext)
	{
		
		HideAll();
		ShowOne(loctext);
	}
	

	function AddMapLink()
	{	
		document.write('<a href="../../properties.html" title="Click here to return to the Map"><img src="../../map_images/North-America_116x116.gif" alt="" border="0" height="116" width="116" hspace="0" vspace="0"></a>');
		
	}
