var reEmail = /^[a-zA-Z0-9]+[a-zA-Z0-9_\-\.]*@[a-zA-Z0-9]+[a-zA-Z0-9_\-\.]*\.[a-zA-Z]{2,4}$/;
var reAlphaNumeric = /^[a-zA-Zà-ÿÀ-ß0-9\s\-\.\,\"]+$/;
var reLogin = /^[a-zA-Z0-9\-_]{4,}$/;
var rePassword = /^[a-zA-Z0-9\-_]{6,}$/;
var reNumeric = /^[0-9]+$/;
var rePhone = /^[0-9\-\+\s()]{5,}$/;

var oTarget;

function trim(inputString) {
  // Removes leading and trailing spaces from the passed string. Also removes
  // consecutive spaces and replaces it with one space. If something besides
  // a string is passed in (null, custom object, etc.) then return the input.
  if (typeof(inputString) != "string") {
    return inputString;
  }
  var retValue = inputString;
  var ch = retValue.substring(0, 1);
  // Check for spaces at the beginning of the string
  while (ch == " ") {
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
  }
  // Check for spaces at the end of the string
  ch = retValue.substring(retValue.length-1, retValue.length);
  while (ch == " ") {
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1, retValue.length);
  }
  // Note that there are two spaces in the string
  // look for multiple spaces within the string
  while (retValue.indexOf("  ") != -1) {
    // Again, there are two spaces in each of the strings
    retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
  }
  // Return the trimmed string back to the user
  return retValue;
}

// Check the string is empty or not
function is_empty(inputString)  {
  inputString = trim(inputString);
  return ((inputString == null) || (inputString.length == 0) || typeof(inputString) != "string")
}

//
// Creates new window from link
// Parameters:
// Link - link to show in window
// Effect:
// Opens a window with name "Additional" and shows needed link in it.
//
function linkWindow(link_url, width, height) {
  if (event) {
    event.cancelBubble = true;
    event.returnValue = false;
  }
  if (typeof(width) == "undefined" && typeof(height) == "undefined") {
    var width = Math.ceil(screen.width/2);
    var height = Math.ceil(screen.height*0.6);
    if (width < 600) { width = 600; }
    if (height < 400) { height = 400; }
  } else {
    if (width > 800) { width = 800; }
    if (height > 600) { height = 600; }
    width = width + 20;
    height = height + 5;
  }
  var left = Math.ceil(screen.width/8);
  var top = Math.ceil(screen.height*0.1);
  var oTarget = window.open(link_url, "", "height="+height+",width="+width+",scrollbars=1,left="+left+",top="+top);
  oTarget.focus();
  return false;
};

function start_search() {
  var params = '';

  var frm = document.forms['search'];
  var by_name = trim(frm.by_name.value);
  var by_vendor = trim(frm.by_vendor.value);

  if (by_name != '') {
    params = '&by_name=' + by_name;
  } else if (by_vendor != '') {
    params = '&by_vendor=' + by_vendor;
  }

  if (typeof(frm.sale) != 'undefined' && (frm.sale.value == 1)) {
//    params = params + '&sale=1';
    params = params;
  }
  document.location = 'products.html?' + params;
  return false;
};

