////////////////////
// BEGIN CTK Code //
////////////////////

// initialize global variables
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var safari = navigator.userAgent.toLowerCase().indexOf("safari") + 1;
var firefox = navigator.userAgent.toLowerCase().indexOf("firefox") + 1;
var m_scrollbar = 18;
if (safari)
	m_scrollbar = 0;		// Work-around for safari Flash/scrolling bug

function returnToCart()
{
	var l = topFrame().document.getElementById('return');
	l.setAttribute("href", "content.asp", 0);
	l.className = 'toolbar';
}

var detectableWithVB = false;
var pluginFound = false;
function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}


function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');


    document.writeln('</scr' + 'ipt>');
}
//var isflash = detectFlash();
var isflash = true;

////////////////////
//  END CTK Code  //
////////////////////


/////////////////////////////////////////////////
// Define getElementById function if necessary //
/////////////////////////////////////////////////
if (!document.getElementById)
{
	if(document.all)
		document.getElementById=function()
		{
			if(typeof document.all[arguments[0]]!="undefined")
				return document.all[arguments[0]];
			else
				return null;
		}
	else if(document.layers)
		document.getElementById=function()
		{
			if(typeof document[arguments[0]]!="undefined")
				return document[arguments[0]];
			else
				return null;
		}
}

var m_max_highlight_id = 0;			// # of highlight rects on the page
var m_page_version = 0;				// Default page version = 0 for old pages with no page version specified in htm
function get_page_version()
{
	return m_page_version;
}

function topFrame()
{
	if (parent)
		return parent.topFrame;
	else
		return null;
}


//////////////////////
//  Mouse Tracking  //
//////////////////////
if (!ie4)
	window.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = track_mouse;

var m_mouse_x=0, m_mouse_y=0, m_mouse_paused=0;
function track_mouse(e)
{
	var x, y;
	if (ie4) 
	{ // grab the x-y pos.s if browser is IE
    	x = event.clientX;
    	y = event.clientY;
  	}
	else
	{  // grab the x-y pos.s if browser is NS
    	x = e.pageX;
    	y = e.pageY;
	}  
	// catch possible negative values in NS4
	if (x < 0)
		x = 0;
	if (y < 0)
		y = 0;

	if ((x != m_mouse_x) || (y != m_mouse_y))
	{
		m_mouse_x = x;
		m_mouse_y = y;
		m_mouse_paused = 0;
		hide_tip();
	}

	return true
}

function get_mouse_x()
{
	return m_mouse_x+get_scroll_x()-m_border_left-m_skin_border_width;
}

function get_mouse_y()
{
	return m_mouse_y+get_scroll_y()-m_border_top-m_skin_border_width;
}

function get_mouse_paused()
{
	return m_mouse_paused;
}


////////////////////
// EVENT HANDLERS //
////////////////////

// This function is called after the page has successfully loaded.  Place any UI code here which should be exectuted at that point
function on_load_page()
{
	//save_page_details();
	toggle_div("Flash", 1);

	get_highlight();
	center_highlight();

	ReloadPageControl();
}

function on_resize_page()
{
	//if (!m_skin_zoom_multiple)
	//	fit_page();
	//else
		resize_page();
}

// This function called after Flash is loaded and displayed
function on_load_flash()
{
	toggle_div("Links", 1);
	toggle_div("Page", 1);

	place_safari_scroll();
}

var m_tip_str="";
var m_tip_show=false;
var m_tip_on=false;
function on_mouse_out_tip()
{
	m_tip_show = false;
	hide_tip();
}

function on_mouse_enter_tip(tip_str)
{
	m_tip_str = tip_str;
	m_tip_show = true;
	start_tip_timer();
}

function on_mouse_move_tip(tip_str)
{
	// No longer used
}


///////////////////////
// Toolbar Functions //
///////////////////////

function fit_page()
{
	if (!ie4) {
		fit_page_old();
	} else {
		var scale = get_fit_page_scale();
		m_zoom = -1;
		zoom_page(scale);
	}
}

function fit_width()
{
	if (!ie4) {
		fit_width_old();
	} else {
		var scale = get_fit_width_scale();
		m_zoom = -2;
		zoom_page(scale);
	}
}

function zoom_in()
{ 
	var scale;

	scale = m_scale*m_skin_zoom_pct/100;
	m_zoom = scale*100;
	zoom_page(scale);

	if ((m_highlight_left==0) && (m_highlight_top==0))
	{
		var e=document.getElementById("navmovie1");
		if (e)
		{
			m_highlight_left = e.width/(2 * m_scale);
			m_highlight_top = e.height/(m_scale * 2);
		}
	}
	m_highlight_width = 1;
	m_highlight_height = 1;
	center_highlight();
}

