// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function remove_field(element, item) {
  element.up(item).remove();
}

function go()
{
	box = document.getElementById("brandselect");
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function goExhibition()
{
	box = document.getElementById("exhibitionselect");
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function rate(rating,url,lang) {
	var sUrl = url + '&rating=' + rating;
	
	var loading = (lang=='en') ? 'sending' : 'enviando';
	
	jQuery("div#rating").html('<div id="rating_loading">&nbsp;</div><div class="rating_messages"><h1>' + loading + '...</h1></div>');

	// document.getElementById("rating").innerHTML = '<div id="rating_loading">&nbsp;</div><div class="rating_messages"><h1>sending...</h1></div>';

	jQuery.post(sUrl,function(data){
		jQuery("#rating").html(data);
		new Effect.Fade("thanksfade",{delay: 1.5, duration: 3.0});
	});

	// var args = [rating]; 
	// var responseSuccess = function(o) {
	// 	document.getElementById("rating").innerHTML = o.responseText;
	// };
	// 
	// var responseFailure = function(o){
	// 	document.getElementById("rating").innerHTML = '<div id="rating_loading">&nbsp;</div><div class="rating_messages"><h1>error!</h1></div>';
	// }
	// 
	// var callback =
	// {
	//   success:responseSuccess,
	//   failure:responseFailure,
	//   argument:args
	// };
	// 
	// var showStatus = undefined;
	// 
	// YAHOO.util.Connect.initHeader('Accept-Charset','UTF-8');
	// var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null); 
	
}

function showcaseswitch(container,url,trigger) {
	for (i=1;i<20;i++) {
		if (document.getElementById('showcase' + i)) {
			//document.getElementById('showcase' + i).style.backgroundColor = '#8269DB'; 
			document.getElementById('showcase' + i).className = 'picture_buttons'; 
		}
	}
	//document.getElementById('showcase' + trigger).style.backgroundColor = '#666';
	document.getElementById('showcase' + trigger).className = 'picture_buttons_selected'; 
	document.getElementById(container).style.backgroundImage = "url(" + url + ")";
	startIn = trigger - 1;
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}


function alterInput(oI,oT,vT,nF) {
  if(!oI || !oI.parentNode || (oT.length<4) || 
    !document.getElementById || !document.createElement) return;
  var nE = document.createElement('input');
  nE.className = 'tinytext';
  nE.type = oT;
  if(oI.name) nE.name = oI.name;
  if(oI.id) nE.id = oI.id;
  nE.onfocus = function() {
    if(this.hasFocus) return;
    var nE = alterInput(this,'password',
      (this.value.toLowerCase()=='password')?'':this.value);
    if(nE) nE.hasFocus=true;
  }
  nE.onblur = function() {
    if(this.hasFocus)
    if(this.value=='' || this.value.toLowerCase()=='password') {
      alterInput(this,'text','password',true);
    }
  }
  nE.hasFocus=false;
  oI.parentNode.replaceChild(nE,oI);
  if(vT) nE.value = vT;
  if(!nF || typeof(nF)=='undefined') {
    window.tE = nE;
    setTimeout("tE.hasFocus=true;tE.focus();",1);
  }
  return nE;
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function mapita() {

	if (vallerylanguage == "en") {
  	var WINDOW_HTML = '<div style="font-size: 11px; font-family: Helvetica, Arial; color:#666; width: 210px; padding-right: 10px"><strong>Vallery:</strong><br /><br />We are open <strong>Monday thru Friday</strong> from 16h to 20h<br /><br />Calabria, 85<br />08015 Barcelona<br />Spain</div>';
	} else {
  	var WINDOW_HTML = '<div style="font-size: 11px; font-family: Helvetica, Arial; color:#666; width: 210px; padding-right: 10px"><strong>Vallery:</strong><br /><br />Abrimos de <strong>Lunes a Viernes</strong> de 16h a 20h<br /><br />Calabria, 85<br />08015 Barcelona<br />España</div>';
	}
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(41.378813, 2.156153), 16);
	
	
	var marker = new GMarker(new GLatLng(41.378813, 2.156153));
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(WINDOW_HTML);
	});
	marker.openInfoWindowHtml(WINDOW_HTML);

  }
}