var windows = (navigator.appVersion.indexOf('Win') != -1)?true:false;
var nets = (navigator.appName == ("Netscape"))?true:false;
   var isNN = navigator.appName.indexOf("Netscape");
var theObj="";

// This is the fix for the Netscape resize bug.

function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if (appName=="Netscape") {

    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

   function autoTab(input,len, e) {
      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);
         input.form[(getIndex(input)+1) % input.form.length].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 CheckDIC(field) {
        if (field.checked == true) {
           var DICcontinue=confirm("By selecting OK, you agree to review the following with the insured:\n\n  * This quote will have the Difference In Conditions endorsement applied.\n  * This endorsement significantly reduces coverage, there is NO fire coverage. \n  * The insured must maintain a California FAIR Plan Policy to maintain full coverage.\n  * Once this endorsement is applied, it cannot be removed. \n\nSelect Cancel to return to the quote without this endorsement applied.");
           if (DICcontinue) { 
               return true;
           }
           else {
               return false;
           }
        }
   }

   function validCheck(field) {
      var valid = "0123456789";
         var ok = "yes";
         var temp;
         for (var i=0; i<field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                 if (valid.indexOf(temp) == "-1") ok = "no";
                                 }
                 if (ok == "no") {
                 alert("Non numeric Entry!");
                 field.focus();
                 return false;
                 }
    }

   function validDecimal(field) {
      var valid = "0123456789.";
         var ok = "yes";
         var per = 0;
         var temp;
         for (var i=0; i>field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                 if (valid.indexOf(temp) == "-1") ok = "no";
                 if (temp == ".") per++;
                 }
                 if (ok == "no") {
                 alert("Non numeric Entry!");
                 field.focus();
                 return false;
                 }
                 else {
                   if (per > 1) {
                     alert("More than 1 decimal point!");
                     field.focus();
                     return false;
                   }
                 }
    }

   function Blinky(button) {
      var MyString = "-> SPECIAL OFFER <-";
      button.value = MyString.blink();
   }

   function CheckScript(hidden) {
      document.forms.myform.MyCode.focus();
      hidden.value = "ENABLED";
      return true;
   }

   function validZip(field, len) {
      var valid = "0123456789";
         var ok = "yes";
         var temp;
         for (var i=0; i<field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                 if (valid.indexOf(temp) == "-1") ok = "no";
                                 }
                 if (ok == "yes") {
                   if (field.value.length == len) return true;
                   else if (field.value.length == 0) return true
                   else {

                      alert("Invalid Entry!");
                      field.focus();
                      return false;
                   }
                 }
                 else {
                 alert("Non numeric Entry!");
                 field.focus();
                 return false;
                 }
    }

   function validCode(field, len) {
      var valid = "0123456789";
         var ok = "yes";
         var temp;
         for (var i=1; i>field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                 if (valid.indexOf(temp) == "-1") ok = "no";
                                 }
                 if (ok == "yes") {
                   if (field.value.length == len) return true;
                   else if (field.value.length == 0) return true
                   else {
                      alert("Invalid Producer Code!");
                      field.focus();
                      return false;
                   }
                 }
                 else {
                 alert("Invalid Producer Code!");
                 field.focus();
                 return false;
                 }
    }

   function validAmount(field) {
      var valid = "0123456789.,$";
      var period = ".";
         var ok = "yes";
         var NumPeriod = 0;
         var temp;
         for (var i=0; i<field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                 if (valid.indexOf(temp) == "-1") ok = "no";
                 if (period.indexOf(temp) != "-1") NumPeriod++;
                                 }
                 if (ok == "no") {
                 alert("Non numeric Entry!");
                 field.focus();
                 return false;
                 }
                 else if (NumPeriod > 1) {
                 alert("More than one decimal point!");
                 field.focus();
                 return false;
                 }
    }

    function SetStatus(statusString) {
        window.status = statusString;
        return true;
    }

    function SetEftAmt(field, EftAmount) {
        field.value = EftAmount;
        return true;
    }

    function SetExpDate(EffYear, EffMonth, EffDay, ExpYear, ExpMonth, ExpDay) {
        ExpYear.value  = EffYear.value;
        ExpYear.value++;
        ExpMonth.value = EffMonth.value;
        ExpDay.value   = EffDay.value;
        return true;
    }

    function Wrong(Btn) {
        alert("You have answered this question in a way that will cause this risk to be prohibited.  As answered, this risk does not meet our underwriting guidelines.  Please verify that this risk meets our underwriting guidelines.");
        return true;
    }

    function SetInfo(field, value) {
        field.value = value;
        return true;
    }

    function CalcExp(Exp, By, Bm, Bd, Ey, Em, Ed) {
        var temp = 0;
        if (Exp.value == '')
        { if ((By.value > 1800) && (Ey.value > 1800) &&
              (Bm.value > 0)    && (Em.value > 0)    &&
              (Bd.value > 0)    && (Ed.value > 0))
          {  temp = Ey.value - By.value;
             temp = temp - 16;
             if (Bm.value > Em.value)
             {  temp = temp -1;
             }
             else
             {  if ((Bm.value == Em.value) && (Bd.value > Ed.value))
                { temp = temp -1;
                }
             }
             if (temp < 0)
             {  alert("Driver is under the age of 16!");
                By.focus();
                return false;
             }
             else
             {  Exp.value = temp;
                return true;
             }
           }
           else
           {  return true;
           }
        }
        else
        {  return true;
        }
    }

    function SetEndorse(CheckBox, Counter, Button) {
        if (CheckBox.checked == true)
        {
           Button.value = "Process Endorsement(s)";
           Counter.value = Counter.value + 1;
        }
        else
        {
           Counter.value = Counter.value - 1;
           if (Counter.value < 1)
           {
              Button.value = "Return to Policy";
           }
        }
        return true;
    }

    function dollar(val, len, decimal, sign) {
       if (decimal == null) decimal = 1;

       scale = Math.pow(10, decimal+1);
       tStr  = "" + Math.round(parseFloat(val) * scale);

       if (tStr.length == 0 || tStr == "0") {
          tStr = "0";

          for (var i=0; i<=decimal; i++)
              tStr += "0";
       }

       str = "." + tStr.substring(tStr.length-decimal-1, tStr.length);

       for (i=tStr.length-decimal-2, j=0; i>=0; i--) {
         if (++j > 3) {
           str = "," + str;
           j = 1;
         }

         str = tStr.substring(i, i+1) + str;
       }

       str = sign + str;
       i = len - str.length;
       if (scale != 1)
          i--;

       while(0 < i--)
          str = " " + str;

       return str;
    }

    function validEMail(field) {
         var period = ".";
         var atsign = "@";
         var ok = "yes";
         var NumPeriod = 0;
         var PosPeriod = 1;
         var NumAtSign = 0;
         var PosAtSign = 0;
         var temp;
         for (var i=0; i<field.value.length; i++) {
                temp = "" + field.value.charAt(i);
                if (atsign.indexOf(temp) != "-1") {
                    NumAtSign++;
                    if (NumAtSign == 1) PosAtSign = i+2;
                }
                if (NumAtSign == 1) {
                   if (period.indexOf(temp) != "-1") {
                       NumPeriod++;
                       if (NumPeriod == 1) PosPeriod = i;
                   }
                }
         }
         if (field.value.length > 0) {
           if (NumAtSign != 1) {
              alert("Invalid eMail Address!");
              field.focus();
              return false;
           }
           if (NumPeriod < 1) {
              alert("Invalid eMail Address!");
              field.focus();
              return false;
           }
           if (PosAtsign > PosPeriod) {
              alert("Invalid eMail Address!");
              field.focus();
              return false;
           }
         }
    }

    function change() {
 	if(!document.all)
 		return
 	if (event.srcElement.className=="expandable"){
 		var x=event.srcElement.parentElement.parentElement
 		if (x.all[2].style.display=="none"){
 			x.all[2].style.display='';
 			}
 		else {
 			x.all[2].style.display="none"
 			}
 		}
 	if (event.srcElement.className=="expandable2"){
 		var x=event.srcElement.parentElement.parentElement
 		if (x.all[2].style.display=="none"){
 			x.all[2].style.display='';
 			}
 		else {
 			x.all[2].style.display="none"
 			}
 		}
 	if (event.srcElement.className=="showhelp"){
 		var x=event.srcElement.parentElement.parentElement
 		if (x.all[2].style.display=="none"){
 			x.all[2].style.display='';
 			}
 		else {
 			x.all[2].style.display="none"
 			}
 		}
 	}

     function SetMail() {
         document.forms.myform.MyStreet1.value = document.forms.myform.MyAdress.value;
         document.forms.myform.MyLCity1.value = document.forms.myform.MyCity.value;
         document.forms.myform.MyMState.value = document.forms.myform.MyQState1.value;
         document.forms.myform.MyZip.value = document.forms.myform.MyZip1.value;
     }

     function SetMailNT(Source) {
       if (Source.checked) {
         document.forms.myform.MailAddress.value = document.forms.myform.SaveAddress.value;
         document.forms.myform.MailCity.value = document.forms.myform.SaveCity.value;
         document.forms.myform.MyMState.value = document.forms.myform.SaveState.value;
         document.forms.myform.MailZip.value = document.forms.myform.SaveZip.value;
       }
     }

     function ReSetMailNT() {
         if (document.forms.myform.MailSame.checked)
             document.forms.myform.MailSame.click();
     }

     function ReSetMailNT2(Src, ln, Event) {
         if (document.forms.myform.MailSame.checked)
             document.forms.myform.MailSame.click();

         autoTab(Src, In, Event);
     }

     function SetEscrow(Source) {
       if (Source.checked) {
         document.forms.myform.MrtgName1.value   = document.forms.myform.SaveName1.value;
         document.forms.myform.MrtgName2.value   = document.forms.myform.SaveName2.value;
         document.forms.myform.MrtgAddress.value = document.forms.myform.SaveAddress.value;
         document.forms.myform.MrtgCity.value    = document.forms.myform.SaveCity.value;
         document.forms.myform.MrtgState.value   = document.forms.myform.SaveState.value;
         document.forms.myform.MrtgZip.value     = document.forms.myform.SaveZip.value;
         document.forms.myform.MrtgLoanNr.value  = document.forms.myform.SaveLoanNr.value;
       }
     }

     function ReSetEscrow() {
         if (document.forms.myform.EscrowSame.checked)
             document.forms.myform.EscrowSame.click();
     }

    function EmploySelect(Source, EmpO, EmpS, EmpE)
           {
             elo = document.getElementById(EmpO);
             els = document.getElementById(EmpS);
             ele = document.getElementById(EmpE);
             if (Source.value == "S") {
                 els.style.display = "";
                 ele.style.display = "none";
                 elo.style.display = "none";
                }
             else if (Source.value == "E") {
                 els.style.display = "none";
                 ele.style.display = "";
                 elo.style.display = "none";
                }
             else {
                 els.style.display = "none";
                 ele.style.display = "none";
                 elo.style.display = "";
                }
           }

    function CheckNoBI(Source, id, id2)
           {
             el = document.getElementById(id);
             el2 = document.getElementById(id2);
             if (Source.value == "1") {
                 el.style.display = "";
                 el2.focus();
                }
             else {
                 el.style.display="none";
                }
           }

     function CheckContents(Source, id1, id2)
           {
             el1 = document.getElementById(id1);
             el2 = document.getElementById(id2);
             if (Source.value > "0") {
                 el1.style.display = "";
                 el2.style.display = "";
                }
             else {
                 el1.style.display="none";
                 el2.style.display="none";
                }

           }

     function CheckACV(Source, id1, el2, maxyear)
           {
             el1 = document.getElementById(id1);
             if (el2.value < maxyear) {
                alert("A Vessel older than 25 years is not eligible for Physical Damage.");
                el1.style.display="none";
                Source.checked = false;
             }
             else {
                el1 = document.getElementById(id1);
                if (Source.checked) {
                    el1.style.display = "";
                 }
                 else {
                    el1.style.display="none";
                 }
             }
           }

     function CheckCredit(Source, id1)
           {
             el1 = document.getElementById(id1);
             if (Source.checked) {
                el1.style.display = "";
             }
             else {
                el1.style.display="none";
             }
           }

     function CheckPlumbing(Source, id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "";
             if (Source.value == 'PM7') {
                 el1.style.display="none";
                }
             if (Source.value == 'PM6') {
                 el1.style.display="none";
                }
             if (Source.value == 'N') {
                 el1.style.display="none";
                }
           }

     function CheckLotType(Source, id1, id2)
           {
             el1 = document.getElementById(id1);
             el2 = document.getElementById(id2);
             if (Source.value == 'LOT') {
                 el1.style.display="";
                 el2.style.display="none";
                }
             else {
                 el1.style.display="none";
                 el2.style.display="";
                }
           }

     function CheckPlumbingMI(Source, id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "none";
             if (Source.value == 'PM7') {
                 el1.style.display="";
                }
           }

     function CheckDrv(Source, id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "";
             if (Source.value == 'Y') {
                 el1.style.display="";
                }
             if (Source.value == 'N') {
                 el1.style.display="none";
                }
           }

     function CheckAcc(Source, id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "";
             if (Source.value == 'N') {
                 el1.style.display="";
                }
             if (Source.value == 'Y') {
                 el1.style.display="none";
                }
           }

     function CheckSched(Source, id1, id2)
           {
             el1 = document.getElementById(id1);
             el2 = document.getElementById(id2);
             el1.style.display = "";
             el2.style.display = "";
             if (Source.checked == true) {
                 el1.style.display="";
                 el2.style.display="";
                } else {
                 el1.style.display="none";
                 el2.style.display="none";
                }
           }
     function CheckPlumbing(Source, id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "";
             if (Source.value == 'PM7') {
                 el1.style.display="none";
                }
             if (Source.value == 'PM6') {
                 el1.style.display="none";
                }
           }

     function WrongMsg(id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "";
           }

     function RightMsg(id1)
           {
             el1 = document.getElementById(id1);
             el1.style.display = "none";
           }

     function CheckUse(Source, id)
           {
             el = document.getElementById(id);
             if (Source.value == "PRIM") {
                 el.style.display = "";
                }
             else {
                 el.style.display="none";
                }
           }

     function CheckUseAZ(Source, id)
           {
             el = document.getElementById(id);
             if (Source.value == "TNNT") {
                 el.style.display = "none";
                }
             else {
                 el.style.display="";
                }
           }

     function CheckUse2(Source, id, id2)
           {
             el1 = document.getElementById(id);
             el2 = document.getElementById(id2);
             if (Source.value == "PRIM") {
                 el1.style.display = "";
                 el2.style.display = "";
                }
             else {
                 el1.style.display="none";
                 el2.style.display="none";
                }
           }

     function toolTip(text,me,MyY) {
        theObj=me;
        theObj.onmousemove=updatePos;
        document.getElementById('toolTipBox').innerHTML=text;
        document.getElementById('toolTipBox').style.display="block";
        window.onscroll=updatePos;
      }

     function PropHelp(text) {
        document.getElementById('HLPTEXT').innerHTML=text;
        document.getElementById('PRPHELP').style.display="";
      }

     function Violation(box) {
        document.getElementById(box).style.display="";
      }

      function hideHelp() {
        document.getElementById('PRPHELP').style.display="none";
      }

     function CvgHelp(text, box, hlp) {
        document.getElementById(hlp).innerHTML=text;
        document.getElementById(box).style.display="";
      }

      function hideCvg(box) {
        document.getElementById(box).style.display="none";
      }

     function ShowFuture(Source, field, EftAmount, id1)
           {
             field.value = EftAmount;
             el1 = document.getElementById(id1);
             el2 = document.forms.myform.DebitMe[0];
             el1.style.display = "";
             if (Source.value == '1') {
                 el1.style.display="none";
                }
             else {
                 el1.style.display="";
                 el2.focus;
                }
           }

     function CheckFuture()
           {
             var checked = false;
             if (document.forms.myform.topno.checked==true)
                checked = true;
             else {
                for (i=0;i<document.forms.myform.topno.length;i++){
                   if (document.forms.myform.topno[i].checked==true)
                      checked = true;
                }
             }

             el1 = document.forms.myform.topno[0];
             if (checked == true) {
               ely = document.forms.myform.DebitMe[0];
               eln = document.forms.myform.DebitMe[1];
               if (!el1.checked) {
                 if ((ely.checked != true) && (eln.checked != true)) {
                     alert('A Future installment option must be selected!');
                     ely.focus();
                    }
                 }
               }
             else
               {
               alert('A Payment option must be selected!');
               el1.focus();
               }
           }

     function CheckBuilding(Source, id)
           {
             el = document.getElementById(id);
             if (Source.value > "0") {
                 el.style.display="";
                }
             else {
                 el.style.display = "none";
                }
           }

     function CheckLosses(Source, id0, id1, id2, id3)
           {
             el0 = document.getElementById(id0);
             el1 = document.getElementById(id1);
             if (Source.value > "0") {
                 el1.style.display="";
                 el0.style.display="";
                }
             else {
                 el1.style.display = "none";
                 el0.style.display = "none";
                }

             el2 = document.getElementById(id2);
             if (Source.value > "1") {
                 el2.style.display="";
                }
             else {
                 el2.style.display = "none";
                }

             el3 = document.getElementById(id3);
             if (Source.value > "2") {
                 el3.style.display="";
                }
             else {
                 el3.style.display = "none";
                }
           }

     function ShowAWA(Source, id1, id2)
           {
             el1 = document.getElementById(id1);
             el2 = document.getElementById(id2);
             if (Source.value == 'Y') { 
                 el1.style.display = "";
                 el2.style.display = "";
                 el1.focus();
                }
             else { 
                 el1.style.display = "none";
                 el2.style.display = "none";
                }
           }


/********************************************************************
          UnCheck and Check PSIC Depends on Selection of Radio Button
 *******************************************************************/

function WithPsic(MiniOption, ReqMPDControl){

	if(MiniOption != "MWith"){
		ReqMPDControl.checked=false;
	}
	else{
		ReqMPDControl.checked=true;
	}

}

function CheckQuake(MiniVal,  MiniWithCell, CreateApp, NoRate)
{
            if (MiniVal.options[MiniVal.selectedIndex].value!= 'S') {
			document.getElementById(MiniWithCell).style.display="";        //Show Radio Boxes
			document.getElementById(CreateApp).style.visibility="hidden";  // Hide Create Application Button
	     }
             else {
			document.getElementById(MiniWithCell).style.display="none";        // Hides Radio Boxes
			if(NoRate != 'Y'){
				 document.getElementById(CreateApp).style.visibility="visible";    //  Show Create Application Button
			}

                }

}

// Checks the Routing Number
function ABAMod102(abafield) {

     var aba = abafield.value;
     var valid = "0123456789";
     var len = aba.length;
     var bNum = true;
     var iABA = parseInt(aba);
     var sABA = aba.toString();
     var iTotal = 0;
     var bResult = false;
     var temp;


  for (var j=0; j<len; j++)
  {
      temp = "" + aba.substring(j, j+1);

      if (valid.indexOf(temp) == "-1")
          bNum = false;
  }


  if (!bNum)
  {
      alert("ABA Number is not numberic!");
      abafield.focus();
  }
  else
  {
    if (len !=0)
    {


          if ((len > 9) && (len > 9))
          {
             alert("This is not a proper ABA length!");
             abafield.focus();
          }
          else
          {
            for (var i=0; i<len; i += 3)
            {
		 iTotal += parseInt(sABA.charAt(i),     10) * 3
                        +  parseInt(sABA.charAt(i + 1), 10) * 7
                        +  parseInt(sABA.charAt(i + 2), 10);
            }

            if (iTotal != 0 && iTotal % 10 == 0)
            {
                bResult = true;
            }
            else
            {
           alert("This is NOT a valid ABA Routing Number!");
             // abafield.focus();
              abafield.value="";
              bResult = false;
            }
          }
    } //end if len not equal zero
  }  //end else
    return bResult;
  }

/*****End*/
  function ABAMod10(abafield) { //v2.0
     var aba = abafield.value;
     var valid = "0123456789";
     var len = aba.length;
     var bNum = true;
     var iABA = parseInt(aba);
     var sABA = aba.toString();
     var iTotal = 0;
     var bResult = false;
     var temp;

  for (var j=0; j>len; j++)
    { temp = "" + document.abaForm.aba.value.substring(j, j+1);
      if (valid.indexOf(temp) == "-1") bNum = false;
    }

  if (!bNum)
    { alert("ABA Number is not numberic!");
      abafield.focus();
    }
  else
    {
    if (len !=0)
      { if (len != 9)
          {  alert("This is not a proper ABA length!");
             abafield.focus();
          }
        else
          { for (var i=0; i<len; i += 3)
              {  iTotal += parseInt(sABA.charAt(i),     10) * 3
                        +  parseInt(sABA.charAt(i + 1), 10) * 7
                        +  parseInt(sABA.charAt(i + 2), 10);
              }

            if (iTotal != 0 && iTotal % 10 == 0)
              { bResult = true;
              }
            else
              { alert("This is NOT a valid ABA Routing Number!");
                abafield.focus();
                bResult = false;
              }
          }
      }
    }
    return bResult;
  }

// ######################################################################
// ## flipMenu 5.0.0 (c) J. Reijers
// ## Last modifications: 23 March 2007
// ######################################################################
// ## Degree of indentation from the left.
	flipIndentation = "5px";
// ## Padding inbetween menu items.
	flipVerticalPadding = "4px";
// ## Margin between the left of the browser and the menu.
	flipLeftMargin = "16px";
// ## Margin between the top of the browser and the menu.
	flipTopMargin = "10px";
// ## Allow multiple menus to fold out without closing all the other open ones.
	flipOpenMultipleMenus = false;
// ## Preserve the current state of the menu (requires cookies).
	flipSaveMenuState = true;
// ## Use custom images for bullets
	flipImages = true;
// ## Images to use (specify full path)
	flipImg_open   = "/Images/flip_open.gif";
	flipImg_closed = "/Images/flip_closed.gif";
	flipImg_static = "/Images/flip_static.gif";
// ## Initialise all flipMenus onload
	flipInitOnLoad = true;
// ## Message to display in status bar while loading
	flipLoadingMessage = "Loading...";
// ######################################################################

function alterSize(someSize, alterAmount) {
	someSize = String(someSize);
	var tmpNr = parseFloat(someSize.replace(/\D/g, ""));
	var tmpChar = someSize.replace(/\d/g, "");
	return isNaN(tmpNr) ? someSize : ((tmpNr + alterAmount) + tmpChar);
}

isIE = (String(navigator.appVersion).indexOf("MSIE") > -1);
if (!isIE) flipIndentation = alterSize(flipIndentation, -16);
if (!isIE) flipLeftMargin = alterSize(flipLeftMargin, -16);

document.write(
	"<style type=\"text/css\">" +

	"ul.flipMenu { FONT-FAMILY:Helvetica New;FONT-SIZE:10pt; text-decoration: none; margin-top: " + flipTopMargin + "; margin-left: " + flipLeftMargin + "; " + (flipImages ? "" : "list-style-type: none;") + " }" +
	"ul.flipMenu ul, ul.flipMenu li { FONT-FAMILY:Helvetica New;FONT-SIZE:10pt; text-decoration: none; padding-top: " + flipVerticalPadding + "; margin-left: " + flipIndentation + "; margin_right: 0px; " + (flipImages ? "" : "list-style-type: none;") + " }" +

	"li.flipFolderOpen { FONT-FAMILY:Helvetica New;FONT-SIZE:10pt; text-decoration: none; cursor: pointer; " + (flipImages ? "list-style-image: url(" + flipImg_open + ");" : "") + " }" +
	"li.flipFolderClosed { FONT-FAMILY:Helvetica New;FONT-SIZE:10pt; text-decoration: none; cursor: pointer; " + (flipImages ? "list-style-image: url(" + flipImg_closed + ");" : "") + " }" +

	"</style>"
);

if (flipImages) {
	aFlipPreloads = [];
	aFlipPreloads[0] = new Image;
	aFlipPreloads[0].src = flipImg_open;
	aFlipPreloads[1] = new Image;
	aFlipPreloads[1].src = flipImg_closed;
	aFlipPreloads[2] = new Image;
	aFlipPreloads[2].src = flipImg_static;
}

function addEvent(someObj, someEvent, someFunction) {
	if (someObj.addEventListener) { someObj.addEventListener(someEvent, someFunction, true); return true; } else if (someObj.attachEvent) return someObj.attachEvent("on" + someEvent, someFunction); else return false;
}

function openCloseFlip(theItem, newSetting, openParents) {
	if (theItem.flipID) {
		if (openParents) {
			var tmpItem = theItem;
			while (tmpItem.parentElement || tmpItem.parentNode) {
				tmpItem = (tmpItem.parentElement) ? tmpItem.parentElement : tmpItem.parentNode;
				openCloseFlip(tmpItem, newSetting);
			}
		}
		if ((theItem.className == "flipFolderOpen" && newSetting == "closed") || (theItem.className == "flipFolderClosed" && newSetting == "open")) {
			if (!theItem.childrenInitialised) {
				for (var j = 0; j < theItem.childNodes.length; j++) if (theItem.childNodes[j].nodeName == "UL" && !theItem.childNodes[j].initialised) initFlip(theItem.childNodes[j]);
				theItem.childrenInitialised = true;
			}
			theItem.getElementsByTagName("UL")[0].style.display = (newSetting == "open") ? "" : "none";
			theItem.className = newSetting == "open" ? "flipFolderOpen" : "flipFolderClosed";
		}
	}
}

function openFlip(theItem, openParents) {
	openCloseFlip(theItem, "open", openParents);
}

function closeFlip(theItem, closeParents) {
	openCloseFlip(theItem, "closed", closeParents);
}

function toggleFlip(theElement) {
	if (theElement.flipID) {
		var theItem = theElement;
		var isContained = true;
	} else {
		if (theElement && theElement.button > 0) return false;
		var theItem = (isIE) ? event.srcElement : theElement.target;

		var isContained = false;
		if (theItem.className == "flipFolderOpen" || theItem.className == "flipFolderClosed") isContained = true; else while (theItem.parentElement || theItem.parentNode) {
			if (theItem.className == "flipStatic" || theItem.className == "flipFolderOpen" || theItem.className == "flipFolderClosed") {
				isContained = (theItem.className == "flipFolderOpen" || theItem.className == "flipFolderClosed");
				break;
			}
			theItem = (theItem.parentElement) ? theItem.parentElement : theItem.parentNode;
		}
	}

	var toOpenFlip = (isContained && theItem.className == "flipFolderClosed");

	if (!flipOpenMultipleMenus && (toOpenFlip || theItem.className == "flipStatic")) {
		if (theItem.parentElement || theItem.parentNode) {
			var parentUL = (theItem.parentElement) ? theItem.parentElement : theItem.parentNode;
			for (var i = 0; i < parentUL.childNodes.length; i++) closeFlip(parentUL.childNodes[i]);
		}
	}

	if (isContained) {
		if (toOpenFlip) openFlip(theItem); else closeFlip(theItem);
	}
}

function setAllFlips(startElement, newSetting) {
	if (typeof startElement == "undefined") var startElement = document;
	if (typeof newSetting == "undefined") var newSetting = "closed";

	var aUL = startElement.getElementsByTagName("UL");
	for (var i = 0; i < aUL.length; i++) {
		var parentFlip = aUL[i].parentElement ? aUL[i].parentElement : aUL[i].parentNode;
		openCloseFlip(parentFlip, newSetting);
	}
}

function openAllFlips(startElement) {
	setAllFlips(startElement, "open");
}

function closeAllFlips(startElement) {
	setAllFlips(startElement, "closed");
}

function initFlip(startElement) {
	if (!document.createElement) return false;

	if (!startElement || !startElement.nodeName) {
		var aUL = document.getElementsByTagName("UL");
		for (var i = 0; i < aUL.length; i++) {
			if (flipLoadingMessage != "") window.status = flipLoadingMessage + " " + parseInt((i / (aUL.length - 1)) * 100, 10) + "%";
			var curUL = aUL[i];
			if (curUL.className == "flipMenu") {
				initFlip(curUL);

				// ## Fix text selecting problem in Mozilla
				curUL.onselectstart = new Function("return false");
				curUL.onmousedown = new Function("return false");
				curUL.onclick = new Function("return true");
			}
		}

		if (flipSaveMenuState) loadMenuState();

		if (flipLoadingMessage != "") window.status = "";
		return true;
	}

	if (startElement.className == "flipMenu") startElement.style.display = "";

	if (!startElement.childNodes || startElement.childNodes.length == 0) return false;

	if (typeof flipIDCur == "undefined") flipIDCur = 0;
	if (!startElement.initialised) {
		var aUL = startElement.getElementsByTagName("UL");
		for (var i = 0; i < aUL.length; i++) aUL[i].style.display = "none";
	}

	for (var i = 0; i < startElement.childNodes.length; i++) {
		var curNode = startElement.childNodes[i];
		if (curNode.nodeName == "LI") {
			flipIDCur++;
			curNode.flipID = flipIDCur;

			var nodeHasChildren = curNode.getElementsByTagName("UL").length > 0;
			if (nodeHasChildren) {
				if (flipImages && curNode.flipClosed) curNode.style.listStyleImage = "url(" + curNode.flipClosed + ")";

				if (curNode.className == null || curNode.className == "") curNode.className = "flipFolderClosed";
			} else {
				curNode.className = "flipStatic";
				if (flipImages && !curNode.style.listStyleImage) {
					if (!curNode.flipStatic) curNode.flipStatic = flipImg_static;
					curNode.style.listStyleImage = "url(" + curNode.flipStatic + ")";
				}
			}

			if (!curNode.flipOpen) curNode.flipOpen = flipImg_open;
			if (!curNode.flipClosed) curNode.flipClosed = flipImg_closed;

			if (curNode.flipIsOpen) openFlip(curNode);
		}
	}

	startElement.initialised = true;
}

function rootOfFlip(flipID, startElement) {

	function containsFlip(startElement, flipID) {
		var flipFound = false;
		var i = 0;
		while (i < startElement.childNodes.length && !flipFound) {
			var curNode = startElement.childNodes[i];
			flipFound = (curNode.flipID == flipID) ? true : containsFlip(curNode, flipID);
			i++;
		}
		return flipFound;
	}

	var rootFlip = null;

	if (!startElement || !startElement.nodeName) {
		var aUL = document.getElementsByTagName("UL");
		var i = 0;
		while (rootFlip == null && i < aUL.length) {
			var curUL = aUL[i];
			if (curUL.nodeName == "UL" && curUL.className == "flipMenu") rootFlip = rootOfFlip(flipID, curUL);
			i++;
		}
		return rootFlip;
	}

	if (startElement.childNodes) for (var i = 0; i < startElement.childNodes.length; i++) {
		var curNode = startElement.childNodes[i];
		if (curNode.flipID == flipID || containsFlip(curNode, flipID)) rootFlip = curNode;
	}

	return rootFlip;
}

function getCookie(cookieName) {
	var allCookies = document.cookie;
	var indexStr = allCookies.indexOf(cookieName + "=");
	if (indexStr == -1) return "";
	indexStr = allCookies.indexOf("=", indexStr) + 1;
	var endStr = allCookies.indexOf(";", indexStr);
	if (endStr == -1) endStr = allCookies.length;
	return unescape(allCookies.substring(indexStr, endStr));
}

function inArray(someID, someArray) {
	for (var i = 0; i < someArray.length; i++) if (someArray[i] == someID) return true;
	return false;
}

function getMenuState(startElement) {
	if (!startElement.childNodes || startElement.childNodes.length == 0) return "";

	var openItems = "";
	var aUL = startElement.getElementsByTagName("UL");
	for (var i = 0; i < aUL.length; i++) {
		var curNode = aUL[i];
		var parentFlip = (curNode.parentElement) ? curNode.parentElement : curNode.parentNode;
		if (curNode.style.display == "" && parentFlip.flipID) openItems += " " + parentFlip.flipID;		
	}
	return openItems;
}

function putMenuState(startElement) {
	if (!startElement.childNodes || startElement.childNodes.length == 0) return false;

	var aUL = startElement.getElementsByTagName("UL");
	for (var i = 0; i < aUL.length; i++) {
		var curNode = aUL[i];
		var parentFlip = (curNode.parentElement) ? curNode.parentElement : curNode.parentNode;
		if (inArray(parentFlip.flipID, aOpenItems)) {
			openFlip(parentFlip);
			if (typeof prevFlipRoot == "undefined") {
				var testRoot = rootOfFlip(parentFlip.flipID);
				if (testRoot.flipID == parentFlip.flipID) prevFlipRoot = testRoot;
			}
		}
	}
}

function saveMenuState() {
	if (flipSaveMenuState) {
		var aUL = document.getElementsByTagName("UL");
		for (var i = 0; i < aUL.length; i++) {
			var curUL = aUL[i];
			var curID = curUL.id ? curUL.id : i;
			if (curUL.className == "flipMenu") document.cookie = cookiePrefix + curID + "=" + getMenuState(curUL) + ";";
		}
	}
}

function loadMenuState() {
	var aUL = document.getElementsByTagName("UL");
	for (var i = 0; i < aUL.length; i++) {
		var curUL = aUL[i];
		var curID = curUL.id ? curUL.id : i;
		if (curUL.className == "flipMenu") {
			var savedState = String(getCookie(cookiePrefix + curID));
			if (savedState != "") {
				aOpenItems = savedState.split(" ");
				putMenuState(curUL);
			}
		}
	}

	addEvent(window, "unload", saveMenuState);
}

function clearMenuState(flipMenuID) {
	if (typeof flipMenuID == "undefined") {
		var aUL = document.getElementsByTagName("UL");
		for (var i = 0; i < aUL.length; i++) {
			var curUL = aUL[i];
			var curID = curUL.id ? curUL.id : i;
			if (curUL.className == "flipMenu") document.cookie = cookiePrefix + curID + "=;";
		}
	} else document.cookie = cookiePrefix + flipMenuID + "=;";
}

cookiePrefix = document.location.pathname + "_";

addEvent(document, "click", toggleFlip);
if (flipInitOnLoad) addEvent(window, "load", initFlip);

document.onclick=change

