﻿function RespondToAction(action, text){
    
    strURL = escape(location.href); //encode URL's

    switch(action){
    
      case "c": //post comment 
        location.href = "#PostComments"          
        break;            
      
      case "e":
        location.href = "mailto:?subject=" + text + "&body=" + strURL;
        break;
                  
      case "b":  //bookmark IE ONLY
        if(document.all){
            window.external.AddFavorite(unescape(strURL), unescape(strTitle));
        }else{
            alert("Press \"CTRL + D\" to bookmark this page.")
        }            
        break;            
      
      case "del": //delicious      
        window.open("http://del.icio.us/post?url=" + strURL + "&title=" + text, "", "", "");            
        break;
                  
      case "dig":  //digg
        window.open("http://digg.com/submit?phase=2&url=" + strURL + "&title=" + text + "&bodytext=&topic=");
        break;
                    
      case "cb":
         $.ajax({
            type: "POST",
            url: "/ws/Articles.asmx/AddArticleToClipboard",
            data: "contentId=" + queryString("id"),
            dataType: "xml",
            success: function(xml){
                var insertSuccessful = ($("boolean", xml).text() == "true");
                
                if(insertSuccessful){
                    alert("Content added to clipboard.");
                }else{
                    alert("Unable to add content to clipboard.  Please try again later.");
                }
            }
         });                  
         
         break;
    }
    
    return false;
}

function queryString( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}