﻿var article = null;

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

Ext.onReady(function() {

   
    Ext.get("alerts").on("click", function(evt) {
        evt.preventDefault();
       
        var tt = "<div id=\"alerts-box\" style=\"margin-left: 5px;border:1px solid silver;padding:10px;width:775px;\">" + 
                 "<div id=\"Div2\" style=\"border:1px solid silver;padding:10px;\">" + 
                 "<table><tr><td width=\"100%\"> <div style=\"font-size:15px;\">" + 
                 "Sign Up For DigitalSports Keyword Alerts to recieve an email alert any time a photo or article is "+
                 "published to the <span style=\"color:Red;\"> " + siteName + " </span> web site that has or is tagged with " + 
                 "matching keywords or you can subscribe to all news for this particular web site. </div>" + 
                 "</td></tr></table><table><tr><td valign=\"top\">" + 
                 "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">Your First Name</span>" + 
                 "&nbsp;<span style=\"color:Silver;\">(required)</span> " + 
                 "<br style=\"clear:both;\" /> " + 
                 "<input type=\"text\" value=\"Enter your first name\" onclick=\"this.value=''\" size=\"40\" id=\"first_name\" />" +
                 "<div style=\"clear:both;\" /><br /><div style=\"clear:both;\" />" + 
                 "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">Your Last Name</span>&nbsp;" + 
                 "<span style=\"color:Silver;\">(required)</span><br style=\"clear:both;\" />" +
                 "<input type=\"text\" value=\"Enter your last name\" onclick=\"this.value=''\" size=\"40\" id=\"last_name\" />" +
                 "<div style=\"clear:both;\" /><br /><div style=\"clear:both;\" />" + 
                 "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">" + 
                 "Your Email Address</span>&nbsp;<span style=\"color:Silver;\">(required)</span>" + 
                 "<br style=\"clear:both;\" /><input type=\"text\" value=\"Enter recipient address\" onclick=\"this.value=''\" size=\"40\" id=\"email_address\" />" +
                 "<div style=\"clear:both;\" /><br style=\"clear:both;\" />" + 
                 "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">" + 
                 "Make a Selection</span>&nbsp;<span style=\"color:Silver;\">(required)</span> " + 
                 "<br style=\"clear:both;\" />" + 
                 "<input name=\"alertchoice\" type=\"radio\" id=\"all_news\" checked />" +
                 " all news or <input type=\"radio\" name=\"alertchoice\" id=\"by_keyword\" /> by keyword" + 
                 "<div id=\"keywords_box\" style=\"display:none;\">" +
                 "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">" + 
                 "Your Keywords (seperate by comma)</span><span style=\"color:Silver;\">(required)</span>" + 
                 "<br style=\"clear:both;\" /> <textarea id=\"keywords\" rows=\"10\" cols=\"30\"></textarea>" + 
                 "</div><br style=\"clear:both;\" /><br style=\"clear:both;\" /><img src=\"/images/share-this-signup.jpg\" id=\"Img1\"  style=\"float:right;\"/>" + 
                 "<div id=\"alert-status\" style=\"visibility:hidden; font-size: 12px;position: relative; top: 3px;\">&nbsp;</div></div>" + 
                 "</td>" + 
                 "<td width=\"100\">&nbsp;</td></td>" + 
                 "<td>&nbsp;&nbsp;" + 
                 "<br style=\"clear:both;\" /></td>" +
                 "<td><b> How to use DigitalSports Alerts:</b>" + 
                 "<br style=\"clear:both;\" /> <br style=\"clear:both;\" /> " + 
                 "1.       Enter your first name, last name, and email address <br style=\"clear:both;\" />" +
                 "<br style=\"clear:both;\" />" + 
                 "2.       Select the type of news you would like to subscribe to: <br style=\"clear:both;\" />"  + 
                 "<br style=\"clear:both;\" />" +                                                                      
                 "<b> All News </b><br style=\"clear:both;\" />" + 
                 "<br style=\"clear:both;\" />" + 
                 "If you select the box next to all <span style=\"color:Red;\">" + siteName + "</span> alerts, all your favorite news regarding " + siteName + 
                 "will be sent to your inbox. <br style=\"clear:both;\" />" + 
                 "<br style=\"clear:both;\" /> <b>OR</b> <br style=\"clear:both;\" />" + 
                 "<br style=\"clear:both;\" />" +  
                 "<b> By Keyword</b> <br style=\"clear:both;\" /><br style=\"clear:both;\" /> " + 
                 "Through DigitalSports Alerts you can subscribe to your favorite news based on the keywords you choose within " +
                 "<span style=\"color:Red;\">" + siteName + "</span>." +   
                 "Simply enter the keywords or terms you would like to receive news on in the text box to the left, and each time an " + 
                 "article is published that is related to your keywords, you will be notified!  Please make sure to separate your keywords with a" + 
                 "comma (Example – boys basketball, Hampton High School, john smith)" +
                 "<br style=\"clear:both;\" />" +                         
                 "<br style=\"clear:both;\" />" + 
                 "1.       Click the “Sign Up” button." +
                 "<br style=\"clear:both;\" /><br style=\"clear:both;\" />" +
                 "*If you would like to subscribe to news in other areas of DigitalSports" + 
                 "(at the state, conference/league/district , or school level), please navigate to the area you would like to see" + 
                 "and then select alerts on an article within that area. <br style=\"clear:both;\" />" + 
                 "<br style=\"clear:both;\" />For help with alerts, please contact us at" +
                 " <a href=\"mailto:alerts@digitalsports.com\">alerts@digitalsports.com</a><br style=\"clear:both;\" /><br style=\"clear:both;\" />" + 
                 "</td></tr></table>"; 
               
        
       
        Ext.get("talkbox").update(tt); 
        Ext.get("talkbox").show();
       
       
       
        Ext.get("all_news").on("click", function(evt) {
    
         Ext.get("keywords_box").setStyle("display" , "none");
         Ext.get("by_keyword").dom.checked = false;
         }); 
   
   Ext.get("by_keyword").on("click" , function(evt) {
   
        Ext.get("keywords_box").setStyle("display" , "block");
        
        Ext.get("all_news").dom.checked = false;
        
   
   
   
   }); 
   
    Ext.get("Img1").on("click" , function(evt) {
   
        evt.stopEvent();
        var firstName = Ext.get("first_name").getValue();
        var lastName  = Ext.get("last_name").getValue();
	    if (firstName == 'Enter your first name') firstName = '';
	    if (lastName  == 'Enter your last name') lastName = '';
	    if (emailAddr == 'Enter your address') senderAddr = '';
        var emailAddr = Ext.get("email_address").getValue();
	    var keywords = Ext.get("keywords").getValue();
        var alertType = null;
      
        if (Ext.get("by_keyword").dom.checked)
        {
            alertType = "keyword";
         }
         else
         {   
            alertType = "allnews" ;
         }
            
            
        
        Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'email' } });
        Ext.get('alert-status').show().update('Sending...');
        
        
     
        Ext.Ajax.request({url: "/service/Alert.ashx" , callback:function(o,s,r){
            Ext.get('alert-status').update('Your Alert has been recorded. Thank You!');
            setTimeout(function(){Ext.get('alerts-box').setStyle('display', 'none');},1000);
        },params: { firstname: firstName , lastname: lastName , emailaddr: emailAddr , alerttype: alertType  , nodeid: nodeId , nodetype: nodeType ,  keywords: keywords, locurl: location.href } } );
        
        
       
   
   });
       
        var share = Ext.get('talkbox');
        if (share.dom.style.display == 'block') share.setStyle('display', 'none');
        else share.setStyle('display', 'block');
        Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'alerts'} });
        
        
        
    });

    Ext.get("bookmark").on("click" , function(evt) {
        
        evt.preventDefault();
        bookmark(document.location , document.title );
        
         Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'bookmark'} });
        
   });
   
   Ext.get("facebook").on("click" , function(evt) {
        
        evt.preventDefault();
        window.open(evt.getTarget().href , 'newwin');
        Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'facebook'} });
        
   
   });
   
    Ext.get("google").on("click" , function(evt) {
        
        evt.preventDefault();
        window.open(evt.getTarget().href , 'newwin');
        Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'google'} });
        
   
   });
   
   
   Ext.get("emailer").on("click" , function(evt) {
   
         evt.preventDefault();
         
         Ext.get("talkbox").update("");
         
         var tt = "<div id=\"email_box\" style=\"margin-left: 5px;width:775px;border:1px solid silver;padding:10px;\">" +  
                  "<div id=\"inner_box\" style=\"border:1px solid silver;padding:10px;\">" + 
                   "<table><tr><td width=\"100%\"> <h4>Email a copy of " + article_title +  " to a friend </h4> " +
                   "</td> </tr></table><table><tr><td>" + 
                   "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">Your Name</span>&nbsp;<span style=\"color:Silver;\">" + 
                   "(required)</span><input type=\"text\" value=\"Enter your name\" onclick=\"this.value=''\" size=\"40\" id=\"sender_name\" />" + 
                   "<div style=\"clear:both;\" /> <br /> <div style=\"clear:both;\" />" + 
                   "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">Your Email Address</span>&nbsp;" +
                   "<span style=\"color:Silver;\">(required)</span>" + 
                   "<input type=\"text\" value=\"Enter your address\" onclick=\"this.value=''\" size=\"40\" id=\"sender_address\" />" + 
                   "<div style=\"clear:both;\" />" + 
                   "<br /> <div style=\"clear:both;\" />" + 
                   "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">" + 
                   "Recipient Address</span>&nbsp;<span style=\"color:Silver;\">(required)</span>" + 
                   "<input type=\"text\" value=\"Enter recipient address\" onclick=\"this.value=''\" size=\"40\" id=\"recipient_address\" />" + 
                   "<div style=\"clear:both;\" /> " + 
                   "<div style=\"clear:both;\" />" + 
                   "</td><td width=\"100\">&nbsp;</td>" + 
                   "<td valign=\"top\">" +
                   "<span style=\"color:Black;font-size:14px;font-family:Arial;font-weight:bold;\">" + 
                   "Enter A Message</span><span style=\"color:Silver;\">(optional)</span>" +
                   "<textarea id=\"sender_message\" rows=\"05\" cols=\"30\"></textarea> " +   
                   "<img src=\"/images/send-button-black.jpg\" id=\"sender_email\" />&nbsp;&nbsp;" + 
                   "<div id=\"email-status\" style=\"visibility:hidden; font-size: 12px;position: relative; top: 3px;\">&nbsp;</div>" + 
                   "</td></tr></table> </div></div>";
         
         Ext.get("talkbox").update(tt);
         
         
         
         
         Ext.get('email-status').update('&nbsp;').hide();
         
       
   
   Ext.get("sender_email").on("click" , function(evt) {
   
        evt.stopEvent();
       
        var senderName = Ext.get("sender_name").getValue();
	if (senderName == 'Enter your name') senderName = '';
        var senderAddr = Ext.get("sender_address").getValue();
	if (senderAddr == 'Enter your address') senderAddr = '';
        var recipAddr  = Ext.get("recipient_address").getValue();
        var senderMessage = Ext.get("sender_message").getValue();
        Ext.Ajax.request({url: "/service/Share.ashx" , params: { locurl : location.href , sharetype: 'email' } });
        Ext.get('email-status').show().update('Sending...');
       
        
        Ext.Ajax.request({url: "/service/Email.ashx" , callback:function(o,s,r){
            Ext.get('email-status').update('Sent!');
            setTimeout(function(){Ext.get('email_box').setStyle('display', 'none');},1000);
        },params: { emailtime: "yes" , name: senderName , tempShareType: tempShareType ,  sender_address: senderAddr , recipient_address: recipAddr , sender_message: senderMessage, locurl: location.href, article_title: article_title } } );
        
        
       
   
   });
       
       
       
       
       
       
         var emailBox = Ext.get('talkbox');
         if (emailBox.dom.style.display == 'block') emailBox.setStyle('display', 'none');
         else emailBox.setStyle('display', 'block');
       
   });
   
   
 
   
    Ext.get('share-what-btn').on('click', function(evt){
        evt.stopEvent();
        var tt = escape("<div id=\"share-what\" style=\"margin-left: 5px;border:1px solid silver;padding:10px;width: 775px;\"> " +
                                                   "The share bar allows for you to share the news you love with your friends and family in a few quick and easy ways:" + 
                                 "<br /><br /><b>Email</b> - Quickly and easily send news to your friends and family.  Simply enter your name, email address," +  
                                 "and the email addresses of those you wish to send the article to and they will receive an email message with the link to this article." + 
                                "<br /><br /><b>Bookmarks</b> - Add this page to your web browser's favorites so you will always know where to find it!" + 
                                "<br /><br />Show it to the world!  With the following icons you can make sure these stories get the recognition they deserve:" + 
                                "<br /><br /><b>Facebook</b> (www.facebook.com) is a social utility that connects you with the people around you. "  + 
                                " Post articles to your facebook profile to share with your friends and networks."  + 
                                "<br /><br /><b>Del.icio.us</b> (www.delicious.com) is a del.icio.us is a social bookmarking website -- the primary use of del.icio.us is to " + 
                                "store your bookmarks online, which allows you to access the same bookmarks from any computer and to share your favorites with friends, family, " + 
                                "coworkers, and the del.icio.us community.  Bookmark and share the articles you love!" + 
                                "<br /><br /><b>iGoogle</b> (http://www.google.com/ig) is a personal homepage that allows users to subscribe to their favorite news and media feeds and organize" +
                                " them in one place.  Add your favorite DigitalSports destinations to your page!</div>") ;
                                
          Ext.get("talkbox").dom.innerHTML = unescape(tt);          
        var share = Ext.get('talkbox');
        if (share.dom.style.display == 'block') share.setStyle('display', 'none');
        else share.setStyle('display', 'block');
    });
    
    
    
    
    


});
