

function getTimeStamp()
{
	// get current data object
	var now = new Date();
	// convert to seconds
	timestamp = now.getTime();
	return timestamp;
}


//--------------------cookie stuff-----------------------------

function getSessionId(lbl)
{
if(cookiesOn())
  {
  inmid = GetCookie(''+lbl+'sessionid')
  if(inmid == null)
	{
	var oneYear = 365 * 24 * 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime (expDate.getTime() + oneYear);
	SetCookie(''+lbl+'sessionid',getTimeStamp(),expDate,null,null,null);
	inmid = GetCookie(''+lbl+'sessionid');
	}
  }
return inmid;
}


function GetCookie(name) {
  var result = null;
  var myCookie = " " + document.cookie + ";";
  var searchName = " " + name + "=";
  var startOfCookie = myCookie.indexOf(searchName)
  var endOfCookie;
  if (startOfCookie != -1) {
    startOfCookie += searchName.length; // skip past cookie name
    endOfCookie = myCookie.indexOf(";", startOfCookie);
    result = unescape(myCookie.substring(startOfCookie,
						   endOfCookie));
  }
  return result;
}

function SetCookie(name, value, expires, path, domain, secure) {
  var expString = ((expires == null)
		   ? "" : ("; expires=" + expires.toGMTString()))
  var pathString = ((path == null) ? "" : ("; path=" + path))
  var domainString = ((domain == null)
		   ? "" : ("; domain=" + domain))
  var secureString = ((secure == true) ? "; secure" : "")
  document.cookie = name + "=" + escape(value)
		  + expString + pathString + domainString
		  + secureString;
}


function ClearCookie(name) {
  var ThreeDays = 3 * 24 * 60 * 60 * 1000;
  var expDate = new Date();
  expDate.setTime (expDate.getTime() - ThreeDays);
  document.cookie = name + "=EXPIRED; expires="
		  + expDate.toGMTString();
}


function cookiesOn()
{
ClearCookie("cEnabled");
SetCookie("cEnabled",1,null,null,null,null);
var cCheck;
cCheck = GetCookie("cEnabled");
if(cCheck)
	{
	return 1;
	}
else
	{
	return 0;
	}

}


//----------------quick key---------------------------------

var quickkey = 13;
if(navigator.appName == "Netscape") {
 document.captureEvents(Event.KEYPRESS);
}

function qk(keyp){
if(navigator.appName == "Netscape") {
if (keyp.which == quickkey)
	{
	doEvent();
	}
}
if (navigator.appVersion.indexOf("MSIE") != -1){
  if (event.keyCode == quickkey)
	{
	doEvent();
	}
}

}

document.onkeypress = qk



//-------------------CC custom js -------------------------------------


function applyNow(inmid,setid,lbl) {
//  top.Frame1.navving=true;
  if  (inmid=='0') { ClearCookie(lbl+'sessionid');  inmid = getSessionId(lbl); }
	parent.top.location='QuestionFrame.jsp?sid=' + inmid + '&qid=' + setid+'&ccSendToPage=Questionnaire.jsp';
}

function resetquestionaire()   {
 win1 = window.open('ResetQuestionaire.jsp','ResetQuestion','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=320,height=150');
}

function openurl(url)	{
	 win1 = window.open(url,'inmwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=650,height=450');
}

function openurl3(url)	{
	 win1 = window.open(url,'inmwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=650,height=380');
}

function openurlbig(url)   {
	 win1 = window.open(url,'inmwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=800,height=600');
}

function doNothing() { }

function recommendations(id) {
    parent.location='Recommendations.jsp?sid='+sid;
}

