﻿// Tabbed modules
   function Accordian(target) {
   	typeof target == "object" ? this.element = target : this.element = document.getElementById(target); if (!this.element) return false;  
   	this.ul = this.element.getElementsByTagName("ul")[0]; 
   	this.tabs = this.ul.getElementsByTagName("li");
   	this.tabContent = this.getTabContent();
   	this.bind();
   }

   Accordian.prototype.getTabContent = function() {
   	tabContent= new Array();    
   	this.divs = this.element.getElementsByTagName("div");
    
   	for(var i = 0; i < this.divs.length; i++) {
           if (/tabContent/i.test(this.divs[i].className)) {
           tabContent.push(this.divs[i]);           
   		}
   	}

   	return tabContent;
   }


   Accordian.prototype.bind = function() {    
   	var o = this;
   	for(var i = 0; i < this.tabs.length; i++) {
   		this.tabs[i].onclick = function() { 
   		   if (this.className != 'selected') {
   		      o.open(this); return false;
   		      var a = this.getElementsByTagName("a")[0];
   		      if (a) a.onclick = function() { 
                    return false; 
               }
   		   }
   		} 
   	}
   }

   Accordian.prototype.open = function(caller) {    
   	for(var i = 0; i < this.tabs.length; i++) {
   		var tab = this.tabs[i]; 
   		if (tab == caller) {  
   			this.collapse();
   			tab.className = "selected"
   			this.tabContent[i].style.display = "block";
   		}
   	}
   }

   Accordian.prototype.collapse = function() {
   	for(var i = 0; i < this.tabs.length; i++) {    
   		this.tabs[i].className = "";
   		this.tabContent[i].style.display = "none";                 
   	}                                                                
   }
   
      // Form Highlight   
    function initHighlight() {
        if (!document.getElementsByTagName){ return; }
        var allfields = document.getElementsByTagName("input");

        // loop through all input tags and add events
        for (var i=0; i<allfields.length; i++){
            var field = allfields[i];
            if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
                field.onfocus = function () {this. className = 'formActive';}
                field.onblur = function () {this.className = 'formInactive';}
            }
        }
    }

    function addLoadEvent(func) {   
        var oldonload = window.onload;
        if (typeof window.onload != 'function'){
            window.onload = func;
        } else {
            window.onload = function(){
            oldonload();
            func();
            }
        }
    }

    addLoadEvent(initHighlight);
    
// ---- BEGIN BROWSER DETECTION FUNCTIONS ----

var isIE4 = (document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;

/*************************************************************************

  dw_viewport.js
  version date Nov 2003
  
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.

*************************************************************************/  
  
viewport = {
  getWinWidth: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		this.width = document.body.clientWidth;
  },
  
  getWinHeight: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		this.height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		this.height = document.body.clientHeight;
  },
  
  getScrollX: function () {
    this.scrollX = 0;
  	if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		this.scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		this.scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) this.scrollX = window.scrollX;
  },
  
  getScrollY: function () {
    this.scrollY = 0;    
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		this.scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		this.scrollY = document.body.scrollTop; 
  	else if (window.scrollY) this.scrollY = window.scrollY;
  },
  
  getAll: function () {
    this.getWinWidth(); this.getWinHeight();
    this.getScrollX();  this.getScrollY();
  }
  
}

function GetViewableBrowserDimension(dimension)
{
    var bWidth = 0, bHeight = 0;
    
    if(typeof(window.innerWidth) == 'number')
    {
        //Non-IE
        bWidth = window.innerWidth;
        bHeight = window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        bWidth = document.documentElement.clientWidth;
        bHeight = document.documentElement.clientHeight;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        bWidth = document.body.clientWidth;
        bHeight = document.body.clientHeight;
    }
    else
    {
        bWidth = document.offsetWidth;
        bHeight = document.offsetHeight;
    }
    
    if(dimension.toLowerCase() == 'w')
    {
        return bWidth;
    }
    else if(dimension.toLowerCase() == 'h')
    {
        return bHeight;
    }
}

function GetViewableBrowserWidth()
{
    return GetViewableBrowserDimension('w');
}

function GetViewableBrowserHeight()
{
    return GetViewableBrowserDimension('h');
}

