﻿//
// GENERAL USE
//
function submitNow(a, group){
if (typeof(Page_ClientValidate) == 'function'){
  if(group.length > 0 && Page_ClientValidate(group)){
    __doPostBack(a.id.replace("_","$"),'');
    a.className+=' processing';
}}else{
  __doPostBack(a.id.replace("_","$"),'');
  a.className+=' processing';
}return false;}

function returnPageValidityWFeedback(a,group){
    if (typeof(Page_ClientValidate) == 'function'){
        if(group.length > 0 && Page_ClientValidate(group)){
            a.className+=' processing';
            return true;
        }
    }else{
        return true;
    }
}
function submitNowWOptions(a, group){
if (typeof(Page_ClientValidate) == 'function'){
  if(group.length > 0 && Page_ClientValidate(group)){
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(a.id.replace("_","$"),"",true,group,"",false,true));
    a.className+=' processing';
}}else{
  __doPostBack(a.id.replace("_","$"),'');
  a.className+=' processing';
}return false;}

// INVALID B/C METHODS ARE PROPERTIES IN JS, SO YOU CAN'T OVERRIDE  function GetObjectPos(o){return GetObjectPos(o,true,false);}
// INVALID B/C METHODS ARE PROPERTIES IN JS, SO YOU CAN'T OVERRIDE  function GetObjectPos(o,IgnoreOutterMost){return GetObjectPos(o,IgnoreOutterMost,false);}
function GetObjectPos(obj,ignoreOutter,X){
    var offset=0;var last=0;// X-> true means X false means Y.  i->true means ignore outtermoust
    if (obj.offsetParent){
        do{
           /* if (obj.className)
                alert(obj.offsetTop.toString() + " " + obj.id + " (" + obj.className + ")");
            else
            alert(obj.offsetTop.toString() + " " + obj.id);*/
            if ((X ? obj.offsetLeft : obj.offsetTop) > 0){
               last=(X ? obj.offsetLeft : obj.offsetTop);offset+=last;
            }
        }while (obj = obj.offsetParent);
        if(ignoreOutter){
            offset-=last;
        }
    }
    return offset;
}

function realPreviousSibling(node){
    var tempNode=node.previousSibling;
    while(tempNode.nodeType!=1){
        tempNode=tempNode.previousSibling;
    }
    return tempNode;
}

function ResolveUrl(path){
    var mydirs = window.location.pathname.substr(window.location.pathname.indexOf('/CinchWeb/') === 0 ? 10 : 1).split('/').length-1;
    var retVal = '';
    for(i=0;i<mydirs;i++){
        retVal += '../';
    }
    return retVal + path;
}

/// 
/// helper functions
///
String.prototype.startsWith = function(str){return (this.match("^"+str)==str);};

function NoHTML(source, args){args.IsValid = (args.Value.search(/(<(.+)>)/ig) >= 0 ? false : true);}


function nocb(){}
/// fades an object from view.  requires jquery.
function fadeThis(liID){
    var options = {};
    $(liID).hide('blind',options,500,nocb);
}

function getWebPath(){return window.location.pathname;} ///CinchWeb/default.aspx
// INVALID B/C METHODS ARE PROPERTIES IN JS, SO YOU CAN'T OVERRIDE  function getWebRoot(){return getWebRoot(null,true);}
// INVALID B/C METHODS ARE PROPERTIES IN JS, SO YOU CAN'T OVERRIDE  function getWebRoot(option){return getWebRoot(option, true);}
function getWebRoot(option, wProtocol){
  /*if(document.getElementsByTagName){
    var elems = document.getElementsByTagName('base');
    if(elems.length){alert(elems[0].href); return = elems[0].href;}
  } 
  alert(window.location.protocol + window.location.host + window.location.path);
  return window.location.protocol + window.location.host + window.location.path; 
  
  
   var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }*/
    var root = (wProtocol ? window.location.protocol + "//" : "") + window.location.host + "/";
    
    if (option === null){
        return (window.location.host.toLowerCase().startsWith("localhost") ? root + "CinchWeb/" : root);
    }else{
        return (wProtocol ? window.location.protocol + "//" : "") + option + ".cinch.fm/";
    }
}
var RegisterFirst = function(followUrl,feedID){
    var s = getWebRoot(null,true) + "register.aspx?ReturnUrl=" + encodeURIComponent(getWebPath());
    var bquery = window.location.search.length > 0;
    if (bquery){
        s += encodeURIComponent(window.location.search);
    }
    if (typeof(followUrl) !== 'undefined'){
        s += encodeURIComponent((bquery?"&":"?")+ "FollowUrl="+escape(followUrl));
    }else if(typeof(feedID) !== 'undefined'){
        s += encodeURIComponent((bquery?"&":"?")+ "FollowFeedID="+feedID);
    }
    window.location.href = s;
    return false;
};
var flash_array = null; // will hold the most recent player.

///
/// DYNAMICALLY-INSTANTIATED PLAYER
/// urlOption controls which env we instantiate from.
function CreatePlayer(div, ID, playlistFile, width, height, urlOption){
    // kill any active players.
    if (flash_array !== null && flash_array.onclick !== undefined){
        $('#'+flash_array.flashID).replaceWith("<div id='" + flash_array.divID + "' class='cplayer faux'>&nbsp;</div>");
        $('#'+flash_array.divID).attr('onclick',flash_array.onclick);
        if($('#'+flash_array.divID).attr('onclick')===null)
        {
            document.getElementById(flash_array.divID).setAttribute("onclick",flash_array.onclick);
        }
        flash_array = null;
    }
    if (flash_array === null){
        flash_array = {};
    }
    flash_array.divID = div.id; // divPlayerctl00_ContentMain_Cinchs1_rptCinch_ctl07 (cplayer faux)
    flash_array.flashID = ID; //12667]
    if (typeof($(div).attr('onclick')) !== 'undefined' && $(div).attr('onclick') != null){
        var oc=$(div).attr('onclick');
       
        if (typeof(oc) === 'function'){
            oc = oc.toString();
        }
        oc=oc.substr(oc.indexOf('Create',10));
        oc=oc.substr(0,oc.indexOf('}',10)-1);
        flash_array.onclick = oc;
    }
    
    var webroot = getWebRoot(urlOption,true);
    var fname = webroot + "cinchplayer.swf";

    var callbackurl = webroot + "flashplayercallback.aspx?referrer_url=" + escape(window.location.pathname);
    var plist = webroot + playlistFile;
    var flashvars = {};
    flashvars.file = plist;
    flashvars.autostart = "true";
    flashvars.bufferlength = "5";
    flashvars.volume = "80";
    flashvars.callback = callbackurl;
    var params = {};
    //params.quality = "high";
    params.menu = "false";
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = ID;
    attributes.name = fname;
    attributes.styleclass = "flash cplayer";
    swfobject.embedSWF(fname, div.id, width, height, "9.0.0", false, flashvars, params, attributes);
    div.className = "cplayer";
    div.removeAttribute("onclick");
}


