/*
 * placeholder for all common js function for pcs app
 */

  // validate empty string and return boolean
  function validate_str(val) {
    if(trim(val) == '')
      return false;
    else
      return true;
  }

  // Removes leading whitespaces
  function LTrim( value ) {
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
  }

  // Removes ending whitespaces
  function RTrim( value ) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
  }

  // Removes leading and ending whitespaces
  function trim( value ) {
    return LTrim(RTrim(value));
  }

function limitChatCounter(event,formElem,maxlimit)
{
    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

    var textElem='';
    var counterElem='';

    if (formElem)
    {
        textElem = formElem.Text;
        counterElem = formElem.Count;
    }

    if (textElem && counterElem)
    {
        if (textElem.value.length > maxlimit)
        {
            textElem.value = textElem.value.substring(0,maxlimit);
        }
        else
        {
            counterElem.value = maxlimit-textElem.value.length;
        }
        if(Key == 13)
        {
            formElem.submit();
        }
    }
}

var global_tz;
var global_region;

function utc_clock()
{
    var tz = global_tz;
    var region = global_region;
	var today = new Date();
    today.setTime(today.getTime() + (tz * 1000));
    var year = today.getUTCFullYear();
    var month = today.getUTCMonth() + 1;
    var day = today.getUTCDate();
    var hour = today.getUTCHours();
    var minute = today.getUTCMinutes();
    var second = today.getUTCSeconds();
    var utc_time;

    if (month <= 9) month = "0" + month;
    if (day <= 9) day = "0" + day;
    if (hour <= 9) hour = "0" + hour;
    if (minute <= 9) minute = "0" + minute;
    if (second <= 9) second = "0" + second;

    utc_time = year + "-" + month + "-" + day + " "
        + hour + ":" + minute + ":" + second + " ("+region+")";

    var clock_div = document.getElementById('utc_clock');
    clock_div.innerHTML = utc_time;
    setTimeout("utc_clock()", 500);
}
