//Top Nav 
/*	
	This script will utilize any of the links with ids in the 
	parentDivId and check if there are subNav items 
	based on that same id name with the sub_ 
	prepended to them. From this it will add the correct 
	mouse over and out functionality to both the parent 
	and child elements.
	
	To use the menu, make the appropriate changes to 
	the initilization variables, add the ids to the links within 
	the parentDivId layer, add subnavs with the 
	correct divs.
*/
onload = init;

/*
	get the browser type
*/
ns4 = (document.layers)? true : false;
ie4 = (document.all)? true : false;
dom = (document.getElementById)? true : false;

/*
	initilization variables
*/
var parentDivId = "navItems";
var subNavExt = "sub_";
var menuOverOnExt = "Over";
var hideDelay = 2500;
var menuTimer = 0;
var trackCurrentMenu = null;
var trackOnMenu = null;

function init() {
	/*
		initilization function for the menu - called onload
	*/
	if (dom || ie4) {
		menu = new addMenuItems(parentDivId);
		trackOnMenu = getOnMenu();
		startMenuOn();
	}
}

function addMenuItems(divId) {
	/*
		adds the functionality to the menu items that have 
		secondary items utilitizing the ids on each of the 
		menu links and prepending the subNavExt to them
	*/
	obj = getElement(divId);
		
	for (i=0; i<obj.childNodes.length; i++) {
		node = obj.childNodes[i];
		if (node.attributes) {
						
			node.onmouseout= function() {
				/*
					add the functionality for the mouse out and 
					hiding the appropriate menu
				*/
				subNode = getSubNode(this);
							
				if (subNode) {
					
					subNode.onmouseout = function() {
						/*
							add the functionality for the sub menu 
							items for the mouse out
						*/
						startTimer(this)
					}
					
					subNode.onmouseover = function() {
						/*
							add the functionality for the sub menu 
							items for the mouse over
						*/
						clearTimeout(menuTimer);
					}
					startTimer(subNode)
					
				} else {
					/*
						for menus that do not have any sublevels 
						we must return to the On Menu
					*/
					clearTimeout(menuTimer);
					showCurrentMenu();
					changeStyleOff();
				}
			}
			
			node.onmouseover= function() {
				/*
					add the functionality for the mouse over and 
					showing the appropriate menu
				*/
				changeStyleOff();
				if (this.attributes.id.value != trackOnMenu) {
					if (this.className.indexOf(menuOverOnExt) == -1)
						this.className+=menuOverOnExt;
				}
				
				clearMenus();
				trackCurrentMenu = this.attributes.id.value;
				
				subNode = getSubNode(this);
				clearTimeout(menuTimer);
				
				if (subNode) {
					displayBlock(subNode)
				}
			}
		}
	}	
}

function startTimer(node) {
	/*
		timeout for the menu system - controlled in millseconds 
		using hideDelay
	*/
	ID = node.attributes.id.value;
	if (trackCurrentMenu != trackOnMenu)
		menuTimer = setTimeout("displayNoneById('" + ID + "')", hideDelay);
}

function showCurrentMenu() {
	/*
		shows the current menu after a user has rolled off others 
		if there is a OnMenu
	*/
	//alert(trackOnMenu)
	if (trackOnMenu != null) {
		obj = getElement(trackOnMenu);
		subNode = getSubNode(obj);
		if (subNode != null) {
			displayBlock(subNode);
		}
	}
}

function changeStyleOff() {
	/*
		turns the style of the main nav back to its original class 
		by removing the 
	*/
	if (trackCurrentMenu != null) {
		obj = getElement(trackCurrentMenu);
		if (obj.attributes.id.value != trackOnMenu)
			obj.className=obj.className.replace(menuOverOnExt, "")
	}
}

function displayBlock(node) {
	/*
		changes display to block depending on the node - which 
		is typically a sub nav item
	*/
	node.style.display = "block";
}
function displayNone(node) {
	/*
		changes display to none depending on the node - which 
		is typically a sub nav item
	*/
	node.style.display = "none";
}
function displayNoneById(ID) {
	/*
		changes display to none based on the ID of an element 
		that you pass it
	*/
	obj = getElement(ID);
	obj.style.display = "none";
	showCurrentMenu();
	changeStyleOff();
}

