﻿// JScript File

function changeToUppercase(element){
    element.value = element.value.toUpperCase();
}

function removeSpaces(element){
    element.value = element.value.replace(/(\s+)/g,"");
}

//Get and set position so page retains its scroll position.
function getPosition() 
{ 
alert(document.body.scrollTop);
document.forms[0].hid.value=document.body.scrollTop; 
//document.forms[0].element.value=document.body.scrollTop; 
} 
 
function setPosition() 
{ 
alert(document.forms[0].hid.value);
document.body.scrollTop=document.forms[0].hid.value; 
//document.body.scrollTop=document.forms[0].element.value; 
}

function getPositionNew(element) 
{ 
alert(document.body.scrollTop);
document.getElementById(element).value=document.body.scrollTop; 
//document.forms[0].element.value=document.body.scrollTop; 
} 
 
function setPositionNew(element) 
{ 
alert(document.forms[0].hid.value);
document.body.scrollTop=document.getElementById(element).value; 
//document.body.scrollTop=document.forms[0].element.value; 
}

function ExtractInitials(forenameControlID,initialsControlID)
{
    var initials = document.getElementById(initialsControlID);
    initials.value = '';
    var forename = document.getElementById(forenameControlID).value;
    var forenameCollection = forename.split(' ');
    for (var i = 0;i < forenameCollection.length;i++)
    initials.value +=forenameCollection[i].substring(0,1) + ' ';
}

// 
/*
Script to solve a bug in the Component Art ComboBox
Problem 
When you are using the ComboBox in DropDown mode (No text box), if you select an item in the list that has text wider than the combo box the box will streatch to accomodate the text. The reason for this is caused by the <nobr> that the text is wrapped in. 
Workaround 
To get round the problem attach an event handler to the changed event on the combobox and add the following code. 

Applies to version 2008.1.1110
*/
function ComboChange(sender,e)
{
document.getElementById(sender.DomElementId + "_TextBox").innerHTML = "<div style='width: " + (sender.Width - 23) + "px; overflow: hidden;'><nobr>" + sender.getSelectedItem().Text + "</nobr></div>";
}

function textCounter(field, countfield, maxlimit) {
    /*
    * The input parameters are: the field name;
    * field that holds the number of characters remaining;
    * the max. numb. of characters.
    */
    if (field.value.length > maxlimit) // if the current length is more than allowed
        field.value = field.value.substring(0, maxlimit); // don't allow further input
    else
        countfield.value = maxlimit - field.value.length;
} // set the display field to remaining number

