


String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

/**
 * returns string with all leading and trailing characters 
 * eliminated.
 */
function trim(str){
  var s = new String(str);
  //trailing spaces
  while (s.length>0 && isSpaceCharacter(""+s.charAt(s.length-1))){
    s = s.substring(0,s.length-1);
  }
  //leading spaces
  while (s.length>0 && isSpaceCharacter(""+s.charAt(0))){
    s = s.substring(1);
  }
  return s
}

var spaces = " \t\r\n"+String.fromCharCode(160);

function isSpaceCharacter(ch){
  return spaces.indexOf(ch) >-1;
}
/**
 * Validates that input's value is correct email address
 */
function validateEmail(elem) {
    var str = "";
    if (elem.value) {
        str = new String(elem.value);
    } else {
        str = new String(elem);
    }

    if (window.RegExp) {
        var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
        var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$";
        var reg3str = "\"([^\"]+)\"\\s+<{1}([A-z]{1}[A-z0-9\\x2d\\.]*[A-z0-9]{1}@[A-z0-9\\x2d\\.]*[A-z-9]{1}\\.[A-z]{2,5})>{1}";
        var reg1 = new RegExp(reg1str);
        var reg2 = new RegExp(reg2str);
        var reg3 = new RegExp(reg3str);
        if (!reg1.test(str) && (reg2.test(str) || reg3.test(str))) return true;
        return false;
    } else {
        if (str.indexOf("@") >= 0) return true;
        return false;
    }
}

function isEmpty(elem){
  return trim(elem.value).length==0;
}

function isNumber(d,isinteger,ispositive){
 var data=new String(d);
 var numStr=".-0123456789";
 var th;  var counter=0;  var ret=false;
 for(var i=0; i < data.length; i++){
  th = data.substring(i, i+1); if(numStr.indexOf(th) != -1) counter++;
 }
 if(counter == data.length){
   if(data.indexOf(".")!=data.lastIndexOf(".")) return false;
   if(data.indexOf("-")>0) return false;
   if(isinteger&&data.indexOf(".")!=-1) return false;
   if(ispositive&&data.indexOf("-")!=-1) return false;
   return true;
 }
 return(false);
}

function viewContactInformation(x,id){
    if(x=="client"){
        alert('To view contact information in category Home Exchange you need to become Home Exchange member. Click OK to register. If you are already a registered member, please click OK to login and to add your Home Exchange listing.');
        document.location.href = '/?p2=/modules/houseexchange/register.jsp&accid=' + id;
    }
    if(x=="owner"){
        alert('To view contact information in category Home Exchange you need to become Home Exchange member.  Click OK to add your listing in category Home Exchange.');
        document.location.href = '/?p2=modules/houseexchange/editaccommodation.jsp&rnd=' + Math.random();
    }
    if(x=="deactivated"){
        alert('Your account has not been activated yet.  Please wait a few hours until your account is activated, or contact the webmaster.');
    }
    if(x=="reg"){
        document.forms['ownercontacts'].accid.value=id;
        document.forms['ownercontacts'].submit();
    }
}