//
// REPLY-SPECIFIC
//
function saveAudioReply(){
    $('#recordPanelReply').addClass('hide');
    $('#rrtop .recorder').empty().html('<div id="recorderReply"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>');
    var baseID = $('#hdnReplyCinch').val()+'_spnRecorded';
    $('#'+baseID).removeClass('hide').siblings('span.rhover').removeClass('hide').siblings('a.record').addClass('hide').parent('div.record').next().removeClass('hide');
    return false;
}
function cancelReplyRecord(){
    $('#recordPanelReply').addClass('hide');
    $('#'+$('#hdnReplyCinch').val() + "_hdnAudioFile").val('');
    $('#rrtop .recorder').empty().html('<div id="recorderReply"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>');
}
function showReplyBoxStd(li,trackName)
{
    var $li = $('#'+li).removeClass('hide');
    // just in case there's a bug and the replies ul is hidden
    if ($li.parent().is('ul.replies.hide')){
        $li.parent().removeClass('hide');
    }
    document.getElementById(li.replace("_liAdd","_txtAdd")).focus();
    pageTracker._trackEvent(trackName,'Reply','Click');return false;
}
function showReplyFlash(filenm){
    var flashvars = {};
    flashvars.URI = "rtmp://ec2-184-73-78-25.compute-1.amazonaws.com:1935";
    flashvars.filename = filenm;
    var params = {};
    params.quality = "high";
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "Recorder2";
    attributes.name = "Recorder2";
    attributes.styleclass = "flash";
    swfobject.embedSWF(getWebRoot(null,true) + "user/Recorder.swf", "recorderReply", "250", "137", "10.0.0", false, flashvars, params, attributes);
}
//function CheckReplyTxtBox(sender,args){args.IsValid = (args.Value == '' || args.Value=='Add a reply...' ? false : true);}
function ReplySubmitSet(b, txtID, valID, cid){
    var $bb = $('#'+b);
    var $val = $('#'+valID);
    var $txt = $('#'+txtID);
    var $audio = $('#'+txtID.replace("txtAdd","hdnAudioFile"));
    if (($txt.val() === 'Add a reply...' || $txt.val() === '') && $audio.val().length < 2){ 
        $txt.focus();
        $val.removeClass('hide').html('Reply text or audio required.');
        $bb.removeClass('processing');
        return false;
    }else if ($txt.val().search(/(<([^a>)]+)>)/ig) >= 0){
        $txt.val($txt.val().replace(/(<([^a>)]+)>)/ig,"")).removeClass('hide').html('Reply cannot contain those HTML characters.');
        $txt.focus();
        $bb.removeClass('processing');
        return false;
    }else{
        $val.addClass('hide');
        $bb.addClass('processing').attr('disabled','disabled');
        var tt = setTimeout("ResetReplyAction('" + cid.toString() + "','" + $audio.val() + "','" + escape($txt.val()) + "','" + b + "');",repostDelay);
        var aa = [tt,1];
        rHash.setItem(cid.toString(),aa);
        $.getJSON(ResolveUrl('ajax2.aspx?arg=reply&txt='+escape($txt.val())+'&audio='+$audio.val()+'&rid='+cid.toString()+'&ctx='+b)+'&JSONCallback=?',recReplyServerDataNewReply);
    }
}

function ResetReplyAction(rid, audio, text, buttonID)
{
    // first look to see if the timeout item is still there. if so, it wasn't processed.
    if (rHash.hasItem(rid))
    {
        var aa = rHash.getItem(rid);
        var tt = aa[0];
        var iteration = aa[1];
        rHash.removeItem(rid);
        if (typeof(tt) !== 'undefined' && iteration < 5)
        {
           // if (confirm("Well, this is embarrasing.  The server has not responded yet.  Send your reply again?"))
        //    {
            
                tt = setTimeout("ResetReplyAction('" + rid + "','" + audio + "','" + text + "','" + buttonID + "');",repostDelay);
                aa = [tt,iteration+1];
                rHash.setItem(rid,aa);
                $.getJSON(ResolveUrl('ajax2.aspx?arg=reply&txt='+text+'&audio='+audio+'&rid='+rid+'&ctx='+buttonID)+'&JSONCallback=?',recReplyServerDataNewReply);
                //$.get(ResolveUrl('ajax.aspx'),{'arg':'reply','txt':text,'audio':audio, 'rid': rid,'ctx':buttonID}, recReplyServerDataNewReply);
                //return FetchAsyncReplyResult(text + "<audio>" + audio + "</audio><rid>" + rid + "</rid>", buttonID);
         /*   }
            else
            {
                var bb = document.getElementById(buttonID);
                bb.className="button";
                bb.disabled = false;
            }
            */
        }
    }
}


function DelReplySubmitSet(d, cid, did){
    if (confirm('Are you sure you want to delete this reply?')){
        $('#'+d).addClass('processing').attr('disabled','disabled');
        $.getJSON(
            ResolveUrl('ajax2.aspx?arg=did&did='+did.toString()+'&rid='+cid.toString()+'&ctx='+d)+'&JSONCallback=?', 
            function (jr){$('#'+jr.success.ctx).parent().parent().html(jr.success.Msg);}
        );
    }else{
        return false;
    }
}
var pr = new Array(); /*  pending items.  each item in the array is also an array:
/// [0] the containing div ID
/// [1] the number of attempts to refresh.  stop after 4.*/
var rq = new Array(); // play requests on pending items.
rq[0] = 0;
function QueueReply(rid){
 for(var i=0; i<rq.length;i++){
    if(rq[i] == rid){
        return;
    }
 }
// alert("queued " + rid.toString()); */
 rq[rq.length] = rid;
}
function ExpandReplies(hdn, ul,li){
    document.getElementById(hdn).value = "true";
    var theul = document.getElementById(ul);
    theul.className = theul.className.replace(" hide","");
    document.getElementById(li).style.display="none";
    return false;
}

