function fieldChange(field, origtxt, state){
  if (state == 1){
    if ((field.value==origtxt) || (field.value=="")){
      field.value = "";
      field.style.color = "#000";
    }
  }else if (state == 0){
    if ((field.value=="")){
      field.value = origtxt;
      field.style.color = "#BDBDCE";
    }else{
      field.style.color = "#000";
    }
  }
}


function forgotPW(){
  window1=open('forgotPW.asp', 'forgotPW', 'status=no,toolbar=no,location=no,scrollbars=yes,resizable=no,width=320,height=160');
  window1.focus();
}

function register(){
  window1=open('register.asp', 'register', 'status=no,toolbar=no,location=no,scrollbars=no,resizable=no,width=360,height=390');
  window1.focus();
}

function changeText(theID,theText){
  if (document.getElementById){
    document.getElementById(theID).innerHTML=theText;
  } else if(document.all){
    document.all(theID).innerHTML=theText;
  } else if(document.layers){
    with(Eval("document."+theID+".document")){
      open();
      write(theText);
      close();
    }
  }
}


//------------------------------------------
// CONTACT FORM SCRIPTS
//------------------------------------------
function validateContactForm(f){
  if (f.Topic.selectedIndex <= 0){
    alert("Please select a topic");
    f.Topic.focus();
    return false;
  }else if (f.Name.value == ""){
    alert("Please enter your name");
    f.Name.focus();
    return false;
  }else if (f.Company.value == ""){
    alert("Please enter your company");
    f.Company.focus();
    return false;
  }else if ((f.Email.value == "") || (f.Email.value.indexOf("@")==-1) || (f.Email.value.indexOf(".")==-1)){
    alert("Please enter a valid email address");
    f.Email.focus();
    return false;
  }else if (f.Comment.value == ""){
    alert("Please enter your question or comment");
    f.Comment.focus();
    return false;
  }else{
    f.submit();
  }
}


//------------------------------------------
// COMPARISON FORM SCRIPTS
//------------------------------------------
function CalculateScore(f){
  iYes = 0;
  sNo = "";
  nScore = 0;
  for (i=1; i<=27; i++){
    if (eval("f.tf"+i+"[0].checked")){
      iYes++;
    }else{
      sNo = sNo + i + ",";
    }
  }
  nScore = iYes/0.27;
  nScore = Math.round(nScore*Math.pow(10,0))/Math.pow(10,0);
  f.Score.value = nScore + "%";
  f.No.value = sNo;

  if (nScore == 100){
    changeText("display","Your current third party administrator only provides "+ nScore +"% of the services Eagle Claims Management provides. Check the box below to find out how you can receive 100% satisfaction.");
  }else{
    changeText("display","Your current third party administrator only provides "+ nScore +"% of the services Eagle Claims Management provides. Check the box below to find out how you can receive 100% satisfaction.");
  }
  changeText("scoretxt","Score:");
  changeText("scorenum",nScore+"%");
}


function ShowFields(f){
  if (document.getElementById){
    opt = document.getElementById("optional");
  }else if(document.all){
    opt = document.all("optional");
  }else if(document.layers){
    opt = document.optional.document;
  }
  if (f.OptFields.checked){
    opt.style.display = "inline";
  }else{
    opt.style.display = "none";
  }
}


function validateComparison(f){
  if (f.FirstName.value == ""){
    alert("Please enter your first name");
    f.FirstName.focus();
    return false;
  }else if (f.LastName.value == ""){
    alert("Please enter your last name");
    f.LastName.focus();
    return false;
  }else if (f.Company.value == ""){
    alert("Please enter your company");
    f.Company.focus();
    return false;
  }else if ((f.Email.value == "") || (f.Email.value.indexOf("@")==-1) || (f.Email.value.indexOf(".")==-1)){
    alert("Please enter a valid email address");
    f.Email.focus();
    return false;
  }else{
    f.submit();
  }
}


//------------------------------------------
// CALCULATOR FORM SCRIPTS
//------------------------------------------

var total;

function sfcalc(top,bot){
  var aOut = new Array("$",",");
  nPremium = top;
  for (i=0;i<aOut.length;i++){
    while (nPremium.indexOf(aOut[i])>-1) {
      nPremium = "" + (nPremium.substring(0, nPremium.indexOf(aOut[i])) + nPremium.substring((nPremium.indexOf(aOut[i]) + aOut[i].length), nPremium.length));
    }
  }
  nPaid = bot;
  for (i=0;i<aOut.length;i++){
    while (nPaid.indexOf(aOut[i])>-1) {
      nPaid = "" + (nPaid.substring(0, nPaid.indexOf(aOut[i])) + nPaid.substring((nPaid.indexOf(aOut[i]) + aOut[i].length), nPaid.length));
    }
  }
  if ((nPremium >= 0)||(nPremium < 0)){
  }else{
    nPremium = 0;
  }
  if ((nPaid >= 0)||(nPaid < 0)){
  }else{
    nPaid = 0;
  }
  nResult = nPremium - nPaid;
  nResult = Math.round(nResult*Math.pow(10,2))/Math.pow(10,2);
  total = total + nResult;
  nResult = ""+nResult;
  if (nResult.indexOf(".") == -1){
    sZeros = ".00";
  }else if (nResult.length - nResult.indexOf(".") == 2){
    sZeros = "0";
  }else{
    sZeros = "";
  }
//  nResult = nResult + sZeros;
  if (nResult<0){
    prefix = "-";
    nResult = (nResult*-1) + "";
  }else{
    prefix = "";
  }
  rebuild = "";
  for (i=0;i<nResult.length;i++){
    rebuild = rebuild + nResult.charAt(i);
    if (((nResult.length-i) % 3) == 1){
      if ((nResult.length-i) > 1){
        rebuild = rebuild + ",";
      }
    }
  }
  return (prefix + rebuild);
}

