NN = (document.layers) ? 1 : 0; 
IE = (document.all) ? 1 : 0;
var Arr_FormInds=new Array();
var Protocols=new Array();
Protocols[0]= new Array('','(other)');
Protocols[1]= new Array('file://','file:');
Protocols[2]= new Array('ftp://','ftp:');
Protocols[3]= new Array('gopher://','gopher:');
Protocols[4]= new Array('http://','http:',1);
Protocols[5]= new Array('https://','https:');
Protocols[6]= new Array('mailto:','mailto:');
Protocols[7]= new Array('news:','news:');
Protocols[8]= new Array('telnet:','telnet:');
Protocols[9]= new Array('wais:','wais:');
//*****************************************************************************************************************
function placeFocus() 
{
 var CheckList,j,flag=0;
 CheckList=document.forms;
 if (!CheckList) return;
 if (CheckList.length > 0) 
    {
     for (j=0;j<CheckList.length; j++)
         {
          var field = CheckList[j];
          for (i =0; i < field.length; i++) 
              {
               if ((field.elements[i].type == "text") || 
                   (field.elements[i].type == "file") || 
                   (field.elements[i].type == "password") || 
                   (field.elements[i].type == "textarea") || 
                   (field.elements[i].type.toString().charAt(0) == "s")) 
                  {
                   field.elements[i].focus();
                   flag=1;
                   break;
                  }// if
             }// for i
         if (flag) break;    
        }// for j
    }// if (CheckList.length > 0) 
 return;  
}
//*****************************************************************************************************************
function AddOption(OptionValue,OptionText)
{
 var no = new Option();
 no.value = OptionValue;
 no.text  = OptionText;
 return no;       
}
//******************************************************************************
function CheckDelete(FormName)
{
 if ( window.confirm("Do you really want to delete record?")) 
    {
     document.forms[FormName].submit();
     return;
    } 
 return;   
}
//******************************************************************************
function SubmitForm(FormName)
{
 document.forms[FormName].submit(); 
 return;   
}
//******************************************************************************
function SubmitForm1(which)
{
  which.submit();
  return;   
}
//**********************************************************************************************************
function  BuildSubForm(FormTitle,subForm)
{
 var i,
     theSubForm="",
     arg="";
 arg='"'+FormTitle+'",'+subForm;  
 theSubForm+="<select size=1 name=RelatedForm"+subForm+" onChange='ChangeSelectForm(theRelForms,"+arg+");'>";
 theSubForm+="<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
 theSubForm+="<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
 theSubForm+="<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
 theSubForm+="</select>";
 return theSubForm;
}
//**********************************************************************************************************
function ClearSubForm(FormTitle,SubForm)
{
 if (document.forms[FormTitle].elements["RelatedForm"+SubForm])
    {
     document.forms[FormTitle].elements["RelatedForm"+SubForm].length=0;
     ClearSubForm(FormTitle,SubForm+1);
    } 
 return;
}
//**********************************************************************************************************
function FillSubForm(theRelForms,FormTitle, SubForm, FormElement)
{
 var i,i1;
 if (!theRelForms) 
    {
     return;
    } 
 document.forms[FormTitle].elements["RelatedForm"+SubForm].length=0;
 i1=0;
 for (i in theRelForms[FormElement])
     {
      document.forms[FormTitle].elements["RelatedForm"+SubForm].options[i1]=AddOption(theRelForms[FormElement][i][1],
                                                                                      theRelForms[FormElement][i][0]);
      i1++;                                                                                          
     }                                                                                         
 document.forms[FormTitle].elements["RelatedForm"+SubForm].selectedIndex=0; 
 Arr_FormInds[SubForm]=FormElement;
 for (i in theRelForms[FormElement])
     {
      if (theRelForms[FormElement][i] && theRelForms[FormElement][i][2])  //theRelForms[FormElement].length &&  
         {
          FillSubForm(theRelForms,FormTitle, SubForm+1, theRelForms[FormElement][i][2])
         } 
      else
         {
          ClearSubForm(FormTitle, SubForm+1);
         } 
      break;        
     }    
 return;
}
//**********************************************************************************************************
function ChangeSelectForm(theRelForms,FormTitle,SubForm)
{
 var SelEl=0, iSelEl;
 iSelEl=document.forms[FormTitle].elements["RelatedForm"+SubForm].selectedIndex;
  SelEl=document.forms[FormTitle].elements["RelatedForm"+SubForm].options[iSelEl].value;
 if (theRelForms[Arr_FormInds[SubForm]][SelEl] && theRelForms[Arr_FormInds[SubForm]][SelEl][2])
    {
     FillSubForm(theRelForms,FormTitle, SubForm+1, theRelForms[Arr_FormInds[SubForm]][SelEl][2]);
    } 
 else 
    {
     ClearSubForm(FormTitle, SubForm+1)
    } 
 return;
}
//**********************************************************************************************************
function buildForm(theRelForms,FormTitle,id,intFormNum, DirectionFlag, SelectNames )
{
 var theForms="";
 if (!theRelForms) 
    {
     return "";
    } 
 var iLen=0;
 for (i in theRelForms[0]) iLen++;
 if (iLen>0)
    {
     if (DirectionFlag) 
        {
         for (i=0;i<intFormNum;i++) 
             theForms=theForms+"<tr><td class=SummaryChapter>"+SelectNames[i]+"</td><td>"+BuildSubForm(FormTitle,i)+"</td></tr>";
        }
     else    
        for (i=0;i<intFormNum;i++)  theForms=theForms+"<td>"+BuildSubForm(FormTitle,i)+"</td>";
    } 
 return theForms;
}    
 //**********************************************************************************************************