function zoom_out()
{ 
	var scale;

	//if (!m_skin_zoom_multiple)
	//	return fit_page();

	scale = m_scale*100/m_skin_zoom_pct;
	m_zoom = scale*100;
	zoom_page(scale);

	if ((m_highlight_left==0) && (m_highlight_top==0))
	{
		var e=document.getElementById("navmovie1");
		if (e)
		{
			m_highlight_left = e.width/(m_scale * 2);
			m_highlight_top = e.height/(m_scale * 2);
		}
	}
	m_highlight_width = 1;
	m_highlight_height = 1;
	center_highlight();
}

function print_page()
{
	m_proxy.call("print_page");
}

////////////////////////////
// Randy's Page Functions //
////////////////////////////

function parse_args()
{
	if (location.search.length > 0)
	{
		launchString = location.search.substring(1, location.search.length);
		var launchStringArray = launchString.split("&");
		for (var i = 0; i <= launchStringArray.length - 1; i++)
		{
			var left = launchStringArray[i].substring(0, launchStringArray[i].indexOf("="));
			var right = launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1, launchString.length);
			if (isNaN(right))
				right = '"' + right + '"';
			eval(left + " = " + right);
		}
	}
}

function get_fit_page_scale()
{
	var scale1 = 0;
	var scale2 = 0;
	var border2 = m_skin_border_width*2;
	var e=document.getElementById("navmovie1");
	if(e) {
		var save_width = e.width/m_scale;
		var save_height = e.width/m_scale;

		get_window_size();

		scale1 = (m_window_width-border2-1)/save_width;
		scale2 = (m_window_height-border2-1)/save_height;
		if (scale2 < scale1)
			scale1 = scale2;
	}
	return scale1;
}

function get_fit_width_scale()
{
	var scale1 = 0;
	var scale2 = 0;
	var border2 = m_skin_border_width*2;
	var e=document.getElementById("navmovie1");

	if(e) {

		var save_width = e.width/m_scale;
		var save_height = e.height/m_scale;

		get_window_size();

		scale1 = (m_window_width-m_scrollbar-border2-1)/save_width;
		scale2 = (m_window_height-m_scrollbar-border2-1)/save_height;
		if (scale2 > scale1)
			scale1 = scale2;
	}
	return scale1;
}

// Adjusts scale to avoid double horz scrollbar problem
function check_horz_scale(scale)
{
	var scale1 = 0;
	var scale2 = 0;
	var border2 = m_skin_border_width*2;
	var e=document.getElementById("navmovie1");

	if (e) { 

		var save_width = e.width/m_scale;

		get_window_size();

		scale1 = (m_window_width-m_scrollbar-border2)/save_width;
		scale2 = (m_window_width-border2)/save_width;
		if ((scale > scale1) && (scale < scale2))
			scale = scale1;
	}
	return scale;
}

// Adjusts scale to avoid double vert scrollbar problem
function check_vert_scale(scale)
{
	var scale1 = 0;
	var scale2 = 0;
	var border2 = m_skin_border_width*2;
	var e=document.getElementById("navmovie1");

	if(e) {
		var save_height = e.height/m_scale;
		get_window_size();

		scale1 = (m_window_height-m_scrollbar-border2)/save_height;
		scale2 = (m_window_height-border2)/save_height;
		if ((scale > scale1) && (scale < scale2))
			scale = scale1;
	}
	return scale;
}


function get_highlight()
{
	// If the highlight was passed as a url argument then just return
	
	if ((m_highlight_left != 0.0) || (m_highlight_top != 0.0) ||
		(m_highlight_width != 0.0) || (m_highlight_height != 0.0))
	{
		return;
	}

	// This would be highlights from search results
	var e=document.getElementById("highlight_1");
	if (e)
	{
		m_highlight_left = parseInt(e.style.left)/m_scale;
		m_highlight_top = parseInt(e.style.top)/m_scale;
		m_highlight_width = parseInt(e.style.width)/m_scale;
		m_highlight_height = parseInt(e.style.height)/m_scale;
	}
	else
	{
		m_highlight_left = 0;
		m_highlight_top = 0;
		m_highlight_width = 1;
		m_highlight_height = 1;
	}
}

function get_window_size()
{
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		m_window_width = window.innerWidth;
		m_window_height = window.innerHeight;
	} 
	else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		m_window_width = document.documentElement.clientWidth;
		m_window_height = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		m_window_width = document.body.clientWidth;
		m_window_height = document.body.clientHeight;
	}
}

// This function is called by page.swf which then expects it to call the swf back at:
//
//		function get_window_center_return(x:Number, y:Number):Void
//
// in order to set the window x and y center coordinates to use in centering the preload.swf
// graphic.
//
// Not sure where or when we lost this functionality but by at least implementing a null
// function here we get rid of the javascript functionality.  However until we either
// implement the get_window_center_return callback or another approach within the page.swf,
// I believe we have effectively disabled the showing of the preload.swf animation.
function get_window_center()
{
}

function get_screen_size()
{
	m_screen_avail_w = screen.availWidth;
	m_screen_avail_h = screen.availHeight;
	m_screen_size_w = screen.width;
	m_screen_size_h = screen.height
}