function recReplyServerStatusCheck(jr){
    if (jr.success){
        jr = jr.success;
        var ctx = jr.ctx;
        if (jr.statusPending){
            for(var k=0; k<pr.length;k++){
        //alert("k=" + k.toString() + " " + pr[k][0] + " b=" + ctx); 
                if(pr[k][0] == ctx){
                    if(pr[k][1] < prtries){
                        pr[k][1] += 1;
                        // alert("#" + pr[k][1].toString() + " & no chnage on " + pr[k][0] + ". will try CheckPendingReply1(" +  jr.statusPending + ",'" + ctx + "'); again in " + prtimeout.toString() + " ms.");
                        setTimeout("CheckPendingReply1(" + jr.statusPending + ",'" + ctx + "');", prtimeout);
                     }/*else{ //alert(prtries.toString() + " tries and no change on " + pr[k][0] + ". stopping check there."); }*/
                }
            }
        }else if (jr.statusDone){ //  alert("status change on " + ctx +  
            for(var i=0; i<pr.length;i++){
                if(pr[i] !== 0 && pr[i][0] === ctx){
                    pr[i] = 0;
                    // now set up the player onclick, or just play it, if they asked for it already.
                    var divPlayerReady = document.getElementById(ctx);
                    for(var j=0; j<rq.length;j++){
                        if (rq[j].toString() === jr.statusDone){
                            //    alert("play previously requested, setting up player now");
                            CreatePlayer(divPlayerReady, jr.statusDone, jr.url,'42','50',null); 
                            pageTracker._trackEvent('Cinch','Audio','Click');
                            rq[j] = 0;
                            divPlayerReady.onclick = null;
                        }else{
                            //   alert("audio for " + jr.statusDone + " is ready.");
                            divPlayerReady.className = "cplayer faux";
                            divPlayerReady.onclick= function() {//alert("no longer pending - creating the player setup now" + jr);
                                CreatePlayer( divPlayerReady, jr.statusDone, jr.url,'42','50',null); pageTracker._trackEvent('Cinch','Audio','Click');};
                        }
                    }
                }
            }
        }else if (jr.statusDeleted){
            for(var d=0; d<rq.length;d++){
                if (rq[d].toString() === jr.statusDeleted){
                    rq[d] = 0;
                }
            }
            // we need to delete the item from the list of li's? nah.  //divPlayerctl00_ContentMain_Cinchs1_rptCinch_ctl07_Replies1_rptReplies_ctl00
            var $li = $('#'+ctx).parent('.time').parent('.box').parent('li');
            if ($li.html().indexOf('Reply deleted.') < 0){
                $li.remove();
            }
        }
    }
}

function recReplyServerDataNewReply(jr){
    var o = jr.success ? jr.success : jr.failure;
    var ctx = o.ctx;
    var bHashed = false;
    if (jr.failure){
        $('#'+ctx.replace('_Replies1_btnSubmit','_liCinch')).remove();
        if (o.Msg){alert(o.Msg);}
        return;
    }
    // cancel any pending timeout 
    if (o.pid && rHash.hasItem(o.pid)){
        rHash.removeItem(o.pid);
        bHashed = true;
    }
    
    var $b = $('#'+ctx).removeClass('processing').removeAttr('disabled');
    $b.siblings(':text').val('Add a reply...');
    var b = $b[0];
    var ul = b.parentNode.parentNode.parentNode.parentNode;  // ul
    var li = b.parentNode.parentNode.parentNode;  // the add box.
    var liPagerTop = null;
    if(ul.getElementsByTagName("li")[0].className==="pageing"){
        liPagerTop = ul.getElementsByTagName("li")[0];
    }
    var numReplies = ul.getElementsByTagName("li").length;
    if (liPagerTop !== null){ // if we have a pager, we'll be adding this to the 
        numReplies -= 2;
    }
    
    if (bHashed){
        var newObject = document.createElement("li");
        ul.removeChild(li);
        if(liPagerTop !== null && numReplies > 0){
            ul.insertBefore(newObject,ul.getElementsByTagName("li")[1]); // puts it just after the top pager at the top of the stack of replies
        }else{
            ul.appendChild(newObject, null);
        }
        ul.appendChild(li);
        newObject.innerHTML = o.reply;
    }
    if (o.divAudioID){
        // this is something that should update on a timer.
        if (!document.getElementById(o.divAudioID)){
          alert("ERROR: DOM IS NOT SET!");
        }else{
          AddPendRepCheck(o.divAudioID, parseInt(o.rid,10));
        }
    }
    // now if audio was involved, we need to reset the audio controls.... 
    $b.parent().siblings('div.record').children('a.record').removeClass('hide').siblings('span.recorded').addClass('hide').siblings('span.rhover').addClass('hide').parent('div.record').prev().val('').end().siblings('div.msg.clearall').addClass('hide');
}


function ClientErrorCallBack(arg){alert("Error!: " + arg);}
function AddPendRepCheck(divID, rid){
    var found = false;
    for(var k=0;k<pr.length;k++){
        if(pr[k][0] === divID){
            found = true;
        }
    }
    // alert("adding " + rid + " to a timered check");
    if (!found){
        var dm = new Array(2);
        dm[0] = divID;
        //dm[1] = setTimeout("CheckPendingReply1(" + rid.toString() + ",'" + divID + "');", prtimeout);
        dm[1] = 0;// no checks yet.
        pr[pr.length] = dm;
        setTimeout("CheckPendingReply1(" + rid.toString() + ",'" + divID + "');", prtimeout);
    }//else alert("problem: trying to add a reply check twice");
}
function CheckPendingReply1(rid, divID){
/* for(var k=0; k<pr.length;k++)
  if(pr[k][0] == divID)
    if(pr[k][1] >= prtries){
       alert(prtries.toString() + " tries and no change on " + pr[k][0] + ". stopping check there.");
    }else{
   //   pr[k][1] += 1;
      alert("checking " + pr[k][1].toString() + " " + rid.toString());*/
      $.getJSON(ResolveUrl('ajax2.aspx?arg=raudiocheck&divID='+divID+'&rid='+rid.toString()+'&ctx='+divID)+'&JSONCallback=?',recReplyServerStatusCheck);
      //$.get(ResolveUrl('ajax.aspx'),{'arg':'raudiocheck','divID':divID,'rid':rid.toString(),'ctx':divID}, recReplyServerStatusCheck);
//return FetchAsyncReplyResult("<divID>" + divID + "</divID><rid>" +rid.toString() + "</rid>", divID);
// }
}