function clearMenus() {
	/*
		turn off all sub menus if there are sub menus to be 
		turned off
	*/
	obj = getElement(parentDivId);
	
	for (i=0; i<obj.childNodes.length; i++) {
		node = obj.childNodes[i];
		if (node.attributes) {
			subNode = getSubNode(node);
			
			if (subNode != null)
				displayNone(subNode)
		}
	}
}

function getSubNode(node) {
	/*
		find the sub nodes based on the extension and the 
		node that it is passed
	*/
	nodeIdName = node.attributes.id.value
	nodeIdName = subNavExt + nodeIdName;
	subNode = getElement(nodeIdName);
	
	return subNode;
}

function getOnMenu() {
	/*
		find the current on utilizing the On within the class of 
		the node and then use this for tracking purposes
	*/
	obj = getElement(parentDivId);
	
	for (i=0; i<obj.childNodes.length; i++) {
		node = obj.childNodes[i];
		if (node.attributes) {
			if (node.className.indexOf("On") > 0)
				return node.attributes.id.value
		}
	}
}

function startMenuOn() {
	/*
		turn the subnav on if there is a sub node for it on the 
		load of the page
	*/	
	obj = getElement(parentDivId);
	
	for (i=0; i<obj.childNodes.length; i++) {
		node = obj.childNodes[i];
		if (node.attributes) {
		
			if (node.attributes.id.value == trackOnMenu) {
				subNode = getSubNode(node);
				if (subNode != null)
					displayBlock(subNode)
			}
		}
	}
}

function getElement(ID) {
	if (ns4) {
		return null;
	} else if (dom) {
		return (document.getElementById(ID))? document.getElementById(ID) : null;
	} else if (ie4) {
		return (document.all[ID])? document.all[ID] : null;
	}
}
//End Top Nav 

//Search
function checkSearch() { 
if (document.SearchForm.q.value == "") {
window.alert("Please enter a text value to be searched for.");
return false;
}	

document.SearchForm.q.value=trim(document.SearchForm.q.value.toLowerCase());
return true;
}

function trim(psText) {
psText = psText.replace(/^[\s]+/g,"");
psText = psText.replace(/[\s]+$/g,"");
return psText;
}

//ArticleEmail
function CheckForm(){
mystr = document.emailArticle.mailTo.value;
varArr = new Array();
varArr = mystr.split(";");

for (j=0; j<=varArr.length-1; j++){     
     if(!ValidEmail(varArr[j]))
     {strMsg = "The Colleague email address you typed is invalid.";            
     alert(strMsg);
     document.emailArticle.mailTo.focus();
     return false;
     }
}

if (!ValidEmail(document.emailArticle.mailFrom.value))
   {strMsg = "The email address you typed as yours is invalid.";            
    alert(strMsg);
    document.emailArticle.mailFrom.focus();
    return false;
   }

addRefPage();
}

function ValidEmail(email) {

var invalidChars = " /:,;";
var invalidChar;

if (email == "") {
   return false;
}

for (i=0; i<invalidChars.length; i++) {
     invalidChar = invalidChars.charAt(i)
     if (email.indexOf(invalidChar,0) != -1) {
         return false;
     }
     }
     atPos = email.indexOf("@",1)
     if (atPos == -1) {
        return false;
     }
     if (email.indexOf("@",atPos+1) != -1) {
        return false;
     }
     periodPos = email.indexOf(".",atPos)
     if (periodPos == -1) {
        return false;
     }
     if (periodPos+3 > email.length) {
        return false;
     }       

     return true;
}

function addRefPage() {
     var loc = "" + location
     if (loc.indexOf("&refPage") == -1) 
     return  
     var ref = loc.substring( loc.indexOf("&refPage=") + 9, loc.length );
     document.emailArticle.refPage.value = ref;
     return true;}