function fit_and_center()
{
	var max_w, max_h, window_w, window_h, top, left;

	get_screen_size();
	
	max_w = m_screen_avail_w*0.8;
	max_h = m_screen_avail_h*0.8;
	
	window.resizeTo(300,300);
	get_window_size();
	window_w = 300 - m_window_width + document.images[0].width;
	window_h = 300 - m_window_height + document.images[0].height;

	if (window_w > max_w)
		window_w = max_w;
	if (window_h > max_h)
		window_h = max_h;
	left = (m_screen_size_w-window_w)/2;
	top =  (m_screen_size_h-window_h)/2;

	window.moveTo(left,top);
	window.resizeTo(window_w, window_h);	
}

function open_center(mypage,myname,w,h,scroll)
{
	var left,top, settings, obj, re;

	get_screen_size();
	left = (m_screen_avail_w-w)/2;
	top = (m_screen_avail_h-h)/2;
	settings='width='+w+',height='+h+',top='+top+',left='+left+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	obj = window.open(mypage,myname,settings);
	re = new RegExp('object','gi');
	if(!re.test(String(obj)))
		popup_blocker_alert();
}

function open_mapprint(mypage,myname,w,h,scroll)
{
	var left,top, settings, obj, re;

	get_screen_size();
	left = (m_screen_avail_w-w)/2;
	top = (m_screen_avail_h-h)/2;
	settings='width='+w+',height='+h+',top='+top+',left='+left+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=yes,toolbar=no,resizable=yes';
	obj = window.open(mypage,myname,settings);
	re = new RegExp('object','gi');
	if(!re.test(String(obj)))
		popup_blocker_alert();
}

function open_and_fit(mypage,x,y,w,h)
{
	var left,top, settings, obj, re;

	get_screen_size();
	left = (m_screen_avail_w-w)/2;
	top = (m_screen_avail_h-h)/2;
	settings='width='+w+',height='+h+',top='+top+',left='+left+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	url = mypage+'?m_zoom=100&m_highlight_left='+x+'&m_highlight_top='+y+'&m_highlight_width='+w+'&m_highlight_height='+h;
	//url = mypage+'?m_zoom=100';
	obj = window.open(url,'Name',settings);
	re = new RegExp('object','gi');
	if(!re.test(String(obj)))
		popup_blocker_alert();
}

function open_display_ad(mypage,page_w, page_h, x,y,w,h)
{
	var scale, left,top, settings, url, obj, re, max_x, max_y, w2, h2, single_page_w;

	get_screen_size();

	// Check for doubletruck
	if (page_w > page_h)
		single_page_w = page_w/2;
	else
		single_page_w = page_w;

	max_y = m_screen_avail_h*0.90
	scale = (max_y/page_h);
	max_x = page_w*scale;
	if (max_x > (m_screen_avail_w*0.90))
	{
		max_x = m_screen_avail_w*0.90;
		scale = (max_x/page_w);
		max_h = page_h*scale;
	}

	w2 = w;
	if (w < single_page_w*0.20)
		w2 = max_x/2;			// (5 column book - 1 column wide)
	else if (w < single_page_w*0.25)
		w2 = max_x/2;			// (4 column book - 1 column wide)
	else if (w < single_page_w*0.33)
		w2 = max_x/2;			// (3 column book - 1 column wide)
	else if (w < single_page_w*0.40)
		w2 = (max_x*2)/3;		// (5 column book - 2 columns wide
	else if (w < single_page_w*0.50)
		w2 = (max_x*2)/3;		// (half page width)
	else if (w < single_page_w*0.60)	
		w2 = (max_x*3)/4;		// (5 column book - 3 columns wide)
	else if (w < single_page_w*0.66)
		w2 = (max_x*3)/4;		// (3 column book - 2 columns wide)
	else if (w < single_page_w*0.75)
		w2 = (max_x*5)/6;		// (4 column book - 3 columns wide)
	else if (w < single_page_w*0.80)
		w2 = (max_x*5)/6;		// (5 column book - 4 columns wide)
	else if (w < single_page_w)
		w2 = max_x;				// ( full page width)
	else
		w2 = max_x;				// (double truck)
	scale = (w2/w);
	h2 = h*scale;

	if (h2 > max_y)
	{
		h2 = max_y;
		scale = (h2/h);
		w2 = w*scale;
	}

	left = (m_screen_avail_w-w2)/2;
	top = (m_screen_avail_h-h2)/2;
	settings='width='+w2+',height='+h2+',top='+top+',left='+left+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	url = mypage+'?m_display_ad=true&m_zoom='+scale*100+'&m_highlight_left='+x+'&m_highlight_top='+y+'&m_highlight_width='+w+'&m_highlight_height='+h;
	obj = window.open(url,'_blank',settings);
	re = new RegExp('object','gi');
	if(!re.test(String(obj)))
		popup_blocker_alert();
}

