// when the window loads things will be better
window.onload = function(){
		//gmap shtuff
		if(gmap_x) {
		loadMap(gmap_x, gmap_y,15);
		}
		
		/*  need to marry this + ratings so they work together.  NOT IT!
		if(document.getElementById('r1')){
			flowerHolder = new Array();
			flowerOriginal = new Array();
			flowerHolder[0] = document.getElementById('r1');
			flowerHolder[1] = document.getElementById('r2');
			flowerHolder[2] = document.getElementById('r3');
			flowerHolder[3] = document.getElementById('r4');
			flowerHolder[4] = document.getElementById('r5');
			
			flowerOriginal = checker(flowerHolder)
			
			for(i=0;i<flowerHolder.length;i++){
				flowerHolder[i].addEventListener('mouseover', function(){change(this.id)}, true);
				flowerHolder[i].addEventListener('click', function(){click(this.id)}, true);
			}
			document.getElementById('bus_reviews').addEventListener('mouseout', changeBack, true);
		}
		*/

	}
	var flowerFull = new Image();
	var flowerNone = new Image();
	flowerFull.src = 'images/flower_color.gif';
	flowerNone.src = 'images/flower_none.gif';
	function change(current){
		current = parseInt(current.substr(1))
		for(i=0;i<current;i++){
			flowerHolder[i].src = flowerFull.src;
		}
		for(i=current;i<flowerHolder.length;i++){
			flowerHolder[i].src = flowerNone.src;
		}
	}
	function changeBack(){
		for(i=0;i<flowerHolder.length;i++){
			if(flowerOriginal[i]){
				flowerHolder[i].src = flowerFull.src
			}
			else
				flowerHolder[i].src = flowerNone.src
		}
	}
	function click(number){
		flowerOriginal = checker(flowerHolder);
	}
	function checker(theArray){
		var holder = new Array();
		for(i=0;i<theArray.length;i++){
			if(theArray[i].src == flowerFull.src){
				holder[i] = true;
			}
			else
				holder[i] = false;
		}
		return holder;
	}
// http://snippets.dzone.com/posts/show/2630
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }




// this function controls everything the menu buttons do
 // initialize a section as the default
	var oldtab = "about";
function viewtab(tab) {
  // populate the tabs and buttons with the new values
	var cur_tab = document.getElementById("tab_"+tab);
	var old_tab = document.getElementById("tab_"+oldtab);
	var cur_btn = document.getElementById("btn_"+tab);
	var old_btn = document.getElementById("btn_"+oldtab);

  // hide the old tab and undo old button from being current
	old_tab.className = old_tab.className+" hide";
	RemoveClassName(old_tab,'show');
	RemoveClassName(old_tab,'current_tab');
	RemoveClassName(old_btn,'current_btn');

  // unhide the new tab and set its button to current
	cur_tab.className = cur_tab.className+" show current_tab";
	cur_btn.className = "current_btn";
	RemoveClassName(cur_tab,'hide');

  // set the new tab as the old one for the next round
	oldtab = tab;
}



// stuff for google map
    function loadMap(x_c,y_c,zoom) {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("bus_map"));
        var point = new GLatLng(x_c, y_c);

        map.setCenter(point, zoom);
        map.addControl(new GSmallMapControl());
        map.addOverlay(new GMarker(point));
      }
    }



function shower(c, t){
	hour_day=c.name+'s'
	hour_open = hour_day+'_o';
	hour_close = hour_day+'_c';
	min_open = hour_open.replace('hours','min');
	min_close = hour_close.replace('hours','min');	
	document.getElementById(hour_day+'_c').disabled = t;
	document.getElementById(hour_day+'_o').disabled = t;
	document.getElementById(hour_close.replace('hours','min')).disabled = t;
	document.getElementById(hour_open.replace('hours','min')).disabled = t;
	document.getElementById(hour_close.replace('hours','m')).disabled = t;
	document.getElementById(hour_open.replace('hours','m')).disabled = t;
}


	
function PopupPic(sPicURL) {
     window.open( "/picview.php?"+sPicURL, "",  
     "resizable=1,HEIGHT=200,WIDTH=200");
}

function busPopup(sPicURL) {
     window.open( "/bus_popup.php?"+sPicURL, "",  
     "resizable=1,HEIGHT=600,WIDTH=420");
}

	var resizemaybe = true;

