// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//create the ToolTip overlay object
function ToolTip(marker,html,width) {
this.html_ = html;
this.width_ = (width ? width + 'px' : 'auto');
this.marker_ = marker;
}
ToolTip.prototype = new GOverlay();
ToolTip.prototype.initialize = function(map) {
var div = document.createElement("div");
div.style.display = 'none';
map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
this.map_ = map;
this.container_ = div;
}
ToolTip.prototype.remove = function() {
this.container_.parentNode.removeChild(this.container_);
}
ToolTip.prototype.copy = function() {
return new ToolTip(this.html_);
}
ToolTip.prototype.redraw = function(force) {
if (!force) return;
var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
this.container_.innerHTML = this.html_;
this.container_.style.position = 'absolute';
this.container_.style.left = pixelLocation.x+10 + "px";
this.container_.style.top = pixelLocation.y-30 + "px";
this.container_.style.width = this.width_;
this.container_.style.font = 'bold 10px/10px verdana, arial, sans';
this.container_.style.border = '1px solid black';
this.container_.style.background = 'yellow';
this.container_.style.padding = '4px';
//one line to desired width
this.container_.style.whiteSpace = 'nowrap';
if(this.width_ != 'auto') this.container_.style.overflow = 'hidden';
this.container_.style.display = 'block';
}
GMarker.prototype.ToolTipInstance = null;
GMarker.prototype.openToolTip = function(content) {
//don't show the tool tip if there is a custom info window
if(this.ToolTipInstance == null) {
this.ToolTipInstance = new ToolTip(this,content)
map.addOverlay(this.ToolTipInstance);
}
}
GMarker.prototype.closeToolTip = function() {
if(this.ToolTipInstance != null) {
map.removeOverlay(this.ToolTipInstance);
this.ToolTipInstance = null;
}
}


///////////
function updateMapOnClick(myMap){
		//alert(myMap);
}
function inspect(obj, maxLevels, level)
{
  var str = '', type, msg;

    // Start Input Validations
    // Don't touch, we start iterating at level zero
    if(level == null)  level = 0;

    // At least you want to show the first level
    if(maxLevels == null) maxLevels = 1;
    if(maxLevels < 1)     
        return '<font color="red">Error: Levels number must be > 0</font>';

    // We start with a non null object
    if(obj == null)
    return '<font color="red">Error: Object <b>NULL</b></font>';
    // End Input Validations

    // Each Iteration must be indented
    str += '<ul>';

    // Start iterations for all objects in obj
    for(property in obj)
    {
      try
      {
          // Show "property" and "type property"
          type =  typeof(obj[property]);
          str += '<li>(' + type + ') ' + property + 
                 ( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';

          // We keep iterating if this property is an Object, non null
          // and we are inside the required number of levels
          if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
          str += inspect(obj[property], maxLevels, level+1);
      }
      catch(err)
      {
        // Is there some properties in obj we can't access? Print it red.
        if(typeof(err) == 'string') msg = err;
        else if(err.message)        msg = err.message;
        else if(err.description)    msg = err.description;
        else                        msg = 'Unknown';

        str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
      }
    }

      // Close indent
      str += '</ul>';

    return str;
}

/////maps
    function clickStoreLocation(overlay, point){  
      if (point) {  
        var px = point.x;  
        var py = point.y;  
        $('place_lng').setValue( px);  
        $('place_lat').setValue( py);  
         
   
       my_marker.setLatLng(new GLatLng(py, px));  
     }     
   }    
     
  
   function updateStoreLocation(){
     var latlng = marker.getLatLng().toUrlValue();  
     var tmp = latlng.split(',');  
     var px = tmp[1];  
     var py = tmp[0];  
     $('place_lng').setValue( px);  
     $('place_lat').setValue( py);  
   } 
   
function gmap_update_position(){
alert("ah");}   

function clearSearch(){
	if($('searhfield').value=='Keyword, Club, Restaurant, Area...'){
		$('searhfield').setValue('');	
	}
}

function setSearch(){
	if($('searhfield').value==''){
		$('searhfield').setValue('Keyword, Club, Restaurant, Area...');	
	}
}

function checkChanged(){
	if($('searhfield').value=='Keyword, Club, Restaurant, Area...'){
		alert("Enter a Keyword to Search ");
		return false;
	}
	else{
		return true;
	}
}
function clearLogin(){
	if($('login').value=='email'){
		$('login').setValue('');	
	}
}
function setLogin(){
	if($('login').value==''){
		$('login').setValue('email');	
	}
}

function hideDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideshow').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideshow.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.hideshow.style.visibility = 'hidden'; 
} 
} 
}
 
function showDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideshow').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideshow.visibility = 'visible'; 
} 
else { // IE 4 
document.all.hideshow.style.visibility = 'visible'; 
} 
} 
}


function clearSUEmail(){
	if($('user_email').value=='email'){
		$('user_email').setValue('');	
	}
}

function setSUEmail(){
	if($('user_email').value==''){
		$('user_email').setValue('email');	
	}
}
function setSUPassword(){
	if($('user_password').value==''){
		$('user_password').setValue('password');	
		$('user_password').type = 'text';
	}
}
function clearSUPassword(){
	if($('user_password').value=='password'){
		$('user_password').setValue('');	
		$('user_password').type = 'password';
	}
}


function clearSUNick(){
	if($('user_nickname').value=='nickname'){
		$('user_nickname').setValue('');	
	}
}

function setSUNick(){
	if($('user_nickname').value==''){
		$('user_nickname').setValue('nickname');	
	}
}
function setSUConfirmPassword(){
	if($('user_password_confirmation').value==''){
		$('user_password_confirmation').setValue('confirm password');	
		$('user_password_confirmation').type = 'text';
	}
}
function clearSUConfirmPassword(){
	if($('user_password_confirmation').value=='confirm password'){
		$('user_password_confirmation').setValue('');	
		$('user_password_confirmation').type = 'password';
	}
}

function setPassword(){
	
	if($('password').value==''){
		$('password').hide();
		$('password_field').hide();

		$('password_dummy').show()
		$('password_dummy_field').show()
	}

}

function clearPassword(){
	$('password_dummy').hide();
	$('password_dummy_field').hide();
	

	$('password').show();
	$('password_field').show();

	$('password').focus();
}

var bar_login = 0;
var bar_signup = 0;
var first_time = 0;
function showLoginBar(id){

	if (first_time == 0) {
		$('password').hide();
		$('password_field').hide();
		first_time = 1;
	}		
	if(id=='0'){
		if (bar_login == 0) {
			if (bar_signup == 0) {
				Effect.toggle('loginfields', 'blind');
				bar_login = 1;
			}
			else{
				Effect.toggle('signupfields','blind');
				Effect.toggle('loginfields', 'blind');
				bar_login = 1;
				bar_signup = 0;
			}	
		}	
		else{
			Effect.toggle('loginfields', 'blind');
			bar_login = 0;
		}
	}
	else{
		if (bar_signup == 0) {
			if (bar_login == 0) {
				Effect.toggle('signupfields','blind');
				bar_signup = 1;
			}
			else{
				Effect.toggle('loginfields', 'blind');
				Effect.toggle('signupfields','blind')				;
				bar_login = 0;
				bar_signup = 1;
			}	
		}	
		else{
			Effect.toggle('signupfields','blind');
			bar_signup = 0;
		}
	}
}

function addReviewPopup(text){
	Modalbox.show(text, {title: this.title, width: 500, height: 180});
}

function forgotPasswordPopup(){
	Modalbox.show('<div class=\'warning\'>'+
	'<h3>Check Your Email</h3>'+
	'<p>A password reset link has been sent to your email address. Click on the link in your email to reset your password. </p></div>', {title: this.title, width: 500, height: 100});
}
function signinPopup(text){
	Modalbox.show(text, {title: this.title, width: 500, height: 180});
}

function escapeString(s) {
var eChars = ["\\", "'", '"'];
var lasti = eChars.length;
for (var i = 0; i < lasti; i++) {
var sArray = s.split(eChars[i]);
var lastj = sArray.length;
s = '';
for (var j = 0; j < lastj; j++) {
s += sArray[j] + '\\' + eChars[i];
}
}
var last = s.length - 2*eChars.length;
return s.substring(0, last);
}

