//------------------------------------------//
// JavaScript General Functions Document
// Copyright St. Jame's Place 2006
// Script creator: Paulo Marques @ CCHM:Ping
//------------------------------------------//

//Function that uses the DOM to find the DIV parent node of a 
//clicked box header and passes it as an object to expandBoxContainer() for handling
function toggleBox(href) {	
	var itemEl = href.parentNode;
	while (itemEl.nodeName.toLowerCase() != "div") {
		itemEl = itemEl.parentNode;
	}
	expandBoxContainer(itemEl);
}

//Function that displays or hides sidebar 
//colapsible boxes
function expandBoxContainer(itemEl) {
	var containerId = itemEl.id + "-container"
	var containerEl = document.getElementById(containerId);
	
	if (itemEl.className == "slidetitle-expanded") {
		containerEl.style.display = "none";
		itemEl.className = "slidetitle-colapsed";
		var elStringId = itemEl.id.substring(itemEl.id.length-1);
		initHideSideBoxes(elStringId);
	} else if (itemEl.className == "slidetitle-colapsed"){
		containerEl.style.display = "block";
		itemEl.className = "slidetitle-expanded";
		var elStringId = itemEl.id.substring(itemEl.id.length-1);
		initHideSideBoxes(elStringId);
	}
}

//Function that parses the entire webpage DOM 
//to look for the sidebar boxes and hides them
function initHideSideBoxes(init) {
	var pos = 1;
	var id = ""
	var initId = "sidebar-box-"+init+"-container";
	var initIdTitle = "sidebar-box-"+init;

	var listElArray = document.getElementsByTagName("div");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i].className == "slidetitle-expanded") {
			id = "sidebar-box-"+pos;
			if (id != initIdTitle) {
				listElArray[i].className = "slidetitle-colapsed";
			}
		}
		if (listElArray[i].className == "sidebar-box-container") {
			id = "sidebar-box-"+pos+"-container";
			if (id != initId) {
				listElArray[i].style.display = "none";
			}
			pos++
		}
	}
	return true
}

/*----------------------------------*/
/* Scripted Questions functionality
/*----------------------------------*/
//Function that uses the DOM to find the DT parent node of a 
//clicked question link and passes it as an object to showContent() for handling
function showPanel(href) {
	var itemEl = href.parentNode;
	while (itemEl.nodeName.toLowerCase() != "dt") {
		itemEl = itemEl.parentNode;
	}
	showContent(itemEl);
}

//Function that displays or hides Scripted 
//Answer panels in Products & Services Page
function showContent(itemEl) {
	var listElArray = document.getElementsByTagName("dt");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i] == itemEl && listElArray[i].className == "qtab") {
			listElArray[i].className = "qtabActive";
		} else if (listElArray[i] != itemEl && listElArray[i].className == "qtabActive") {
			listElArray[i].className = "qtab";
			var xDiv = document.getElementById(listElArray[i].title);
				xDiv.style.display = "none";
		}
	}
	var divEl = document.getElementById(itemEl.title);
	if (divEl != null)
		divEl.style.display = "block";
}

//Function that parses the entire webpage DOM 
//to look for scripted answer panels and based on variables hides them
function initHidePanels() {
	var pos = 1;
	var id = ""
	var listElArray = document.getElementsByTagName("dl");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i].style.display) {
			id = "q"+pos;
			if (listElArray[i].id == id) {
				if (listElArray[i].className != "init") {
					listElArray[i].style.display = "none";
				}
				pos++
			}
		}
	}
	return true
}

//Functions below this point are written by SJP, not CCHM

//Function that opens a link in a new window without IE toolbars etc.

function open_window(url) {
			mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=1000,height=600');


}





function changeText(){

    // called from clicking the AAA image link 
    var min=1;
    var max=1.15;
   
   
    
    theBody=document.getElementById('outer-space');
    //theBody=document.body;
    currentfSize=theBody.style.fontSize;
    
    if(!currentfSize)
      currentfSize=min;
    else
      currentfSize=currentfSize.replace('em','')
    
    //currentfSize=currentfSize*1.072;
    currentfSize=currentfSize*1.14;
     
    if(currentfSize>=max)
      currentfSize=min;

    currentfSizeUnits = currentfSize+"em";
    
    theBody.style.fontSize=currentfSizeUnits; 
        
    createCookie('fontsize', currentfSizeUnits,365);
       
     		
}

function setFontSize(){

        // called from header.jsp	
	// read the cookie and set the font size
	var cookieFontSize = readCookie('fontsize');
	
		theBody=document.getElementById('outer-space');
        
	if (cookieFontSize)
		theBody.style.fontSize=cookieFontSize;
		
		
	
}


function setLargeFontSize(){

      
	
		theBody=document.getElementById('outer-space');
        

		theBody.style.fontSize='1.14em';
		
		
	
}


function setSmallFontSize(){
theBody=document.getElementById('outer-space');
        

		theBody.style.fontSize='1em';
       
	
}

function setWebTrendsCookie(value){



        // called from header.jsp	

         var readwebtrends = readCookie('webtrends');

	 if (!readwebtrends) {createCookie('webtrends', value,365);}
	
		
		
		
	
}

function createCookie(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 eraseCookie(name) {
	createCookie(name,"",-1);
}


function EnterPressed(e) {
// Code adapted from Jennifer Madden
// http://jennifermadden.com/162/examples/stringEnterKeyDetector.html

  var characterCode

//  if(e && e.which){           // NN4 specific code
 //   e = e
 //   characterCode = e.which

//  }
//  else {
 //   e = event
 //   characterCode = e.keyCode // IE specific code

 // }


var Key=e.keyCode? e.keyCode : e.charCode;

  if (Key == 13) { return true}   // Enter key is 13
  else return false



}







	