function popup_player(show,pathcorrect) {
day = new Date();
id = day.getTime();
//eval("page" + id + " = window.open('player/mp3player.php?show=" + show + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=yes,width=520,height=500');");
eval("page" + " = window.open('"+(pathcorrect?'../':'')+"player/player.php?show=" + show + "', 'senseifmplayer', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=yes,width=560,height=400');");
}

function error(txt){
 jQuery('#error')
 //.prepend(txt)
 .html(txt)
 .css({'display':'block','opacity':1,'visibility':'visible'})
 //.delay(2000).fadeOut(1000)
 ;
 }
function error2(txt){
 //closepopup();
 setStyles(['error'],{'opacity':0,'visibility':'hidden'});
 getElem('error').innerHTML = txt;
 setTimeout(function(){ fadein('error',500); },10);
 
 setTimeout(function(){ fadeout('error',200); },1500);
 setTimeout(function(){
  getElem('error').innerHTML = ''
+'<a onclick="item_add_new();" class="sm-button" style="float:left;" href="javascript:;">'
+'<div class="btn-lhs">CREATE NEW</div>'
+'<div class="btn-rhs"></div>'
+'</a><br/>';
  fadein('error',200);
  },1710);
 }


function item_add_new(){ ajaxeval(docname(true),'add=&new='); }
function item_insert(id,after){
 var n = document.createElement('form');
 n.id = 'item_'+id;
 n.className = 'item';
 n.method = 'POST';
 n.enctype = 'multipart/form-data';
 insertAfter(n,getElem('error'));
 refresh_item_info(id);
 }
function item_cancel_edit(id){
 popup_html('getting data...please wait..');
 refresh_item_info(id);
 }
function refresh_item_info(id){
 var fn = function(){
  if(isIE()){
   $$('.edit_text'+id).add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; });
   $$('.edit_text'+id).add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; });
   }
  else{
   $$('.edit_text'+id).add('keydown',function(event){ this.style.height=0+'px'; this.style.height=this.scrollHeight+'px'; });
   $$('.edit_text'+id).add('keyup',function(event){ this.style.height=0+'px'; this.style.height=this.scrollHeight+'px'; });
   }
  getElem('input-text-title'+id).style.height = getElem('input-text-title'+id).scrollHeight+'px';
  getElem('input-text-normal'+id).style.height = getElem('input-text-normal'+id).scrollHeight+'px';
  closepopup_delay();
  }
 ajaxload(docname(false),'get_item='+id, 'item_'+id, fn);
 }
function closepopup_delay(t){ var t = t||50; setTimeout(function(){ closepopup(); },t); }

function item_delete(id){
 if(confirm('Are you sure you wish to DELETE this item?\r\nAll info and files associated with this entry will also be deleted.\r\nWould you like to proceed?')){
  ajaxeval(docname(true),'delete='+id);
  }
 }

function delete_file(id,param){
 if(confirm('Are you sure you wish to DELETE this file?\r\nAny text changes will be cancelled.')){
  ajaxeval(docname(true),'deletefile='+id+'&param='+param);
  popup_html('deleting file...please wait.');
  }
 }
function update_filename(e){
 if(name = input_get_filename(e)){
  var btn = '<a href="javascript:;" class="sm-button" style="float:left;"'
  +' onclick="reset_file_input(\''+e.id+'\');"'
  +' >'
  +'<div class="btn-lhs">CLEAR FILE</div><div class="btn-rhs"></div>'
  +'</a>';
  e.parentNode.parentNode.style.display = 'none';
  nextSib(e.parentNode.parentNode).innerHTML = btn + '<span style="margin:2px 0px 0px 8px;"><span>' + e.name +' : '+ name + '</span></span>';
  }
 }
function update_filename_refresh(e){
 if(name = input_get_filename(e)){
  form = jQuery(e).parent().parent().parent().parent().get(0);
  if(form.name.value=='TYPE DJ NAME HERE'){ form.name.value=''; }
  jQuery(form).prepend('<input type="hidden" name="KeepAlive" />');
  ajax_formpost(form);
  popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;"/></div>',768);
  }
 }
function update_filename_news(e){
 if(name = input_get_filename(e)){
  form = jQuery(e)
  .parent()
  .parent()
  .parent()
  .parent()
  .parent()
  .parent()
  .prepend('<input type="hidden" name="KeepAlive" />')
  .trigger('submit')
  .get(0)
  ;
  popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;"/></div>',768);
  }
 }
function input_get_filename(elem){
 var val = elem.value;
 var i = val.lastIndexOf('\\');
 val = val.substr(i+1);
 if(val!=''){ return val; }
 else{ return false; }
 }
function reset_file_input(e){
 if(typeof(e)=='string') e = getElem(e);
 
 e.parentNode.parentNode.style.display = 'block';
 
 var id = e.id;
 var name = e.name;
 var className = e.className;

 var p = e.parentNode;
 p.removeChild(e);
 p.innerHTML += '<input type="file" name="'+name+'" class="'+className+'" id="'+id+'" />';
 
 getElem(id).onchange = function(){ update_filename(this); }
 nextSib(p.parentNode).innerHTML = '';
 
 return true;
 }

