// JavaScript Document

// open print version popup

function openPrintVersion(url){
	window.open(url, 'print', 'resizeable=no,width=1000,height=600,toolbar=no,scrollbars=yes');
}
function openChat(url){
	window.open(url, 'chat', 'resizeable=no,width=550,height=550,toolbar=no,scrollbars=no,status=no');
}
// runs any function once the entire page has loaded, cross-browser compatible
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//popup opener for the exit counseling page

function exitCounseling(){
	var w = window.open('/exitcounseling.html', 'exitcounseling', 'height=640,width=970,location=no,toolbar=no,scrollbars=no,menubar=no,resizable=no,status=no');	
}

function exitCounselingtest(){
	var w = window.open('/exitcounselingtest.html', 'exitcounselingtest', 'height=640,width=970,location=no,toolbar=no,scrollbars=no,menubar=no,resizable=no,status=no');	
}

//adjusts dates on the corporate news page
function adjustDates(){
	var d = new Date();
	document.getElementById('newsmonth').value = d.getMonth();
	document.getElementById('newsyear').value = d.getFullYear();
	document.getElementById('pressmonth').value = d.getMonth();
	document.getElementById('pressyear').value = d.getFullYear();
}

// find object's position on the page
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 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];}}
}

// adjusts column heights, width, etc.
function adjustPage(){
	var i = 1;
	var topBlock;
	var rightSquareBlock;
	var rightCol;
	var leftCol;
	var altLeftCol;
	var altLeftColRight;
	
	if(document.getElementById('inner-page-main')){
		while(document.getElementById('content-block' + i)){
			topBlock = document.getElementById('content-block' + i);
			rightSquareBlock = document.getElementById('right-square-block' + i);
			if(rightSquareBlock){
				var topBlockCoords = findPos(topBlock);
				var topBlockBottomPos = topBlockCoords[1] + topBlock.offsetHeight;
		
				var rightSquareBlockCoords = findPos(rightSquareBlock);
				var rightSquareBlockHeight = topBlockBottomPos - rightSquareBlockCoords[1];
				rightSquareBlock.style.height = rightSquareBlockHeight + 'px';
			}
		
			rightCol = document.getElementById('right-col'+i);
			if(!rightCol){
				leftCol = document.getElementById('left-col'+i);
				if(leftCol){
					leftCol.style.width = '705px';	
				}
				altLeftCol = document.getElementById('left-col-alt'+i);
				altLeftColRight = document.getElementById('left-col-alt-right'+i);
				if(altLeftCol && altLeftColRight){
					altLeftCol.style.width = '705px';
					altLeftColRight.style.width = '584px';
				}
			}
			i++;
		}
	}
	else{
		rightCol = document.getElementById('right-col');
		leftCol = document.getElementById('left-col');
		rightSquareBlock = document.getElementById('right-square-block');
		if(rightCol && leftCol){
			if(rightSquareBlock && (leftCol.offsetHeight > rightCol.offsetHeight)){
				var leftColCoords = findPos(leftCol);
				var leftColBottomPos = leftColCoords[1] + leftCol.offsetHeight;
			
				var rightSquareBlockCoords = findPos(rightSquareBlock);
				var rightSquareBlockHeight = leftColBottomPos - rightSquareBlockCoords[1];
				rightSquareBlock.style.height = rightSquareBlockHeight + 'px';
			}
		}
		else {
			if(leftCol){
				leftCol.style.width = '705px';
			}
		}
	}
	
	if(document.getElementById('wide-2col')){
		rightCol = document.getElementById('right-2col');
		leftCol = document.getElementById('left-2col');
		if(rightCol && leftCol){
			if(rightCol.offsetHeight > leftCol.offsetHeight){
				leftCol.style.height = rightCol.offsetHeight - 2 + 'px';
			}
			else {
				rightCol.style.height = leftCol.offsetHeight - 2 + 'px';
			}
		}	
	}
}