function hdnResize(theImage,maxHeight,maxWidth) {

if(resizemaybe) {

	var theThing= document.getElementById(theImage);

    if(theThing.width < maxWidth && theThing.height < maxHeight) {

        theThing.width = maxWidth;

    }

    if(theThing.height >= theThing.width && theThing.height > maxHeight) {

        theThing.height = maxHeight;

       theThing.removeAttribute('width');

    }

    if(theThing.height < theThing.width && theThing.width > maxWidth) {

        theThing.width = maxWidth;

       theThing.removeAttribute('height');

    }

}

}

// stuff for the ratings ajax stuff
var ratingurl = "/includes/rating_ajax.php?"; // the server-side script
function createRating(who,what,which) {     
	http.open("GET", ratingurl + "rating_user_id=" + escape(who) + "&rating_bus_id=" + escape(what) + "&rating=" + escape(which), true); // lets send that stuff off
	http.onreadystatechange = handleHttpResponse; // ready state change? see if we're complete and retrieve the results
	http.send(null); // send the request
	document.getElementById('sub_rating').className = "";
//	document.getElementById('add_bizmark').innerHTML = "Bizmark Added!";
//	alert("Rating submitted.");



}


function handleHttpResponse() {  // this function checks to see if the http request is complete and then spits out the results 
	if (http.readyState == 4) {
		if(http.status==200) {
			var results=http.responseText;
			document.getElementById('review_flowers').innerHTML = results;
		}
	}
} 

/*
// leaving this here for a bit
var ratingurl = "/includes/rating_submit.php?"; // The server-side script
function createRating(who,what,which) {     
	http.open("GET", ratingurl + "rating_user_id=" + escape(who) + "&rating_bus_id=" + escape(what) + "&rating=" + escape(which), true);
	http.send(null);
	document.getElementById('sub_rating').className = "";
//	document.getElementById('add_bizmark').innerHTML = "Bizmark Added!";
//	alert("Rating submitted.");
}
*/

// stuff for the bizmarks ajax stuff
var url = "/user/bizmark.php?"; // The server-side script
function createBizmark(who,what) {     
	http.open("GET", url + "fav_user_id=" + escape(who) + "&fav_bus_id=" + escape(what), true);
	http.send(null);
	document.getElementById('add_bizmark').innerHTML = "Bizmark Added!";
	alert("Bizmark Added!\nVisit the user menu for quick access to all your favorite businesses.");
}
function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
   
}
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object

// end of bizmarks ajax stuff

function claimBusiness(thatThing) {
	var answer = confirm("You are about to send an e-mail to a KanConnect representative.\nContinue ONLY if you are the owner of this business and you wish to claim it on KanConnect.net.");
	if(answer){
		window.location = "/includes/bus_proc.php?bus_id="+thatThing;
	}
}

function removeUserItem(itemType,itemId,itemName) {
	var answer = confirm("Delete "+itemType+" for "+itemName+"?");
	if (answer){
		alert(itemName+" "+itemType+" removed!");
		window.location = "/user/item_remove.php?item_type="+itemType+"&item_id="+itemId;
	}
	else{
		alert(itemType+" deletion canceled.");
	}
}
	
// Super Rating System Stuff
	


// End Super Rating System Stuff



/* back up this before i fudge with it
// stuff for the menu buttons
	var oldtab = "about";
function viewtab_backup(tab) {
	var cur_tab = document.getElementById("tab_"+tab);
	var old_tab = document.getElementById("tab_"+oldtab);
	var cur_btn = document.getElementById("btn_"+tab);
	var old_btn = document.getElementById("btn_"+oldtab);
	var cur_img = tab+".gif";
	var old_img = oldtab+".gif";

	old_tab.className = old_tab.className+" hide";
	old_btn.className = "hide";
	RemoveClassName(old_tab,'show');
	RemoveClassName(old_tab,'current_tab');
	
	old_btn.style.backgroundImage = "url('images/buttons/"+old_img+"')";
	cur_btn.style.backgroundImage = "url('images/buttons/"+cur_img+"')";

	cur_tab.className = cur_tab.className+" show current_tab";
	cur_btn.className = "current_btn";
	RemoveClassName(cur_tab,'hide');

	oldtab = tab;
}
*/