//INITIALIZATION
///////////////////////////
var html = document.getElementsByTagName('html')[0];
var hasReqdDOM = (document.getElementsByTagName && document.getElementById);

function PageInit() {
	if ( !(hasReqdDOM) ) return;
	PopUpSafe( document.getElementsByTagName('a') );
	Rollovers( );
}

function initFlash() {
	if ( !document.getElementById || typeof(FlashObject) == 'undefined')  return;
	myFlash = new FlashObject("/images/mp/sc_flash_final.swf", "flashy", "766", "209", 6.0, "#ffffff");
	myFlash.addParam("wmode","opaque"); //fix bug with IE 5.x
	myFlash.write("fl_replace");
}

function PopUpSafe(els) {
	if (!els) return;
	var OnSiteLink = /(bankozarkstest\.aristotle\.net)|(bankozarks\.com)|(applicantharbor\.com\/ozarksjobs)|(www.mybounceproof\.com)|(www.Mybounceproof\.com)|(javascript:)|(www.tcalc\.com\/tvwww\.dll)|(bankozarks\.elliemae\.net)|(bankoftheozarks\.com)|(bankozark\.com)|(129.41.235.140)|(experienceelife\.com) /;
	
	for (var i = 0; i < els.length; i++) {
		var a = els[i];
		if (a.href.indexOf("mailto:") > -1 ){
		a.onclick = function() {return alert ("E-mails to the bank are not secure.  Please do not include any sensitive account information."); }
		}
		else if ( a.href.search(OnSiteLink) < 0 ) {
			a.onclick = function() { return PopWin("/leaving_site.asp?url="+escape(this.href),'leaving'); }
		}
		else if (a.rel.indexOf("external") >= 0 ) {
			a.onclick = function() { return PopWin(this.href,'new'); }
		}
		else if (a.rel.indexOf(':') >= 0) {
			a.onclick = function() { args = this.rel.split(':'); return PopWin(this.href,args[0],args[1],args[2]); }
		}

	}// for
}// PopUpSafe()


//IMAGE ROLLOVERS
///////////////////////////
var over = new Object();
var out = new Object();
function Rollovers() {
	if (!document.images) return;
	var imgs, a;
	var func = getRollSrc;
	var idArr = getElementsByClass('rollover');

	for (i = 0; i < idArr.length; i++) {
		imgs = idArr[i];
		if ( imgs.id=='' || !imgs.id ) imgs.id = 'ro_'+i;
		out[ imgs.id ] = new Image();
		over[ imgs.id ] = new Image();
		out[ imgs.id ].src = imgs.src;
		over[ imgs.id ].src = func(imgs.src,1);
		a = imgs.parentNode;
		if ((a && a.nodeName.toLowerCase() == 'a') ){
			a.onmouseover = function() { this.childNodes[0].src = over[this.childNodes[0].id].src; }
			a.onmouseout = function() { this.childNodes[0].src = out[this.childNodes[0].id].src;  }
			a.onfocus = function() { this.childNodes[0].src = over[this.childNodes[0].id].src; }
			a.onblur = function() { this.childNodes[0].src = out[this.childNodes[0].id].src; }
		}
		else if (imgs.nodeName.toLowerCase() == 'input') {
			imgs.onmouseover = function() { this.src = over[this.id].src; }
			imgs.onmouseout = function() { this.src = out[this.id].src; }
		}
	}
}
function getRollSrc(src, hover) { return (hover) ? src.replace(/.(gif|jpg)/,"_m.$1") : src.replace(/_m.(gif|jpg)/,".$1"); }

//UTILITY FUNCTIONS
///////////////////////////
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var iev = Detect.IEVersion();
	var els = ( iev < 6 && iev > 0 && tag == '*' ) ? node.all :  node.getElementsByTagName(tag);

	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var wini; //Reference to a window
function PopWin(url, name, width, height) {
	var s;
	if (width || height) {
		h = (height) ? height : 600;
		w = (width) ? width : 800;
		lp = (screen.width) ? (screen.width-w)/2 : 0;
		tp = (screen.height) ? (screen.height-h)/2 : 0;
		sc = (name == 'gallery') ? 'no' : 'yes';
		s = 'height='+ h +',width='+ w +',top='+tp+',left='+lp+',scrollbars='+sc+',resizable,menubar=1';
	}
	else s = '';
	wini = window.open(url,name,s);
	if (wini) wini.focus();
	return ( !wini )
}// PopWin()


function getObj() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }
  return elements;
}

function addEvent(obj,evType,fn){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,false);
	}
	else if(obj.attachEvent){
		var r=obj.attachEvent("on"+evType,fn);
	}
	else{
		if ( typeof( obj['on'+evType] ) == 'function' ) {
			var last = obj['on'+evType] ;
			obj['on'+evType] = null;
			obj['on'+evType] = function() { last(); fn(); };
		}
		else obj['on'+evType] = fn;
	}
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win -jps disabled
  //obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


// CSS/Dom AID
// based off of function found at 
// http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
//////////////////////////////////
var JSCSS = {
 Swap : function(o,c1,c2) { o.className=!JSCSS.Check(o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2); },
 Add : function(o, c1) { if(!JSCSS.Check(o,c1)){o.className+=o.className?' '+c1:c1;} },
 Remove : function(o, c1) { var rep=o.className.match(' '+c1)?' '+c1:c1; o.className=o.className.replace(rep,''); },
 Check : function(o, c1) { return new RegExp('\\b'+c1+'\\b').test(o.className) }
}

// COOKIE OBJECT
//////////////////////////////
var Cookies = {
	add : function(name, value, days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires="+date.toGMTString();
		}
		document.cookie = name+"="+value+expires+"; path=/";
	},
	read : function (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);
		}
	},
	remove : function(name) { this.add(name,"",-1); }
}

// DETECT OBJECT
///////////////////////////////////////////
var Detect = {
 IEVersion : function () {
  var rv = -1;
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
 	}
  return rv;
 },
 FlashVersion : function () {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		result = false;
		for(var i = 15; i >= 3 && result != true; i--){
			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
			flashversion = i;
		}
	}
	return flashversion;
 },
 Flash : function (ver) { return (Detect.FlashVersion() >= ver) ? true:false; }
}

JSCSS.Add(html,'hasScript');
if ( Detect.Flash(6) ) JSCSS.Add(html,'hasFlash');
addEvent(window,'load',PageInit);