﻿$(document).ready(function() { 
    $('#newsletterContent img').addClass("newsletterimg");
    var month =$.jqURL.get("month");
    $("#ddlArchive").val(month);
         
    $("#ddlArchive").unbind("change").change(function() {
    
        if ($("#ddlArchive").val() != '')
        {
            var m=$("#ddlArchive").val();
            window.location.href = "?month=" + m;           
        }      
    });    
  
    
     if ($("#ddlArchive").val() == '')
     {        
         var mydate= new Date();
        var m=mydate.getMonth()+1;
        $("#ddlArchive").val(m);
         var link =$(".newsItem a").attr("href");
         var url = "http://"+document.location.hostname+link;
         if(link != null && link != 'undefined' && document.URL != url)
         {
            location.href =link;         
         }       
     }
     else
     {     
         var link =$(".newsItem a").attr("href");
         var url = "http://"+document.location.hostname+link;
        
         if(link != null && link != 'undefined')
         {   
            if(window.history.length > 1 && document.referrer.indexOf("month="+month)== -1 && document.URL != encodeURI(url)) 
             {	
                location.href=url;             
             }
        }       
     }
     
     var anchorList = $(".newsItem a");
     var pageList = $("#numbers");
     for(var i=0;i<anchorList.length;i++)
     {
         if(document.URL == anchorList[i])
         {
           pageList.append("<span>"+(i+1)+"</span>");
               if((i+1)== anchorList.length)
               {
                    $("#next a").remove();
                    if($("#next a").html() == null)
					{
                    $('#next').append('>');
                    $('#next').addClass("disabled");
					}
               }
               if(i == 0)
               {
                    $("#prev a").remove();
                    if($("#prev a").html() == null)					
					{
					$('#prev').append('&lt;');
                    $('#prev').addClass("disabled");
					}
					
               }
               var k=anchorList.length-1;
               $("#next a").attr('href',anchorList[k]);
               
               var j = 0;
               $("#prev a").attr('href',anchorList[j]);
         }
         else 
         {
         pageList.append("<a href='"+anchorList[i]+"'>"+(i+1)+"</a>"); 
         }  
     }
     if($("#numbers span").html() == null)
     {
     $("#prev").remove();
     $("#next").remove();
     }
});
