var topLevel ='/'; // -for the 3 findFrameset functions - change this to'/' for root home or other '/root folder/' when developing

function findFrameset (level) {//jumps into frameset - level is empty for main pages or ../ for general pages
   if (window.name!='mainFrame'
		 && !((self.innerHeight == 0) && (self.innerWidth == 0)) || (window.name=='mainFrame' && !top.frames[1] ))//new OR 2006 to counter IE 'open link in new win' from leftMenu
  {
	var url = window.location.pathname;
	var thisExt = url.substring(url.lastIndexOf('.') + 1);
	var isSumtable = url.substring(url.lastIndexOf('.') - 8);
	if ((thisExt!="php") || (isSumtable=="sumtable.php")) {
		var thisPage = url.substring(url.lastIndexOf('/') + 1);
		var theFolder='content/'
		if (!level) {level=''}else {theFolder='content/general/'};
//if (url.lastIndexOf('/')+1!=0) {theFolder=''} //allows local opening in explorer only
{ 
 		writeCookie('foundPage', theFolder+thisPage ); //new 
		var check=readCookie ('foundPage');

if (check!= null){//alert(check); //if cookie written successfully then go to home. Then frameset will read cookie and load page into mainFramea and then delete cookie.
		top.location.replace(topLevel);//new level+'../index.htm'
		//deleteCookie('foundPage');
			}
			else {; //if cookie not written then load page from here
	top.location.replace(level+'../index.htm?'+theFolder+thisPage+'~mainFrame'); //or ?' + location.href + '~
	}				
   }
  }
 }
}

function findFramesetLeft () {//jumps Left Menu into frameset
  if (window.name!='leftNavigation'
		 && !((self.innerHeight == 0) && (self.innerWidth == 0)))
  {
		top.location.replace(topLevel); 
	}
}

function findFramesetTop () {//jumps Top Menu into frameset
  if (window.name!='topNavigation'
		 && !((self.innerHeight == 0) && (self.innerWidth == 0)))
  {
		top.location.replace(topLevel); 
	}
}


function tellMenu() {
if (parent.leftNavigation) {
 if (parent.leftNavigation.document.getElementById('pCM1DWT1p7menu1')) {//checks lowest td id to see if page loaded
	parent.leftNavigation.nudge(page,sect);
 }
}
//new remove shell.php? from all links if in frames----------***** replaces goPage in prev scripts
if (window.name=='mainFrame') {
	var i=0;
	for (i=0;i<document.links.length;i++)
	{
	 var x=document.links[i];
	 x.href=(x.href.replace('shell.php?', ''));
	 if (x.target=="_top") {
	 x.target=(x.target.replace('_top', '_self'));
	 }
	} 
if (MM_findObj('navtop')) {MM_findObj('navtop').style.visibility='visible'};//these 3 added with hidden in css stylesheet to prevent clicking before 'shell' removed from URLs
if (MM_findObj('navlow')) {MM_findObj('navlow').style.visibility='visible'};
if (MM_findObj('navlowgen')) {MM_findObj('navlowgen').style.visibility='visible'};

  }
}

//write search term to cookie so when result link is clicked and findframeset/reload happens - search is preserved.
function saveSearch (fieldValue) {
	writeCookie('search', fieldValue);
}

function getLastSearch() {//called on leftMenu load
	var lastSearch=readCookie('search');
	if (lastSearch!= null){
	document.forms[0].elements["q"].value=lastSearch;//sets Google search to last term
	deleteCookie ('search');
	}
}

// new Google results attempt to open results in same page
function resultsWin () {
//alert(0);
	var i=0;
	for (i=0;i<document.links.length;i++)
	{
	 var x=document.links[i];
	x.target='blank';
//alert(x);
//alert (x.target);
//alert(document.links.length);
	 //x.target=(x.target.replace('_self', '_blank'));
	}

}

function printPage() {
  if (window.print)
    window.print()
  else
    alert("For Internet Explorer on Mac: click in frame to print, then choose 'print' from the file menu");
}

function preloadButtons() {
	MM_preloadImages('/content/common/preroll.gif','/content/common/nexroll.gif','/content/common/preon.gif','/content/common/nexon.gif','/content/common/prevroll.gif','/content/common/prevon.gif','/content/common/nextroll.gif','/content/common/nexton.gif','/content/common/help.gif','/content/common/printerRoll.gif');
}
function preloadImages() {
	MM_preloadImages('common/shadowbox-corners.png','common/shadowbox-v.png','common/shadowbox-h.png');
}


//-----------------------start tooltip

function WebSliceSupported () {//detect ie8
    return (typeof (window.external.AddToFavoritesBar) != "undefined");
}

