// JavaScript Document
function getNewsletterDate(){
	
var today = new Date();
var dayOn = 2
thisDay=today.getDay();
thisDate = today.getDate();
thisMonth = today.getMonth() + 1;
thisYear = today.getFullYear();
dateString = thisYear+''+thisMonth+''+thisDate;
textString = '<a href="http://gmdc.retailwire.com/newsletters/'+dateString+'/" target="_blank">See this week’s newsletter...</a>';

if(thisDay+1 == dayOn){
	if(thisMonth < 10 ){
		thisMonth = '0'+thisMonth;
	}
	
	if(thisDate < 10){
		
		thisDate = '0'+thisDate;	
	}
	dateString = thisYear+''+thisMonth+''+thisDate;
textString = '<a href="http://gmdc.retailwire.com/newsletters/'+dateString+'/" target="_blank">See this week’s newsletter...</a>';
	document.write(textString);
	//alert(thisYear+''+thisMonth+''+thisDate);
		
} else {
	var lastDate = new Date();
	var diffday = 0;
	if(thisDay+1 < dayOn){
			diffday = dayOn - (thisDay+1);
			
			lastDate.setDate(thisDate+diffday);
			
			lastDate.setDate(lastDate.getDate()-7);
			
	} else if(thisDay+1 > dayOn){
		diffday = (thisDay+1) - dayOn;
		
		lastDate.setDate(thisDate - diffday);
	}

	
	newDate = lastDate.getDate();
	newMonth = lastDate.getMonth() + 1;
	newYear = lastDate.getFullYear();
	
	if(newMonth < 10 ){
		newMonth = '0'+newMonth;
	}
	
	if(newDate < 10){
		
		newDate = '0'+newDate;	
	}
	var dateString = newYear+''+newMonth+''+newDate;
	document.write('<a href="http://gmdc.retailwire.com/newsletters/'+dateString+'/" target="_blank">See this week’s newsletter...</a>');
}
}

//Redirects browser to newsletter.
function goToNewsletter(){
var today = new Date();
var dayOn = 2
thisDay=today.getDay();
thisDate = today.getDate();
thisMonth = today.getMonth() + 1;
thisYear = today.getFullYear();
dateString = thisYear+''+thisMonth+''+thisDate;
textString = '<a href="http://gmdc.retailwire.com/newsletters/'+dateString+'/" target="_blank">See this week’s newsletter...</a>';

if(thisDay+1 == dayOn){
	if(thisMonth < 10 ){
		thisMonth = '0'+thisMonth;
	}
	
	if(thisDate < 10){
		
		thisDate = '0'+thisDate;	
	}
	dateString = thisYear+''+thisMonth+''+thisDate;
textString = '<a href="http://gmdc.retailwire.com/newsletters/'+dateString+'/" target="_blank">See this week’s newsletter...</a>';
	document.write(textString);
	//alert(thisYear+''+thisMonth+''+thisDate);
		
} else {
	var lastDate = new Date();
	var diffday = 0;
	if(thisDay+1 < dayOn){
			diffday = dayOn - (thisDay+1);
			
			lastDate.setDate(thisDate+diffday);
			
			lastDate.setDate(lastDate.getDate()-7);
			
	} else if(thisDay+1 > dayOn){
		diffday = (thisDay+1) - dayOn;
		
		lastDate.setDate(thisDate - diffday);
	}

	
	newDate = lastDate.getDate();
	newMonth = lastDate.getMonth() + 1;
	newYear = lastDate.getFullYear();
	
	if(newMonth < 10 ){
		newMonth = '0'+newMonth;
	}
	
	if(newDate < 10){
		
		newDate = '0'+newDate;	
	}
	var dateString = newYear+''+newMonth+''+newDate;
	location.replace("http://gmdc.retailwire.com/newsletters/" +dateString);
}
}