function goto_and_fit(url, native_rect_left, native_rect_top, native_rect_width, native_rect_height)
{
	get_window_size();

	the_scale_x = (m_window_width/native_rect_width);
	the_scale_y = (m_window_height/native_rect_height);
	if (the_scale_x < the_scale_y)
		the_scale = the_scale_x;
	else
		the_scale = the_scale_y;
	if (the_scale > 2.0)
		the_scale = 2.0;

	device_rect_left = native_rect_left*the_scale;
	device_rect_top = native_rect_top*the_scale;
	device_rect_width = native_rect_width*the_scale;
	device_rect_height = native_rect_height*the_scale;

	the_scale *= 100;
	location_str = url + "?m_zoom="+the_scale+"&m_window_width="+m_window_width+"&m_window_height="+m_window_height+
	                     "&m_highlight_left="+device_rect_left+"&m_highlight_top="+device_rect_top+
	                     "&m_highlight_width="+device_rect_width+"&m_highlight_height="+device_rect_height;
	window.location = location_str;
}

function goto_rect(url, the_rect_left, the_rect_top, the_rect_width, the_rect_height)
{
	get_window_size();
	x = the_rect_left+(the_rect_width/2);
	y = the_rect_top+(the_rect_height/2);

	center_x = m_window_width/2;
	center_y = m_window_height/2;
	max_x = m_page_width-m_window_width;
	max_y = m_page_height-m_window_height;
	if (max_x < 0)
		max_x = 0;
	if (max_y < 0)
		max_y = 0;

	top_x = x-center_x;
	if (top_x < 0)
		top_x = 0;
	if (top_x > max_x)
		top_x = max_x;
	top_y = y-center_y;
	if (top_y < 0)
		top_y = 0;
	if (top_y > max_y)
		top_y = max_y;

	e = document.getElementById('Page');
	if (e)
	{
		e.scrollTop = top_x;
		e.scrollLeft = top_y;
	}
}

function popup_blocker_alert()
{
	var	msg;
	if (ie4)
	{
		msg =  "It appears that a popup blocker may have stopped your request to display this url.\n";
		msg += "Click on the Information Bar near the top of your browser window to specify your\n";
		msg += "desire to allow popups from this site only.\n\n";
		msg += "Please be assured that this site only displays information specifically requested by you.\n";
		msg += "There are no unsolicited popup windows.";
	}
	else
	{
		msg =  "It appears that a popup blocker may have stopped your request to display this url.\n";
		msg  = "We've designed this web site to be compatible with the default settings of many internet\n";
		msg += "security or personal firewall popup blockers.  However, you may need to configure your\n";
		msg += "software to allow user requested popups in order to see the url you have requested.\n\n";
		msg += "Please be assured that this site only displays information specifically requested by you.\n";
		msg += "There are no unsolicited popup windows.";
	}
	alert(msg);
}

function center_highlight()
{
	get_window_size();
	
	x = m_scale*(m_highlight_left+(m_highlight_width/2));
	y = m_scale*(m_highlight_top+(m_highlight_height/2));
	
	center_x = m_window_width/2;
	center_y = m_window_height/2;
	
	max_x = m_page_width-m_window_width;
	max_y = m_page_height-m_window_height;
	if (max_x < 0)
		max_x = 0;
	if (max_y < 0)
		max_y = 0;
	
	top_x = x-center_x;
	if (top_x < 0)
		top_x = 0;
	if (top_x > max_x)
		top_x = max_x;
	top_y = y-center_y;
	if (top_y < 0)
		top_y = 0;
	if (top_y > max_y)
		top_y = max_y;
	
	e = document.getElementById('Page');
	if (e)
	{
		e.scrollTop = top_y;
		e.scrollLeft = top_x;
	}
}

function get_scroll_x() 
{
	var e;
	var x = 0;

	e = document.getElementById('Page');
	if (e)
		x = e.scrollLeft;

	return x;
}

function get_scroll_y() 
{
	var e;
	var y = 0;

	e = document.getElementById('Page');
	if (e)
		y = e.scrollTop;

	return y;
}

function is_scroll_x()
{
	return (m_page_width > (m_window_width-m_scrollbar-m_skin_border_width*2));
}

function is_scroll_y()
{
	return (m_page_height > (m_window_height-m_scrollbar-m_skin_border_width*2));
}

function get_scroll_x_max()
{
	var max_x;

	max_x = m_page_width-m_window_width+m_scrollbar+m_skin_border_width*2;
	if (max_x < 0)
		max_x = 0;
	return max_x;
}

function get_scroll_y_max()
{
	var max_y;

	max_y = m_page_height-m_window_height+m_scrollbar+m_skin_border_width*2;
	if (max_y < 0)
		max_y = 0;
	return max_y;
}