function checkRequired() {
   if (document.forms[0] && document.forms[0].fieldcount.value) {
	 zForm = document.forms[0];
	 fieldcount = zForm.fieldcount.value;
	 for(var x=1; x<=fieldcount; x++) {
	 	if(eval('zForm.DisplayType' + x + '.value') == 'textarea'  && eval('zForm.CurrentQuestion' + x + '.value.length') >= '500' ) {
			  alert('There is a 500 character limit for ' + eval('zForm.QuestionLabel' + x +'.value') + '. Please shorten your answer.');
			  eval('zForm.CurrentQuestion' + x + '.select()');
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
	 
	    if(eval('zForm.IsRequired' + x + '.value')=='1' && eval('zForm.IsHidden' + x + '.value')=='0') {
	    if(eval('zForm.DisplayType' + x + '.value') == 'textarea' && eval('zForm.CurrentQuestion' + x + '.value') == '' ) {
			  alert('You must supply a value for ' + eval('zForm.QuestionLabel' + x +'.value'));
			  eval('zForm.CurrentQuestion' + x + '.select()');
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
	    if(eval('zForm.DisplayType' + x + '.value') == 'text'  && eval('zForm.CurrentQuestion' + x + '.value') == '' ) {
			  alert('You must supply a value for ' + eval('zForm.QuestionLabel' + x +'.value'));
			  eval('zForm.CurrentQuestion' + x + '.select()');
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
    if(eval('zForm.DisplayType' + x + '.value') == 'date'  && eval('zForm.CurrentQuestion' + x + '.value') == '' ) {
			  alert('You must supply a valid date for ' + eval('zForm.QuestionLabel' + x +'.value'));
			  eval('zForm.CurrentQuestion' + x + '.select()');
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
    if(eval('zForm.DisplayType' + x + '.value') == 'doubleselect' && eval('zForm.CurrentQuestion' + x + '.value') == '' ) {
			  alert('You must select a ' + eval('zForm.QuestionLabel' + x +'.value'));
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
    if(eval('zForm.DisplayType' + x + '.value') == 'dropdown'  && eval('zForm.CurrentQuestion' + x + '.selectedIndex') == '' ) {
			  alert('You must select a ' + eval('zForm.QuestionLabel' + x +'.value'));
			  eval('zForm.CurrentQuestion' + x + '.focus()');
		  return;
		}
		    if(eval('zForm.DisplayType' + x + '.value') == 'checkbox' ||  eval('zForm.DisplayType' + x + '.value') == 'radio' ||  eval('zForm.DisplayType' + x + '.value') == 'radio2' ||  eval('zForm.DisplayType' + x + '.value') == 'special' ) {
				flength=eval('zForm.CurrentQuestion'+ x + '.length');
				var checkboxok = 0;
				for(var c=0; c<flength;c++) {
						if(eval('zForm.CurrentQuestion' + x + '[c].checked')==true)	{checkboxok=1;}
				}
				if(!checkboxok) {
	    alert('You must select a value for ' + eval('zForm.QuestionLabel' + x +'.value'));
	    eval('zForm.CurrentQuestion' + x + '[0].focus()');
	    return;
	}
			}
	     }
	  }

	  //check master fields
	  if (zForm.masterFields) {
	    var mffieldcount = zForm.masterFields.value;
	    if (mffieldcount > 0) {
	      var parms;
	      for(var xx=1; xx<=mffieldcount; xx++) {
		eval('parms =  zForm.CCMF'+xx+'.value.split(\'~\');')
		if (eval('zForm.DisplayType'+parms[0]+'.value==\'dropdown\'')) {
		   eval('zForm.'+parms[1]+'.value=zForm.CurrentQuestion'+parms[0]+'[zForm.CurrentQuestion'+parms[0]+'.selectedIndex].text');
		} else if (eval('zForm.DisplayType'+parms[0]+'.value==\'radio\'')) {
		    flength=eval('zForm.CurrentQuestion'+ parms[0] + '.length');
		    for(var c=0; c<flength;c++) {
		      if(eval('zForm.CurrentQuestion' + parms[0] + '[c].checked')==true){
			eval('zForm.'+parms[1]+'.value=zForm.CurrentQuestion'+parms[0]+'[c].value');
		      }
		    }
		} else {
		  if (eval('zForm.CurrentQuestion'+parms[0]+'')) {
		    eval('zForm.'+parms[1]+'.value=zForm.CurrentQuestion'+parms[0]+'.value');
		  }
		}
	       //check for ~~~
	       if (eval('zForm.'+parms[1]+'.value.indexOf(\'~~~\') > 0')) {
		 eval('zForm.'+parms[1]+'.value=zForm.'+parms[1]+'.value.substring((zForm.'+parms[1]+'.value.indexOf(\'~~~\')+3),zForm.'+parms[1]+'.value.length)');
	       }
	       }
	      }
	    }
	  }

	  //save
	  zForm.frmaction.value='save';
	  zForm.submit();

 }
 
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
 
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
 
    var newstr = string.substring(0,i) + by;
 
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
 
    return newstr;
}

var revcheck=0;
function register2() {
 
    zForm = document.forms[0];
    elems = zForm.elements.length;
     for(var x=0; x<elems; x++) {
	if(zForm.elements[x].type=='text') {
	    if(zForm.elements[x].value == '' && zForm.elements[x].name != 'AddressLine2') {
		alert('You must supply a value for ' + zForm.elements[x].name);
		zForm.elements[x].select();
		zForm.elements[x].focus();
		return;
	    }
	 }
    }
	
	mytext = zForm.Revenue.value
	mytext2 = zForm.Employees.value
 
var myresult = replace(mytext,',','');var myresult = replace(myresult,'.000','000');var myresult = replace(myresult,'.00','');var myresult = replace(myresult,'.0','');var myresult = replace(myresult,'.5M','500000');var myresult = replace(myresult,'.4M','400000');var myresult = replace(myresult,'.3M','300000');var myresult = replace(myresult,'.2M','200000');var myresult = replace(myresult,'.1M','100000');var myresult = replace(myresult,'.6M','600000');var myresult = replace(myresult,'.7M','700000');var myresult = replace(myresult,'.8M','800000');var myresult = replace(myresult,'.9M','900000');var myresult = replace(myresult,'.','');var myresult = replace(myresult,'$','');var myresult = replace(myresult,'USD','');var myresult = replace(myresult,'CAN','');var myresult = replace(myresult,'about','');var myresult = replace(myresult,'About','');var myresult = replace(myresult,'ABOUT','');var myresult = replace(myresult,'approx','');var myresult = replace(myresult,'+','');var myresult = replace(myresult,'K','000');var myresult = replace(myresult,'k','000');var myresult = replace(myresult,'million','000000');var myresult = replace(myresult,'Million','000000');var myresult = replace(myresult,'MILLION','000000');var myresult = replace(myresult,'Mil','000000');var myresult = replace(myresult,'MIL','000000');var myresult = replace(myresult,'mil','000000');var myresult = replace(myresult,'mil.','000000');var myresult = replace(myresult,'MIL.','000000');var myresult = replace(myresult,'Mil.','000000');var myresult = replace(myresult,' ','');
	if ((myresult.indexOf('-')> -1) || (myresult.indexOf('?')> -1)){alert('We need a numeric value for the revenue.');return;}
	var myresult2 = replace(mytext2,'about','');var myresult2 = replace(myresult2,'average','');var myresult2 = replace(myresult2,'approx','');var myresult2 = replace(myresult2,'About','');var myresult2 = replace(myresult2,' ','');var myresult2 = replace(myresult2,'none','0');
  
  for (var i=0, len=myresult2.length-1, valid='0123456789.' ; i<len ; i++) 
        if (valid.indexOf(myresult2.substring(i,i+1)) == -1) {
            alert('Please enter a numeric value for Employees. Example 75');
            return;
        }
		
 
 for (var i=0, len=myresult.length-1, valid='0123456789.' ; i<len ; i++) 
        if (valid.indexOf(myresult.substring(i,i+1)) == -1) {
            alert('Please enter a numeric value for Revenue. Example 4500000');
            return;
        }
		
	//	if (myresult.length <=5) {
      //      alert('Minimum revenue is $1 million. Use numeric characters only.');
        //    return;
     //   }
		
zForm.Employees.value = myresult2
zForm.Revenue.value = myresult
		
		if ((myresult>=11000000 && revcheck==0 && myresult2<8) || (myresult>=20000000 && revcheck==0 && myresult2<15)) {
			var revstr=""+myresult;revstr=revstr.substring(0,(myresult.length-6))
            alert('Please verify that your revenue of $'+revstr +' MILLION is correctly entered. Then click Next.');revcheck=1;
            return;
        }

    zForm.FullUserName.value = zForm.FirstName.value + ' ' + zForm.LastName.value;
    zForm.frmaction.value='register2';
     zForm.submit();
}

function openphoneurl2(SessionId) {
  openWin= window.open ('http://insurepro.net/cgi/start.exe/apps/livehelp/index.html?gids=Sales','LHC_'+Math.floor(Math.random()*100000),'resizable,height=340,width=400');
 }


function isDigit(num) {
 var string = '1234567890';
    if (string.indexOf(num)  != -1) { return true; } else { return false; }
}

function isNumeric(val) {
   var dp = false;
   for (var i=0; i<val.length; i++) {
      if ( !isDigit(val.charAt(i)) ) {
	if ( val.charAt(i) == '.' ) {
	    if (dp==true) { return false; } else { dp=true; }
	}
	else { return false;
	}
      }
   }
 return true;
 }

//------------------CC action page stuff  ----------------------


function retake(lablecode,id3) {

var newsessionid = getNewSessionId(lablecode);
parent.location='QuestionFrame.jsp?id1='+newsessionid+'&id3='+id3;

}

function getNewSessionId(lbl) {
	 var oneYear = 365 * 24 * 60 * 60 * 1000;
	 var expDate = new Date();
	 expDate.setTime (expDate.getTime() + oneYear);
	 SetCookie(lbl+'sessionid',getTimeStamp(),expDate,null,null,null);
	 inmid = GetCookie(lbl+'sessionid');
	 return inmid;
}




//------------------CC custom mouseover code for header frame ----------------------


var imgpath = 'images/';
function setimgdir(ccpath) {
  imgpath = ccpath + '/';
  imgpath = '';
}

	Area1Off= new Image();
	Area1Off.src = imgpath + 'StartOff.gif';
	Area1On = new Image();
	Area1On.src = imgpath +  'StartOn.gif';
	Area2Off= new Image();
	Area2Off.src = imgpath +  'AboutOff.gif';
	Area2On = new Image();
	Area2On.src = imgpath +   'AboutOn.gif';
	Area3Off= new Image();
	Area3Off.src = imgpath +   'HelpOff.gif';
	Area3On = new Image();
	Area3On.src = imgpath +   'HelpOn.gif';
	Area5Off = new Image();
	Area5Off.src = imgpath +   'HomeOff.gif';
	Area5On = new Image();
	Area5On.src = imgpath +   'HomeOn.gif';

 function byt(place, imgName) {
	 document[place].src = imgpath + eval(imgName + '.src');
  //alert(''+imgpath + eval(imgName + '.src')+'');
 }



//------------------CC invalid password alert ----------------------

function invalidPassword() {
  alert('The user name and/or password specified is invalid.  \n\nPlease note that your user name and password is case sensitive.  \n\nTry again.');
return;

}



