// JavaScript Document

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/*
createElement function
*/
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function insertTop(obj) {
	// Create the two div elements needed for the top of the box
	d=createElement("div");
	d.className="bt"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}

function insertBottom(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function initCB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var cbDivs = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with cbb in their class attribute while allowing for multiple class names
		if (/\bcbb\b/.test(divs[i].className))
			cbDivs[cbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv, outer, i1, i2;
	for (var i = 0; i < cbDivs.length; i++) {
	// Save the original outer div for later
		thediv = cbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'cbb' with 'cb'
		outer = createElement('div');
		outer.className = thediv.className;
		outer.className = thediv.className.replace('cbb', 'cb');
	// Change the original div's class name and replace it with the new div
		thediv.className = 'i3';
		thediv.parentNode.replaceChild(outer, thediv);
	// Create two new div elements and insert them into the outermost div
		i1 = createElement('div');
		i1.className = 'i1';
		outer.appendChild(i1);
		i2 = createElement('div');
		i2.className = 'i2';
		i1.appendChild(i2);
	// Insert the original div
		i2.appendChild(thediv);
	// Insert the top and bottom divs
		insertTop(outer);
		insertBottom(outer);
	}
}

if(document.getElementById && document.createTextNode)
{
	addEvent(window, 'load', initCB);
}


/*---------------------------------------------------------------------*/

function mybook_showhide(section) {
	var element = document.getElementById(section);

	if (element.style.display == "none")
	{
		element.style.display = "block";
	}else {
		element.style.display = "none";
	}
	
	return false;
}

function sublink_showhide(txt_section, txt_image, txt_img_up, txt_img_down) {
	var element_sec = document.getElementById(txt_section);
	var element_img = document.getElementById(txt_image);

	if (element_sec.style.display == "block")
	{
		element_sec.style.display = "none";
		element_img.src = txt_img_up;
	}else {
		element_sec.style.display = "block";
		element_img.src = txt_img_down;
	}

	return false;
}


/*------------------------------------------------------------*/


function HideMenu(d)
{
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowLayer(d,caller,left_offset,top_offset)
{
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);

	var newtop = findPos(caller)[1];
	var newleft = findPos(caller)[0];

	dd.style.left = (newleft + left_offset) + "px";
	dd.style.top = (newtop + top_offset) + "px";

	dd.style.display = "block";
}

function ShowMenu(d,caller)
{
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);

	var newtop = findPos(caller)[1];
	var newleft = findPos(caller)[0];

	dd.style.left = (newleft - 325) + "px";
	dd.style.top = (newtop + 7) + "px";

	dd.style.display = "block";
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/*------------------------------------------------------------*/

function P7_colH2(sub) {
	var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;
	if(dA&&dA.length) {
		for(i=1;i<dA.length;i+=2) {
			dA[i+1].style.paddingBottom='';
		}
		for(i=1;i<dA.length;i+=2) {
			oh=dA[i].offsetHeight;
			h=(oh>h)?oh:h;
		}
		for(i=1;i<dA.length;i+=2) {
			oh=dA[i].offsetHeight;
			if(oh<h) {
				np=h-oh;
				if(!an&&dA[0]==1) {
					P7_eqA2(dA[i+1].id,0,np);
				} else {
					dA[i+1].style.paddingBottom= (np - sub )+"px";
				}
			}
		}
		
		document.p7eqa=1;
		document.p7eqth=document.body.offsetHeight;
		document.p7eqtw=document.body.offsetWidth;
	}
}
function P7_eqT2(sub) { 
	if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){
		P7_colH2(sub);
	}
}
function P7_equalCols2() {
	var c,e,el;
	
	if(document.getElementById) {
		document.p7eqc=new Array();
		document.p7eqc[0]=arguments[0];
		for(i=1;i<arguments.length;i+=2) {
			el=null;
			c=document.getElementById(arguments[i]);
			if(c) {
				e=c.getElementsByTagName(arguments[i+1]);
				if(e) {
					el=e[e.length-1];
					if(!el.id) {el.id="p7eq"+i;}
				}
			}
		if(c&&el){
			document.p7eqc[document.p7eqc.length]=c;
			document.p7eqc[document.p7eqc.length]=el
		}
	}

	//make adjustment for book reader page.
	if (arguments[5] == 'y') {
		setInterval("P7_eqT2(167)",10);
	} else if (arguments[5] == 'p') {
		setInterval("P7_eqT2(261)",10);
	} else {
		setInterval("P7_eqT2(0)",10);
	}
	}
}
function P7_eqA2(el,p,pt) {
	var sp=10,inc=20,g=document.getElementById(el);
	np=(p>=pt)?pt:p;
	g.style.paddingBottom=np+"px";
	if(np<pt) {
		np+=inc;
		setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);
	}
}

/*---------------------------------------------------------------------------------*/
function Hide_ScreenLayer(d)
{
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function Show_ScreenLayer(d)
{
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}
/*---------------------------------------------------------------------------------*/

function turn_page_ro(c,side)
{
	var cell = document.getElementById(c);
	cell.style.backgroundColor  = '#7cb910';

	if (side == 'l')
	{
		var img1 = document.getElementById('tl');
		var img2 = document.getElementById('bl');
		var img3 = document.getElementById('arrow_left');
		
		img1.src = './images/reader_left_top_ro.gif';
		img2.src = './images/reader_left_bottom_ro.gif';
		img3.src = './images/icon_reader_left_ro.gif';
		
	} else {
		var img1 = document.getElementById('tr');
		var img2 = document.getElementById('br');
		var img3 = document.getElementById('arrow_right');

		img1.src = './images/reader_right_top_ro.gif';
		img2.src = './images/reader_right_bottom_ro.gif';
		img3.src = './images/icon_reader_right_ro.gif';
	}
	
}

function turn_page_off(c, side)
{
	var cell = document.getElementById(c);
	cell.style.backgroundColor = '#eef9d7';

	if (side == 'l')
	{
		var img1 = document.getElementById('tl');
		var img2 = document.getElementById('bl');
		var img3 = document.getElementById('arrow_left');
		
		img1.src = './images/reader_left_top_off.gif';
		img2.src = './images/reader_left_bottom_off.gif';
		img3.src = './images/icon_reader_left_off.gif';
	} else {
		var img1 = document.getElementById('tr');
		var img2 = document.getElementById('br');
		var img3 = document.getElementById('arrow_right');
		
		img1.src = './images/reader_right_top_off.gif';
		img2.src = './images/reader_right_bottom_off.gif';
		img3.src = './images/icon_reader_right_off.gif';
	}
}
/*---------------------------------------------------------------------------------------------------------*/
function ERB_button(d,caller,left_offset,top_offset)
{
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	var c = document.getElementById(caller);

	var newtop = findPos(c)[1];
	var newleft = findPos(c)[0];

	dd.style.left = (newleft + left_offset) + "px";
	dd.style.top = (newtop + top_offset) + "px";
}