///
/// Album Popup JS
///
function ShowTBAlbum(bShow,txtEditID,lblEditID,lblShowID,aUpdateID,lblCancelID,hdnID,hdnvalue){
if (bShow){
document.getElementById(lblEditID).style.display='none';
var txt = document.getElementById(txtEditID);
txt.className=txt.className.replace(" hide","");
txt.focus();
document.getElementById(lblShowID).style.display='none';
document.getElementById(aUpdateID).style.display='';
var cancel = document.getElementById(lblCancelID);
cancel.className=cancel.className.replace(" hide","");
document.getElementById(hdnID).value=hdnvalue;
}else{
document.getElementById(lblEditID).style.display='';
document.getElementById(txtEditID).className += " hide";
document.getElementById(lblShowID).style.display='';
document.getElementById(aUpdateID).style.display='none';
document.getElementById(lblCancelID).className += " hide";
document.getElementById(hdnID).value="";
}}

///
/// Editing a Cinch (popup)
///
function caleditDate(val,spanID){
  document.getElementById(spanID).style.display = (val == "c" ? "" : "none");
  if (val === "c"){showEditCal();}
}
function setRadEditWaitUI(RadID){
    var dis = document.getElementById(RadID).getElementsByTagName("input");
    var baseID = RadID.substring(0,RadID.lastIndexOf("_"));
    var i = 0;
    for(i=0; i<dis.length;i++){
        if (dis[i].className==="ruButton ruBrowse"){
            dis[i].value="wait...";
        }else if (dis[i].className==="ruFakeInput"){
            var fakePathString = "fakepath";
            if (dis[i].value.indexOf(fakePathString) > -1){
                var fakePathLength = dis[i].length + dis[i].value.indexOf(fakePathString) + 1;
                dis[i].value = dis[i].value.substring(fakePathLength);
            }
        }
    }
    document.getElementById(baseID + '_lbtnCancel').style.display='none';
    document.getElementById(baseID + '_lbtnClose').style.display='none';
    document.getElementById(baseID + '_lbtnSubmit').style.display='none';
    document.getElementById(baseID + '_lblEditTitle').innerHTML += " (loading...)";
}
function yPosEdit(obj)
{
    document.getElementById('ctl00_ContentMain_EditExistingCinch1_hdnYPos').value = GetObjectPos(obj,true,false).toString();
}

///
/// RECORDING CINCH CODE
///
function showRecorderFlash(filenm){
    var flashvars = {};
    flashvars.URI = "rtmp://ec2-184-73-78-25.compute-1.amazonaws.com:1935";
    flashvars.filename = filenm;
    var params = {};
    params.quality = "high";
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "Recorder1";
    attributes.name = "Recorder1";
    attributes.styleclass = "flash";
    swfobject.embedSWF(getWebRoot(null,true) + "user/Recorder.swf", "recorderMainCinch", "250", "137", "10.0.0", false, flashvars, params, attributes);
}
//ctl00_ContentMain_Record1
function SetImgUploadUIFeedback(blockID,RadID0){
    document.getElementById(blockID + '_aAttachPic').className = "picprocessing";
    var txt = document.getElementById(blockID +'_txtDescription');
    txt.value='processing image, please wait...';
    txt.disabled = true;
    btn = document.getElementById(blockID +'_aSubmit2');
    btn.className+=" processing";
    txt.className="ctext";
    btn.innerHTML = "wait";
    btn.disabled=true;
    document.getElementById(RadID0).disabled=true; 
}
function DeletingNewCinchPic(ibtn,blockID)
{
    var txt = document.getElementById(blockID +'_txtDescription');
    ibtn.className+=' processing';
    document.getElementById(blockID +'_hdnText').value = txt.value;
    
    var btn = document.getElementById(blockID +'_aSubmit2');
    btn.className+=' processing';
    btn.innerHTML = "wait";
    btn.disabled=true;
   
    txt.value = 'removing image, please wait...';
    txt.className="ctext";
    txt.disabled = true;
}
function setNewCinchClickUI(abtn)
{
    var blockID = abtn.id.substring(0,abtn.id.lastIndexOf("_"));
    abtn.className+=' processing';
    abtn.innerHTML='processing';
    var txt = document.getElementById(blockID + '_txtDescription');
    txt.className="ctext";
    txt.value = 'submitting cinch, please wait...';
    txt.disabled=true;
    document.getElementById('cimgupmsg').style.display = "none";
    
}

///
/// albums chooser (simple drop down)
///
function GetThisAlbum(hdnID, option,btnID){
    document.getElementById(hdnID).value = option.value;
    document.getElementById(btnID).click();
}

///
/// SINGLE CINCH VIEW RELATED.
///
function DoFollow(FeedUrl, id){
    var b = document.getElementById(id);
    var bSubscribe = (b.innerHTML === "Follow" ? true : false);
    b.innerHTML = "wait";
    return FetchFollowAsyncResult(bSubscribe.toString() + "<feedUrl>" + FeedUrl + "</feedUrl><albumUrl></albumUrl>",id);
}
function recieveServerDataFollow(arg, ctx){document.getElementById(ctx).innerHTML = (arg == "1" ? "Unfollow" : "Follow");} 
function ClientErrorCallBackFollow(arg){alert("Error!: " + arg);}




///
/// large image popup
///
function LoadPlayerIMG(CinchID,playlistFile,urlOption){CreatePlayer(document.getElementById("divImgPlayer"),"LIP"+CinchID,playlistFile,'84','100',urlOption);}
function ShowImg(obj,imgsrc,CinchID,playlistFile,urlOption,addYOffset){
    //var winX = (document.all)?window.screenLeft:window.screenX;
    var top = document.body.scrollTop ? document.body.scrollTop : (window.pageYOffset ? window.pageYOffset : (document.body.parentElement ? document.body.parentElement.scrollTop : 0 ));
        //var offset = GetObjectPos(document.getElementById('mpIMG'),false,false);
        
    top += (20); //GetObjectPos(obj,true,false);
    document.getElementById('imgFull').setAttribute("src",imgsrc);
    document.getElementById('mpIMG').style.top = top.toString() + "px";
    document.getElementById('divImagePopup').style.display='';
    if (!document.getElementById('divImgPlayer')){document.getElementById('divImgPlayerOuter').innerHTML = "<div id='divImgPlayer'> </div>";}
    if (playlistFile != null){LoadPlayerIMG(CinchID,playlistFile,urlOption);}
}