/**/
function o_delete_file(filename,id,param){
 if(confirm('Are you sure you wish to DELETE this file?\r\nOther changes will be cancelled.')){
  ajaxeval(filename,'deletefile='+id+'&param='+param);
  }
 }
/*
CUSTOMISED CMS ACTIONS FOR ARTISTS/ALBUMS/TRACKS
AJAX ADD
DYN HTML INSERT
POPUP EDIT FORM
SUBMIT/SAVE EDITS
CANCEL/UNDO/REFRESH EDIT
AJAX DELETE WITH JS EVAL CALLBACK
EDIT FORM FILE SELECT/ONCHANGE ACTION = indicates filename loaded into custom file input form field
*/
//ARTISTS CMS FUNCTIONS
function o_add_artist(){
 popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;"/></div>',768);
  

 
 }
function o_insert_artist(id){
/*
 n = document.createElement('div');
 n.id = 'artist-holder-'+id;
 n.className = 'artist-holder';

 n.style.margin = '10px 0px';
 n.innerHTML = '<div class="artist" id="artist-'+id+'"></div><div class="break0" id="new-album-marker-'+id+'"></div>';
 insertAfter(n,getElem('new-artist-marker'));

 jQuery.get('get_info.php?artist_id='+id,{},function(data){
  
  });
*/

 o_edit_artist(id);
 }
function o_edit_artist(id){
 popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;"/></div>',768);
  
 jQuery.get('cms_djs.php',{'id':id},function(data){
  popup_html(data,768);  
  });
 
 }
function o_save_artist(id){
 if(document.forms['artist_item_'+id].name.value=='TYPE DJ NAME HERE'){ document.forms['artist_item_'+id].name.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="gfx/loading.gif" style="width:20px;height:20px;" /></div>');
 ajax_formpost(document.forms['artist_item_'+id]);
 }
function o_cancel_artist(id){
getElem('popupmsg').style.height = ''+(getElem('popupmsg').offsetHeight-34)+'px';
o_edit_artist(id);
}
function o_delete_artist(id){ ajaxeval('cms_djs.php?delete='+id); }
function o_filename_artist(e){ if(name=input_get_filename(e)){ nextSib(e.parentNode.parentNode).innerHTML = name; } }

//ALBUMS CMS FUNCTIONS
function o_add_album(id){
 //popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" /></div>');
 ajaxeval('cms_genres.php','add=&new=&artist_id='+id);
 }
function o_insert_album(id,artist_id){
 n = document.createElement('div');
 n.id = 'album-holder-'+id;
 n.className = 'album-holder';
 n.style.padding = '10px 0px';
 n.innerHTML = '<div class="album" id="album-'+id+'"></div><div class="break0" id="new-track-marker-'+id+'"></div>';
 insertAfter(n,getElem('new-album-marker-'+artist_id));
 ajaxload('get_info.php?album_id='+id,false,'album-'+id,false);
 o_edit_album(id);
 }
function o_edit_album(id){
 popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;" /></div>');
 
 oncomplete = function(){
 if(getElem('popupmsg')) getElem('popupmsg').style.height = 'auto';
 $$(document.forms['album_item_'+id].name)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE GENRE TITLE HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE GENRE TITLE HERE'){ this.value=''; }; }); 
 $$(document.forms['album_item_'+id].description)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE TEXT DESCRIPTION HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE TEXT DESCRIPTION HERE'){ this.value=''; }; });
 if(isIE()){
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ alert(keycode(event)); this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }
 document.forms['album_item_'+id].name.style.height = document.forms['album_item_'+id].name.scrollHeight+'px';
 document.forms['album_item_'+id].description.style.height = document.forms['album_item_'+id].description.scrollHeight+'px';
  }
 
 ajaxload('cms_genres.php?id='+id,false,'popupmsg',oncomplete);
 }
function o_imagefilename_album(e){
 if(name = input_get_filename(e)){
  nextSib(e.parentNode.parentNode).innerHTML = '<span style="margin:2px 0px 0px 8px;">' + e.name +' : '+ name + '</span>';
  }
 }
function o_save_album(id){
 if(document.forms['album_item_'+id].name.value=='TYPE GENRE TITLE HERE'){ document.forms['album_item_'+id].name.value=''; }
 if(document.forms['album_item_'+id].description.value=='TYPE TEXT DESCRIPTION HERE'){ document.forms['album_item_'+id].description.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="gfx/loading.gif" style="width:20px;height:20px;" /></div>');
 ajax_formpost(document.forms['album_item_'+id]);
 }
function o_cancel_album(id){ getElem('popupmsg').style.height = (getElem('popupmsg').offsetHeight-34)+'px'; o_edit_album(id); }
function o_delete_album(id){ ajaxeval('cms_genres.php?delete='+id); }
function o_filename_album(e){  }

//TRACKS CMS FUNCTIONS
function o_add_track(id){
 //popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" /></div>');
 ajaxeval('cms_shows.php','add=&new=&albumid='+id);
 }
function o_update_track(id){
 //alert('update'+id);
 ajaxload('get_info.php?track_id='+id,false,'track-'+id,false);
 getElem('popupmsg').style.height = (getElem('popupmsg').offsetHeight-34)+'px';
 o_edit_track(id);
 }
function o_insert_track(id,album_id){
 n = document.createElement('div');
 n.id = 'track-'+id;
 n.className = 'track';
 insertBefore(n,getElem('new-track-marker-'+album_id));
 ajaxload('get_info.php?track_id='+id,false,'track-'+id,false);
 ajaxload('get_info.php?album_id='+album_id,false,'album-'+album_id,false);
 o_edit_track(id);
 }
function o_edit_track(id){
 popup_html('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" style="width:40px;height:40px;" /></div>');
 jQuery.get('cms_shows.php',{'id':id},function(data){
  //alert(data);
  popup_html(data, 650);/*'<div id=\'popup-close\' onclick=\'popup_close();\'></div>'+*/
  });
 }
function o_save_track(id){
 if(document.forms['track_item_'+id].name.value=='TYPE MIX TITLE HERE'){ document.forms['track_item_'+id].name.value=''; }
 if(document.forms['track_item_'+id].description.value=='TYPE MIX DESCRIPTION HERE'){ document.forms['track_item_'+id].description.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="gfx/loading.gif" style="width:20px;height:20px;" /></div>');
 ajax_formpost(document.forms['track_item_'+id]);
 }
function o_cancel_track(id){ getElem('popupmsg').style.height = (getElem('popupmsg').offsetHeight-34)+'px'; o_edit_track(id); }
function o_delete_track(id,albumid){ if(confirm("Are you sure you wish to delete this Mix?")) ajaxeval('cms_shows.php','delete='+id+'&albumid='+albumid); }
function o_filename_track(e){  }

/*END CUSTOMISED CMS ACTIONS FOR ARTISTS/ALBUMS/TRACKS*/




/**/
function form_defaults(form,name_text_array){
 for(var name in name_text_array){
 
 $$(form[name])
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value=name_text_array[name]; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value==name_text_array[name]){ this.value=''; }; }); 
 if(isIE()){
  $$(form[name])
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$(form[name])
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }  
 form[name].style.height = form[name].scrollHeight+'px';
 form[name].style.height = form[name].scrollHeight+'px';
  }
 }


