﻿//***********************************************
//* GVI Common functions
//***********************************************/
// home page redirection (drop-down)
function redirectDropDown(ddl) 
{
    var index = ddl.selectedIndex;
    if (index == -1)
        return;
    var redirect =  ddl.options[index].value;
    if (redirect == "")
        return;
    location.href = redirect; 
}

function redirectURL(url) 
{
    if (url == "")
        return;
    location.href = url; 
}


function clearText(thefield) 
{ 
    if (thefield.defaultValue==thefield.value) 
        thefield.value = "";
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

//***********************************************
//* Highlight Table Cells Script- By Menexis.com
//***********************************************/
//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
//var highlightbehavior="TR"
var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor,highlightbehavior)
{
    source=ie? event.srcElement : e.target
    if (source.tagName=="TABLE")
    return
    while(source.tagName!=highlightbehavior && source.tagName!="HTML")
        source=ns6? source.parentNode : source.parentElement;
    if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
        source.style.backgroundColor=highlightcolor;
}

function contains_ns6(master, slave) 
{ //check if slave is contained by master
    while (slave.parentNode)
    if ((slave = slave.parentNode) == master)
    return true;
    return false;
}

function changeback(e,originalcolor)
{
    if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
    return
    else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
    return
    
    if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
    source.style.backgroundColor=originalcolor
}

//***********************************************
//  Flash Player Version Detection - Rev 1.5
//  Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
//***********************************************/

// 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;

// determine ActiveX version
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];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			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;
}

// ** DETECT FLASH VERSION 
// If 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) 
		{
			tempArray         = versionStr.split(" ");
			tempString        = tempArray[1];
			versionArray      = tempString .split(",");				
		} 
		else 
		{
			versionArray      = versionStr.split(".");
		}
		versionMajor      = parseInt(versionArray[0]); 
		versionMinor      = parseInt(versionArray[1]);
		versionRevision   = parseInt(versionArray[2]);
		// alert(versionMajor +"|"+ versionMinor + "|" + versionRevision);

		// Check Major version [10803]
		if (versionMajor < reqMajorVer) return false; 
		if (versionMajor > reqMajorVer) return true;

		// versionMajor == reqMajorVer so check the minor version [10803]
		if (versionMinor < reqMinorVer) return false;
		if (versionMinor > reqMinorVer) return true;

		// versionMinor == reqMinorVer so check the revision [10803]
		if (versionRevision < reqRevision) return false;
		if (versionRevision >= reqRevision) return true;

		}

	// still processing, no condition met, assume flash not valid
	return false;
}

// Google analytics code - Will Golesorkhi - 1/07
function __utmLinker2(l,h) {
 if (!_ulink) return;
 var p,k,a="-",b="-",c="-",z="-",v="-";
 var dc=_ubd.cookie;
 if (!l || l=="") return;
 var iq = l.indexOf("?"); 
 var ih = l.indexOf("#"); 
 if (dc) {
  a=_uES(_uGC(dc,"__utma="+_udh,";"));
  b=_uES(_uGC(dc,"__utmb="+_udh,";"));
  c=_uES(_uGC(dc,"__utmc="+_udh,";"));
  z=_uES(_uGC(dc,"__utmz="+_udh,";"));
  v=_uES(_uGC(dc,"__utmv="+_udh,";"));
  k=(_uHash(a+b+c+z+v)*1)+(_udh*1);
  p="__utma="+a+"&__utmb="+b+"&__utmc="+c+"&__utmz="+z+"&__utmv="+v+"&__utmk="+k;
  return p;
 } 
 if (p) {
  if (h && ih>-1) return;
  if (h) { _udl.href=l+"#"+p; }  
  else {
   if (iq==-1 && ih==-1) _udl.href=l+"?"+p;
   else if (ih==-1) _udl.href=l+"&"+p;
   else if (iq==-1) _udl.href=l.substring(0,ih-1)+"?"+p+l.substring(ih);
   else _udl.href=l.substring(0,ih-1)+"&"+p+l.substring(ih);
  } 
 } else { _udl.href=l; }
}
//more google analytics - Ellen Roseman -8/11
// Copyright 2011 Google Inc. All Rights Reserved.

/**
* @fileoverview A simple script to automatically track Facebook and Twitter
* buttons using Google Analytics social tracking feature.
* @author api.nickm@google.com (Nick Mihailovski)
*/


/**
* Namespace.
* @type {Object}.
*/
var _ga = _ga || {};


/**
* Ensure global _gaq Google Anlaytics queue has be initialized.
* @type {Array}
*/
var _gaq = _gaq || [];


