/*
'===========================================================================
'Name:			ChildPreferences.js
'Purpose:		Functions for _ChildPreferences.asp
'
'Author:		Cathy Hubin
'Creation Date:	07/10/2007
'
'Change History:
'
'DATE		AUTHOR			REQUEST #	DESCRIPTION
'07/10/2007 Cathy Hubin     939         Initial creation/separation from asp
'08/02/2007	Cathy Hubin		963			Added to ClearOptions orphaned/handicapped/HIV,
'										removed special need
'===========================================================================
*/
function addElement(list, text_in, value_in)
    {
        var objOptionList = list.options;
        var intIndex;
        
	    if (objOptionList.length < 0) //IE for Mac 4.5 sets length to -1 if list is empty
		    intIndex = 0;
	    else
	        intIndex = objOptionList.length;
	        objOptionList[intIndex] = new Option(text_in, value_in);
    }

function ChangeArea(objForm)
	//Called when a user selects an area from a combo box. 
	//This determines what should be displayed in the country drop down box.
    {
        var strAreaSelected = objForm.cboArea.options[objForm.cboArea.selectedIndex].value
        var arrAreaSelected = strAreaSelected.split('#');
        var intAreaDescrIndex = arrAreaSelected[0];
        var arrCountryList  = CountryArray[intAreaDescrIndex];
    
        clearList(objForm.cboCountry);

        addElement(objForm.cboCountry, "Any Country", "Any Country");
        if(arrCountryList)
        { 
            var arrCountryArea = arrCountryList.split(',');
        
            for (var intIndex = 0; intIndex < arrCountryArea.length; intIndex++)
            {
                if (arrCountryArea[intIndex])
                {
                    var arrCountryArea2 = arrCountryArea[intIndex].split('#');
                    addElement(objForm.cboCountry, arrCountryArea2[0], arrCountryArea2[1]);
                }
            }
        }
        objForm.cboCountry.selectedIndex = 0;
    } 

function clearList(list) 
    {
        var intIndex = 0;
        var objOptionList = list.options;
        for (intIndex = objOptionList.length; intIndex >= 0; --intIndex)
		    objOptionList[intIndex] = null;
	}

function ClearOptions (objForm) {
	    objForm.cboArea.selectedIndex = 0;
	    objForm.cboCountry.selectedIndex = 0;
	    objForm.gender.selectedIndex = 0;
	    objForm.cboAge.selectedIndex = 0;	
	    objForm.cboCharacteristicsCount.selectedIndex = 0;
	    objForm.cboOrphaned.selectedIndex = 0;
	    objForm.cboHandicapped.selectedIndex = 0;
	    objForm.cboHIVAffected.selectedIndex = 0;
	    objForm.prefer[0].checked = true;
	    //refresh the country drop down box
	    ChangeArea(objForm);
	}
	
function CheckPreference(objForm) {
	    objForm.cboLongestCount.selectedIndex = 0;
	    objForm.prefer[1].checked = true;
	}
	