function closeCImgPopup(){
    if(navigator.appName == "Microsoft Internet Explorer"){ 
        var ver = navigator.appVersion;ver = ver.substr(ver.indexOf("MSIE ")+5);
        if (parseFloat(ver.substr(0,ver.indexOf(";"))) >= 8.0){
            var innerObj = document.getElementById('divImgPlayerOuter').getElementsByTagName("object")[0];
            if (innerObj){
                swfobject.removeSWF(innerObj.id);
                document.getElementById('divImgPlayerOuter').innerHTML='<div id=\'divImgPlayer\'> </div>';
            }
        }
    }
    document.getElementById('imgFull').src='/Img/blank.gif';document.getElementById('divImagePopup').style.display='none';return false;
}
///
/// EMBED popup
///
function SetEmbed(obj,rid,mode){
    document.getElementById('mpEmbed').style.top = (GetObjectPos(obj,true,false)-28).toString()+"px";
    document.getElementById('divEmbedPopup').style.display='';
    var webroot = getWebRoot(null,true);
    var txtt = "<embed src=\"" + 
    webroot + "cinchplayerext.swf\" flashvars=\"file=" + 
    webroot.replace(/\//gi,"%2f") + 
    "cinchplaylist.aspx%3FRecordingID%3D" + 
    rid + 
    "&playermode="+
    mode+
    "&amp;autostart=false&amp;bufferlength=5&amp;volume=80&amp;callback=" + 
    webroot + 
    "flashplayercallback.aspx&width=300&height=200&volume=80&corner=rounded\" menu=\"false\" wmode=\"transparent\" quality=\"high\" name=\"" + 
    rid + "\" id=\"" + 
    rid + "\"" + 
    " width=\"300\" height=\"200\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" allowScriptAccess=\"always\"></embed>";
    document.getElementById('txtembedcode').value=txtt;
}


///
/// RSS FLYOVER
///        
function SetRSSForPop(link,feedurl,hdnID){
    RssTop(link);
    link.className+=' processing';
    $('#'+hdnID).val(feedurl);
    if(pageTracker){pageTracker._trackEvent('Cinch','Subscribe','Click');}
}

//var rss_b_bIsIE6=(navigator.userAgent.indexOf("MSIE 6") > 0);
var rss_offsetxpoint=-5; //Customize x offset
var rss_offsetypoint=-5; //Customize y offset
var rss_ie=document.all;
var rss_ns6=(document.getElementById && !document.all);
var rss_enableRssFlyover=false;
var currX = 0;
var currY = 0;
var currW = 0;
var currH = 0;
var rss_curX=0;
var rss_curY=0;
var rss_tipobj=null;
if (rss_ie||rss_ns6){
    rss_tipobj=document.all? document.all.dhtmlRss : document.getElementById? document.getElementById('dhtmlRss') : '';
}

function rss_ietruebody(){return ((document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body);}

/*
function loaddhtmlRss3(obj,bUseNewWindows, TheUrl,bUseItunes ){
	var thewidth = 93;
	var theheight = (bUseItunes ? 191 : 175);
	if (rss_ie||rss_ns6){
		var thetext = EmitRSSFly(bUseNewWindows,TheUrl,bUseItunes)
        if (typeof thewidth!='undefined'){ 
			rss_tipobj.style.width=thewidth+'px'
			currW=thewidth}
		if (typeof theheight!='undefined'){ 
			rss_tipobj.style.height=theheight+'px'
			currH=theheight
		}else{currH=0}
		rss_tipobj.style.top = (GetObjectPos(obj,false,false)-102).toString() + "px";
		rss_tipobj.style.left = GetObjectPos(obj,false,true).toString() + "px";
		rss_tipobj.style.visibility='visible';
		rss_tipobj.innerHTML=thetext + "<iframe id='therssiframe' style='width: " + (thewidth+4) + "px; height: " + (currH > 0 ? currH + "px" : "100%") + ";'></iframe>"
		rss_enableRssFlyover=true
		return false
	}
}*/
function StopMouseListen()
{
    
    if (document.addEventListener){ // DOM Level 2 Event Model
        //if (eval("document.onmousemove"))
        document.removeEventListener("mousemove", rss_positiontip, false);
    }else if (document.attachEvent){
        //if (document.mousemove)
        //{
         //   alert("eval in ie was true");
        document.detachEvent("onmousemove",rss_positiontip);
        //alert("ie5 model removed listener");
       // }
    }
}
function AddMouseListen()
{
    if (document.addEventListener){ // DOM Level 2 Event Model
        document.addEventListener("mousemove", rss_positiontip, false);
    }else if (document.attachEvent){ // IE 5+ Event Model
        document.attachEvent("onmousemove", rss_positiontip);
    }
    //alert('added event capturing');
}
/*
getEvent = function(event, property) {
    if (event.isSetup)
        return event;
    if (isIE) {
        event = window.event;
        event.stopPropagation = new Function("this.cancelBubble = true");
        event.preventDefault = new Function("this.returnValue = false");
        event.target = event.srcElement;
        if ("fromElement" in event)
        event.relatedTarget = event.fromElement;
        else if ("toElement" in event)
        event.relatedTarget = event.toElement;
        if (!("layerX" in event) && "offsetX" in event) {
            event.layerX = event.offsetX;
            event.layerY = event.offsetY;
        }
    } else {
        if (event.target.nodeType == 3) event.target = event.target.parentNode;
    }
    if ("button" in event)
        event.mouseButton = event.button != 2 ? 1 : 2;
    if (!("pageX" in event) && "clientX" in event) {
        event.pageX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
        event.pageY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
    }
    event.stop = stop;
    event.find = find;
    event.isSetup = true;
    return event;
};*/

function loaddhtmlRss2(bUseNewWindows, TheUrl,bUseItunes ){
    StopMouseListen();
    AddMouseListen();

    if (rss_tipobj === null){
        rss_tipobj=document.all? document.all.dhtmlRss : document.getElementById? document.getElementById('dhtmlRss') : '';
    }
	var thewidth = 93;
	var theheight = bUseItunes ? 191 : 175;
	if (rss_ie||rss_ns6){
		var thetext = EmitRSSFly(bUseNewWindows,TheUrl,bUseItunes);
        if (typeof thewidth!='undefined'){ 
			rss_tipobj.style.width=thewidth+'px';
			currW=thewidth;
		}
		if (typeof theheight!='undefined'){ 
			rss_tipobj.style.height=theheight+'px';
			currH=theheight;
		}else{
			currH=0;
		}
		rss_tipobj.innerHTML=thetext + "<iframe id='therssiframe' style='width: " + (thewidth+4) + "px; height: " + (currH > 0 ? currH + "px" : "100%") + ";'></iframe>";
		rss_enableRssFlyover=true;
		return false;
	}
}


function rss_positiontip(e){
	rss_curX=(rss_ns6)?e.pageX : event.clientX+rss_ietruebody().scrollLeft;
	rss_curY=(rss_ns6)?e.pageY : event.clientY+rss_ietruebody().scrollTop;
	if (rss_enableRssFlyover){
		rss_enableRssFlyover=false;
		//Find out how close the mouse is to the corner of the window
		var rss_rightedge=rss_ie&&!window.opera? rss_ietruebody().clientWidth-event.clientX-rss_offsetxpoint : window.innerWidth-e.clientX-rss_offsetxpoint-20;
		var bottomedge=rss_ie&&!window.opera? rss_ietruebody().clientHeight-event.clientY-rss_offsetypoint : window.innerHeight-e.clientY-rss_offsetypoint-20;
		var leftedge=(rss_offsetxpoint<0)? rss_offsetxpoint*(-1) : -1000;
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rss_rightedge<rss_tipobj.offsetWidth){
            //move the horizontal position of the menu to the left by it's width
			currX = rss_ie? rss_ietruebody().scrollLeft+event.clientX-rss_tipobj.offsetWidth : window.pageXOffset+e.clientX-rss_tipobj.offsetWidth;
		}else if (rss_curX<leftedge){
            currX=5;
		}else{
            //position the horizontal position of the menu where the mouse is positioned
			currX=rss_curX+rss_offsetxpoint;
		}
		rss_tipobj.style.left=currX+'px';
		//same concept with the vertical position
		if (bottomedge<rss_tipobj.offsetHeight){
		    currY=rss_ie? rss_ietruebody().scrollTop+event.clientY-rss_tipobj.offsetHeight-rss_offsetypoint : window.pageYOffset+e.clientY-rss_tipobj.offsetHeight-rss_offsetypoint;
		}else{
            currY=rss_curY+rss_offsetypoint;
        }
		rss_tipobj.style.top=currY+'px';
		rss_tipobj.style.visibility='visible';
	}else if(rss_tipobj.style.visibility=='visible' && ((rss_curX<currX || rss_curX > (currX+currW)) ||(rss_curY<currY || rss_curY>(currY+currH)))){
		rss_hideFlyover();
	}
}

function rss_hideFlyover(){
    if (rss_ns6||rss_ie){
        rss_enableRssFlyover=false;
		rss_tipobj.style.visibility='hidden';
		rss_tipobj.style.left='-1000px';
		StopMouseListen();
	}
}

function EmitRSSFly(newWindows,burl,showItunes){
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); 
    var webRoot = getWebRoot(null,true);
    burl = webRoot.replace("http://","") + burl;
    var burlesc = escape(burl).replace("+"," ");
    var btml = [];
    btml.push("<div class='rss-feed-div2' id='FeedList_Popup'>");
    btml.push("<ul class='rss-feed2' id='FeedList'>");
    // add this
    btml.push("<li><a class='add2' ");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" title='Subscribe to my feed' id='aSubscribAny' href=\"http://");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // itunes
    if(showItunes){
        btml.push("<li><a");
        if (newWindows){btml.push(" target='_blank'");}
        btml.push(" id='aItunes' class='imgItunes' href=\"itpc://");
        btml.push(burl);
        btml.push("\">&nbsp;</a></li>");
    }
    // GOOGLE READER
    btml.push("<li><a class='imgRssGoogle' ");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" href=\"http://fusion.google.com/add?feedurl=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // YAHOO READER
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssYahoo' href=\"http://add.my.yahoo.com/rss?url=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // BLOGLINES
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssBloglines' href=\"http://www.bloglines.com/sub/");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // NEWSGATOR
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssNewsgater' href=\"http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // MY MSN
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssMsn' href=\"http://my.msn.com/addtomymsn.armx?id=rss&amp;ut=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // TECHNORATI
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssTechnorati' href=\"http://technorati.com/faves?add=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // LIVE.COM
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssWindowslive' href=\"http://www.live.com/?add=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    // ADD THIS
    btml.push("<li><a");
    if (newWindows){btml.push(" target='_blank'");}
    btml.push(" class='imgRssAddthis' href=\"http://www.addthis.com/bookmark.php?pub=cinchcast&amp;url=http%3a%2f%2f");
    btml.push(burlesc);
    btml.push("\">&nbsp;</a></li>");
    btml.push("</ul></div>");
    return btml.join("");
    // this is just so that it pre-loads the images.  When sent a blank url, it doesn't show it, just sets the html.
}


