function getRandomInt(start, total)
{
	return Math.round((Math.random() * (total - 1)) + start);
};

function imagePreloader(imageSource)
{
	var imageObject = new Image();
	imageObject.src = imageSource;
	return true;
};

function preloadArray(start, total, path, fileNameStart, fileNameEnd)
{
	for (var i = start; i < (total + start); i++)
	{
		imagePreloader(path + fileNameStart + i + fileNameEnd);
	}
	return true;
};

function setImages()
{
	// a set of numImages (currently 1) images starting with imageStartNum (1)
	var imageStartNum = 1;
	var numImages = 1;
	
	var randomImageNum = getRandomInt(imageStartNum, numImages);
	var newClassName = "image";
	
	// preload the images
	var imagePath = "/sites/hig/images/";
	var imageFileNameStart1 = "individuals_families_";
	var imageFileNameEnd = ".jpg";
	preloadArray(imageStartNum, numImages, imagePath, imageFileNameStart1, imageFileNameEnd);
	var imageFileNameStart2 = "business_";
	preloadArray(imageStartNum, numImages, imagePath, imageFileNameStart2, imageFileNameEnd);
	
	// set the classes
	document.getElementById("individualContainer").className = newClassName;
	document.getElementById("businessContainer").className = newClassName;
	
	// set the images
	document.getElementById("individualContainer").style.backgroundImage = "url(" + imagePath + imageFileNameStart1 + randomImageNum + imageFileNameEnd + ")";
	document.getElementById("businessContainer").style.backgroundImage = "url(" + imagePath + imageFileNameStart2 + randomImageNum + imageFileNameEnd + ")";
	
	// fix for IE6 issue
	document.getElementById("productContainer").style.backgroundImage = "none";
	return true;
};


var initialSearchValue;
var initialSearchColor;
var initialSearchNewsValue;
var initialSearchNewsColor;

/* search text color, button click images */
var newSearchColor = "#000";
var newSearchSubmitSrc = "/sites/hig/images/button_go_click.jpg";

var newSearchNewsColor = "#000";
var newSearchNewsSubmitSrc = "/sites/hig/images/button_go_click.jpg";

var newInternationalSubmitSrc = "/sites/hig/images/button_go_click.jpg";

function body_onload(bodyObject)
{
	// Cuurently there is only 1 image for each product so it isn't necessary to randomize product images via JS
	//setImages();
	
	imagePreloader(newSearchSubmitSrc);
	imagePreloader(newInternationalSubmitSrc);
 
	
	if (document.getElementById("searchNewsText"))
	{
		initialSearchNewsValue = document.getElementById("searchNewsText").value;
		initialSearchNewsColor = document.getElementById("searchNewsText").style.color;
	}
	
	return true;
};

// search functions
function searchForm_onsubmit(searchFormObject)
{
	// logic to process search form goes here
	searchFormObject.submit();
	return true;
};

function searchText_onfocus(searchTextObject)
{
	
	searchTextObject.value = (searchTextObject.value == initialSearchValue) ? "" : searchTextObject.value;
	searchTextObject.style.color = newSearchColor;
	return true;
};

function searchText_onblur(searchTextObject)
{
	searchTextObject.value = (searchTextObject.value == "") ? initialSearchValue : searchTextObject.value;
	searchTextObject.style.color = (searchTextObject.value == initialSearchValue) ? initialSearchColor : newSearchColor;
	return true;
};

function searchSubmit_onclick(searchSubmitObject)
{
	// switch image to clicked state
	searchSubmitObject.src = newSearchSubmitSrc;
	return true;
};

// news search functions
function searchNewsForm_onsubmit(searchNewsFormObject)
{
	//updates by bv - to include check field
	// logic to process search form goes here
	if(document.NewsSearch.elements['searchNewsText'].value=="Search News Releases" || document.NewsSearch.elements['searchNewsText'].value==""){
		alert("Please enter a Search Term");
		document.NewsSearch.elements['searchNewsText'].focus();
		return false;
	}
	else{
		
		newssearchvalue = document.NewsSearch.elements['searchNewsText'].value;
		if(newssearchvalue.indexOf("+")>=0){
			
			newssearchvalue= newssearchvalue.replace("+", ",");
			document.NewsSearch.elements['searchNewsText'].value=newssearchvalue;
		}
	
		
		searchNewsFormObject.submit();
		return true;
	}
};

function searchNewsText_onfocus(searchNewsTextObject)
{
	if(document.NewsSearch.elements['searchNewsText'].value=="Search News Releases"){
	//searchNewsTextObject.value = (searchNewsTextObject.value == initialSearchNewsValue) ? "" : searchNewsTextObject.value;
	searchNewsTextObject.value ="";
	searchNewsTextObject.style.color = newSearchNewsColor;
	return true;
	}
};