function SelfFundCalc(f){
    total = 0;
    f.Tot1.value = "";
    f.Tot2.value = "";
    f.Tot3.value = "";
    f.Tot4.value = "";
    f.Tot5.value = "";
    f.total.value = "";
    f.Tot1.style.color = "#000";
    f.Tot2.style.color = "#000";
    f.Tot3.style.color = "#000";
    f.Tot4.style.color = "#000";
    f.Tot5.style.color = "#000";

  if ((f.PY1.value)||(f.Loss1.value)){
    tot1 = sfcalc(f.PY1.value,f.Loss1.value);
    if (tot1.indexOf("-") > -1){
      f.Tot1.style.color = "#c00";
    }
    f.Tot1.value = "$"+tot1;
  }
  if ((f.PY2.value)||(f.Loss2.value)){
    tot2 = sfcalc(f.PY2.value,f.Loss2.value);
    if (tot2.indexOf("-") > -1){
      f.Tot2.style.color = "#c00";
    }
    f.Tot2.value = "$"+tot2;
  }
  if ((f.PY3.value)||(f.Loss3.value)){
    tot3 = sfcalc(f.PY3.value,f.Loss3.value);
    if (tot3.indexOf("-") > -1){
      f.Tot3.style.color = "#c00";
    }
    f.Tot3.value = "$"+tot3;
  }
  if ((f.PY4.value)||(f.Loss4.value)){
    tot4 = sfcalc(f.PY4.value,f.Loss4.value);
    if (tot4.indexOf("-") > -1){
      f.Tot4.style.color = "#c00";
    }
    f.Tot4.value = "$"+tot4;
  }
  if ((f.PY5.value)||(f.Loss5.value)){
    tot5 = sfcalc(f.PY5.value,f.Loss5.value);
    if (tot5.indexOf("-") > -1){
      f.Tot5.style.color = "#c00";
    }
    f.Tot5.value = "$"+tot5;
  }
  rebuild = "";
  total = ""+total;
  if (total<0){
    prefix = "-";
    total = (total*-1) + "";
    f.total.style.color = "#c00";
  }else{
    prefix = "";
    f.total.style.color = "#000";
  }
  for (i=0;i<total.length;i++){
    rebuild = rebuild + total.charAt(i);
    if (((total.length-i) % 3) == 1){
      if ((total.length-i) > 1){
        rebuild = rebuild + ",";
      }
    }
  }
  f.total.value = "$" + prefix + rebuild;
}

function reSet(id,f){
  f = document.CalcForm;
  if (id == "calc"){
    f.PY1.value = "";
    f.PY2.value = "";
    f.PY3.value = "";
    f.PY4.value = "";
    f.PY5.value = "";
    f.Loss1.value = "";
    f.Loss2.value = "";
    f.Loss3.value = "";
    f.Loss4.value = "";
    f.Loss5.value = "";
    f.Tot1.value = "";
    f.Tot2.value = "";
    f.Tot3.value = "";
    f.Tot4.value = "";
    f.Tot5.value = "";
    f.total.value = "";
  }else if (id == "email"){
    f.FirstName.value = "";
    f.LastName.value = "";
    f.Title.value = "";
    f.Company.value = "";
    f.Email.value = "";
    f.Phone.value = "";
    f.Fax.value = "";
    f.StreetAddress.value = "";
    f.StreetLine2.value = "";
    f.City.value = "";
    f.State.value = "";
    f.Zip.value = "";
  }
}


function validateCalcForm(f){
  if (f.total.value == ""){
    alert("You need to run a calculation prior to sending the email.");
    f.PY1.focus();
    return false;
  }else if (f.FirstName.value == ""){
    alert("Please enter your first name");
    f.FirstName.focus();
    return false;
  }else if (f.LastName.value == ""){
    alert("Please enter your last name");
    f.LastName.focus();
    return false;
  }else if (f.Company.value == ""){
    alert("Please enter your company");
    f.Company.focus();
    return false;
  }else if ((f.Email.value == "") || (f.Email.value.indexOf("@")==-1) || (f.Email.value.indexOf(".")==-1)){
    alert("Please enter a valid email address");
    f.Email.focus();
    return false;
  }else{
    f.submit();
  }
}