///
///  This code is here to provide hash table capabilities.  Named in order to avoid namespace conflicts with jquery and prototype.
///  http://www.mojavelinux.com/articles/javascript_hashes.html
function ZHash(){
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) !== 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
		
	}
	this.removeItem = function(in_key){
		var tmp_previous;
		if (typeof(this.items[in_key]) !== 'undefined') {
			this.length--;
			tmp_previous = this.items[in_key];
			delete this.items[in_key];
		}
		return tmp_previous;
	};
	this.setItem = function(in_key, in_value){
		var tmp_previous;
		if (typeof(in_value) !== 'undefined') {
			if (typeof(this.items[in_key]) === 'undefined') {
				this.length++;
			}else {
				tmp_previous = this.items[in_key];
			}
			this.items[in_key] = in_value;
		}
		return tmp_previous;
	};

	this.hasItem = function(in_key){return typeof(this.items[in_key]) != 'undefined';};

	this.clear = function(){
		for (var i in this.items){
		    delete this.items[i];
		}
		this.length = 0;
	};
	
	// this is supposedly kinda slow but avoids exposing the internal Array items.  
	this.getItem = function(in_key) {
		return this.items[in_key];
	};
}
var rHash = new ZHash(); // request hash
var udHash = new ZHash(); // undelete hash
var repostDelay = 8000;