function searchNewsText_onblur(searchNewsTextObject)
{
	//searchNewsTextObject.value = (searchNewsTextObject.value == "") ? initialSearchNewsValue : searchNewsTextObject.value;
	searchNewsTextObject.style.color = (searchNewsTextObject.value == initialSearchNewsValue) ? initialSearchNewsColor : newSearchNewsColor;
	return true;
};

function searchNewsSubmit_onclick(searchNewsSubmitObject)
{
	// switch image to clicked state
	searchNewsSubmitObject.src = newSearchNewsSubmitSrc;
	return true;
};

// international form functions
function internationalForm_onsubmit()
{
	//ALTERED BY BV on 7/28/05
	// logic to process international form goes here
	//internationalFormObject.submit();
	var myIndex = internationalForm.intselction.selectedIndex;
	var optionVal = new String(internationalForm.intselction.options[myIndex].value);
	window.location = optionVal;
	return false;
};

function internationalSubmit_onclick(internationalSubmitObject)
{
	// switch image to clicked state
	internationalSubmitObject.src = newInternationalSubmitSrc;
	return true;
};

function pfversion(){
	openBWindow(pfurl, "pf", "true", "610", "400", "10", "10");
}

function openBWindow(pageToLoad, winName, rs, w, h, thex, they) {
        xposition=0; yposition=0;
        if ((parseInt(navigator.appVersion) >= 4 ) && (thex) && (they)){
                xposition = thex
                yposition = they
        }
	var resize = "";
	if (rs) {
	    resize = "resizable,";
	}

       msgWindow=open(pageToLoad,winName,'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=1,' + resize + 'width=' + w + ',height=' + h);
        if (msgWindow.opener == null){
                msgWindow.opener = self;
        }
	    if(! window.focus){

	     }
	   else{
		 msgWindow.focus();
	   }

}

function openCWindow(pageToLoad, winName, rs, w, h, thex, they) {
        xposition=0; yposition=0;
        if ((parseInt(navigator.appVersion) >= 4 ) && (thex) && (they)){
                xposition = thex
                yposition = they
        }
	var resize = "";
	if (rs) {
	    resize = "resizable,";
	}

       msgWindow=open(pageToLoad,winName,'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,' + resize + 'width=' + w + ',height=' + h);
        if (msgWindow.opener == null){
                msgWindow.opener = self;
        }
	    if(! window.focus){

	     }
	   else{
		 msgWindow.focus();
	   }

}


function formsubmit(formname,selectname){
	//alert("selectname=" + selectname);
	var selectedindex = formname[selectname].selectedIndex;
	if(selectedindex!=0){
	var optionVal = new String(formname[selectname].options[selectedindex].value);
	//
	window.location = optionVal;
	return false;
	}
	else{
		alert("Please select a value from the dropdown");
		formname[selectname].focus();
		return false;
	}
}


function formsubmitpopup(formname,selectname){
	//alert("selectname=" + selectname);
	var selectedindex = formname[selectname].selectedIndex;
	if(selectedindex!=0){
	var optionVal = new String(formname[selectname].options[selectedindex].value);
	
	openBWindow(optionVal, "popup", "true", "800", "600", "10", "10");
	return false;
	}
	else{
		alert("Please select a value from the dropdown");
		formname[selectname].focus();
		return false;
	}
}

function clearSearchForm(formname,fieldname) {
    currsearchvalue = formname[fieldname].value;
  	if(currsearchvalue.indexOf("Search The Hartford")>=0 || currsearchvalue.indexOf("Search News Releases")>=0 || currsearchvalue.indexOf("Search Woodbury Transition")>=0 || currsearchvalue.indexOf("Search Hartford Investor")>=0){
   	  setSearchEmpty(formname,fieldname);
   	}
      }


function checkSearchForm(formname,fieldname){
	currsearchvalue = formname[fieldname].value;
	if(currsearchvalue.indexOf("+")>=0){
		currsearchvalue= currsearchvalue.replace("+", ",");
		formname[fieldname].value=currsearchvalue;
	}
 
 	  if (currsearchvalue == "Search The Hartford" || currsearchvalue == "Search News Releases" || currsearchvalue == "Search Woodbury Transition" || currsearchvalue == "Search Hartford Investor"){
		setSearchEmpty(formname,fieldname);
		
		
		return true;
	  }

}

function setSearchEmpty(formname,fieldname){
  	formname[fieldname].value="";
}

function show(which){
	//Access the element by the faq ID in the div tag
	m=document.getElementById("faq");
	//alert(m);
	if (document.getElementById && document.createTextNode){
	//alert("here");
	 	//Access the first DIV and read its display attribute.
		displayFAQ=m.getElementsByTagName("div").item(which).style.display;
		//determine whether or not to display the faq text or not.  If the attribute is "none", it gets set to "block" and vice versa.
		if (displayFAQ=="block") displayFAQ="none";
			else if (displayFAQ=="" || displayFAQ=="none") displayFAQ="block";
		//Assign the changed attribute to the first DIV.
		m.getElementsByTagName("div").item(which).style.display=displayFAQ;
	}
} 

function jumpMenu(targ,selObj,restore) {
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