function GetScrollPosition(scrollType)
{
    var vXOffset;
    var vYOffset;
 
     if(typeof(window.pageXOffset) == 'number')
    {
        //Non-IE
        vXOffset = window.pageXOffset;
        vYOffset = window.pageYOffset;
    }
    else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE 6+ in 'standards compliant mode'
        vXOffset = document.documentElement.scrollLeft;
        vYOffset = document.documentElement.scrollTop;
    }
    else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //IE 4 compatible
        vXOffset = document.body.scrollLeft;
        vYOffset = document.body.scrollTop;
    }
    
    if(scrollType.toLowerCase() == 'x')
    {
        return vXOffset;
    }
    else if(scrollType.toLowerCase() == 'y')
    {
        return vYOffset;
    }
}

function GetScrollPositionWidth()
{
    return GetScrollPosition('x');
}

function GetScrollPositionHeight()
{
    return GetScrollPosition('y');
}

function GetObjectPosition(obj, positionType)
{
    var curLeft = 0;
    var curTop = 0;
    
    if(obj.offsetParent)
    {
//        alert('IN IF STATEMENT');
        curLeft = obj.offsetLeft;
        curTop = obj.offsetTop;
        
        while(obj = obj.offsetParent)
        {
            curLeft += obj.offsetLeft;
            curTop += obj.offsetTop;
        }
    }
    else
    {
//        alert(obj.offsetParent);
//        alert('Left is: ' + obj.x + '\n Top is: ' + obj.y);
    }
    
    if(positionType.toLowerCase() == 'x')
    {
        return curLeft;
    }
    else if(positionType.toLowerCase() == 'y')
    {
        return curTop;
    }
}

function GetObjectPositionX(obj)
{
    return GetObjectPosition(obj,'x');
}

function GetObjectPositionY(obj)
{
    return GetObjectPosition(obj,'y');
}

// ---- END BROWSER DETECTION FUNCTIONS ----    

// ---- BEGIN DHTML DISPLAY FUNCTIONS ----

function ToggleDivDisplay(div)
{
    if(document.getElementById(div).style.display == 'none')
    {
        document.getElementById(div).style.display = 'block';
    }
    else
    {
        document.getElementById(div).style.display = 'none';
    }
}

function CenterLayerPosition(divLayer)
{
    var elem = document.getElementById(divLayer);
    var scrollX = parseInt(GetViewableBrowserWidth());
    var scrollY = parseInt(GetViewableBrowserHeight());
    
    elem.style.left = ((scrollX/2) - (parseInt(elem.style.width)/2)) + 'px';
    elem.style.top = ((scrollY/2) + (parseInt(elem.style.height)/2) + GetScrollPositionHeight() - 120) + 'px';
    elem = null;
}

function CenterOffsetLayerPosition(divLayer, offsetX, offsetY)
{
    var elem = document.getElementById(divLayer);
    var scrollX = parseInt(GetViewableBrowserWidth());
    var scrollY = parseInt(GetViewableBrowserHeight());
    
    elem.style.left = ((scrollX/2) - offsetX - (parseInt(elem.style.width)/2)) + 'px';
    elem.style.top = ((scrollY/2) + (parseInt(elem.style.height)/2) + GetScrollPositionHeight() - 120) + 'px';
    elem = null;
}

function CenterParentOffsetLayerPosition(divLayer,divParent)
{
    //var offsetX = GetObjectPositionX(divParent);
    //var offsetY = GetObjectPositionY(divParent);
    viewport.getAll();
    document.getElementById(divLayer).style.position = 'absolute';
    
    //manually setting these values
    var progressBarWidth = 125;
    document.getElementById(divLayer).style.left = (viewport.width/2) + viewport.scrollX - (progressBarWidth/2) + "px";
    document.getElementById(divLayer).style.top = (viewport.height/2) + viewport.scrollY + "px";


}

//function CenterLayerPosition(divLayer)
//{
//    var elem = document.getElementById(divLayer);
//    var scrollY = parseInt(GetViewableBrowserHeight());

//    elem.style.left = (785 - (parseInt(elem.style.width)/2)) + 'px';
//    elem.style.top = ((scrollY/2) - (parseInt(elem.style.height)/2) + GetScrollPositionHeight() - 120) + 'px';
//    elem = null;
//}

// ---- END DHTML DISPLAY FUNCTIONS ----

// ---- BEGIN POPUP WINDOW FUNCTIONS ----

function OpenPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenBarlessScrollingPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenBarlessPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();
}

function OpenScrollingPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=yes");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenScrollingToolPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=1,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenFullPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=1,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
	//remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}



// ---- END POPUP WINDOW FUNCTIONS ----