function doPrint(id){
  $('#' + id).printElement({overrideElementCSS: true});
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function isNumeric(num) {
  var st="0123456789";
  if (num.charAt(0)=="-"){
    num = num.substring(1, num.length);
  }
  for (i=0; i<num.length; i++) {
    if (0 > st.indexOf(num.charAt(i))) return false;
  }
  return true;
}
function isReal(num) {
  if (num.length==0) return false;
  if (num.charAt(0)=="-") var loopStart=1;
  else loopStart=0;
  var st="0123456789.";
  for (i=loopStart; i<num.length; i++) {
    if (0 > st.indexOf(num.charAt(i))) return false;
  }
  if (num.indexOf(".", num.indexOf(".")+1)!=-1) return false;
  return true;
}
function getScreenSize() {
  var r = new Array(1);
  r[0] = 0;
  r[1] = 0;
  r[2] = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
  if (typeof(window.innerWidth )=='number') {
    r[0] = window.innerWidth;
    r[1] = window.innerHeight;
  } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    r[0] = document.documentElement.clientWidth;
    r[1] = document.documentElement.clientHeight;
  } else if (document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    r[0] = document.body.clientWidth;
    r[1] = document.body.clientHeight;
  }
  return r;
}
function createParamsString(o) {
  var val = '';
  var result = '';
  var st = '';
  if (arguments.length>1) var delim1 = arguments[1];
  else var delim1 = "&";
  if (arguments.length>2) var delim2 = arguments[2];
  else var delim2 = "=";
  if (arguments.length>3) var includeEmptyValues = arguments[3];
  else var includeEmptyValues = true;
  if (arguments.length>4) var trimValues = arguments[4];
  else var trimValues = false;


  for (var i=0; i<o.length; i++) {
    x = o.elements[i];
    if (x.name!='') {
      switch (x.type.toLowerCase()) {
        case 'select-one':
        case 'select-multiple':
          st = "";
          for (var j=0; j<x.length; j++) if (x.options[j].selected) st += ',' + x.options[j].value;
          if (st.charAt(0) == ',') st = st.substring(1, st.length);
          if (trimValues) st = trim(st);
          if (includeEmptyValues||!includeEmptyValues&&st.length>0) result += delim1 + x.name + delim2 + encodeURIComponent(st)
          break;
        case 'radio':
          st = x.value;
          if (trimValues) st = trim(st);
          if (x.checked&&(includeEmptyValues||!includeEmptyValues&&st.length>0)) result += delim1 + x.name + delim2 + encodeURIComponent(st);
          break;
        case 'checkbox':
          st = x.value;
          if (trimValues) st = trim(st);
          if (x.checked&&(includeEmptyValues||!includeEmptyValues&&st.length>0)) result += delim1 + x.name + delim2 + encodeURIComponent(st);
          break;
        default: {
          st = x.value;
          if (trimValues) st = trim(st);
          if (includeEmptyValues||!includeEmptyValues&&st.length>0) result += delim1 + x.name + delim2 + encodeURIComponent(st);
        }
      }
    }
  }
  if (result.charAt(0) == delim1) result = result.substring(1, result.length);
  return result
}
function trim(s){
  var spaces = String.fromCharCode(32) + String.fromCharCode(9) + String.fromCharCode(10) + String.fromCharCode(13);
  while (s.length>0&&spaces.indexOf(s.charAt(s.length - 1))!=-1){
    s = s.substring(0, s.length - 1);
  }
  while (s.length>0&&spaces.indexOf(s.charAt(0))!=-1){
    s = s.substring(1, s.length);
  }
  return s
}
function isEmail(em){
   //var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,7}$/;
   var emailRegex = /^[a-z0-9-_&~\+\.]+@([a-z0-9-]+\.){1,4}[a-z]{2,7}$/i;
   return emailRegex.test(em);
}
function isValidCreditCard(type, ccnum) {
  if (type == "visa") {
    // Visa: length 16, prefix 4, dashes optional.
    var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
  } else if (type == "master card") {
    // Mastercard: length 16, prefix 51-55, dashes optional.
    var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
  } else if (type == "disc") {
    // Discover: length 16, prefix 6011, dashes optional.
    var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
  } else if (type == "amex") {
    // American Express: length 15, prefix 34 or 37.
    var re = /^3[4,7]\d{13}$/;
  } else if (type == "diners") {
    // Diners: length 14, prefix 30, 36, or 38.
    var re = /^3[0,6,8]\d{12}$/;
  } else return false
  if (!re.test(ccnum)) return false;
  // Remove all dashes for the checksum checks to eliminate negative numbers
  ccnum = ccnum.split("-").join("");
  // Checksum ("Mod 10")
  // Add even digits in even length strings or odd digits in odd length strings.
  var checksum = 0;
  for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
    checksum += parseInt(ccnum.charAt(i-1));
  }
  // Analyze odd digits in even length strings or even digits in odd length strings.
  for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
    var digit = parseInt(ccnum.charAt(i-1)) * 2;
    if (digit < 10) {
      checksum += digit;
    } else {
      checksum += (digit-9);
    }
  }
  if ((checksum % 10) == 0) return true;
  else return false;
}
function doConfirmedRellocate(sMSG, sURL) {
  if (confirm(sMSG)) {
    document.location = sURL;
  }
}
function showHideByID(id){
  var idText = "";
  var wordTrue = "";
  var wordFalse = "";
  if (arguments.length >= 4) {
    idText = arguments[1];
    wordTrue = arguments[2];
    wordFalse = arguments[3];
  }
  if (document.getElementById(id).style.display=="none"){
    document.getElementById(id).style.display = "";
    if (idText.length > 0) document.getElementById(idText).innerHTML = wordTrue;
  } else {
    document.getElementById(id).style.display = "none";
    if (idText.length > 0) document.getElementById(idText).innerHTML = wordFalse;
  }
}
