/* =Onload Function
-------------------------------------------------- */
// Non-destructive way to add new functions to the window.onload event
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload !== 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        };
    }
}

function addUnLoadEvent(func) {
	var oldonload = window.onunload;
	if (typeof window.onunload !== 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			oldonunload();
			func();
		};
	}
}

/* =Jump Menu Script (Unobtrusive)
-------------------------------------------------- */
function initJumpMenus() {
		// Turns all <select> elements with the 'jumpmenu' class into jump menus
		var selectElements = document.getElementsByTagName("select");
		for( i = 0; i < selectElements.length; i++ ) {
				// Check for the class and make sure the element has an ID
				if( selectElements[i].className == "jumpmenu" && document.getElementById(selectElements[i].id) != "" ) {
						jumpmenu = document.getElementById(selectElements[i].id);
						jumpmenu.onchange = function() {
								if( this.options[this.selectedIndex].value != '' ) {
										// Redirect
										location.href=this.options[this.selectedIndex].value;
								}
						}
				}
		}
}

function myOpen(page,width,height) {
    if (navigator.appName == 'Netscape') {
        adjWidth = width+10;
        adjHeight = height+10;
    } else {
        adjWidth = width;
        adjHeight = height;
    }
   
    window.open(page,'windowName','width=' + adjWidth + ',height=' + adjHeight + ',toolbar=no,location=no,directories=no,resizable=yes,status=yes,menubar=yes,scrollbars=yes');
}

// Runs the Jump Menu function when the page loads
addLoadEvent(initJumpMenus);

/* =Window Functions
----------------------------------------------- */
function windowFunctions() {
  if (!document.getElementsByTagName) { return false; }
	var links, i;
  links = document.getElementsByTagName("a");
  for (i = 0; i < links.length; i++) {
    if (links[i].className.match("extLink")) {
      links[i].onclick = function() {
        disclaimer(this.href);
				return false;
      };
    }
		if (links[i].className.match("emailLink")) {
      links[i].onclick = function() {
        mailConfirm(this.href);
				return false;
      };
    }
		if (links[i].className.match("newWindow")) {
      links[i].onclick = function() {
        window.open(this.href);
				return false;
      };
    }
		if (links[i].className.match("calcLink")) {
      links[i].onclick = function() {
        window.open(this.href,'calculators','scrollbars=yes,resizable=yes,width=640,height=480');
				return false;
      };
    }
		if (links[i].className.match("testBrowser")) {
      links[i].onclick = function() {
        window.open(this.href,'securityAdvisor','scrollbars=yes,resizable=yes,width=400,height=450');
				return false;
      };
    }
  }
}
addLoadEvent(windowFunctions);

/* =Disclaimers
----------------------------------------------- */
var emailDisclaimer = "Email sent through the Internet is NOT secure. Do not use email to send us confidential information such as credit card numbers, personal identification numbers, Social Security numbers, account numbers or other confidential information.";
function mailConfirm(passedAddress) {
	if (confirm(emailDisclaimer)) {
		window.location.href = passedAddress;
	}
}

var linkDisclaimer = "You are about to leave StellarOne\'s website. We do not provide, and are not responsible for, the products, services, or overall content of the linked website. We do not endorse or guarantee the products, information, or recommendations provided by the linked website, and are not liable for any failure of the products or services advertised. Our privacy and security policies do not apply to the linked website, and you should consult the privacy and security disclosures of that website for further information.";
function disclaimer(passedWebsite) {
	var oWin;
	if (confirm(linkDisclaimer)) {
		oWin = window.open(passedWebsite,"newWindow");
		if (oWin === null || typeof(oWin) === "undefined") {
			window.location.href = passedWebsite;
		} else {
			return true;
		}
	}
}

var wmDisclaimerText = "This information will not be available beginning on Thursday, August 21 and will not be available until Saturday, August 23.  We regret any inconvenience this may cause.";
function wmDisclaimer(passedWebsite) {
	var oWin;
	if (confirm(wmDisclaimerText)) {
		oWin = window.open(passedWebsite,"newWindow");
		if (oWin === null || typeof(oWin) === "undefined") {
			window.location.href = passedWebsite;
		} else {
			return true;
		}
	}
}

/* =Print Function
----------------------------------------------- */
function printCheck() {
	if (window.print) {
		window.print();
	} else { 
		alert("Your browser does not support this print function. Please hit CTRL-P if you are using windows, or APPLE/ALT-P if using a Mac.");
	}
}


//Product Matrix Show/Hide Code With Gray Bar Background.
function toggleMoreInfoHighlight(id) {
	if (document.getElementById("moreInfo" + id).className == "hideMoreInfo") {
		//eval("objectFlag" + id + " = 1;");
		document.getElementById("moreInfo" + id).className = "showMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "&laquo;Hide";
		document.getElementById("productRowHighlight" + id).className = "rowHighlight";
	}
	else {
		//eval("objectFlag" + id + " = 0;");
		document.getElementById("moreInfo" + id).className = "hideMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "More&raquo;";
		document.getElementById("productRowHighlight" + id).className = "";
	}
}

//eval link function
function evalLink(linkURL,linkTarget,disclaimerFlag) {
	var disclaimer = 'You are leaving the Stellar One website. The site you have chosen is independent from Stellar One. We do not control these sites and do not guarantee the accuracy, completeness, efficiency or timeliness contained therein. Be aware the privacy policy of the linked website is not that of Stellar One.';

  switch(linkTarget) {
		case 0: //Same window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimer)) window.location = linkURL;
			}
			else window.location = linkURL;
			break;

		case 1: // New Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimer)) window.open(linkURL);
			}
			else window.open(linkURL);
			break;

		case 2: // Popup Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimer)) void myOpen(linkURL,500,450);
			}
			else void myOpen(linkURL,500,450);
			break;
	}
}



/* Adobe Active Content Script */
//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

