

var PdpUtils = {

  logHash: function(hash) {
    for (var key in hash)
      console.log(key + ' -> ' + hash[key]);
  },

  executeJs: function(id) {
    jQuery('#' + id).each(function() {
      eval(jQuery(this).text());
    });
  },

  getInsideWindowWidth: function() {
    if (window.innerWidth) {
      return window.innerWidth;
    } else if (document.body && document.body.clientWidth) {
      return document.body.clientWidth;
    }
    return 0;
  },

  getInsideWindowHeight: function() {
    if (window.innerHeight) {
      return window.innerHeight;
    } else if (document.body && document.body.clientHeight) {
      return document.body.clientHeight;
    }
    return 0;
  },

  duration2String: function(nMS) {
    var sReturn, sComp, nDur;

    nDur = nMS % 1000;
    sComp = nDur.toString();
    while (sComp.length < 3)
      sComp = "0" + sComp;
    sReturn = "." + sComp + " seconds";

    nMS -= nDur;
    nMS /= 1000;

    nDur = nMS % 60;
    if (nDur)
      sReturn = nDur.toString() + sReturn;
    else
      sReturn = "0" + sReturn;

    nMS -= nDur;
    nMS /= 60;

    nDur = nMS % 60;
    sReturn = nDur.toString() + " minutes, and " + sReturn;

    nMS -= nDur;
    nMS /= 60;

    return nMS.toString() + " hours, " + sReturn;
  },

  isValidEmail: function(email) {
    return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
  },

  isValidEmailsString: function(emailsString, separator) {
    var emails = emailsString.split(separator);
    for (var i in emails)
      if (!this.isValidEmail(emails[i])) return 0;
    return 1;
  }
}