﻿function onMouseOver(obj)
{
    var classNames = obj.className.split(' ');
    var newClassNames = new Array();
    for(var i = 0; i < classNames.length; i++)
    {
        newClassNames[i] = classNames[i] + 'Over';
    }
    obj.className = obj.className + ' ' + newClassNames.join(' ');
}

function onMouseOut(obj)
{
    var classNames = obj.className.split(' ');
    var newClassNames = new Array();
    var overWord = 'Over';
    for(var i = 0; i < classNames.length; i++)
    {
        if(!(classNames[i].indexOf(overWord) > 0 && (classNames[i].indexOf(overWord) + overWord.length) == classNames[i].length))
            newClassNames[i] = classNames[i];
    }
    obj.className = newClassNames.join(' ');
}

function ClickOnReturn(evt, buttonToClick)
{
    evt = (evt) ? evt : ((window.event) ? window.event : "");
    if(evt)
    {
        if ((evt.which && evt.which == 13) || 
            (evt.keyCode && evt.keyCode == 13))
        {
            ClickElement(buttonToClick);
            return true;
        } 
        else 
            return false;
    }
}

function ClickElement(elementToClick)
{
    location = document.getElementById(elementToClick).href;
    return true;
}

function checkLength(text,long,displayName) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (text.value.length > maxlength){
		text.value = text.value.substring(0,maxlength);
		alert(" Only " + long + " chars");
	}
	display = document.getElementById(displayName);
	if(display != null)
	    display.value = text.value.length;
}

function ignoreEnterEscOnKeyPress(sender, e) {
    if (e.get_domEvent().rawEvent.keyCode == 13) { //enter   
        //special handling (focus other control and so on) here   
        //e.get_domEvent().preventDefault();
        e.get_domEvent().stopPropagation();
    }
    else if (e.get_domEvent().rawEvent.keyCode == 27) { // ESC   
        //special handling (clear values and so on) here   
        //e.get_domEvent().preventDefault();
        e.get_domEvent().stopPropagation();
    }
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
    var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
    return newnumber.toFixed(rlength); // Output the result to the form field (change for your purposes)
}

function disableControl(controlClientId){
    var control = $find(controlClientId);
    if(control == null){
        control = $get(controlClientId);
    }
    if(control != null){
        control.disable();
    }
}
            
function enableControl(controlClientId){
    var control = $find(controlClientId);
    if(control == null){
        control = $get(controlClientId);
    }
    if(control != null){
        control.enable();
    }
}
            
function disableCheckBox(checkBoxClientId){
    if($('#' + checkBoxClientId) != null){
        $('#' + checkBoxClientId).attr('disabled', 'disabled');
        $('#' + checkBoxClientId + ' .rfdCheckboxChecked').addClass('rfdInputDisabled');
        $('#' + checkBoxClientId + ' .rfdCheckboxUnchecked').addClass('rfdInputDisabled');
    }
}
            
function enableCheckBox(checkBoxClientId){
    if($('#' + checkBoxClientId) != null){
        $('#' + checkBoxClientId).removeAttr('disabled');
        $('#' + checkBoxClientId + ' .rfdCheckboxChecked').removeClass('rfdInputDisabled');
        $('#' + checkBoxClientId + ' .rfdCheckboxUnchecked').removeClass('rfdInputDisabled');
    }
}
            
function enableDatePicker(datePickerClientId){
    var control = $find(datePickerClientId);
    if(control != null){
        control.set_enabled(true);
    }
}
            
function disableDatePicker(datePickerClientId, setDateNull){
    var control = $find(datePickerClientId);
    if(control != null){
        control.set_enabled(false);
        control.hidePopup();
        if(setDateNull){
            control.set_selectedDate(null);
        }
    }
}
            
function getCheckboxValue(controlId, defaultValue){
    var checkedValue = defaultValue;
    var checkedControl = $get(controlId);
    if(checkedControl != null){
        checkedValue = checkedControl.checked;
    }
    return checkedValue;
}
            
function setCheckboxValue(controlId, value){
    var checkedControl = $get(controlId);
    if(checkedControl != null){
        checkedControl.checked = value;
    }
}
            
function getComboboxValue(controlId, defaultValue, trueString){
    var comboBoxValue = defaultValue;
    var comboBoxControl = $find(controlId);
    if (trueString == '' || trueString == null || trueString == 'undefined') {
        trueString = 'True';
    }
    if(comboBoxControl != null){
        comboBoxValue = comboBoxControl.get_value() == trueString ? true : false;
    }
    return comboBoxValue;
}
            
function setComboboxValue(controlId, value){
    var comboBoxControl = $find(controlId);
    if(comboBoxControl != null){
        var comboBoxItem = comboBoxControl.findItemByValue(value);
        if(comboBoxItem != null){
            comboBoxControl.trackChanges();
            comboBoxItem.select();
            comboBoxControl.commitChanges();
        }
    }
}

function getRadioListValue(controlId, defaultValue, trueString) {
    var checkedValue = defaultValue;
    var checkedControl = $get(controlId);
    if (trueString == '' || trueString == null || trueString == 'undefined') {
        trueString = 'True';
    }
    if (checkedControl != null) {
        checkedValue = $('#' + controlId + '  input:radio:checked').val() == trueString ? true : false;
    }
    return checkedValue;
}
            
function setRadioListValue(controlId, value){
    var checkedControl = $get(controlId);
    if(checkedControl != null){
        $('#' + controlId).find("input[value='" + value + "']").attr("checked", "checked");
    }
}

function disableRadioListControl(radioListValueClientId) {
    if ($('#' + radioListValueClientId) != null) {
        $('#' + radioListValueClientId).attr('disabled', 'disabled');
    }
}

function enableRadioListControl(radioListValueClientId) {
    if ($('#' + radioListValueClientId) != null) {
        $('#' + radioListValueClientId).removeAttr('disabled');
    }
}

function onNumberValueOnBlur(sender, args) {
    if(sender.get_value() == ''){
        sender.set_value(0);
    }
    return false;
}

function AutoExpand(txtBox, event) {
    if (event.keyCode == "13" || event.keyCode == "8") {
        AutoExpand(txtBox);
        return false;
    }
}

function AutoExpand(txtBox) {
    var therows = 0
    var thetext = document.getElementById(txtBox.id).value;
    var newtext = thetext.split("\n");
    therows += newtext.length;
    document.getElementById(txtBox.id).rows = therows;
    return false;
}
