function terms_of_sale_popup(){
	window.open('/page/terms_of_sale_popup','TermsOfSaleWindow','width=350,height=400,scrollbars=yes,status=yes,resizable=yes');
}

function tos_popup(){
  window.open('/page/tos_popup','TOSwindow','width=350,height=400,scrollbars=yes,status=yes,resizable=yes');
}
function artist_name_popup(){
  window.open('/page/artist_name_popup','ArtistNamewindow','width=350,height=300,scrollbars=yes,status=yes,resizable=yes');
}
function sub_popup(){
  window.open('/page/sub_popup','SubInfowindow','width=400,height=400,scrollbars=yes,status=yes,resizable=yes');
}

function cityOrZip(value){
  if(value == null || value == ''){
    $('postal_option').hide();
    $('city_option').hide();
  }
  else if(value == 204 || value == 35){
    $('postal_option').show();
    $('city_option').hide();
  }
  else{
    $('postal_option').hide();
    $('city_option').show();
  }
}

function verifyCountry(id){
  if(id == 204 || id == null || id == ''){
    document.getElementsByClassName('us_option').each(function(s){ s.enable(); });
    document.getElementsByClassName('international_option').each(function(s){ s.disable(); });
    $('us_options').show();
    $('international_options').hide();    
  }
  else{
    $('us_options').hide();
    document.getElementsByClassName('us_option').each(function(s){ s.disable(); });
    document.getElementsByClassName('international_option').each(function(s){ s.enable(); });
    $('international_options').show();
  }
}

function verifyCountry2(id){
  if(id == 204){
    document.getElementsByClassName('postal_code_option').each(function(s){ s.enable(); });
    document.getElementsByClassName('city_option').each(function(s){ s.disable(); });
    $('postal_code_option').show();
    $('city_option').hide();
  }else if(id == null || id == ''){
    document.getElementsByClassName('postal_code_option').each(function(s){ s.enable(); });
    document.getElementsByClassName('city_option').each(function(s){ s.disable(); });
    $('postal_code_option').show();
    $('city_option').hide();
  }else{
    document.getElementsByClassName('postal_code_option').each(function(s){ s.disable(); });
    document.getElementsByClassName('city_option').each(function(s){ s.enable(); });
    $('postal_code_option').hide();
    $('city_option').show();
  }
}

function verifyPaymentVisibility(){
  subscription_offer_checked = false;
  document.getElementsByClassName('subscription_offer_option').each(function(s){ if(s.checked){ subscription_offer_checked = true; } });
  no_subscription_offer_checked = document.getElementById('no_subscription_offer_option').checked;
  if(no_subscription_offer_checked || !subscription_offer_checked){
    $('enable_payment').hide();
    $('disable_payment').show();
  }else{
    $('enable_payment').show();
    $('disable_payment').hide();
  }
}

function icon_to_loading(id){
  $(id).addClassName('loading_icon');
  $(id).blur();
}

// this is a ghetto hack the spinner to show on popup boxes
var spinner = new Image();
spinner.src = "/images/spinner_big.gif";
var spinner_sm = new Image();
spinner_sm.src = "/images/spinner_sm.gif";	
var progress_bar = new Image();
progress_bar.src = "/images/progress_bar.gif";

function rotateCollection(id,count){
  Effect.toggle(id+'_'+spotlight,'appear',{duration:2.0});
  $(id+'_link_'+spotlight).removeClassName('c');  
  if(spotlight == count) {spotlight = 1;} else {spotlight++;}
  Effect.toggle(id+'_'+spotlight,'appear',{duration:2.0});
  $(id+'_link_'+spotlight).addClassName('c');  
}

var Video = {
  start:function(video){
    setPopupPosition('popup_container');
    $('popup_container').show();
    $('popup_content').update($(video).innerHTML+"<p class='center'><a href='\#' onclick='Video.stop(); return false;' class='red'>close window</a></p>")
  },
  stop:function(video){
    $('popup_container').hide(); 
    $('popup_content').update('');
  }
}

function close_browse_selector(e){
  $(e + "_selector").hide();
}

function open_browse_selector(e){
  $(e + "_selector").show();
}

var Downloads = {
  artist_id:null,
  album_id:null,
  load_albums:function(artist){
    if(this.artist_id != null){ $('dl_artist_'+this.artist_id).removeClassName('active') } 
    this.artist_id = artist
    $('dl_artist_'+this.artist_id).addClassName('active')
  },
  load_songs:function(album){
    if(this.album_id != null && $('dl_album_'+this.album_id)){ $('dl_album_'+this.album_id).removeClassName('active') }
    this.album_id = album
    $('dl_album_'+this.album_id).addClassName('active')
  }
}

var Player = {
  played:null,
  preview_id:null,
  pe:null,  
  start:function(id, preview_length){
    if(this.preview_id){this.next();}
    this.preview_id = id;
    new Effect.toggle('preview_'+this.preview_id,'blind');
    
    $('pause_preview_'+this.preview_id).show();
    $('play_preview_'+this.preview_id).hide();
    $('play_preview_'+this.preview_id).removeClassName('loading_icon');
    
    var increment = 100/preview_length;
    var current_width = 0
    // start animating the progress bar...
    this.pe = new PeriodicalExecuter(function(pe) {
          if(current_width >= 100){pe.stop();}else{current_width = current_width + increment; $('bar_'+id).setStyle({width: current_width+'%'})}
          }, 1)
  },
  stop:function(){
    wimpy_stop();
    this.next();
  },
  next:function(){
    new Effect.toggle('preview_'+this.preview_id,'blind');
    $('pause_preview_'+this.preview_id).hide();
    $('play_preview_'+this.preview_id).show();
    this.pe.stop();
    this.preview_id = null;
  }
}

function setSearchCategory(type, name){
  $('quick_search_category').value = type;
  $('selected_search_option').update(name);
  $('search_options_list').hide();
}

function setupSearch(el){
  if(el.value == 'search...'){ el.value = ''}
}