function usr_favorite(type,id,cell) {
 ajaxload('usr_favorite.php','type='+type+'&id='+id,cell,false);
 }
function usr_rating(type,id,current) {
 var currentRating = new Array();
 currentRating[current] = " checked";
 popup_html('<h1><img src="php.fonts/maketextww.php?font=trebucbd.ttf&text=USER RATING&c=999999&bgc=FFFFFF" /></h1>'
+'<div class="break9"></div>'
+'<p style="margin:10px 0px;">Please choose a rating (1 = Low, 5 = High)</p>'
+'<div class="break9"></div>'
+'<div class="radiobuttons">'
+'<input type="radio" name="rating" value="1" onclick="ajaxload(\'usr_rating.php\',\'type='+type+'&id='+id+'&rating=1\',false,\'window.location.reload( true );\');"'+currentRating[1]+'> 1'
+'<input type="radio" name="rating" value="2" onclick="ajaxload(\'usr_rating.php\',\'type='+type+'&id='+id+'&rating=2\',false,\'window.location.reload( true );\');"'+currentRating[2]+'> 2'
+'<input type="radio" name="rating" value="3" onclick="ajaxload(\'usr_rating.php\',\'type='+type+'&id='+id+'&rating=3\',false,\'window.location.reload( true );\');"'+currentRating[3]+'> 3'
+'<input type="radio" name="rating" value="4" onclick="ajaxload(\'usr_rating.php\',\'type='+type+'&id='+id+'&rating=4\',false,\'window.location.reload( true );\');"'+currentRating[4]+'> 4'
+'<input type="radio" name="rating" value="5" onclick="ajaxload(\'usr_rating.php\',\'type='+type+'&id='+id+'&rating=5\',false,\'window.location.reload( true );\');"'+currentRating[5]+'> 5'
+'</div>'
+'<div class="break9"></div>'
+'<div class="break9"></div>'
+'<p style="margin:10px 0px;">When you are logged in you will see your own ratings near the ratings icon. When not logged in you will see the averge rating across all users.'
,'360');
 }
function usr_comment(type,id) {
 if(window.name == 'senseifmplayer')
  alert('The player window is too small for leaving comments.\nPlease use the main window for comments.\nThank you.');
 else
  window.location = 'usr_comments.php?type='+type+'&id='+id;
 }
function usr_email(type,id) {
 popup_html('<iframe frameborder=\'0\' scrolling=\'no\' style=\'border:0px;width:320px;height:398px;\' src=\'usr_email.php?type='+type+'&id='+id+'\'></iframe>','320');
 //window.location = 'usr_email.php?type='+type+'&id='+id;
 }


