// {{{ Globals
var mSrc = ""; //modal dialog source
var gID;
var gDir;
var gMutex = false; // default unlocked
var gCDPos = 0;
//following array is used to get MORE rows of API data, by index: 0=recent shows, 1=upcoming shows, 2=past shows, 3=artists, 4=all upcoming, 5=all past, 6=show comments, 7=artists followed, 8=shows favorited, 9=shows attented, 10=show comments, 11=main page recent, 12=main page upcoming, 13=main page past
var apiPG = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var fCnt=0 //fade count
var fState=0 //fade out=0 / in=1

var st = 0;
var showID = null;
var artistID = null;
function _$(id) { return document.getElementById(id); }
function _$S(id) { return _$(id).style; }
//}}}
$(window).load(function(){ // {{{load process after page has loaded...set presets
  resizeImg();
  if(mSrc.length > 0) { openModal(); }
  notifications();
 }) // }}}
function processAJAX(url,id,showLoading) //{{{
{
  if(gMutex) return;
  try { req = new XMLHttpRequest(); } catch(e) {
  try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {
  try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {
    alert("AJAX Error. Scripting for ActiveX might be disabled?");
    return;
  } } }
  gMutex = true;
  gID = id;
  req.onreadystatechange = function()
  { 
    if(req.readyState == 4) {
      if(req.status == 200) {
        if(showLoading) closeModal();
        if(typeof(gID) == 'function')
          gID(req.responseText);
        else
          fadeReplace(gID,req.responseText);
      } else {
        _$(gID).innerHTML = "Oops, error: " + req.statusText;
      }
      gMutex = false;
    }
  };

  req.open("GET", url , true);
  req.send(null);
  if(showLoading) {
    mSrc = "loading";
    document.getElementById('loading').setAttribute('class','loading');
    openModal();
    _$('loading').innerHTML = "&nbsp;";
  }
}
//}}}
function fadeReplace(id,txt,fnc) { //{{{
  $('#'+id).fadeOut('fast', function() { 
    _$(id).innerHTML = txt;
    if(typeof(fnc) == 'function')
      $('#'+id).fadeIn('fast',fnc);
    else
      $('#'+id).fadeIn('fast');
      resizeImg();
  });
 } //}}}
