/* Check for enters and convert to tabs */
function CheckEnter()
{    
     if(event.keyCode==13 && document.all){event.keyCode=9;return event.keyCode}   
}


/* All input type actions will be declared here! */

//Generate commentary text for required textboxes
function SetCommentary(elementID, commentaryText, commentaryClassName)
{
    var element = document.getElementById(elementID);
    
    if (element.value == '')
    {
        element.value = commentaryText;
        
        if(commentaryClassName != '')
        {
            element.className = commentaryClassName;
        }
    }
}

function RemoveCommentary(elementID, commentaryText, defaultClassName)
{
    var element = document.getElementById(elementID);
    
    if(defaultClassName != '')
    {
        element.className = defaultClassName;
    }
    
    if (element.value == commentaryText)
    {
        element.value = '';
    }
}

//Block non numercal key values
function BlockNonNumericalsValue(id, allowNegativeNumbers, leadingNumbersCount, decimalCount, englishDecimal, e)
{   
	var key = '';
	var success = false;
	var decimalType = '.';

    if (!englishDecimal)
    {
        decimalType = ',';
    }

    if (!e)
    {
        key = event.keyCode ? event.keyCode : event.which;
    }
    else
    {
        key = e.keyCode ? e.keyCode : e.which;
    }
    
    if (document.getElementById(id).value == null || document.getElementById(id).value == '') 
    {
        return true;
    }
    
    var regString = '';
    
    if (decimalCount == 0)
    {
        if (allowNegativeNumbers)
        {
            regString = '^[-]$|^[-]?(0)$|^[-]?([1-9][0-9]{0,' + (leadingNumbersCount - 1) + '})$';
        }
        else
        {
            regString = '^(0)$|^([1-9][0-9]{0,' + (leadingNumbersCount - 1) + '})$';
        }
    }
    else
    {
        if (allowNegativeNumbers)
        {
            regString = '^[-]$|^[-]?(0)$|^[-]?([1-9][0-9]{0,' + (leadingNumbersCount - 1) + '})$|^[-]?([0-9]{0,' + leadingNumbersCount + '}\\' + decimalType + '[0-9]{0,' + decimalCount + '})$';
        }
        else
        {
            regString = '^(0)$|^([1-9][0-9]{0,' + (leadingNumbersCount - 1) + '})$|^([0-9]{0,' + leadingNumbersCount + '}\\' + decimalType + '[0-9]{0,' + decimalCount + '})$';
        }
    }
    
    var reg = new RegExp(regString);
    
    success = reg.test(document.getElementById(id).value);
	
	return success;
}

//Generate commentary text for required textboxes
function SetNumericValue(elementID, defaultValue, commentaryClassName)
{
    var element = document.getElementById(elementID);
        
    if (element.value == '')
    {
        element.value = defaultValue;
        
        if(commentaryClassName != '')
        {
            element.className = commentaryClassName;
        }
    }
}

function RemoveNumericValue(elementID, defaultValue, defaultClassName)
{
    var element = document.getElementById(elementID);

    var curFloatValue = ParseFloatFromString(element.value);
    var curDefaultValue = ParseFloatFromString(defaultValue);
    
    if(defaultClassName != '')
    {
        element.className = defaultClassName;
    }
    
    if (curDefaultValue == curFloatValue || curFloatValue == 0)
    {
        element.value = '';
    }
}

//Set attributes using javascript
function SetAttribute(id, attributeName, attributeValue)
{
    document.getElementById(id).setAttribute(attributeName, attributeValue);
}

//Parse float string values
function ParseFloatFromString(stringValue)
{
    var curFloatValue = parseFloat(stringValue.replace(',', '.'));
    
    if(curFloatValue != 'NaN')
    {
        return curFloatValue;
    }
    else
    {
        return 0.0000;
    }
}

//show and hide elements

function showHide(idDiv)
    {
        if(document.getElementById(idDiv).style.display == 'none')
        {
        
            document.getElementById(idDiv).style.display = 'block';
        }
        else
        {
            document.getElementById(idDiv).style.display = 'none';
        }
    }
function changeSrc(id, src)
    {
        document.getElementById(id).src = src;
    }