﻿    // clears all text (to empty) and combo fields (to -1)
    function ClearForm()
    {
        var formTable = document.getElementById("formTable");
        ChangeAllControlsValue(formTable, "input", "text","");
        ChangeAllControlsValue(formTable, "select", "","-1");
    }

    // Changes all child controls of the parent element with the requested tag and type to the requestd value.
    // Allows to change the value of all controls of a certain type (text boxes, combos etc.) without specifying their names
    function ChangeAllControlsValue(parentElement, controlsTag, controlsType, value)
    {
        var controls = parentElement.getElementsByTagName(controlsTag);
        for( i in controls)
        {
            if (controlsType == "" || controls[i].type == controlsType)
            {
                controls[i].value = value;
            }
        }

    }
       
    //Activates validation on page and then scrolls all the way down 
    // fixes scrolling problem on usual validation
    function ValidateAndScroll()
    {
        Page_ClientValidate();
        window.scrollTo(0,1000);
    }
    
    // clears all text and combo fields in ContactUs form
    function ClearContactForm()
    {
        var formTable = document.getElementById("formTable");
        ChangeAllControlsValue(formTable, "input", "text","");
        ChangeAllControlsValue(formTable, "textarea", "","");
        ChangeAllControlsValue(formTable, "select", "","מנוי התנסות");
    }


    var universityManager =
{
    target: Object,
    lstUniversityId: '',

    Init: function(targetId,lstUniversityId) {
        this.target = document.getElementById(targetId);
        this.lstUniversityId = lstUniversityId;
    },

    GetUniversityData: function(universityId) {
        ajaxHelper.ShowProgress('GetStudentData');

        SearchEngineService.GetUniversityData
        (
            universityId,
            universityManager.GetUniversityData_Complete
        );
    },

    GetUniversityData_Complete: function(args) {
        if (!args) {
            ajaxHelper.ShowError();
            universityManager.target.innerHTML = '';
            return;
        }

        // Set the result html to the target
        universityManager.target.innerHTML = args.Result;
        //document.getElementById(universityManager.divStudentDataId).innerHTML = args.Result;
    },

    ValidateUniversitySelection: function(source, arguments) {
    var universityList = document.getElementById(universityManager.lstUniversityId);
    if (null != universityList) {
        var iValue = new Number(universityList[universityList.selectedIndex].value);
            arguments.IsValid = (iValue > 0);
        }
        else {
                arguments.IsValid = false;
            }
    }	
}




