var ie = /MSIE/.test(navigator.userAgent);
/* =================================================== */
var addEvent;
if (document.addEventListener) {
    addEvent = function(element, type, handler) {
        element.addEventListener(type, handler, null);
    };
} else if (document.attachEvent) {
    addEvent = function(element, type, handler) {
        element.attachEvent("on" + type, handler);
    };
} else {
    addEvent = new Function; // not supported
}
/* =================================================== */
function hasClass(o,sClass) {
  if (o.className == sClass) {
    return true;
  }
  var reg = new RegExp('(^| )'+ sClass +'($| )')
  if (reg.test(o.className)) {
    return true;
  }
  return false;
}

function removeClass (o,sClass) {
	o.className = o.className.replace(/ ?active$/,'');
}

function addClass (o,sClass) {
	removeClass(o,sClass);
	o.className += " " + sClass;
}
/* =================================================== */
function getElementsByClassName(parentNode,node,classname) {
	var a = [];
	var re = new RegExp('(^| )'+classname+'( |$)');
	var els = parentNode.getElementsByTagName(node);
	for(var i=0,j=els.length; i<j; i++){
		if(re.test(els[i].className))a.push(els[i]);
	}
	return a;
}
/* =================================================== */
// Display Date / Time
function clock(){
	if (!document.getElementById){ return }
	this.start = function(){
		var self = this;
		this.date = new Date();
		// ===== Set Timezone & Daylight Savings ===========
		var day = this.date.getDay();
		var month = this.date.getMonth() + 1;
		var week = Math.floor((this.date.getDate() - 1) / 7) + 1;
		var dst = Number(month +""+ week +""+ day);
		// daylight savings range
		var start = 317  // March(3): Second(2) Sunday(7) = 327;
		var end = 1117	// November(11): First(1) Sunday(7) = 1117;

		this.offset = (dst > start && dst < end)? -5 : -6;
		this.zone = "CT";
		this.utc = this.date.getTime() + (this.date.getTimezoneOffset() * 60000);
		this.d = new Date(this.utc + (3600000*this.offset));
		// ===== Format Date ===============================
		this.day = this.addZeros(this.d.getDate());
		this.month = this.getMonthName(this.d.getMonth());
		this.yr = this.d.getYear();
		this.year = (this.yr<1000)? (this.yr+=1900) : this.yr;
		self.addSeconds();
		window.setInterval(function() {self.addSeconds();},1000);
	};
	this.addSeconds = function() {
		this.d.setSeconds(this.d.getSeconds() + 1);
		var hours = this.setMeridian(this.d.getHours());
		var minutes = this.addZeros(this.d.getMinutes());
		var seconds = this.addZeros(this.d.getSeconds());
		document.getElementById("dateTime").innerHTML = this.month+" "+this.day+" "+this.year+" "+hours+":"+minutes+":"+seconds+" "+meridian+" "+this.zone;
	};
	this.getMonthName= function(nMonth){
		var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		return months[nMonth] 
	};
	this.setMeridian = function(hours){
		meridian = (hours < 12)? "AM" : "PM";
		return (hours > 12)? hours-12 : (hours==0)? 12 : hours;
	};
	this.addZeros = function(digits){
		 return (Number(digits) < 10) ? "0"+digits : digits;
	};
}
addEvent(window,'load',startClock);
function startClock(){
	var theClock = new clock();
	theClock.start();
}
/* =================================================== */
// <select> dropdown redirect
function goto(form) {
	var index = form.company.selectedIndex;
	var page = form.company.options[index].value;
	if (page != "")
	{
		if (page.indexOf("_") == 0)  // "_http..." signifies external
		{
			window.open(page.substr(1));
		}
		else
		{
			location.href = page;
		}

	}

}
/* =================================================== */
// EOLAS workaround
function writeHeader(path,src){
	if(src != null){
		document.write('<div id="flashLogo"><object type="application/x-shockwave-flash" data="'+path+src+'" width="350" height="76"><param name="movie" value="'+path+src+'" /><param name="wmode" value="transparent" /><img src="'+path+'images/logo_header_ONEOK.gif" width="171" height="53" alt="" /></object></div>');
	} else {
		document.write('<img src="'+path+'images/logo_header_ONEOK.gif" width="171" height="53" alt="" />');
	}
}
/* =================================================== */

