﻿//v2.0
// RcsWeb Global JavaScript library
//
// This library contains functions that are common javascript functions that should
// have been included to begin with?
//
// Copyright (c) 2010 RightWeb Consulting Services


// ---------------------------------------------------------------------------------
/* STRING MANIPULATION */
// ---------------------------------------------------------------------------------

// FUNCTION: rcs_String_StartsWith()
// Returns True if string starts with substr, false otherwise   
function rcs_String_StartsWith(str, substr)
{
    return (str.match("^"+substr)==substr);
}

// FUNCTION: rcs_String_Count()
// Returns the number of times substr appears in string
function rcs_String_Count(string, substr)
{
    var _c = 0;
    for (var i=0;i<string.length;i++)
    {
        if (substr == string.substr(i,substr.length))
        _c++;
    }
    return(_c);
}

// FUNCTION: rcs-String_IsNullOrEmpty
// Returns true if string is null, empty, or not a string. Returns false otherwise.
function rcs_String_IsNullOrEmpty(value) {
    if (typeof (value) == 'string' || (value instanceof String)) {
        if ((value == null) || (value == '')) {

            return true;
        }
        else {
            return false;
        }
    }
    else {
        return true;
    }
}

// FUNCTION: rcs_String_ReplaceNullOrEmpty
// Returns the value if it is not null or empty, otherwise returns replacementValue
function rcs_String_ReplaceNullOrEmpty(value, replacementValue) {
    if (rcs_String_IsNullOrEmpty(value) == true) {
        return replacementValue;
    }
    else {
        return value;
    }
}


// ---------------------------------------------------------------------------------
/* TIMING */
// ---------------------------------------------------------------------------------

// FUNCTION: rcs_Wait()
// Pauses script for the specified amount of time, in milliseconds.
function rcs_Wait(milliseconds)
{
var date = new Date();
var curDate = null;
do {curDate = new Date();}
while(curDate-date<milliseconds);
}


function rcs_GetPageElement(id)
{
    if (document.getElementById) {
        return document.getElementById(id);
    }
    else {
        if (document.layers) {
            return document.id;
        }
        else {
            return document.all.id;
        }
    }
}
