/*********************************************************
For IT to remove
**********************************************************/
setBodyID = function(newID) {//move this into codebehind - sets body class
	document.getElementById('bodyID').className=newID;
}
swapChoice = function(theValue, theID) {//move this into codebehind, swaps optionals $$
	if(theValue == 'primary'){
		document.getElementById('primary_'+theID).style.display='block';
		document.getElementById('secondary_'+theID).style.display='none';
	}else{
		document.getElementById('primary_'+theID).style.display='none';
		document.getElementById('secondary_'+theID).style.display='block';
	}
}
optionalsTable = function(theID, theCheckbox) {//move this into codebehind, swaps table classname so it shows white/blue
	var temp = document.getElementById(theID);
	if(theCheckbox.checked == true){temp.className ='optionalsTable optionalsTable2';}
	else{temp.className='optionalsTable';}
}
/*********************************************************
IE5/6 fixes
**********************************************************/
function constExpression(w,x,y,z) { //fixes IE6 style tag issues
	var temp = document.getElementsByTagName(w);
	for(i=0;i<temp.length;i++){
		if(eval("temp[i].type=='"+x+"';")){
			eval("temp[i].style."+y+" = z;");
		}
	}
	return false;
}
/*********************************************************
popDIV
**********************************************************/
var resizeDelay;
var temp_targetDiv, temp_toOpacity, temp_IDtag;
resize = function(targetDiv, toOpacity, IDtag){
	popDiv1.POPdivShow(temp_targetDiv, temp_toOpacity, temp_IDtag);
}
POPdivShow = function(targetDiv, toOpacity, IDtag) {
	popInfo.INFOdivClose();
	temp_targetDiv = targetDiv;
	temp_toOpacity = toOpacity;
	temp_IDtag = IDtag;
	

	this.DivOpacity = toOpacity;
	this.popupDiv = document.getElementById('popupDiv'+IDtag);
	this.ShowDiv = document.getElementById(targetDiv);
	this.IEselectBoxFix = document.getElementById('IEselectBoxFix'+IDtag);

	if(this.popupDiv.style.display != 'inline'){ //make sure it isn't already showing b/4 animating
		POPdivShow = new fx.Combo(targetDiv, {height: false, width: false, opacity:true, duration: 300}); 
		POPdivShow.hide();
	}

	this.POPdivResize();
	window.onresize = resize;
	window.onscroll = resize; // reposition div if user scrolls - calls 24+ times
	return false; // remove browser history
}
POPdivResize = function() {
	if (this.popupDiv){ //make sure popupDiv is accessable/visible b/4 manipulating
		if(this.DivOpacity == '' || this.DivOpacity == null){this.DivOpacity=50};
		
		//SIZE BACKGROUND COLORED DIV		
		if(this.popupDiv.style.display != 'inline'){ //make sure it isn't already showing b/4 animating
			POPdivShow.toggle();
		}
		this.popupDiv.style.display = 'inline'; //have to show b/4 i can calculate
		this.IEselectBoxFix.style.display = 'inline'; //have to show b/4 i can calculate
		if (window.innerHeight){var windowHeight = window.innerHeight;} //Safari fix
		else {var windowHeight = document.documentElement.clientHeight;} //IE fix	
		var test= Math.max(document.body.scrollHeight,document.body.clientHeight,windowHeight,document.body.parentNode.scrollHeight);
		this.popupDiv.style.height = test +'px';
		this.IEselectBoxFix.style.height = test +'px';	
		
		if (document.body.clientWidth){windowWidth = document.body.clientWidth;}
		else{windowWidth = document.body.scrollWidth;} //IE fix		
		this.popupDiv.style.width = windowWidth +'px';
		this.IEselectBoxFix.style.width = windowWidth +'px';
			
		//STYLE POPUP
		this.popupDiv.style.opacity = (this.DivOpacity /100);
		this.popupDiv.style.MozOpacity = (this.DivOpacity /100);
		this.popupDiv.style.KhtmlOpacity = (this.DivOpacity /100);
		this.popupDiv.style.filter = "alpha(opacity=" + this.DivOpacity + ")";
		this.IEselectBoxFix.style.filter = "alpha(opacity=" + 0 + ")";

		//POSITION POPUP
		this.ShowDiv.style.display = 'block'; //have to show b/4 i can calculate
		this.ShowDiv.style.marginLeft = (document.body.scrollWidth - this.ShowDiv.scrollWidth)/2 + 'px';
		if (document.documentElement.scrollTop){userScrollTop = document.documentElement.scrollTop;}
		else{userScrollTop = document.body.scrollTop;} //Safari fix
		this.ShowDiv.style.marginTop = ((windowHeight - this.ShowDiv.scrollHeight)/2) + userScrollTop + 'px';
		if(this.ShowDiv.id == 'coveragePOP1' || (this.ShowDiv.scrollHeight+20 >=windowHeight)){this.ShowDiv.style.marginTop = '40px';}//has accordion feature that messes w height calculations or pop is too large
	}
	return false; // remove browser history
}
POPdivClose = function() {
	POPdivShow.hide();
	this.popupDiv.style.display = "none";
	this.ShowDiv.style.display = "none";
	this.IEselectBoxFix.style.display = "none";

	window.onresize = null;// Remove the events so that we don't reshow the message
    window.onscroll = null;

	return false; // remove browser history
}
POPdivInit = function(obj) {
	obj.POPdivShow = POPdivShow;//inherit values
	obj.POPdivResize = POPdivResize;//inherit values
	obj.POPdivClose = POPdivClose;//inherit values
}
var popDiv1 = new Object();
var popDiv2 = new Object();
var popDivErr = new Object();
POPdivInit(popDiv1);
POPdivInit(popDiv2);
POPdivInit(popDivErr);
/*********************************************************
popINFO
**********************************************************/
var INFOdivCurrentItem;
var INFOdivAnimate;
INFOdivShow = function(targetDiv, toOpacity, href) {
	clearTimeout(this.timer);
	this.targetDiv=targetDiv;
	this.toOpacity=toOpacity;
	this.href=href;
	this.timer = setTimeout("popInfo.INFOdivDOShow()",800); //delay b/4 showing
	return false;
}
INFOdivDOShow = function(targetDiv, toOpacity, href) {
	clearTimeout(this.timer);
	if(INFOdivCurrentItem != this.href){//check if already showing this item
		popInfo.INFOdivClose(); // close current popInfo
		INFOdivAnimate = new fx.Combo(this.targetDiv, {height: false, width: false, opacity:true, duration: 300}); 
		INFOdivAnimate.hide(); //hide b/4 you opacity it in
		INFOdivCurrentItem = this.href; //set to current item
		this.DivOpacity = this.toOpacity;
		this.popupDiv = document.getElementById('popupInfo');
		this.ShowDiv = document.getElementById(this.targetDiv);
		this.IEselectBoxFix = document.getElementById('IEselectBoxFixInfo');
		this.popInfoArrow = document.getElementById('popInfoArrow');
		
		this.INFOdivResize(this.toOpacity, this.href);
	}
	return false; // remove browser history
}
INFOdivResize = function(DivOpacity) {
	if (this.popupDiv){ //make sure popupDiv is accessable/visible b/4 manipulating
		if(DivOpacity == '' || DivOpacity == null){DivOpacity=30};
INFOdivAnimate.toggle();
		this.ShowDiv.style.display = 'inline'; //have to show b/4 i can calculate
		this.popupDiv.style.display = 'inline'; //have to show b/4 i can calculate
		this.IEselectBoxFix.style.display = 'inline'; //have to show b/4 i can calculate
		this.popInfoArrow.style.display = 'inline'; //have to show b/4 i can calculate
		
		this.popupDiv.style.height=this.ShowDiv.offsetHeight+10+'px';
		this.IEselectBoxFix.style.height=this.ShowDiv.offsetHeight+10+'px';
		
		var posX = this.href.offsetLeft;
		var posY = this.href.offsetTop;
		while(this.href.offsetParent){
			if(this.href==document.getElementsByTagName('body')[0]){break}
			else{
				posX=posX+this.href.offsetParent.offsetLeft;
				posY=posY+this.href.offsetParent.offsetTop;
				this.href=this.href.offsetParent;
			}
		}
		var leftOffset = (posX + 5);
		var topOffset = (posY - this.popupDiv.offsetHeight - 3);
		var arrowOffset = leftOffset + 16;
		if ((leftOffset + this.popupDiv.offsetWidth)  > document.body.scrollWidth){
			leftOffset = leftOffset - this.popupDiv.offsetWidth + 15;
			arrowOffset = leftOffset + this.popupDiv.offsetWidth - 16;
		}
		//STYLE POPUP
		this.popupDiv.style.opacity = (DivOpacity /100);
		this.popupDiv.style.MozOpacity = (DivOpacity /100);
		this.popupDiv.style.KhtmlOpacity = (DivOpacity /100);
		this.popupDiv.style.filter = "alpha(opacity=" + DivOpacity + ")";
		this.IEselectBoxFix.style.filter = "alpha(opacity=" + 0 + ")";

		//LEFT
		this.popupDiv.style.marginLeft = leftOffset + 'px';
		this.IEselectBoxFix.style.marginLeft = leftOffset + 'px';
		this.ShowDiv.style.marginLeft = leftOffset + 6 + 'px';		
		this.popInfoArrow.style.marginLeft = arrowOffset+ 'px';
		
		//TOP	
		this.popupDiv.style.marginTop = topOffset + 'px';
		this.IEselectBoxFix.style.marginTop = topOffset + 'px';
		this.ShowDiv.style.marginTop = topOffset + 5 + 'px';
		this.popInfoArrow.style.marginTop = topOffset + this.popupDiv.offsetHeight - 4 + 'px';		
	}
	return false; // remove browser history
}
INFOShow = function(){
	clearTimeout(this.timer);
	this.ShowDiv.style.display = 'inline'; //have to show b/4 i can calculate
	this.popupDiv.style.display = 'inline'; //have to show b/4 i can calculate
	this.IEselectBoxFix.style.display = 'inline'; //have to show b/4 i can calculate
	this.popInfoArrow.style.display = 'inline'; //have to show b/4 i can calculate	
}
INFOdivHide = function(){
	clearTimeout(this.timer);
	this.timer = setTimeout("popInfo.INFOdivClose()",1000);
	return false;
}
INFOdivClose = function() {
	INFOdivCurrentItem= null; //reset since no longer showing
	if(INFOdivAnimate){INFOdivAnimate.hide();} //hide b/4 you opacity it in
	clearTimeout(this.timer);
	if(this.popupDiv){this.popupDiv.style.display = "none";}
	if(this.ShowDiv){this.ShowDiv.style.display = "none";}
	if(this.IEselectBoxFix){this.IEselectBoxFix.style.display = "none";}
	if(this.popInfoArrow){this.popInfoArrow.style.display = "none";}
	return false; // remove browser history
}
var popInfo = new Object();
popInfo.INFOdivShow = INFOdivShow;//inherit values
popInfo.INFOdivDOShow = INFOdivDOShow;//inherit values
popInfo.INFOdivResize = INFOdivResize;//inherit values
popInfo.INFOdivClose = INFOdivClose;//inherit values
popInfo.INFOdivHide = INFOdivHide;
popInfo.INFOShow = INFOShow;
/*********************************************************
Add-on for mootools
**********************************************************/
showHide = {tc1 : null, tc2 : null, tArray : null, tEventArray : null};
showHide.tArray = new Array();
showHide.tEventArray = new Array();
showHide.classToogle = function(theID){//toogle item's class for mootool's fx.height (toogle the  +/-)
	this.tc1 = document.getElementById(theID);
	this.tc2 = this.tc1.className.substring(this.tc1.className.length-5,this.tc1.className.length);
	if(this.tc2 == "_show"){
		this.tc1.className = this.tc1.className.substring(0,this.tc1.className.length-5) + "_hide";
	} else if (this.tc2 == "_hide"){
		this.tc1.className = this.tc1.className.substring(0,this.tc1.className.length-5) + "_show";
	}else{}
	return false;
}
showHide.tArrayCount = function(toogle, myEvent){//count for initialzing toogles
	showHide.tArray.push(toogle);
	showHide.tEventArray.push(myEvent);
	return false;
}
showHide.initializeShowHide = function(){//call each toogle to animate
	for (var i=0; i<showHide.tArray.length; i++) {
		showHide.doShowHide('fxShowHide'+i, i);
	}
	return false;
}
showHide.clearOnChange = function (obj){ //remove show/hide feature
	document.getElementById(obj).onchange = null;
	return false;
}
showHide.clearOnClick = function (obj){ //remove show/hide feature
	document.getElementById(obj).onclick = null;
	return false;
}
showHide.doShowHide = function(obj, i){//initialze toogle to animate
	obj = new fx.Height(showHide.tArray[i]+'_Child');
	switch (showHide.tEventArray[i]) {
	case 'onChange': //show/hide on change, modify class
		$(showHide.tArray[i]).onchange = function() {
			obj.toggle();		
			showHide.classToogle(this.id);
		};
	break;
	case 'onChangeOnce': //show on change - no toggle, modify class
		$(showHide.tArray[i]).onchange = function() {
			obj.toggle();
			showHide.classToogle(this.id);
			showHide.clearOnChange(this.id);
		};
	break;
	case 'onclick-Show': //initialize AND show, modify class
		$(showHide.tArray[i]).onclick = function() {
			obj.toggle();
			showHide.classToogle(this.id);
		};
		document.getElementById(showHide.tArray[i]+'_Child').style.height = 'auto';
	break;
	case 'onclickOnce':
		$(showHide.tArray[i]).onclick = function() {
			obj.toggle();
			showHide.classToogle(this.id);
			showHide.clearOnClick(this.id);
		};
	break;
	default: //show on click w toggle, modify class
		$(showHide.tArray[i]).onclick = function() {
			obj.toggle();
			showHide.classToogle(this.id);
		};
	}
	return false;
}
/*********************************************************
Coverage Details Accordion
**********************************************************/
accordion = {tObj : null, tStretchers : null, tToggles : null, tWhitespace : null, stretchers: null, toggles : null};
accordion.tObj = new Array();
accordion.tStretchers = new Array();
accordion.tToggles = new Array();
accordion.tWhitespace = new Array();

