﻿function SearchPanel() {

    this.WhatTextBox = document.getElementById('WhatTextBox');
    this.WhoTextBox = document.getElementById('WhoTextBox');
    this.WhereTextBox = document.getElementById('WhereTextBox');

    this.WhatIsEmptyHiddenField = document.getElementById('whatIsEmptyHiddenField');
    this.WhoIsEmptyHiddenField = document.getElementById('whoIsEmptyHiddenField');
    this.WhereIsEmptyHiddenField = document.getElementById('whereIsEmptyHiddenField');

    this.Init = function() {

        if (this.WhatIsEmptyHiddenField.value.length == 0) {
            this.WhatTextBox.style.color = "Gray";
        }
        else {
            this.WhatTextBox.style.color = "Black";
        }

        if (this.WhoIsEmptyHiddenField.value.length == 0) {
            this.WhoTextBox.style.color = "Gray";
        }
        else {
            this.WhoTextBox.style.color = "Black";
        }

        if (this.WhereIsEmptyHiddenField.value.length == 0) {
            this.WhereTextBox.style.color = "Gray";
        }
        else {
            this.WhereTextBox.style.color = "Black";
        }
    }

    this.ShareTextBoxContent = function(e, control) {

        var keynum;

        if (window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
        if (keynum != 9 && keynum != 13) {
            //alert(keynum);
            var HiddenField;

            switch (control.id) {
                case "WhatTextBox":
                    HiddenField = document.getElementById('whatIsEmptyHiddenField');
                    HiddenField.value = control.value;
                    control.style.color = "Black";
                    break;
                case "WhoTextBox":
                    HiddenField = document.getElementById('whoIsEmptyHiddenField');
                    HiddenField.value = control.value;
                    control.style.color = "Black";
                    break;
                case "WhereTextBox":
                    HiddenField = document.getElementById('whereIsEmptyHiddenField');
                    HiddenField.value = control.value;
                    control.style.color = "Black";
                    break;
            }
        }
    }

    this.SetTextBoxDirty = function(control) {

        var HiddenField;

        switch (control.id) {
            case "WhatTextBox":
                HiddenField = document.getElementById('whatIsEmptyHiddenField');
                break;
            case "WhoTextBox":
                HiddenField = document.getElementById('whoIsEmptyHiddenField');
                break;
            case "WhereTextBox":
                HiddenField = document.getElementById('whereIsEmptyHiddenField');
                break;
        }

        if (HiddenField.value.length == 0) {
            control.value = '';
        }

        control.style.color = "Black";
    }

    this.ShareContent = function() {
        if (this.WhatIsEmptyHiddenField.value.length > 0) {
            this.WhatIsEmptyHiddenField.value = this.WhatTextBox.value;
        }
        if (this.WhoIsEmptyHiddenField.value.length > 0) {
            this.WhoIsEmptyHiddenField.value = this.WhoTextBox.value;
        }
        if (this.WhereIsEmptyHiddenField.value.length > 0) {
            this.WhereIsEmptyHiddenField.value = this.WhereTextBox.value;
        }
    }

    this.ResetHiddenFields = function() {
        this.WhatIsEmptyHiddenField.value = '';
        this.WhoIsEmptyHiddenField.value = '';
        this.WhereIsEmptyHiddenField.value = '';
    }
}

function AdvancedSearchPanel() {
    
    this.WhatTextBox = document.getElementById('advancedWhatTextBox');
    this.WhoTextBox = document.getElementById('advancedWhoTextBox');
    this.WhereTextBox = document.getElementById('advancedWhereTextBox');

    this.StreetTextBox = document.getElementById('streetTextBox');
    this.NumberTextBox = document.getElementById('numberTextBox');
    this.PhoneTextBox = document.getElementById('phoneTextBox');

    //this.RadioButtonList = document.getElementById('rayonRadioButtonList');

    this.WhatIsEmptyHiddenField = document.getElementById('whatIsEmptyHiddenField');
    this.WhoIsEmptyHiddenField = document.getElementById('whoIsEmptyHiddenField');
    this.WhereIsEmptyHiddenField = document.getElementById('whereIsEmptyHiddenField');

    this.Init = function() {

        if (this.WhatIsEmptyHiddenField.value.length == 0) {
            this.WhatTextBox.style.color = "Gray";
        }
        else {
            this.WhatTextBox.value = this.WhatIsEmptyHiddenField.value;
            this.WhatTextBox.style.color = "Black";
        }

        if (this.WhoIsEmptyHiddenField.value.length == 0) {
            this.WhoTextBox.style.color = "Gray";
        }
        else {
            this.WhoTextBox.value = this.WhoIsEmptyHiddenField.value;
            this.WhoTextBox.style.color = "Black";
        }

        if (this.WhereIsEmptyHiddenField.value.length == 0) {
            this.DisableInputsFromWhere();
        }
        else {
            this.WhereTextBox.value = this.WhereIsEmptyHiddenField.value;
            this.WhereTextBox.style.color = "Black";
        }

        if (this.StreetTextBox.value.length > 0 || this.NumberTextBox.value.length > 0 || this.PhoneTextBox.value.length > 0) {
            //this.RadioButtonList.disabled = true;
            this.DisableRadiosButtons();
        }

        var radio = document.forms[0].elements['rayonRadioButtonList'];

        if (radio[0].checked) {
            //alert(radio[0].value);
        }
        else {
            this.StreetTextBox.disabled = true;
            this.NumberTextBox.disabled = true;
            this.PhoneTextBox.disabled = true;
            this.StreetTextBox.style.backgroundColor = "#C0C0C0";
            this.NumberTextBox.style.backgroundColor = "#C0C0C0";
            this.PhoneTextBox.style.backgroundColor = "#C0C0C0";
        }

    }

    this.ResetHiddenFields = function() {
        this.WhatIsEmptyHiddenField.value = '';
        this.WhoIsEmptyHiddenField.value = '';
        this.WhereIsEmptyHiddenField.value = '';
    }

    this.ShareContent = function() {
        if (this.WhatIsEmptyHiddenField.value.length > 0) {
            this.WhatIsEmptyHiddenField.value = this.WhatTextBox.value;
        }
        if (this.WhoIsEmptyHiddenField.value.length > 0) {
            this.WhoIsEmptyHiddenField.value = this.WhoTextBox.value;
        }
        if (this.WhereIsEmptyHiddenField.value.length > 0) {
            this.WhereIsEmptyHiddenField.value = this.WhereTextBox.value;
        }
    }

    this.ShareTextBoxContent = function(e, control) {

    var keynum;

        if (window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
        
        if (keynum != 9 && keynum != 13) {
            var HiddenField;

            switch (control.id) {
                case "advancedWhatTextBox":
                    HiddenField = document.getElementById('whatIsEmptyHiddenField');
                    var HiddenCatID = document.getElementById('selectedCatID');
                    HiddenCatID.value = '';
                    HiddenField.value = control.value;
                    control.style.color = "Black";
                    break;
                case "advancedWhoTextBox":
                    HiddenField = document.getElementById('whoIsEmptyHiddenField');
                    HiddenField.value = control.value;
                    control.style.color = "Black";
                    break;
                case "advancedWhereTextBox":
                    HiddenField = document.getElementById('whereIsEmptyHiddenField');
                    var HiddenCPID = document.getElementById('selectedPostalCode');
                    HiddenCPID.value = '';
                    HiddenField.value = control.value;
                    control.style.color = "Black";

                    if (control.value.length == 0) {
                        this.DisableInputsFromWhere();
                    }
                    else {
                        this.EnableInputsFromWhere();
                    }
                    break;
                case "streetTextBox":
                    this.CheckControl(control);
                    break;
                case "numberTextBox":
                    this.CheckControl(control);
                    break;
                case "phoneTextBox":
                    this.CheckControl(control);
                    break;
            }
        }
    }

    this.CheckSelectedRadioButton = function(value) {
        if (value > 0) {
            this.StreetTextBox.style.backgroundColor = "#C0C0C0";
            this.NumberTextBox.style.backgroundColor = "#C0C0C0";
            this.PhoneTextBox.style.backgroundColor = "#C0C0C0";
            this.StreetTextBox.disabled = true;
            this.NumberTextBox.disabled = true;
            this.PhoneTextBox.disabled = true;
            this.StreetTextBox.value = '';
            this.NumberTextBox.value = '';
            this.PhoneTextBox.value = '';
        }
        else {
            this.StreetTextBox.style.backgroundColor = "White";
            this.NumberTextBox.style.backgroundColor = "White";
            this.PhoneTextBox.style.backgroundColor = "White";
            this.StreetTextBox.disabled = false;
            this.NumberTextBox.disabled = false;
            this.PhoneTextBox.disabled = false;
        }
    }

     this.DisableInputsFromWhere = function() {
        this.WhereTextBox.style.color = "Gray";
        this.StreetTextBox.style.backgroundColor = "#C0C0C0";
        this.NumberTextBox.style.backgroundColor = "#C0C0C0";
        this.StreetTextBox.disabled = true;
        this.NumberTextBox.disabled = true;
        this.StreetTextBox.value = '';
        this.NumberTextBox.value = '';
        //this.RadioButtonList.disabled = true;
        this.DisableRadiosButtons();
        
    }

    this.EnableInputsFromWhere = function() {
        this.WhereTextBox.style.color = "Black";
        this.StreetTextBox.style.backgroundColor = "White";
        this.NumberTextBox.style.backgroundColor = "White";
        this.StreetTextBox.disabled = false;
        this.NumberTextBox.disabled = false;
        //this.RadioButtonList.disabled = false;
        this.EnableRadiosButtons();                
    }

    this.CheckControl = function(control) {
        if (this.StreetTextBox.value.length > 0 || this.NumberTextBox.value.length > 0 || this.PhoneTextBox.value.length > 0) {
            //this.RadioButtonList.disabled = true;
            this.DisableRadiosButtons();
        }
        else {
            if (this.WhereTextBox.value.length > 0) {
                //this.RadioButtonList.disabled = false;
                this.EnableRadiosButtons();
            }
        }
    }

    this.EnableRadiosButtons = function() {
        var radio = document.forms[0].elements['rayonRadioButtonList'];

        var i;
        for (i = 0; i < radio.length; i++) {
            radio[i].disabled = false;
        }
    }

    this.DisableRadiosButtons = function() {
        var radio = document.forms[0].elements['rayonRadioButtonList'];

        var i;
        for (i = 0; i < radio.length; i++) {
            radio[i].disabled = true;
        }
    }

    this.SetTextBoxDirty = function(control) {

        var HiddenField;

        switch (control.id) {
            case "advancedWhatTextBox":
                HiddenField = document.getElementById('whatIsEmptyHiddenField');
                break;
            case "advancedWhoTextBox":
                HiddenField = document.getElementById('whoIsEmptyHiddenField');
                break;
            case "advancedWhereTextBox":
                HiddenField = document.getElementById('whereIsEmptyHiddenField');
                break;
        }

        if (HiddenField.value.length == 0) {
            control.value = '';
        }

        control.style.color = "Black";
    }
    
    

   /* this.ShareWhereContent = function(e) {

        var keynum;

        if (window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
        if (keynum != 9) {
            this.WhereIsEmptyHiddenField.value = this.WhereTextBox.value;
        }

        if (this.WhereTextBox.value == 0) {
            this.WhereTextBox.style.color = "Gray";
            this.StreetTextBox.style.backgroundColor = "#C0C0C0";
            this.NumberTextBox.style.backgroundColor = "#C0C0C0";
            this.StreetTextBox.disabled = true;
            this.NumberTextBox.disabled = true;
            this.StreetTextBox.value = '';
            this.NumberTextBox.value = '';
            this.RadioButtonList.disabled = true;
        }
        else {
            this.WhereTextBox.style.color = "Black";
            this.StreetTextBox.style.backgroundColor = "White";
            this.NumberTextBox.style.backgroundColor = "White";
            this.StreetTextBox.disabled = false;
            this.NumberTextBox.disabled = false;

            if (this.StreetTextBox.value == 0 && this.NumberTextBox.value == 0) {
                this.RadioButtonList.disabled = false;
            }
        }
    }

    this.ShareWhatContent = function(e) {

        var keynum;

        if (window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
        if (keynum != 9) {
            this.WhatIsEmptyHiddenField.value = this.WhatTextBox.value;
        }
    }

    this.ShareWhoContent = function(e) {

    var keynum;

    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    
        if (keynum != 9) {
            this.WhoIsEmptyHiddenField.value = this.WhoTextBox.value;
        }
    }*/
}