var UNDEFINED;

/** The character that MUST be at the beginning of the query string. */ 
var QUERY_STRING_START_CHAR = "?";

/** The character that separates parameters in the query string. */
var QUERY_STRING_SEPARATION_CHAR = "&"; 

var INPUT_TYPE_BUTTON    = "button";
var INPUT_TYPE_TEXTFIELD = "text";
var INPUT_TYPE_TEXTAREA  = "textarea";


function runReport()
{
    
   // Retrieve our form
   var form = eval("window.document." + cJSFormName);

   // Retrieve the report selection
   var report = form.report_menu.value;
 
   var pageSetupInstructions = "";
   if(navigator.appName.indexOf("Netscape") != -1)
   {
       pageSetupInstructions = "Page Setup Instructions For Netscape: \n";
       pageSetupInstructions += "\n"; 
       pageSetupInstructions += "For best results, print report with the top margin set to 0.5 inches \n";
       pageSetupInstructions += "and the bottom margin set to 0.7 inches."; 
   }
   else if(navigator.appName.indexOf("Microsoft") != -1)
   {
       pageSetupInstructions = "Page Setup Instructions For Internet Explorer: \n";
       pageSetupInstructions += "\n"; 
       pageSetupInstructions += "For best results, print report with the top \n";
       pageSetupInstructions += "and bottom margins set to 0.8 inches.";  
   }
   
                
   if (form != UNDEFINED && report != "-select-")
   {
      if(pageSetupInstructions != "" && report != "prayer-request-report")
      {
          alert(pageSetupInstructions);
      }
       
      var queryString =  QUERY_STRING_START_CHAR + "action=" + report; 
      var newWindow = window.open(form.action + queryString);  

   }
   else
   {
     // alert("form is undefined");
   }


}

function runAdminReport()
{
    
   // Retrieve our form
   var form = eval("window.document." + cJSFormName);

   // Retrieve the report selection
   var report = form.admin_report_menu.value;
    
                
   if (form != UNDEFINED && report != "-select-")
   { 
      var queryString =  QUERY_STRING_START_CHAR + "action=" + report; 
      var newWindow = window.open(form.action + queryString);  
   }
   else
   {
     // alert("form is undefined");
   }


}


function deleteStub(iAction,iExtraInfo)
{
   if (iAction == "delete-member") 
   {   
      alert("Member delete not implemented yet."); 
   }
   else 
   {
      alert("Missionary delete not implemented yet.");
   }   
}

function confirmDelete(iAction,iExtraInfo)
{
   var res;
   var recordType = "";
   
   if (iAction == "delete-address") 
   {   
      recordType = "address"; 
   }
   else if (iAction == "delete-member-status")
   {
       recordType = "member status";
   }
   else if (iAction == "delete-member")
   {
       recordType = "member";
   }
   else if (iAction == "delete-spouse")
   {
       recordType = "spouse";
   }
   else if (iAction == "delete-family")
   {
       recordType = "member";
   }
   else if (iAction == "delete-missionary")
   {
       recordType = "missionary";
   }
   else if (iAction == "delete-child")
   {
       recordType = "child";
   }

   res = confirm("Are you sure you want to delete the selected " + recordType + "?");
   
   if (res)
   {
      performDelete(iAction,iExtraInfo);
   }
   else
   {
      // do nothing
   }
}

function confirmDeleteMember(iAction,iExtraInfo,iIsMissionary)
{
   var res;
   var recordType = "";
   
   if (iIsMissionary == "Y") 
   {   
      recordType = "missionary"; 
   }
   else 
   {
       recordType = "member";
   }
   
   res = confirm("Are you sure you want to delete the selected " + recordType + "?");
   
   if (res)
   {
      performDelete(iAction,iExtraInfo);
   }
   else
   {
      // do nothing
   }
}

function performDelete(iAction, iExtraInfo)
{
    
   var form = eval("window.document." + cJSFormName + ";");
   if (form != UNDEFINED)
   {
      var queryString =  QUERY_STRING_START_CHAR + "action=" + iAction + iExtraInfo; 
      var originalFormAction = form.action;
      //alert("orig form action = " + form.action);
      form.action = form.action + queryString;
      // alert("form action = " + form.action);
      form.submit();
      form.action = originalFormAction;   
   }
   else
   {
      alert("form is undefined");
   }
}



function submitPage(iNextPage)
{
    
   var form = eval("window.document." + cJSFormName + ";");
   if (form != UNDEFINED)
   {
      if(form.preaction != UNDEFINED){iNextPage=form.preaction.value};
      var queryString =  QUERY_STRING_START_CHAR + "action=" + iNextPage; 
      var originalFormAction = form.action;
      //alert("orig form action = " + form.action);
      form.action = form.action + queryString;
      // alert("form action = " + form.action);
      form.submit();
      form.action = originalFormAction;   
   }
   else
   {
      alert("form is undefined");
   }
}

/** 
 * placeFocus()
 *
 * This function locates the first textfield or textarea on the page and gives it the focus
 * so that the cursor will be there.  
 */
function placeFocus()
{
   // Retrieve our form
   var form = eval("window.document." + cJSFormName);

   // Retrieve the number of elements on the page
   var numElements = form.length;
   var i;
   var fieldType;
   var thisElement;

   // Loop through the elements and give focus to the first textfield or textarea.
   for (i = 0; i < numElements; i++)
   {
      thisElement = form.elements[i];

      // Ignore disabled fields
      if ( thisElement.disabled )
      {
         continue;
      }
        
      fieldType = form.elements[i].type;
      if ( fieldType == INPUT_TYPE_TEXTFIELD || fieldType == INPUT_TYPE_TEXTAREA )
      {
         thisElement.focus();

         // In case we've scrolled to display the input field, go back to the top.
         // Calling "scrollTo()" immediately doesn't do the scrolling, but using
         // setTimeout(), even with a delay of "0", works.
         //if ( browser_GetScrollX() != 0 || browser_GetScrollY != 0 ) 
          //  {
           // setTimeout( 'scrollTo(0,0)', 0 );
           // }

         break;
      }
   }  // for loop
}



				
				
