
// JakeMAN's Javascripts!

//Make a link zoom open by adding the event handler
//onclick="zoomBox(event,this);return false"
//To zoom into a new, positioned window add width, height, left, and top
//onclick="zoomBox(event,this,640,480,100,50);return false"

var maxW,maxH,fromX,fromY,toX,toY,adjX,adjY,zBox,zStep=0,zLink,zNew;

function zoomBox(evt,zlink,maxw,maxh,tox,toy) {
if (arguments.length > 2) zNew=1;
scrollH=(window.pageYOffset!=null)?window.pageYOffset:document.body.scrollTop;
maxW=maxw?maxw:window.innerWidth?innerWidth:document.body.clientWidth;
maxH=maxh?maxh:window.innerHeight?innerHeight:document.body.clientHeight;
toX=tox?tox:0;
toY=(toy?toy:0)+scrollH;
fromX=evt.pageX?evt.pageX:evt.clientX;
fromY=(evt.pageY?evt.pageY:evt.clientY)+(document.all?scrollH:0);
adjX=toX+evt.screenX-fromX;
adjY=toY+evt.screenY-fromY;
if (document.createElement && document.body.appendChild && !zBox) {
	zBox=document.createElement("div");
	zBox.style.position="absolute";
	document.body.appendChild(zBox);
} else if (document.all && !zBox) {
	document.all[document.all.length-1].outerHTML+='<div id="zBoxDiv" style="position:absolute"></div>';
	zBox=document.all.zBoxDiv;
} else if (document.layers && !zBox) {
	zBox=new Layer(maxW);
	zBox.style=zBox;
	}
zLink=zlink;
doZoom();
}

function doZoom() {
zStep+=1;
zPct=(10-zStep)/10
if (document.layers) {
	zBox.moveTo(toX+zPct*(fromX-toX),toY+zPct*(fromY-toY));
	zBox.document.open();
	zBox.document.write("<table width='"+maxW*(1-zPct)+"' height="+maxH*(1-zPct)+" border=2 cellspacing=0><tr><td></td></tr></table>");
	zBox.document.close();
	} else {
	zBox.style.border="2px solid #999999";
	zBox.style.left=toX+zPct*(fromX-toX);
	zBox.style.top=toY+zPct*(fromY-toY);
	zBox.style.width=maxW*(1-zPct);
	zBox.style.height=maxH*(1-zPct);
	}
zBox.style.visibility="visible";
if (zStep < 10) setTimeout("doZoom("+fromX+","+fromY+","+toX+","+toY+")",30);
else {
	zBox.style.visibility='hidden';
	zStep=0;
	if (zLink && !zNew) location.href=zLink.href;
	else if (zLink && zNew) {
		var w=window.open(zLink.href,'','width='+maxW+',height='+maxH+',left='+adjX+',top='+adjY+',scrollbars,resizable');
		zNew=null;
		}
	}
}


function cameFrom(where) {
   if (!document.referrer && !where) return true;
   else return (document.referrer.indexOf(where)>=0)
   }

function Dec2Hex(Decimal) {
  var hexChars = "0123456789ABCDEF";
  var a = Decimal % 16;
  var b = (Decimal - a)/16;
  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  L = hexChars.charAt(a);
  H = hexChars.charAt(b);
  return hex;
  }
  var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";

function toAscii (mychar)  {
  var loAZ = "abcdefghijklmnopqrstuvwxyz";
  symbols+= loAZ.toUpperCase();
  symbols+= "[\\]^_`";
  symbols+= loAZ;
  symbols+= "{|}~";
  var loc;
  loc = symbols.indexOf(mychar);
  if (loc >-1) { 
	Ascii_Decimal = 32 + loc;
  return (32 + loc);
  }
  return(0);  // If not in range 32-126 return ZERO
}

function jakeman(message) {
  var mylength = message.length;
  var newmessage = "";
  var mytype = document.jakeman.urgency[0].checked;
  var callback = document.jakeman.callback.value;
  var x = 0  
  
  if (mylength != 0){
    if (mylength > 116){
	window.alert('Your message is too darn long, Mmkay?')
	document.jakeman.Message.focus(); 
	return;   
    }else {
		while(mylength > 0){
			if (message.charAt(x) == ','){
				newmessage = newmessage + ',';
			}else {	
				if (Dec2Hex(toAscii(message.charAt(x))) == '00'){
					newmessage = newmessage + '_';
				}else {
					newmessage = newmessage + "%" + Dec2Hex(toAscii(message.charAt(x)));	
				}
			}
		mylength -= 1;
		x += 1;
		}
	} 
	if ((document.jakeman.From.value != '')||(document.jakeman.callback.length == 0)) {
		newmessage = newmessage + "-" + document.jakeman.From.value;
	}
	popupWin = window.open('http://www.jakeman.com/SendMessage.asp?message=' + newmessage + '&type=' + mytype + '&callback=' + callback, 'SendMessage', 'width=10,height=10')
	setTimeout("popupWin.close();", 5000);
  }else {
	window.alert('Please type in a message.')
	document.jakeman.Message.focus();
  }
}


function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


function emailjakeman()
{
  var dude = document.jakemanmail.myfrom.value;

	if (isEmail(dude)==false) {
		window.alert("I don't think '" + dude + "' is a real email address.\nIt should look something like this:\n\nsomedude@somewhere.com")
		document.jakemanmail.myfrom.focus();
		return false;
	}
	var mylength;
	mylength=dude.length
	if (mylength>254) {
		window.alert("Dude, I KNOW your not trying to crash my home page!\n\nIf you're not, then your email address is too darn long!")
		document.jakemanmail.myfrom.focus();
		return false;
	}
	if (document.jakemanmail.mybody.value == "") {
		window.alert("Dude, you gotta type some kinda message!\nDon't just leave it blank!")
		document.jakemanmail.mybody.focus();
		return false;	
	}
	if (isEmail(dude)==true) {
		return true;
	}	
}


function showdate()
{
d = new Array(
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
);
m = new Array(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
);

today = new Date();
day = today.getDate();
year = today.getYear();

if (year < 2000)    
year = year + 1900;  

end = "th";
if (day==1 || day==21 || day==31) end="st";
if (day==2 || day==22) end="nd";
if (day==3 || day==23) end="rd";
day+=end;

var PleaseShowDate = (d[today.getDay()]+", "+m[today.getMonth()]+" "+day+", " + year);
document.write(PleaseShowDate);
}

var SpecialWord = "foot",
    SpecialUrl = "http://www.foottothehead.com",
    SpecialLetter = 0;
function getKey(keyStroke) {
var isNetscape=(document.layers);
var eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
var which = String.fromCharCode(eventChooser).toLowerCase();
if (which == SpecialWord.charAt(SpecialLetter)) {
SpecialLetter++;
if (SpecialLetter == SpecialWord.length) window.location = SpecialUrl;
}
else SpecialLetter = 0;
}
document.onkeypress = getKey;

var timerID = null;
var timerRunning = false;

function toketime(){
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
if (timeValue == "4:19:00 A.M.") window.alert("It's 4:19. Got a Minute?") ;
if (timeValue == "4:19:00 P.M.") window.alert("It's 4:19. Got a Minute?") ;
if (timeValue == "4:20:00 A.M.") window.alert("Toke Alert: It's 4:20. Failure to toke now will result in system failure.") ;
if (timeValue == "4:20:00 P.M.") window.alert("Toke Alert: It's 4:20. Failure to toke now will result in system failure.") ;
timerID = setTimeout("toketime()",1000);
timerRunning = true;
}

document.onLoad = toketime();
