var agt=navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
/*	This function sets the first form element to true if
	the first form element is named ehi.JAVASCRIPT_ENABLED
	and JavaScript is enabled. */
function checkForJavaScript() {
	if( document.forms[0] != null && document.forms[0].elements[0] != null &&
		document.forms[0].elements[0].name == "ehi.JAVASCRIPT_ENABLED") {
		document.forms[0].elements[0].value = "TRUE";
	}
} //end checkForJavaScript

var submitted = 0;
function submitOnce() {
	if (submitted == 0) {
	   submitted++;
	   return true;
	}
	return false;
} //end submitOnce

var requested = 0;
function requestQuoteOnce() {
	if (requested == 0) {
	   requested++;
	   return true;
	}
	return false;
} //end requestQuoteOnce

function resetPageVariables() {
	submitted = 0;
} //end resetPageVariables

function resetCensusPageVariables() {
	requested = 0;
} //end resetPageVariables

function instantQuotePressed() {
  return submitOnce();
} //end instantQuotePressed

function getQuotePressed() {
  return requestQuoteOnce();
} //end getQuotePressed

function Open_Window(freshurl) {
	var options = "width=620,height=480,resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,'newWin',options);
	newWin.focus();
} //end Open_Window

function Open_HelpWindow(freshurl) {
	var options = "width=566,height=331,resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,'HelpWin',options);
	newWin.focus();
} //end Open_Help Window

function Open_NewWindow(freshurl) {
	var options = "width=620,height=480,resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,'',options);
	newWin.focus();
} //end Open_Window

function Open_WindowSize(freshurl,width,height) {
	var options = "width=" + width +",height=" + height +",resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,'newWin',options);
	newWin.focus();
} //end Open_WindowSize

function Open_WindowPositionSize(freshurl,left, top, width,height) {
	var options = "left=" + left + ",top=" + top +",width=" + width +",height=" + height +",resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,'newWin',options);
	newWin.focus();
} //end Open_WindowPositionSize

function Open_WindowNamePositionSize(name, freshurl,left, top, width,height) {
	var options = "left=" + left + ",top=" + top +",width=" + width +",height=" + height +",resizable,scrollbars,toolbar";
	var newWin = window.open(freshurl,name,options);
	newWin.focus();

} //end Open_WindowNamePositionSize

function Open_WindowNoScroll(freshurl,width,height,name) {
	var options = "width=" + width +",height=" + height;
	var newWin = window.open(freshurl,name,options);
	newWin.focus();
} //end Open_WindowSize

function Plan_window2(freshurl) { 
	var options = "width=420,height=580";
   	while (freshurl.indexOf(" ") > -1) { freshurl = freshurl.replace(" ","%20") }
	var newWin = window.open(freshurl,'newWin',options);
	newWin.focus();
} //end Plan_window2

function Open_WindowMenuBar(freshurl) {
	var newWin = window.open(freshurl);
	newWin.focus();
} //end Open_Window

function enterLivePerson(aname, gname, re, name) {
	window.name = "lp_parent";
	var url = "http://server.iad.liveperson.net/hc/11354526/?cmd=file&file=visitorWantsToChat&site=11354526&byhref=1";
	var hWnd = window.open(url,"chat11354526","width=472,height=320,resizable=yes,scrollbars=yes");
	if (hWnd != null) {
		if (hWnd.opener == null) {
			hWnd.opener = self; window.name = "home"; hWnd.location.href=url;
		}
	}
} //end enterLivePerson

function resetWaitMsg() {
	if (document.PleaseWait != null){
		document.PleaseWait.src="/ehealthinsurance/images/PleaseWaitBlank.gif";
	}
	if (document.PageLoading != null){
		document.PageLoading.src="/ehealthinsurance/images/PleaseWaitBlank.gif";
	}
	if (document.title == "Small Group Employee Census")
		setFocus();
} //end resetWaitMsg

function stopEnterKey(e) {
	return (e != null && e.keyCode == '13' ? false : true);
} //end stopEnterKey

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
if(isNN)
  document.captureEvents(Event.KEYPRESS);

function autoTab(input,len, e, next){
	var keyCode = (isNN)?e.which:e.keyCode;
	var filter = (isNN)?[0,8,9]:[0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)){
	    input.value = input.value.slice(0,len);
		var obj = input.form[next];
		if (obj == null) {
		    input.focus();
		} else {
			input.form[next].focus();
		}
  }
  
  function containsElement(arr, ele){
	    var found = false, index = 0;
	    while(!found && index < arr.length)
	      if(arr[index]==ele)
	        found = true;
	      else
	        index++;
	    return found;
  }

  function getIndex(input){
	    var index = -1, i = 0, found = false;
	    while (i < input.form.length && index==-1)
	      if (input.form[i] == input)index = i;
	      else i++;
	    return index;
  }
  return true;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
