﻿function trim(el) {
    el.value = trimValue(el.value);
}

function trimValue(value) {
    return value.replace(/^\s+|\s+$/g, '');
}

function setVisibility(id, visible) {
    $get(id).style.display = visible ? 'block' : 'none';
}

/*==================================================================================================================
    Retourneert de waarde van een RadioButtonList. 
    Als er geen radiobutton is geselecteerd, dan wordt 'undefined' teruggegeven
    De aanroeper kan desondanks wel een volgende controle opnemen en hoeft niet eerst een null check uit te voeren:
    getRadioButtonListSelectedValue('ClientID of your server control') == 'my value' 
==================================================================================================================*/
function getRadioButtonListSelectedValue(id) {
    return $('#' + id + ' input:checked').val();
}

/*==================================================================================================================
Activeert de focus van de opgegeven control en zet de cursor positie naar het einde van de tekst
==================================================================================================================*/
function setFocusAndCursorPositionToEndOfText(elemId) {
    var elem = $get(elemId);
    if (elem != null) {
        var caretPos = elem.value.length;
            
        if (elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if (elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}

function escapeHtml(s) {
    return s.replace(
      /[&<>"]/g,
      function(m) {
          var map = {
              "&": "amp",
              "<": "lt",
              ">": "gt",
              '"': "quot"
          };

          return "&" + map[m] + ";";
      });
}

function unescapeHtml(s) {
    return s.replace(
      /&(amp|[lg]t|quot);/g,
      function(m, p1) {
          var map = {
              amp: "&",
              lt: "<",
              gt: ">",
              quot: '"'
          };

          return map[p1];
      });
}

function trackPageView(pagename) {
    try {
        _gaq.push(['_trackPageview', pagename]);
    }
    catch (err) { }
}

function isValidDate(day, month, year) {
    /*
    Purpose: return true if the date is valid, false otherwise

    Arguments: day integer representing day of month
    month integer representing month of year
    year integer representing year

    Variables: dteDate - date object

    */
    var dteDate;

    //set up a Date object based on the day, month and year arguments
    //javascript months start at 0 (0-11 instead of 1-12)
    dteDate = new Date(year, month - 1, day);

    /*
    Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...
    */

    return ((day == dteDate.getDate()) && (month == dteDate.getMonth() + 1) && (year == dteDate.getFullYear()));
}

    

