
/**
 * The contents of the JavaScript code which swaps class definitions
 * and text colors to facilatate the operation of ttnmenus.cgi
 * has been written by Joel Walker, based on readily available examples.
 * handleReSize has been adapted from examples.
 * Single- vs. Double-Click differentiation is based on code appearing at:
 * http://www.chipchapin.com/WebTools/JavaScript/example3-01.html
 * Dynamic TextArea Verification adapted from http://javascript.internet.com
 * Background "dashboard" effect is based on css tips appearing at:
 * http://dbachrach.com/blog/2006/10/09/a-cool-css-effect-dashboard/ and
 * http://brainerror.net/scripts/javascript/blendtrans/
 **/

var nsOrigWidth,nsOrigHeight,ImgWindow,ImgX,ImgY,ImgOffsetX,ImgOffsetY,IWOpen,dimbg,dbCss;
var ttnSCDelay	= 250;
var ttnDCBlock	= 100;
var ttnRegExpNonText = /[^0-9A-Za-z ]/g;
var ttnRegExpNonNumber = /[^0-9]/g;

function ttnCheckInt(ci) {
	if (isNaN(ci)) return;
	var ii = parseInt(ci);
	if (ii != parseFloat(ci)) return;
	return ii; }

function roundFive(rff) {
	return 5*Math.floor(.2*parseFloat(rff) + .5); }

function ttnSwapClass(ttn_obj, ttn_class_id, ttn_class_sx) {
	var ttn_class_name = '';
	if (ttn_class_id == '0') {
		ttn_class_name = 'ttnfriendBG'; }
	else if (ttn_class_id == '1') {
		ttn_class_name = 'ttnthumbBG'; }
	else if (ttn_class_id == '2') {
		ttn_class_name = 'ttnflagBG'; }
	else {
		return; }
	ttn_obj.className = ttn_class_name + ttn_class_sx; }

function ttnStretch() {
	//if (HM_NS4) return;
	var y1 = ttnPosition((new ttnGetObject('ttnpagetop')).obj,1);
	var y2 = ttnPosition((new ttnGetObject('ttnpagelogo')).obj,1);
	var y3 = ttnPosition((new ttnGetObject('ttnpagebot')).obj,1);
	var ttnlb = (y3 - y2 - 15);
	var ttnbt = (y3 - y1 - 245);
	if (ttnlb > 125) {
		var ttnlbs = (new ttnGetObject('ttnlogobar')).style;
		if (ttnlbs) ttnlbs.height = ttnlb + (HM_NS4 ? 0 : "px"); }
	if (ttnbt > 0) {
		var ttnbts = (new ttnGetObject('ttnbodyblue')).style ||
			(((ttnbt -= 30) > 0) && (new ttnGetObject('ttnbodywhite')).style);
		if (ttnbts) ttnbts.height = ttnbt + (HM_NS4 ? 0 : "px"); }}

function handlePageLoad() {
	if (HM_NS4) {
		nsOrigWidth = window.innerWidth;
		nsOrigHeight = window.innerHeight; }
	ttnStretch();
	initHoverBox();
	initAddThisBox();
	initDimBG();
	self.focus(); }

function handleUnLoad() {
	ClearImgWindow(); }

function handleReSize() {
	if (HM_NS4) {
		if ((window.innerWidth == nsOrigWidth) && (window.innerHeight == nsOrigHeight)) return;
		window.history.go(0); }
	else {
		TTNsetClock(); }}

function initDimBG() {
	if (HM_NS4) return;
	var idb = new ttnGetObject('dimBG');
	if (!(dimbg = idb.obj)) return;
	dbCss = idb.style;
	dbCss.visibility = 'hidden';
	dbCss.opacity = '0.6';
	dbCss.MozOpacity = '0.6';
	dbCss.KhtmlOpacity = '0.6';
	dbCss.filter = 'alpha(opacity=60)'; }

function doDimBG() {
	if (!dimbg) return;
	dbCss.visibility = 'visible'; }

function undoDimBG() {
	if (!dimbg) return;
	dbCss.visibility = 'hidden'; }

function GetImgXY() {
	ImgX = (HM_IE) ? ImgWindow.screenLeft : ImgWindow.screenX;
	ImgY = (HM_IE) ? ImgWindow.screenTop : ImgWindow.screenY;
	if ((typeof ImgX) != 'number') {
		ImgX = 20;
		ImgY = 20; }}