function set_scroll_x(x)
{
	var max_x;
	var e;

	e = document.getElementById('Page');
	if (e)
	{
		max_x = get_scroll_x_max();
		if (x < 0)
			e.scrollLeft = 0;
		else if (x < max_x)
			e.scrollLeft = x;
		else
			e.scrollLeft = max_x;
	}
}

function set_scroll_y(y)
{
	var max_y;
	var e;

	e = document.getElementById('Page');
	if (e)
	{
		max_y = get_scroll_y_max();
		if (y < 0)
			e.scrollTop = 0;
		else if (y < max_y)
			e.scrollTop = y;
		else
			e.scrollTop = max_y;
	}
}

function get_native_x(x)
{
	x = x + get_scroll_x();
	x = x/m_scale;

	return x;
}

function get_native_y(y)
{
	y = y + get_scroll_y();
	y = y/m_scale;

	return y;
}

function zoom_at_click()
{
	var x, y, the_scale;

	if (m_skin_has_zoom_at_click)
	{
		var theEvent=window.event || arguments.callee.caller.arguments[0];
		x = get_native_x(theEvent.clientX);
		y = get_native_y(theEvent.clientY);

		//if (!m_skin_zoom_multiple)
		//{
		//	if (m_zoom == -1)
		//		zoom_at_xy(x,y, true);
		//	else
		//		fit_page();
		//}
		//else
		{
			zoom_at_xy(x,y, !((theEvent.ctrlKey) || (theEvent.shiftKey)) );
		}
	}
}

function zoom_at_xy(x,y, zoomin)
{
	if (zoomin)
		the_scale = m_scale*m_skin_zoom_pct/100;
	else
		the_scale = m_scale*100/m_skin_zoom_pct

	m_highlight_left = x;
	m_highlight_top = y;
	m_highlight_width = 1;
	m_highlight_height = 1;

	m_zoom = the_scale*100;
	zoom_page(the_scale);
	center_highlight();
}

function set_max_highlight_id(max)
{
	m_max_highlight_id = max;
}

function save_page_details()
{
	var i;
	var e;
	var id;

	e=document.getElementById("navmovie1");
	if (e)
	{
		e.save_width = e.width/m_scale;
		e.save_height = e.height/m_scale;
	}
	for(i=0; i<=m_max_link_id; i++)
	{
		id = ("lnk" + i).toString();
		e=document.getElementById(id);
		if (e)
		{
			e.style.save_left = parseInt(e.style.left)/m_scale;
			e.style.save_top = e.style.pixelTop/m_scale;
		}

		id = ("img" + i).toString();
		e=document.getElementById(id);
		if (e)
		{
			e.save_width = e.width/m_scale;
			e.save_height = e.height/m_scale;
		}
	}
	for(i=1; i<=m_max_highlight_id; i++)
	{
		id = ("highlight_" + i).toString();
		e=document.getElementById(id);
		if (e)
		{
			e.style.save_left = e.style.pixelLeft/m_scale;
			e.style.save_top = e.style.pixelTop/m_scale;
			e.style.save_width = e.style.pixelWidth/m_scale;
			e.style.save_height = e.style.pixelHeight/m_scale;
		}
	}
}

resize_interval = 0;
function resize_page()
{
	if (!ie4) {
		resize_page_old();
	} else {
		resize_page_helper();

		// Need a 2nd call to get rid of auto scrollbars which appear when sizing the window down.
		// Must wait so browser can redraw/recalc window first, hence the setInterval
		resize_interval = setInterval("resize_page_helper()",50);
	}
}

function resize_page_helper()
{
	if (resize_interval != 0)
	{
		clearInterval(resize_interval);
		resize_interval = 0;
	}

	var border = m_skin_border_width;
	var border2 = m_skin_border_width*2;

	m_border_width = m_page_width+border2;
	m_border_height = m_page_height+border2;

	get_window_size();

	if ((m_window_width >= m_border_width) && (m_window_height >= m_border_height))
	{
		is_centering_horz = true;
		is_centering_vert = true;
		the_page_width = m_page_width;
		the_page_height = m_page_height;
	}
	else if (m_window_width > m_border_width)
	{
		is_centering_horz = true;
		is_centering_vert = false;
		m_border_width += m_scrollbar;
		m_border_height = m_window_height;
		the_page_width = m_page_width + m_scrollbar;
		the_page_height = m_window_height-border2;
	}
	else if (m_window_height > m_border_height)
	{
		is_centering_horz = false;
		is_centering_vert = true;
		m_border_width = m_window_width;
		m_border_height += m_scrollbar;
		the_page_width = m_window_width-border2
		the_page_height = m_page_height+m_scrollbar;
	}
	else
	{
		is_centering_horz = false;
		is_centering_vert = false;
		m_border_width = m_window_width;
		m_border_height = m_window_height;
		the_page_width = m_window_width-border2;
		the_page_height = m_window_height-border2;
	}
	if (m_skin_center_page)
	{
		m_border_left = (m_window_width-m_border_width)/2;
		m_border_top = (m_window_height-m_border_height)/2;
	}
	 else
	{
		m_border_left = 0;
		m_border_top = 0;
	}

    var obj;
	obj = document.getElementById("Border");
	if (obj)
	{
		obj.style.left = m_border_left.toString()+"px";
		obj.style.top = m_border_top.toString()+"px";
		obj.style.width = m_border_width.toString()+"px";
		obj.style.height = m_border_height.toString()+"px";
	}

	obj = document.getElementById("BorderCell");
	if (obj)
	{
		obj.style.width = the_page_width.toString()+"px";
		obj.style.height = the_page_height.toString()+"px";
	}

	if (obj)
	{
		obj = document.getElementById("Page");
		obj.style.width = the_page_width.toString()+"px";
		obj.style.height = the_page_height.toString()+"px";
	}

	place_safari_scroll();
}

