﻿// JScript File
var curTabNav = "";

//Universal image swapfunction
function swapImg(aIN, aIS, aDA){var dA = "";if(document.layers && aDA){for( var i = 0; i < aDA.length; i++ ){dA += 'document.' + aDA[i] + '.';}eval(dA + 'document.' + aIN + '.src ="' + aIS + '";');return true;}else{document[aIN].src = aIS;}}

//Universal Window Function Type "yes" or "no" for scrollBar
  function flexWin(aU,aS,aW,aH,aN,aO,aX,aY,aC){
   var wN = aN ? aN : "myWin" + nocacheRandom();
   var oV = aO == "all" ? 1 : 0;
   var oS = "history="+oV+",toolbar="+oV+",location="+oV+",directories="+oV+",status="+oV+",menubar="+oV+",resizable="+oV;
   var wO = aO != "all" ? aO : oS;
   var wW = aW ? aW : 800;wO += ",width=" + wW;
   var wH = aH ? aH : 600;wO += ",height=" + wH;
   var sB = ",scrollbars="+aS;wO+=sB;
   var wX = aX ? aX :(screen.availWidth-wW)/2;wO+=",left="+wX+",screenX="+wX;
   var wY = aY ? aY :((screen.availHeight-wH)/2)-40;wO+=",top="+wY+",screenY="+wY;
   window.open(aU,wN,wO);
   aC ? window.close():"";
  }
  function clearForm(localformids){
      var localids = new Array(31,32);
      for(var i=0;i <= localformids.length;i++){
        var field = document.getElementById(localformids[i]);
        if ( field ){
            field.value = '';
        }
      }
  }

function getZipCodeCookie(header) {
    var zipcodeCookie = null;
    if(header) {
        zipcodeCookie = "Enter ZIP code";
    } else {
        zipcodeCookie = "Enter ZIP code";
    }
    var tempcookie = getCookie("gsZipcode");
    if(tempcookie) {
        return tempcookie;
    } else {
        return zipcodeCookie;
    }
}

function getCookie(key) {
    key += "=";
    var value = null;
    var allcookies = document.cookie;
    var pos = allcookies.indexOf(key);
    if(pos != -1) {
        var start = pos + key.length;
        var end = allcookies.indexOf(";", start);
        if(end == -1) end = allcookies.length;
        value = allcookies.substring(start, end);
    }
    return value;
}

function linkTracking(linkId, linkPos, url){
  // Gateway variables are being set for WSS and then sent
   // _hbSet('lid', linkId);
   // _hbSet('lpos', linkPos);
   // _hbSend();
	
	if(url != '' && url != null) {
		window.location.href = url;
	}
}

function swapImage(el,state) {
    //swaps an image with it's over state
	//over state image must use the original filename plus '_ovr'
	//i.e. - 'button.gif' would be swapped with 'button_ovr.gif'	
	
	var arrImgPath = el.src.split('/');
	var imgPath = "";
	var imgName = "";
	
	for(var i=0;i<arrImgPath.length;i++) { //loop url parts
	    if(i == arrImgPath.length-1) { //find image name
			imgName = arrImgPath[i];
			var arrImgName = imgName.split('.');

			if(state==1) {
				//add '_ovr' to the img filename
				var newImgName = arrImgName[0]+"_ovr."+arrImgName[1];
			} else {
				//remove '_ovr' from the img filename
				var arrOrigName = arrImgName[0].split('_ovr');
				var newImgName = arrOrigName[0]+"."+arrImgName[1];
			}
		} else { //reassemble url to use with the new img name
			imgPath += (arrImgPath[i] + "/");
		}
	}
	
	el.src = imgPath + newImgName;
}

function fadeObj(el, fadeDir) {
    if($(el).fx){$(el).fx.stop();}
    $(el).fx = $(el).effect('opacity', {duration: 500}).start(fadeDir); //if fadeDir = 0 (fade out), if fadeDir = 1 (fade in)	
}

//add events for bubble image links (on homepage)
function initEvents() {
    $('bubbleListImg1').addEvent('mouseover', swapImage($('bubbleListImg1'),1));
    $('bubbleListImg1').addEvent('mouseout', swapImage($('bubbleListImg1'),0));

    $('bubbleListImg2').addEvent('mouseover', swapImage($('bubbleListImg2'),1));
    $('bubbleListImg2').addEvent('mouseout', swapImage($('bubbleListImg2'),0));
}

///////////////////////OTHER FUNCTIONS/////////////////////////////////////////////////////

//Universal function to take user to a page in main window
function targetMainWindow(aU){if(window.blur){self.blur();}if (window.opener.closed){window.open(aU,"newWin");}else{window.opener.location = aU;}}

//Universal function for no cache
function nocacheRandom(){var axel = Math.random() + "";var ord = axel * 1000000000000000000;return ord;}

// generate random number within range passed in
function generateRandomNumber( argRange ) {return 1 + Math.round( Math.random() * ( argRange - 1 ) );}

//Universal function to get parameter from url srting
function getParameter(aP){var qS = new String(location.search.substring(1,location.search.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}}

//Universal function to Print Page in all browsers including IE 4
var da = (document.all) ? 1 : 0;var pr = (window.print) ? 1 : 0;var mac = (navigator.userAgent.indexOf("Mac") != -1);