function disableForm(theform) 
{
 if (document.all || document.getElementById) 
    {
     for (i in theform) 
         {
          var tempobj = theform.elements[i];
          if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
              tempobj.disabled = true;
         }
     setTimeout('alert("Your form has been submitted.  Notice how the submit and reset buttons were disabled upon submission.")', 2000);
     return true;
   }
 else 
   {
    alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
    return false;
   }
 return;  
}
//******************************************************************************
function SelectProtocol(el_name,url)
{
 var strProt="";
 strProt+="<select name=protocol onChange='AddProtocol(this.form,this.form.elements."+el_name+")'>";
 for (i in Protocols)
     {
      op="";
      if (Protocols[i][0]!="" && Protocols[i][0].toUpperCase()==url.substring(0,Protocols[i][0].length).toUpperCase())
          op=" selected";
      strProt+="<option value='"+Protocols[i][0]+"'"+op+">"+Protocols[i][1]+"</option>";
     }
 strProt+="</select>";
 return strProt;
}
//******************************************************************************
function AddProtocol(wform,which)
{
 var strVariable;
 strVariable=new String(which.value);
 // Truncate the URL string
 for (pos1 = 0; pos1 < strVariable.length; pos1++)
 {
    if(strVariable.charAt(pos1) != ' ')
        break;
 }
 for (pos2 = strVariable.length-1; pos2 >= 0; pos2--)
 {
    if(strVariable.charAt(pos2) != ' ')
        break;
 }
 strVariable = strVariable.substring(pos1, pos2+1);
 // End of truncate

 for (i in Protocols)
     {
      if (Protocols[i][0]!="" && Protocols[i][0].toUpperCase()==strVariable.substring(0,Protocols[i][0].length).toUpperCase())
         {
          strVariable=strVariable.substr(Protocols[i][0].length);
          break;
         } 
     }
 which.value=wform.protocol.options[wform.protocol.selectedIndex].value+strVariable;
 return;
}
//******************************************************************************
function UpdateListOnMasterPage(intOperation,intValue,strDescription,strForm,strField)
{
 var i=0;
 if (!opener) return;
 el=opener.document.forms[strForm].elements[strField];
 if (intOperation==1)
    {
     if (IE)
        {
         var oOption = opener.document.createElement("OPTION");
         el.options.add(oOption,1);
         oOption.text = strDescription;
         oOption.value = intValue;
         el.selectedIndex=1;
        }
     if (NN)    
        {
         var oOption=new Option(strDescription,intValue);
         el.options[el.options.length]=oOption;
         el.selectedIndex=el.options.length-1;
        }     
     return;
    } 
  for (i=0;i<el.options.length;i++)
     {
       if (parseInt(el.options[i].value)==intValue)
         {
          if (intOperation==2)
             {
              var f=0;
              if (el.selectedIndex==i) f=1;
               el.options[i]=null;
              if (f) el.selectedIndex=1;             
              return;
             }
          if (intOperation==3)
             {
              el.options[i].value=intValue;
              el.options[i].text =strDescription;
              return;
             }             
         }
      }
 return;
}
//******************************************************************************
function FormButtons(CancelLink,SubmitLink,SubmitTitle,CancelTitle)
{
 var str="";
 if (SubmitTitle) tit1=SubmitTitle;
 else             tit1="Submit"; 
 if (CancelTitle) tit2=CancelTitle;
 else             tit2="Cancel";
 if (! SubmitLink ||  SubmitLink=="") link1="ValidateForm(this.form)";
 else link1=SubmitLink;
 
 str+='<table BORDER="0" CELLPADDING="10" CELLSPACING="0">';
 str+='<tr>';
 str+='<td><input type="button" name=but1 value="'+tit1+'" onClick="javascript:'+link1+';return false;"></td>';
 if (CancelLink!="") 
    str+='<td><input type="button" name=but2 value="'+tit2+'" onClick="'+CancelLink+'"></td>';
 str+='</tr>';
 str+='</table>';
 
 return str;
}