﻿// JScript File

//Function checks whether the supplied string is empty or not
function IsStringEmpty(argString)
{
    var Empty = false;
    var lString = Trim(argString);
    
    if(lString == "")
        Empty = true;

    return Empty;
}

//Function checks whether the supplied string is empty or not
function IsControlEmpty(argControlID)
{
    var Empty = false;
    var lString = Trim(document.getElementById(argControlID).value);

    document.getElementById(argControlID).value = lString;    
    
    if(lString == "")
        Empty = true;

    return Empty;
}

//Trim spaces from the right of the string
function RTrim(argString)
{
    var lString = "";
    
    for(i = argString.length - 1; i >= 0; i--)
    {
        if (argString[i] != " ")
        {
            lString = argString.substring(0, i + 1);
            break;
        }
    }
    
    return lString;
}

//Trim spaces from the left of the string
function LTrim(argString)
{
    var lString = "";
    
    for(i = 0; i <= argString.length; i++)
    {
        if (argString[i] != " ")
        {
            lString = argString.substring(i, argString.length);
            break;
        }
    }
    
    return lString;
}

//Trim spaces from the left and right of the string
function Trim(argString)
{
    var lString = argString;

    lString = RTrim(lString);
    lString = LTrim(lString);
    
    
    return lString;
}

//Checks whether the supplied value is numeric
function IsNumeric(argControlID)
{
    return !isNaN(document.getElementById(argControlID).value);
}

//Limits the string length
function LimitStringLength(argString, argMaxLength)
{
    var lString = "";
    
    if(argString.length > argMaxLength)
        lString = argString.substring(0, argMaxLength);
    else
        lString = argString
    
    return lString;
}

//Compare two strings and return true if both are equal else false
function CompareStrings(argString1, argString2)
{
    var Equal = false;    
    if(argString1 == argString2)
        Equal = true;        
    return Equal;
}

//Clears the text box value
function ClearTextBox(argTextBoxID)
{
    document.getElementById(argTextBoxID).value = "";
}


//Sets the focus on the control
function SetFocusOnControl(argControlID)
{
    document.getElementById(argControlID).focus();
}

//Clears the form on the client side
function ClearForm(argFormID)
{
    for(i = 0; i<= document.forms.item(argFormID).elements.length - 1;i++)
    {
        if(document.forms.item(argFormID).elements.item(i).type == "text" || document.forms.item(argFormID).elements.item(i).type == "textarea" || document.forms.item(argFormID).elements.item(i).type == "file")
            document.forms.item(argFormID).elements.item(i).value = "";
        else if(document.forms.item(argFormID).elements.item(i).type == "select-one")
            document.forms.item(argFormID).elements.item(i).selectedIndex = -1;
        else if(document.forms.item(argFormID).elements.item(i).type == "checkbox")
            document.forms.item(argFormID).elements.item(i).checked = false;
//        else if(document.form1.elements.item(i).type == "checkbox")
//           document.form1.elements.item(i).checked = false;
    }
}

function IsValueSelected(argSelect)
{
    var Selected = true;
    
    if(document.getElementById(argSelect).selectedIndex == 0 || document.getElementById(argSelect).selectedIndex == -1)
        Selected = false;
        
    return Selected;
}

function getStringLength(argControlID)
{
    var len = 0;
    
    len = document.getElementById(argControlID).value.length;
    
    return len;
}

function IsSpaceInString(argString)
{
    //for(lInteger = 0; lInteger=0
}