function addToFavorites(paletteid) {
  var url = '/rpc.php';
  var params = 'a=addtofavorites&p=' + paletteid;
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
      Element.update('palette-fav-' + paletteid, transport.responseText + '<br/>');
    },
    onFailure: function(transport) {
      Element.update('palette-fav-' + paletteid, 'error.  sorry.');
    }
  });
}

function removeFromFavorites(userid, paletteid, paletteposition) {
  var url = '/rpc.php';
  var params = 'a=removefromfavorites&u=' + userid + '&p=' + paletteid;
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
//      if (paletteposition == '') {
//        Element.update('palette-fav-' + paletteid, 'removed from favorites! <a href="#" onclick="addToFavorites(' + userid + ',' + paletteid + '); return false;">Oops, add it back to my favorites.</a>');
//      } else {
        Element.update('palette-' + paletteposition, '');
//      }
    },
    onFailure: function(transport) {
      Element.update('palette-fav-' + paletteid, 'error.  sorry.');
    }
  });
}

function toggleImageCookie() {
  var url = '/rpc.php';
  var params = 'a=toggleimagecookie';
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
        // nothing to do
    },
    onFailure: function(transport) {
        // nothing to do
    }
  });
}


function toggleBrightDullCookie() {
  var url = '/rpc.php';
  var params = 'a=togglebrightdullcookie';
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
        // nothing to do
    },
    onFailure: function(transport) {
        // nothing to do
    }
  });
}

function toggleTagsCookie() {
  var url = '/rpc.php';
  var params = 'a=toggletagscookie';
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
        // nothing to do
    },
    onFailure: function(transport) {
        // nothing to do
    }
  });
}


 
function removeFavPrompt(palette_id, i){
  Element.toggle('removefavyesno-'+palette_id);
}


function ratePalette(paletteid, vote) {
  var url = '/rpc.php';
  var params = 'a=ratepalette&p=' + paletteid + '&v=' + vote;
  new Ajax.Request(url, {
    method: 'get',
    parameters: params,
    onSuccess: function(transport) {
       resultarray = eval("("+transport.responseText+")");
       if (resultarray['total_votes'] == 1){
           Element.update('rating'+paletteid, '' + Math.round(resultarray['avg_rating']) + ', ' + resultarray['total_votes'] + ' vote');
       } else {
           Element.update('rating'+paletteid, '' + Math.round(resultarray['avg_rating']) + ', ' + resultarray['total_votes'] + ' votes');
       }
    },
    onFailure: function(transport) {
        Element.update('rating'+paletteid, 'error. please try later')
    }
  });

}


var formbtn;

function validateHunt(){
  var examplemesg = 'Please enter a six character hex color code like: ff0000'
  if (formbtn.value == 'hunt by color code') {
    p = $('p').value;
    if (p.length != 6) {
      alert(examplemesg);
      return false;
    } else {
      var okchars = "0123456789ABCDEFabcdef";
      for(i=0; i<6; i++){
        if (okchars.indexOf(p.substr(i,1)) < 0){
          alert(examplemesg);
          return false;
	}
      }
      return true;
    }
  } else {
    return true;
  }
}




