//***************************************************************************
// Update the page title so the browser's title bar is displayed correctly.
//  Set it to the intranet name if there is no title.  If the title already
//  contains the intranet name, do not add it.
//***************************************************************************
/*Use to put company name first.
  Project team decided not to use this because of SEO - hard code company name on each page instead.
if (document.title.length == 0){
	document.title = "Travelers";
} else if (document.title.indexOf("inside") < 0){
	document.title = "Travelers | " + document.title;
}

*/

function addParmToUrl(lnkID) {
	
	var parmChar = ""
	
	if (document.location.href.toLowerCase().indexOf("useportal=n") > 0) {
		
		if (document.getElementById(lnkID).search.length > 0) {
				
			parmChar = "&";
		} else {
			parmChar = "?";
		}
		document.getElementById(lnkID).href = document.getElementById(lnkID).href + parmChar + "useportal=n";
	
	}
	
}

//***************************************************************************
// Add a call to addPrinterFriendlyLogo during the body onload event if the
//  page is being built in the printer friendly mode.
//  addPrintFriendly() inserts the corporate logo at the top of the whitespace
//  in lieu of this being built by the portal framework.
//***************************************************************************
if (location.search.toLowerCase().indexOf('printerfriendly=true') >= 0){
	STA4JS.EventManager.addEvent(window, 'load', addPrintFriendlyLogo);
}
function addPrintFriendlyLogo(){
	var divWhitespace = document.getElementById('whitespaceContent');
	divWhitespace.innerHTML = "<div id='bannerLogoContainer' style='margin:15px 0'><img src='http://www.travelers.com/corporate-info/PortalWebResource.axd?n=/theme/TCOM/images/PL-Travelers-Portal-Logo.gif' border='0' /></div>" + divWhitespace.innerHTML;
}


//***************************************************************************
// Opens a new window without tools based on link passed in.  The link 
//   passed in has its href and target attributes updated to refresh
//   the current page.  This is due to defining the href attribute and
//   using JavaScript for navigation, otherwise the JavaScript and link
//   definitions will both be processed.
// [Rob Upton 02/11/2009] updated to not change the link's attributes.  It is up to
//   the calling link to accept and use the returned boolean (false).
//   For example => onclick="return openWinNoTools(this);"
//***************************************************************************
function openWinNoTools(clickedLink){
	window.open(clickedLink.href,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, copyhistory=no,fullscreen=0,left=0,top=0,screenX=0,screenY=0,width=825,height=675");
	//clickedLink.href = document.location;
	//clickedLink.target = "_self";
	return false;
}

//***************************************************************************
// Validates posting of the search control - required field.
//***************************************************************************
function validateSearch() {

	if ((document.searchTravCom.attr1.value=="") | (document.searchTravCom.attr1.value.toLowerCase()=="search this site..."))
 	{
 		alert("Please Enter Your Search Criteria");
 		document.searchTravCom.attr1.focus();
 		document.searchTravCom.attr1.select();
		return false;
	}
 
 	// fully qualify the location to www.travelers.com so is viable for investors use.
 	// ensure the querytext value is encoded  - " and & characters.
 	top.location = 'http://www.travelers.com/corporate-info/search/results.aspx?querytext=' + document.searchTravCom.attr1.value.replace(/\"/g,"%22").replace(/\&/g,"%26");
 	return false;
}


//***************************************************************************
// This function updates an image's source based on the image array and 
//   specified index.  If a link/anchor element is specified and link/target 
//   arrays are passed in, these will also be updated based on the index.
//   If all three arrays are specified, the information at the specified 
//   index is considered to be associated.
//   Once this function is called, it will continue to call itself every
//   7 seconds with an updated index such that the images are rotated in 
//   sequential order.
//   The index must be specified and numeric, and the imageId & imageArray 
//   must exist; otherwise no image rotation will be performed.
//***************************************************************************
function imageRotator(index, imageId, imageArray, altTxtArray, linkId, linkArray, targetArray) {
    try{
	// ensure the specified index will work for the image array.
  	if (index < 0 || index >= imageArray.length) {
		index = 0;
	}
	// update the image
	document.getElementById(imageId).src = imageArray[index];
	document.getElementById(imageId).alt = altTxtArray[index];
		
	// update the link only if it exists and can be valued
	var link = document.getElementById(linkId);
	if (link != null){
  	        if (linkArray != null && linkArray.length > index) {
  			link.href = linkArray[index];
  		}else{
  		   	link.href = "JavaScript://";
  		}
  		if (targetArray != null && targetArray.length > index) {
			link.target = targetArray[index];
		}else{
		    	link.target = "_top";
		}
	}
		
	// increment the index.  if it is already at the end of the array, reset to the beginning.
	if (index == imageArray.length - 1 ) {
		index = 0;
	}else{
		index++;
	}
	
	// call this funtion with the updated index in 7 seconds.
	setTimeout(function(){imageRotator(index, imageId, imageArray, altTxtArray, linkId, linkArray, targetArray);}, 7000);

    }catch(ex){
	// something happened, do nothing - images will no longer rotate.
    }
}