accordion.tArrayCount = function(obj, stretchers, toggles, whitespace){//count for initialzing toogles
	accordion.tObj.push(obj);
	accordion.tStretchers.push(stretchers);
	accordion.tToggles.push(toggles);
	accordion.tWhitespace.push(whitespace);
	return false;
}
accordion.initializeShowHide = function(){//call each toogle to animate
	for (var i=0; i<accordion.tObj.length; i++) {
		accordion.doShowHide(accordion.tObj[i], i);
	}
	return false;
}
accordion.doShowHide = function(obj, i){//initialze toogle to animate
	Element.cleanWhitespace(accordion.tWhitespace[i]); //enable the accordion feature for mootools

	this.stretchers = document.getElementsByClassName(this.tStretchers[i]);
	this.toggles = document.getElementsByClassName(this.tToggles[i]);
	var temp2=0;
	if(obj == 'coverageDetailsACC1'){//issues w directly accessing object by name
		this.coverageDetailsACC1 = new fx.Accordion(this.toggles, this.stretchers, {opacity: false, height: true, duration: 600});
		temp2=0;
	}else if(obj == 'travelerInfoACC2'){//issues w directly accessing object by name
		this.travelerInfoACC2 = new fx.Accordion(this.toggles, this.stretchers, {opacity: false, height: true, duration: 600});
		temp2=1;
	}else{
		this.obj = new fx.Accordion(this.toggles, this.stretchers, {opacity: false, height: true, duration: 600});
		temp2=2;
	}
	//hash functions
	if(temp2==2){//not coverageDetailsACC1 so assume it is showing
		var found = false;
		this.toggles.each(function(h3, i){
			//var div = Element.find(h3, 'nextSibling nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				//this.obj.showThisHideOpen(div);			
				found = true;
			}
		});
		if (!found){this.obj.showThisHideOpen(this.stretchers[0]);}
	}
	if(temp2==1){//not coverageDetailsACC1 so assume it is showing
		var found = false;
		this.toggles.each(function(h3, i){
			//var div = Element.find(h3, 'nextSibling nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				//this.obj.showThisHideOpen(div);			
				found = true;
			}
		});
		if (!found){this.travelerInfoACC2.showThisHideOpen(this.stretchers[0]);}
	}
	return false;
}
/*********************************************************
HORIZONTAL SCROLL
**********************************************************/
horizontalScroll = {scrollStep : 3, timerLeft : null, timerRight : null};
horizontalScroll.scrollDivLeft = function(id){
	clearTimeout(this.timerRight);
	document.getElementById(id).scrollLeft+=this.scrollStep;
	this.timerRight=setTimeout("horizontalScroll.scrollDivLeft('"+id+"')",10);
	return false;
}
horizontalScroll.scrollDivRight = function(id){
	clearTimeout(this.timerLeft);
	document.getElementById(id).scrollLeft-=this.scrollStep;
	this.timerLeft=setTimeout("horizontalScroll.scrollDivRight('"+id+"')",10);
	return false;
}
horizontalScroll.stopMe = function(id){
	clearTimeout(this.timerRight);
	clearTimeout(this.timerLeft);
	return false;
}
/*********************************************************
DOCKING BAR
**********************************************************/
DockingBar = {};
DockingBar.ShowHide = function(F1,F2){
	var temp1 = document.getElementById('dockingbarShown');
	var temp2 = document.getElementById('dockingbarHidden');
	var temp3 = document.getElementById('IEselectBoxFixDockingBar');
	temp1.style.display = F1;
	temp2.style.display = F2;
	if(temp3){
		temp3.style.width= Math.max(temp1.offsetWidth,temp2.offsetWidth) + 'px';
	}
	return false;
}