//for hottest bartender voting -- hightlights current selection in a radio button group and deselects the other options. Updates on the fly as you change your selection
function highlight(reguser){
var frm=document.forms[0];
for (var i=0;i< frm.elements.length;i++){
node=frm.elements[i].parentNode;
if(frm.elements[i].checked){
node.style.background='red';
}
else{ 
node.style.background='#fff';
}}}

//for displaying a "currently selected" div with votes or shopping cart items
function showSelection(divid,vote){
clearContents(divid);
var curselect = document.createElement('txt');
curselect.setAttribute('name', 'curselect');
curselect.innerHTML = vote;
document.getElementById(divid).appendChild(curselect);

}

//JS to show/hide content on a page
function toggle_display(object) {
var display = document.getElementById(object).style.display;
if (display == 'none') {
	document.getElementById(object).style.display = "";
	} else {
	document.getElementById(object).style.display="none";
	}
	}
	
//function for doing an image swap
function switchLink(imgid, divid,filepath){ 
var imgs = document.getElementById(divid).getElementsByTagName('img').length;
var srcs = document.getElementById(divid).getElementsByTagName('img');
for (var i = 1; i <= imgs; i++){
var c=i-1;
if(i == imgid){
srcs[c].src= filepath + i + "b.gif";
}
else{
srcs[c].src= filepath + i + ".gif";
}}}

function chngLink(divid,content){ 
document.getElementById(divid).innerHTML=content;
}

var msg = '';
var shw = new Array();
function swapLink(cnt,elem,msg1, msg2){
if(!shw[cnt]){
shw[cnt]='0';}
shw[cnt] == "0"?shw[cnt]='1':shw[cnt]='0';
msg = shw[cnt]=="0"?msg1:msg2;
document.getElementById(elem).innerHTML=msg;
}



//function for making an ajax request
 var http_request = false;
   function makeAjaxRequest(method, tf, url, divid, parameters, loader) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } 
      
      else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      } //end of if
      
      http_request.onreadystatechange = function(){
      alertContents(divid,loader);
      }//end of function
      
      if (method == 'GET'){
      http_request.open('GET', url, true);
      http_request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
  	  http_request.send(null);
      }//end of if
      else if (method == 'POST'){
   	  http_request.open('POST', url, tf);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
     
     }//end of if

   }//end of function


   function alertContents(divid, loader) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText); 
            pageTracker._trackPageview("/ajaxpage/"+divid);
            var result = http_request.responseText; 
          document.getElementById(loader).style.display="none";
            document.getElementById(divid).innerHTML = result;  
            var obj = document.getElementById(divid).getElementsByTagName("script");
            var num = obj.length;
            for(i=0;i<num;i++){
           // alert(obj[i].innerHTML);
          
          eval(obj[i].innerHTML);
            }
         
		   document.getElementById(divid).style.display="";        
         } else {
            alert('There was a problem with the request.');
         }//ends else
      }//ends = 4
   }//ends function
  
   
   	function ajaxForm(formName, method, tf, url, divid,loader) { 
 document.getElementById(loader).style.display="block";
   if (method == 'POST'){
   		var parameters = '';
        var formElem;
        var strLastElemName = '';
     	for (i = 0; i < document[formName].elements.length; i++) {
     
         formElem = document[formName].elements[i];
          switch (formElem.type) {
        
                        // Text, select, hidden, password, textarea elements, submit
                        case 'text':
                        case 'select-one':
                        case 'hidden':
                        case 'password':
                        case 'textarea':
                        parameters += formElem.name + 
                                '=' + escape(formElem.value) + '&'
                             
                        break;
                        case 'select-multiple':
                        var myArray = new Array();
                          for(var x=0; x < formElem.length; x++) {
                          if(formElem[x].selected == true){
                           parameters += formElem.name +
                           '=' +formElem[x].value + '&';
                           }
                          }
                        break;
                        case 'checkbox':
                             parameters += formElem.name +
                             '=' + formElem.checked + '&'
                             
                        break;
                        case 'radio':
                          if(formElem.checked){
                              parameters += formElem.name +
                             '=' + formElem.value + '&'
                             }
                        break;
                        }
                   
        }//ends for loop
  
   }//ends if loop 
makeAjaxRequest(method, tf, url, divid, parameters,loader);
   }//end of function
                
   
   
   function get(url, divid,loader){
   document.getElementById(loader).style.display="block";
   makeAjaxRequest('GET','true', url, divid,'',loader);
   }
   
 
   //parameters are query -- the item you're searching for in the dbase
   //divid -- the div where the results are going to go
   
   //url -- the url of the file that has the actual mysql search query
   //method -- whether it is POST (from a form) or GET (query appended to URL)
   //loader -- the div where the little status wheel appears while the search is conducted
	function ajaxSearch(query, divid, url, method,loader) {
	if (query.length >= 2)
	{ var url=url + query;
	document.getElementById(loader).style.display="";
	var result = makeAjaxRequest(method, 'true', url, divid,'',loader);
	document.getElementById(divid).style.display = '';
	}
	if (query.length == 0)
	{ document.getElementById(divid).style.display = 'none';
	  document.getElementById(divid).innerHTML ='';
	}
	}   
   
   	function clearContents(divid){
  	document.getElementById(divid).innerHTML = ''; 
   	}
   	
   	function setContents(divid, data){
  	document.getElementById(divid).innerHTML = data; 
   	}
	function hideDiv(divid){
	document.getElementById(divid).style.display= 'none';
	}
	function showDiv(divid){
	document.getElementById(divid).style.display='';
	}
	function clearValue(divid){
  	document.getElementById(divid).value = ''; 
   	}
   	
  	function makeSelection(divid, selection, divid2, selection2) {
	document.getElementById(divid).value = selection;
	document.getElementById(divid2).value = selection2;
	}
	
	function inputSelection(divid, divid2) {
	var x = document.getElementById(divid).value;
	document.getElementById(divid2).value = x;
	}
	
	function makeFocus(divid){
	document.getElementById(divid).focus(); 
	}
	
	function loadMap() {
        if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(glat,glng), 15);
       map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
      map.addOverlay(new GMarker(new GLatLng(glat, glng)));   
      }
    }
 	function loadMap2() {
        if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(gid));
      map.setCenter(new GLatLng(glat,glng), 15);
       map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
      map.addOverlay(new GMarker(new GLatLng(glat, glng)));   
      }
    }   

// This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }

    
function loadScript(lng,lat) {
glng=lng;
glat=lat;
 var script = document.createElement("script");
      script.setAttribute("src", "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAArB64qs0tdGt0nCvvZbtqMRRZ3D1n6dGcuW8_niz5lTAwFC77ThQEDRXSGPTCG5LTki-jeEMWS0X9tw&async=2&callback=loadMap");
      script.setAttribute("type", "text/javascript");
      script.setAttribute("defer","defer");
      $(document).append(script); 
    }
    
function loadScript2(lng,lat,id) {
glng=lng;
glat=lat;
gid=id;
 var script = document.createElement("script");
      script.setAttribute("src", "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAArB64qs0tdGt0nCvvZbtqMRRZ3D1n6dGcuW8_niz5lTAwFC77ThQEDRXSGPTCG5LTki-jeEMWS0X9tw&async=2&callback=loadMap2");
      script.setAttribute("type", "text/javascript");
      script.setAttribute("defer","defer");
      $(document).append(script);
    
    } 