function zoom_page(scale)
{
	if (!ie4) { 
		zoom_page_old(scale);
	} else {
		var i;
		var e;
		var id;

		hide_tip();
		toggle_div("Flash", 0);
		toggle_div("Links", 0);
		toggle_div("Page", 0);

		if (scale > 4.0)
			scale = 4.0;
		else if (scale < 0.10)
			scale = 0.10;

		// Avoid double horz scrollbar problem
		scale = check_horz_scale(scale);
		// Avoid double vert scrollbar problem
		scale = check_vert_scale(scale);
		m_scale = scale;

		e=document.getElementById("navmovie1");
		if (e)
		{
			m_page_width = (e.width/m_scale)*scale;
			m_page_height = (e.height/m_scale)*scale;
		}

		resize_page_helper();

		e=document.getElementById("navmovie1");
		if (e)
		{
			e.width = (e.width/m_scale)*scale;
			e.height = (e.height/m_scale)*scale;
		}
		for(i=0; i<=m_max_link_id; i++)
		{
			id = ("lnk" + i).toString();
			e=document.getElementById(id);
			if (e)
			{
				var save_left = parseInt(e.style.left)/m_scale;
				var save_top = parseInt(e.style.top)/m_scale;

				e.style.left = (save_left*scale).toString()+"px";
				e.style.top = (save_top*scale).toString()+"px";
			}

			id = ("img" + i).toString();
			e=document.getElementById(id);
			if (e)
			{
				e.width = (e.width/m_scale)*scale;
				e.height = (e.height/m_scale)*scale;
			}
		}
		for(i=1; i<=m_max_highlight_id; i++)
		{
			id = ("highlight_" + i).toString();
			e=document.getElementById(id);
			if (e)
			{
				var save_left = parseInt(e.style.left)/m_scale;
				var save_top = parseInt(e.style.top)/m_scale;
				var save_width = parseInt(e.style.width)/m_scale;
				var save_height = parseInt(e.style.height)/m_scale;

				e.style.left = (save_left*scale).toString()+"px";
				e.style.top = (save_top*scale).toString()+"px";
				e.style.width = (save_width*scale).toString()+"px";
				e.style.height = (save_height*scale).toString()+"px";
			}
		}
	
		e=document.getElementById("divSpine");
		if (e)
		{
			e.style.left = ((m_page_width/2)-31).toString()+"px";
			e.style.height = (m_page_height).toString()+"px";
		}
		e=document.getElementById("topLeft");
		if (e)
		{
			e.style.height = (m_page_height/2).toString()+"px";
		}
		e=document.getElementById("bottomLeft");
		if (e)
		{
			e.style.top = (m_page_height/2).toString()+"px";
			e.style.height = (m_page_height/2).toString()+"px";
		}
		e=document.getElementById("topRight");
		if (e)
		{
			e.style.left = (m_page_width-80).toString()+"px";
			e.style.height = (m_page_height/2).toString()+"px";
		}
		e=document.getElementById("bottomRight");
		if (e)
		{
			e.style.left = (m_page_width-80).toString()+"px";
			e.style.top = (m_page_height/2).toString()+"px";
			e.style.height = (m_page_height/2).toString()+"px";
		}
	
		zoom_interval = setInterval("redisplay()",250);
	}
}

function redisplay()
{
	toggle_div("Links", 1);
	toggle_div("Page", 1);
	toggle_div("Flash", 1);
	clearInterval(zoom_interval);
}

function trace_for_flash(arg)
{
	alert(arg);
}

function toggle_div(id, state) // state: 1=show, 0=hide
{
    if(document.layers)	   //NN4+
    {
      document.layers[id].visibility = state ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(id);
        obj.style.visibility = state ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[id].style.visibility = state ? "visible" : "hidden";
    }
}

