
function currentPage()
{
	if(document.URL=="http://www.brianbutlerblues.com/"){page="index";}
	else{
	var url = document.URL;
	var dot = url.lastIndexOf(".");
	var slash = url.lastIndexOf("/") + 1;
	var page = url.substring(slash,dot);
	}
	document.getElementById(page).style.color="blue"
}

function saveParm(string)
{
	parm = string;
}

var map = null;
    var geocoder = null;

function load() 
{
      if (GBrowserIsCompatible()) 
	  {
        map = new GMap2(document.getElementById("map"));
        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        geocoder = new GClientGeocoder();
      }
	else
	{
		alert("no way");
	}
}

    function showAddress(address) 
	{
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
       		  //map = new GMap2(document.getElementById("map"));     			  		
			  //var winRef = window.open('test.html','myWin','width=400,height=200')
			  //map = new GMap2(document.getElementById("map"));			
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
				//winRef.close();
            }
          }
        );
      }
    }



function hello(msg)
{ 	alert("hello there: " + msg);  }


// Used on wait.html & restless.html for displaying lyrics
function fetchData(url, dataToSend, objectID)
{
	var req = false;
 	if (typeof XMLHttpRequest != "undefined") 
    {
       req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
       req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else return false;
    req.onreadystatechange = function() 
    {
      if(req.readyState==4)
      {
         if(req.status==200)
		 {
				var t = document.createElement('INPUT')
				var tid = "temp"
				t.setAttribute('id', tid)
				mytype = 'text'
				t.setAttribute('type', mytype)
				document.getElementById('rightlyric').appendChild(t)	
				document.getElementById("lyricBox").innerHTML = req.responseText + "<a href='#top' onClick='clearLyrics()'>Top of page</a><p>&nbsp;</p>";				
				document.getElementById('temp').focus();			
				document.getElementById('rightlyric').removeChild(t)
		 }
		 else if (req.status==400)
		 {
			document.getElementById("right").innerHTML = "there is a problem";
		 }
		 }
	}
	
//	if(dataToSend)
//	{
//		alert("dataToSend");
//		var data = "data=" + dataToSend;
//		req.open('POST', url, true);
//		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//		req.send(data);
//	}
//	else
//	{
		//alert("get");
		req.open('GET', url, true);
		req.send(null);
//	}
}

//////////////////////////////////////////


// Used on wait.html & restless.html for displaying lyrics
function fetchReview(url, dataToSend, objectID)
{
	var req = false;
 	if (typeof XMLHttpRequest != "undefined") 
    {
       req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
       req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else return false;
    req.onreadystatechange = function() 
    {
      if(req.readyState==4)
      {
         if(req.status==200)
		 {
				var t = document.createElement('INPUT')
				var tid = "temp"
				t.setAttribute('id', tid)
				mytype = 'text'
				t.setAttribute('type', mytype)
				document.getElementById('position').appendChild(t)						
				document.getElementById('temp').focus();	
				document.getElementById("review").innerHTML = req.responseText + "<a href='#top' onClick='clearLyrics()'>Top of page</a><p>&nbsp;</p>";				
				//document.getElementById("lyricBox").innerHTML = (document.getElementById("lyricBox").childNodes[0].nextSibling); 
				
				document.getElementById('position').removeChild(t)
			}
			else if (req.status==400)
			{
				document.getElementById("right").innerHTML = "there is a problem";
			}
		}
	}
	
//	if(dataToSend)
//	{
//		alert("dataToSend");
//		var data = "data=" + dataToSend;
//		req.open('POST', url, true);
//		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//		req.send(data);
//	}
//	else
//	{
		//alert("get");
		req.open('GET', url, true);
		req.send(null);
//	}
}


var req = null;
	var url = null;
	var link;

    function makeRequest() 
	{
		url="cal.xml";
	
   if (typeof XMLHttpRequest != "undefined") 
   {
       req = new XMLHttpRequest();
   } 
   else if (window.ActiveXObject) 
   {
       req = new ActiveXObject("Microsoft.XMLHTTP");
   }

        if (!req) 
		{
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		
        req.onreadystatechange = process; 
       	req.open('GET', url, true);
        req.send(null);	
    }

    function process() 
	{
        if (req.readyState == 4) 
		{
			//{
			  // alert("File was last modified on - "+
			    //req.getResponseHeader("Last-Modified"))
			//}
			
            if (req.status == 200) 
			{
				var loc;
				var xmldoc = req.responseXML;
            	var root = xmldoc.getElementsByTagName('gig');
				var gignum = root.length;
				var container;
				var theData ;
				var tmp;
				var newEl;
				var row;
				var myDiv;
				
				newEl = document.createElement('TABLE');
				newEl.setAttribute('cellPadding',5);
				newEl.setAttribute('border',2);
				//newEl.setAttribute('borderColor',#6499c5);
				newEl.setAttribute('bgcolor','FFFFFF');
				tmp = document.createElement('TBODY');
				newEl.appendChild(tmp);				
				row = document.createElement('TR');

				// get the table headers //////////////////////////////////////////////////
				for(h = 0; h < root[0].childNodes.length; h++)
				{
					if(root[0].childNodes[h].nodeType != 1) continue;
					container = document.createElement('TH');
					container.setAttribute('class', 'gigtable');
					theData = document.createTextNode(root[0].childNodes[h].nodeName);
					container.appendChild(theData);
					row.appendChild(container);
				}
				
				tmp.appendChild(row);
				
				// get the data ////////////////////////////////////////////////////////////
				for(i = 0; i < gignum; i++)
				{
					row = document.createElement('TR');
					
					// the directions column may have a link to a directions html page
					
					for(j=0; j < root[i].childNodes.length; j++)
					{
						if(root[i].childNodes[j].nodeName == "directions")
						{
							if(root[i].childNodes[j].nodeType != 1) continue;
							myDiv = document.createElement("div");
							myDiv.setAttribute('class', 'gigtable');
							link = root[i].childNodes[j].firstChild.nodeValue;
							
							if((link != "t.b.d.") && (null != link.match("http")))
							{
								if(root[i].childNodes[j].nodeType != 1) continue;
								myDiv.innerHTML = "<a href=" + link + ">link</a>";
							}
							else
							{
								if(root[i].childNodes[j].nodeType != 1) continue;
								myDiv.innerHTML = link;
							}
							container = document.createElement('TD');
							container.appendChild(myDiv);
						}
						else
						{
							if(root[i].childNodes[j].nodeType != 1) continue;
							
							newDiv = document.createElement('div');
							newDiv.setAttribute('class', 'gigtable');
							newDiv.innerHTML = root[i].childNodes[j].firstChild.nodeValue;
							//theData = document.createTextNode(root[i].childNodes[j].firstChild.nodeValue);
							container = document.createElement('TD');
							//contain.setAttribute('class', 'topalign');
							container.appendChild(newDiv);
						}
						
						//container.appendChild(theData);
						row.appendChild(container);
					}
					tmp.appendChild(row);
				}
				document.getElementById('gigTable').appendChild(newEl);
            } 
			else 
			{
                alert('There was a problem with the request.');
            }
        }
    }







// slide show of album covers
		var timeout_id = null;
		var num_loaded_images = 0;
		function countImages()
		{
			if (++num_loaded_images == 4) rotatePics();
		}

		var images = new Array(4);
		for (var i = 0; i < images.length; i++)
		{
			images[i] = new Image();
			images[i].onload = countImages;
			images[i].src = "images/cd/" + i + ".jpg";
		}
		
		var labels = new Array(4);

			labels[0] = "Restless Street";
			labels[1] = "Seattle's Best Blues #1";
			labels[2] = "Seattle Folklore Society - Musical Doorways";			
			labels[3] = "Seattle's Best Blues #2";

		var frame = 0;
		var counter = 0;
		function rotatePics()
		{
			//alert(frame + " " + counter);
			//document.rotate.src=images[frame].src;
			//document.slideshow.label.value=labels[frame];
			frame++;
			counter++;
			if (frame==images.length)
			{
				frame=0;
				//counter--;
			}
			if (counter < 8 )  //rotate twice through the CD covers
			{
				timeout_id = setTimeout("rotatePics()", 2000);
			} 
			else 
			{
				//alert("frame: " + frame + "/ counter: " + counter);
				//document.rotate.src=images[0].src;
				//document.slideshow.label.value=labels[0];
			}
		}

		function rotateCDPicsAgain()
		{
			frame=1;
			counter=4;
			rotatePics();
		}


///////////////////////////////////////
// the main page pics

//	function rotateMainPics()
//	{
//		var photos = new Array("sun_banks.jpg",
//							   "tumbleweed.jpg",
//							   "acoustic.gif",
//							   "band_gasworks.gif",
//							   "butler_rocking_sm.jpg",
//							   "doc_maynards_sm.jpg",
//							   "pigalle_sm.jpg",
//							   "with_elvin_sm.jpg");
//		var photoText = new Array("2006 at the Sun Banks Blues Festival. Grand Coulee dam country.","2006 Tumbleweed Festival in Richland, WA on the banks of the mighty Columbia River.", 
//								  "Brian at Marymoor Heritage Festival around 1980",
//								  "Brian Butler Blues Band 1980(left to right): Mark Dalton, Larry Harris, Kim Field, Brian Butler",
//								  "Heavy rocking tonight! Somewhere in the 80's",
//								  "At Doc Maynards, Pioneer Square, 1980's",
////								  "Late 70's at the Place Pigalle in the Pike Place Market",
//								  "Everett show with Elvin Bishop, 1980's");
//								
//		var num = Math.round(Math.random()*7);
//		currentImage = new Image();
//		currentImage.src="images/" + photos[num];
//		document.rotatePics.src=currentImage.src;
//		document.mainPhoto.rotatePicsText.value=photoText[num];
//	}


	// open a new window, pass in the text and the pic to be displayed
	function newWindow(title,pic)
	{
		var screenHeight = screen.height;
		var screenWidth = screen.width;
		var myWindowHeight = 550;
		var myWindowWidth = 550;	
		var vertical = screenHeight/2-myWindowHeight/2;
		var horizontal = screenWidth/2-myWindowWidth/2;	
		
		var myWin=window.open ('','newWin','width='+myWindowHeight+',height='+myWindowHeight+',top='+vertical+',left='+horizontal )
		myWin.document.write('<html><body><h3>'+title+'</h3>');
		myWin.document.write('<img src='+pic+'><p><input type="button" value="Close" onClick="javascript:self.close()"></body></html>');
	}

	function newMapWindow(pt1,pt2)
	{
//		alert(pt1);
		var screenHeight = screen.height;
		var screenWidth = screen.width;
		var myWindowHeight = 550;
		var myWindowWidth = 550;	
		var vertical = screenHeight/2-myWindowHeight/2;
		var horizontal = screenWidth/2-myWindowWidth/2;	
		
		var myWin=window.open ('maps/test.html','newWin','width='+myWindowHeight+',height='+myWindowHeight+',top='+vertical+',left='+horizontal )
		myWin.document.write('<html><body><h3>hey</h3>');
		myWin.document.write(pt1 + " " + pt2);
//		myWin.document.write('<img src='+pic+'><p><input type="button" value="Close" onClick="javascript:self.close()"></body></html>');
	}

	function myFunc()
{
	alert("hey you");
}

function clearLyrics()
{
	document.getElementById("lyricBox").innerHTML = "";
}

// using this for video
function newwindow(url)
{
	window.open(url,'jav','width=450,height=500,left=100,top=100,screenX=100,screenY=100,resizable=yes');
}

function newMapWindow(url)
{
	window.open(url,'jav','width=600,height=400,left=100,top=100,screenX=100,screenY=100,resizable=yes');
}
