
function validateEmail(toCheck) {
var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
return(email.test(toCheck));
}
function emailFriend(cId,bId) {
if (validateEmail(document.getElementById('recipient').value) == true) {
	postUrl = '/do/emailFriend?id=' + cId + '&bId=' + bId + '&to=' + document.getElementById('recipient').value + '&username=' + document.getElementById('username').value + '&message='  + document.getElementById('message').value;
	getUpdate(postUrl,'dropResponse');
	hideDialog('dialog');
	}
else {
	$('dialog-error').style.visibility = 'visible';
	$('dialog-error').innerHTML = 'OMG! Enter a valid email!';
	}
}
//Begin Modal Window
if (!document.getElementById('dialog')) {
	document.write('<div id="dialog" class="dialog"><div class="dialog-top"><b class="dialog-top_left"></b><b class="dialog-top_right"></b></div><div id="dialog_content" class="dialog-content">');
	document.write('</div><div class="dialog-bottom"><b class="dialog-bottom_left"></b><b class="dialog-bottom_right"></b></div><div style="clear: both;"></div></div>');
	}
function showDialog(dialog,theClass,width,height,clickable,cId,bId) {
	var emailDialog = 
		'<form action="#" onsubmit="return false;">\n' +
		'<span id="dialog-error">&nbsp;</span>\n' +
		'<div id="dialog-input" class="alignright">\n' +
		'<span class="bold">Email to: </span><input id="recipient" name="recipient" type="text" /><br />\n' +
		'<span class="bold">Your Name: </span><input id="username" name="username" type="text" /></span>\n' +
		'</div>\n' +
		'<span class="bold">&nbsp;&nbsp;Add a personal message (optional):</span>\n' +
		'<div id="dialog-submit" class="alignright">\n' +
		'<textarea cols="28" rows="5" id="message" name="message">Just thought I\'d send you this link.</textarea><br />\n' +
		'<input type="image" src="/images/game/btn-cancel_blue.gif" onclick="hideDialog(\'dialog\');" value="Cancel" />\n' +
		'<input type="image" src="/images/game/btn-send_blue.gif" onclick="emailFriend(' + cId + ',' + bId + ');" value="Send" />\n' +
		'</div>\n' +
		'</form>\n';
var allPageTags = new Array();
var allPageTags = document.getElementsByTagName('*');
for (i=0; i<allPageTags.length; i++) {
	if (allPageTags[i].className == theClass + '-content') {
		if (dialog == 'email') {
			dialog = emailDialog;
			}
		if (clickable) {
			dialog = '<div onclick="hideDialog(\'dialog\');">' + dialog + '<div>';
			}
		allPageTags[i].innerHTML = dialog;
		}
	}
 sm('dialog',width,height);
}
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function scrollFix(){
	var obol = document.getElementById('ol');
	obol.style.top=posTop()+'px';
	obol.style.left=posLeft()+'px'
	}
function sizeFix(){
	var obol = document.getElementById('ol');
	obol.style.height = pageHeight()+'px';
	obol.style.width = pageWidth()+'px';
}
function inf(hidden){
	tag=document.getElementsByTagName('select');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=hidden;
	tag=document.getElementsByTagName('iframe');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=hidden;
	tag=document.getElementsByTagName('object');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=hidden;
}
function sm(obl, wd, ht){
	var obol = document.getElementById('ol');
	var obbxd = document.getElementById('mbd');
	obbxd.innerHTML = document.getElementById(obl).innerHTML;
	obol.style.height=pageHeight()+'px';
	obol.style.width=pageWidth()+'px';
	obol.style.top=posTop()+'px';
	obol.style.left=posLeft()+'px';
	obol.style.display='block';
	var tp=posTop()+((pageHeight()-ht)/2)-12;
	var lt=posLeft()+((pageWidth()-wd)/2)-12;
	var obbx = document.getElementById('mbox');
	obbx.style.top=(tp<0?0:tp)+'px';
	obbx.style.left=(lt<0?0:lt)+'px';
	obbx.style.width=wd+'px';
	obbx.style.height=ht+'px';
	obbx.style.display='block';
	return false;
}
function hideDialog(){
	document.getElementById('ol').style.display='none';
	document.getElementById('mbox').style.display='none';
}
function initmb(){
	var obody=document.getElementsByTagName('body')[0];
	var frag=document.createDocumentFragment();
	var obol=document.createElement('div');
	obol.setAttribute('id','ol');
	obol.style.display='none';
	obol.style.position='absolute';
	obol.style.top=0;
	obol.style.left=0;
	obol.style.zIndex=898;
	obol.style.width='100%';
	frag.appendChild(obol);
	var obbx=document.createElement('div');
	obbx.setAttribute('id','mbox');
	obbx.style.display='none';
	obbx.style.position='absolute';
	obbx.style.zIndex=899;
	var obl=document.createElement('span');
	obbx.appendChild(obl);
	var obbxd=document.createElement('div');
	obbxd.setAttribute('id','mbd');
	obl.appendChild(obbxd);
	frag.insertBefore(obbx,obol.nextSibling);
	obody.insertBefore(frag,obody.firstChild);
	window.onscroll = scrollFix;
	window.onresize = sizeFix;
}
window.onload = function(){
	initmb();
}
// End Modal Window
// Begin Thumbs
function truncateCookie(cookie, delimiter, maxElements) {
	var cookieParts = cookie.split(delimiter);
	if (cookieParts.length > maxElements) {
		var newCookie = '', delim = '';
		for ( var i = (cookieParts.length - maxElements); i < cookieParts.length; i++) {
			if (newCookie.length > 0) { delim = delimiter; }
			newCookie += delim + cookieParts[i];
		}
		return newCookie;
	}
	return cookie;
}
function thumbsWriteIdCookie(myId) {
var date = new Date();
date.setDate(date.getDate()+30);
thumbscheckIdCookie(myId);
if (thumbscookiedata.length > 0) {
	thumbscookiedata = truncateCookie(thumbscookiedata, '|', 9);
	document.cookie = 'thumbs=' + thumbscookiedata + '|' + myId + '; expires=' + date.toGMTString() + '; path=/;';
	}
else {
	document.cookie = 'thumbs=' + myId + '; expires=' + date.toGMTString() + '; path=/;';
	}
}
function thumbsGetIdCookie(name) {
	thisCookie = document.cookie.split('; ')
	for (i = 0; i < thisCookie.length; i++) {
		if ('thumbs' == thisCookie[i].split('=')[0]) {
			return thisCookie[i].split('=')[1];
			}
		}
	return 0;
	}
var hasVoted, thumbscookiedata;
function thumbscheckIdCookie(myId) {
	hasVoted = 'false';
	thumbscookiedata = thumbsGetIdCookie('thumbs');
	if (thumbscookiedata.length > 0) {
		var nameVal = thumbscookiedata.split('|');
		for (var i=0; i<nameVal.length; i++) {
			if (nameVal[i] == myId) {
				hasVoted = 'true';
			}
		}
	}
}
function thumbsUp(postUrl, myId, totalThumbs) {
	document.getElementById('thumbs_count_' + myId).innerHTML = '[' + (totalThumbs + 1) + ']';
	document.getElementById('thumbs_up_' + myId).innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks!&nbsp;';
	thumbsWriteIdCookie(myId);
	getUpdate(postUrl,'dropResponse');
}
// End Thumbs
var request;