var gterm
var ex
function showTip(glossterm, e) {
 if (!document.all && document.getElementById && !(e.pageY)) {//if no mouse used in non IE(that is tabbed)if tabbing, page scrolls to new link after tooltip is positioned so set delay:
	gterm=glossterm;
	ex = e;
	setTimeout ("displayTip (gterm, ex)", 100);
 }else {
	displayTip (glossterm, e);
 }
}

function displayTip (glossterm, e) {
var ie8
var tipContent=defs[unescape(glossterm)],object='dHTMLToolTip',shadow='dHTMLShad', ttwidth=150, shadbackcolor='#555555',shadbackcolor2='#AEAEAE';

var bordercolor='#31B9A5';
var backcolor='#FFF8F7';
var headcolor='#007B69'; //green
var textcolor='#005145';

var theLeft, theTop, theClientWidth, theClientHeight ;

if (self.pageYOffset) // all except Explorer
{
	theLeft = self.pageXOffset;
	theTop = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
	// Explorer 6 Strict
{
	theLeft = document.documentElement.scrollLeft;
	theTop = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
	theLeft = document.body.scrollLeft;
	theTop = document.body.scrollTop;
}

if (self.innerHeight) // all except Explorer
{
	theClientWidth = self.innerWidth;
	theClientHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
{	// Explorer 6 Strict Mode
	theClientWidth = document.documentElement.clientWidth;
	theClientHeight = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	theClientWidth = document.body.clientWidth;
	theClientHeight = document.body.clientHeight;
}

	if (document.all) {//Explorer	
MM_findObj(object).innerHTML='<table id="dtable" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; color: '+textcolor+'; text-align:left; line-height: 1.3em; border:2px solid '+bordercolor+'; background-color: '+backcolor+'; width:158px;"><tr><td style="padding: 1px 4px 5px;"><span style="white-space:nowrap;"><img style="margin:0 3px -3px 0;" src="common/help.gif" width="29" height="27"><span style="position:relative; top:-8px; margin-bottom:-8px; font-size: 1em; color: '+headcolor+' "><strong>'+unescape(glossterm)+':</strong></span></span><br><span style="width:100%">'+ unescape(tipContent)+'</span></td></tr></table> ';
var layerHeight = MM_findObj(object).offsetHeight;
if (layerHeight <20) { layerHeight=100};
var layerWidth = MM_findObj(object).offsetWidth;

if (layerWidth <20) { layerWidth=ttwidth+8}; //width speced above + borders
var shadLayerWidth=layerWidth+3;

MM_findObj(shadow).style.filter="progid:DXImageTransform.Microsoft.Blur(pixelradius=2.5, makeshadow='true', shadowopacity=0.5)";
var hoho=25;
		if (MM_findObj(shadow).filters) {// if really IE - full blur shadow				
		MM_findObj(shadow).innerHTML='<table style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; color: '+textcolor+';text-align:left; line-height: 1.3em; border:2px solid '+shadbackcolor+'; background-color: '+shadbackcolor+'; width:'+shadLayerWidth+'px; "><tr><td style="padding: 1px 6px 5px 5px; "><span style="white-space:nowrap;"><img style="margin:0 3px -3px 0;" src="common/help.gif" width="29" height="27"><span style="position:relative; top:-8px; margin-bottom:-8px; font-size: 1em; color: '+headcolor+' "><strong>'+ unescape(glossterm)+':</strong></span></span><br><span style="width:100%">'+ unescape(tipContent)+'</span></td></tr></table> ';
				}
		else {//if not IE - eg Opera - paler no blur shadow		
		MM_findObj(shadow).innerHTML='<table style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; color: '+textcolor+';text-align:left; line-height: 1.3em; border:2px solid '+shadbackcolor2+'; background-color: '+shadbackcolor2+';  "><tr><td style="padding: 1px 4px 5px;"><img style="margin:0 3px -3px 0;" src="common/help.gif" width="29" height="27"><span style="position:relative; top:-8px; margin-bottom:-8px; font-size: 1em; color: '+headcolor+' "><strong>'+ unescape(glossterm)+':</strong></span><br><span style="width:100%">'+ unescape(tipContent)+'</span></td></tr></table> ';
		}

//doc.all Y position
		if (!(event.clientY)) {//if no mouse
			MM_findObj(object).style.top=10+'px';
			MM_findObj(shadow).style.top=11+'px';//was15
		}                     
		else if ((event.clientY + layerHeight+15) > (theClientHeight )) {//if near bottom
					MM_findObj(object).style.top = event.clientY + theTop - layerHeight-25+'px';
					MM_findObj(shadow).style.top = event.clientY + theTop - layerHeight-24+'px';//was-20
			}
		else { //if mouse normal
			MM_findObj(object).style.top=theTop+event.clientY+20+'px';
			MM_findObj(shadow).style.top=theTop+event.clientY+21+'px';//was25
		}
//doc.all X position
			if (!(event.clientX)||event.clientX-10<layerWidth)//if no mouse or close to left
				{
					MM_findObj(object).style.left=e.x+35+'px';
					MM_findObj(shadow).style.left=e.x+31+'px';//was40
				}
			else { //if mouse normal
				MM_findObj(object).style.left=(theLeft+event.clientX)-layerWidth-15+'px';
				MM_findObj(shadow).style.left=(theLeft+event.clientX)-layerWidth-19+'px';//was10
				}
				MM_findObj(object).style.visibility="visible"
				MM_findObj(shadow).style.visibility="visible"

		return true;
		}

	else if(!document.all && document.getElementById)//Mozilla/Safari
		{
		//event=e;

        MM_findObj(object).innerHTML='<table id="fft" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; color: '+textcolor+'; text-align: left; line-height: 1.3em; border:2px solid '+bordercolor+'; background-color: '+backcolor+';  "><tr><td style="padding:1px 4px 6px 5px"><img style="float:left; margin:0 3px -3px 0" src="common/help.gif" width="29" height="27"><div style="padding-top:6px; margin:0 0 -10px 34px; font-size: 1em; color: '+headcolor+' "><strong>'+unescape(glossterm)+':</strong></div><br>'+ unescape(tipContent)+'</td></tr></table>';
		
var layerHeight = MM_findObj(object).offsetHeight
if (layerHeight <20) { layerHeight=100};
var layerWidth = MM_findObj(object).offsetWidth
//alert(layerWidth);
if (layerWidth <20) { layerWidth=ttwidth+8}; //width speced above + borders
//shadLayerWidth=layerWidth;
//MM_findObj(shadow).width=layerWidth;
shadLayerWidth=(MM_findObj('fft').offsetWidth);
MM_findObj(shadow).style.width=shadLayerWidth+'px';
		MM_findObj(shadow).innerHTML='<div class="ui-shadow-wrp1"><table style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; text-align: left; line-height: 1.3em; border: 2px solid red;"><tr><td style="padding:1px 4px 6px 5px"><img style="float:left; margin:0 3px -3px 0" src="common/help.gif" width="29" height="27"><div style="padding-top:6px; margin:0 0 -10px 34px; font-size: 1em; color: '+textcolor+' "><strong>'+unescape(glossterm)+':</strong></div><br>'+ unescape(tipContent)+'</td></tr></table></div><i class="ui-shadow-border-nw"></i><i class="ui-shadow-border-n"></i><i class="ui-shadow-border-ne"></i><i class="ui-shadow-border-e"></i><i class="ui-shadow-border-se"></i><i class="ui-shadow-border-s"></i><i class="ui-shadow-border-sw"></i><i class="ui-shadow-border-w"></i>';
//
//<i class="ui-shadow-border-nw"></i><i class="ui-shadow-border-n"></i><i class="ui-shadow-border-ne"></i><i class="ui-shadow-border-e"></i><i class="ui-shadow-border-se"></i><i class="ui-shadow-border-s"></i><i class="ui-shadow-border-sw"></i><i class="ui-shadow-border-w"></i>';		

//NOT doc.all - Y position
//set conditional esp. for Safari which returns clientX same as pageX
var Ypos=0;
var Xpos=0;

if (e.pageY || e.pageX) //FF +Safari etc
{
	Ypos = e.pageY;
	Xpos = e.pageX;
}

	if (!(e.pageY)) {//if no mouse used (ie tabbed)
		theLeft = self.pageXOffset; 
		theTop = self.pageYOffset; 
		Ypos = theTop+250; 
		Xpos = theLeft+350; 
		MM_findObj(object).style.top=Ypos+'px'; 
		MM_findObj(shadow).style.top=Ypos+'px'; 
		//alert('hy');
		}//if near bottom
		else if ((e.pageY +layerHeight-theTop+80) > (theClientHeight)) {
					MM_findObj(object).style.top = (e.pageY -layerHeight-25+'px');
					MM_findObj(shadow).style.top = (e.pageY -layerHeight-25+'px');
			} 
		else { //if mouse normal
			MM_findObj(object).style.top=Ypos+20+'px';//was:  theTop+e.clientY+20+'px';
			MM_findObj(shadow).style.top=Ypos+20+'px';

//NOT doc.all - X position		
		}

			if ((e.pageX -theLeft-30) < (layerWidth))//if too left
				{
					MM_findObj(object).style.left = (e.pageX+30+'px') ;
					MM_findObj(shadow).style.left = (e.pageX+30+'px') ;
				}	
			else {//if mouse normal or tabbed
				MM_findObj(object).style.left=Xpos-layerWidth-30+'px';  //was:  (theLeft+e.clientX)-layerWidth-30+'px';
				MM_findObj(shadow).style.left=Xpos-layerWidth-30+'px';
				}
		MM_findObj(object).style.visibility="visible"
		MM_findObj(shadow).style.visibility="visible"
		return true;
		}


	else if (document.layers) //NN4 
				{
		MM_findObj(object).document.write('<table width="10" border="0" cellspacing="12" cellpadding="1"><tr bgcolor="'+bordercolor+'"><td><table width="150" border="0" cellspacing="0" cellpadding="5"><tr bgcolor="'+backcolor+'"><td align="center"><font style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em; color: '+headcolor+'"><strong>'+ unescape(glossterm)+'</strong><br><span style="color: '+textcolor+'"> '+ unescape(tipContent)+'</span></td></tr></table></td></tr></table>')
		MM_findObj(object).document.close()
		MM_findObj(object).top=e.y+15

		if ((e.x + MM_findObj(object).clip.width) > (window.pageXOffset + window.innerWidth))
			{
				MM_findObj(object).left = window.innerWidth - MM_findObj(object).clip.width-10;
			}
		else
			{
			MM_findObj(object).left=e.x;
			}
		MM_findObj(object).visibility="show"

		return true;
	}
	else
	{
		return true;
	}
}

function hideTip() {
var object='dHTMLToolTip'
var shadow='dHTMLShad'

if (document.all)
{
	MM_findObj(object).style.visibility="hidden"
	MM_findObj(shadow).style.visibility="hidden"
return false
}
else if(!document.all && document.getElementById)
{
	MM_findObj(object).style.visibility="hidden"
	MM_findObj(shadow).style.visibility="hidden"
return false
}
else if (document.layers)
{
	MM_findObj(object).visibility="hide"
	MM_findObj(object).left = 1;
	MM_findObj(object).top = 1;
	return false
}
else
	return true
}

//-----------------------end tooltip

//-----------------------COOKIE (text size+ also for find Frameset)

function setTextSize ()  { //called from pages--gTextSize stored in index.htm (parent) otherwise each new page initialises it
//uses global but also writes and checks for cookies.
if (window.name=='mainFrame') {//only changable in frames version
	var  c=readCookie ('mstsize')
	if (c!= null) {
		changeText (c);
		parent.gTextSize=c;	
		} else {	
		changeText (parent.gTextSize);
		}
}
}

function checkTextSize () { //called from NavLeft on load
var  c=readCookie ('mstsize');
if (c!= null) {
	hiliteTsize(c);
	} else {
	hiliteTsize(parent.gTextSize);
	}
}

function writeCookie(name,value,days){
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookie (name) {
	document.cookie = name+"=0; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/";
}

function changeText (tsize)  {
var t = MM_findObj('theBody')
var d = MM_findObj ('dHTMLToolTip')
var s = MM_findObj ('dHTMLShad')
//if (parent.leftNavigation) {
//	parent.leftNavigation.hiliteTsize(tsize)
//}
switch (tsize) {
case 't1' : t.className='bodytext1'; if(d){d.className='tooltip1'; s.style.fontSize='100%';}
break;
case 't2' : t.className='bodytext2'; if(d){d.className='tooltip2'; s.style.fontSize='110%';}
break;
case 't3' : t.className='bodytext3'; if(d){d.className='tooltip3'; s.style.fontSize='130%';}
break;
default : t.className='bodytext1'; if(d){d.className='tooltip1'; s.style.fontSize='100%'};
	}
parent.gTextSize=tsize;	
writeCookie('mstsize', tsize, 700);

}


//-------------------------------END COOKIE

function Validate(theForm) { 
var allTextInput = theForm.Liked.value+theForm.Disliked.value+theForm.Comments.value+theForm.Name.value+theForm.Email.value;
 if (allTextInput.match("http://")=="http://") {
	alert("This form does not accept weblinks")
	//theForm.reset();
	return (false);
  } else {
	theForm.action=getPostAct();
	theForm.submit();
	return (true);
 }
}

function getPostAct() {
	var v1="f"; var v2 ="back"; var v3= ".php"
	var thePage = v1+v2+v3;
	return (thePage);

}

function MM_preloadImages() {//v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);