﻿// common.js
// Andyville common scripts v1.00.12; 5/26/05; last: 9/08/09; (C) 2005-2009 Dimbee
// v1.00.12 9/08/09: modified ninjaAndyMonth function to display black background and Andyville silhouette logo
// v1.00.11 12/31/08: added tomSpace function
// v1.00.10 9/09/08: added ifMonthDoShow and ifDayMonthDoShow functions
// v1.00.09 8/02/08: added freakQuote function
// v1.00.08 7/05/08: added kungFuRipoff function
// v1.00.07 6/26/08: modified doShowAds function so ads and stats will count at new ninjaandy.com location
// v1.00.06 11/28/06: eliminated statCountAdd function. Replaced functionality with statSecCode function
// v1.00.05 11/15/06: added statCountAdd function
// v1.00.04 11/03/06: added googleAdAdd, whereAmI, and doShowAds functions. Cleaned up and better commented code.
// v1.00.03 9/03/06: added nakedNinjaGirls and ninjaAndyDay functions
// v1.00.02 8/20/06: added bitchBoy function
// v1.00.01 6/12/06: added tag function
// v1.00.00 5/26/05: Initial Version.

var VERSION="3.10.04" //global variable for version of Andyville

function randInt(n){ // function that returns a random integer >= 1 using seed value n
	var x=Math.random()*n	
	
	for(i=1; i<=n; i++)
	{
		if(x<=i)
		{
			y=i;
			break;
		}
	}
	return y;
}

function tag(content){ // dumbest function ever, but it avoids confusion of parsers. Surrounds content with "<" and ">"
	return "<" + content + ">";
}

function whereAmI(){ // resolves host name
	var chunk=location.href.split('/');
	return chunk[2];
}

function doShowAds(){ // decides whether ads should appear
	whereYouAre=whereAmI();
	if((whereYouAre=="andyville.atspace.com")||(whereYouAre=="www.ninjaandy.com"))
		return true;
	else
		return false;
}

function googleAdAdd(){ // function to only allow ads in production so that they do not appear on test server. Must be last thing in script block or IE7 chokes.
	if(doShowAds()){
		google_ad_client = "pub-9238528585847922";
		google_alternate_color = "000000";
		google_ad_width = 728;
		google_ad_height = 90;
		google_ad_format = "728x90_as";
		google_ad_type = "text_image";
		google_ad_channel ="";
		google_color_border = "000000";
		google_color_bg = "000000";
		google_color_link = "FF0000";
		google_color_text = "FFFF00";
		google_color_url = "FFFF0F";
		document.write("<script src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript'></script>"); //call ad source (if applicable)
	}
}

function statSecCode(){ // function to feed counter security code in production so test server hits don't count.
	if(doShowAds())
		return "6010eadb";
}

function bitchBoy(link){ // code for "Josh Gracin owes Big Cray" banner with optional link to article
	var currentTime = new Date();
	var milli = currentTime.getTime();
	var currTime=milli/1000;
	var owe=100 * Math.pow((1 + .2/52),((currTime-1151978400)/(60*60*24*7)));

	document.write("<div align='center'><table><tr><td><div align='center' style='border: 5px groove yellow; background: red; font-size: 25px; color: yellow'>");
	if(link)
		document.write("<a href='crayspaceblog2.html' style='text-decoration: none; color: yellow;'>");

	document.write("Josh 'Bitch Boy' Gracin<br>currently owes Big Cray<br><b style='background: yellow; color: red'>$" + owe.toFixed(2) + "</b>");
	if(link)
		document.write("</a>");

	document.write("</div></td></tr></table></div>");
}

function kungFuRipoff(link){ // code for "Dreamworks Owes Ninja Andy" banner with optional link to article
	var currentTime = new Date();
	var milli = currentTime.getTime();
	var currTime=milli/1000;
	var owe=1000000 * Math.pow((1 + .2/52),((currTime-1215252700)/(60*60*24*7)));

	document.write("<div align='center'><table><tr><td><div align='center' style='border: 5px groove yellow; background: red; font-size: 25px; color: yellow'>");
	if(link)
		document.write("<a href='kungfupanda.html' style='text-decoration: none; color: yellow;'>");

	document.write("Dreamworks<br>currently owes Ninja Andy<br><b style='background: yellow; color: red'>$" + owe.toFixed(2) + "</b>");
	if(link)
		document.write("</a>");

	document.write("</div></td></tr></table></div>");
}

function freakQuote(link){ // code to call "Jason the Freak Random Quote" banner
	freakyLink=link;
	document.write("<script src='freakQuote.js' type='text/javascript'></script>"); //call generator
}

function ifDayMonthDoShow(day, month, actionToTake){
	var currentTime = new Date();
	if((currentTime.getDate()==day) && (currentTime.getMonth()==month-1))
		document.write(actionToTake);
}

function ifMonthDoShow(month, actionToTake){
	var currentTime = new Date();
	if(currentTime.getMonth()==month-1)
		document.write(actionToTake);
}

function nakedNinjaGirls(link, justText){ // code for naked ninja girl banner with optional link to article and option to just return the text
	returnString="<div align='center' id='nng'><table><tr><td><div align='center' style='border: 5px groove yellow; background: red; font-size: 25px; color: yellow'>";
	if(link)
		returnString+="<a href='nakedninjagirls.html' style='text-decoration: none; color: yellow;'>";

	returnString+="Happy<br>Naked Ninja<br>Girls Day!<br>[Sept. 4th]";
	if(link)
		returnString+="</a>";

	returnString+="</div></td></tr></table></div>";

	if(justText)
		return returnString;
	else
		document.write(returnString);
}

function ninjaAndyMonth(link, justText){ // code for Ninja Andy Month banner with optional link to article and option to just return the text
	returnString="<div align='center' id='nam'><table><tr><td><div align='center' style='border: 5px groove yellow; background-color:black; background-image: url(images/midandydark.png); background-repeat: no-repeat; background-position: center; font-size: 25px; color: yellow'>";
	if(link)
		returnString+="<a href='nakedninjagirls.html' style='text-decoration: none; color: yellow;'>";

	returnString+="Happy<br>Ninja Andy<br>Month<br>[September]";
	if(link)
		returnString+="</a>";

	returnString+="</div></td></tr></table></div>";

	if(justText)
		return returnString;
	else
		document.write(returnString);
}

function tomSpace(user, link, textLabel){	// allows printing of myspace addresses. User goes in the URL, link is boolean for if it is a link, textLabel is the text label if it is a link
	var returnString="";
	if(link)
		returnString="<a href='";
	returnString+="http://www.my";
	returnString+="space.com/";
	returnString+=user;
	if(link){
		returnString+="'>";
		returnString+=textLabel;
		returnString+="</a>"
	}
	return returnString;
}