///////////////////////widget stuff
function CreateCustomizer(div, ID, userurl, urlOption, width, height){
    var webroot = getWebRoot(null,true);
    var fname = webroot + "customizer.swf";

    var plist = webroot + "playerops.aspx?userurl="+userurl+"%26op=getusersfollowing";
    var flashvars = {};
    flashvars.userDataProvider  = plist;
    flashvars.showAllCinches  = "false";
    flashvars.autoPlay  = "false";
    flashvars.volume = "80";
    flashvars.minimumCinches = "20";
    var params = {};
    //params.quality = "high";
    params.menu = "false";
    params.wmode = "transparent";
    params.allowScriptAccess="always";
    var attributes = {};
    attributes.id = ID;
    attributes.name = fname;
    swfobject.embedSWF(fname, div, width, height, "9.0.115.0", false, flashvars, params, attributes);
}

function thisMovie(movieName){return document[movieName];}

function getEmbedCode(){thisMovie("cinchWidget").getEmbedCode();}

function previewWidget(widgetWidth, widgetHeight, feedURL, cinchCount, autoStart, autoIncrement, listLoop, initCinchNum, headerGradient, headerSolidColor, headerGradientColor1, headerGradientColor2, headerGradientColor3, headerGradientColor4, detailsBaseColor, detailsTextColor, itemTextColor, buttonIconColor, buttonBorderColor, scrollerColor, scrollerHoverColor, widgetVolume) {
  var cw = new SWFObject("ccwidget.swf", "cinchWidget", widgetWidth, "440","9.0.115.0");  
   cw.addParam("allowScriptAccess","always");
   cw.addVariable("width", widgetWidth);
   cw.addVariable("height", "440");
   cw.addVariable("feed", feedURL.replace("http://www.cinchcast.com/",getWebRoot(null,true)));
   cw.addVariable("cinchCount", cinchCount);
   cw.addVariable("autoStart", autoStart);
   cw.addVariable("autoIncrement", autoIncrement);
   cw.addVariable("listLoop", listLoop);
   cw.addVariable("initialItem", initCinchNum);
   cw.addVariable("headerGradient", headerGradient);
   cw.addVariable("headerColor", headerSolidColor);
   cw.addVariable("headerColor1", headerGradientColor1);
   cw.addVariable("headerColor2", headerGradientColor2);
   cw.addVariable("headerColor3", headerGradientColor3);
   cw.addVariable("headerColor4", headerGradientColor4);
   cw.addVariable("detailsBaseColor", detailsBaseColor);
   cw.addVariable("detailsTextColor", detailsTextColor);
   cw.addVariable("itemTextColor", itemTextColor);
   cw.addVariable("buttonIconColor", buttonIconColor);
   cw.addVariable("buttonBorderColor", buttonBorderColor);
   cw.addVariable("scrollerColor", scrollerColor);
   cw.addVariable("scrollerHoverColor", scrollerHoverColor);
   cw.addVariable("volume", widgetVolume);
   cw.write("widgetContainer");
}
  
function previewWidget2() { // is this even used? I don't think it is.
    var webroot = getWebRoot(null,true);
    var fname1 = webroot + "ccwidget.swf";
    alert(feedURL);
    if (feedURL!==undefined){
        var plist1 = feedURL;
        var flashvars1 = {};
        flashvars1.feed  = plist1;
        flashvars1.cinchCount  = cinchCount;
        flashvars1.autoStart  = autoStart;
        flashvars1.volume = widgetVolume;
        flashvars1.width = widgetWidth;
        flashvars1.height = widgetHeight;
        flashvars1.autoIncrement = autoIncrement;
        flashvars1.listLoop = listLoop;
        flashvars1.initialItem = initCinchNum;
        flashvars1.headerGradient = headerGradient;
        flashvars1.headerColor = headerSolidColor;
        flashvars1.headerColor1 = headerGradientColor1;
        flashvars1.headerColor2 = headerGradientColor2;
        flashvars1.headerColor3 = headerGradientColor3;
        flashvars1.headerColor4 = headerGradientColor4;
        flashvars1.detailsBaseColor = detailsBaseColor;
        flashvars1.itemTextColor = itemTextColor;
        flashvars1.buttonIconColor = buttonIconColor;
        flashvars1.buttonBorderColor = buttonBorderColor;
        flashvars1.scrollerColor = scrollerColor;
        flashvars1.scrollerHoverColor = scrollerHoverColor;

        var params1 = {};
        //params1.quality = "high";
        //params1.menu = "false";
        //params1.wmode = "transparent";
        params1.allowScriptAccess="always";
        var attributes1 = {};
        attributes1.id = "cinchWidget";
        attributes1.name = "cinchWidget";

        var wc = document.getElementById("widgetContainer");
        alert(wc);
        if(wc===null){wc = document.getElementById("cinchWidget");}
        wc.innerHTML=" ";
        alert(wc);
        swfobject.embedSWF(fname1, wc.id, "280", "440", "9.0.115.0", false, flashvars1, params1, attributes1);
    }
  }
