/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}


/* used for setting and formatting today's date */
function GetDay(intDay){
	var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
					 "Thursday", "Friday", "Saturday")
	return DayArray[intDay]
}

function GetMonth(intMonth){
	var MonthArray = new Array("January", "February", "March",
						   "April", "May", "June",
						   "July", "August", "September",
						   "October", "November", "December") 
	return MonthArray[intMonth] 	  	 
}

function getDateStrWithDOW(){
	var today = new Date()
	var year = today.getYear()
	if(year<1000) year+=1900
	var todayStr = GetDay(today.getDay()) + ", "
	todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
	todayStr += ", " + year
	return todayStr
}

function paramLink(sDestUrl)
{
   // Send browser to link specified in sDestUrl
   // Call other paramLink function with no string substitions
   paramLink(sDestUrl, "");
}

function paramLink(sDestUrl, sSubstitutionString)
{
   // Send browser to link specified in sDestUrl.  
   // Update inbound parameters with values specified in substitutionString
   sOriginalParameters = window.location.search;
   var sNewParameters = substituteString(sOriginalParameters, sSubstitutionString)
   location.href = sDestUrl + sNewParameters;
}

function substituteString(sOriginalString, sSubstitutionString)
{
   // This function replaces values in an "original" string with values specfied in 
   // a "substitution" string.
   // The format of the substitution string is:
   // "source1||replace1, source2||replace2, ...sourceN||replaceN"

   if (sSubstitutionString != null && sSubstitutionString.length > 0)
   {
      // split the substitution string into an array of source/replace pairs (Delimiter is ",")
      var aPairList = sSubstitutionString.split(",");

      // loop through the array of pairs
      for (i = 0; i < aPairList.length; i++)
      {
         // split each pair into "source" and "replace" values(delimiter is "||")
         var aPair = aPairList[i].split("||");

         // create a regular expression to represent the source value 
         // (RegExp needed for "replace" method)
         var sSource = new RegExp(aPair[0]);

         // replace the source value with the replacement value in the original String
         var sOriginalString = sOriginalString.replace(sSource, aPair[1]);
      }
   }

   return sOriginalString;
}

// OBI signon 
function displayOBI() {
document.getElementById('signon').style.display = "block";
document.getElementById('signon-nojs').style.display = "none";
} 

function displayERD_disclosure() {
document.getElementById('erd').style.display = "block";
document.getElementById('erd-nojs').style.display = "none";
}

function displaySA_disclosure() {
document.getElementById('sa').style.display = "block";
document.getElementById('sa-nojs').style.display = "none";
}

function displayMCDSA_disclosure() {
document.getElementById('mcdsa').style.display = "block";
document.getElementById('mcdsa-nojs').style.display = "none";
}

function displayWT_disclosure() {
document.getElementById('wt').style.display = "block";
document.getElementById('wt-nojs').style.display = "none";
}

function displayOS_disclosure() {
document.getElementById('os').style.display = "block";
document.getElementById('os-nojs').style.display = "none";
}

function displayKISSA_disclosure() {
document.getElementById('kissa').style.display = "block";
document.getElementById('kissa-nojs').style.display = "none";
}

function createTarget(t){
	t = window.open("",t,"width=570,height=400,top=20,left=20,resizable=yes,scrollBars=yes,status=yes");
	t.focus(); 	
 	return true;
}


/* home page cookie setter functions */




function onlySetCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}



function createCookie(name,value,days)
{
	onlySetCookie(name,value,days);
	var makehome = document.getElementById('makehome');
	makehome.style.display = "none";
        document.rptImg = new Image(); 
        document.rptImg.src="/images/logo_key.gif?sqkl=setview" + value;
        alert ('Your Key.com default view is now set.');
}

function readCookie(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);
	}
	return null;
}



function eraseCookie(name)
{
	createCookie(name,'home','-1');
}



function getquerystring () {

	var dataPassed = '';
	if (window.location.search.length > 0){
	dataPassed = unescape (window.location.search.substring(1));
	return dataPassed;
	}
}

function file_name_only(str) {
	return str.substring(str.lastIndexOf('/') + 1)
}


function theHideOrShow() {
	var x = readCookie('homepage');
	var makehome = document.getElementById('makehome');
	var thispage = file_name_only(window.location.href);

	if (x) {
		
		if (x == 'I.html') onlySetCookie('homepage','SmallBusiness','365');
		else if (x == 'J.html') onlySetCookie('homepage','Corporate','365');
		else if (x == 'A.html') onlySetCookie('homepage','About','365');
		else {
		
			if (((thispage.indexOf('I.html') >= 0) && (x == 'SmallBusiness')) || ((thispage.indexOf('J.html') >= 0) && (x == 'Corporate')) || ((thispage.indexOf('A.html') >= 0) && (x == 'About'))) { makehome.style.display = "none"; }	
			else if ( (thispage.indexOf('I.html') >= 0) || (thispage.indexOf('J.html') >= 0) || (thispage.indexOf('A.html') >= 0) || (thispage.indexOf('index.html') >= 0) ) {
				makehome.style.display = "block";
				return;
				}
			}
		}
	
	else {
		if ( (thispage.indexOf('index.html') >= 0) || (thispage == '') ) { makehome.style.display = "none"; }
		else if ( (thispage.indexOf('I.html') >= 0) || (thispage.indexOf('J.html') >= 0) || (thispage.indexOf('A.html') >= 0) ) {
			makehome.style.display = "block";
			return;
			}
		}
	}


function togDisp(e){stopB(e);var toggleObj=document.getElementById('more');var dpToggle="";if(toggleObj.style.display==""){dpToggle="none";}toggleObj.style.display=dpToggle;return false;}
function stopB(e){ if(!e)e=window.event;e.cancelBubble=true; }
function applyWindowEvent() { if(document.getElementById('more')) { document.onclick= function(event){var dropdownObj=document.getElementById('more');if(dropdownObj.style.display == ""){togDisp(event);}} } }



function init() {
	theHideOrShow();
	applyWindowEvent();
	}


window.onload = init;




var getById = (typeof document.getElementById != "undefined");	

function setClassName(obj, className){
		getRef(obj).className= className;
}

function getRef(obj){
		if(getById)
			return(typeof obj == "string") ? document.getElementById(obj) : obj;
}

function zipvalidate()
{
 validForm = true;

  if (!/^\d{5}$/.test(document.locatorform.zip.value)) {// checks length of 5 digits
   alert('Zip code must be five numbers.');
   document.locatorform.zip.focus();
   document.locatorform.zip.select();
   validForm = false;
  }
 
 return validForm;
}

// Detect Client Browser type
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;

// Helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	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;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		} else {
			flashVer = -1;
		}
	}
	// 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;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
}

// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) {
			flash_installed = "N";
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
			
			flash_installed = "Y";
			flash_version = versionString;
			
			// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	
	return (reqVer ? false : 0.0);
}


/* for javascript dropdowns */

function togDisp(e){
	stopB(e);
	if(document.getElementById('more')) {
	var obj=document.getElementById('more');
	var dp="";
	if(obj.style.display==""){dp="none";}
	obj.style.display=dp;return false;
	}
}
function stopB(e){
	if(!e) e = window.event;e.cancelBubble=true;
}
document.onclick = function(event){
	if(document.getElementById('more')) {
		var obj = document.getElementById('more');
		if(obj.style.display == "") togDisp(event);
	}
}