function isNumber(n) { //{{{
    return !isNaN(parseFloat(n)) && isFinite(n);
} //}}}
function openModal() { //{{{
 document.getElementById('obscure').style.display='block';
 document.getElementById(mSrc).style.display='block';
 $("#obscure").animate({ opacity: 0.8 }, 500 );
 $("#"+mSrc).animate({ opacity: 1 }, 500 );
} //}}}
function closeModal() { //{{{
 $("#obscure").animate({ opacity: 0 }, 500, function() { document.getElementById('obscure').style.display='none'; } );
 $("#"+mSrc).animate({ opacity: 0 }, 500, function() { document.getElementById(mSrc).style.display='none'; });
 clearModal();
} //}}}
function clearModal() { //{{{
  switch(mSrc) {
    case "password":
      document.password.mPass.style.backgroundColor = "#fff";
      document.password.mPass.style.color = "#000";
      document.password.mPassV.style.backgroundColor = "#fff";
      document.password.mPassV.style.color = "#000";
      document.password.mPass.value = "";
      document.password.mPassV.value = "";
      document.getElementById('passwordMsg').innerHTML = "";
      document.getElementById('passwordMsg').style.display = 'none';
      break;
    case "reset":
      document.reset.mUser.style.backgroundColor = "#fff";
      document.reset.mUser.style.color = "#000";
      document.reset.f_verify.style.backgroundColor = "#fff";
      document.reset.f_verify.style.color = "#000";
      document.reset.mUser.value = "";
      document.reset.f_verify.value = "";
      document.getElementById('resetMsg').innerHTML = "";
      document.getElementById('resetMsg').style.display = 'none';
      break;
    case "resend":
      document.resend.mEmail.style.backgroundColor = "#fff";
      document.resend.mEmail.style.color = "#000";
      document.resend.f_verify.style.backgroundColor = "#fff";
      document.resend.f_verify.style.color = "#000";
      document.resend.mEmail.value = "";
      document.resend.f_verify.value = "";
      document.getElementById('resendMsg').innerHTML = "";
      document.getElementById('resendMsg').style.display = 'none';
      break;
    case "activate":
      document.activate.mUser.style.backgroundColor = "#fff";
      document.activate.mUser.style.color = "#000";
      document.activate.f_verify.style.backgroundColor = "#fff";
      document.activate.f_verify.style.color = "#000";
      document.activate.mUser.value = "";
      document.activate.f_verify.value = "";
      document.getElementById('activateMsg').innerHTML = "";
      document.getElementById('activateMsg').style.display = 'none';
      break;
    case "follow":
      document.getElementById('followMsg').innerHTML = "";
      document.getElementById('followMsg').style.display = 'none';
      break;
    case "favorite":
      document.getElementById('favoriteMsg').innerHTML = "";
      document.getElementById('favoriteMsg').style.display = 'none';
      break;
    case "attend":
      document.getElementById('attendMsg').innerHTML = "";
      document.getElementById('attendMsg').style.display = 'none';
      break;
    case "vmap":
      document.getElementById('vmapMsg').innerHTML = "";
      document.getElementById('vmapMsg').style.display = 'none';
      break;
    case "comment":
      document.comment.message.value = "";
      document.comment.message.style.backgroundColor = "#fff";
      document.comment.message.style.color = "#000";
      document.getElementById('commentMsg').innerHTML = "";
      document.getElementById('commentMsg').style.display = 'none';
      break;
    case "msg":
      if(document.getElementById("errorMsg")) {
        document.getElementById('errorMsg').innerHTML = "";
        document.getElementById('errorMsg').style.display = 'none';
      }
      if(document.getElementById("successMsg")) {
        document.getElementById('successMsg').innerHTML = "";
        document.getElementById('successMsg').style.display = 'none';
      }
      break;
    default:
      break;
  }
} //}}}
function signout() //{{{
{
  var url = '/index.html?act=sgo';
  processAJAX(url, successSignout, false);
} //}}}
function successSignout(txt) //{{{
{
  if(txt=="TRUE") { document.location.href='/'; } 
} //}}}
function password() //{{{
{
  var msg = "";
  var fail = 0;
  var pass = document.password.mPass;
  var passV = document.password.mPassV;

  if(pass.value.length == 0) {
    pass.style.backgroundColor = "#C00";
    pass.style.color = "#fff";
    msg += "<li>Please enter your New Password.</li>";
    fail = 1;
  }
  else {
    pass.style.backgroundColor = "#FFF";
    pass.style.color = "#000";
  }
  if(passV.value.length == 0) {
    passV.style.backgroundColor = "#C00";
    passV.style.color = "#fff";
    msg += "<li>Please verify your Password.</li>";
    fail = 1;
  }
  else {
    passV.style.backgroundColor = "#FFF";
    passV.style.color = "#000";
  }
  if(pass.value != passV.value) {
    pass.style.backgroundColor = "#C00";
    pass.style.color = "#fff";
    passV.style.backgroundColor = "#C00";
    passV.style.color = "#fff";
    msg += "<li>The New Password and Verify Password do not match, please re-enter your passwords.</li>";
    fail = 1;
  }
  if(fail==1) {
    document.getElementById("passwordMsg").className = "errMsg";
    document.getElementById('passwordMsg').innerHTML = "<p>An error occured while attempting to update your password:</p><ul>"+msg+"</ul>";
    document.getElementById('passwordMsg').style.display = 'block';
  }
  else {
    document.getElementById('passwordMsg').innerHTML = "";
    document.getElementById('passwordMsg').style.display = 'none';
    var url = '/account/password?p='+escape(pass.value)+'&pv='+escape(passV.value)
    processAJAX(url, successPassword, false);
  }
} //}}}
function successPassword(txt) //{{{
{
  if(txt=="TRUE") { 
    clearModal();
    document.getElementById("passwordMsg").className = "successMsg";
    document.getElementById('passwordMsg').innerHTML = "<p class=mText>Your Password has been successfully updated.</p>";
    document.getElementById('passwordMsg').style.display = 'block';
  }
  else {
    document.getElementById("passwordMsg").className = "errMsg";
    document.getElementById('passwordMsg').innerHTML = "<p>An error occured when attempting to update your password:</p><ul>"+txt+"</ul>";
    document.getElementById('passwordMsg').style.display = 'block';
  }
} //}}}
function reset() //{{{
{
  var msg = "";
  var fail = 0;
  var user = document.reset.mUser;
  var verify = document.reset.f_verify;
  var verifym = document.reset.f_verify_match;

  if(user.value.length == 0) {
    user.style.backgroundColor = "#C00";
    user.style.color = "#fff";
    msg += "<li>Please enter your User Name.</li>";
    fail = 1;
  }
  else {
    user.style.backgroundColor = "#FFF";
    user.style.color = "#000";
  }
  if(verify.value.length == 0) {
    verify.style.backgroundColor = "#C00";
    verify.style.color = "#fff";
    msg += "<li>Security Image Does Not Match.</li>";
    fail = 1;
  }
  else {
    verify.style.backgroundColor = "#FFF";
    verify.style.color = "#000";
  }
  if(fail==1) {
    document.getElementById("resetMsg").className = "errMsg";
    document.getElementById('resetMsg').innerHTML = "<p>An error occured while attempting to reset your password:</p><ul>"+msg+"</ul>";
    document.getElementById('resetMsg').style.display = 'block';
  }
  else {
    document.getElementById('resetMsg').innerHTML = "";
    document.getElementById('resetMsg').style.display = 'none';

    var url = '/index.html?act=rst&u='+escape(user.value)+'&v='+escape(verify.value)+'&vm='+escape(verifym.value);
    processAJAX(url, successReset, false);
  }
}//}}}
function successReset(txt) //{{{
{
  if(txt=="TRUE") { 
    clearModal();
    document.getElementById("resetMsg").className = "successMsg";
    document.getElementById('resetMsg').innerHTML = "<p class=mText>An email has been sent with your sign in details.</p>";
    document.getElementById('resetMsg').style.display = 'block';
  }
  else {
    document.getElementById("resetMsg").className = "errMsg";
    document.getElementById('resetMsg').innerHTML = "<p>An error occured when attempting to reset your password:</p><ul>"+txt+"</ul>";
    document.getElementById('resetMsg').style.display = 'block';
  }
} //}}}
function resend() //{{{
{
  var msg = "";
  var fail = 0;
  var email = document.resend.mEmail;
  var verify = document.resend.f_verify;
  var verifym = document.resend.f_verify_match;

  if(email.value.length == 0) {
    email.style.backgroundColor = "#C00";
    email.style.color = "#fff";
    msg += "<li>Please enter your Email Address.</li>";
    fail = 1;
  }
  else {
    email.style.backgroundColor = "#FFF";
    email.style.color = "#000";
  }
  if(verify.value.length == 0) {
    verify.style.backgroundColor = "#C00";
    verify.style.color = "#fff";
    msg += "<li>Security Image Does Not Match.</li>";
    fail = 1;
  }
  else {
    verify.style.backgroundColor = "#FFF";
    verify.style.color = "#000";
  }
  if(fail==1) {
    document.getElementById("resendMsg").className = "errMsg";
    document.getElementById('resendMsg').innerHTML = "<p>An error occured while attempting to resend your confirmation email:</p><ul>"+msg+"</ul>";
    document.getElementById('resendMsg').style.display = 'block';
  }
  else {
    document.getElementById('resendMsg').innerHTML = "";
    document.getElementById('resendMsg').style.display = 'none';

    var url = '/index.html?act=rsd&e='+escape(email.value)+'&v='+escape(verify.value)+'&vm='+escape(verifym.value);
    processAJAX(url, successResend, false);
  }
}//}}} 
function successResend(txt) //{{{
{
  if(txt=="TRUE") { 
    clearModal();
    document.getElementById("resendMsg").className = "successMsg";
    document.getElementById('resendMsg').innerHTML = "<p class=mText>An email has been sent with a list of all of your CHICAGOER account confirmation links.</p>";
    document.getElementById('resendMsg').style.display = 'block';
  }
  else {
    document.getElementById("resendMsg").className = "errMsg";
    document.getElementById('resendMsg').innerHTML = "<p>An error occured when attempting to resend your confirmation links:</p><ul>"+txt+"</ul>";
    document.getElementById('resendMsg').style.display = 'block';
  }
} //}}}
function activate() //{{{
{
  var msg = "";
  var fail = 0;
  var user = document.activate.mUser;
  var verify = document.activate.f_verify;
  var verifym = document.activate.f_verify_match;

  if(user.value.length == 0) {
    user.style.backgroundColor = "#C00";
    user.style.color = "#fff";
    msg += "<li>Please enter your User Name.</li>";
    fail = 1;
  }
  else {
    user.style.backgroundColor = "#FFF";
    user.style.color = "#000";
  }
  if(verify.value.length == 0) {
    verify.style.backgroundColor = "#C00";
    verify.style.color = "#fff";
    msg += "<li>Security Image Does Not Match.</li>";
    fail = 1;
  }
  else {
    verify.style.backgroundColor = "#FFF";
    verify.style.color = "#000";
  }
  if(fail==1) {
    document.getElementById("activateMsg").className = "errMsg";
    document.getElementById('activateMsg').innerHTML = "<p>An error occured while attempting to send your activation email:</p><ul>"+msg+"</ul>";
    document.getElementById('activateMsg').style.display = 'block';
  }
  else {
    document.getElementById('activateMsg').innerHTML = "";
    document.getElementById('activateMsg').style.display = 'none';

    var url = '/index.html?act=act&u='+escape(user.value)+'&v='+escape(verify.value)+'&vm='+escape(verifym.value);
    processAJAX(url, successActivate, false);
  }
}//}}}
function successActivate(txt) //{{{
{
  if(txt=="TRUE") { 
    clearModal();
    document.getElementById("activateMsg").className = "successMsg";
    document.getElementById('activateMsg').innerHTML = "<p class=mText>An email has been sent with details on how to activate your account.</p>";
    document.getElementById('activateMsg').style.display = 'block';
  }
  else {
    document.getElementById("activateMsg").className = "errMsg";
    document.getElementById('activateMsg').innerHTML = "<p>An error occured when attempting to send your activation email:</p><ul>"+txt+"</ul>";
    document.getElementById('activateMsg').style.display = 'block';
  }
} //}}}
function artistFollow(artist,loggedIn) //{{{
{
  mSrc='follow';
  var msg = "";
  var fail = 0;
  if(artist.length == 0) {
    fail = 1;
    msg += "<li>No Artist given to follow.</li>";
  }
  if(!(loggedIn)) {
    fail = 1;
    msg += "<li>Please <a href='/signin' class='white'>Sign In</a> to follow this artist.</li>";
  }
  if(fail==1) {
    document.getElementById("followMsg").className = "errMsg";
    document.getElementById('followMsg').innerHTML = "<p>An error occured when attempting to follow this artist:</p><ul>"+msg+"</ul>";
    document.getElementById('followMsg').style.display = 'block';
    openModal();
  }
  else {
    var url = '/index.html?act=afw&a='+escape(artist)+'&f='+escape(follow);
    processAJAX(url, successArtistFollow, false);
  }
}//}}}
function successArtistFollow(txt) //{{{
{
  if(txt=="TRUE1") { 
    clearModal();
    document.getElementById("followArt").className = "follow1";
    document.getElementById("followArt").setAttribute('title','click to stop following this artist');
    document.getElementById("followMsg").className = "mText";
    document.getElementById('followMsg').innerHTML = "<p>You are now following this artist.</p>";
    document.getElementById('followMsg').style.display = 'block';
    openModal();
    follow=0;
  }
  else if(txt=="TRUE0") {
    clearModal();
    document.getElementById("followArt").className = "follow0";
    document.getElementById("followArt").setAttribute('title','click to follow this artist');
    document.getElementById("followMsg").className = "mText";
    document.getElementById('followMsg').innerHTML = "<p>You have stopped following this artist.</p>";
    document.getElementById('followMsg').style.display = 'block';
    openModal();
    follow=1;
  }
  else {
    document.getElementById("followMsg").className = "errMsg";
    document.getElementById('followMsg').innerHTML = "<p>An error occured when attempting to follow this artist:</p><ul>"+txt+"</ul>";
    document.getElementById('followMsg').style.display = 'block';
    openModal();
  }
} //}}}
function showFavorite(show,loggedIn) //{{{
{
  mSrc='favorite';
  var msg = "";
  var fail = 0;
  if(show.length == 0) {
    fail = 1;
    msg += "<li>No Show given to favorite.</li>";
  } else {
    showID = show;
  }
  if(!(loggedIn)) {
    fail = 1;
    msg += "<li>Please <a href='/signin' class='white'>Sign In</a> to favorite this show.</li>";
  }
  if(fail==1) {
    document.getElementById("favoriteMsg").className = "errMsg";
    document.getElementById('favoriteMsg').innerHTML = "<p>An error occured when attempting to favorite this show:</p><ul>"+msg+"</ul>";
    document.getElementById('favoriteMsg').style.display = 'block';
    openModal();
  }
  else {
    var url = '/index.html?act=sfv&s='+escape(show)+'&f='+escape(favorite);
    processAJAX(url, successShowFavorite, false);
  }
}//}}}
function successShowFavorite(txt) //{{{
{
  if(txt=="TRUE1") { 
    clearModal();
    document.getElementById("favoriteShow"+showID).className = "fav1";
    document.getElementById("favoriteShow"+showID).setAttribute('title','click to remove this show from your favorites');
    document.getElementById("favoriteMsg").className = "mText";
    document.getElementById('favoriteMsg').innerHTML = "<p>This show is now in your favorites list.</p>";
    document.getElementById('favoriteMsg').style.display = 'block';
    openModal();
    favorite=0;
  }
  else if(txt=="TRUE0") {
    clearModal();
    document.getElementById("favoriteShow"+showID).className = "fav0";
    document.getElementById("favoriteShow"+showID).setAttribute('title','click to add this show to your favorites');
    document.getElementById("favoriteMsg").className = "mText";
    document.getElementById('favoriteMsg').innerHTML = "<p>This show has been removed from your favorites list.</p>";
    document.getElementById('favoriteMsg').style.display = 'block';
    openModal();
    favorite=1;
  }
  else {
    document.getElementById("favoriteMsg").className = "errMsg";
    document.getElementById('favoriteMsg').innerHTML = "<p>An error occured when attempting to add this show to your favorites:</p><ul>"+txt+"</ul>";
    document.getElementById('favoriteMsg').style.display = 'block';
    openModal();
  }
} //}}}
function showAttend(show,loggedIn) //{{{
{
  mSrc='attend';
  var msg = "";
  var fail = 0;
  if(show.length == 0) {
    fail = 1;
    msg += "<li>No Show given to attend.</li>";
  } else {
    showID = show;
  }
  if(!(loggedIn)) {
    fail = 1;
    msg += "<li>Please <a href='/signin' class='white'>Sign In</a> to add this show to your attended shows list.</li>";
  }
  if(fail==1) {
    document.getElementById("attendMsg").className = "errMsg";
    document.getElementById('attendMsg').innerHTML = "<p>An error occured when attempting to add this show to your attended shows list:</p><ul>"+msg+"</ul>";
    document.getElementById('attendMsg').style.display = 'block';
    openModal();
  }
  else {
    var url = '/index.html?act=sat&s='+escape(show)+'&f='+escape(attend);
    processAJAX(url, successShowAttend, false);
  }
}//}}}
function successShowAttend(txt) //{{{
{
  if(txt=="TRUE1") { 
    clearModal();
    document.getElementById("attendShow"+showID).className = "attend1";
    document.getElementById("attendShow"+showID).setAttribute('title','click to remove this show from your attended shows list');
    document.getElementById("attendMsg").className = "mText";
    document.getElementById('attendMsg').innerHTML = "<p>This show is now in your attended shows list.</p>";
    document.getElementById('attendMsg').style.display = 'block';
    openModal();
    attend=0;
  }
  else if(txt=="TRUE0") {
    clearModal();
    document.getElementById("attendShow"+showID).className = "attend0";
    document.getElementById("attendShow"+showID).setAttribute('title','click to add this show to your attended shows list');
    document.getElementById("attendMsg").className = "mText";
    document.getElementById('attendMsg').innerHTML = "<p>This show has been removed from your attended shows list.</p>";
    document.getElementById('attendMsg').style.display = 'block';
    openModal();
    attend=1;
  }
  else {
    document.getElementById("attendMsg").className = "errMsg";
    document.getElementById('attendMsg').innerHTML = "<p>An error occured when attempting to add this show to your attended shows list:</p><ul>"+txt+"</ul>";
    document.getElementById('attendMsg').style.display = 'block';
    openModal();
  }
} //}}}
function unfollow(artist) //{{{
{
  artistID = artist;
  var url = '/index.html?act=afw&a='+escape(artist)+'&f=0';
  processAJAX(url, successUnfollow, false);
}//}}}
function successUnfollow(txt) //{{{
{
  if(txt=="TRUE0") { 
    document.getElementById('unfollow'+artistID).style.display='none';
//    document.getElementById('countFollow').innerHTML = parseInt(document.getElementById('countFollow').innerHTML) - 1;
//    if(parseInt(document.getElementById('countFollow').innerHTML)==0) {
//      document.getElementById('uFollowingBody').innerHTML = '<div class=\"errMsg\" id=\"uFollowingMsg\"></div><img src=\"/images/cg_meme_megusta.png\" width=45 height=45>You aren\'t following any bands.<br><br>Well, at least you\'re not a stalker.';
//    }
  }  
}//}}}
function unfavorite(show) //{{{
{
  showID = show;
  var url = '/index.html?act=sfv&s='+escape(show)+'&f=0';
  processAJAX(url, successUnfavorite, false);
}//}}}
function successUnfavorite(txt) //{{{
{
  if(txt=="TRUE0") { 
    document.getElementById('unfavorite'+showID).style.display='none';
//    document.getElementById('countFav').innerHTML = parseInt(document.getElementById('countFav').innerHTML) - 1;
//    if(parseInt(document.getElementById('countFav').innerHTML)==0) {
//      document.getElementById('uFavoritesBody').innerHTML = '<div class=\"errMsg\" id=\"uFavoritesMsg\"></div><img src=\"/images/cg_meme_yuno.png\" width=45 height=45>You haven\'t favorited any shows!<br><br>Why you no like the Chicago music scene?';
//    }
  }  
}//}}}
function unattend(show) //{{{
{
  showID = show;
  var url = '/index.html?act=sat&s='+escape(show)+'&f=0';
  processAJAX(url, successUnattend, false);
}//}}}
function successUnattend(txt) //{{{
{
  if(txt=="TRUE0") { 
    document.getElementById('unattend'+showID).style.display='none';
//    document.getElementById('countAttend').innerHTML = parseInt(document.getElementById('countAttend').innerHTML) - 1;
//    if(parseInt(document.getElementById('countAttend').innerHTML)==0) {
//      document.getElementById('uAttendedBody').innerHTML = '<div class=\"errMsg\" id=\"uAttendedMsg\"></div><img src=\"/images/cg_meme_i4vralone.png\" width=45 height=45>You haven\'t attended any shows!<br><br>Too bad, you realy should get out more or you will end up forever alone.';
//    }
  }  
}//}}}
function notifications() //{{{
{
  var url = '/index.html?act=ntf';
  processAJAX(url, successNotifications, false);
}//}}}
function successNotifications(txt) //{{{
{
  if(txt.length>0) {
    rslt=txt.split('\t');
    document.getElementById('nCnt').innerHTML=rslt[0];
    document.getElementById('notification').style.display='block';
    document.getElementById('notifyBody').innerHTML=rslt[1];
    fade();
  }
}//}}}
function makeFeat(show) //{{{
{
  var url = '/index.html?act=ftr&s='+escape(show);
  processAJAX(url, "makeFeat", false);
}//}}}
function fade() //{{{
{
  //fade show alerts in and out 10 times
  fCnt++
  if(fCnt>10) { return true; }
  if(fState==1) {
    $('#notification').fadeIn('slow',function(){ fade();} );
    fState=0;
  } else {
    $('#notification').fadeOut('slow',function(){ fade();} );
    fState=1;
  }
}//}}}
function notify(ele) //{{{
{
  //display the show alerts
  mSrc='notify'; 
  openModal();

  //hide the notifications alert
  ele.style.display='none';

  //upon opening the notifications, set a cookie signifying the last time we looked
  var exp = new Date();
  exp.setTime(exp.getTime()+604800000);
  document.cookie = "notify_t="+parseInt((new Date().getTime())/1000)+"; expires="+exp.toGMTString()+"; path=/";
}//}}}
function midnight(dt) //{{{
{
  var offset = new Date().getTimezoneOffset()*60;
  dt -= offset;
  dt = (dt - (dt%86400)) + offset;
  return dt;
} //}}}
function imgState() // {{{
{
  st=Math.abs(st-1);
  if(st && userPics && (uPicsPg>1)) _$S('lessPics').display='block'; else _$S('lessPics').display='none';
  if(st && userPics && (uPicsPg<(Math.ceil(userPics/4)))) _$S('morePics').display='block'; else _$S('morePics').display='none';
  $('#stockPics').animate({'left':'-'+(st*265)+'px'},300);
} //}}}
function uPics(pg) // {{{
{
  $('#userPics').animate({'left':'+='+(260*pg)+'px'},300);
  uPicsPg+=(pg*-1);
  if(uPicsPg>=(Math.ceil(userPics/4))) { _$S('morePics').display='none'; } else { _$S('morePics').display='block'; }
  if(uPicsPg>1) { _$S('lessPics').display='block'; } else { _$S('lessPics').display='none'; }
} //}}}
function getMoreAPI(type,id,pg,main) // {{{
{
  var typeArr = type.split('-');
  switch (typeArr[0]) {
    case 'recent' : if(main==0){idx=0;apiPG[idx]++;}else{idx=11;} break;
    case 'upcoming' : idx = 1; apiPG[idx]++; break;
    case 'past' : idx = 2; apiPG[idx]++; break;
    case 'artists' : idx = 3; apiPG[idx]=pg; break;
    case 'allup' : if(main==0){idx=4;apiPG[idx]++;}else{idx=12;} break;
    case 'allpast' : if(main==0){idx=5;apiPG[idx]++;}else{idx=13;} break;
    case 'usercomment' : idx = 6; break;
    case 'following' : idx = 7; break;
    case 'favorites' : idx = 8; break;
    case 'attended' : idx = 9; break;
    case 'showcomments' : idx = 10; apiPG[idx]=pg; break;
  }
//  if(typeArr[0]=='showcomments') apiPG[idx] = pg;
  var url = '/index.html?act=mre&type='+type+'&page='+apiPG[idx];
  switch (typeArr[0]) {
    case 'recent' : 
      if(main==0) {
        url+='&count=6';
        processAJAX(url, successRecent, false);
      } else {
        url+='&count=10&main=1';
        processAJAX(url, successRecentMain, false);
      }
      break;
    case 'upcoming' : 
      url+='&count=8&id='+id;
      processAJAX(url, successUpcoming, false);
      break;
    case 'past' : 
      url+='&count=8&id='+id;
      processAJAX(url, successPast, false);
      break;
    case 'artists' : 
      url+='&count=25&l='+id+'&h=0';
      processAJAX(url, successArtists, false);
      break;
    case 'allup' : 
      if(main==0) {
        url+='&count=10';
        processAJAX(url, successAllUp, false);
      } else {
        url+='&count=10&main=1';
        processAJAX(url, successAllUpMain, false);
      }
      break;
    case 'allpast' : 
      if(main==0) {
        url+='&count=10';
        processAJAX(url, successAllPast, false);
      } else {
        url+='&count=10&main=1';
        processAJAX(url, successAllPastMain, false);
      }
      break;
    case 'usercomment' :
      url+='&count=20&id='+id;
      processAJAX(url, successUserComment, false);
      break;
    case 'following' :
      url+='&count=20&id='+id;
      processAJAX(url, successFollowing, false);
      break;
    case 'favorites' :
      url+='&count=20&id='+id;
      processAJAX(url, successFavorites, false);
      break;
    case 'attended' :
      url+='&count=20&id='+id;
      processAJAX(url, successAttended, false);
      break;
    case 'showcomments' :
      url+='&count=10&id='+id;
      processAJAX(url, successShowComments, false);
      break;
  }
  if(idx==6 || idx==7 || idx==8 || idx==9 || idx==11 || idx==12 || idx==13) apiPG[idx]++;
} //}}}
function successRecent(txt) //{{{
{
  successAPI('recent',txt);
} //}}}
function successRecentMain(txt) //{{{
{
  successAPIMain('recent',txt);
} //}}}
function successUpcoming(txt) //{{{
{
  successAPI('upcoming',txt);
} //}}}
function successPast(txt) //{{{
{
  successAPI('past',txt);
} //}}}
function successArtists(txt) //{{{
{
  successAPI('artists',txt);
} //}}}
function successAllUp(txt) //{{{
{
  successAPI('allup',txt);
} //}}}
function successAllUpMain(txt) //{{{
{
  successAPIMain('allup',txt);
} //}}}
function successAllPast(txt) //{{{
{
  successAPI('allpast',txt);
} //}}}
function successAllPastMain(txt) //{{{
{
  successAPIMain('allpast',txt);
} //}}}
function successUserComment(txt) //{{{
{
  successAPIMain('usercomment',txt);
} //}}}
function successFollowing(txt) //{{{
{
  successAPIMain('following',txt);
} //}}}
function successFavorites(txt) //{{{
{
  successAPIMain('favorites',txt);
} //}}}
function successAttended(txt) //{{{
{
  successAPIMain('attended',txt);
} //}}} 
function successShowComments(txt) //{{{
{
  successAPI('showcomments',txt);
} //}}}
function successAPI(type,txt) //{{{
{
  switch (type) {
    case 'recent' : idx = 0; hg=135; tm=200; break;
    case 'upcoming' : idx = 1; hg=80; tm=200; break;
    case 'past' : idx = 2; hg=80; tm=200; break;
    case 'artists' : idx = 3; hg=512; tm=500; break;
    case 'allup' : idx = 4; hg=235; tm=200; break;
    case 'allpast' : idx = 5; hg=235; tm=200; break;
    case 'usercomment' : idx = 6; hg=200; tm=200; break;
    case 'following' : idx = 7; hg=200; tm=200; break;
    case 'favorites' : idx = 8; hg=200; tm=200; break;
    case 'attended' : idx = 9; hg=200; tm=200; break;
    case 'showcomments' : idx = 10; hg=602; tm=500; break;
  }
  if(apiPG[idx] > 0) {
    _$(type+'More').parentNode.removeChild(_$(type+'More'));
    _$(type).innerHTML += txt;
    $('#'+type).animate({scrollTop:'+='+hg},tm);
    resizeImg();
  } else {
    if(txt.length==0) {
      txt="No results found.";
    }
    _$(type).scrollTop = 0;
    fadeReplace(type,txt);
  }
} //}}}
function successAPIMain(type,txt) //{{{
{
  switch (type) {
    case 'recent' : idx = 11; apiPG[12]=apiPG[13]=0; ttl = "RECENTLY ADDED SHOWS"; break;
    case 'allup' : idx = 12; apiPG[11]=apiPG[13]=0; ttl = "UPCOMING SHOWS"; break;
    case 'allpast' : idx = 13; apiPG[11]=apiPG[12]=0; ttl = "PAST SHOWS"; break;
    case 'usercomment' : idx = 6; ttl = "ALL OF YOUR COMMENTS"; break;
    case 'following' : idx = 7; ttl = "ARTISTS YOU ARE FOLLOWING"; break;
    case 'favorites' : idx = 8; ttl = "YOUR FAVORITE SHOWS"; break;
    case 'attended' : idx = 9; ttl = "SHOWS YOU HAVE ATTENDED"; break;
  }
  if(apiPG[idx] > 1) {
    _$(type+'MoreMain').parentNode.removeChild(_$(type+'MoreMain'));
    _$(type+'Main').innerHTML += txt;
    resizeImg();
  } else {
    if(txt.length==0) {
      txt="No results found.";
    }
    txt = "<div class=\"stripe\" style=\"margin-left:-13px;\">\n<div class=\"mTitle\">"+ttl+"</div>\n</div>\n<div class=\"bMain\" id=\""+type+"Main\">"+txt+"</div>\n</div>\n";
    fadeReplace('cal',txt);
  }
} //}}}
function getCookie(check_name) //{{{
{
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false; // set boolean t/f default f
  for ( i = 0; i < a_all_cookies.length; i++ ) {
    a_temp_cookie = a_all_cookies[i].split( '=' );
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
    if ( cookie_name == check_name ) {
      b_cookie_found = true;
      if ( a_temp_cookie.length > 1 ) {
        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      return cookie_value;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if ( !b_cookie_found ) {
    return null;
  }
} //}}} 
function btnLabel(label) //{{{
{
  document.getElementById('btnLabel').innerHTML = label;
} //}}}
function switchView() //{{{
{
  if(document.location.href.search(/\/showlist\//)!= -1) {
    document.location.href = document.location.href.replace(/\/showlist\//,"/show/");
  } else {
    document.location.href = document.location.href.replace(/\/show\//,"/showlist/");
  }
} //}}}
function resizeImg() //{{{
{
  if(document.location.href.search(/\/show\//) !== -1) {
    newH = 965;
  }else { 
    if(document.location.href.search(/\/(artists?|venues?)(\/|.html)/) !== -1) {
      newH = $('#cal').height()+49;
    } else {
      newH = $('#events').height()+139;
    }
  }
  if(newH < 816) newH=816;
  $('#bkgdimg').height(newH);
} //}}}
function getCookie(check_name) //{{{
{
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false; // set boolean t/f default f
  for ( i = 0; i < a_all_cookies.length; i++ ) {
    a_temp_cookie = a_all_cookies[i].split( '=' );
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
    if ( cookie_name == check_name ) {
      b_cookie_found = true;
      if ( a_temp_cookie.length > 1 ) {
        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      return cookie_value;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if ( !b_cookie_found ) {
    return null;
  }
} //}}} 
function btnLabel(label) //{{{
{
  document.getElementById('btnLabel').innerHTML = label;
} //}}}
function switchView() //{{{
{
  if(document.location.href.search(/\/showlist\//)!= -1) {
    document.location.href = document.location.href.replace(/\/showlist\//,"/show/");
  } else {
    document.location.href = document.location.href.replace(/\/show\//,"/showlist/");
  }
} //}}}
function resizeImg() //{{{
{
  if(document.location.href.search(/\/show\//) !== -1) {
    newH = 965;
  }else { 
    newCH = $('#cal').height()+49;
    newEH = $('#events').height()+139;
    if(newCH > newEH) { newH = newCH; } else {
    if(newEH > newCH) { newH = newEH; } }
  }
  if(newH < 816) newH=816;
  $('#bkgdimg').height(newH);
} //}}}
function pad(number, length, chr) //{{{
{
  var str = '' + number;
  while (str.length < length) {
      str = chr + str;
  }
  return str;
} //}}}