// May use this approach for backwards compatibility so keep for now
function resize_page_old()
{
	var location_str;

	get_window_size();
	location_str = window.location.href;
	if (m_skin_has_modal_zoom)
	{
		location_ndx = location_str.indexOf("&m_window_width=");
		if (location_ndx != -1)
			location_str = location_str.substring(0, location_ndx);
		location_str += "&m_window_width="+m_window_width+"&m_window_height="+m_window_height;
	}
	else
	{
		location_ndx = location_str.indexOf("m_zoom=");
		if (location_ndx != -1)
			location_str = location_str.substring(0, location_ndx);
		else
			location_str += "?";
		location_str += "m_zoom="+m_scale*100+"&m_scale="+m_scale+"&m_window_width="+m_window_width+"&m_window_height="+m_window_height;
	}
	window.location.replace(location_str);
}

function fit_page_old() 
{
	var location_str;

	location_str = window.location.href;
	location_ndx = location_str.indexOf("m_zoom=");
	if (location_ndx != -1)
		location_str = location_str.substring(0, location_ndx);
	else
		location_str += "?";
	location_str += "m_zoom=-1"+
	                "&m_highlight_left="+m_highlight_left+"&m_highlight_top="+m_highlight_top+"&m_highlight_width=1&m_highlight_height=1"+
					"&m_window_width="+m_window_width+"&m_window_height="+m_window_height;

	zoom_interval = setInterval("redisplay()",250);
	window.location = location_str;
}

function fit_width_old() 
{
	var location_str;

	location_str = window.location.href;
	location_ndx = location_str.indexOf("m_zoom=");
	if (location_ndx != -1)
		location_str = location_str.substring(0, location_ndx);
	else
		location_str += "?";
	location_str += "m_zoom=-2"+
	                "&m_highlight_left="+m_highlight_left+"&m_highlight_top="+m_highlight_top+"&m_highlight_width=1&m_highlight_height=1"+
					"&m_window_width="+m_window_width+"&m_window_height="+m_window_height;

	zoom_interval = setInterval("redisplay()",250);
	window.location = location_str;
}

function zoom_page_old(scale) 
{
	// Mac/Safari compromise for Flash page overwrite problem
	//var	fit_width_scale = get_fit_width_scale();
	//if (scale > fit_width_scale)
	//	return fit_width_old();

	var location_str;

	if (scale > 4.0)
		scale = 4.0;
	else if (scale < 0.10)
		scale = 0.10;

	// Avoid double horz scrollbar problem
	scale = check_horz_scale(scale);
	// Avoid double vert scrollbar problem
	scale = check_vert_scale(scale);

	location_str = window.location.href;
	location_ndx = location_str.indexOf("m_zoom=");
	if (location_ndx != -1)
		location_str = location_str.substring(0, location_ndx);
	else
		location_str += "?";
	location_str += "m_zoom="+scale*100+"&m_scale="+scale+
	                "&m_highlight_left="+m_highlight_left+"&m_highlight_top="+m_highlight_top+"&m_highlight_width=1&m_highlight_height=1"+
					"&m_window_width="+m_window_width+"&m_window_height="+m_window_height;

	window.location = location_str;
}

///////////////////////
// Tooltip Functions //
///////////////////////

function hide_tip()
{
	show_tip("", 0, 0);
}

function show_tip(tip_text, mouse_x, mouse_y)
{
	var tip_element, border_element;
	var	border_left, border_top;
	var tip_height, tip_width;
	var	tip_limit_min_x, tip_limit_max_x, tip_limit_max_y;
	var tip_offset_x, tip_offset_y;
	var tip_x, tip_y;

	//if ((!m_skin_zoom_multiple) && (m_zoom!=-1))
	//{
	//	if (tip_text == m_skin_tip_link_magnify)
	//		tip_text = m_skin_tip_link_zoom_out;
	//}

	// If tip_text is empty, we need to hide the tip.  However it is
	// already hidden so just return
	if ((tip_text == "") && (!m_tip_on))
		return;

	// Must change tooltip text before getting width/height
	tip_element=document.getElementById("Tip");
	if (tip_element)
	{
		tip_element.lastChild.lastChild.nodeValue = tip_text;

		tip_width = get_tip_width();
		tip_height = get_tip_height();
		tip_offset_x = tip_width/2;
		tip_offset_y = 22;
		tip_limit_min_x = get_scroll_x()+m_scrollbar+2+tip_offset_x;
		tip_limit_max_x = get_scroll_x()+m_border_width-(m_skin_border_width*2)-tip_width-m_scrollbar-2+tip_offset_x;
		tip_limit_max_y = get_scroll_y()+m_border_height-(m_skin_border_width*2)-tip_height-m_scrollbar-2-tip_offset_y;
	
		if (mouse_y > tip_limit_max_y)
			tip_y = mouse_y - tip_offset_y-tip_height;
		else
			tip_y = mouse_y + tip_offset_y;
	
		if (mouse_x < tip_limit_min_x)
			tip_x = tip_limit_min_x-tip_offset_x;
		else if (mouse_x > tip_limit_max_x)
			tip_x = tip_limit_max_x-tip_offset_x;
		else
			tip_x = mouse_x - tip_offset_x;

		tip_element.style.left =(tip_x).toString()+"px";
		tip_element.style.top = (tip_y).toString()+"px";
		if (tip_text == "")
		{
			tip_element.style.visibility = "hidden";
			m_tip_on = false;
		}
		else
		{
			tip_element.style.visibility = "visible";
			m_tip_on = true;
		}
	}
}