function reBuildRefPage() { 
	var loc = "" + location;
	//-- replace ending caret with empty string using a regular expression pattern
	loc = loc.replace(/\^$/, '');
	//-- 9 is the length of the string &refpage=
	var pos = loc.toLowerCase().indexOf("&refpage=") + 9;
	//-- get all text to the right of &refpage=
	var ref = "" + loc.substring(pos);
	var splitRef = ref.split("^");
	var rebuiltRef = ""
	for (var i = 0; i < splitRef.length; i++) {
        	rebuiltRef += splitRef[i];
		//-- don't append ampersand to the last item in the array
		if (i + 1 < splitRef.length){
			rebuiltRef+="&";
		}
	}
	window.open(rebuiltRef,'_self');
}

function appendLocation(theLink) {
    var thisPage = "" + location;
    var bits = thisPage.split("&");
    var s = ""
    for (var i = 0; i < bits.length; i++) {
      s += bits[i] + "^"
    }
    if (s == "") {
      theLink.href = theLink.href + "&refPage=" + thisPage
     } else {
       theLink.href = theLink.href + "&refPage=" + s
    }
    return true;
}

//Cookies
function makeCookie(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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(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;
}

//login form in c-clamp
function login(mainLoginForm){
	if (document.mainLoginForm.login_id.value == ''){
		alert('Please enter your user name')
		document.mainLoginForm.login_id.focus();
		return false;
	}
	if (document.mainLoginForm.pass.value == ''){
		alert('Please enter your password')
		document.mainLoginForm.pass.focus();
		return false;
	}	
	document.mainLoginForm.returnURL.value = window.location.href	
	document.mainLoginForm.submit()
	return true;
}

//google ads 
function google_ad_request_done(google_ads) {
    /*
     * This function is required and is used to display
     * the ads that are returned from the JavaScript
     * request. You should modify the document.write
     * commands so that the HTML they write out fits
     * with your desired ad layout.
     */
    var s = '';
    var i;

    /*
     * Verify that there are actually ads to display.
     */
    if (google_ads.length == 0) {
      return;
    }
    /*
     * If an image or Flash ad is returned, display that ad.
     * Otherwise, build a string containing all of the ads and
     * then use a document.write() command to print that string.
     */

    if (google_ads[0].type == "flash") {
      s += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
              ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
              ' WIDTH="' + google_ad.image_width +
              '" HEIGHT="' + google_ad.image_height + '">' +
              '<PARAM NAME="movie" VALUE="' + google_ad.image_url + '">'
              '<PARAM NAME="quality" VALUE="high">'
              '<PARAM NAME="AllowScriptAccess" VALUE="never">'
              '<EMBED src="' + google_ad.image_url +
              '" WIDTH="' + google_ad.image_width +
              '" HEIGHT="' + google_ad.image_height + 
              '" TYPE="application/x-shockwave-flash"' + 
              ' AllowScriptAccess="never" ' + 
              ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';

    } else if (google_ads[0].type == "image") {
      s += '<a hre' + 'f=\"' + google_ads[0].url +
              '" target="_blank" title="go to ' + google_ads[0].visible_url +
              '"><img border="0" src="' + google_ads[0].image_url +
              '"width="' + google_ads[0].image_width +
              '"height="' + google_ads[0].image_height + '"></a>';

    } else {
      s += '<div id=\"google\"><div class=\"googleSponsor\">Ads By Google</div>';
      if (google_ads.length == 1) {
        /*
         * Partners should adjust text sizes
         * so ads occupy the majority of ad space.
         */
        s += '<a hre' + 'f=\"' + google_ads[0].url + '" ' +
                          'target="_blank" ' + 
                          'onmouseout="window.status=\'\'" ' +
                          'onmouseover="window.status=\'go to ' +
                          google_ads[0].visible_url + '\'" ' +
                          'style="text-decoration:none">' +
                          '<div class=\"googleAd\">' + google_ads[0].line1 + '</div>' +
						  '<div class=\"googleAdText\">' + google_ads[0].line2 + 
						  '&nbsp;' + google_ads[0].line3 + '</div>' +
                          '<div class=\"googleAdURL\">' +
                          google_ads[0].visible_url + '</div></a></div>';
      } else if (google_ads.length > 1) {
        /*
         * For text ads, append each ad to the string.
         */
        for(i=0; i < google_ads.length; ++i) {
          s += '<a hre' + 'f=\"' + google_ads[i].url + '" ' +
                            'target="_blank" ' + 
                            'onmouseout="window.status=\'\'" ' +
                            'onmouseover="window.status=\'go to ' +
                            google_ads[i].visible_url + '\'" ' +
                            'style="text-decoration:none">' +
                            '<div class=\"googleAd\">' + google_ads[i].line1 + '</div>' + 
                            '<div class=\"googleAdText\">' + google_ads[i].line2 + 
							'&nbsp;' + google_ads[i].line3 + '</div>' +
                            '<div class=\"googleAdURL\">' +
                            google_ads[i].visible_url + '</div></a>';

        }
s += '</div>';
      }
    }

    document.write(s);
    return;
  }



//Featured Stories Slideshow on homepage
var FEATURED_STORY_ROTATE_INTERVAL = 10.0 * 1000; // milliseconds
var FEATURED_STORY_COUNT = 3;
var FeaturedStoryCurrentIndex = 0;
var FeaturedStoryTimerId = null;
var FeaturedClick = 0;
var FeaturedStories = new Array(FEATURED_STORY_COUNT);
var storyCount = 0;


function FeaturedStory(linkUrl, imageUrl, altAttribute, headline)
{
	this.LinkUrl = linkUrl;
	this.ImageUrl = imageUrl;
	this.AltAttribute = altAttribute;
	this.Headline = headline;
	
	this.PreloadedImage = new Image();
	this.PreloadedImage.src = imageUrl;
}

function Switch(featuredStoryIndex)
{
	FeaturedClick = 1;
	RotateStop();
	FeaturedStoryCurrentIndex = featuredStoryIndex;
	UpdateFeaturedStoryDisplay(featuredStoryIndex);
}

function SwitchPrevious()
{
	FeaturedClick = 1;
	RotateStop();
	RotatePrevious();
}

function SwitchNext()
{
	FeaturedClick = 1;
	RotateStop();
	RotateNext();
}

function RotatePlay()
{
	if (FeaturedClick == 0) {
		FeaturedStoryTimerId = window.setInterval('RotateNext()', FEATURED_STORY_ROTATE_INTERVAL);
	}
}

function RotateStop()
{
	if (FeaturedStoryTimerId != null)
	{
		window.clearInterval(FeaturedStoryTimerId);

		FeaturedStoryTimerId = null;
	}
}

function RotatePrevious()
{
	FeaturedStoryCurrentIndex--;

	if (FeaturedStoryCurrentIndex < 0)
	{
		FeaturedStoryCurrentIndex = FEATURED_STORY_COUNT - 1;
	}

	UpdateFeaturedStoryDisplay(FeaturedStoryCurrentIndex);
}

function RotateNext()
{
	FeaturedStoryCurrentIndex++;

	if (FeaturedStoryCurrentIndex >= FEATURED_STORY_COUNT)
	{
		FeaturedStoryCurrentIndex = 0;
	}

	UpdateFeaturedStoryDisplay(FeaturedStoryCurrentIndex);
}

function UpdateFeaturedStoryDisplay(featuredStoryIndex)
{
	var headlineAnchor1 = document.getElementById('featuredstorylinkurl1');	
	var slideshow = document.getElementById('featuredstoriesslideshownav');
	var featuredImage = document.getElementById('featuredstoryimageurl');
	var slideshowAnchors = slideshow.getElementsByTagName('a');
	var highlightIndex = 0;
	var featuredStory = FeaturedStories[featuredStoryIndex];

	headlineAnchor1.href = featuredStory.LinkUrl;	
	featuredImage.src = featuredStory.ImageUrl;
	featuredImage.alt = featuredStory.AltAttribute;
	

	for (var anchorIndex = 0; anchorIndex < slideshowAnchors.length; anchorIndex++)
	{
		switch (slideshowAnchors[anchorIndex].className)
		{
			case 'sequenceoff':
			case 'sequenceon':
				if (highlightIndex == featuredStoryIndex)
				{
					slideshowAnchors[anchorIndex].className = 'sequenceon';
				}
				else
				{
					slideshowAnchors[anchorIndex].className = 'sequenceoff';
				}

				highlightIndex++;

				break;
		}
	}
}

function toggleLayer(sourceElement, elementId)
{
      var element;
 
      if (document.getElementById)
      {
            // this is the way the standards work
            element = document.getElementById(elementId);
      }
      else if (document.all)
      {
            // this is the way old msie versions work
            element = document.all[elementId];
      }
      else if (document.layers)
      {
            // this is the way nn4 works
            element = document.layers[elementId];
      }
 
      element.style.display = element.style.display ? '' : 'inline';
      
      sourceElement.innerHTML = element.style.display ? '&lt; <strong>less</strong>' : '<strong>more</strong> &gt; ';
}


//The following 2 functions are for the tabs - blog/whitepaper/video

	function initRollTabs(rtImgClass, classname, rtArr, rtindex, rtNum, rtSelected) {
		var inc=0
		var alltags=document.all? document.all : document.getElementsByTagName("*")
		for (q=0; q<alltags.length; q++){
			if (alltags[q].className==classname){
				rtArr[inc++]=alltags[q]
			}
		}
		
		if (!document.getElementById) return

		var rtPreLoad = new Array();		
		var rtTempSrc;
		var rtTabs = document.getElementsByTagName('li');

		for (var i = 0; i < rtTabs.length; i++) {
			for (var w = 1; w <= rtNum; w++) {				
				tempnm = rtImgClass + w;				
				if (rtTabs[i].id == tempnm) {
					rtindex.value = w;
					var src = rtTabs[i].className;
					var hsrc = 'lion';

					rtTabs[i].setAttribute('hsrc', hsrc);
					rtTabs[i].setAttribute('tbid', w);
					rtTabs[i].setAttribute('ibid', i);
					if (w == rtSelected) {
						rtTabs[i].className='lion';
						rtindex = i;
					}


	
					rtTabs[i].onclick = function() {
						rtTempSrc = this.getAttribute('className');
						this.className=this.getAttribute('hsrc');
						ShowContent(this.getAttribute('tbid'), rtNum, rtArr);
						if (rtindex != this.getAttribute('ibid')) {
							rtTabs[rtindex].className='lioff';
							rtindex = this.getAttribute('ibid');
						}
					}	

					
				}
			}

		}
		ShowContent(rtSelected, rtNum, rtArr);
	}
	

	function ShowContent(divOn, numDivs, arrName){
		//get chosen message index (to show it):
		selindex = divOn - 1;
		for (p=0;p<numDivs;p++)
		{
		  if (p == selindex) {
		    arrName[p].style.display="block" //show current message
		  } else {
		    arrName[p].style.display="none" //hide previous message
		  }

		}
	}

/* Privacy Policy pop up 11-16-2007
var myDate=new Date()
var today = new Date()
myDate.setFullYear(2008,1,1)
 
if ((!getCookie('HZ-PrivacyPolicy')) && (today < myDate)){

makeCookie('HZ-PrivacyPolicy','Y',60);
window.open('/index.asp?layout=article-Body&articleID=CA6501912&cache=FALSE', 'privacy_policy_popup', 'width=298, height=270, resizable=no, scrollbars=no' ); 

}
Removed 1-14-2008 */

/* begin added 7-27-09 for Giants home page */

function hideAllFeatImages(){
  for (count=1; count<numHomePageFeatures + 1; count++)
  document.getElementById('hpFeat-image'+count).style.display='none';
}


function showHpFeatImage(box){
  document.getElementById(box).style.display='block';
}


// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* end added 7-27-09 for Giants home page */