/**
* Helper method to track social features. This assumes all the social
* scripts / apis are loaded synchronously. If they are loaded async,
* you might need to add the nextwork specific tracking call to the
* a callback once the network's script has loaded.
* @param {string} opt_pageUrl An optional URL to associate the social
*     tracking with a particular page.
* @param {string} opt_trackerName An optional name for the tracker object.
*/
_ga.trackSocial = function (opt_pageUrl, opt_trackerName) {
    _ga.trackFacebook(opt_pageUrl, opt_trackerName);
    _ga.trackTwitter(opt_pageUrl, opt_trackerName);
};


/**
* Tracks Facebook likes, unlikes and sends by suscribing to the Facebook
* JSAPI event model. Note: This will not track facebook buttons using the
* iFrame method.
* @param {string} opt_pageUrl An optional URL to associate the social
*     tracking with a particular page.
* @param {string} opt_trackerName An optional name for the tracker object.
*/
_ga.trackFacebook = function (opt_pageUrl, opt_trackerName) {
    var trackerName = _ga.buildTrackerName_(opt_trackerName);
    try {
        if (FB && FB.Event && FB.Event.subscribe) {
            FB.Event.subscribe('edge.create', function (targetUrl) {
                _gaq.push([trackerName + '_trackSocial', 'facebook', 'like',
            targetUrl, opt_pageUrl]);
            });
            FB.Event.subscribe('edge.remove', function (targetUrl) {
                _gaq.push([trackerName + '_trackSocial', 'facebook', 'unlike',
            targetUrl, opt_pageUrl]);
            });
            FB.Event.subscribe('message.send', function (targetUrl) {
                _gaq.push([trackerName + '_trackSocial', 'facebook', 'send',
            targetUrl, opt_pageUrl]);
            });
        }
    } catch (e) { }
};


/**
* Returns the normalized tracker name configuration parameter.
* @param {string} opt_trackerName An optional name for the tracker object.
* @return {string} If opt_trackerName is set, then the value appended with
*     a . Otherwise an empty string.
* @private
*/
_ga.buildTrackerName_ = function (opt_trackerName) {
    return opt_trackerName ? opt_trackerName + '.' : '';
};


/**
* Tracks everytime a user clicks on a tweet button from Twitter.
* This subscribes to the Twitter JS API event mechanism to listen for
* clicks coming from this page. Details here:
* http://dev.twitter.com/pages/intents-events#click
* This method should be called once the twitter API has loaded.
* @param {string} opt_pageUrl An optional URL to associate the social
*     tracking with a particular page.
* @param {string} opt_trackerName An optional name for the tracker object.
*/
_ga.trackTwitter = function (opt_pageUrl, opt_trackerName) {
    var trackerName = _ga.buildTrackerName_(opt_trackerName);
    try {
        if (twttr && twttr.events && twttr.events.bind) {
            twttr.events.bind('tweet', function (event) {
                if (event) {
                    var targetUrl; // Default value is undefined.
                    if (event.target && event.target.nodeName == 'IFRAME') {
                        targetUrl = _ga.extractParamFromUri_(event.target.src, 'url');
                    }
                    _gaq.push([trackerName + '_trackSocial', 'twitter', 'tweet',
            targetUrl, opt_pageUrl]);
                }
            });
        }
    } catch (e) { }
};


/**
* Extracts a query parameter value from a URI.
* @param {string} uri The URI from which to extract the parameter.
* @param {string} paramName The name of the query paramater to extract.
* @return {string} The un-encoded value of the query paramater. underfined
*     if there is no URI parameter.
* @private
*/
_ga.extractParamFromUri_ = function (uri, paramName) {
    if (!uri) {
        return;
    }
    var uri = uri.split('#')[0];  // Remove anchor.
    var parts = uri.split('?');  // Check for query params.
    if (parts.length == 1) {
        return;
    }
    var query = decodeURI(parts[1]);

    // Find url param.
    paramName += '=';
    var params = query.split('&');
    for (var i = 0, param; param = params[i]; ++i) {
        if (param.indexOf(paramName) === 0) {
            return unescape(param.split('=')[1]);
        }
    }
    return;
};


// Air pricing - Will Golesorkhi - 2/07
var newwindow;
function pop_taxes_window(url)
{
      newwindow=window.open(url,'name','height=320px,width=780px');
      if (window.focus) {newwindow.focus()}
}

// Slideshow - Golesorkhi - 4/08
function OpenPhotoSlideShow(url, winWidth, winHeight)
{
	winName = "_newSlideShow"
	winParams = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + winWidth + ',height=' + winHeight;
	newwin = window.open(url, winName, winParams);
	newwin.focus();
}

// Show or hide a div 
function showOrHideDiv(theDivName, unfoundMessage)
{
    var theDiv = document.getElementById(theDivName);
    if (theDiv == null) 
    { 
        if (unfoundMessage != "") alert(unfoundMessage); 
        return;
    }
    
    if (theDiv.style.display == "inline")
    {
        theDiv.style.display = "none";
        theDiv.style.visibility = "hidden";
    }
    else
    {
        theDiv.style.display = "inline";
        theDiv.style.visibility = "visible";
    }
}