//adjusts dynamic flash header
function adjustHeader(){
	var header = document.getElementById('dynamic-header');
	var offset;
	if(header){
		var dynHdrW = header.offsetWidth;
		if(document.getElementById('inner-page-wide-header')){
			offset = dynHdrW % 24;
		}
		else{
			offset = (dynHdrW - 12) % 24;
		}
		if(offset > 5){
			var adjustValue = 24 - offset;
			header.style.width = Number(dynHdrW + adjustValue) + 'px';
		}
		if(document.getElementById('inner-page-wide-noback-header')){
			header.style.width = '100%';
		}
	}
}
//initializes the flash header
function initSIFR(){
	if(typeof sIFR == "function" && document.getElementById('dynamic-header') && document.getElementById('inner-page-header')){
		sIFR.replaceElement(named({sSelector:"#inner-page-header h1", sFlashSrc:"/flash/tradegothicHead.swf", sColor:"#adc32a", sBgColor:"#000000", sWmode:"transparent", nPaddingTop:22, nPaddingBottom:0, sFlashVars:"fontSize=26"}));
	}
	else if(typeof sIFR == "function" && document.getElementById('dynamic-header') && document.getElementById('secondary-home-page-header')){
		sIFR.replaceElement(named({sSelector:"#secondary-home-page-header h1", sFlashSrc:"/flash/tradegothicHead.swf", sColor:"#adc32a", sBgColor:"#000000", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"fontSize=26"}));
	}
	else if(typeof sIFR == "function" && document.getElementById('dynamic-header') && document.getElementById('inner-page-wide-header')){
		sIFR.replaceElement(named({sSelector:"#inner-page-wide-header h1", sFlashSrc:"/flash/tradegothicHead.swf", sColor:"#adc32a", sBgColor:"#000000", sWmode:"transparent", nPaddingTop:22, nPaddingBottom:0, sFlashVars:"fontSize=26"}));
	}
	else if(typeof sIFR == "function" && document.getElementById('dynamic-header') && document.getElementById('inner-page-wide-noback-header')){
		sIFR.replaceElement(named({sSelector:"#inner-page-wide-noback-header h1", sFlashSrc:"/flash/tradegothicHead.swf", sColor:"#adc32a", sBgColor:"#000000", sWmode:"transparent", nPaddingTop:22, nPaddingBottom:0, sFlashVars:"fontSize=26"}));
	}
	else if(typeof sIFR == "function" && document.getElementById('dynamic-header') && document.getElementById('popup-title')){
		sIFR.replaceElement(named({sSelector:"#popup-title h1", sFlashSrc:"/flash/tradegothicHead.swf", sColor:"#adc32a", sBgColor:"#000000", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"fontSize=26"}));
	}
	adjustHeader();
}

//initializes advice pop-ups
function initAdvice(){
	var i = 1;
	var btn;
	var position;
	var popup;
	while(document.getElementById('tip-button' + i)){
		btn = document.getElementById('tip-button' + i);
		btn.order = i;
		btn.over = false;
		position = findPos(btn);
		btn.x = position[0];
		btn.y = position[1];
		if(document.getElementById('advice-popup' + i)){
			popup = document.getElementById('advice-popup' + i);
			popup.over = false;
			btn.onmouseover = showAdvice;
			btn.onmouseout = hideAdvice;
			popup.onmouseover = showAdvicePopup;
			popup.onmouseout = hideAdvicePopup;
		}
		i++;
	}
}
function showAdvice(){
	var popup;
	var xOffset;
	this.over = true;
	if(document.getElementById('advice-popup' + this.order)){
		popup = document.getElementById('advice-popup' + this.order);
		popup.style.display = 'block';
		xOffset = popup.offsetWidth - 99;
		popup.style.top = this.y + 19 + 'px';
		popup.style.left = this.x - xOffset + 'px';	
	}
}
function hideAdvice(){
	var popup;
	this.over = false;
	if(!document.getElementById('advice-popup' + this.order).over){
		popup = document.getElementById('advice-popup' + this.order);
		popup.style.display = 'none';
	}
}
function showAdvicePopup(){
	this.over = true;
	this.style.display = 'block';
}
function hideAdvicePopup(){
	this.over = false;
	this.style.display = 'none';
}

//if (<%=Request.Cookies("ptw")("name")%> == 'nn')
//{
//	document.body.style.margin='0';
//	document.body.style.padding='0';
//	document.body.style.background='url(/common/wrapper/images/bg_page.gif) center top repeat-y';
//	document.body.style.backgroundcolor='#e3e0dc';
//	document.body.style.font-family='Arial, Helvetica, sans-serif';
//	document.body.style.color='#333333';
//}

addLoadEvent(initSIFR);
addLoadEvent(adjustPage);
addLoadEvent(initAdvice);