function ClearImgWindow() {
	if ((IWOpen) && (ImgWindow != null) && (!ImgWindow.closed) && (ImgWindow.location)) {
		GetImgXY();
		ImgX -= ImgOffsetX;
		ImgY -= ImgOffsetY;
		IWOpen = false;
		ImgWindow.close();
		ImgWindow = null; }}

function OpenImgWindow(imgPath,imgFile,imgDesc,bgColor,imgWidth,imgHeight,imgBorder) {
	ClearImgWindow();
	IWOpen = true;
	ImgWindow=window.open('','ImgWindow',eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+(parseInt(imgWidth)+2*parseInt(imgBorder))+",height="+(parseInt(imgHeight)+2*parseInt(imgBorder))+",left="+ImgX+",top="+ImgY+"'"));
	if (ImgWindow == null) {
		return true; }
	ImgWindow.document.open();
	ImgWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>'+imgDesc+'<\/title><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><\/head><body bgcolor="'+bgColor+'" style="margin:0px; padding:0px; background-color:bgColor; background-image:url('+imgPath+'/misc/loading.gif); background-repeat:no-repeat; background-attachment-fixed; background-position:center center;"><IMG src="'+imgPath+imgFile+'" alt="'+imgDesc+'" title="'+imgDesc+'" height="'+imgHeight+'" width="'+imgWidth+'" border="'+imgBorder+'" style="border:'+imgBorder+'px solid '+bgColor+';"><\/body><\/html>');
	ImgWindow.document.close();
	//if (!ImgWindow.opener) ImgWindow.opener = self; //Designed to retain position change for self close -- throws errors on reload
	if (HM_IE) { //catch onMove;
		ImgWindow.document.body.onbeforeunload = function() { //loop problem?
			self.ClearImgWindow(); }}
	//		if (!ImgWindow.opener.closed) {
	//			ImgWindow.opener.ClearImgWindow(); }}}
	ImgWindow.focus();
	if (ImgOffsetX == null) {
		GetImgXY();
		ImgOffsetX = ImgX - 20;
		ImgOffsetY = ImgY - 20; }
	return false; }

function ttnOMO(ttn_omo,ttn_msg) {
	var ttn_mow = '';
	if (ttn_omo == '1') {
		ttn_mow = 'Thanks for Supporting ToyTracker.Net!'; }
	else if (ttn_omo == '2') {
		ttn_mow = 'Search Current eBay Listings'; }
	else if (ttn_omo == '3') {
		ttn_mow = 'View eBay Listing'; }
	if ((ttn_msg != undefined) && (''+ttn_msg).length) {
		ttn_mow += ((ttn_mow.length?' ':'')+ttn_msg); }
	if (window.status == ttn_mow) {
		return true; }
	window.status = (ttn_mow.length?ttn_mow:' ');
	return true; }

function ttnSingleClick(ttnthat,coderef,argref) {
	if (((new Date()).getTime() - ttnthat.dcTime) < ttnDCBlock) return false;
	if (ttnthat.timerID) { clearTimeout(ttnthat.timerID); ttnthat.timerID = null; }
	ttnthat.timerID = setTimeout(ttnGetClosure(coderef,argref),ttnSCDelay);
	return true; }

function ttnDoubleClick(ttnthat,coderef,argref) {
	if (ttnthat.timerID) { clearTimeout(ttnthat.timerID); ttnthat.timerID = null; }
	ttnthat.dcTime = (new Date()).getTime();
	(ttnGetClosure(coderef,argref))();
	return true; }

function ttnCheckTextArea(tarea,count,cmax) {
	if (typeof(tarea) != 'object') return;
	var lim = ttnCheckInt(cmax);
        if (lim != null) {
		if (tarea.value.length > lim) tarea.value = tarea.value.substring(0,lim);
		else {
			var rem = ''+(lim - tarea.value.length);
			if ((typeof(count)=='string') && (count.length>=1)) ttnOverWriteLayerText(count,rem);
			else if (typeof(count)=='object') count.value = rem; }}}

function ttnLimitText(text,mode) {
	if ((typeof(text) != 'object') || (typeof(text.value) != 'string')) return;
	var tnxt; if (mode == 1) tnxt = text.value.replace(ttnRegExpNonText,'');
	else if (mode == 0) tnxt = text.value.replace(ttnRegExpNonNumber,'');
	else return; if (tnxt != text.value) text.value = tnxt; }