function get_tip_width()
{
	var width=0;
	var e = document.getElementById("Tip");
	if (e)
		width = e.offsetWidth;
	return width;
}

function get_tip_height()
{
	var height = 0;
	var e = document.getElementById("Tip");
	if (e)
		height = e.offsetHeight;
	return height;
}

var m_tip_timer_id=-1;
function start_tip_timer()
{
	if (m_tip_timer_id == -1)
		m_tip_timer_id = setInterval("tip_timer_rtn()", 500);
}

function stop_tip_timer()
{
	if (m_tip_timer_id != -1)
	{
		clearTimeout(m_tip_timer_id);
		m_tip_timer_id = -1;
	}
}

function tip_timer_rtn()
{
	m_mouse_paused += 1;
	if (m_mouse_paused >= 2)
	{
		if ((m_tip_show)  & (!m_tip_on) && (m_tip_str!=""))
			show_tip(m_tip_str, get_mouse_x(), get_mouse_y());
	}
}

//////////////////////////////
// Macintosh Scroll Buttons //
//////////////////////////////

var m_scroll_inc_x=0;
var m_scroll_inc_y=0;
var m_scroll_interval=0;

function on_mouse_out_scroll()
{
	if (m_scroll_interval)
	{
		clearInterval(m_scroll_interval);
		m_scroll_interval = 0;
	}
}

function on_mouse_over_scroll_left()
{
	if (m_scroll_interval)
		on_mouse_out_scroll();
	m_scroll_inc_x = -15;
	m_scroll_inc_y = 0;
	m_scroll_interval = setInterval("scroll_interval()",10);
}

function on_mouse_over_scroll_right()
{
	if (m_scroll_interval)
		on_mouse_out_scroll();
	m_scroll_inc_x = 15;
	m_scroll_inc_y = 0;
	m_scroll_interval = setInterval("scroll_interval()",10);
}

function on_mouse_over_scroll_up()
{
	if (m_scroll_interval)
		on_mouse_out_scroll();
	m_scroll_inc_x = 0;
	m_scroll_inc_y = -15;
	m_scroll_interval = setInterval("scroll_interval()",10);
}

function on_mouse_over_scroll_down()
{
	if (m_scroll_interval)
		on_mouse_out_scroll();
	m_scroll_inc_x = 0;
	m_scroll_inc_y = 15;
	m_scroll_interval = setInterval("scroll_interval()",10);
}

function scroll_interval()
{
	set_scroll_x(get_scroll_x()+m_scroll_inc_x);
	set_scroll_y(get_scroll_y()+m_scroll_inc_y);
}


function place_safari_scroll()
{
	if (!safari || m_display_ad)
		return;

	var e;
	var is_horz_scrollbar, is_vert_scrollbar;


	is_horz_scrollbar = is_scroll_x();
	is_vert_scrollbar = is_scroll_y();

	e=document.getElementById("SafariScrollLeft");
	if (e)
	{
		e.style.left = (m_border_left+m_skin_border_width).toString()+"px";
		e.style.top = (m_border_top+((m_border_height-parseInt(e.style.height))/2)).toString()+"px";
		toggle_div("SafariScrollLeft", is_horz_scrollbar);
	}
	e=document.getElementById("SafariScrollRight");
	if (e)
	{
		e.style.left = (m_border_left+m_border_width-m_skin_border_width-parseInt(e.style.width)).toString()+"px";
		e.style.top = (m_border_top+((m_border_height-parseInt(e.style.height))/2)).toString()+"px";
		toggle_div("SafariScrollRight", is_horz_scrollbar);
	}
	e=document.getElementById("SafariScrollUp");
	if (e)
	{
		e.style.top = (m_border_top+m_skin_border_width).toString()+"px";
		e.style.left = (m_border_left+((m_border_width-parseInt(e.style.width))/2)).toString()+"px";
		toggle_div("SafariScrollUp", is_vert_scrollbar);
	}
	e=document.getElementById("SafariScrollDown");
	if (e)
	{
		e.style.top = (m_border_top+m_border_height-m_skin_border_width-parseInt(e.style.height)).toString()+"px";
		e.style.left = (m_border_left+((m_border_width-parseInt(e.style.width))/2)).toString()+"px";
		toggle_div("SafariScrollDown", is_vert_scrollbar);
	}
}

// These two functions are called by the onRelease event handlers of the flash page curl animations
function goto_prev_page()
{
	parent.mainFrame.location = "../../../content.asp?pagenav=-1&from=iframe";
}

function goto_next_page()
{
	parent.mainFrame.location = "../../../content.asp?pagenav=100000&from=iframe";
}


