﻿//This function sets the default button of the page,
//i.e. if the "Enter" is clicked which button to be clicked from the page.
//param: btn - object
//author: Slavena Savova
//date: 07/17/2007
function SetDefaultButton(btn, keyEvent) {
    if (btn != null) {
        if (document.all) {
            if (keyEvent.srcElement.tagName == 'TEXTAREA')
                return;
            if (keyEvent.keyCode == 13) {
                keyEvent.returnValue = false;
                keyEvent.cancel = true;
                btn.click();
            }
        }
        else if (document.getElementById) {
            if (keyEvent.target.tagName == 'TEXTAREA')
                return;
            if (keyEvent.which == 13) {
                keyEvent.returnValue = false;
                keyEvent.cancel = true;
                btn.click();
            }
        }
        else if (document.layers) {
            if (keyEvent.target.tagName == 'TEXTAREA')
                return;
            if (keyEvent.which == 13) {
                keyEvent.returnValue = false;
                keyEvent.cancel = true;
                btn.click();
            }
        }
    }
}

//Find a document element by tag type and id
//param:tagname - input or span
//param:realName - the id of the asp control
//Author: Slavena Savova
//Date: 12/11/2006
function getName(tagType, realName) {
    inputArray = document.body.getElementsByTagName(tagType);
    for (i = 0; i < inputArray.length; i++) {
        if (inputArray[i].id.toString().indexOf(realName) != -1) {
            return inputArray[i].id;
        }
    }
}

//Find a document element by parent control, tag type and id
//param:parent - parent control
//param:tagname - input or span
//param:realName - the id of the asp control
//Author: Slavena Savova
//Date: 12/11/2006
function getNameByParent(parent, tagType, realName) {
    inputArray = parent.getElementsByTagName(tagType);
    for (i = 0; i < inputArray.length; i++) {
        if (inputArray[i].id.toString().indexOf(realName) != -1) {
            return inputArray[i].id;
        }
    }
}

/*
Author: Melon Team
Date: 10/08/2009
Description: Set dropdown value in textbox
*/
function DropDownTextToBox(objDropdown, strTextboxId) {
    var txtGroupName = document.getElementById(getName('input', strTextboxId));
    if (txtGroupName.style.display == 'none')
    {
        return;
    }

    txtGroupName.value = objDropdown.options[objDropdown.selectedIndex].value; 
    DropDownIndexClear(objDropdown.value);
    txtGroupName.focus(); 
} 

/*
Author: Melon Team 
Date: 10/08/2009
Description: Clear dropdown selection when textbox value is changed
*/
function DropDownIndexClear(strDropdownId) {
    var ddlGroupName = document.getElementById(getName('select', strDropdownId));
    if (ddlGroupName != null) {
        ddlGroupName.selectedIndex = -1;
    }
}
