var returnVal = false;
var fundnewwindow=false;
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)
{

	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 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 clearSearchForm(formname,fieldname) {
    currsearchvalue = formname[fieldname].value;
  	if(currsearchvalue.indexOf("Search The Hartford")>=0 || currsearchvalue.indexOf("Search Press Releases")|| currsearchvalue.indexOf("Search Hartford Investor")>=0){
   	  setSearchEmpty(formname,fieldname);
   	  return false;
   	}
      }


function checkSearchForm(formname,fieldname){
		currsearchvalue = formname[fieldname].value;
		keywordsearch = true;
		
		if(currsearchvalue.length>=2){
		
			checkChars(currsearchvalue,keywordsearch);
			if(returnVal==false){
			return false;
			}
		}
		else{
			alert("Please enter at least 2 characters into the search box");
			return false;
		}
}

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

function getCookie()
{
    var name="remember_me";
    var value = "";
   	var aCookie ="";
   	aCookie=document.cookie;
    if (document.cookie.length > 0) 
    { 
    	name=name+"=";
     	begin = document.cookie.indexOf(name,0);
    
		if (begin != -1) 
		{ 
			//begin += name.length+1; 
			begin = begin+name.length; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) 
			{
				end=document.cookie.length;
			}
			value = unescape(document.cookie.substring(begin, end)); 
		}
    } 
	setFields(value);
}


function onClickFund(fundName) {

	split = fundName.indexOf("_");
	prod = fundName.substring("0", split);
	//fundsplit = fundName.indexOf(".");
	fundbegin = (split + 1);
	fundend = fundName.indexOf(".");
	fund = fundName.substring(fundbegin, fundend);
//alert(fund);
//alert(prod);
//alert(currpage);
fundurl = "/servlet/Satellite?pagename=Investor/Page/HLI_RedirectFund&site=HI&fund=" + fund + "&prod=" + prod + "&currpage=" + currpage;

//alert(fundurl);
if(fundnewwindow==false){
	window.location=fundurl;
}else{	
	openBWindow(fundurl, "pf", "true", "610", "500", "10", "10");
}

}
  
function checkSection(){

//make sure at least one section is selected
var sectioncheck = false;
//alert(echo.sections.length);
for (var i = 0; i < echo.sections.length; i++){

  if (echo.sections[i].checked == true){
	    sectioncheck = true;
	    }
   }
  if (sectioncheck == false){
	      alert('You must select a Category');
	      returnVal = false;
	      return false;
	  }else{


	      //check include prospectus is on only if on keyword search
	      if(echo.prospectus.checked == true){
			//alert(echo.searchtype[0].checked==false);
			if(echo.searchtype[0].checked==false){
				alert('You may only search for Prospectuses when doing a Keyword Search');
				echo.prospectus.checked = false;
				returnVal = false;
				return false;
			}
			else{
			 //checkform1();
			//returnVal = true;
			}

	      }else{
	      //checkform1();
		//returnVal = true;
	      }

}

}

function checkChars(field,stype){
	//check to see string is not empty
	if(field==""){
		alert("You must enter at least one word into the search field");
	}
	else{

		//alert(field);
		var ichar="";
		hiterror="false";
		hitanderror="false";
		//check field value for +,;
		illegalchar = new Array();
		illegalchar[0]="+";
		illegalchar[1]="-";
		illegalchar[2]=";";
		illegalchar[3]="'";
		illegalchar[4]="|";
		illegalchar[5]="~";
		illegalchar[6]=",";
		illegalchar[7]="'";

		for(var a=0; a<=8; a++){
			if(field.indexOf(illegalchar[a])>=0){
					ichar = illegalchar[a];
					hiterror="true";
					break;
			}
		}
		//alert(stype);
		if(stype==true){
			//put field in lower case
			fieldlower = field.toLowerCase();

			if(fieldlower.indexOf("and")>=0){
				//alert("contains and");
				//check to see if it isn't just the word and
				if(fieldlower.length==3){
					hitanderror = "true";
					ichar = "AND";


				}
				else{
					if(fieldlower.length==4){
						if(fieldlower.indexOf(" and")>=0){
							hitanderror = "true";
							ichar = "AND";
						}
						else{
							if(fieldlower.indexOf("and ")>=0){
								hitanderror = "true";
								ichar = "AND";
							}

						}
					}

				}


			}
			else{
				if(fieldlower.indexOf("or")>=0){
								//alert("contains or");
								//check to see if it isn't just the word and
								if(fieldlower.length==2){
									hitanderror = "true";
									ichar = "OR";


								}
								else{
									if(fieldlower.length==3){
										if(fieldlower.indexOf(" or")>=0){
											hitanderror = "true";
											ichar = "OR";
										}
										else{
											if(fieldlower.indexOf("or ")>=0){
												hitanderror = "true";
												ichar = "OR";
											}

										}
									}


								}


							}				

			}



		}



		if(hiterror=="true"){
			alert("Illegal Character " + ichar +" in Search String \n\nPlease remove character");
			returnVal = false;
			return false;
		}else{
			if(hitanderror=="true"){
				alert("Please search for a word other than " + ichar);
				returnVal = false;
				return false;
			}	
			else{
				returnVal = true;
			}



		}
	 }

}
 
function selectFund(obj) {
 	var v_loc = obj.options[obj.selectedIndex].value;
 	//alert(v_loc);
 	if (v_loc != "0") {
 		document.location = v_loc;
 	}
 	
}
function selectProduct(obj) {
	var v_loc = obj.options[obj.selectedIndex].value;
	//alert(v_loc);
	if (v_loc != "0") {
		document.location = v_loc;
	}
	
}

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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

 function salesOrderMaterialPopup(srchtype,srchtxt)
 {
  var url = "https://financialprofessional.hartfordinvestor.com/portal/index.jsp?pageID=sales_order_material&searchType="+srchtype+"&searchText="+srchtxt;
  window.open(url,'SalesOrderMaterial',"width=530,height=440,scrollbars=yes,resizable=yes");
 }