function byebyeblock(id,cspan,blockID){
    var b = document.getElementById(blockID);
    b.className = b.className.replace("shown","");
    //b.className += " hidden";
    setTimeout("fadeAndHide('#"+ blockID + "',250);",0);
    var text = "\"" + b.getElementsByTagName('h4')[0].innerHTML + "\" is now hidden. Click \"Show Hidden\" to display.";
    var newObject = document.createElement("div");
    newObject.className="panel noticemsg grey";
    newObject.id = blockID + "_replacer";
    newObject.innerHTML = text;
    newObject.style.display="none";
    insertAfter(b,newObject);
    // slide it in now.
    setTimeout("showSlide('#" + newObject.id + "',250);",0);
    // set the fader 15 seconds from now
    var theTimeout = setTimeout("fadeAndDel('#" + newObject.id + "',250);", 4000);
    var ahider = $('#aShowHidden > .num')[0];
    var num = parseInt(ahider.innerHTML,10) + 1;
    ahider.innerHTML = num.toString();
    var $p2fH = $('#p2fH');
    var numShown = $p2fH.attr('numshown') - 1;
    $p2fH.attr('numshown',numShown.toString());
    if (numShown == 0){
        $('#p2fH').addClass('hide');
    }
    //fadeThis(blockID);
    return FetchAsyncUBCResult("<close>" + id.toString() + "</close>", cspan.ID);
}
function minmaxblock(id,mmspan,blockID){// jquery takes too long, use non-jquery
  var b =  document.getElementById(blockID);//$('#' + blockID)[0];//
  if (mmspan.className=="maximize"){
    mmspan.className = "minimize";
    b.className = b.className.replace("minimized","maximized");
    //$('#' + blockID).addClass("minimized").removeClass("maximized");
    return FetchAsyncUBCResult("<maximize>" + id.toString() + "</maximize>", mmspan.ID);
  }else{
    mmspan.className = "maximize";
    b.className = b.className.replace("maximized","minimized");
    //$('#' + blockID).addClass("maximized").removeClass("minimized");
    return FetchAsyncUBCResult("<minimize>" + id.toString() + "</minimize>", mmspan.ID);
  }
  
}
function ShowHiddenBlocks()
{
    $('.part.hidden').removeClass("hidden").addClass("shown");
    $('#p2fH').removeClass('hide').attr('numshown',$('#aShowHidden > .num').html());
    $('#aShowHidden > .num')[0].innerHTML = "0";
    $('.panel.noticemsg.grey').remove();
    
    return FetchAsyncUBCResult("<unhide> </unhide>", " ");
}
function recUBCServerData(arg, ctx){ }
// This function inserts newNode after referenceNode
function insertAfter( referenceNode, newNode ){ referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );}
/// fades an object from view.  requires jquery.
function fadeAndDel(obj,time){var options = {};$(obj).hide('blind',options,time,function(){$(this).remove();});}
function fadeAndHide(obj,time){var options = {};$(obj).hide('blind',options,time,function(){$(this).addClass("hidden").css({display:''});});}
function showSlide(obj,time){var options = {};$(obj).show('blind',options,time,function(){$(this).css({display:''});});}

var theDelTimeout;
function DelCinch(link, rid){
    if (pageTracker){
        pageTracker._trackEvent('Cinch','Delete','Click');
    }
    if(confirm('Are you sure you want to delete this cinch?')){
        var lid = $(link).parent().parent().attr('id');
        udHash.setItem(lid,$('#'+lid).html()); // save for undelete        
        $(link).addClass('processing').html('&nbsp;');
        $.getJSON(ResolveUrl('ajax2.aspx?arg=delc&rid='+rid+'&lid='+lid+'&ctx='+lid)+'&JSONCallback=?',
            function recReplyServerDataCinchDel(jr){
                var o = jr.success ? jr.success : jr.failure;
                var ctx = o.ctx;
                var $li = $('#'+ctx); 
                if (!jr.success){
                    $li.remove();
                    if (o.Msg){ alert(o.Msg);}
                    return;
                }else{    
                    $li.html(o.html);
                    var jdelay = function(){fadeThis('#'+ctx);};
                    theDelTimeout = setTimeout(jdelay, 15000);
                }
            }
        );
    }
}


function UndoCinchDelete(link){
    if (pageTracker){
        pageTracker._trackEvent('Cinch','undelete','Click');
    }
    clearTimeout(theDelTimeout);
    var lid = $(link).addClass('processing').parent().parent().parent().attr('id');
    $.getJSON(ResolveUrl('ajax2.aspx?arg=udelc&rid='+$(link).attr('id').replace('adel','')+'&lid='+lid+'&ctx='+lid)+'&JSONCallback=?',
        function (jr){
            var ctx = jr.success.ctx;
            var $li = $('#'+ctx);
            if (udHash.hasItem(ctx)){
                $li.html(udHash.getItem(ctx));
                udHash.removeItem(ctx);
            }
        }
    );
}



function delFlv(link){//reverts to the "record a cinch" view.
    $('#'+$(link).attr('id').replace('_aRemove','')+'_spnRecorded').addClass('hide').siblings('span.rhover').addClass('hide').siblings('a.record').removeClass('hide').parent('div.record').prev().val('x').end().next().addClass('hide');
}
function ReInitJQuery(){
    $('a.rss.processing').removeClass('processing');
}
function follow(aLink,url,feedID){
    url = (typeof(url) === 'undefined')?'':url;
    feedID = (typeof(feedID) === 'undefined')?'0':feedID.toString();
    var $a = $(aLink);
    var action = $a.html().toLowerCase().indexOf('follow')==0?'subscribe':'unsubscribe';
    var isAlbum = $a.html().toLowerCase().indexOf(' album') > 0;
    return $.getJSON(ResolveUrl('ajax2.aspx?arg=doFollow&url='+url+'&feedID='+feedID+'&action='+action+'&ctx='+$a.attr('id'))+'&JSONCallback=?',
        function(jr){
            var newaction = (action==='subscribe'?'Unfollow':'Follow')+(isAlbum?' This Album':'');
            $a.html(newaction);
            if ($a.is('.fllow a')){
                // now look for and replace any others on the same user.
                var $oc = $a.attr('onclick').toString();
                //$.each('.fllow a',function(val){
                $('.fllow a').each(function(){
                    var $va = $(this);
                    if ($va.attr('onclick') && $va.attr('onclick').toString() === $oc){
                        $va.html(newaction);
                        if ($va.attr('title').toLowerCase().indexOf('follow') == 0)
                            $va.attr('title','Unfollow '+$va.attr('title').substr(7));
                        else
                            $va.attr('title','Follow '+$va.attr('title').substr(9));
                    }
                });
            }
            
        });
};
function resendConfimationEmail(uID){
    $.getJSON(ResolveUrl('ajax2.aspx?arg=resendconfirm&uid='+uID)+'&JSONCallback=?',        
        function(jr){
            if (jr.success){           
                alert('Your Email Confirmation has been sent.');
                $('#aSendConfirm').text('Email Sent');
            }else{
                alert('There was a problem sending your message please try again.');
            }
        }
    );
};
function DoHighlightFollow(aLink,url,action){
    $.getJSON(ResolveUrl('ajax2.aspx?arg=doFollow&url='+url+'&action='+action+'&ctx='+$(aLink).attr('id'))+'&JSONCallback=?',function(jr){$('#'+jr.success.ctx.replace('aHF','')).remove();});
};




