// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

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

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

function switchDisplay(id)
{
	if(document.getElementById(id).style.display=="block")
	{
		document.getElementById(id).style.display="none";
	}
	else
	{
		document.getElementById(id).style.display="block";
	}
	
}

function rate(rating,url) {

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

	var args = [rating]; 
	var responseSuccess = function(o) {
		document.getElementById("rating").innerHTML = o.responseText;
		new Effect.Fade("thanksfade",{delay: 1.5, duration: 3.0});
	};

	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;
	var sUrl = url + rating;
	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 tuesdays thru saturdays from 10 to 14 and 17 to 20<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 martes a s�bado de 10 a 14 y de 17 a 20<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);


	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());


	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);

  }
}

function pqtyMod(amount){
	var qty = (document.getElementById('pqty').value)*1+(amount)*1;
	if(qty < 0)
	{
		qty = 0;
	}
	document.getElementById('pqty').value = qty;
	
}

function changeColor(color){
	document.getElementById('colorBig').style.background = color;
	document.getElementById('colorName').innerHTML = color;
}

function show_picker(ID, Current_Color, Previous_Color){
	
	Current_Color = document.getElementById('color_es_div').style.backgroundColor;
	//Current_Color has something like that: rgb(89, 22, 22)
	Current_Color = Current_Color.replace("(", "");
	Current_Color = Current_Color.replace(")", "");
	Current_Color = Current_Color.replace("rgb", "");
	Current_Color = Current_Color.replace(" ", "");
	var data = new Array();
	data = Current_Color.split(",");
	
	var r = data[0]*1;
	var g = data[1]*1;
	var b = data[2]*1;
	
	Current_Color = DecToHex(r,g,b);
	which_input = ID;
	var lnk = "/color_picker_files/color_picker_interface.html?cur_color="+Current_Color+"&pre_color="+Previous_Color;
	window.open(lnk, "", "width=465, height=350");
}

function fillColorValue(color){
	document.getElementById(which_input).value = "#"+color;
	document.getElementById(which_input+"_div").style.backgroundColor = "#"+color;
}



function GiveDec(Hex)
{
   if(Hex == "A")
      Value = 10;
   else
   if(Hex == "B")
      Value = 11;
   else
   if(Hex == "C")
      Value = 12;
   else
   if(Hex == "D")
      Value = 13;
   else
   if(Hex == "E")
      Value = 14;
   else
   if(Hex == "F")
      Value = 15;
   else
      Value = eval(Hex);

   return Value;
}

function GiveHex(Dec)
{
   if(Dec == 10)
      Value = "A";
   else
   if(Dec == 11)
      Value = "B";
   else
   if(Dec == 12)
      Value = "C";
   else
   if(Dec == 13)
      Value = "D";
   else
   if(Dec == 14)
      Value = "E";
   else
   if(Dec == 15)
      Value = "F";
   else
      Value = "" + Dec;

   return Value;
}

function DecToHex(Red,Green,Blue)
{
   a = GiveHex(Math.floor(Red / 16));
   b = GiveHex(Red % 16);
   c = GiveHex(Math.floor(Green / 16));
   d = GiveHex(Green % 16);
   e = GiveHex(Math.floor(Blue / 16));
   f = GiveHex(Blue % 16);

   z = a + b + c + d + e + f;

   return z;
}

function changePtypes(id)
{
	document.getElementById('ptypes').value = id*1;
}
