﻿// JScript File

       var myArgGloabal;
       
       var myTopDioceseCode;
       
        function GetDioceses(){     

                    myArgGloabal = "dio|get|";
	                var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value   
                   
    	            myTarget = document.getElementById("section3_display");       
                    myTarget.innerHTML =  "<IMG SRC='../../images/general/pleasewait.gif' ALT=''>"
                    UseDioceseCallback("dio|get|" + selectedcounty);
                    
        }
        
        
        function GetDiocesesFromServer(countryNode, context){   
               var myRegExp = new RegExp(/\#/)
               var TotalArray = countryNode.split(myRegExp); 

                  switch (TotalArray[0]) { 
                    case "org|get|": writeOrgs(TotalArray[1]); 
                              break;
                    case "or2|get|": writeOrgs_no_new(TotalArray[1]); 
                              break;                                
                    case "dio|get|": writeDioceses(TotalArray[1]);
                              break;            
                    case "org|add|": getOrg();
                              break;            
                    case "dio|add|": GetDioceses();
                              break;            
                  }
             } 
                         
            function writeDioceses(countryNode){       
           
                    //alert(countryNode);          
                          
                   	var dioceseList = document.form1.Communities1$Other_dioceses1$DropDownList2;

                   	for (var count = dioceseList.options.length-1; count >-1; count--)
	                    {
		                    dioceseList.options[count] = null;
	                    }
	                	                
    	                    myTarget = document.getElementById("section3_display");
                            myTarget.innerHTML =  ""
	                        var myRegExp = /`/;
	                        var myString = countryNode;
	                        var resultsArray = myString.split(myRegExp);
	                        var arrayLength = resultsArray.length;
        	                
	                        optionItem = new Option("please select", "0",  false, false);
	                        dioceseList.options[dioceseList.length] = optionItem;

	                        //Add new states list to the state combo box.
	                       for (var count = 0; count < arrayLength; count++)
	                        {

 	                            var myRegExp = /~/;
	                            var myString2 = resultsArray[count];
	                            var resultsArray2 = myString2.split(myRegExp);  		      
	                           
	                           
	                            if (count == 0){
	                                myTopDioceseCode = resultsArray2[1]
	                               }
	                               else
	                               {
	                                    if (myTopDioceseCode < resultsArray2[0]) {
	                                        myTopDioceseCode = resultsArray2[0]
	                                   }
	                               } 
	                                      
		                        optionItem = new Option(resultsArray2[1], resultsArray2[0]);
		                        //alert(resultsArray2[1]+" - "+resultsArray2[0])
		                        dioceseList.options[dioceseList.options.length] = optionItem;
		                        resultsArray2 = ""
	                        }            

        }
       
       
        function writeOrgs(countryNode){      
           
              	        myTarget = document.getElementById("section3_display");
                        myTarget.innerHTML = countryNode
                        newOrg()
    	                
          }   
       
        function writeOrgs_no_new(countryNode){      
           
              	        myTarget = document.getElementById("section3_display");
                        myTarget.innerHTML = countryNode
    	                
          }  
          
        function newDiocese(){   

	                    var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value   
 	                    var selectedcounty_text = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].text   
            
    	                myTarget = document.getElementById("section3_display");
                        
                        myTarget.innerHTML =  "<table><tr><td colspan='2'><p class='body_text_8'><b>New Diocese for " + selectedcounty_text + "</b></p></td></tr><tr><td><p class='body_text_8' align='right'>Name:</p></td><td><input id='dio_name' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>State-Region-Provance:</p></td><td><input id='dio_state' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>Type:&nbsp;</p></td><td><select id='dio_type'><option value='Diocese'>Diocese</option><option value='Archdiocese'>Archdiocese</option> <option value='Archeparchy'>Archeparchy</option> <option value='Military_Ordinariate'>Military Ordinariate</option><option value='Territorial_Abbey'>Territorial Abbey</option><option value='Territorial_Prelature'>Territorial Prelature</option><option value='Exarchate'>Exarchate</option><option value='Eparchy'>Eparchy</option><option value='Other'>Other</option></select></td></tr></tr><tr><td colspan='2'><p class='body_text_8' align='right'><a href='javascript:addDiocese()'>Add...</a></p></td></tr></table>"
   
         } 
        
        
        function addDiocese(){   

                    myArgGloabal = "dio|add|";
   	                var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value   
                    var dio_name = document.getElementById("dio_name").value;
                    var dio_state = document.getElementById("dio_state").value;
                    var myDio_type = document.getElementById("dio_type");
                    var selected_dio_type = myDio_type.options[myDio_type.selectedIndex].value 
                  //  alert(dio_name + '|zzzz|' + dio_state + '|zzzz|' + selected_dio_type + '|zzzz|' + myTopDioceseCode)
                    UseDioceseCallback("dio|add|" + dio_name + '|zzzz|' + dio_state + '|zzzz|' + selected_dio_type + '|zzzz|' + myTopDioceseCode);
                    
         }   
         
        function addOrg(){   

                    myArgGloabal = "org|add|";
   	                var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value
                    var org_name = document.getElementById("org_name").value;
                    var org_other_name = document.getElementById("org_other_name").value;
                    var org_suburb = document.getElementById("org_suburb").value;
                    var org_postal = document.getElementById("org_postal").value;
                    var myOrg_type = document.getElementById("org_class");
                    var selected_org_type = myOrg_type.options[myOrg_type.selectedIndex].value 
                    var myDio_type = document.getElementById("dio_type");
	                var selecteddiocese = document.form1.Communities1$Other_dioceses1$DropDownList2.options[document.form1.Communities1$Other_dioceses1$DropDownList2.selectedIndex].value   
                    var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value   


                    //alert(selectedcounty + "|zzzz|" + selecteddiocese + "|zzzz|" + org_name + "|zzzz|" + org_other_name + "|zzzz|" + org_suburb + "|zzzz|" + org_postal + "|zzzz|" + selected_org_type)
                    UseDioceseCallback("org|add|" + selectedcounty + "|zzzz|" + selecteddiocese + "|zzzz|" + org_name + "|zzzz|" + org_other_name + "|zzzz|" + org_suburb + "|zzzz|" + org_postal + "|zzzz|" + selected_org_type);
                    
         }   
                
         function newOrg(){   

	                    var selectedcounty = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].value   
 	                    var selectedcounty_text = document.form1.Communities1$Other_dioceses1$country.options[document.form1.Communities1$Other_dioceses1$country.selectedIndex].text   
            
    	                myTarget = document.getElementById("section3_display");
                        
                        myTarget.innerHTML =  myTarget.innerHTML + "<br /><table><tr><td colspan='2'><p class='body_text_8'><b>If your organisation is not listed (please check carefully) you may add a new organisation. The new organisation while be manually checked later, but meanwhile will work normally.</b></p></td></tr><tr><td><p class='body_text_8' align='right'>Name:</p></td><td><input id='org_name' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>Alternate Name:</p></td><td><input id='org_other_name' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>Suburb:</p></td><td><input id='org_suburb' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>Postal/Zip Code:</p></td><td><input id='org_postal' type='text' /></td></tr><tr><td><p class='body_text_8' align='right'>Type:&nbsp;</p></td><td><select id='org_class'><option value='parish'>Parish</option><option value='school'>Catholic School</option> <option value='gov_school'>Government School</option><option value='dio_org'>Diocesan Organisation</option><option value='lay_mov'>Lay Movement</option><option value='rel_order'>Religous Order</option><option value='higher_ed'>Higher Education</option><option value='hosp'>Hospitial</option><option value='aged_care'>Aged Care Facility</option><option value='welfare'>Welfare Sevice Provider</option><option value='work_place'>Work Place</option><option value='other'>Other</option></select></td></tr><tr><td colspan='2'><p class='body_text_8' align='right'><a href='javascript:addOrg()'>Add...</a></p></td></tr></table>"
   
         }  
         
         function getOrg(){  
         
                  myArgGloabal = "org|get|";
                  
	              var selecteddiocese = document.form1.Communities1$Other_dioceses1$DropDownList2.options[document.form1.Communities1$Other_dioceses1$DropDownList2.selectedIndex].value   
        
                  if(selecteddiocese == "000_add"){
                   
                     newDiocese()
                  
                  }
                  else
                  {

    	            myTarget = document.getElementById("section3_display");
                        
                    myTarget.innerHTML =  "<IMG SRC='../../images/general/pleasewait.gif' ALT=''>"
                    UseDioceseCallback("org|get|" + selecteddiocese);

                  }      

         }    
        
        function openDiv(myArg)
          {
               var PrivacyInfo = document.getElementById(myArg);
           //   alert(myArg); 
               var PrivacyPlus = document.getElementById("plus_" + myArg);
               PrivacyInfo.style.display = (PrivacyInfo.style.display == "none")?"inline":"none";
               PrivacyPlus.innerHTML = (PrivacyPlus.innerHTML == "+")?"–":"+";
          }  
